diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py index 40b301c3a..afb2f5926 100755 --- a/pwndbg/__init__.py +++ b/pwndbg/__init__.py @@ -56,6 +56,7 @@ import pwndbg.inthook import pwndbg.memory import pwndbg.net import pwndbg.proc +import pwndbg.prompt import pwndbg.regs import pwndbg.stack import pwndbg.stdio @@ -130,27 +131,3 @@ handle SIGSEGV stop print nopass for line in pre_commands.strip().splitlines(): gdb.execute(line) - -msg = "Loaded %i commands. Type pwndbg [filter] for a list." % len(pwndbg.commands._Command.commands) -print(pwndbg.color.red(msg)) - -cur = (gdb.selected_inferior(), gdb.selected_thread()) - -def prompt_hook(*a): - global cur - new = (gdb.selected_inferior(), gdb.selected_thread()) - - if cur != new: - pwndbg.events.after_reload() - cur = new - - if pwndbg.proc.alive: - prompt_hook_on_stop(*a) - - -@pwndbg.memoize.reset_on_stop -def prompt_hook_on_stop(*a): - with pwndbg.stdio.stdio: - pwndbg.commands.context.context() - -gdb.prompt_hook = prompt_hook diff --git a/pwndbg/commands/ropper.py b/pwndbg/commands/ropper.py index 9a433ae23..3817bcbe3 100644 --- a/pwndbg/commands/ropper.py +++ b/pwndbg/commands/ropper.py @@ -41,5 +41,3 @@ def ropper(argument): io = subprocess.call(cmd) except Exception: print("Could not run ropper. Please ensure it's installed and in $PATH.") - - diff --git a/pwndbg/config.py b/pwndbg/config.py index 875a69917..d8ccf90b7 100644 --- a/pwndbg/config.py +++ b/pwndbg/config.py @@ -19,9 +19,9 @@ module, for example: """ from __future__ import unicode_literals +import collections import sys import types -import collections import six diff --git a/pwndbg/events.py b/pwndbg/events.py index ec41ab4c0..a186af83d 100644 --- a/pwndbg/events.py +++ b/pwndbg/events.py @@ -141,12 +141,12 @@ def log_objfiles(ofile=None): gdb.events.new_objfile.connect(log_objfiles) -def after_reload(): +def after_reload(start=True): if gdb.selected_inferior().pid: for f in registered[gdb.events.stop]: f() for f in registered[gdb.events.start]: - f() + if start: f() for f in registered[gdb.events.new_objfile]: f() diff --git a/pwndbg/prompt.py b/pwndbg/prompt.py new file mode 100644 index 000000000..89f6fdf2e --- /dev/null +++ b/pwndbg/prompt.py @@ -0,0 +1,27 @@ +import gdb +import pwndbg.events +import pwndbg.memoize +import pwndbg.stdio + +msg = "Loaded %i commands. Type pwndbg [filter] for a list." % len(pwndbg.commands._Command.commands) +print(pwndbg.color.red(msg)) + +cur = (gdb.selected_inferior(), gdb.selected_thread()) + +def prompt_hook(*a): + global cur + new = (gdb.selected_inferior(), gdb.selected_thread()) + + if cur != new: + pwndbg.events.after_reload(start=False) + cur = new + + if pwndbg.proc.alive: + prompt_hook_on_stop(*a) + +@pwndbg.memoize.reset_on_stop +def prompt_hook_on_stop(*a): + with pwndbg.stdio.stdio: + pwndbg.commands.context.context() + +gdb.prompt_hook = prompt_hook