Skip to content

Commit

Permalink
feature(radare2): add argument to set base when loading for PIE (Gall…
Browse files Browse the repository at this point in the history
…opsled#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
  • Loading branch information
anthraxx authored Mar 31, 2021
1 parent cd3cbf3 commit b036575
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pwndbg/commands/radare2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@
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])

Expand Down

0 comments on commit b036575

Please sign in to comment.