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")
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)
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)
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)
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")
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", ""), )
def __init__( self, processes: str, hook_manager: HookManager, pid: int, name: str, emu: IEmuHelper, parent_pid: int, main_module: str = None, orig_file_name: str = "", cmdline_args: List = None, environment_variables: Dict = None, virtual_filename: str = None, virtual_path: str = None, disableNX: bool = False, ): # OS plugins place OS-specific, process-level, functionality class ZOS(object): def __init__(self): pass self.zos = ZOS() self.processes = processes self._hook_manager = hook_manager self.emu = emu self.name = name self.pid = pid self.parent_pid = parent_pid self.main_module = main_module self.main_module_name = ( "" if main_module is None else main_module.Filepath ) self.cmdline_args = [] if cmdline_args is None else cmdline_args self.environment_variables = ( {} if environment_variables is None else environment_variables ) self.virtual_filename = virtual_filename self.virtual_path = virtual_path self.original_file_name = orig_file_name self.modules = Modules() self.memory = Memory( self.emu, hook_manager, processes.state, disableNX=disableNX ) self.threads = Threads( self.emu, self.memory, self.processes.stack_size, hook_manager ) self.hooks = Hooks(self.emu, self.threads.scheduler)
def test_map_anywhere_bounded(self): # Check mapping when given bounds 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, ) min_addr = 0x10000 max_addr = 0x12000 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)
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)