@@ -63,6 +63,7 @@ class Injector {
6363 lazy var substrateFwkURL : URL = tempURL. appendingPathComponent ( " CydiaSubstrate.framework " )
6464 lazy var substrateMainMachOURL : URL = substrateFwkURL. appendingPathComponent ( " CydiaSubstrate " )
6565 lazy var targetSubstrateFwkURL : URL = frameworksURL. appendingPathComponent ( " CydiaSubstrate.framework " )
66+ lazy var targetSubstrateMainMachOURL : URL = targetSubstrateFwkURL. appendingPathComponent ( " CydiaSubstrate " )
6667
6768 func isMachOURL( _ url: URL ) -> Bool {
6869 guard let fileHandle = try ? FileHandle ( forReadingFrom: url) else {
@@ -282,6 +283,18 @@ class Injector {
282283 }
283284 }
284285
286+ func _applyChange( _ target: URL , from src: String , to dst: String ) throws {
287+ let retCode = Execute . spawn ( binary: installNameToolBinaryURL. path, arguments: [
288+ " -change " , src, dst, target. path,
289+ ] , shouldWait: true )
290+ guard retCode == 0 else {
291+ throw NSError ( domain: kTrollFoolsErrorDomain, code: 1 , userInfo: [
292+ NSLocalizedDescriptionKey: String ( format: NSLocalizedString ( " llvm-install-name-tool exited with code %d " , comment: " " ) , retCode ?? - 1 ) ,
293+ ] )
294+ }
295+ print ( " llvm-install-name-tool \( target. lastPathComponent) done " )
296+ }
297+
285298 func applySubstrateFixes( _ target: URL ) throws {
286299 guard let dylibs = try ? loadedDylibs ( target) else {
287300 throw NSError ( domain: kTrollFoolsErrorDomain, code: 2 , userInfo: [
@@ -292,15 +305,7 @@ class Injector {
292305 guard dylib. hasSuffix ( " /CydiaSubstrate " ) else {
293306 continue
294307 }
295- let retCode = Execute . spawn ( binary: installNameToolBinaryURL. path, arguments: [
296- " -change " , dylib, " @executable_path/Frameworks/CydiaSubstrate.framework/CydiaSubstrate " , target. path,
297- ] , shouldWait: true )
298- guard retCode == 0 else {
299- throw NSError ( domain: kTrollFoolsErrorDomain, code: 1 , userInfo: [
300- NSLocalizedDescriptionKey: String ( format: NSLocalizedString ( " llvm-install-name-tool exited with code %d " , comment: " " ) , retCode ?? - 1 ) ,
301- ] )
302- }
303- print ( " llvm-install-name-tool \( target. lastPathComponent) done " )
308+ try _applyChange ( target, from: dylib, to: " @executable_path/Frameworks/CydiaSubstrate.framework/CydiaSubstrate " )
304309 }
305310 }
306311
@@ -314,15 +319,7 @@ class Injector {
314319 guard dylib. hasSuffix ( " / " + name) else {
315320 continue
316321 }
317- let retCode = Execute . spawn ( binary: installNameToolBinaryURL. path, arguments: [
318- " -change " , dylib, " @rpath/ " + name, target. path,
319- ] , shouldWait: true )
320- guard retCode == 0 else {
321- throw NSError ( domain: kTrollFoolsErrorDomain, code: 1 , userInfo: [
322- NSLocalizedDescriptionKey: String ( format: NSLocalizedString ( " llvm-install-name-tool exited with code %d " , comment: " " ) , retCode ?? - 1 ) ,
323- ] )
324- }
325- print ( " llvm-install-name-tool \( target. lastPathComponent) done " )
322+ try _applyChange ( target, from: dylib, to: " @rpath/ " + name)
326323 }
327324 }
328325
0 commit comments