def __init__(self): super(MPTable, self).__init__() u = unpack.Unpackable(self._floating_pointer_memory) self.add_field('floating_pointer', FloatingPointer(u)) self._base_header_memory = bits.memory( self.floating_pointer.physical_address_pointer, 44) u = unpack.Unpackable(self._base_header_memory) self.add_field('header', Header(u), "\n\n{!r}") self._base_table_memory = bits.memory( self.floating_pointer.physical_address_pointer, self.header.base_table_length) u = unpack.Unpackable(self._base_table_memory) u.skip(44) self.add_field('base_structures', unpack.unpack_all(u, _base_structures), unpack.format_each("\n\n{!r}")) self._extended_table_memory = bits.memory( self.floating_pointer.physical_address_pointer + self.header.base_table_length, self.header.extended_table_length) u = unpack.Unpackable(self._extended_table_memory) self.add_field('extended_structures', unpack.unpack_all(u, _extended_structures), unpack.format_each("\n\n{!r}"))
def __init__(self): super(SMBIOS, self).__init__() u = unpack.Unpackable(self._header_memory) self.add_field('header', Header(u)) self._structure_memory = bits.memory(self.header.structure_table_address, self.header.structure_table_length) u = unpack.Unpackable(self._structure_memory) self.add_field('structures', unpack.unpack_all(u, _smbios_structures, self), unpack.format_each("\n\n{!r}"))
def __init__(self): super(MPTable, self).__init__() u = unpack.Unpackable(self._floating_pointer_memory) self.add_field('floating_pointer', FloatingPointer(u)) self._base_header_memory = bits.memory(self.floating_pointer.physical_address_pointer, 44) u = unpack.Unpackable(self._base_header_memory) self.add_field('header', Header(u), "\n\n{!r}") self._base_table_memory = bits.memory(self.floating_pointer.physical_address_pointer, self.header.base_table_length) u = unpack.Unpackable(self._base_table_memory) u.skip(44) self.add_field('base_structures', unpack.unpack_all(u, _base_structures), unpack.format_each("\n\n{!r}")) self._extended_table_memory = bits.memory(self.floating_pointer.physical_address_pointer + self.header.base_table_length, self.header.extended_table_length) u = unpack.Unpackable(self._extended_table_memory) self.add_field('extended_structures', unpack.unpack_all(u, _extended_structures), unpack.format_each("\n\n{!r}"))
def __new__(cls): offset = find_mp_table() if offset is None: return None mp = super(MPTable, cls).__new__(cls) mp._floating_pointer_memory = bits.memory(offset, 0x10) return mp
def __new__(cls): offset = find_pir_table() if offset is None: return None pir = super(PIRTable, cls).__new__(cls) pir._header_memory = bits.memory(offset, 0x20) return pir
def __init__(self): super(PIRTable, self).__init__() u = unpack.Unpackable(self._header_memory) self.add_field('header', Header(u), "\n\n{!r}") self._table_memory = bits.memory(bits.memory_addr(self._header_memory), self.header.table_size) u = unpack.Unpackable(self._table_memory) u.skip(0x20) self.add_field('structures', unpack.unpack_all(u, [SlotEntry]), unpack.format_each("\n\n{!r}"))
def find_mp_table(): if sys.platform == "BITS-EFI": import efi return efi.system_table.ConfigurationTableDict.get(efi.MPS_TABLE_GUID) signature = struct.unpack("<I", "_MP_")[0] address_ranges = valid_address_ranges + bad_address_ranges bda = bits.memory(0x400, 0x100) ebda_address = unpack.Unpackable(bda).unpack_one("<14xH") << 4 if ebda_address: address_ranges.insert(0, (ebda_address, 0x400)) for address, size in address_ranges: mem = bits.memory(address, size) for offset in range(0, len(mem), 16): if struct.unpack_from("<I", mem, offset)[0] == signature: length = struct.unpack_from("8xB", mem, offset)[0] if length == 1: csum = sum(map(ord, mem[offset : offset + 16])) & 0xFF if csum == 0: return bits.memory_addr(mem) + offset return None
def __new__(cls): if sys.platform == "BITS-EFI": import efi sm_ptr = efi.system_table.ConfigurationTableDict.get(efi.SMBIOS_TABLE_GUID) else: mem = bits.memory(0xF0000, 0x10000) signature = struct.unpack("<I", "_SM_")[0] for offset in range(0, len(mem), 16): if struct.unpack_from("I", mem, offset)[0] == signature: entry_point_length = struct.unpack_from("B", mem, offset + 5)[0] csum = sum(map(ord, mem[offset:offset + entry_point_length])) & 0xff if csum == 0: sm_ptr = bits.memory_addr(mem) + offset break else: return None if not sm_ptr: return None sm = super(SMBIOS, cls).__new__(cls) sm._header_memory = bits.memory(sm_ptr, 0x1f) return sm
def find_pir_table(): """Find and validate the address of the PCI Interrupt Routing table""" signature = struct.unpack("<I", "$PIR")[0] address_ranges = valid_address_ranges + bad_address_ranges for address, size in address_ranges: mem = bits.memory(address, size) for offset in range(0, len(mem), 16): if struct.unpack_from("<I", mem, offset)[0] == signature: table_size = struct.unpack_from("<H", mem, offset + 6)[0] if table_size <= (size - offset) and ((table_size - 32) % 16 == 0): csum = sum(ord(mem[c]) for c in range(offset, offset + table_size)) if csum & 0xff == 0: return bits.memory_addr(mem) + offset return None
def find_pir_table(): """Find and validate the address of the PCI Interrupt Routing table""" address_ranges = valid_address_ranges + bad_address_ranges for address, size in address_ranges: mem = bits.memory(address, size) for offset in range(0, len(mem), 16): signature = (ctypes.c_char * 4).from_address(address + offset).value if signature == '$PIR': table_size = ctypes.c_uint16.from_address(address + offset + 6).value if table_size <= (size - offset) and ((table_size - 32) % 16 == 0): csum = sum(ord(mem[c]) for c in range(offset, offset + table_size)) if csum & 0xff == 0: return address + offset return None
def find_pir_table(): """Find and validate the address of the PCI Interrupt Routing table""" address_ranges = valid_address_ranges + bad_address_ranges for address, size in address_ranges: mem = bits.memory(address, size) for offset in range(0, len(mem), 16): signature = (ctypes.c_char * 4).from_address(address + offset).value if signature == '$PIR': table_size = ctypes.c_uint16.from_address(address + offset + 6).value if table_size <= (size - offset) and ((table_size - 32) % 16 == 0): csum = sum( ord(mem[c]) for c in range(offset, offset + table_size)) if csum & 0xff == 0: return address + offset return None
def find_mp_table(): if sys.platform == "BITS-EFI": import efi return efi.system_table.ConfigurationTableDict.get(efi.MPS_TABLE_GUID) address_ranges = valid_address_ranges + bad_address_ranges bda_address = 0x400 ebda_address = ctypes.c_uint16.from_address(bda_address + 0x14).value << 4 if ebda_address: address_ranges.insert(0, (ebda_address, 0x400)) for address, size in address_ranges: mem = bits.memory(address, size) for offset in range(0, size, 16): signature = (ctypes.c_char * 4).from_address(address + offset).value if signature == "_MP_": length = ctypes.c_ubyte.from_address(address + offset + 8).value if length == 1: csum = sum(map(ord, mem[offset:offset+16])) & 0xff if csum == 0: return address + offset return None
def find_mp_table(): if sys.platform == "BITS-EFI": import efi return efi.system_table.ConfigurationTableDict.get(efi.MPS_TABLE_GUID) address_ranges = valid_address_ranges + bad_address_ranges bda_address = 0x400 ebda_address = ctypes.c_uint16.from_address(bda_address + 0x14).value << 4 if ebda_address: address_ranges.insert(0, (ebda_address, 0x400)) for address, size in address_ranges: mem = bits.memory(address, size) for offset in range(0, size, 16): signature = (ctypes.c_char * 4).from_address(address + offset).value if signature == "_MP_": length = ctypes.c_ubyte.from_address(address + offset + 8).value if length == 1: csum = sum(map(ord, mem[offset:offset + 16])) & 0xff if csum == 0: return address + offset return None
def __init__(self, u, sm): super(SmbiosBaseStructure, self).__init__() self.start_offset = u.offset length = u.unpack_peek_one("<xB") self.raw_data = u.unpack_raw(length) self.u = unpack.Unpackable(self.raw_data) self.strings_offset = u.offset def unpack_string(): return "".join(iter(lambda: u.unpack_one("c"), "\x00")) strings = list(iter(unpack_string, "")) if not strings: u.skip(1) self.strings_length = u.offset - self.strings_offset self.raw_strings = str(bits.memory(sm.header.structure_table_address + self.strings_offset, self.strings_length)) if len(strings): self.strings = strings self.add_field('type', self.u.unpack_one("B")) self.add_field('length', self.u.unpack_one("B")) self.add_field('handle', self.u.unpack_one("<H"))