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