Skip to content

Commit 0d1c6c2

Browse files
authored
Check if dylib in shared cache (#243)
1 parent da2fb21 commit 0d1c6c2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Sources/SnapshotPreviewsCore/ConformanceLookup.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,23 @@ public func getPreviewTypes() -> [LookupResult] {
8484
let images = _dyld_image_count()
8585
var types = [LookupResult]()
8686
for i in 0..<images {
87+
let header = _dyld_get_image_header(i)!
88+
let headerType = UnsafeRawPointer(header).assumingMemoryBound(to: mach_header_type.self)
89+
90+
// Anything in the dylib cache is a system library that we should not include
91+
guard headerType.pointee.flags & MH_DYLIB_IN_CACHE == 0 else {
92+
continue
93+
}
94+
8795
let imageName = String(cString: _dyld_get_image_name(i))
88-
guard imageName.starts(with: Bundle.main.bundleURL.path) else {
96+
guard !imageName.contains(".simruntime") && !imageName.contains(".platform") && !imageName.starts(with: "/usr/lib/") && !imageName.starts(with: "/System/Library/") else {
8997
continue
9098
}
9199

92-
let header = _dyld_get_image_header(i)!
93100
var size: UInt = 0
94101
let sectStart = UnsafeRawPointer(
95102
getsectiondata(
96-
UnsafeRawPointer(header).assumingMemoryBound(to: mach_header_type.self),
103+
headerType,
97104
"__TEXT",
98105
"__swift5_proto",
99106
&size))?.assumingMemoryBound(to: Int32.self)

0 commit comments

Comments
 (0)