diff --git a/pwndbg/aglib/macho.py b/pwndbg/aglib/macho.py index aff4f27ad..7539132f2 100644 --- a/pwndbg/aglib/macho.py +++ b/pwndbg/aglib/macho.py @@ -10,6 +10,7 @@ from typing import TypeVar import pwndbg import pwndbg.aglib.memory +import pwndbg.aglib.symbol def _uleb128(ptr: int) -> Tuple[int, int]: @@ -637,7 +638,10 @@ class DyldSharedCache: return DyldSharedCacheHashSet(ptr) -@pwndbg.lib.cache.cache_until("exit") +_global_new_variable_id = 0 + + +@pwndbg.lib.cache.cache_until("objfile") def shared_cache() -> DyldSharedCache | None: """ Base address of the Darwin shared cache. @@ -659,12 +663,22 @@ def shared_cache() -> DyldSharedCache | None: [1]: https://github.com/apple-oss-distributions/objc4/blob/f126469408dc82bd3f327217ae678fd0e6e3b37c/runtime/objc-opt.mm#L434 [2]: https://github.com/apple-oss-distributions/dyld/blob/main/doc/dyld4.md#libdylddylib """ - base = int( - pwndbg.dbg.selected_inferior().evaluate_expression( - "(const void*)_dyld_get_shared_cache_range()" - ) + if pwndbg.aglib.symbol.lookup_symbol("_dyld_get_shared_cache_range") is None: + return None + + # Due to bug: https://github.com/llvm/llvm-project/issues/84806#issuecomment-1995055683 + # we have to create new variable on each call + global _global_new_variable_id + _global_new_variable_id += 1 + var = f"$_pwndbg_internal_shared_cache_size{_global_new_variable_id}" + + base = pwndbg.dbg.selected_inferior().evaluate_expression( + f"size_t {var} = 0; (const void*)_dyld_get_shared_cache_range(&{var})" ) + if base.is_optimized_out: + return None + base = int(base) if base == 0: return None diff --git a/pwndbg/lib/memory.py b/pwndbg/lib/memory.py index cdf794701..78ca73e69 100644 --- a/pwndbg/lib/memory.py +++ b/pwndbg/lib/memory.py @@ -33,6 +33,9 @@ def format_address(vaddr: int, memsz: int, permstr: str, offset: int, objfile: s "Format the given address as a string." width = 2 + 2 * pwndbg.aglib.arch.ptrsize + if memsz > 0x100000000: + return f"{vaddr:#{width}x} {vaddr + memsz:#{width}x} {permstr} {memsz:8x} {offset:6x} {objfile or ''}" + return f"{vaddr:#{width}x} {vaddr + memsz:#{width}x} {permstr} {memsz:8x} {offset:7x} {objfile or ''}"