From de352771c096f2cf375222f5514b7d3cd4e536af Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Wed, 22 Mar 2017 17:00:17 +0100 Subject: [PATCH] adding simple r2 (radare) command with auto-seek to $pc (#188) It's quite handy to drop into radare2 in the middle of a deep debugging session to fire up the visual mode and examine the current location in gdb using the ascii graph view (or something else) in radare2. --- pwndbg/__init__.py | 1 + pwndbg/commands/radare2.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 pwndbg/commands/radare2.py diff --git a/pwndbg/__init__.py b/pwndbg/__init__.py index 6608cc078..df20711ac 100755 --- a/pwndbg/__init__.py +++ b/pwndbg/__init__.py @@ -33,6 +33,7 @@ import pwndbg.commands.misc import pwndbg.commands.next import pwndbg.commands.peda import pwndbg.commands.procinfo +import pwndbg.commands.radare2 import pwndbg.commands.reload import pwndbg.commands.rop import pwndbg.commands.ropper diff --git a/pwndbg/commands/radare2.py b/pwndbg/commands/radare2.py new file mode 100644 index 000000000..41f2843a5 --- /dev/null +++ b/pwndbg/commands/radare2.py @@ -0,0 +1,37 @@ +#!/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 argparse +import subprocess + +import pwndbg.commands + +parser = argparse.ArgumentParser(description=".", + epilog="Example: r2 -- -S -AA") +parser.add_argument('--no-seek', action='store_true', + help='Do not seek to current pc') +parser.add_argument('arguments', nargs='*', type=str, + help='Arguments to pass to radare') + +@pwndbg.commands.ArgparsedCommand(parser) +def r2(arguments, no_seek=False): + filename = pwndbg.file.get_file(pwndbg.proc.exe) + + if not filename: + print('No file is selected') + return + + # Build up the command line to run + cmd = ['radare2', filename] + if not no_seek and pwndbg.proc.alive: + cmd.extend(['-s', hex(pwndbg.regs.pc)]) + cmd += arguments + + try: + subprocess.call(cmd) + except Exception: + print("Could not run radare2. Please ensure it's installed and in $PATH.")