示例#1
0
    def hexdump(self, command):
        max_line = 20
        width = (terminalWidth() - len(formatAddress(1)) - 3) // 4
        width = max(width, 1)

        limited = None
        parts = command.split(" ", 1)
        if 1 < len(parts):
            try:
                start_address = self.parseInteger(parts[0])
                end_address = self.parseInteger(parts[1])
                if end_address <= start_address:
                    raise ValueError('End address (%s) is smaller than start address(%s)!'
                                     % (formatAddress(end_address), formatAddress(start_address)))
            except ValueError as err:
                return str(err)
            size = end_address - start_address
            max_size = width * max_line
            if max_size < size:
                limited = max_size
                end_address = start_address + max_size
        else:
            try:
                start_address = self.parseInteger(command)
            except ValueError as err:
                return str(err)
            end_address = start_address + 5 * width

        read_error = None
        address = start_address
        while address < end_address:
            size = min(end_address - address, width)
            try:
                # Read bytes
                memory = self.process.readBytes(address, size)

                # Format bytes
                hexa = formatHexa(memory)
                hexa = hexa.ljust(width * 3 - 1, ' ')

                ascii = formatAscii(memory)
                ascii = ascii.ljust(width, ' ')

                # Display previous read error, if any
                if read_error:
                    warning("Warning: Unable to read memory %s" % (
                        formatAddressRange(*read_error)))
                    read_error = None

                # Display line
                error("%s| %s| %s" % (formatAddress(address), hexa, ascii))
            except PtraceError:
                if not read_error:
                    read_error = [address, address + size]
                else:
                    read_error[1] = address + size
            address += size

        # Display last read error, if any
        if read_error:
            warning("Warning: Unable to read memory %s" % (
                formatAddressRange(*read_error)))
        if limited:
            warning("(limit to %s bytes)" % max_size)
        return None
示例#2
0
文件: gdb.py 项目: tjmaas/cs373-idb
    def hexdump(self, command):
        max_line = 20
        width = (terminalWidth() - len(formatAddress(1)) - 3) // 4
        width = max(width, 1)

        limited = None
        parts = command.split(" ", 1)
        if 1 < len(parts):
            try:
                start_address = self.parseInteger(parts[0])
                end_address = self.parseInteger(parts[1])
                if end_address <= start_address:
                    raise ValueError('End address (%s) is smaller than start address(%s)!'
                        % (formatAddress(end_address), formatAddress(start_address)))
            except ValueError as err:
                return str(err)
            size = end_address - start_address
            max_size = width*max_line
            if max_size < size:
                limited = max_size
                end_address = start_address + max_size
        else:
            try:
                start_address = self.parseInteger(command)
            except ValueError as err:
                return str(err)
            end_address = start_address + 5*width

        read_error = None
        address = start_address
        while address < end_address:
            size = min(end_address - address, width)
            try:
                # Read bytes
                memory = self.process.readBytes(address, size)

                # Format bytes
                hexa = formatHexa(memory)
                hexa = hexa.ljust(width*3-1, ' ')

                ascii = formatAscii(memory)
                ascii = ascii.ljust(width, ' ')

                # Display previous read error, if any
                if read_error:
                    warning("Warning: Unable to read memory %s" % (
                        formatAddressRange(*read_error)))
                    read_error = None

                # Display line
                error("%s| %s| %s" % (formatAddress(address), hexa, ascii))
            except PtraceError:
                if not read_error:
                    read_error = [address, address + size]
                else:
                    read_error[1] = address + size
            address += size

        # Display last read error, if any
        if read_error:
            warning("Warning: Unable to read memory %s" % (
                formatAddressRange(*read_error)))
        if limited:
            warning("(limit to %s bytes)" % max_size)
        return None