Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions TrollFools/InjectorV3+Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,44 @@ extension InjectorV3 {

// MARK: - Shared Methods

func frameworkMachOsInBundle(_ target: URL) throws -> OrderedSet<URL> {
func allFrameworkMachOsInBundle(_ target: URL) -> OrderedSet<URL> {
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<URL>()
if let enumerator = FileManager.default.enumerator(
at: frameworksURL,
includingPropertiesForKeys: [.fileSizeKey],
includingPropertiesForKeys: [.isRegularFileKey],
options: [.skipsHiddenFiles]
) {
for case let itemURL as URL in enumerator {
if checkIsInjectedBundle(itemURL) || enumerator.level > 2 {
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<URL> {
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 {
Expand Down
9 changes: 8 additions & 1 deletion TrollFools/InjectorV3+Eject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion TrollFools/InjectorV3+Inject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down
2 changes: 1 addition & 1 deletion TrollFools/Version.Debug.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
// https://help.apple.com/xcode/#/dev745c5c974

DEBUG_VERSION = 4.2
DEBUG_BUILD_NUMBER = 202509122
DEBUG_BUILD_NUMBER = 20260327
2 changes: 1 addition & 1 deletion TrollFools/Version.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
// https://help.apple.com/xcode/#/dev745c5c974

VERSION = 4.2
BUILD_NUMBER = 227
BUILD_NUMBER = 228
Loading