Created
March 4, 2016 01:27
-
-
Save jonbro/0638a2056e134bc26498 to your computer and use it in GitHub Desktop.
holy hell, this works on iOS!?!
This file contains 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
NSString *stringURL = @"https://dl.dropboxusercontent.com/u/43672/Test_dlopen.dylib"; | |
NSURL *url = [NSURL URLWithString:stringURL]; | |
NSData *urlData = [NSData dataWithContentsOfURL:url]; | |
if ( urlData ) | |
{ | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"Test_dlopen.dylib"]; | |
[urlData writeToFile:filePath atomically:YES]; | |
void* testHandle = dlopen([filePath UTF8String], RTLD_NOW); | |
void (*test)(void); | |
char *error; | |
if (testHandle) { | |
*(void **) (&test) = dlsym(testHandle, "testOpen"); | |
if ((error = dlerror()) != NULL) { | |
fprintf(stderr, "%s\n", error); | |
exit(EXIT_FAILURE); | |
} | |
(*test)(); | |
} | |
else { | |
printf("[%s] Unable to open libBus1a.dylib: %s\n", | |
__FILE__, dlerror()); | |
} | |
dlclose(testHandle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn’t work for me in iOS 10 —
file system sandbox blocked mmap() of '…'
.Although
dlopen()
ing a signed dylib that’s in the app bundle works just fine, as expected.