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

Commit 7b3d3e9

Browse files
committed
update
1 parent 3d3f2db commit 7b3d3e9

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/DyldExtractor/converter/stub_fixer.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,10 @@ def _addToMap(stubName: bytes, stubAddr: int):
12501250
stubMap[stubName] = [stubAddr]
12511251
pass
12521252

1253+
linkeditFile = self._machoCtx.fileForAddr(
1254+
self._machoCtx.segments[b"__LINKEDIT"].seg.vmaddr
1255+
)
1256+
12531257
for segment in self._machoCtx.segmentsI:
12541258
for sect in segment.sectsI:
12551259
if sect.flags & SECTION_TYPE == S_SYMBOL_STUBS:
@@ -1262,7 +1266,7 @@ def _addToMap(stubName: bytes, stubAddr: int):
12621266
stubNames = None
12631267

12641268
# Try to symbolize though indirect symbol entries
1265-
symbolIndex = self._machoCtx.readFormat(
1269+
symbolIndex = linkeditFile.readFormat(
12661270
self._dysymtab.indirectsymoff + ((sect.reserved1 + i) * 4),
12671271
"<I"
12681272
)[0]
@@ -1274,11 +1278,11 @@ def _addToMap(stubName: bytes, stubAddr: int):
12741278
and symbolIndex != (INDIRECT_SYMBOL_ABS | INDIRECT_SYMBOL_LOCAL)
12751279
):
12761280
symbolEntry = nlist_64(
1277-
self._machoCtx.file,
1281+
linkeditFile.file,
12781282
self._symtab.symoff + (symbolIndex * nlist_64.SIZE)
12791283
)
12801284
stubNames = [
1281-
self._machoCtx.readString(self._symtab.stroff + symbolEntry.n_strx)
1285+
linkeditFile.readString(self._symtab.stroff + symbolEntry.n_strx)
12821286
]
12831287
pass
12841288

@@ -1335,32 +1339,24 @@ def _addToMap(stubName: bytes, stubAddr: int):
13351339
elif stubFormat == _StubFormat.StubOptimized:
13361340
# only need to relink stub
13371341
newStub = self._arm64Utils.generateStubNormal(stubAddr, symPtrAddr)
1338-
self._machoCtx.writeBytes(
1339-
self._dyldCtx.convertAddr(stubAddr),
1340-
newStub
1341-
)
1342+
stubOff, ctx = self._dyldCtx.convertAddr(stubAddr)
1343+
ctx.fileCtx.writeBytes(stubOff, newStub)
13421344
continue
13431345

13441346
elif stubFormat == _StubFormat.AuthStubNormal:
13451347
# only need to relink symbol pointer
1346-
self._machoCtx.writeBytes(
1347-
self._dyldCtx.convertAddr(symPtrAddr),
1348-
struct.pack("<Q", stubAddr)
1349-
)
1348+
symPtrOff, ctx = self._dyldCtx.convertAddr(symPtrAddr)
1349+
ctx.fileCtx.writeBytes(symPtrOff, struct.pack("<Q", stubAddr))
13501350
continue
13511351

13521352
elif stubFormat == _StubFormat.AuthStubOptimized:
13531353
# need to relink both the stub and the symbol pointer
1354-
self._machoCtx.writeBytes(
1355-
self._dyldCtx.convertAddr(symPtrAddr),
1356-
struct.pack("<Q", stubAddr)
1357-
)
1354+
symPtrOff, ctx = self._dyldCtx.convertAddr(symPtrAddr)
1355+
ctx.fileCtx.writeBytes(symPtrOff, struct.pack("<Q", stubAddr))
13581356

13591357
newStub = self._arm64Utils.generateAuthStubNormal(stubAddr, symPtrAddr)
1360-
self._machoCtx.writeBytes(
1361-
self._dyldCtx.convertAddr(stubAddr),
1362-
newStub
1363-
)
1358+
stubOff, ctx = self._dyldCtx.convertAddr(stubAddr)
1359+
ctx.fileCtx.writeBytes(stubOff, newStub)
13641360
continue
13651361

13661362
elif stubFormat == _StubFormat.AuthStubResolver:
@@ -1398,7 +1394,7 @@ def _fixCallsites(self, stubMap: Dict[bytes, Tuple[int]]) -> None:
13981394
textAddr = textSect.addr
13991395
# Section offsets by section_64.offset are sometimes
14001396
# inaccurate, like in libcrypto.dylib
1401-
textOff = self._dyldCtx.convertAddr(textAddr)
1397+
textOff = self._dyldCtx.convertAddr(textAddr)[0]
14021398

14031399
for sectOff in range(0, textSect.size, 4):
14041400
# We are only looking for bl and b instructions only.

0 commit comments

Comments
 (0)