@ -12,15 +12,24 @@ import six
import pwndbg . color . memory as M
import pwndbg . commands
import pwndbg . typeinfo
from pwndbg . color import bold
from pwndbg . color import red
from pwndbg . color import underline
from pwndbg . color import yellow
def value_from_type ( type_name , addr ) :
gdb_type = pwndbg . typeinfo . load ( type_name )
return gdb . Value ( addr ) . cast ( gdb_type . pointer ( ) ) . dereference ( )
def read_chunk ( addr ) :
# in old versions of glibc, `mchunk_[prev_]size` was simply called `[prev_]size`
# to support both versions, we change the new names to the old ones here so that
# the rest of the code can deal with uniform names
renames = {
" mchunk_size " : " size " ,
" mchunk_prev_size " : " prev_size " ,
}
val = pwndbg . typeinfo . read_gdbvalue ( " struct malloc_chunk " , addr )
return dict ( { renames . get ( key , key ) : int ( val [ key ] ) for key in val . type . keys ( ) } , value = val )
def format_bin ( bins , verbose = False ) :
main_heap = pwndbg . heap . current
@ -159,7 +168,7 @@ def top_chunk(addr=None):
last_addr = None
addr = heap_start
while addr < heap_end :
chunk = value_from_type( ' struct malloc_chunk ' , addr )
chunk = read_chunk( addr )
size = int ( chunk [ ' size ' ] )
# Clear the bottom 3 bits
@ -185,7 +194,7 @@ def malloc_chunk(addr):
if not isinstance ( addr , six . integer_types ) :
addr = int ( addr )
chunk = value_from_type( ' struct malloc_chunk ' , addr )
chunk = read_chunk( addr )
size = int ( chunk [ ' size ' ] )
actual_size = size & ~ 7
prev_inuse , is_mmapped , non_main_arena = main_heap . chunk_flags ( size )
@ -204,7 +213,7 @@ def malloc_chunk(addr):
header + = yellow ( ' IS_MMAPED ' )
if non_main_arena :
header + = yellow ( ' NON_MAIN_ARENA ' )
print ( header , chunk )
print ( header , chunk [" value " ] )
return chunk