def _update_maps(self): sys_info = self.get_proc_attribute('system_info') self.maps = {} address_cursor = 0 VirtualQueryEx = self.k32.VirtualQueryEx meminfo = wintypes.MEMORY_BASIC_INFORMATION() MEM_COMMIT = flags('MEM_COMMIT') MEM_PRIVATE = flags('MEM_PRIVATE') PROTECT_FLAGS = { 0x10: '--x', 0x20: 'r-x', 0x40: 'rwx', 0x80: 'r-x', 0x01: '---', 0x02: 'r--', 0x04: 'rw-', 0x08: 'r--' } while address_cursor < sys_info.lpMaximumApplicationAddress: if VirtualQueryEx(self.handle, address_cursor, ctypes.byref(meminfo), ctypes.sizeof(meminfo)) == 0: break address_cursor = meminfo.BaseAddress + meminfo.RegionSize if (meminfo.State & MEM_COMMIT) == 0: continue addr_low = meminfo.BaseAddress addr_high = address_cursor perms = PROTECT_FLAGS[(meminfo.Protect & 0xff)] if (meminfo.Type & MEM_PRIVATE) == 0: perms += 's' else: perms += 'p' self.maps[addr_low] = MemoryRegion(addr_low, addr_high, perms) return
def maps(self): sys_info = self.get_proc_attribute('system_info') _maps = collections.deque() address_cursor = 0 VirtualQueryEx = m_k32.VirtualQueryEx meminfo = wintypes.MEMORY_BASIC_INFORMATION() MEM_COMMIT = flags('MEM_COMMIT') MEM_PRIVATE = flags('MEM_PRIVATE') PROTECT_FLAGS = { 0x01: '---', 0x02: 'r--', 0x04: 'rw-', 0x08: 'r--', 0x10: '--x', 0x20: 'r-x', 0x40: 'rwx', 0x80: 'r-x' } while address_cursor < sys_info.lpMaximumApplicationAddress: if VirtualQueryEx(self.handle, address_cursor, ctypes.byref(meminfo), ctypes.sizeof(meminfo)) == 0: break address_cursor = meminfo.BaseAddress + meminfo.RegionSize if not meminfo.State & MEM_COMMIT: continue addr_low = meminfo.BaseAddress addr_high = address_cursor perms = PROTECT_FLAGS[meminfo.Protect & 0xff] perms += 'p' if meminfo.Type & MEM_PRIVATE else 's' _maps.append(MemoryRegion(addr_low, addr_high, perms)) return collections.OrderedDict( (mr.addr_low, mr) for mr in sorted(_maps, key=lambda mr: mr.addr_low))