Пример #1
0
 def initMemfile(self,args):
   size = os.fstat(args.memfile.fileno()).st_size
   if size > Config.MAX_MAPPING_SIZE_FOR_MMAP:
     mem = memory_mapping.FileBackedMemoryMapping(args.memfile, args.baseOffset, args.baseOffset+size) ## is that valid ?
     log.warning('Dump file size is big. Using file backend memory mapping. Its gonna be slooow')
   else:
     mem = memory_mapping.MemoryDumpMemoryMapping(args.memfile, args.baseOffset, args.baseOffset+size) ## is that valid ?
   mappings = memory_mapping.Mappings([mem], args.memfile.name)
   return mappings
Пример #2
0
 def _load_mappings(self):
     """Loads the mappings content from the dump to a MemoryMappings.
 
 If an underlying file containing a memory dump does not exists, still
 create a MemoryMap for metadata purposes.
 If the memory map is > Config.MAX_MAPPING_SIZE_FOR_MMAP, use a slow FileBackedMemoryMapping.
 Else, load the mapping in memory.
 """
     mappingsFile = self._open_file(self.archive, self.indexFilename)
     self.metalines = []
     for l in mappingsFile.readlines():
         fields = l.strip().split(' ')
         if '' in fields:
             fields.remove('')
         self.metalines.append((fields[0], fields[1], fields[2], fields[3],
                                fields[4], fields[5], ' '.join(fields[6:])))
     self_mappings = []
     for start, end, permissions, offset, devices, inode, mmap_pathname in self.metalines:
         start, end = int(start, 16), int(end, 16)
         offset = int(offset, 16)
         inode = int(inode)
         #rebuild filename
         mmap_fname = "%s-%s" % (dbg.formatAddress(start),
                                 dbg.formatAddress(end))
         # get devices nums
         major_device, minor_device = devices.split(':')
         major_device = int(major_device, 16)
         minor_device = int(minor_device, 16)
         log.debug('Loading %s - %s' % (mmap_fname, mmap_pathname))
         # open the file in the archive
         try:
             mmap_content_file = self._protected_open_file(
                 mmap_fname, mmap_pathname)
         except (IOError, KeyError), e:
             log.debug('Ignore absent file : %s' % (e))
             raise e
             mmap = memory_mapping.MemoryMapping(start,
                                                 end,
                                                 permissions,
                                                 offset,
                                                 major_device,
                                                 minor_device,
                                                 inode,
                                                 pathname=mmap_pathname)
             self_mappings.append(mmap)
             continue
         except ValueError, e:  # explicit non-loading
             log.debug('Ignore useless file : %s' % (e))
             mmap_content_file = file(
                 os.path.sep.join(
                     [self.archive, self.filePrefix + mmap_fname]), 'rb')
             mmap = memory_mapping.FileBackedMemoryMapping(
                 mmap_content_file,
                 start,
                 end,
                 permissions,
                 offset,
                 major_device,
                 minor_device,
                 inode,
                 pathname=mmap_pathname)
             self_mappings.append(mmap)
             continue
Пример #3
0
                                         offset,
                                         major_device,
                                         minor_device,
                                         inode,
                                         pathname=mmap_pathname)
     mmap = memory_mapping.LocalMemoryMapping.fromBytebuffer(
         mmap, mmap_content_file.read())
 elif end - start > Config.MAX_MAPPING_SIZE_FOR_MMAP:  # use file mmap when file is too big
     log.warning(
         'Using a file backed memory mapping. no mmap in memory for this memorymap (%s).'
         % (mmap_pathname) + ' Search will fail. Buffer is needed.')
     mmap = memory_mapping.FileBackedMemoryMapping(
         mmap_content_file,
         start,
         end,
         permissions,
         offset,
         major_device,
         minor_device,
         inode,
         pathname=mmap_pathname)
 else:
     log.debug('Using a MemoryDumpMemoryMapping. small size')
     mmap = memory_mapping.MemoryDumpMemoryMapping(
         mmap_content_file,
         start,
         end,
         permissions,
         offset,
         major_device,
         minor_device,
         inode,