Update Fix vmmap indicator overwriting address prefix (#3422)

* 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 <Cnaples79@gmail.com>
pull/3429/head
jackmisbach 2 weeks ago committed by GitHub
parent 4d32831b8f
commit 4f7e515775
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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)

@ -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):

Loading…
Cancel
Save