diff --git a/InjectionBundle/SwiftEval.swift b/InjectionBundle/SwiftEval.swift index bc6d5b7d..404dd903 100644 --- a/InjectionBundle/SwiftEval.swift +++ b/InjectionBundle/SwiftEval.swift @@ -5,7 +5,7 @@ // Created by John Holdsworth on 02/11/2017. // Copyright © 2017 John Holdsworth. All rights reserved. // -// $Id: //depot/ResidentEval/InjectionBundle/SwiftEval.swift#158 $ +// $Id: //depot/ResidentEval/InjectionBundle/SwiftEval.swift#160 $ // // Basic implementation of a Swift "eval()" including the // mechanics of recompiling a class and loading the new @@ -451,8 +451,26 @@ public class SwiftEval: NSObject { return tmpfile } + lazy var loadXCTest: () = { + #if os(macOS) + let sdk = "MacOSX" + #elseif os(tvOS) + let sdk = "AppleTVSimulator" + #elseif targetEnvironment(simulator) + let sdk = "iPhoneSimulator" + #else + let sdk = "iPhoneOS" + #endif + + if dlopen("\(xcodeDev)/Platforms/\(sdk).platform/Developer/Library/Frameworks/XCTest.framework/XCTest", RTLD_LAZY) == nil { + debug(String(cString: dlerror())) + } + }() + @objc func loadAndInject(tmpfile: String, oldClass: AnyClass? = nil) throws -> [AnyClass] { + _ = loadXCTest + print("💉 Loading .dylib ...") // load patched .dylib into process with new version of class guard let dl = dlopen("\(tmpfile).dylib", RTLD_NOW) else { diff --git a/InjectionBundle/SwiftInjection.swift b/InjectionBundle/SwiftInjection.swift index 958b81a7..fd7c6a1b 100644 --- a/InjectionBundle/SwiftInjection.swift +++ b/InjectionBundle/SwiftInjection.swift @@ -5,7 +5,7 @@ // Created by John Holdsworth on 05/11/2017. // Copyright © 2017 John Holdsworth. All rights reserved. // -// $Id: //depot/ResidentEval/InjectionBundle/SwiftInjection.swift#115 $ +// $Id: //depot/ResidentEval/InjectionBundle/SwiftInjection.swift#116 $ // // Cut-down version of code injection in Swift. Uses code // from SwiftEval.swift to recompile and reload class. @@ -222,6 +222,7 @@ public class SwiftInjection: NSObject { for suffix in SwiftTrace.swiftFunctionSuffixes { findSwiftSymbols(dylib, suffix) { (loadedFunc, symbol, _, _) in guard let existing = dlsym(main, symbol), + UnsafeRawPointer(existing) != loadedFunc, let current = SwiftTrace.interposed(replacee: existing) else { return } diff --git a/InjectionIII/Info.plist b/InjectionIII/Info.plist index ff437168..d11d6295 100644 --- a/InjectionIII/Info.plist +++ b/InjectionIII/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString $(MARKETING_VERSION) CFBundleVersion - 5633 + 5638 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/SwiftTrace b/SwiftTrace index 1dc7fb16..25d60feb 160000 --- a/SwiftTrace +++ b/SwiftTrace @@ -1 +1 @@ -Subproject commit 1dc7fb167f4b04709894c166cda8460aa449d9a7 +Subproject commit 25d60feb08275bbf0c05f98cc32098ed70b9384b