Skip to content

Commit 95ddfef

Browse files
authored
Merge pull request #9 from p-x9/feature/fix-methlist-offset-cache
Fix offset calculation for `__objc_methlist` in subcache
2 parents bf8db99 + b24b2c7 commit 95ddfef

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/MachOObjCSection/MachOFile+ObjectiveC.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,19 @@ extension MachOFile.ObjectiveC {
5656
return nil
5757
}
5858

59+
let offset = if let cache = machO.cache {
60+
__objc_methlist.address - numericCast(cache.mainCacheHeader.sharedRegionStart)
61+
} else {
62+
__objc_methlist.offset
63+
}
64+
5965
return .init(
6066
data: machO.fileHandle.readData(
6167
offset: numericCast(__objc_methlist.offset + machO.headerStartOffset),
6268
size: __objc_methlist.size
6369
),
64-
offset: numericCast(__objc_methlist.offset),
65-
align: numericCast(__objc_methlist.align),
70+
offset: offset,
71+
align: __objc_methlist.align,
6672
is64Bit: machO.is64Bit
6773
)
6874
}

0 commit comments

Comments
 (0)