def _load_memory_mappings(self): """ make the python objects""" _mappings = [] default_ctypes = types.load_ctypes_default() for mmap_fname, start, end, permissions, offset, major_device, minor_device, inode, pathname in self.metalines: log.debug('Loading %s - %s' % (mmap_fname, pathname)) # open the file in the archive fname = os.path.sep.join([self.dumpname, mmap_fname]) mmap = FilenameBackedMemoryMapping(fname, start, end, permissions, offset, major_device, minor_device, inode, pathname=pathname) mmap.set_ctypes(default_ctypes) _mappings.append(mmap) _target_platform = target.TargetPlatform(_mappings, cpu_bits=self._cpu_bits, os_name=self._os_name) self._memory_handler = MemoryHandler(_mappings, _target_platform, self.dumpname) self._memory_handler.reset_mappings() return
def _load_memory_mappings(self): """ make the python objects""" _mappings = [] for mmap_fname, start, end, permissions, offset, major_device, minor_device, inode, pathname in self.metalines: log.debug('Loading %s - %s' % (mmap_fname, pathname)) # open the file in the archive try: mmap_content_file = self._protected_open_file(mmap_fname, pathname) except (IOError, KeyError) as e: log.debug('Ignore absent file : %s' % (e)) mmap = AMemoryMapping(start, end, permissions, offset, major_device, minor_device, inode, pathname=pathname) _mappings.append(mmap) continue except LazyLoadingException as e: mmap = FilenameBackedMemoryMapping(e._filename, start, end, permissions, offset, major_device, minor_device, inode, pathname=pathname) _mappings.append(mmap) continue if isinstance(self.archive, zipfile.ZipFile): # ZipExtFile is lame log.warning( 'Using a local memory mapping . Zipfile sux. thx ruby.') mmap = AMemoryMapping(start, end, permissions, offset, major_device, minor_device, inode, pathname=pathname) mmap = LocalMemoryMapping.fromBytebuffer( mmap, mmap_content_file.read()) # use file mmap when file is too big elif end - start > haystack.MAX_MAPPING_SIZE_FOR_MMAP: log.warning('Using a file backed memory mapping. no mmap in memory for this memorymap (%s).' % (pathname) + ' Search will fail. Buffer is needed.') mmap = FileBackedMemoryMapping(mmap_content_file.name, start, end, permissions, offset, major_device, minor_device, inode, pathname=pathname) else: # log.debug('Using a MemoryDumpMemoryMapping. small size') # mmap = MemoryDumpMemoryMapping(mmap_content_file, start, end, permissions, offset, log.debug('Always use FilenameBackedMemoryMapping. small size') mmap = FilenameBackedMemoryMapping(mmap_content_file.name, start, end, permissions, offset, major_device, minor_device, inode, pathname=pathname) _mappings.append(mmap) _target_platform = target.TargetPlatform(_mappings, cpu_bits=self._cpu_bits, os_name=self._os_name) self._memory_handler = MemoryHandler(_mappings, _target_platform, self.dumpname) return