Fix the issues when finding `tcache` for some 32-bit architectures (#1625)

* Fix the wrong tcache result for 32-bit architectures

* Remove redundant code

`arena.active_heap.start` already done i686 alginment

* Use `.heaps[0]` instead of `.active_heap`

https://github.com/pwndbg/pwndbg/pull/1625#issuecomment-1470453812
pull/1632/head
Alan Li 3 years ago committed by GitHub
parent f2fb803957
commit 36972fd982
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1351,7 +1351,6 @@ class DebugSymsHeap(GlibcMemoryAllocator):
thread's tcache.
"""
if self.has_tcache():
tcache = self.get_sbrk_heap_region().vaddr + 0x10
if self.multithreaded:
tcache_addr = pwndbg.gdblib.memory.pvoid(
pwndbg.gdblib.symbol.static_linkage_symbol_address("tcache")
@ -1361,6 +1360,8 @@ class DebugSymsHeap(GlibcMemoryAllocator):
# This thread doesn't have a tcache yet
return None
tcache = tcache_addr
else:
tcache = self.main_arena.heaps[0].start + pwndbg.gdblib.arch.ptrsize * 2
try:
self._thread_cache = pwndbg.gdblib.memory.poi(self.tcache_perthread_struct, tcache)
@ -1780,18 +1781,9 @@ class HeuristicHeap(GlibcMemoryAllocator):
)
# TODO: The result might be wrong if the arena is being shared by multiple thread
ptr_size = pwndbg.gdblib.arch.ptrsize
cursor = arena.active_heap.start
# i686 alignment heuristic
first_chunk_size = pwndbg.gdblib.arch.unpack(
pwndbg.gdblib.memory.read(cursor + ptr_size, ptr_size)
self._thread_cache = self.tcache_perthread_struct(
arena.heaps[0].start + pwndbg.gdblib.arch.ptrsize * 2
)
if first_chunk_size == 0:
cursor += ptr_size * 2
self._thread_cache = self.tcache_perthread_struct(cursor + ptr_size * 2)
self._thread_caches[gdb.selected_thread().global_num] = self._thread_cache
return self._thread_cache

Loading…
Cancel
Save