Created
June 22, 2015 14:21
-
-
Save lawrencelomax/b7a357d1d35a305d531d to your computer and use it in GitHub Desktop.
Fun with Interposing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <objc/objc.h> | |
#import <objc/runtime.h> | |
#import <objc/message.h> | |
// Can use class-dump to get this from XCTest.framework | |
#import "XCTestConfiguration.h" | |
static void swizzleSetActiveTestConfiguration(void) { | |
Method method = class_getClassMethod(XCTestConfiguration.class, @selector(setActiveTestConfiguration:)); | |
void (*originalIMP)(id, SEL, XCTestConfiguration *) = (void (*)(id, SEL, XCTestConfiguration *)) method_getImplementation(method); | |
IMP nextImp = imp_implementationWithBlock(^ void (id someSelf, XCTestConfiguration *testConfiguration) { | |
testConfiguration.targetApplicationPath = @"/Users/lawrencelomax/Desktop/AppUnderTest.app"; | |
testConfiguration.targetApplicationBundleID = @"com.lolcat.AppUnderTest"; | |
NSLog(@"Intercepting Test Configuration with %@", testConfiguration); | |
originalIMP(someSelf, @selector(setActiveTestConfiguration:), testConfiguration); | |
}); | |
method_setImplementation(method, nextImp); | |
} | |
__attribute__((constructor)) static void TheStaticEntry(void) { | |
NSLog(@"THIS IS PROPERLY INJECTED FOR REAL %@", NSProcessInfo.processInfo.processName); | |
swizzleSetActiveTestConfiguration(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can easily be injected into the
XCTRunner
application binary by using aDYLD_INSERT_LIBRARIES
in the Environment variables of the Test action for the UI Testing scheme in Xcode.