Beispiel #1
0
    def find(self, guid: str) -> Optional[int]:
        ptr = self.baseptr
        nitems = self.nitems
        efi_guid = utils.str_to_guid(guid)

        for _ in range(nitems):
            entry = EFI_CONFIGURATION_TABLE.loadFrom(self.ql, ptr)

            if utils.CompareGuid(entry.VendorGuid, efi_guid):
                return ptr

            ptr += EFI_CONFIGURATION_TABLE.sizeof()

        return None
Beispiel #2
0
def GetHobList(ql: Qiling, context: UefiContext) -> int:
    """Get HOB list location in memory (ostensibly set by PEI).
	"""

    conftable_guid = ql.os.profile['HOB_LIST']['Guid']
    conftable_ptr = GetEfiConfigurationTable(context, conftable_guid)
    conftable = EFI_CONFIGURATION_TABLE.loadFrom(ql, conftable_ptr)

    return ql.unpack64(conftable.VendorTable)
Beispiel #3
0
    def get_vendor_table(self, guid: str) -> Optional[int]:
        ptr = self.find(guid)

        if ptr is not None:
            entry = EFI_CONFIGURATION_TABLE.loadFrom(self.ql, ptr)

            return entry.VendorTable.value

        # not found
        return None
Beispiel #4
0
def GetEfiConfigurationTable(context, guid: str) -> Optional[int]:
    """Find a configuration table by its GUID.
	"""

    guid = guid.lower()
    confs = context.conf_table_array

    if guid in confs:
        idx = confs.index(guid)
        ptr = context.conf_table_array_ptr + (idx *
                                              EFI_CONFIGURATION_TABLE.sizeof())

        return ptr

    # not found
    return None
Beispiel #5
0
    def install(self, guid: str, table: int):
        ptr = self.find(guid)
        append = ptr is None

        if append:
            ptr = self.baseptr + self.nitems * EFI_CONFIGURATION_TABLE.sizeof()
            append = True

        instance = EFI_CONFIGURATION_TABLE()
        instance.VendorGuid = utils.str_to_guid(guid)
        instance.VendorTable = table
        instance.saveTo(self.ql, ptr)

        if append:
            self.nitems += 1
Beispiel #6
0
	def install_configuration_table(self, guid: str, table: int):
		guid = guid.lower()
		confs = self.conf_table_array

		# find configuration table entry by guid. if found, idx would be set to the entry index
		# in the array. if not, idx would be set to one past end of array
		if guid not in confs:
			confs.append(guid)

		idx = confs.index(guid)
		ptr = self.conf_table_array_ptr + (idx * EFI_CONFIGURATION_TABLE.sizeof())

		instance = EFI_CONFIGURATION_TABLE()
		instance.VendorGuid = str_to_guid(guid)
		instance.VendorTable = table
		instance.saveTo(self.ql, ptr)
Beispiel #7
0
def initialize(ql: Qiling, gST: int):
    ql.loader.gST = gST

    gBS = gST + EFI_SYSTEM_TABLE.sizeof()  # boot services
    gRT = gBS + EFI_BOOT_SERVICES.sizeof()  # runtime services
    gDS = gRT + EFI_RUNTIME_SERVICES.sizeof()  # dxe services
    cfg = gDS + ds.EFI_DXE_SERVICES.sizeof()  # configuration tables array

    ql.log.info(f'Global tables:')
    ql.log.info(f' | gST   {gST:#010x}')
    ql.log.info(f' | gBS   {gBS:#010x}')
    ql.log.info(f' | gRT   {gRT:#010x}')
    ql.log.info(f' | gDS   {gDS:#010x}')
    ql.log.info(f'')

    bs.initialize(ql, gBS)
    rt.initialize(ql, gRT)
    ds.initialize(ql, gDS)

    instance = EFI_SYSTEM_TABLE()
    instance.RuntimeServices = gRT
    instance.BootServices = gBS
    instance.NumberOfTableEntries = 0
    instance.ConfigurationTable = cfg

    instance.saveTo(ql, gST)

    # configuration tables bookkeeping
    confs = []

    # these are needed for utils.CoreInstallConfigurationTable
    ql.loader.dxe_context.conf_table_array = confs
    ql.loader.dxe_context.conf_table_array_ptr = cfg

    # configuration table data space; its location is calculated by leaving
    # enough space for 100 configuration table entries. only a few entries are
    # expected, so 100 should definitely suffice
    conf_data = cfg + EFI_CONFIGURATION_TABLE.sizeof() * 100
    ql.loader.dxe_context.conf_table_data_ptr = conf_data
    ql.loader.dxe_context.conf_table_data_next_ptr = conf_data

    install_configuration_table(ql.loader.dxe_context, "HOB_LIST", None)
    install_configuration_table(ql.loader.dxe_context, "DXE_SERVICE_TABLE",
                                gDS)