How to visualize free heap chunks using Python GDB command

Viewed 192

I need to visualize free heap chunks like the following:

free fast bin chunks:
chunk 1:
address=...
prev_size=...
size=...
fd=...
bk=...
fd_nextsize=...
bk_nextsize=...
data=...

chunk 2:
....
....

free large bin chunks:
chunk 1:
....

free unsorted bin chunks:
....

So far I have managed to do it using heap command in pwndbg and some string parsing inside a python script that I pass to gdb using --command=my_command.py flag.

The problem is I have to use vanilla gdb, and I wasn't able to find a similar command or method to visualise free heap chunks.

What I was doing previously was using:

x = gdb.parse_and_eval('main_arena.bins')
bins_string = x.format_string(max_elements=254)
bins = bins_string[1:-1].split(',')

and then iterating over all free chunks in bins and calling heap {chunk_address} for each of them and parsing the output.

How can I do this without using heap with the means of vanilla gdb?

UPDATE: I would also like to skip tcache chunks but I am not sure how to tell if it is tcache or other type without the heap command

I will appreciate your help!

0 Answers
Related