From b036575589d43d73f8840a65633975e43a0961c2 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Wed, 31 Mar 2021 12:37:13 +0200 Subject: [PATCH] feature(radare2): add argument to set base when loading for PIE (#897) * feature(radare2): add alias radare2 to r2 command * feature(radare2): add argument to set base when loading for PIE Depending on the use case, one may want to have either the same addresses for PIE as in gdb or just use the non rebased plain addresses without taking the current memory mapping into account. * fix(radare2): fix relocations in disassembly warning by enabling io.cache --- pwndbg/commands/radare2.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pwndbg/commands/radare2.py b/pwndbg/commands/radare2.py index 9a94743a9..efb4cf9e1 100644 --- a/pwndbg/commands/radare2.py +++ b/pwndbg/commands/radare2.py @@ -10,23 +10,30 @@ parser = argparse.ArgumentParser(description='Launches radare2', epilog="Example: r2 -- -S -AA") parser.add_argument('--no-seek', action='store_true', help='Do not seek to current pc') +parser.add_argument('--no-rebase', action='store_true', + help='Do not set the base address for PIE according to the current mapping') parser.add_argument('arguments', nargs='*', type=str, help='Arguments to pass to radare') -@pwndbg.commands.ArgparsedCommand(parser) +@pwndbg.commands.ArgparsedCommand(parser, aliases=['radare2']) @pwndbg.commands.OnlyWithFile -def r2(arguments, no_seek=False): +def r2(arguments, no_seek=False, no_rebase=False): filename = pwndbg.file.get_file(pwndbg.proc.exe) # Build up the command line to run cmd = ['radare2'] + flags = ['-e', 'io.cache=true'] if pwndbg.proc.alive: addr = pwndbg.regs.pc if pwndbg.elf.get_elf_info(filename).is_pie: - addr -= pwndbg.elf.exe().address + if no_rebase: + addr -= pwndbg.elf.exe().address + else: + flags.extend(['-B', hex(pwndbg.elf.exe().address)]) if not no_seek: cmd.extend(['-s', hex(addr)]) + cmd.extend(flags) cmd += arguments cmd.extend([filename])