From 8f6587395d16be48c238d5f8af63575957e6d37f Mon Sep 17 00:00:00 2001 From: Zach Riggle Date: Sat, 9 Apr 2016 13:03:28 -0700 Subject: [PATCH] Add more Windbg compat --- pwndbg/commands/__init__.py | 21 ++++++++--- pwndbg/commands/shell.py | 2 +- pwndbg/commands/vmmap.py | 4 ++- pwndbg/commands/windbg.py | 72 +++++++++++++++++++++++++++++++++++-- pwndbg/symbol.py | 2 +- 5 files changed, 91 insertions(+), 10 deletions(-) diff --git a/pwndbg/commands/__init__.py b/pwndbg/commands/__init__.py index fa9d6d32e..c91844920 100644 --- a/pwndbg/commands/__init__.py +++ b/pwndbg/commands/__init__.py @@ -24,8 +24,8 @@ class _Command(gdb.Command): count = 0 commands = [] - def __init__(self, function, inc=True): - super(_Command, self).__init__(function.__name__, gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION) + def __init__(self, function, inc=True, prefix=False): + super(_Command, self).__init__(function.__name__, gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION, prefix=prefix) self.function = function if inc: @@ -40,15 +40,20 @@ class _Command(gdb.Command): def invoke(self, argument, from_tty): argv = self.split_args(argument) try: - return self.function(*argv) + return self(*argv) except TypeError: if debug: print(traceback.format_exc()) raise def __call__(self, *args, **kwargs): - with pwndbg.stdio.stdio: - return self.function(*args, **kwargs) + try: + with pwndbg.stdio.stdio: + return self.function(*args, **kwargs) + except TypeError as te: + print(te) + print('%r: %s' % (self.function.__name__.strip(), + self.function.__doc__.strip())) class _ParsedCommand(_Command): @@ -67,8 +72,14 @@ class _ParsedCommand(_Command): def fix(self, arg): return fix(arg, self.sloppy, self.quiet) +class _ParsedCommandPrefix(_ParsedCommand): + def __init__(self, function, inc=True, prefix=True): + super(_ParsedCommand, self).__init__(function, inc, prefix) def fix(arg, sloppy=False, quiet=False): + if isinstance(arg, gdb.Value): + return arg + try: parsed = gdb.parse_and_eval(arg) return parsed diff --git a/pwndbg/commands/shell.py b/pwndbg/commands/shell.py index 35375e5b7..c02ce4491 100644 --- a/pwndbg/commands/shell.py +++ b/pwndbg/commands/shell.py @@ -27,7 +27,7 @@ shellcmds = [ # "kill", # "killall", "less", - "ln", + # "ln", "ls", "man", "mkdir", diff --git a/pwndbg/commands/vmmap.py b/pwndbg/commands/vmmap.py index 69ef0d378..4b1a8db2d 100644 --- a/pwndbg/commands/vmmap.py +++ b/pwndbg/commands/vmmap.py @@ -14,8 +14,10 @@ import pwndbg.vmmap @pwndbg.commands.QuietSloppyParsedCommand def vmmap(map=None): """ - Print the virtal memory map + Print the virtal memory map, or the specific mapping for the + provided address / module name. """ + print(repr(map)) int_map = None str_map = None diff --git a/pwndbg/commands/windbg.py b/pwndbg/commands/windbg.py index f50ee97a6..7b495068b 100644 --- a/pwndbg/commands/windbg.py +++ b/pwndbg/commands/windbg.py @@ -12,6 +12,7 @@ import pwndbg.arch import pwndbg.commands import pwndbg.memory import pwndbg.strings +import pwndbg.symbol import pwndbg.typeinfo @@ -179,6 +180,14 @@ def dds(*a): """ return pwndbg.commands.telescope.telescope(*a) +@pwndbg.commands.ParsedCommand +@pwndbg.commands.OnlyWhenRunning +def kd(*a): + """ + Dump pointers and symbols at the specified address. + """ + return pwndbg.commands.telescope.telescope(*a) + @pwndbg.commands.ParsedCommand @pwndbg.commands.OnlyWhenRunning def dps(*a): @@ -251,9 +260,11 @@ def bc(which = '*'): @pwndbg.commands.OnlyWhenRunning def bp(where): """ - Set a breakpoint + Set a breakpoint at the specified address. """ - gdb.execute('break *%#x' % int(where)) + result = pwndbg.commands.fix(where) + if result is not None: + gdb.execute('break *%#x' % int(result)) @pwndbg.commands.ParsedCommand @pwndbg.commands.OnlyWhenRunning @@ -274,3 +285,60 @@ def k(): Print a backtrace (alias 'bt') """ gdb.execute('bt') + +@pwndbg.commands.ParsedCommand +@pwndbg.commands.OnlyWhenRunning +def ln(value=None): + """ + List the symbols nearest to the provided value. + """ + if value is None: value = pwndbg.regs.pc + x = pwndbg.symbol.get(value) + if x: + result = '(%#x) %s' % (value, x) + +@pwndbg.commands.OnlyWhenRunning +@pwndbg.commands.QuietSloppyParsedCommand +def lm(map): + """ + Windbg compatibility alias for 'vmmap' command. + """ + return pwndbg.commands.vmmap.vmmap(map) + +@pwndbg.commands.OnlyWhenRunning +@pwndbg.commands.QuietSloppyParsedCommand +def address(map): + """ + Windbg compatibility alias for 'vmmap' command. + """ + return pwndbg.commands.vmmap.vmmap(map) + + +@pwndbg.commands.OnlyWhenRunning +@pwndbg.commands.QuietSloppyParsedCommand +def vprot(map): + """ + Windbg compatibility alias for 'vmmap' command. + """ + return pwndbg.commands.vmmap.vmmap(map) + +@pwndbg.commands.Command +@pwndbg.commands.OnlyWhenRunning +def peb(*a): + print("This isn't Windows!") + +@pwndbg.commands.Command +@pwndbg.commands.OnlyWhenRunning +def go(): + ''' + Windbg compatibility alias for 'continue' command. + ''' + gdb.execute('continue') + +@pwndbg.commands.Command +@pwndbg.commands.OnlyWhenRunning +def pc(): + ''' + Windbg compatibility alias for 'nextcall' command. + ''' + return pwndbg.commands.next.nextcall() diff --git a/pwndbg/symbol.py b/pwndbg/symbol.py index 037af0853..58372aad6 100644 --- a/pwndbg/symbol.py +++ b/pwndbg/symbol.py @@ -115,7 +115,7 @@ def get(address, gdb_only=False): Retrieve the textual name for a symbol """ # Fast path - if address < pwndbg.memory.MMAP_MIN_ADDR or address >= (1 << 64): + if address < pwndbg.memory.MMAP_MIN_ADDR or address >= ((1 << 64)-1): return '' # Don't look up stack addresses