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

Commit d6eefb6

Browse files
committed
update
1 parent 64324d2 commit d6eefb6

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

bin/dyldex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _extractImage(
162162
extractionCtx = ExtractionContext(dyldCtx, machoCtx, statusBar, logger)
163163

164164
slide_info.processSlideInfo(extractionCtx)
165-
# linkedit_optimizer.optimizeLinkedit(extractionCtx)
165+
linkedit_optimizer.optimizeLinkedit(extractionCtx)
166166
# stub_fixer.fixStubs(extractionCtx)
167167
# objc_fixer.fixObjC(extractionCtx)
168168

src/DyldExtractor/converter/linkedit_optimizer.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def __init__(self, extractionCtx: ExtractionContext) -> None:
7676
self.statusBar = extractionCtx.statusBar
7777
self.logger = extractionCtx.logger
7878

79+
self.linkeditFile = self.machoCtx.fileForAddr(
80+
self.machoCtx.segments[b"__LINKEDIT"].seg.vmaddr
81+
)
82+
7983
self.symTabCmd: symtab_command = None
8084
self.dynSymTabCmd: dysymtab_command = None
8185
self.dyldInfo: dyld_info_command = None
@@ -134,7 +138,10 @@ def copyWeakBindingInfo(self, newLinkedit: bytearray) -> None:
134138

135139
size = self.dyldInfo.weak_bind_size
136140
if size:
137-
weakBindingInfo = self.machoCtx.getBytes(self.dyldInfo.weak_bind_off, size)
141+
weakBindingInfo = self.linkeditFile.getBytes(
142+
self.dyldInfo.weak_bind_off,
143+
size
144+
)
138145

139146
self.newWeakBindingInfoOffset = len(newLinkedit)
140147
newLinkedit.extend(weakBindingInfo)
@@ -156,7 +163,7 @@ def copyExportInfo(self, newLinkedit: bytearray) -> None:
156163
exportSize = self.dyldInfo.export_size
157164

158165
if exportSize:
159-
exportInfo = self.machoCtx.getBytes(exportOff, exportSize)
166+
exportInfo = self.linkeditFile.getBytes(exportOff, exportSize)
160167

161168
self.newExportInfoOffset = len(newLinkedit)
162169
newLinkedit.extend(exportInfo)
@@ -172,7 +179,7 @@ def copyBindingInfo(self, newLinkedit: bytearray) -> None:
172179

173180
size = self.dyldInfo.bind_size
174181
if size:
175-
bindingInfo = self.machoCtx.getBytes(self.dyldInfo.bind_off, size)
182+
bindingInfo = self.linkeditFile.getBytes(self.dyldInfo.bind_off, size)
176183

177184
self.newBindingInfoOffset = len(newLinkedit)
178185
newLinkedit.extend(bindingInfo)
@@ -188,7 +195,10 @@ def copyLazyBindingInfo(self, newLinkedit: bytearray) -> None:
188195

189196
size = self.dyldInfo.lazy_bind_size
190197
if size:
191-
lazyBindingInfo = self.machoCtx.getBytes(self.dyldInfo.lazy_bind_off, size)
198+
lazyBindingInfo = self.linkeditFile.getBytes(
199+
self.dyldInfo.lazy_bind_off,
200+
size
201+
)
192202

193203
self.newLazyBindingInfoOffset = len(newLinkedit)
194204
newLinkedit.extend(lazyBindingInfo)
@@ -204,17 +214,18 @@ def startSymbolContext(self, newLinkedit: bytearray) -> None:
204214
def copyLocalSymbols(self, newLinkedit: bytearray) -> None:
205215
self.statusBar.update(status="Copy Local Symbols")
206216

217+
symbolsCache = self.dyldCtx.getSymbolsCache()
207218
localSymbolsInfo = dyld_cache_local_symbols_info(
208-
self.dyldCtx.file,
209-
self.dyldCtx.header.localSymbolsOffset
219+
symbolsCache.fileCtx.file,
220+
symbolsCache.header.localSymbolsOffset
210221
)
211222

212223
localSymbolsEntriesInfo = None
213224
for i in range(localSymbolsInfo.entriesCount):
214225
entryOff = (i * dyld_cache_local_symbols_entry.SIZE)
215226
entryOff += localSymbolsInfo._fileOff_ + localSymbolsInfo.entriesOffset
216227

217-
entry = dyld_cache_local_symbols_entry(self.dyldCtx.file, entryOff)
228+
entry = dyld_cache_local_symbols_entry(symbolsCache.fileCtx.file, entryOff)
218229
if entry.dylibOffset == self.machoCtx.fileOffset:
219230
localSymbolsEntriesInfo = entry
220231
break
@@ -241,7 +252,7 @@ def copyLocalSymbols(self, newLinkedit: bytearray) -> None:
241252

242253
for offset in range(entriesStart, entriesEnd, nlist_64.SIZE):
243254
symbolEnt = nlist_64(self.dyldCtx.file, offset)
244-
name = self.dyldCtx.readString(symbolStrOff + symbolEnt.n_strx)
255+
name = symbolsCache.fileCtx.readString(symbolStrOff + symbolEnt.n_strx)
245256

246257
# copy data
247258
self.newLocalSymbolCount += 1

src/DyldExtractor/dyld/dyld_context.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,21 @@ def addSubCaches(self, subCacheFileCtxs: list[FileContext]) -> None:
109109
self.mappings.extend(subCache.mappings)
110110
pass
111111
pass
112+
113+
def getSymbolsCache(self) -> "DyldContext":
114+
"""Get the .symbols cache.
115+
116+
Try to find the .symbols cache by matching uuids.
117+
If there are no sub caches, this just returns itself.
118+
Or None if the .symbols cache cannot be found.
119+
"""
120+
121+
if not self._subCaches:
122+
return self
123+
124+
for cache in self._subCaches:
125+
if self.header.symbolSubCacheUUID == cache.header.uuid:
126+
return cache
127+
pass
128+
129+
return None

0 commit comments

Comments
 (0)