diff --git a/docs/commands/vmmap.md b/docs/commands/vmmap.md index 73f20b36e..c51b4edd3 100644 --- a/docs/commands/vmmap.md +++ b/docs/commands/vmmap.md @@ -9,8 +9,8 @@ differs from one architecture to another (this is one of the main reasons I star place). For example, you can learn that ELF running on SPARC architectures always have their `.data` and `heap` sections set as Read/Write/Execute. -`vmmap` accepts one argument, either a pattern to match again mapping names, or an address to -determine which section it belongs to. +`vmmap` accepts one argument, either a pattern to match again mapping names, an address to determine +which section it belongs to, or the permissions of the sections to match. ![vmmap-grep](https://i.imgur.com/ZFF4QVf.png) diff --git a/gef.py b/gef.py index 22b9b5e94..87cac6dfb 100644 --- a/gef.py +++ b/gef.py @@ -8791,6 +8791,24 @@ 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) + elif argv[0][0] in 'r-?' and \ + argv[0][1] in 'w-?' and \ + argv[0][2] in 'x-?': + correct = True + perms_dict = [Permission.READ, Permission.WRITE, + Permission.EXECUTE] + + for c, perm in zip(argv[0], perms_dict): + if c == '?': + continue + elif c == '-': + correct = correct and not entry.permission & perm + else: + correct = correct and entry.permission & perm + + + if correct: + 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: diff --git a/tests/commands/vmmap.py b/tests/commands/vmmap.py index 591d3b387..63f4c2f1e 100644 --- a/tests/commands/vmmap.py +++ b/tests/commands/vmmap.py @@ -24,3 +24,6 @@ def test_cmd_vmmap(self): res = gdb.execute("vmmap $rip", to_string=True) self.assertEqual(len(res.splitlines()), 2) + + res = gdb.execute("vmmap r-?", to_string=True) + self.assertGreater(len(res.splitlines()), 1)