diff --git a/README.md b/README.md index a2737398a..3a581917b 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,18 @@ Best supported on Ubuntu 14.04 with default `gdb` or `gdb-multiarch` (e.g. with ## Installation -Pretty easy. - 1. Clone the repo: `git clone https://github.com/zachriggle/pwndbg` 2. Add to `~/.gdbinit`: `source ~/pwndbg/gdbinit.py` +### Prerequisites + +As of recent versions, you need Capstone 4.0. + +1. Clone the repo: `git clone https://github.com/aquynh/capstone` +2. Select the `next` branch: `git checkout -t origin/next` +3. Build and install libcapstone: `sudo make.sh install` +4. Build and install Python bindings: `cd bindings/python && python setup.py install` + ## Features Does most things that PEDA does. Doesn't do things that PEDA does that [pwntools](https://github.com/Gallopsled/pwntools) or [binjitsu](https://binjit.su) (my fork of pwntools) do better. diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py index ec0cdf633..9865e207e 100644 --- a/pwndbg/__init__.py +++ b/pwndbg/__init__.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- import gdb import pwndbg.arch import pwndbg.arguments @@ -97,3 +99,9 @@ for line in pre_commands.splitlines(): msg = "Loaded %i commands. Type pwndbg for a list." % len(pwndbg.commands._Command.commands) print(pwndbg.color.red(msg)) + +@pwndbg.memoize.reset_on_stop +def prompt_hook(*a): + pwndbg.commands.context.context() + +gdb.prompt_hook = prompt_hook diff --git a/pwndbg/commands/__init__.py b/pwndbg/commands/__init__.py index 47af2b14a..ffe2bf693 100644 --- a/pwndbg/commands/__init__.py +++ b/pwndbg/commands/__init__.py @@ -11,24 +11,7 @@ import pwndbg.enhance import pwndbg.symbol import pwndbg.ui -__all__ = [ -'asm', -'auxv', -'context', -'dt', -'hexdump', -'ida', -'nearpc', -'packing', -'reload', -'rop', -'search', -'shell', -'start', -'telescope', -'vmmap', -'windbg', -] + debug = True diff --git a/pwndbg/commands/rop.py b/pwndbg/commands/rop.py index aee9dd05e..32493c536 100644 --- a/pwndbg/commands/rop.py +++ b/pwndbg/commands/rop.py @@ -2,7 +2,7 @@ import os import gdb import pwndbg.commands - +import pwndbg.vmmap @pwndbg.commands.Command def rop(start=None, stop=None): @@ -14,6 +14,7 @@ def rop(start=None, stop=None): Searches executable mapped pages only. """ + # for page in pwndbg.vmmap.get() cmd = ['ROPgadget', '--rawArch=x86', '--rawMode=32', diff --git a/pwndbg/commands/start.py b/pwndbg/commands/start.py index d43593e7b..a648d9037 100644 --- a/pwndbg/commands/start.py +++ b/pwndbg/commands/start.py @@ -58,4 +58,4 @@ def entry(*a): global break_on_first_instruction break_on_first_instruction = True run = 'run ' + ' '.join(a) - gdb.execute(run, from_tty=False, to_string=True) + gdb.execute(run, from_tty=False) diff --git a/pwndbg/events.py b/pwndbg/events.py index cdcf03073..95f98ffa9 100644 --- a/pwndbg/events.py +++ b/pwndbg/events.py @@ -72,12 +72,12 @@ def connect(func, event_handler, name=''): def caller(*a): if debug: sys.stdout.write('%r %s.%s %r\n' % (name, func.__module__, func.__name__, a)) if pause: return - with pwndbg.stdio.stdio: - try: - func() - except Exception as e: - print(traceback.format_exc()) - raise e + # with pwndbg.stdio.stdio: + try: + func() + except Exception as e: + traceback.print_exc() + raise e registered[event_handler].append(caller) event_handler.connect(caller) diff --git a/pwndbg/ida.py b/pwndbg/ida.py index a2987d707..7f797af39 100644 --- a/pwndbg/ida.py +++ b/pwndbg/ida.py @@ -155,6 +155,7 @@ _breakpoints=[] @pwndbg.events.stop @withIDA def UpdateBreakpoints(): + # XXX: Remove breakpoints from IDA when the user removes them. current = set(eval(b.location.lstrip('*')) for b in _breakpoints) want = set(GetBreakpoints()) diff --git a/pwndbg/stdio.py b/pwndbg/stdio.py index 0da1e792c..ca05abfd8 100644 --- a/pwndbg/stdio.py +++ b/pwndbg/stdio.py @@ -3,19 +3,18 @@ Provides functionality to circumvent GDB's hooks on sys.stdin and sys.stdout which prevent output from appearing on-screen inside of certain event handlers. """ import io +import os import sys import gdb import pwndbg.compat def get(fd, mode): - file = io.open(1, mode=mode, buffering=0, closefd=False) - - kw = {} if pwndbg.compat.python3: - kw['write_through']=True - - return io.TextIOWrapper(file, **kw) + file = io.open(fd, mode=mode, buffering=0, closefd=False) + return io.TextIOWrapper(file, write_through=True, **kw) + else: + return os.fdopen(fd, mode, 0) stdin = get(0, 'rb') stdout = get(1, 'wb') diff --git a/pwndbg/symbol.py b/pwndbg/symbol.py index 1b1647ef9..87c6504b0 100644 --- a/pwndbg/symbol.py +++ b/pwndbg/symbol.py @@ -62,6 +62,11 @@ def address(symbol): if isinstance(symbol, (int,long)): return symbol + try: + return int(symbol, 0) + except: + pass + try: result = gdb.execute('info address %s' % symbol, to_string=True, from_tty=False) result = result.split()