コード例 #1
0
ファイル: memory.py プロジェクト: pluohust/ConFuzz
    def readMemory(self, va, size):

        for mva, mmaxva, mmap, mbytes in self._map_defs:
            if va >= mva and va < mmaxva:
                mva, msize, mperms, mfname = mmap
                if not mperms & MM_READ:
                    raise envi.SegmentationViolation(va)
                offset = va - mva
                return mbytes[offset:offset+size]
        raise envi.SegmentationViolation(va)
コード例 #2
0
ファイル: memory.py プロジェクト: pluohust/ConFuzz
    def writeMemory(self, va, bytes):
        for mapdef in self._map_defs:
            mva, mmaxva, mmap, mbytes = mapdef
            if va >= mva and va < mmaxva:
                mva, msize, mperms, mfname = mmap
                if not mperms & MM_WRITE:
                    raise envi.SegmentationViolation(va)
                offset = va - mva
                mapdef[3] = mbytes[:offset] + bytes + mbytes[offset+len(bytes):]
                return

        raise envi.SegmentationViolation(va)
コード例 #3
0
ファイル: memory.py プロジェクト: LockeColeFF/vivisect
 def readMemory(self, va, size):
     '''
     Read memory from maps stored in memory maps.
     '''
     for mva, mmaxva, mmap, mbytes in self._map_defs:
         if mva <= va < mmaxva:
             mva, msize, mperms, mfname = mmap
             if not mperms & MM_READ:
                 raise envi.SegmentationViolation(va)
             offset = va - mva
             return mbytes[offset:offset+size]
     raise envi.SegmentationViolation(va)
コード例 #4
0
 def readMemory(self, va, size):
     if self.checkMemory(va):
         return e_mem.MemoryObject.readMemory(self, va, size)
     if self.vw.getSegment(va) is not None:
         return self.vw.readMemory(va, size)
     # We don't have it
     if self.nosegfault:
         return "A" * size
     raise envi.SegmentationViolation(va)
コード例 #5
0
    def writeMemory(self, va, bytez, _origva=None):
        '''
        Write memory to maps stored in memory maps.

        If the write crosses memory maps and fails on a later map, the exception
        will show the details of the last map/failure, but should include the
        original va (but not the original size).
        In this scenario, writes to the first map will succeed, up until the address of the exception.

        _origva is an internal field and should not be used.
        '''
        byteslen = len(bytez)
        for mapdef in self._map_defs:
            mva, mmaxva, mmap, mbytes = mapdef
            if mva <= va < mmaxva:
                mva, msize, mperms, mfname = mmap
                if not (mperms & MM_WRITE or self._supervisor):
                    msg = "Bad Memory Write (no WRITE permission): %s: %s" % (hex(va), hex(byteslen))
                    if _origva:
                        msg += " (original va: %s)" % hex(_origva)
                    raise envi.SegmentationViolation(va, msg)

                offset = va - mva
                maxwritelen = msize - offset
                if byteslen > maxwritelen:
                    # if we're writing past the end of this map, recurse to find the next map
                    # perms checks for that map will be performed, and size, etc... and if
                    # an exception must be thrown, future writeMemory() can throw it
                    if not _origva:
                        _origva = va
                    mapdef[3] = mbytes[:offset] + bytez[:maxwritelen]
                    self.writeMemory(mva + msize, bytez[maxwritelen:], _origva=_origva)
                else:
                    mapdef[3] = mbytes[:offset] + bytez + mbytes[offset+byteslen:]
                return

        msg = "Bad Memory Write (invalid memory address): %s: %s" % (hex(va), hex(byteslen))
        if _origva:
            msg += " (original va: %s)" % hex(_origva)

        raise envi.SegmentationViolation(va, msg)
コード例 #6
0
 def getByteDef(self, va):
     """
     An optimized routine which returns the existing
     segment bytes sequence without creating a new
     string object *AND* an offset of va into the
     buffer.  Used internally for optimized memory
     handling.  Returns (offset, bytes)
     """
     for mapdef in self._map_defs:
         mva, mmaxva, mmap, mbytes = mapdef
         if mva <= va < mmaxva:
             offset = va - mva
             return (offset, mbytes)
     raise envi.SegmentationViolation(va)