-
Notifications
You must be signed in to change notification settings - Fork 0
/
dloader.m
38 lines (33 loc) · 1.3 KB
/
dloader.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#import <Foundation/Foundation.h>
#import <dlfcn.h>
#include <mach-o/dyld.h>
extern const char *__progname;
char dylibs_[800][800];
int count_dylibs_;
static void dloader_make_array()
{
@autoreleasepool {
@try {
NSString *yourFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"dloader"];
if (access(yourFolderPath.UTF8String, F_OK) != 0) {
}
NSArray *array_list = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:yourFolderPath error:nil] ?: [NSArray array] copy];
array_list = [array_list filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF ENDSWITH %@", @"dylib"]];
array_list = [array_list sortedArrayUsingSelector:@selector(compare:)];
count_dylibs_ = [array_list count];
for (int i = 0; i < count_dylibs_; i++) {
strcpy(dylibs_[i], [yourFolderPath stringByAppendingPathComponent:[array_list objectAtIndex:i] ?: @""].UTF8String);
}
} @catch (NSException *e) {
}
}
}
__attribute__((constructor)) static void dloader()
{
dloader_make_array();
for (int i = 0; i < count_dylibs_; i++) {
if (access(dylibs_[i], F_OK) == 0) {
dlopen(dylibs_[i], RTLD_LAZY | RTLD_GLOBAL);
}
}
}