From 7d6ee15a2f32ad80d470a2b70b04b578f863601f Mon Sep 17 00:00:00 2001 From: huami1314 Date: Fri, 27 Mar 2026 23:00:41 +0800 Subject: [PATCH 1/2] refactor: enhance framework Mach-O retrieval methods --- TrollFools/InjectorV3+Bundle.swift | 26 +++++++++++++++++++------- TrollFools/InjectorV3+Eject.swift | 9 ++++++++- TrollFools/InjectorV3+Inject.swift | 9 ++++++++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/TrollFools/InjectorV3+Bundle.swift b/TrollFools/InjectorV3+Bundle.swift index 1ecc3a46..384ef36f 100644 --- a/TrollFools/InjectorV3+Bundle.swift +++ b/TrollFools/InjectorV3+Bundle.swift @@ -36,19 +36,15 @@ extension InjectorV3 { // MARK: - Shared Methods - func frameworkMachOsInBundle(_ target: URL) throws -> OrderedSet { + func allFrameworkMachOsInBundle(_ target: URL) -> OrderedSet { precondition(checkIsBundle(target), "Not a bundle: \(target.path)") - let executableURL = try locateExecutableInBundle(target) - precondition(isMachO(executableURL), "Not a Mach-O: \(executableURL.path)") - let frameworksURL = target.appendingPathComponent("Frameworks") - let linkedDylibs = try linkedDylibsRecursivelyOfMachO(executableURL) var enumeratedURLs = OrderedSet() if let enumerator = FileManager.default.enumerator( at: frameworksURL, - includingPropertiesForKeys: [.fileSizeKey], + includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles] ) { for case let itemURL as URL in enumerator { @@ -56,12 +52,28 @@ extension InjectorV3 { enumerator.skipDescendants() continue } - if enumerator.level == 2 { + if enumerator.level == 2, + isMachO(itemURL), + !itemURL.lastPathComponent.hasSuffix(".\(Self.injectedMarkerName).bak"), + !itemURL.lastPathComponent.hasSuffix(".troll-fools.bak") + { enumeratedURLs.append(itemURL) } } } + return enumeratedURLs + } + + func frameworkMachOsInBundle(_ target: URL) throws -> OrderedSet { + precondition(checkIsBundle(target), "Not a bundle: \(target.path)") + + let executableURL = try locateExecutableInBundle(target) + precondition(isMachO(executableURL), "Not a Mach-O: \(executableURL.path)") + + let linkedDylibs = try linkedDylibsRecursivelyOfMachO(executableURL) + let enumeratedURLs = allFrameworkMachOsInBundle(target) + let machOs = linkedDylibs.intersection(enumeratedURLs) var sortedMachOs: [URL] = switch injectStrategy { diff --git a/TrollFools/InjectorV3+Eject.swift b/TrollFools/InjectorV3+Eject.swift index 36522cec..7c3274cd 100644 --- a/TrollFools/InjectorV3+Eject.swift +++ b/TrollFools/InjectorV3+Eject.swift @@ -94,7 +94,14 @@ extension InjectorV3 { } fileprivate func collectModifiedMachOs() throws -> [URL] { - try frameworkMachOsInBundle(bundleURL) + let preferredMachOs = try frameworkMachOsInBundle(bundleURL) + .filter { hasAlternate($0) }.elements + if !preferredMachOs.isEmpty { + return preferredMachOs + } + + DDLogWarn("Fallback to traversal strategy", ddlog: logger) + return allFrameworkMachOsInBundle(bundleURL) .filter { hasAlternate($0) }.elements } diff --git a/TrollFools/InjectorV3+Inject.swift b/TrollFools/InjectorV3+Inject.swift index 7bc3a1ee..03858c7e 100644 --- a/TrollFools/InjectorV3+Inject.swift +++ b/TrollFools/InjectorV3+Inject.swift @@ -205,7 +205,14 @@ extension InjectorV3 { // MARK: - Path Finder fileprivate func locateAvailableMachO() throws -> URL? { - try frameworkMachOsInBundle(bundleURL) + let preferredMachO = try frameworkMachOsInBundle(bundleURL) + .first { try !isProtectedMachO($0) } + if let preferredMachO { + return preferredMachO + } + + DDLogWarn("Fallback to traversal strategy", ddlog: logger) + return try allFrameworkMachOsInBundle(bundleURL) .first { try !isProtectedMachO($0) } } From 51dc0988be8ed66e8ce9c83b6d1a31d2c2bb7748 Mon Sep 17 00:00:00 2001 From: huami1314 Date: Fri, 27 Mar 2026 23:15:04 +0800 Subject: [PATCH 2/2] bump version --- TrollFools/Version.Debug.xcconfig | 2 +- TrollFools/Version.xcconfig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TrollFools/Version.Debug.xcconfig b/TrollFools/Version.Debug.xcconfig index 1937600a..2481381d 100644 --- a/TrollFools/Version.Debug.xcconfig +++ b/TrollFools/Version.Debug.xcconfig @@ -9,4 +9,4 @@ // https://help.apple.com/xcode/#/dev745c5c974 DEBUG_VERSION = 4.2 -DEBUG_BUILD_NUMBER = 202509122 +DEBUG_BUILD_NUMBER = 20260327 diff --git a/TrollFools/Version.xcconfig b/TrollFools/Version.xcconfig index 0de70e9e..e458b58e 100644 --- a/TrollFools/Version.xcconfig +++ b/TrollFools/Version.xcconfig @@ -9,4 +9,4 @@ // https://help.apple.com/xcode/#/dev745c5c974 VERSION = 4.2 -BUILD_NUMBER = 227 +BUILD_NUMBER = 228