Beispiel #1
0
    def _readBytes(self, address, size):
        offset = address % CPU_WORD_SIZE
        if offset:
            # Read word
            address -= offset
            word = self.readWord(address)
            bytes = word2bytes(word)

            # Read some bytes from the word
            subsize = min(CPU_WORD_SIZE - offset, size)
            data = bytes[offset:offset + subsize]   # <-- FIXME: Big endian!

            # Move cursor
            size -= subsize
            address += CPU_WORD_SIZE
        else:
            data = b('')

        while size:
            # Read word
            word = self.readWord(address)
            bytes = word2bytes(word)

            # Read bytes from the word
            if size < CPU_WORD_SIZE:
                data += bytes[:size]   # <-- FIXME: Big endian!
                break
            data += bytes

            # Move cursor
            size -= CPU_WORD_SIZE
            address += CPU_WORD_SIZE
        return data
Beispiel #2
0
    def _readBytes(self, address, size):
        debug("Read %s bytes at %s" % (size, formatAddress(address)))

        offset = address % CPU_WORD_SIZE
        if offset:
            # Read word
            address -= offset
            word = self.readWord(address)
            bytes = word2bytes(word)

            # Read some bytes from the word
            subsize = min(CPU_WORD_SIZE - offset, size)
            data = bytes[offset:offset + subsize]  # <-- FIXME: Big endian!

            # Move cursor
            size -= subsize
            address += CPU_WORD_SIZE
        else:
            data = ''

        while size:
            # Read word
            word = self.readWord(address)
            bytes = word2bytes(word)

            # Read bytes from the word
            if size < CPU_WORD_SIZE:
                data += bytes[:size]  # <-- FIXME: Big endian!
                break
            data += bytes

            # Move cursor
            size -= CPU_WORD_SIZE
            address += CPU_WORD_SIZE
        return data
Beispiel #3
0
 def getregs(self):
     error("Read registers using ptrace_peekuser()")
     words = []
     nb_words = sizeof(ptrace_registers_t) // CPU_WORD_SIZE
     for offset in xrange(nb_words):
         word = ptrace_peekuser(self.pid, offset * CPU_WORD_SIZE)
         bytes = word2bytes(word)
         words.append(bytes)
     bytes = ''.join(words)
     return cast(bytes, POINTER(ptrace_registers_t))[0]
Beispiel #4
0
 def getregs(self):
     error("Read registers using ptrace_peekuser()")
     words = []
     nb_words = sizeof(ptrace_registers_t) // CPU_WORD_SIZE
     for offset in xrange(nb_words):
         word = ptrace_peekuser(self.pid, offset*CPU_WORD_SIZE)
         bytes = word2bytes(word)
         words.append(bytes)
     bytes = ''.join(words)
     return cast(bytes, POINTER(ptrace_registers_t))[0]
 def getregs(self):
     if HAS_PTRACE_GETREGS or HAS_PTRACE_GETREGSET:
         return ptrace_getregs(self.pid)
     # FIXME: Optimize getreg() when used with this function
     words = []
     nb_words = sizeof(ptrace_registers_t) // CPU_WORD_SIZE
     for offset in range(nb_words):
         word = ptrace_peekuser(self.pid, offset * CPU_WORD_SIZE)
         bytes = word2bytes(word)
         words.append(bytes)
     bytes = ''.join(words)
     return bytes2type(bytes, ptrace_registers_t)
Beispiel #6
0
 def getregs(self):
     if HAS_PTRACE_GETREGS:
         return ptrace_getregs(self.pid)
     else:
         # FIXME: Optimize getreg() when used with this function
         words = []
         nb_words = sizeof(ptrace_registers_t) // CPU_WORD_SIZE
         for offset in range(nb_words):
             word = ptrace_peekuser(self.pid, offset * CPU_WORD_SIZE)
             bytes = word2bytes(word)
             words.append(bytes)
         bytes = ''.join(words)
         return bytes2type(bytes, ptrace_registers_t)
Beispiel #7
0
    def __init__(self, process, address, size=None):
        self._installed = False
        self.process = ref(process)
        self.address = address
        if CPU_POWERPC:
            size = CPU_WORD_SIZE
        elif size is None:
            size = 1
        self.size = size

        # Store instruction bytes
        info("Install %s" % self)
        self.old_bytes = process.readBytes(address, size)

        if CPU_POWERPC:
            # Replace instruction with "TRAP"
            new_bytes = word2bytes(0x0cc00000)
        else:
            # Replace instruction with "INT 3"
            new_bytes = b("\xCC") * size
        process.writeBytes(address, new_bytes)
        self._installed = True
Beispiel #8
0
def getPointers(process, address):
    address = word2bytes(address)
    procmaps = readProcessMappings(process)
    for pm in procmaps:
        for found in pm.search(address):
            yield found
Beispiel #9
0
def getPointers(process, address):
    address = word2bytes(address)
    procmaps = readProcessMappings(process)
    for pm in procmaps:
        for found in pm.search(address):
            yield found