Redirect user to vis_heap_chunks help when chunks are ommited (#2723)

* redirect user to vis help when chunks are ommited

* fix vis_heap_chunks test by adding help text
pull/2736/head
k4lizen 10 months ago committed by GitHub
parent a0e39b06de
commit 7d8084188a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1004,6 +1004,15 @@ def vis_heap_chunks(
allocator = pwndbg.aglib.heap.current
assert isinstance(allocator, GlibcMemoryAllocator)
# Used to determine whether to show command hint
nothing_supplied = (
addr is None
and count == pwndbg.config.default_visualize_chunk_number
and not beyond_top
and not no_truncate
and not all_chunks
)
# If the first argument (count) is big enough (and address isn't provided) interpret it as an address
if addr is None and count is not None and count > 0x1000:
addr = count
@ -1100,6 +1109,7 @@ def vis_heap_chunks(
cursor = cursor_backup
chunk = Chunk(cursor)
reached_top = False
has_huge_chunk = False
# round up to align with 4*ptr_size and get half
half_max_size = (
@ -1144,6 +1154,7 @@ def vis_heap_chunks(
labels.extend(bin_labels_map.get(cursor, []))
if arena is not None and cursor == arena.top:
labels.append("Top chunk")
reached_top = True
asc += bin_ascii(data)
if printed % 2 == 0:
@ -1170,6 +1181,9 @@ def vis_heap_chunks(
)
)
if not reached_top and nothing_supplied:
print(message.hint("Not all chunks were shown, see `vis --help` for more information."))
VALID_CHARS = list(map(ord, set(printable) - set("\t\r\n\x0c\x0b")))

@ -76,7 +76,9 @@ def test_vis_heap_chunk_command(start_binary):
gdb.execute("set default-visualize-chunk-number 1")
assert pwndbg.config.default_visualize_chunk_number == 1
result = gdb.execute("vis_heap_chunk", to_string=True).splitlines()
assert result == expected
# No parameters were passed and top isn't reached so help text is shown
no_params_help = "Not all chunks were shown, see `vis --help` for more information."
assert result == expected + [no_params_help]
gdb.execute(
"set default-visualize-chunk-number %d"
% pwndbg.config.default_visualize_chunk_number.default

Loading…
Cancel
Save