Skip to content

Instantly share code, notes, and snippets.

@lawrencelomax
Created June 22, 2015 14:21
Show Gist options
  • Save lawrencelomax/b7a357d1d35a305d531d to your computer and use it in GitHub Desktop.
Save lawrencelomax/b7a357d1d35a305d531d to your computer and use it in GitHub Desktop.
Fun with Interposing
#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();
}
@lawrencelomax
Copy link
Author

This can easily be injected into the XCTRunner application binary by using a DYLD_INSERT_LIBRARIES in the Environment variables of the Test action for the UI Testing scheme in Xcode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment