Skip to content

Commit 445c55c

Browse files
committed
Implement more hob handling methods
1 parent 7ce7f7b commit 445c55c

File tree

1 file changed

+50
-12
lines changed

1 file changed

+50
-12
lines changed

qiling/os/uefi/hob.py

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#
55

66
from qiling import Qiling
7-
from qiling.os.uefi.utils import GetEfiConfigurationTable
7+
from qiling.os.uefi.context import UefiContext
8+
from qiling.os.uefi.utils import GetEfiConfigurationTable, CompareGuid, str_to_guid
89
from qiling.os.uefi.UefiBaseType import STRUCT, EFI_GUID, UINT32, UINT16
910
from qiling.os.uefi.UefiSpec import EFI_CONFIGURATION_TABLE
1011

@@ -25,31 +26,25 @@ class EFI_HOB_GUID_TYPE(STRUCT):
2526
('Name', EFI_GUID)
2627
]
2728

28-
def GetHobList(ql: Qiling) -> int:
29+
def GetHobList(ql: Qiling, context: UefiContext) -> int:
2930
"""Get HOB list location in memory (ostensibly set by PEI).
3031
"""
3132

3233
conftable_guid = ql.os.profile['HOB_LIST']['Guid']
33-
conftable_ptr = GetEfiConfigurationTable(ql.loader.dxe_context, conftable_guid)
34+
conftable_ptr = GetEfiConfigurationTable(context, conftable_guid)
3435
conftable = EFI_CONFIGURATION_TABLE.loadFrom(ql, conftable_ptr)
3536

3637
return ql.unpack64(conftable.VendorTable)
3738

38-
def CreateHob(ql: Qiling, hob) -> int:
39+
def CreateHob(ql: Qiling, context: UefiContext, hob) -> int:
3940
"""Add a HOB to the end of the HOB list.
4041
"""
4142

42-
hoblist = GetHobList(ql)
43+
hoblist = GetHobList(ql, context)
4344

4445
# look for the list end marker; uefi codebase assumes there is
4546
# always one
46-
while True:
47-
header = EFI_HOB_GENERIC_HEADER.loadFrom(ql, hoblist)
48-
49-
if header.HobType == EFI_HOB_TYPE_END_OF_HOB_LIST:
50-
break
51-
52-
hoblist += header.HobLength
47+
hoblist = GetNextHob(ql, EFI_HOB_TYPE_END_OF_HOB_LIST, hoblist)
5348

5449
# overwrite end marker with the hob
5550
pHob = hoblist
@@ -65,3 +60,46 @@ def CreateHob(ql: Qiling, hob) -> int:
6560

6661
# return the address the hob was written to; it might be useful
6762
return pHob
63+
64+
def GetNextHob(ql: Qiling, hobtype: int, hoblist: int) -> int:
65+
"""Get next HOB on the list.
66+
"""
67+
68+
hobaddr = hoblist
69+
70+
while True:
71+
header = EFI_HOB_GENERIC_HEADER.loadFrom(ql, hobaddr)
72+
73+
# found the hob?
74+
if header.HobType == hobtype:
75+
break
76+
77+
# reached end of hob list?
78+
if header.HobType == EFI_HOB_TYPE_END_OF_HOB_LIST:
79+
return 0
80+
81+
hobaddr += header.HobLength
82+
83+
return hobaddr
84+
85+
def GetNextGuidHob(ql: Qiling, guid: str, hoblist: int):
86+
"""Find next HOB with the specified GUID.
87+
"""
88+
89+
hobguid = str_to_guid(guid)
90+
hobaddr = hoblist
91+
92+
while True:
93+
hobaddr = GetNextHob(ql, EFI_HOB_TYPE_GUID_EXTENSION, hobaddr)
94+
95+
if not hobaddr:
96+
return 0
97+
98+
hob = EFI_HOB_GUID_TYPE.loadFrom(ql, hobaddr)
99+
100+
if CompareGuid(hob.Name, hobguid):
101+
break
102+
103+
hobaddr += hob.Header.HobLength
104+
105+
return hobaddr

0 commit comments

Comments
 (0)