Skip to content

Commit

Permalink
Fix memory watch to use new argparse syntax of hexdump cmd (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
theguy147 committed Jul 28, 2021
1 parent 48a9fd7 commit 880f8b8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
8 changes: 4 additions & 4 deletions docs/commands/hexdump.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ is printable (similarly to the `hexdump -C` command on Linux).
The syntax is as following:

```
hexdump [qword|dword|word|byte] [LOCATION] [[L][SIZE]] [REVERSE]
hexdump (qword|dword|word|byte) [LOCATION] [--size SIZE] [--reverse]
```

Examples:

* Display 4 QWORD from `$pc`:

```
gef➤ dq $pc l4
gef➤ dq $pc --size 4
0x7ffff7a5c1c0+0000 │ 0x4855544155415641
0x7ffff7a5c1c0+0008 │ 0x0090ec814853cd89
0x7ffff7a5c1c0+0010 │ 0x377d6f058b480000
Expand All @@ -40,14 +40,14 @@ gef➤ dq $pc l4
* Display 32 bytes from a location in the stack:

```
gef➤ db 0x00007fffffffe5e5 l32
gef➤ db 0x00007fffffffe5e5 --size 32
0x00007fffffffe5e5 2f 68 6f 6d 65 2f 68 75 67 73 79 2f 63 6f 64 65 /home/hugsy/code
0x00007fffffffe5f5 2f 67 65 66 2f 74 65 73 74 73 2f 77 69 6e 00 41 /gef/tests/win.A
```

* Display 8 WORD from `$sp` in reverse order:
```
gef➤ dw 8 r
gef➤ dw 8 --reverse
0x00007fffffffe0ee│+0x000e 0x0000
0x00007fffffffe0ec│+0x000c 0x7fff
0x00007fffffffe0ea│+0x000a 0xffff
Expand Down
8 changes: 4 additions & 4 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -8330,7 +8330,7 @@ def context_memory(self):
size=sz,
))
else:
gdb.execute("hexdump {fmt:s} 0x{address:x} {size:d}".format(
gdb.execute("hexdump {fmt:s} 0x{address:x} -s {size:d}".format(
address=address,
size=sz,
fmt=fmt,
Expand Down Expand Up @@ -8470,11 +8470,11 @@ def do_invoke(self, argv):

@register_command
class HexdumpCommand(GenericCommand):
"""Display SIZE lines of hexdump from the memory location pointed by ADDRESS."""
"""Display SIZE lines of hexdump from the memory location pointed by LOCATION."""

_cmdline_ = "hexdump"
_syntax_ = "{:s} [ADDRESS] [[L][SIZE]] [REVERSE]".format(_cmdline_)
_example_ = "{:s} byte $rsp L16 REVERSE".format(_cmdline_)
_syntax_ = "{:s} (qword|dword|word|byte) [LOCATION] [--size SIZE] [--reverse]".format(_cmdline_)
_example_ = "{:s} byte $rsp --size 16 --reverse".format(_cmdline_)

def __init__(self):
super().__init__(complete=gdb.COMPLETE_LOCATION, prefix=True)
Expand Down
32 changes: 31 additions & 1 deletion tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,36 @@ def test_cmd_hexdump(self):
self.assertNoException(res)
return

def test_cmd_memory_watch(self):
self.assertFailIfInactiveSession(gdb_run_cmd("memory watch $pc"))
res = gdb_start_silent_cmd("memory watch $pc 0x100 byte")
self.assertNoException(res)
res = gdb_start_silent_cmd("memory watch $pc 0x40 word")
self.assertNoException(res)
res = gdb_start_silent_cmd("memory watch $pc 0x30 dword")
self.assertNoException(res)
res = gdb_start_silent_cmd("memory watch $pc 0x20 qword")
self.assertNoException(res)
res = gdb_start_silent_cmd("memory watch $pc 0x8 pointers")
self.assertNoException(res)
res = gdb_start_silent_cmd("memory watch $pc")
self.assertNoException(res)

def test_cmd_memory_unwatch(self):
self.assertFailIfInactiveSession(gdb_run_cmd("memory unwatch $pc"))
res = gdb_start_silent_cmd("memory unwatch $pc")
self.assertNoException(res)

def test_cmd_memory_list(self):
self.assertFailIfInactiveSession(gdb_run_cmd("memory list"))
res = gdb_start_silent_cmd("memory list")
self.assertNoException(res)

def test_cmd_memory_reset(self):
self.assertFailIfInactiveSession(gdb_run_cmd("memory reset"))
res = gdb_start_silent_cmd("memory reset")
self.assertNoException(res)

def test_cmd_keystone_assemble(self):
valid_cmds = [
"assemble nop; xor eax, eax; syscall",
Expand Down Expand Up @@ -738,4 +768,4 @@ def run_tests():


if __name__ == "__main__":
run_tests()
run_tests()

0 comments on commit 880f8b8

Please sign in to comment.