From a12b5bf79c30c884ba2a6e6236fd82156fd34907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20P=C5=82atek?= Date: Sun, 28 Oct 2018 17:11:32 +0100 Subject: [PATCH] fix unpacking bins tuples (#563) * fix unpacking bins tuples * pop type --- pwndbg/commands/heap.py | 7 ++++--- pwndbg/heap/ptmalloc.py | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pwndbg/commands/heap.py b/pwndbg/commands/heap.py index a18c65bba..6084a297d 100755 --- a/pwndbg/commands/heap.py +++ b/pwndbg/commands/heap.py @@ -37,16 +37,17 @@ def format_bin(bins, verbose=False, offset=None): offset = main_heap.chunk_key_offset('fd') result = [] + bins_type = bins.pop('type') + for size in bins: b = bins[size] - count, is_chain_corrupted = None, False # fastbins consists of only single linked list - if len(b) == 1: # fastbin: + if bins_type == 'fastbins': chain_fd = b # tcachebins consists of single linked list and entries count - elif len(b) == 2: # tcachebin: + elif bins_type == 'tcachebins': chain_fd, count = b # normal bins consists of double linked list and may be corrupted (we can detect corruption) else: # normal bin diff --git a/pwndbg/heap/ptmalloc.py b/pwndbg/heap/ptmalloc.py index ead58d3c4..6558936dc 100644 --- a/pwndbg/heap/ptmalloc.py +++ b/pwndbg/heap/ptmalloc.py @@ -434,6 +434,7 @@ class Heap(pwndbg.heap.heap.BaseHeap): result[size] = chain + result['type'] = 'fastbins' return result @@ -461,6 +462,7 @@ class Heap(pwndbg.heap.heap.BaseHeap): result[size] = (chain, count) + result['type'] = 'tcachebins' return result @@ -520,6 +522,7 @@ class Heap(pwndbg.heap.heap.BaseHeap): result['all'] = chain + result['type'] = 'unsortedbin' return result @@ -537,6 +540,7 @@ class Heap(pwndbg.heap.heap.BaseHeap): result[size] = chain + result['type'] = 'smallbins' return result @@ -554,6 +558,7 @@ class Heap(pwndbg.heap.heap.BaseHeap): result[size] = chain + result['type'] = 'largebins' return result