Exemplo n.º 1
0
 def connectProcess(self):
   """Connect the debugguer to the process and gets the memory mappings metadata."""
   self.dbg = dbg.PtraceDebugger()
   self.process = self.dbg.addProcess(self._pid, is_attached=False)
   if self.process is None:
     log.error("Error initializing Process debugging for %d"% self._pid)
     raise IOError
     # ptrace exception is raised before that
   self.mappings = memory_mapping.readProcessMappings(self.process)
   log.debug('mappings read. Dropping ptrace on pid.')
   return
 def test_mmap_hack(self):
   fname = os.path.normpath(os.path.abspath(__file__))
   fin = file(fname)
   local_mmap_bytebuffer = mmap.mmap(fin.fileno(), 1024, access=mmap.ACCESS_READ)
   fin.close()
   fin = None
   # yeap, that right, I'm stealing the pointer value. DEAL WITH IT.
   heapmap = struct.unpack('L', (ctypes.c_ulong).from_address(id(local_mmap_bytebuffer) + 2*(ctypes.sizeof(ctypes.c_ulong)) ) )[0]
   log.debug('MMAP HACK: heapmap: 0x%0.8x'%(heapmap) )
   class P:
     pid=os.getpid()
   maps = memory_mapping.readProcessMappings(P()) # memory_mapping
   #print '\n'.join([str(m) for m in maps])
   #print '**',hex(heapmap)
   ret=[m for m in maps if heapmap in m]
   self.assertEquals( len(ret), 1)
   self.assertEquals( ret[0].pathname, fname)
Exemplo n.º 3
0
 def initPid(self, pid, mmap):
   dbg = PtraceDebugger()
   process = dbg.addProcess(pid, is_attached=False)
   if process is None:
     log.error("Error initializing Process debugging for %d"% pid)
     raise IOError
     # ptrace exception is raised before that
   mappings = memory_mapping.readProcessMappings(process)
   t0 = time.time()
   for m in mappings :
     if mmap:
       ### mmap memory in local space
       m.mmap()
       log.debug('mmap() : %d'%(len(m.mmap())))
   if mmap:
     ### mmap done, we can release process...
     process.cont()
     log.info('Memory mmaped, process released after %02.02f secs'%(time.time()-t0))
   return mappings
Exemplo n.º 4
0
 def initPid(self, args):
   dbg = PtraceDebugger()
   process = dbg.addProcess(args.pid, is_attached=False)
   if process is None:
     log.error("Error initializing Process debugging for %d"% args.pid)
     raise IOError
     # ptrace exception is raised before that
   mappings = memory_mapping.readProcessMappings(process)
   t0 = time.time()
   for m in mappings :
     if args.mmap:
       ### mmap memory in local space
       m.mmap()
       log.debug('mmap() : %d'%(len(m.mmap())))
   if args.mmap:
     ### mmap done, we can release process...
     process.cont()
     log.info('Memory mmaped, process released after %02.02f secs'%(time.time()-t0))
   return mappings
Exemplo n.º 5
0
 def initPid(self, pid, mmap):
     if not isinstance(pid, (int, long)):
         raise TypeError('PID should be a number')
     dbg = PtraceDebugger()
     process = dbg.addProcess(pid, is_attached=False)
     if process is None:
         log.error("Error initializing Process debugging for %d" % pid)
         raise IOError
         # ptrace exception is raised before that
     mappings = memory_mapping.readProcessMappings(process)
     t0 = time.time()
     for m in mappings:
         if mmap:
             ### mmap memory in local space
             m.mmap()
             log.debug('mmap() : %d' % (len(m.mmap())))
     if mmap:
         ### mmap done, we can release process...
         process.cont()
         log.info('Memory mmaped, process released after %02.02f secs' %
                  (time.time() - t0))
     return mappings
    def test_mmap_hack(self):
        fname = os.path.normpath(os.path.abspath(__file__))
        fin = file(fname)
        local_mmap_bytebuffer = mmap.mmap(fin.fileno(),
                                          1024,
                                          access=mmap.ACCESS_READ)
        fin.close()
        fin = None
        # yeap, that right, I'm stealing the pointer value. DEAL WITH IT.
        heapmap = struct.unpack('L', (ctypes.c_ulong).from_address(
            id(local_mmap_bytebuffer) + 2 *
            (ctypes.sizeof(ctypes.c_ulong))))[0]
        log.debug('MMAP HACK: heapmap: 0x%0.8x' % (heapmap))

        class P:
            pid = os.getpid()

        maps = memory_mapping.readProcessMappings(P())  # memory_mapping
        #print '\n'.join([str(m) for m in maps])
        #print '**',hex(heapmap)
        ret = [m for m in maps if heapmap in m]
        self.assertEquals(len(ret), 1)
        self.assertEquals(ret[0].pathname, fname)
Exemplo n.º 7
0
def getMappings():
  me = Dummy()
  me.pid = os.getpid()
  return memory_mapping.readProcessMappings(me)
Exemplo n.º 8
0
def getMappings():
    me = Dummy()
    me.pid = os.getpid()
    return memory_mapping.readProcessMappings(me)