def test_registers(self): self.assertIn( "rax", itertools.chain.from_iterable( reg.names for reg in Platform(Architecture.X86_64).registers), ) self.assertEqual( Platform(Architecture.UNKNOWN, PlatformFlags(0)).registers, ())
def test_read_unsigned(self): data = b"\x01\x02\x03\x04\x05\x06\x07\x08" for word_size in [8, 4]: for byteorder in ["little", "big"]: flags = PlatformFlags(0) if word_size == 8: flags |= PlatformFlags.IS_64_BIT if byteorder == "little": flags |= PlatformFlags.IS_LITTLE_ENDIAN prog = mock_program( Platform(Architecture.UNKNOWN, flags), segments=[MockMemorySegment(data, 0xFFFF0000, 0xA0)], ) for size in [1, 2, 4, 8]: read_fn = getattr(prog, f"read_u{8 * size}") value = int.from_bytes(data[:size], byteorder) self.assertEqual(read_fn(0xFFFF0000), value) self.assertEqual(read_fn(0xA0, True), value) if size == word_size: self.assertEqual(prog.read_word(0xFFFF0000), value) self.assertEqual(prog.read_word(0xA0, True), value) prog = mock_program( MOCK_32BIT_PLATFORM, segments=[MockMemorySegment(data, 0xFFFF0000, 0xA0)] )
Language, Object, Platform, PlatformFlags, Program, Type, TypeEnumerator, TypeKind, TypeMember, TypeParameter, TypeTemplateParameter, ) DEFAULT_LANGUAGE = Language.C MOCK_32BIT_PLATFORM = Platform(Architecture.UNKNOWN, PlatformFlags.IS_LITTLE_ENDIAN) MOCK_PLATFORM = Platform( Architecture.UNKNOWN, PlatformFlags.IS_64_BIT | PlatformFlags.IS_LITTLE_ENDIAN) class MockMemorySegment(NamedTuple): buf: bytes virt_addr: Optional[int] = None phys_addr: Optional[int] = None def mock_memory_read(data, address, count, offset, physical): return data[offset:offset + count]
def test_default_flags(self): Platform(Architecture.X86_64) self.assertRaises(ValueError, Platform, Architecture.UNKNOWN)
def test_registers(self): self.assertIn("rax", (reg.name for reg in Platform(Architecture.X86_64).registers)) self.assertEqual( Platform(Architecture.UNKNOWN, PlatformFlags(0)).registers, ())