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
pull/899/head
Levente Polyak 5 years ago committed by GitHub
parent cd3cbf3d45
commit b036575589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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:
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])

Loading…
Cancel
Save