コード例 #1
0
    def test_memory_manager_map_anywhere(self):
        state = State(None, None, None)
        mm = Memory(create_emulator(UC_ARCH_X86, UC_MODE_32, state), state)
        address1 = mm.map_anywhere(0x1000, name="name1", kind="size1")

        self.assertEqual(mm.get_region(address1).name, "name1")

        address2 = mm.map_anywhere(0x2000, name="name2", kind="size2")

        self.assertEqual(mm.get_region(address1).name, "name1")
        self.assertEqual(mm.get_region(address2).name, "name2")

        mm.unmap(address1, 0x1000)
        self.assertEqual(mm.get_region(address1), None)
        self.assertEqual(mm.get_region(address2).name, "name2")
コード例 #2
0
    def test_map_anywhere_bounded(self):
        # Check mapping when given bounds
        state = State(None, None, None)
        mm = Memory(create_emulator(UC_ARCH_X86, UC_MODE_32, state), state)
        min_addr = 0x10000
        max_addr = 0x12000
        address1 = mm.map_anywhere(
            0x1000,
            min_addr=min_addr,
            max_addr=max_addr,
            name="name1",
            kind="size1",
        )

        self.assertEqual(mm.get_region(address1).name, "name1")
        self.assertGreaterEqual(address1, min_addr)
        self.assertLessEqual(address1, max_addr)
コード例 #3
0
    def test_map_anywhere_bounded_preexisting_sections(self):
        state = State(None, None, None)
        mm = Memory(create_emulator(UC_ARCH_X86, UC_MODE_32, state), state)
        mm.map(0x10000, 0x1000)
        mm.map(0x15000, 0x1000)
        min_addr = 0x12000
        max_addr = 0x14000
        address1 = mm.map_anywhere(
            0x1000,
            min_addr=min_addr,
            max_addr=max_addr,
            name="name1",
            kind="size1",
        )

        self.assertEqual(mm.get_region(address1).name, "name1")
        self.assertGreaterEqual(address1, min_addr)
        self.assertLessEqual(address1, max_addr)
コード例 #4
0
ファイル: processes.py プロジェクト: nylon7/zelos
    def _create_emulator(self) -> IEmuHelper:
        arch = self.state.arch

        uc_arch_mode_dict = {
            "x86": (uc.UC_ARCH_X86, uc.UC_MODE_32),
            "x86_64": (uc.UC_ARCH_X86, uc.UC_MODE_64),
            "arm": (uc.UC_ARCH_ARM, uc.UC_MODE_ARM),
            "mips": (uc.UC_ARCH_MIPS, uc.UC_MODE_MIPS32),
        }

        (uc_arch, uc_mode) = uc_arch_mode_dict[arch]

        endianness = self.state.endianness
        if endianness == "little":
            uc_mode |= uc.UC_MODE_LITTLE_ENDIAN
        elif endianness == "big":
            uc_mode |= uc.UC_MODE_BIG_ENDIAN
        else:
            raise ZelosLoadException(f"Unsupported endianness {endianness}")

        return create_emulator(uc_arch, uc_mode, self.state)
コード例 #5
0
    def test_memory_manager_map_anywhere(self):
        state = State(None, None, None)
        attrs = {"_get_hooks.return_value": []}
        hook_manager = Mock(**attrs)
        m = Memory(
            create_emulator(UC_ARCH_X86, UC_MODE_32, state),
            hook_manager,
            state,
        )
        address1 = m.map_anywhere(0x1000, name="name1", kind="size1")

        self.assertEqual(m.get_region(address1).name, "name1")

        address2 = m.map_anywhere(0x2000, name="name2", kind="size2")

        self.assertEqual(m.get_region(address1).name, "name1")
        self.assertEqual(m.get_region(address2).name, "name2")

        m.unmap(address1, 0x1000)
        self.assertEqual(m.get_region(address1), None)
        self.assertEqual(m.get_region(address2).name, "name2")
コード例 #6
0
    def test_map_anywhere_bounded_preexisting_sections(self):
        state = State(None, None, None)
        attrs = {"_get_hooks.return_value": []}
        hook_manager = Mock(**attrs)
        m = Memory(
            create_emulator(UC_ARCH_X86, UC_MODE_32, state),
            hook_manager,
            state,
        )
        m.map(0x10000, 0x1000)
        m.map(0x15000, 0x1000)
        min_addr = 0x12000
        max_addr = 0x14000
        address1 = m.map_anywhere(
            0x1000,
            min_addr=min_addr,
            max_addr=max_addr,
            name="name1",
            kind="size1",
        )

        self.assertEqual(m.get_region(address1).name, "name1")
        self.assertGreaterEqual(address1, min_addr)
        self.assertLessEqual(address1, max_addr)