Display bin size range in `largebins` command output (#1613)

* Display bin size range in `largebins` command

* Remove `infinity_symbol` variable

* Remove unnecessary assignment
pull/1619/head
CptGibbon 3 years ago committed by GitHub
parent a847cbba92
commit d0f55d5cf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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"

@ -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()

Loading…
Cancel
Save