예제 #1
0
 def _dump_mapping(self, m, tmpdir):
   """Dump one mapping to one file in one tmpdir."""
   if m.permissions[0] != 'r':
     log.debug('Ignoring read protected mapping')
     return
   elif m.pathname in ['[vdso]','[vsyscall]']:
     log.debug('Ignoring system mapping')
     return
   log.debug('Dumping %s to %s'%(m,tmpdir))
   # dump files to tempdir
   mname = "%s-%s" % (dbg.formatAddress(m.start), dbg.formatAddress(m.end))
   mmap_fname = os.path.join(tmpdir, mname)
   # we are dumping the memorymap content
   if self._just_heap or self._just_stack: #dump heap and/or stack
     if ( (self._just_heap  and m.pathname == '[heap]') or 
            (self._just_stack and m.pathname == '[stack]') ) :
       log.debug('Dumping the memorymap content')
       with open(mmap_fname,'wb') as mmap_fout:
         mmap_fout.write(m.mmap().getByteBuffer())
   else: #dump all the memory maps
     log.debug('Dumping the memorymap content')
     with open(mmap_fname,'wb') as mmap_fout:
       mmap_fout.write(m.mmap().getByteBuffer())
   #dump all the memory maps metadata
   log.debug('Dumping the memorymap metadata')
   self.index.write('%s\n'%(m) )
   return 
예제 #2
0
 def __str__(self):
     text = ' '.join([
         formatAddress(self.start),
         formatAddress(self.end), self.permissions,
         '0x%0.8x' % (self.offset),
         '%0.2x:%0.2x' % (self.major_device, self.minor_device),
         '%0.7d' % (self.inode),
         str(self.pathname)
     ])
     return text
예제 #3
0
 def __str__(self):
   text = ' '.join([formatAddress(self.start), formatAddress(self.end), self.permissions,
          '0x%0.8x'%(self.offset), '%0.2x:%0.2x'%(self.major_device, self.minor_device), '%0.7d'%(self.inode), str(self.pathname)])
   return text
예제 #4
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