@@ -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
0 commit comments