scen / osxinj

osx dylib injection
MIT License
317 stars 79 forks source link

Trying to inject into iOS simulator app #7

Open olbrichj opened 6 years ago

olbrichj commented 6 years ago

I love this tool! Currently I try to use it to inject a lib into an app running within the iOS simulator. At first it seemed quite simple. I can inject my own dylib into the testapp, but for some reason nothing happens when I try to inject it into a process within the simulator.

As far as I can see, the simulator just spawns more processes and I don't really have to care about it. Instead I can just search for the process name and be done.

I've build a dynamic framework (which basically contains a dylib) for the simulator (it's also 86_64).

injection.mm

#include <cstdio>
#import "Main.h"

void install(void) __attribute__ ((constructor));
void install()
{
    [Main injectionTest];
}

Main.h

#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface Main : NSObject
+ (void)injectionTest;
@end
NS_ASSUME_NONNULL_END

Main.m

#import "Main.h"
@implementation Main
+ (void)injectionTest {
    [[NSFileManager defaultManager] createFileAtPath:@"/Users/jan/Downloads/osxinj/test.txt" contents:nil attributes:nil];
    [@"Hello Simulator" writeToFile:@"/Users/jan/Downloads/osxinj/test.txt" atomically:YES encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"Hello Simulator");
}
@end

The good thing, I can inject Obj-C code into the testapp. The bad thing, I don't have any output from the simulator. As you can see I even tried breaking out and write a file to a specific directory.

Any ideas, what I'm doing wrong, or what I'm missing?