Fix DYLD Shared Cache (#3282)

* fix mem for shared cache

* Fix handling of missing DYLD Shared Cache

* Fix `_dyld_get_shared_cache_range` it has first required first argument.

* Rever cache changes

---------

Co-authored-by: Matt. <4922458+mbrla0@users.noreply.github.com>
pull/3308/head
patryk4815 3 months ago committed by GitHub
parent 9b6cbeb906
commit d529cc314f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -10,6 +10,7 @@ from typing import TypeVar
import pwndbg import pwndbg
import pwndbg.aglib.memory import pwndbg.aglib.memory
import pwndbg.aglib.symbol
def _uleb128(ptr: int) -> Tuple[int, int]: def _uleb128(ptr: int) -> Tuple[int, int]:
@ -637,7 +638,10 @@ class DyldSharedCache:
return DyldSharedCacheHashSet(ptr) 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: def shared_cache() -> DyldSharedCache | None:
""" """
Base address of the Darwin shared cache. 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 [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 [2]: https://github.com/apple-oss-distributions/dyld/blob/main/doc/dyld4.md#libdylddylib
""" """
base = int( if pwndbg.aglib.symbol.lookup_symbol("_dyld_get_shared_cache_range") is None:
pwndbg.dbg.selected_inferior().evaluate_expression( return None
"(const void*)_dyld_get_shared_cache_range()"
) # 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: if base == 0:
return None return None

@ -33,6 +33,9 @@ def format_address(vaddr: int, memsz: int, permstr: str, offset: int, objfile: s
"Format the given address as a string." "Format the given address as a string."
width = 2 + 2 * pwndbg.aglib.arch.ptrsize 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 ''}" return f"{vaddr:#{width}x} {vaddr + memsz:#{width}x} {permstr} {memsz:8x} {offset:7x} {objfile or ''}"

Loading…
Cancel
Save