From a5c9738eec2915fc8d2f287c16ac54911ab83c35 Mon Sep 17 00:00:00 2001 From: anthraxx Date: Wed, 31 Mar 2021 02:25:37 +0200 Subject: [PATCH] feature(radare2): add r2pipe command to execute stateful radare2 cmds This can be a useful command to quickly execute some radare2 operations in various positions in mid of a debugging session without the need to shell out and temporarily transfer process control to radare2. --- pwndbg/commands/radare2.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pwndbg/commands/radare2.py b/pwndbg/commands/radare2.py index efb4cf9e1..b842968de 100644 --- a/pwndbg/commands/radare2.py +++ b/pwndbg/commands/radare2.py @@ -4,7 +4,9 @@ import argparse import subprocess +import pwndbg.color.message as message import pwndbg.commands +import pwndbg.radare2 parser = argparse.ArgumentParser(description='Launches radare2', epilog="Example: r2 -- -S -AA") @@ -41,3 +43,21 @@ def r2(arguments, no_seek=False, no_rebase=False): subprocess.call(cmd) except Exception: print("Could not run radare2. Please ensure it's installed and in $PATH.") + + +parser = argparse.ArgumentParser(description='Execute stateful radare2 commands through r2pipe', + epilog="Example: r2pipe pdf sym.main") +parser.add_argument('arguments', nargs='+', type=str, + help='Arguments to pass to r2pipe') + + +@pwndbg.commands.ArgparsedCommand(parser) +@pwndbg.commands.OnlyWithFile +def r2pipe(arguments): + try: + r2 = pwndbg.radare2.r2pipe() + print(r2.cmd(' '.join(arguments))) + except ImportError: + print(message.error("Could not import r2pipe python library")) + except Exception as e: + print(message.error(e))