Skip to content
This repository was archived by the owner on Dec 28, 2025. It is now read-only.

Commit 972df96

Browse files
committed
Fix issue with finding subcaches.
1 parent dcb4236 commit 972df96

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

bin/dyldex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _getArguments():
7878

7979

8080
def _openSubCaches(
81-
mainCachePath: str,
81+
mainCachePath: pathlib.Path,
8282
numSubCaches: int
8383
) -> Tuple[List[DyldContext], List[BinaryIO]]:
8484
"""Create DyldContext objects for each sub cache.
@@ -92,10 +92,10 @@ def _openSubCaches(
9292
Returns:
9393
A list of subcaches, and their file objects, which must be closed!
9494
"""
95-
subCaches = []
96-
subCachesFiles = []
95+
subCaches: List[DyldContext] = []
96+
subCachesFiles: List[BinaryIO] = []
9797

98-
subCacheSuffixes = [i for i in range(1, numSubCaches + 1)]
98+
subCacheSuffixes = [str(i) for i in range(1, numSubCaches + 1)]
9999
subCacheSuffixes.append("symbols")
100100
for cacheSuffix in subCacheSuffixes:
101101
subCachePath = f"{mainCachePath}.{cacheSuffix}"

src/DyldExtractor/converter/linkedit_optimizer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ def copyLocalSymbols(self, newLinkedit: bytearray) -> None:
251251
self.statusBar.update(status="Copy Local Symbols")
252252

253253
symbolsCache = self.dyldCtx.getSymbolsCache()
254+
if symbolsCache.header.localSymbolsOffset == 0:
255+
self.logger.error("Symbols Cache doesn't contain local symbols.")
256+
return
257+
254258
localSymbolsInfo = dyld_cache_local_symbols_info(
255259
symbolsCache.file,
256260
symbolsCache.header.localSymbolsOffset

src/DyldExtractor/dyld/dyld_context.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,24 @@ def headerContainsField(self, field: str) -> bool:
9797

9898
def hasSubCaches(self) -> bool:
9999
"""Check if the dyld cache has sub caches.
100+
101+
Returns:
102+
If the cache has subcaches or not. The symbols cache is factored
103+
into this calculation, but the symbols cache is not counted in
104+
numSubCaches. It is implicitly included.
100105
"""
101106

102107
if self.headerContainsField("numSubCaches") and self.header.numSubCaches:
103108
return True
104-
else:
105-
return False
109+
110+
emptyUUID = b"\x00" * len(self.header.symbolSubCacheUUID)
111+
if (
112+
self.headerContainsField("symbolSubCacheUUID")
113+
and bytes(self.header.symbolSubCacheUUID) != emptyUUID
114+
):
115+
return True
116+
117+
return False
106118

107119
def addSubCaches(self, subCacheCtxs: List["DyldContext"]) -> None:
108120
for ctx in subCacheCtxs:

0 commit comments

Comments
 (0)