Exemple #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
Exemple #2
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
Exemple #3
0
 def readCString(self, address, max_size, chunk_length=256):
     string = []
     size = 0
     truncated = False
     while True:
         done = False
         data = self.readBytes(address, chunk_length)
         pos = data.find(b('\0'))
         if pos != -1:
             done = True
             data = data[:pos]
         if max_size <= size + chunk_length:
             data = data[:(max_size - size)]
             string.append(data)
             truncated = True
             break
         string.append(data)
         if done:
             break
         size += chunk_length
         address += chunk_length
     return b''.join(string), truncated
Exemple #4
0
 def readCString(self, address, max_size, chunk_length=256):
     string = []
     size = 0
     truncated = False
     while True:
         done = False
         data = self.readBytes(address, chunk_length)
         pos = data.find(b('\0'))
         if pos != -1:
             done = True
             data = data[:pos]
         if max_size <= size + chunk_length:
             data = data[:(max_size - size)]
             string.append(data)
             truncated = True
             break
         string.append(data)
         if done:
             break
         size += chunk_length
         address += chunk_length
     return b''.join(string), truncated
Exemple #5
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