From 8f78932c5ec274867f4455f6422ef9c39f2f2818 Mon Sep 17 00:00:00 2001 From: k4lizen <124312252+k4lizen@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:38:16 +0200 Subject: [PATCH] vis: interpret count as addr if its big enough (#2342) --- docs/commands/heap/vis_heap_chunks.md | 2 +- pwndbg/commands/heap.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/commands/heap/vis_heap_chunks.md b/docs/commands/heap/vis_heap_chunks.md index 60572f4cf..57d5534d4 100644 --- a/docs/commands/heap/vis_heap_chunks.md +++ b/docs/commands/heap/vis_heap_chunks.md @@ -21,7 +21,7 @@ usage: vis_heap_chunks [-h] [--beyond_top] [--no_truncate] [--all_chunks] [count |Positional Argument|Help| | :--- | :--- | -|`count`|Number of chunks to visualize. (default: %(default)s)| +|`count`|Number of chunks to visualize. If the value is big enough and addr isn't provided, this is interpreted as addr instead. (default: %(default)s)| |`addr`|Address of the first chunk.| ## Optional Arguments diff --git a/pwndbg/commands/heap.py b/pwndbg/commands/heap.py index 1e25b1695..e5f1bbb93 100644 --- a/pwndbg/commands/heap.py +++ b/pwndbg/commands/heap.py @@ -944,7 +944,7 @@ group.add_argument( nargs="?", type=lambda n: max(int(n, 0), 1), default=pwndbg.config.default_visualize_chunk_number, - help="Number of chunks to visualize.", + help="Number of chunks to visualize. If the value is big enough and addr isn't provided, this is interpreted as addr instead.", ) parser.add_argument("addr", nargs="?", default=None, help="Address of the first chunk.") parser.add_argument( @@ -985,6 +985,11 @@ def vis_heap_chunks( allocator = pwndbg.gdblib.heap.current assert isinstance(allocator, GlibcMemoryAllocator) + # 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 + count = pwndbg.config.default_visualize_chunk_number + if addr is not None: cursor = int(addr) heap_region = Heap(cursor)