From 10258b2cb92de384685e9034457f063cd792f823 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Wed, 5 Jun 2024 16:42:33 +0200 Subject: [PATCH 01/20] [cmd] Add support for flags specifying filters type in vmmap, and allow multiple filters Parse args: - `-a` / `--addr`: - filter by address -> parses the next arg as an int or asks gdb the value - `-n` / `--name`: - filter based on section name - If nothing is specified, print a warning and guess the type (previous behavior) --- gef.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 10 deletions(-) diff --git a/gef.py b/gef.py index af6ee583e..e95b54757 100644 --- a/gef.py +++ b/gef.py @@ -8899,6 +8899,60 @@ def do_invoke(self, argv: List[str]) -> None: err("No address mapping information found") return + # Parse args: + # - `-a` / `--addr`: + # - filter by address -> parses the next arg as an int or asks gdb + # the value + # - `-n` / `--name`: + # - filter based on section name + # - If nothing is specified, print a warning and guess the type + current_type = 0 # 0:None, 1:Address, 2:Name + + addrs = {} + names = [] + + for arg in argv: + if arg in ("-a", "--addr"): + current_type = 1 + continue + if arg in ("-n", "--name"): + current_type = 2 + continue + + if current_type == 1: # Address + if self.is_integer(arg): + addr = int(arg, 0) + else: + addr = safe_parse_and_eval(arg) + + if addr is None: + warn(f"Failed to parse `{arg}` as an address") + else: + addrs[arg] = int(addr) + + elif current_type == 2: + names.append(arg) + + elif current_type == 0: + if self.is_integer(arg): + addr = int(arg, 0) + else: + addr = safe_parse_and_eval(arg) + + if addr is None: + names.append(arg) + warn(f"`{arg}` has no type specified. We guessed it was a name filter.") + else: + addrs[arg] = int(addr) + warn(f"`{arg}` has no type specified. We guessed it was an address filter.") + warn("You can use --name or --addr before the filter value for specifying its type manually.") + gef_print() + + current_type = 0 + + if current_type: + warn("The last filter seems to have no value associated, we ignore it .. :/") + if not gef.config["gef.disable_color"]: self.show_legend() @@ -8907,22 +8961,33 @@ def do_invoke(self, argv: List[str]) -> None: headers = ["Start", "End", "Offset", "Perm", "Path"] gef_print(Color.colorify("{:<{w}s}{:<{w}s}{:<{w}s}{:<4s} {:s}".format(*headers, w=gef.arch.ptrsize*2+3), color)) + last_printed_filter = None + for entry in vmmap: + names_filter = [f"name = '{x}'" for x in names if x in entry.path] + addrs_filter = [f"addr = " + self.format_addr_filter(arg, addr) for arg, addr in addrs.items() + if addr >= entry.page_start and addr < entry.page_end] + filters = names_filter + addrs_filter + filter_content = f"[{' & '.join(filters)}]" + if not argv: self.print_entry(entry) - continue - if argv[0] in entry.path: + + elif any(filters): + if filter_content != last_printed_filter: + gef_print() # skip a line between different filters + gef_print(Color.greenify(filter_content)) + last_printed_filter = filter_content self.print_entry(entry) - elif self.is_integer(argv[0]): - 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) + + gef_print() return + def format_addr_filter(self, arg, addr): + if self.is_integer(arg): + return f"`{arg}`" + return f"`{arg}` ({addr:#x})" + def print_entry(self, entry: Section) -> None: line_color = "" if entry.path == "[stack]": From 4f403254817a69d69abe0d5ff615fc84f4855d92 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sat, 8 Jun 2024 16:40:06 +0200 Subject: [PATCH 02/20] Fix tests --- tests/commands/vmmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/commands/vmmap.py b/tests/commands/vmmap.py index 1ac0c5a2e..b79c3ecff 100644 --- a/tests/commands/vmmap.py +++ b/tests/commands/vmmap.py @@ -23,4 +23,4 @@ def test_cmd_vmmap(self): self.assertGreater(len(res.splitlines()), 1) res = gdb.execute("vmmap $pc", to_string=True) - self.assertEqual(len(res.splitlines()), 2) + self.assertEqual(len(res.splitlines()), 8) From 677c5d56a29cab26fb306f72ae59709b6da6fa0c Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 04:59:13 +0200 Subject: [PATCH 03/20] Update doc --- docs/commands/vmmap.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/commands/vmmap.md b/docs/commands/vmmap.md index 73f20b36e..7ffb4a519 100644 --- a/docs/commands/vmmap.md +++ b/docs/commands/vmmap.md @@ -12,10 +12,14 @@ 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-grep](https://i.imgur.com/ZFF4QVf.png) +![vmmap-grep](https://github.com/hugsy/gef/assets/11377623/a3dbaa3e-88b0-407f-a0dd-07e65c4a3f73) -![vmmap-address](https://i.imgur.com/hfcs1jH.png) +![vmmap-address](https://github.com/hugsy/gef/assets/11377623/4dffe491-f927-4f03-b842-4d941140e66c) The address can be also be given in the form of a register or variable. -![vmmap-register](https://i.imgur.com/RlZA6NU.png) +![vmmap-register](https://github.com/hugsy/gef/assets/11377623/aed7ecdc-7ad9-4ba5-ae03-329e66432731) + +And you can do all of them in one command :) + +![vmmap-all-in-one](https://github.com/hugsy/gef/assets/11377623/b043f61b-48b3-4316-9f84-eb83822149ac) From cd2702787c1a2e42beeccb62aa3303a611b09e7a Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 20:15:27 +0200 Subject: [PATCH 04/20] Move args doc to the actual doc :P --- docs/commands/vmmap.md | 10 ++++++++-- gef.py | 8 -------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/commands/vmmap.md b/docs/commands/vmmap.md index 7ffb4a519..c4a0efd9f 100644 --- a/docs/commands/vmmap.md +++ b/docs/commands/vmmap.md @@ -9,8 +9,14 @@ 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` can accept multiple arguments, either patterns to match again mapping names, or addresses +to determine which section it belongs to: + +- `-a` / `--addr`: + - filter by address -> parses the next argument as an integer or asks gdb to interpret the value +- `-n` / `--name`: + - filter based on section name +- If nothing is specified, it prints a warning and guesses the type ![vmmap-grep](https://github.com/hugsy/gef/assets/11377623/a3dbaa3e-88b0-407f-a0dd-07e65c4a3f73) diff --git a/gef.py b/gef.py index e95b54757..322f0e926 100644 --- a/gef.py +++ b/gef.py @@ -8899,14 +8899,6 @@ def do_invoke(self, argv: List[str]) -> None: err("No address mapping information found") return - # Parse args: - # - `-a` / `--addr`: - # - filter by address -> parses the next arg as an int or asks gdb - # the value - # - `-n` / `--name`: - # - filter based on section name - # - If nothing is specified, print a warning and guess the type - current_type = 0 # 0:None, 1:Address, 2:Name addrs = {} names = [] From 361b8eccb7270ada217ab5a45c65f13d3988b22f Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 20:15:52 +0200 Subject: [PATCH 05/20] Make `current_type` a scoped enum --- gef.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gef.py b/gef.py index 322f0e926..e271f7842 100644 --- a/gef.py +++ b/gef.py @@ -8899,19 +8899,25 @@ def do_invoke(self, argv: List[str]) -> None: err("No address mapping information found") return + class ArgType(enum.Enum): + NONE : enum.auto() + ADDRESS : enum.auto() + NAME : enum.auto() + + current_type: ArgType = ArgType.NONE addrs = {} names = [] for arg in argv: if arg in ("-a", "--addr"): - current_type = 1 + current_type = ArgType.ADDRESS continue if arg in ("-n", "--name"): - current_type = 2 + current_type = ArgType.NAME continue - if current_type == 1: # Address + if current_type is ArgType.ADDRESS: if self.is_integer(arg): addr = int(arg, 0) else: @@ -8922,10 +8928,10 @@ def do_invoke(self, argv: List[str]) -> None: else: addrs[arg] = int(addr) - elif current_type == 2: + elif current_type is ArgType.NAME: names.append(arg) - elif current_type == 0: + elif current_type is ArgType.NONE: if self.is_integer(arg): addr = int(arg, 0) else: @@ -8940,9 +8946,9 @@ def do_invoke(self, argv: List[str]) -> None: warn("You can use --name or --addr before the filter value for specifying its type manually.") gef_print() - current_type = 0 + current_type = ArgType.NONE - if current_type: + if current_type is not ArgType.NONE: warn("The last filter seems to have no value associated, we ignore it .. :/") if not gef.config["gef.disable_color"]: From 5074b2ad3590d1cd65cdb7b8b3793c066a31db7c Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 20:16:40 +0200 Subject: [PATCH 06/20] Add type hints --- gef.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gef.py b/gef.py index e271f7842..901162dc1 100644 --- a/gef.py +++ b/gef.py @@ -8906,8 +8906,8 @@ class ArgType(enum.Enum): current_type: ArgType = ArgType.NONE - addrs = {} - names = [] + addrs: Dict[str, int] = {} + names: List[str] = [] for arg in argv: if arg in ("-a", "--addr"): From 9fa5e8c17625a579d860150b308010e8f87cc6f5 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 20:20:12 +0200 Subject: [PATCH 07/20] fix enum ArgType --- gef.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gef.py b/gef.py index 901162dc1..2ba415e8e 100644 --- a/gef.py +++ b/gef.py @@ -8900,9 +8900,9 @@ def do_invoke(self, argv: List[str]) -> None: return class ArgType(enum.Enum): - NONE : enum.auto() - ADDRESS : enum.auto() - NAME : enum.auto() + NONE = enum.auto() + ADDRESS = enum.auto() + NAME = enum.auto() current_type: ArgType = ArgType.NONE From 2b4127ce17a0c35226e9c00836af8e85a4ff7b5c Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 20:21:37 +0200 Subject: [PATCH 08/20] fix nits --- gef.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/gef.py b/gef.py index 2ba415e8e..4baa2beb3 100644 --- a/gef.py +++ b/gef.py @@ -8963,8 +8963,8 @@ class ArgType(enum.Enum): for entry in vmmap: names_filter = [f"name = '{x}'" for x in names if x in entry.path] - addrs_filter = [f"addr = " + self.format_addr_filter(arg, addr) for arg, addr in addrs.items() - if addr >= entry.page_start and addr < entry.page_end] + addrs_filter = [f"addr = {self.format_addr_filter(arg, addr)}" for arg, addr in addrs.items() + if entry.page_start <= addr < entry.page_end] filters = names_filter + addrs_filter filter_content = f"[{' & '.join(filters)}]" @@ -8981,10 +8981,8 @@ class ArgType(enum.Enum): gef_print() return - def format_addr_filter(self, arg, addr): - if self.is_integer(arg): - return f"`{arg}`" - return f"`{arg}` ({addr:#x})" + def format_addr_filter(self, arg: str, addr: int): + return f"`{arg}`" if self.is_integer(arg) else f"`{arg}` ({addr:#x})" def print_entry(self, entry: Section) -> None: line_color = "" From 64d78850c4121e9d8c2dbd371579c2d2f127a6a3 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 20:24:49 +0200 Subject: [PATCH 09/20] fix indentation --- docs/commands/vmmap.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/commands/vmmap.md b/docs/commands/vmmap.md index c4a0efd9f..f28ed36c0 100644 --- a/docs/commands/vmmap.md +++ b/docs/commands/vmmap.md @@ -13,9 +13,9 @@ and `heap` sections set as Read/Write/Execute. to determine which section it belongs to: - `-a` / `--addr`: - - filter by address -> parses the next argument as an integer or asks gdb to interpret the value + - filter by address -> parses the next argument as an integer or asks gdb to interpret the value - `-n` / `--name`: - - filter based on section name + - filter based on section name - If nothing is specified, it prints a warning and guesses the type ![vmmap-grep](https://github.com/hugsy/gef/assets/11377623/a3dbaa3e-88b0-407f-a0dd-07e65c4a3f73) From 78962b1bcccaa4c48e0d602b03759d274622e221 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 20:27:18 +0200 Subject: [PATCH 10/20] fix indentation --- docs/commands/vmmap.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/commands/vmmap.md b/docs/commands/vmmap.md index f28ed36c0..d2c5ad10a 100644 --- a/docs/commands/vmmap.md +++ b/docs/commands/vmmap.md @@ -13,9 +13,9 @@ and `heap` sections set as Read/Write/Execute. to determine which section it belongs to: - `-a` / `--addr`: - - filter by address -> parses the next argument as an integer or asks gdb to interpret the value + + filter by address -> parses the next argument as an integer or asks gdb to interpret the value - `-n` / `--name`: - - filter based on section name + + filter based on section name - If nothing is specified, it prints a warning and guesses the type ![vmmap-grep](https://github.com/hugsy/gef/assets/11377623/a3dbaa3e-88b0-407f-a0dd-07e65c4a3f73) From f1033add44ee6a59e4656d85f5d8700a40b9b0cf Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Sun, 9 Jun 2024 21:42:43 +0200 Subject: [PATCH 11/20] fix problems with unordered list linting --- docs/commands/vmmap.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/commands/vmmap.md b/docs/commands/vmmap.md index d2c5ad10a..90d401e34 100644 --- a/docs/commands/vmmap.md +++ b/docs/commands/vmmap.md @@ -12,11 +12,11 @@ and `heap` sections set as Read/Write/Execute. `vmmap` can accept multiple arguments, either patterns to match again mapping names, or addresses to determine which section it belongs to: -- `-a` / `--addr`: - + filter by address -> parses the next argument as an integer or asks gdb to interpret the value -- `-n` / `--name`: - + filter based on section name -- If nothing is specified, it prints a warning and guesses the type +1. `-a` / `--addr`: + - filter by address -> parses the next argument as an integer or asks gdb to interpret the value +2. `-n` / `--name`: + - filter based on section name +3. If nothing is specified, it prints a warning and guesses the type ![vmmap-grep](https://github.com/hugsy/gef/assets/11377623/a3dbaa3e-88b0-407f-a0dd-07e65c4a3f73) From 9ea73ee5263e2b3b7935a3075b925740fac6814e Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Tue, 25 Jun 2024 14:36:34 +0200 Subject: [PATCH 12/20] Use argparse --- gef.py | 67 +++++++++++++++++----------------------------------------- 1 file changed, 19 insertions(+), 48 deletions(-) diff --git a/gef.py b/gef.py index 4baa2beb3..be2debb13 100644 --- a/gef.py +++ b/gef.py @@ -8893,63 +8893,34 @@ class VMMapCommand(GenericCommand): _example_ = f"{_cmdline_} libc" @only_if_gdb_running - def do_invoke(self, argv: List[str]) -> None: + @parse_arguments({'unknown_types': ['']}, {('--addr', '-a'): [''], ('--name', '-n'): ['']}) + def do_invoke(self, _: List[str], **kwargs: Any) -> None: + args : argparse.Namespace = kwargs["arguments"] vmmap = gef.memory.maps if not vmmap: err("No address mapping information found") return - class ArgType(enum.Enum): - NONE = enum.auto() - ADDRESS = enum.auto() - NAME = enum.auto() - - current_type: ArgType = ArgType.NONE - - addrs: Dict[str, int] = {} - names: List[str] = [] + addrs: Dict[str, int] = {x: parse_address(x) for x in args.addr} + names: List[str] = [x for x in args.name] - for arg in argv: - if arg in ("-a", "--addr"): - current_type = ArgType.ADDRESS + for arg in args.unknown_types: + if arg is '': continue - if arg in ("-n", "--name"): - current_type = ArgType.NAME - continue - - if current_type is ArgType.ADDRESS: - if self.is_integer(arg): - addr = int(arg, 0) - else: - addr = safe_parse_and_eval(arg) - if addr is None: - warn(f"Failed to parse `{arg}` as an address") - else: - addrs[arg] = int(addr) + if self.is_integer(arg): + addr = int(arg, 0) + else: + addr = safe_parse_and_eval(arg) - elif current_type is ArgType.NAME: + if addr is None: names.append(arg) - - elif current_type is ArgType.NONE: - if self.is_integer(arg): - addr = int(arg, 0) - else: - addr = safe_parse_and_eval(arg) - - if addr is None: - names.append(arg) - warn(f"`{arg}` has no type specified. We guessed it was a name filter.") - else: - addrs[arg] = int(addr) - warn(f"`{arg}` has no type specified. We guessed it was an address filter.") - warn("You can use --name or --addr before the filter value for specifying its type manually.") - gef_print() - - current_type = ArgType.NONE - - if current_type is not ArgType.NONE: - warn("The last filter seems to have no value associated, we ignore it .. :/") + warn(f"`{arg}` has no type specified. We guessed it was a name filter.") + else: + addrs[arg] = int(addr) + warn(f"`{arg}` has no type specified. We guessed it was an address filter.") + warn("You can use --name or --addr before the filter value for specifying its type manually.") + gef_print() if not gef.config["gef.disable_color"]: self.show_legend() @@ -8968,7 +8939,7 @@ class ArgType(enum.Enum): filters = names_filter + addrs_filter filter_content = f"[{' & '.join(filters)}]" - if not argv: + if len(names) + len(addrs) == 0: self.print_entry(entry) elif any(filters): From e9b45bc6fd638dc769c4fc3f79635258f4c53537 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Tue, 25 Jun 2024 14:51:47 +0200 Subject: [PATCH 13/20] Make hugsy happy :P --- gef.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gef.py b/gef.py index be2debb13..9bda7a4b6 100644 --- a/gef.py +++ b/gef.py @@ -8893,7 +8893,7 @@ class VMMapCommand(GenericCommand): _example_ = f"{_cmdline_} libc" @only_if_gdb_running - @parse_arguments({'unknown_types': ['']}, {('--addr', '-a'): [''], ('--name', '-n'): ['']}) + @parse_arguments({"unknown_types": [""]}, {("--addr", "-a"): [""], ("--name", "-n"): [""]}) def do_invoke(self, _: List[str], **kwargs: Any) -> None: args : argparse.Namespace = kwargs["arguments"] vmmap = gef.memory.maps From 3da17febd01d2746a6877d2a7bb7c87f388e8c8c Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Wed, 25 Sep 2024 15:15:58 +0200 Subject: [PATCH 14/20] Add tests for -n and -a --- tests/commands/vmmap.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/commands/vmmap.py b/tests/commands/vmmap.py index b79c3ecff..24df79263 100644 --- a/tests/commands/vmmap.py +++ b/tests/commands/vmmap.py @@ -17,10 +17,34 @@ def test_cmd_vmmap(self): ) gdb.execute("start") res = gdb.execute("vmmap", to_string=True) - self.assertGreater(len(res.splitlines()), 1) + self.assertEqual(len(res.splitlines()), 23) res = gdb.execute("vmmap stack", to_string=True) - self.assertGreater(len(res.splitlines()), 1) + assert "`stack` has no type specified. We guessed it was a name filter." in res + self.assertEqual(len(res.splitlines()), 9) res = gdb.execute("vmmap $pc", to_string=True) + assert "`$pc` has no type specified. We guessed it was an address filter." in res self.assertEqual(len(res.splitlines()), 8) + + def test_cmd_vmmap_addr(self): + gef, gdb = self._gef, self._gdb + gdb.execute("start") + + pc = gef.arch.register("pc") + + res = gdb.execute(f"vmmap -a {pc:#x}", to_string=True) + self.assertEqual(len(res.splitlines()), 5) + + res = gdb.execute("vmmap --addr $pc", to_string=True) + self.assertEqual(len(res.splitlines()), 5) + + def test_cmd_vmmap_name(self): + gdb = self._gdb + gdb.execute("start") + + res = gdb.execute("vmmap -n stack", to_string=True) + self.assertEqual(len(res.splitlines()), 5) + + res = gdb.execute("vmmap --name stack", to_string=True) + self.assertEqual(len(res.splitlines()), 5) From cb9c3fb65be65d758f771b25c9578841f6d41301 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Wed, 25 Sep 2024 15:18:55 +0200 Subject: [PATCH 15/20] Ups I forced pushed without pulling modifications :o --- docs/commands/vmmap.md | 2 +- gef.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/commands/vmmap.md b/docs/commands/vmmap.md index 90d401e34..597decb8d 100644 --- a/docs/commands/vmmap.md +++ b/docs/commands/vmmap.md @@ -26,6 +26,6 @@ The address can be also be given in the form of a register or variable. ![vmmap-register](https://github.com/hugsy/gef/assets/11377623/aed7ecdc-7ad9-4ba5-ae03-329e66432731) -And you can do all of them in one command :) +And you can do all of them in one command 🙂 ![vmmap-all-in-one](https://github.com/hugsy/gef/assets/11377623/b043f61b-48b3-4316-9f84-eb83822149ac) diff --git a/gef.py b/gef.py index 9bda7a4b6..8c9767912 100644 --- a/gef.py +++ b/gef.py @@ -8905,7 +8905,7 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None: names: List[str] = [x for x in args.name] for arg in args.unknown_types: - if arg is '': + if not arg: continue if self.is_integer(arg): From c55c505b9a7c96ebd610bad95003a6706400f081 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Fri, 27 Sep 2024 11:20:03 +0200 Subject: [PATCH 16/20] Update gef.py Co-authored-by: Grazfather --- gef.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gef.py b/gef.py index 8c9767912..7c951867d 100644 --- a/gef.py +++ b/gef.py @@ -8936,8 +8936,7 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None: names_filter = [f"name = '{x}'" for x in names if x in entry.path] addrs_filter = [f"addr = {self.format_addr_filter(arg, addr)}" for arg, addr in addrs.items() if entry.page_start <= addr < entry.page_end] - filters = names_filter + addrs_filter - filter_content = f"[{' & '.join(filters)}]" + filter_content = f"[{' & '.join([*names filter, *addrs_filter])}]" if len(names) + len(addrs) == 0: self.print_entry(entry) From 55a1649130a61c8bc148ba2493579f7837d91897 Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Fri, 27 Sep 2024 11:33:18 +0200 Subject: [PATCH 17/20] Fix tests --- gef.py | 2 +- tests/commands/vmmap.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gef.py b/gef.py index 7c951867d..e8ae28977 100644 --- a/gef.py +++ b/gef.py @@ -8941,7 +8941,7 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None: if len(names) + len(addrs) == 0: self.print_entry(entry) - elif any(filters): + elif filters: if filter_content != last_printed_filter: gef_print() # skip a line between different filters gef_print(Color.greenify(filter_content)) diff --git a/tests/commands/vmmap.py b/tests/commands/vmmap.py index 24df79263..fbc00a46a 100644 --- a/tests/commands/vmmap.py +++ b/tests/commands/vmmap.py @@ -17,7 +17,7 @@ def test_cmd_vmmap(self): ) gdb.execute("start") res = gdb.execute("vmmap", to_string=True) - self.assertEqual(len(res.splitlines()), 23) + self.assertGreater(len(res.splitlines()), 1) res = gdb.execute("vmmap stack", to_string=True) assert "`stack` has no type specified. We guessed it was a name filter." in res From 60215b43379378dd6bf9e8bef345c58599baabda Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Fri, 27 Sep 2024 11:41:50 +0200 Subject: [PATCH 18/20] Fix typo --- gef.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gef.py b/gef.py index e8ae28977..951dc3a05 100644 --- a/gef.py +++ b/gef.py @@ -8936,7 +8936,7 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None: names_filter = [f"name = '{x}'" for x in names if x in entry.path] addrs_filter = [f"addr = {self.format_addr_filter(arg, addr)}" for arg, addr in addrs.items() if entry.page_start <= addr < entry.page_end] - filter_content = f"[{' & '.join([*names filter, *addrs_filter])}]" + filter_content = f"[{' & '.join([*names_filter, *addrs_filter])}]" if len(names) + len(addrs) == 0: self.print_entry(entry) From 76f40f1da24a235b20f6bdb26f605dfe25e880ac Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Fri, 27 Sep 2024 13:38:32 +0200 Subject: [PATCH 19/20] fix filters not defined --- gef.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gef.py b/gef.py index 951dc3a05..f17b12cc0 100644 --- a/gef.py +++ b/gef.py @@ -8941,7 +8941,7 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None: if len(names) + len(addrs) == 0: self.print_entry(entry) - elif filters: + elif names_filter or addrs_filter: if filter_content != last_printed_filter: gef_print() # skip a line between different filters gef_print(Color.greenify(filter_content)) From 4f47cf7298fbdd263b1951db9d538fc23a14f9ad Mon Sep 17 00:00:00 2001 From: ValekoZ Date: Mon, 7 Oct 2024 16:03:00 +0200 Subject: [PATCH 20/20] Fix https://github.com/hugsy/gef/pull/1120#discussion_r1779742622 --- gef.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gef.py b/gef.py index f17b12cc0..05cd93836 100644 --- a/gef.py +++ b/gef.py @@ -8938,7 +8938,7 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None: if entry.page_start <= addr < entry.page_end] filter_content = f"[{' & '.join([*names_filter, *addrs_filter])}]" - if len(names) + len(addrs) == 0: + if not names and not addrs: self.print_entry(entry) elif names_filter or addrs_filter: