def test_mptable(): """Test the MP Table""" mp = MPTable() if mp is None: return addr = bits.memory_addr(mp._floating_pointer_memory) for address, size in bad_address_ranges: if addr >= address and addr < address + size: bad_address = True break else: bad_address = False testsuite.test('MP Floating Pointer Structure at spec-compliant address', not bad_address) testsuite.print_detail( 'Found MP Floating Pointer Structure at bad address {:#x}'.format( addr)) testsuite.print_detail( 'MP Floating Pointer Structure must appear at a 16-byte-aligned address' ) testsuite.print_detail('located, in order of preference, in:') testsuite.print_detail('- the first kilobyte of the EBDA') testsuite.print_detail( '- the last kilobyte of system base memory (639k to 640k)') testsuite.print_detail('- the 0xF0000 to 0xFFFFF block')
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_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 test_pirtable(): """Test the PCI Interrupt Routing Table""" pir = PIRTable() if pir is None: return addr = bits.memory_addr(pir._table_memory) for address, size in bad_address_ranges: if addr >= address and addr < address + size: bad_address = True break else: bad_address = False testsuite.test('PCI Interrupt Routing Table spec-compliant address', not bad_address) testsuite.print_detail('Found PCI Interrupt Routing Table at bad address {:#x}'.format(addr)) testsuite.print_detail('$PIR Structure must appear at a 16-byte-aligned address') testsuite.print_detail('located in the 0xF0000 to 0xFFFFF block')
def test_mptable(): """Test the MP Table""" mp = MPTable() if mp is None: return addr = bits.memory_addr(mp._floating_pointer_memory) for address, size in bad_address_ranges: if addr >= address and addr < address + size: bad_address = True break else: bad_address = False testsuite.test('MP Floating Pointer Structure at spec-compliant address', not bad_address) testsuite.print_detail('Found MP Floating Pointer Structure at bad address {:#x}'.format(addr)) testsuite.print_detail('MP Floating Pointer Structure must appear at a 16-byte-aligned address') testsuite.print_detail('located, in order of preference, in:') testsuite.print_detail('- the first kilobyte of the EBDA') testsuite.print_detail('- the last kilobyte of system base memory (639k to 640k)') testsuite.print_detail('- the 0xF0000 to 0xFFFFF block')
def test_pirtable(): """Test the PCI Interrupt Routing Table""" pir = PIRTable() if pir is None: return addr = bits.memory_addr(pir._table_memory) for address, size in bad_address_ranges: if addr >= address and addr < address + size: bad_address = True break else: bad_address = False testsuite.test('PCI Interrupt Routing Table spec-compliant address', not bad_address) testsuite.print_detail( 'Found PCI Interrupt Routing Table at bad address {:#x}'.format(addr)) testsuite.print_detail( '$PIR Structure must appear at a 16-byte-aligned address') testsuite.print_detail('located in the 0xF0000 to 0xFFFFF block')
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