if hard_stop is not None and address == hard_stop: result.append(hard_end) break result.append(address) try: address = int( pwndbg.memory.poi(pwndbg.typeinfo.ppvoid, address + offset)) address &= pwndbg.arch.ptrmask except gdb.MemoryError: break return result config_arrow_left = theme.Parameter('chain-arrow-left', '◂—', 'left arrow of chain formatting') config_arrow_right = theme.Parameter('chain-arrow-right', '—▸', 'right arrow of chain formatting') config_contiguous = theme.Parameter('chain-contiguous-marker', '...', 'contiguous marker of chain formatting') def format(value, limit=LIMIT, code=True, offset=0, hard_stop=None, hard_end=0): """ Recursively dereferences an address into string representation, or convert the list representation of address dereferences into string representation.
import fcntl import os import struct import sys import termios import pwndbg.arch import pwndbg.color.context as C from pwndbg import config from pwndbg.color import ljust_colored from pwndbg.color import message from pwndbg.color import rjust_colored from pwndbg.color import strip from pwndbg.color import theme theme.Parameter('banner-separator', '─', 'repeated banner separator character') theme.Parameter('banner-title-surrounding-left', '[ ', 'banner title surrounding char (left side)') theme.Parameter('banner-title-surrounding-right', ' ]', 'banner title surrounding char (right side)') title_position = theme.Parameter('banner-title-position', 'center', 'banner title position') @pwndbg.config.Trigger([title_position]) def check_title_position(): valid_values = ['center', 'left', 'right'] if title_position not in valid_values: print( message.warn('Invalid title position: %s, must be one of: %s' % (title_position, ', '.join(valid_values))))
import pwndbg.color.theme as theme import pwndbg.config as config from pwndbg.color import generateColorFunction config_prefix_color = theme.ColoredParameter('code-prefix-color', 'none', "color for 'context code' command (prefix marker)") config_highlight_color = theme.ColoredParameter('highlight-color', 'green,bold', 'color added to highlights like source/pc') config_register_color = theme.ColoredParameter('context-register-color', 'bold', 'color for registers label') config_flag_value_color = theme.ColoredParameter('context-flag-value-color', 'none', 'color for flags register (register value)') config_flag_bracket_color = theme.ColoredParameter('context-flag-bracket-color', 'none', 'color for flags register (bracket)') config_flag_set_color = theme.ColoredParameter('context-flag-set-color', 'green,bold', 'color for flags register (flag set)') config_flag_unset_color = theme.ColoredParameter('context-flag-unset-color', 'red', 'color for flags register (flag unset)') config_flag_changed_color = theme.ColoredParameter('context-flag-changed-color', 'underline', 'color for flags register (flag changed)') config_banner_color = theme.ColoredParameter('banner-color', 'blue', 'color for banner line') config_banner_title = theme.ColoredParameter('banner-title-color', 'none', 'color for banner title') config_register_changed_color = theme.ColoredParameter('context-register-changed-color', 'normal', 'color for registers label (change marker)') config_register_changed_marker = theme.Parameter('context-register-changed-marker', '*', 'change marker for registers label') config_comment = theme.ColoredParameter('comment-color', 'gray', 'color for comment') def prefix(x): return generateColorFunction(config.code_prefix_color)(x) def highlight(x): return generateColorFunction(config.highlight_color)(x) def register(x): return generateColorFunction(config.context_register_color)(x) def register_changed(x): return generateColorFunction(config.context_register_changed_color)(x) def flag_bracket(x):
telescope_lines = pwndbg.config.Parameter( "telescope-lines", 8, "number of lines to printed by the telescope command") skip_repeating_values = pwndbg.config.Parameter( "telescope-skip-repeating-val", True, "whether to skip repeating values of the telescope command", ) skip_repeating_values_minimum = pwndbg.config.Parameter( "telescope-skip-repeating-val-minimum", 3, "minimum amount of repeated values before skipping lines", ) offset_separator = theme.Parameter( "telescope-offset-separator", "│", "offset separator of the telescope command") offset_delimiter = theme.Parameter( "telescope-offset-delimiter", ":", "offset delimiter of the telescope command") repeating_marker = theme.Parameter( "telescope-repeating-marker", "... ↓", "repeating values marker of the telescope command") parser = argparse.ArgumentParser(description=""" Recursively dereferences pointers starting at the specified address ($sp by default) """) parser.add_argument("address", nargs="?", default=None,
def context_disasm(): banner = [pwndbg.ui.banner("DISASM" + pwndbg.arch.mode)] emulate = bool(pwndbg.config.emulate) result = pwndbg.commands.nearpc.nearpc(to_string=True, emulate=emulate, lines=code_lines // 2) # If we didn't disassemble backward, try to make sure # that the amount of screen space taken is roughly constant. while len(result) < code_lines + 1: result.append('') return banner + result theme.Parameter('highlight-source', True, 'whether to highlight the closest source line') def context_code(): try: symtab = gdb.selected_frame().find_sal().symtab linetable = symtab.linetable() closest_pc = -1 closest_line = -1 for line in linetable: if line.pc <= pwndbg.regs.pc and line.pc > closest_pc: closest_line = line.line closest_pc = line.pc if closest_line < 0:
banner = [pwndbg.ui.banner("disasm", target=target, width=width)] emulate = bool(pwndbg.config.emulate) result = pwndbg.commands.nearpc.nearpc(to_string=True, emulate=emulate, lines=code_lines // 2) # If we didn't disassemble backward, try to make sure # that the amount of screen space taken is roughly constant. while len(result) < code_lines + 1: result.append('') return banner + result if with_banner else result theme.Parameter('highlight-source', True, 'whether to highlight the closest source line') source_code_lines = pwndbg.config.Parameter( 'context-source-code-lines', 10, 'number of source code lines to print by the context command') theme.Parameter('code-prefix', '►', "prefix marker for 'context code' command") @pwndbg.memoize.reset_on_start def get_highlight_source(filename): # Notice that the code is cached with open(filename, encoding='utf-8') as f: source = f.read() if pwndbg.config.syntax_highlight: source = H.syntax_highlight(source, filename)
import pwndbg.config color_scheme = None printable = None def groupby(array, count, fill=None): array = copy.copy(array) while fill and len(array) % count: array.append(fill) for i in range(0, len(array), count): yield array[i:i + count] config_colorize_ascii = theme.Parameter( 'hexdump-colorize-ascii', True, 'whether to colorize the hexdump command ascii section') config_separator = theme.Parameter( 'hexdump-ascii-block-separator', '│', 'block separator char of the hexdump command') config_byte_separator = theme.Parameter( 'hexdump-byte-separator', ' ', 'separator of single bytes in hexdump (does NOT affect group separator)') @pwndbg.config.Trigger([ H.config_normal, H.config_zero, H.config_special, H.config_printable, config_colorize_ascii ]) def load_color_scheme(): global color_scheme, printable
config_zero = theme.ColoredParameter("hexdump-zero-color", "red", "color for hexdump command (zero bytes)") config_special = theme.ColoredParameter( "hexdump-special-color", "yellow", "color for hexdump command (special bytes)") config_offset = theme.ColoredParameter( "hexdump-offset-color", "none", "color for hexdump command (offset label)") config_address = theme.ColoredParameter( "hexdump-address-color", "none", "color for hexdump command (address label)") config_separator = theme.ColoredParameter( "hexdump-separator-color", "none", "color for hexdump command (group separator)") config_highlight_group_lsb = theme.Parameter( "hexdump-highlight-group-lsb", "underline", "highlight LSB of each group. Applies only if hexdump-adjust-group-endianess" " actually changes byte order.", ) def normal(x): return generateColorFunction(config.hexdump_normal_color)(x) def printable(x): return generateColorFunction(config.hexdump_printable_color)(x) def zero(x): return generateColorFunction(config.hexdump_zero_color)(x)
import pwndbg.color.hexdump as H import pwndbg.color.theme as theme import pwndbg.config color_scheme = None printable = None def groupby(array, count, fill=None): array = copy.copy(array) while fill and len(array) % count: array.append(fill) for i in range(0, len(array), count): yield array[i:i+count] config_colorize_ascii = theme.Parameter('hexdump-colorize-ascii', True, 'whether to colorize the hexdump command ascii section') config_separator = theme.Parameter('hexdump-ascii-block-separator', u'│', 'block separator char of the hexdump command') @pwndbg.config.Trigger([H.config_normal, H.config_zero, H.config_special, H.config_printable, config_colorize_ascii]) def load_color_scheme(): global color_scheme, printable # # We want to colorize the hex characters and only print out # printable values on the righ hand side. # color_scheme = {i:H.normal("%02x" % i) for i in range(256)} printable = {i:H.normal('.') for i in range(256)} for c in bytearray((string.ascii_letters + string.digits + string.punctuation).encode('utf-8', 'ignore')): color_scheme[c] = H.printable("%02x" % c) printable[c] = H.printable("%s" % chr(c)) if pwndbg.config.hexdump_colorize_ascii else "%s" % chr(c)
"context-flag-set-color", "green,bold", "color for flags register (flag set)") config_flag_unset_color = theme.ColoredParameter( "context-flag-unset-color", "red", "color for flags register (flag unset)") config_flag_changed_color = theme.ColoredParameter( "context-flag-changed-color", "underline", "color for flags register (flag changed)") config_banner_color = theme.ColoredParameter("banner-color", "blue", "color for banner line") config_banner_title = theme.ColoredParameter("banner-title-color", "none", "color for banner title") config_register_changed_color = theme.ColoredParameter( "context-register-changed-color", "normal", "color for registers label (change marker)") config_register_changed_marker = theme.Parameter( "context-register-changed-marker", "*", "change marker for registers label") config_comment = theme.ColoredParameter("comment-color", "gray", "color for comment") def prefix(x): return generateColorFunction(config.code_prefix_color)(x) def highlight(x): return generateColorFunction(config.highlight_color)(x) def register(x): return generateColorFunction(config.context_register_color)(x)
from pwndbg.color import message from pwndbg.color import theme try: import pygments import pygments.formatters import pygments.lexers from pwndbg.color.lexer import PwntoolsLexer except ImportError: pygments = None pwndbg.config.Parameter("syntax-highlight", True, "Source code / assembly syntax highlight") style = theme.Parameter( "syntax-highlight-style", "monokai", "Source code / assembly syntax highlight stylename of pygments module", ) formatter = pygments.formatters.Terminal256Formatter(style=str(style)) pwntools_lexer = PwntoolsLexer() lexer_cache = {} @pwndbg.config.Trigger([style]) def check_style(): global formatter try: formatter = pygments.formatters.Terminal256Formatter(style=str(style)) # Reset the highlighted source cache
'color for hexdump command (printable characters)') config_zero = theme.ColoredParameter('hexdump-zero-color', 'red', 'color for hexdump command (zero bytes)') config_special = theme.ColoredParameter( 'hexdump-special-color', 'yellow', 'color for hexdump command (special bytes)') config_offset = theme.ColoredParameter( 'hexdump-offset-color', 'none', 'color for hexdump command (offset label)') config_address = theme.ColoredParameter( 'hexdump-address-color', 'none', 'color for hexdump command (address label)') config_separator = theme.ColoredParameter( 'hexdump-separator-color', 'none', 'color for hexdump command (group separator)') config_highlight_group_lsb = theme.Parameter( 'hexdump-highlight-group-lsb', 'underline', 'highlight LSB of each group. Applies only if hexdump-adjust-group-endianess' ' actually changes byte order.') def normal(x): return generateColorFunction(config.hexdump_normal_color)(x) def printable(x): return generateColorFunction(config.hexdump_printable_color)(x) def zero(x): return generateColorFunction(config.hexdump_zero_color)(x)
import fcntl import os import struct import sys import termios import pwndbg.arch import pwndbg.color.context as C from pwndbg import config from pwndbg.color import ljust_colored from pwndbg.color import message from pwndbg.color import rjust_colored from pwndbg.color import strip from pwndbg.color import theme theme.Parameter("banner-separator", "─", "repeated banner separator character") theme.Parameter("banner-title-surrounding-left", "[ ", "banner title surrounding char (left side)") theme.Parameter( "banner-title-surrounding-right", " ]", "banner title surrounding char (right side)" ) title_position = theme.Parameter("banner-title-position", "center", "banner title position") @pwndbg.config.Trigger([title_position]) def check_title_position(): valid_values = ["center", "left", "right"] if title_position not in valid_values: print( message.warn( "Invalid title position: %s, must be one of: %s" % (title_position, ", ".join(valid_values))
import pwndbg.color.theme as theme import pwndbg.config as config from pwndbg.color import generateColorFunction config_prefix = theme.Parameter("backtrace-prefix", "►", "prefix for current backtrace label") config_prefix_color = theme.ColoredParameter( "backtrace-prefix-color", "none", "color for prefix of current backtrace label") config_address_color = theme.ColoredParameter("backtrace-address-color", "none", "color for backtrace (address)") config_symbol_color = theme.ColoredParameter("backtrace-symbol-color", "none", "color for backtrace (symbol)") config_label_color = theme.ColoredParameter( "backtrace-frame-label-color", "none", "color for backtrace (frame label)") def prefix(x): return generateColorFunction(config.backtrace_prefix_color)(x) def address(x): return generateColorFunction(config.backtrace_address_color)(x) def symbol(x): return generateColorFunction(config.backtrace_symbol_color)(x) def frame_label(x):
import pwndbg.arch import pwndbg.chain import pwndbg.color.telescope as T import pwndbg.color.theme as theme import pwndbg.commands import pwndbg.config import pwndbg.memory import pwndbg.regs import pwndbg.typeinfo telescope_lines = pwndbg.config.Parameter( 'telescope-lines', 8, 'number of lines to printed by the telescope command') offset_separator = theme.Parameter( 'telescope-offset-separator', u'│', 'offset separator of the telescope command') offset_delimiter = theme.Parameter( 'telescope-offset-delimiter', ':', 'offset delimiter of the telescope command') repeating_maker = theme.Parameter( 'telescope-repeating-marker', u'... ↓', 'repeating values marker of the telescope command') @pwndbg.commands.ParsedCommand @pwndbg.commands.OnlyWhenRunning def telescope(address=None, count=telescope_lines, to_string=False): """ Recursively dereferences pointers starting at the specified address ($sp by default)
from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import fcntl import struct import sys import termios import pwndbg.arch import pwndbg.color.context as C import pwndbg.color.theme as theme import pwndbg.config as config theme.Parameter('banner-separator', '─', 'repeated banner separator character') def banner(title): title = title.upper() try: _height, width = struct.unpack( 'hh', fcntl.ioctl(sys.stdin.fileno(), termios.TIOCGWINSZ, '1234')) except: width = 80 width -= 2 return C.banner( ("[{:%s^%ss}]" % (config.banner_separator, width)).format(title)) def addrsz(address):
#!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import pwndbg.color.theme as theme import pwndbg.config as config from pwndbg.color import generateColorFunction config_prefix = theme.Parameter('backtrace-prefix', '►', 'prefix for current backtrace label') config_prefix_color = theme.ColoredParameter( 'backtrace-prefix-color', 'none', 'color for prefix of current backtrace label') config_address_color = theme.ColoredParameter('backtrace-address-color', 'none', 'color for backtrace (address)') config_symbol_color = theme.ColoredParameter('backtrace-symbol-color', 'none', 'color for backtrace (symbol)') config_label_color = theme.ColoredParameter( 'backtrace-frame-label-color', 'none', 'color for backtrace (frame label)') def prefix(x): return generateColorFunction(config.backtrace_prefix_color)(x) def address(x): return generateColorFunction(config.backtrace_address_color)(x)
import pwndbg.config color_scheme = None printable = None def groupby(array, count, fill=None): array = copy.copy(array) while fill and len(array) % count: array.append(fill) for i in range(0, len(array), count): yield array[i:i + count] config_colorize_ascii = theme.Parameter( "hexdump-colorize-ascii", True, "whether to colorize the hexdump command ascii section") config_separator = theme.Parameter( "hexdump-ascii-block-separator", "│", "block separator char of the hexdump command") config_byte_separator = theme.Parameter( "hexdump-byte-separator", " ", "separator of single bytes in hexdump (does NOT affect group separator)", ) @pwndbg.config.Trigger([ H.config_normal, H.config_zero, H.config_special, H.config_printable, config_colorize_ascii ])
from pwndbg.color import disable_colors from pwndbg.color import message from pwndbg.color import theme try: import pygments import pygments.lexers import pygments.formatters from pwndbg.color.lexer import PwntoolsLexer except ImportError: pygments = None pwndbg.config.Parameter('syntax-highlight', True, 'Source code / assembly syntax highlight') style = theme.Parameter( 'syntax-highlight-style', 'monokai', 'Source code / assembly syntax highlight stylename of pygments module') formatter = pygments.formatters.Terminal256Formatter(style=str(style)) pwntools_lexer = PwntoolsLexer() lexer_cache = {} @pwndbg.config.Trigger([style]) def check_style(): global formatter try: formatter = pygments.formatters.Terminal256Formatter(style=str(style)) # Reset the highlighted source cache from pwndbg.commands.context import get_highlight_source
banner = [pwndbg.ui.banner("disasm", target=target, width=width)] emulate = bool(pwndbg.config.emulate) result = pwndbg.commands.nearpc.nearpc(to_string=True, emulate=emulate, lines=code_lines // 2) # If we didn't disassemble backward, try to make sure # that the amount of screen space taken is roughly constant. while len(result) < code_lines + 1: result.append("") return banner + result if with_banner else result theme.Parameter("highlight-source", True, "whether to highlight the closest source line") source_code_lines = pwndbg.config.Parameter( "context-source-code-lines", 10, "number of source code lines to print by the context command") theme.Parameter("code-prefix", "►", "prefix marker for 'context code' command") @pwndbg.memoize.reset_on_start def get_highlight_source(filename): # Notice that the code is cached with open(filename, encoding="utf-8", errors="ignore") as f: source = f.read() if pwndbg.config.syntax_highlight: source = H.syntax_highlight(source, filename)