Skip to content

Commit

Permalink
Allow hexdump by module name, like vmmap (Gallopsled#683)
Browse files Browse the repository at this point in the history
Implements Gallopsled#678
  • Loading branch information
korniltsev authored and disconnect3d committed Nov 3, 2019
1 parent 203f107 commit 57cc3c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/commands/procinfo/hexdump.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Command: hexdump ##
```
usage: hexdump [-h] [address] [count]
usage: hexdump [-h] [address_or_module] [count]
```
Hexdumps data at the specified address (or at $sp)

| Positional Argument | Info |
|---------------------|------|
| address | Address to dump (default: $sp) |
| address_or_module | Address or module name to dump (default: $sp) |
| count | Number of bytes to dump (default: 64) |

| Optional Argument | Info |
Expand Down
26 changes: 21 additions & 5 deletions pwndbg/commands/hexdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import argparse

import gdb
import six

import pwndbg.arch
import pwndbg.commands
Expand All @@ -23,17 +24,32 @@
64,
'number of bytes printed by hexdump command')

parser = argparse.ArgumentParser(description='Hexdumps data at the specified address (or at $sp)')
parser.add_argument('address', nargs='?', default='$sp',
help='Address to dump')
def address_or_module_name(s):
gdbval_or_str = pwndbg.commands.sloppy_gdb_parse(s)
if isinstance(gdbval_or_str, six.string_types):
module_name = gdbval_or_str
pages = list(filter(lambda page: module_name in page.objfile, pwndbg.vmmap.get()))
if pages:
return pages[0].vaddr
else:
raise argparse.ArgumentError('Could not find pages for module %s' % module_name)
elif isinstance(gdbval_or_str, six.integer_types + (gdb.Value,)):
addr = gdbval_or_str
return addr
else:
raise argparse.ArgumentTypeError('Unknown hexdump argument type.')

parser = argparse.ArgumentParser(description='Hexdumps data at the specified address or module name (or at $sp)')
parser.add_argument('address_or_module', type=address_or_module_name, nargs='?', default='$sp',
help='Address or module name to dump')
parser.add_argument('count', nargs='?', default=pwndbg.config.hexdump_bytes,
help='Number of bytes to dump')


@pwndbg.commands.ArgparsedCommand(parser)
@pwndbg.commands.OnlyWhenRunning
def hexdump(address=None, count=pwndbg.config.hexdump_bytes):

def hexdump(address_or_module=None, count=pwndbg.config.hexdump_bytes):
address = address_or_module
if hexdump.repeat:
address = hexdump.last_address
hexdump.offset += 1
Expand Down

0 comments on commit 57cc3c2

Please sign in to comment.