示例#1
0
    def test_memory_manager_map_anywhere(self):
        mm = Memory(Uc(UC_ARCH_X86, UC_MODE_32), None, 32)
        address1 = mm.map_anywhere(0x1000, "name1", "size1")

        self.assertEqual(
            mm.memory_info[address1],
            Section(mm.emu, address1, 0x1000, "name1", "size1", ""),
        )

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

        self.assertEqual(
            mm.memory_info[address1],
            Section(mm.emu, address1, 0x1000, "name1", "size1", ""),
        )
        self.assertEqual(
            mm.memory_info[address2],
            Section(mm.emu, address2, 0x2000, "name2", "size2", ""),
        )

        mm.unmap(address1, 0x1000)
        self.assertNotIn(address1, mm.memory_info)
        self.assertEqual(
            mm.memory_info[address2],
            Section(mm.emu, address2, 0x2000, "name2", "size2", ""),
        )
示例#2
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")
示例#3
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")
示例#4
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)
示例#5
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)
示例#6
0
    def test_map_anywhere_bounded(self):
        # Check mapping when given bounds
        mm = Memory(Uc(UC_ARCH_X86, UC_MODE_32), None, 32)
        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.memory_info[address1],
            Section(mm.emu, address1, 0x1000, "name1", "size1", ""),
        )
        self.assertGreaterEqual(address1, min_addr)
        self.assertLessEqual(address1, max_addr)
示例#7
0
    def test_map_anywhere_bounded_preexisting_sections(self):
        mm = Memory(Uc(UC_ARCH_X86, UC_MODE_32), None, 32)
        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.memory_info[address1],
            Section(mm.emu, address1, 0x1000, "name1", "size1", ""),
        )
        self.assertGreaterEqual(address1, min_addr)
        self.assertLessEqual(address1, max_addr)
示例#8
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)