Skip to content

Commit

Permalink
addressing comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
r12f committed Dec 22, 2023
1 parent d2bdf19 commit afabab9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/commands/heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ gef➤ heap chunks --min-size 16 --max-size 32

![heap-chunks-size-filter](https://i.imgur.com/AWuCvFK.png)

If heap chunks command gives too many chunks, we can use `--count` argument to limit the number
The range is inclusive, so the above command will display all chunks with size >=16 and <=32.

If heap chunks command still gives too many chunks, we can use `--count` argument to limit the number
of the chunks in the output:

```text
Expand All @@ -107,8 +109,6 @@ gef➤ heap chunks --count 1

![heap-chunks-size-filter](https://i.imgur.com/EinuDAt.png)

The range is inclusive, so the above command will display all chunks with size >=16 and <=32.

### `heap chunk` command

This command gives visual information of a Glibc malloc-ed chunked. Simply provide the address to
Expand Down
12 changes: 6 additions & 6 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6387,18 +6387,18 @@ def do_invoke(self, _: List[str], **kwargs: Any) -> None:
ctx = GlibcHeapWalkContext(min_size=args.min_size, max_size=args.max_size, count=args.count, resolve_type=args.resolve, summary=args.summary)
if args.all or not args.arena_address:
for arena in gef.heap.arenas:
self.dump_chunks_arena(arena, print_arena=args.all, allow_unaligned=args.allow_unaligned, ctx=ctx)
self.dump_chunks_arena(arena, ctx, print_arena=args.all, allow_unaligned=args.allow_unaligned)
if not args.all:
return
try:
arena_addr = parse_address(args.arena_address)
arena = GlibcArena(f"*{arena_addr:#x}")
self.dump_chunks_arena(arena, allow_unaligned=args.allow_unaligned, ctx=ctx)
self.dump_chunks_arena(arena, ctx, allow_unaligned=args.allow_unaligned)
except gdb.error:
err("Invalid arena")
return

def dump_chunks_arena(self, arena: GlibcArena, print_arena: bool = False, allow_unaligned: bool = False, ctx: GlibcHeapWalkContext = GlibcHeapWalkContext()) -> None:
def dump_chunks_arena(self, arena: GlibcArena, ctx: GlibcHeapWalkContext, print_arena: bool = False, allow_unaligned: bool = False) -> None:
heap_addr = arena.heap_addr(allow_unaligned=allow_unaligned)
if heap_addr is None:
err("Could not find heap for arena")
Expand All @@ -6407,15 +6407,15 @@ def dump_chunks_arena(self, arena: GlibcArena, print_arena: bool = False, allow_
gef_print(str(arena))
if arena.is_main_arena():
heap_end = arena.top + GlibcChunk(arena.top, from_base=True).size
self.dump_chunks_heap(heap_addr, heap_end, arena, allow_unaligned=allow_unaligned, ctx=ctx)
self.dump_chunks_heap(heap_addr, heap_end, arena, ctx, allow_unaligned=allow_unaligned)
else:
heap_info_structs = arena.get_heap_info_list() or []
for heap_info in heap_info_structs:
if not self.dump_chunks_heap(heap_info.heap_start, heap_info.heap_end, arena, allow_unaligned=allow_unaligned, ctx=ctx):
if not self.dump_chunks_heap(heap_info.heap_start, heap_info.heap_end, arena, ctx, allow_unaligned=allow_unaligned):
break
return

def dump_chunks_heap(self, start: int, end: int, arena: GlibcArena, allow_unaligned: bool = False, ctx: GlibcHeapWalkContext = GlibcHeapWalkContext()) -> bool:
def dump_chunks_heap(self, start: int, end: int, arena: GlibcArena, ctx: GlibcHeapWalkContext, allow_unaligned: bool = False) -> bool:
nb = self["peek_nb_byte"]
chunk_iterator = GlibcChunk(start, from_base=True, allow_unaligned=allow_unaligned)
heap_summary = GlibcHeapArenaSummary(resolve_type=ctx.resolve_type)
Expand Down

0 comments on commit afabab9

Please sign in to comment.