From 6a2ecce5122850a4c66e8ca4aa3c20dd08b4ad0f Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sat, 20 Apr 2024 16:07:58 +0100 Subject: [PATCH] Evaluate arguments passed to `vmmap` (#1085) ## Description Attempts to parse and eval an argument passed to `vmmap`. This makes `vmmap $rip`, for example, work. This is useful as it is easier to look up the memory section a pointer contained in a register/variable points to. It's also more consistent with commands like `dereference` --- docs/commands/vmmap.md | 4 ++++ gef.py | 4 ++++ tests/commands/vmmap.py | 3 +++ 3 files changed, 11 insertions(+) diff --git a/docs/commands/vmmap.md b/docs/commands/vmmap.md index 76e3bc868..73f20b36e 100644 --- a/docs/commands/vmmap.md +++ b/docs/commands/vmmap.md @@ -15,3 +15,7 @@ determine which section it belongs to. ![vmmap-grep](https://i.imgur.com/ZFF4QVf.png) ![vmmap-address](https://i.imgur.com/hfcs1jH.png) + +The address can be also be given in the form of a register or variable. + +![vmmap-register](https://i.imgur.com/RlZA6NU.png) diff --git a/gef.py b/gef.py index ec03cbe99..f99cf2841 100644 --- a/gef.py +++ b/gef.py @@ -8711,6 +8711,10 @@ def do_invoke(self, argv: List[str]) -> None: addr = int(argv[0], 0) if addr >= entry.page_start and addr < entry.page_end: self.print_entry(entry) + else: + addr = safe_parse_and_eval(argv[0]) + if addr is not None and addr >= entry.page_start and addr < entry.page_end: + self.print_entry(entry) return def print_entry(self, entry: Section) -> None: diff --git a/tests/commands/vmmap.py b/tests/commands/vmmap.py index 50dfeacaa..591d3b387 100644 --- a/tests/commands/vmmap.py +++ b/tests/commands/vmmap.py @@ -21,3 +21,6 @@ def test_cmd_vmmap(self): res = gdb.execute("vmmap stack", to_string=True) self.assertGreater(len(res.splitlines()), 1) + + res = gdb.execute("vmmap $rip", to_string=True) + self.assertEqual(len(res.splitlines()), 2)