Skip to content

Commit edaa929

Browse files
authored
Merge pull request #164 from p-x9/feature/dyld-cache-mapping-name
2 parents 3d2e8f3 + a03d6b7 commit edaa929

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

Sources/MachOKit/Model/DyldCache/DyldCacheMappingAndSlideInfo.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,46 @@ extension DyldCacheMappingAndSlideInfo {
8282
}
8383
}
8484
}
85+
86+
extension DyldCacheMappingAndSlideInfo {
87+
// [dyld implementation](https://github.com/apple-oss-distributions/dyld/blob/66c652a1f1f6b7b5266b8bbfd51cb0965d67cc44/common/DyldSharedCache.cpp#L305)
88+
public var mappingName: String? {
89+
switch maxProtection {
90+
case _ where maxProtection.contains(.execute):
91+
if flags.contains(.textStubs) {
92+
return "__TEXT_STUBS"
93+
} else {
94+
return "__TEXT"
95+
}
96+
case _ where maxProtection.contains(.write):
97+
if flags.contains(.authData) {
98+
if flags.contains(.dirtyData) {
99+
return "__AUTH_DIRTY"
100+
} else if flags.contains(.constTproData) {
101+
return "__AUTH_TPRO_CONST"
102+
} else if flags.contains(.constData) {
103+
return "__AUTH_CONST"
104+
} else {
105+
return "__AUTH"
106+
}
107+
} else {
108+
if flags.contains(.dirtyData) {
109+
return "__DATA_DIRTY"
110+
} else if flags.contains(.constTproData) {
111+
return "__TPRO_CONST"
112+
} else if flags.contains(.constData) {
113+
return "__DATA_CONST"
114+
} else {
115+
return "__DATA"
116+
}
117+
}
118+
case _ where maxProtection.contains(.read):
119+
if flags.contains(.readOnlyData) {
120+
return "__READ_ONLY"
121+
} else {
122+
return "__LINKEDIT"
123+
}
124+
default: return nil
125+
}
126+
}
127+
}

Tests/MachOKitTests/DyldCacheLoadedPrintTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ final class DyldCacheLoadedPrintTests: XCTestCase {
6363
for info in infos {
6464
print("----")
6565
print("Address:", String(info.address, radix: 16))
66+
print("Name:", info.mappingName ?? "unknown")
6667
print("File Offset::", String(info.fileOffset, radix: 16))
6768
print("Size:", String(info.size, radix: 16))
6869
print("Flags:", info.flags.bits)

Tests/MachOKitTests/DyldCachePrintTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ final class DyldCachePrintTests: XCTestCase {
6666
for info in infos {
6767
print("----")
6868
print("Address:", String(info.address, radix: 16))
69+
print("Name:", info.mappingName ?? "unknown")
6970
print("File Offset::", String(info.fileOffset, radix: 16))
7071
print("Size:", String(info.size, radix: 16))
7172
print("Flags:", info.flags.bits)

0 commit comments

Comments
 (0)