From 4f7e515775f4d5910017316493cc10e9e03c8892 Mon Sep 17 00:00:00 2001 From: jackmisbach Date: Sun, 23 Nov 2025 08:43:38 -0600 Subject: [PATCH] Update Fix vmmap indicator overwriting address prefix (#3422) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix vmmap indicator overwriting address prefix Change the prefix handling in memory.get() to prepend the indicator (e.g., ►) with a space instead of replacing the first characters of the address. This prevents the indicator from overwriting the '0x' prefix, making addresses easier to copy-paste. Before: ►xffffffff81000000 After: ► 0xffffffff81000000 Fixes #3412 * Update Fix vmmap indicator overwriting address prefix * Fix vmmap prefix alignment * Align vmmap prefix column and clarify prefix behavior --------- Co-authored-by: Chase Naples --- pwndbg/color/memory.py | 6 +++--- pwndbg/commands/vmmap.py | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pwndbg/color/memory.py b/pwndbg/color/memory.py index 57b24af68..2bd910c9f 100644 --- a/pwndbg/color/memory.py +++ b/pwndbg/color/memory.py @@ -77,7 +77,7 @@ def get( Arguments: address: Address to look up text: Optional text to use in place of the address in the return value string. - prefix: Optional text to set at beginning in the return value string. + prefix: Optional text to set at beginning in the return value string, followed by a space, without modifiying the original text. """ address = int(address) page = pwndbg.aglib.vmmap.find(address) @@ -109,8 +109,8 @@ def get( text = pwndbg.lib.pretty_print.int_to_string(address) if prefix: - # Replace first N characters with the provided prefix - text = prefix + text[len(prefix) :] + # Prepend the prefix and a space before the existing text + text = f"{prefix} {text}" return color(text) diff --git a/pwndbg/commands/vmmap.py b/pwndbg/commands/vmmap.py index 3aea1d55d..3574893a6 100644 --- a/pwndbg/commands/vmmap.py +++ b/pwndbg/commands/vmmap.py @@ -43,14 +43,14 @@ def pages_filter(gdbval_or_str): raise argparse.ArgumentTypeError("Unknown vmmap argument type.") -def print_vmmap_table_header() -> None: +def print_vmmap_table_header(prefix: str = "") -> None: """ Prints the table header for the vmmap command. """ prefer_relpaths = "on" if pwndbg.config.vmmap_prefer_relpaths else "off" width = 2 + 2 * pwndbg.aglib.arch.ptrsize print( - f"{'Start':>{width}} {'End':>{width}} {'Perm'} {'Size':>8} {'Offset':>7} " + f"{prefix}{'Start':>{width}} {'End':>{width}} {'Perm'} {'Size':>8} {'Offset':>7} " f"{'File'} (set vmmap-prefer-relpaths {prefer_relpaths})" ) @@ -271,8 +271,13 @@ def vmmap( print_vmmap_gaps(tuple(total_pages)) return + # Determine prefix width for alignment when showing filtered results + prefix_str = str(pwndbg.config.backtrace_prefix) + empty_prefix = " " * len(prefix_str) if filtered_pages else None + header_prefix = f"{empty_prefix} " if filtered_pages else "" + print(M.legend()) - print_vmmap_table_header() + print_vmmap_table_header(header_prefix) shared_cache_first = None shared_cache_last = None @@ -308,12 +313,12 @@ def vmmap( continue flush_shared_cache_info() - backtrace_prefix = None + backtrace_prefix = empty_prefix display_text = str(page) if page in filtered_pages: # If page was one of the original results, add an arrow for clarity - backtrace_prefix = str(pwndbg.config.backtrace_prefix) + backtrace_prefix = prefix_str # If the page is the only filtered page, insert offset if len(filtered_pages) == 1 and isinstance(gdbval_or_str, integer_types):