diff --git a/pwndbg/commands/heap.py b/pwndbg/commands/heap.py index 7a949ff10..7f67b8c84 100644 --- a/pwndbg/commands/heap.py +++ b/pwndbg/commands/heap.py @@ -81,7 +81,15 @@ def format_bin(bins: Bins, verbose=False, offset=None): formatted_chain = pwndbg.chain.format(chain_fd[0], offset=offset, safe_linking=safe_lnk) if isinstance(size, int): - size = hex(size) + if bins_type == BinType.LARGE: + start_size, end_size = allocator.largebin_size_range_from_index(size) + size = hex(start_size) + "-" + if end_size != pwndbg.gdblib.arch.ptrmask: + size += hex(end_size) + else: + size += "\u221e" # Unicode "infinity" + else: + size = hex(size) if is_chain_corrupted: line = message.hint(size) + message.error(" [corrupted]") + "\n" diff --git a/pwndbg/heap/ptmalloc.py b/pwndbg/heap/ptmalloc.py index c24b8c82c..e4e52868b 100644 --- a/pwndbg/heap/ptmalloc.py +++ b/pwndbg/heap/ptmalloc.py @@ -658,6 +658,22 @@ class GlibcMemoryAllocator(pwndbg.heap.heap.MemoryAllocator): # ptmalloc cache for current thread self._thread_cache: gdb.Value = None + def largebin_size_range_from_index(self, index): + index += NSMALLBINS + spaces_table = self._spaces_table() + largest_largebin = self.largebin_index(pwndbg.gdblib.arch.ptrmask) + start_size = (NSMALLBINS * self.malloc_alignment) - self.malloc_alignment + + for i in range(NSMALLBINS, index + 1): + start_size += spaces_table[i] + + if index != largest_largebin: + end_size = start_size + spaces_table[index + 1] - self.malloc_alignment + else: + end_size = pwndbg.gdblib.arch.ptrmask + + return (start_size, end_size) + def can_be_resolved(self): raise NotImplementedError()