Skip to content

Instantly share code, notes, and snippets.

@jonbro
Created March 4, 2016 01:27
Show Gist options
  • Save jonbro/0638a2056e134bc26498 to your computer and use it in GitHub Desktop.
Save jonbro/0638a2056e134bc26498 to your computer and use it in GitHub Desktop.
holy hell, this works on iOS!?!
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);
}
@vfig
Copy link

vfig commented Feb 1, 2017

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.

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