From 44770fd71f9fed1a3ee02ff446b1aec62feffd9b Mon Sep 17 00:00:00 2001 From: anthraxx Date: Tue, 30 Mar 2021 22:27:34 +0200 Subject: [PATCH] fix(ghidra): handle PIE base address when opening the r2pipe If we are trying to decompile a running binary which is a PIE, we need to make sure to pass the appropriate base address to radare2 to be used when loading a new binary. Furthermore set io.cache to fix relocations in disassembly and avoid a warning from the r2pipe. --- pwndbg/radare2.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pwndbg/radare2.py b/pwndbg/radare2.py index 91e6fbeae..ae51f668b 100644 --- a/pwndbg/radare2.py +++ b/pwndbg/radare2.py @@ -1,3 +1,5 @@ +import pwndbg.elf + radare2 = {} @@ -6,7 +8,10 @@ def r2pipe(filename): if r2: return r2 import r2pipe - r2 = r2pipe.open(filename) + flags = ['-e', 'io.cache=true'] + if pwndbg.elf.get_elf_info(filename).is_pie and pwndbg.elf.exe(): + flags.extend(['-B', hex(pwndbg.elf.exe().address)]) + r2 = r2pipe.open(filename, flags=flags) radare2[filename] = r2 r2.cmd("aaaa") return r2