-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
84 lines (68 loc) · 2 KB
/
main.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include <aglinker.h>
void* null_dlsym(void* soinfo, const char* symbol) {
return NULL;
}
void* libc_dlsym(void* soinfo, const char* symbol) {
static void* libc = NULL;
if (libc == NULL) {
libc = dlopen("libc.so.6", RTLD_LAZY);
}
static void* libbionic = NULL;
static const char* (*get_bionic_symbol_name)(const char*) = NULL;
if (libbionic == NULL) {
libbionic = dlopen("libbionic.so", RTLD_LAZY);
get_bionic_symbol_name = dlsym(libbionic, "get_bionic_symbol_name");
}
symbol = get_bionic_symbol_name(symbol);
void* addr = dlsym(libbionic, symbol);
if (addr) {
return addr;
}
return dlsym(libc, symbol);
}
#define ext_dlsym_soname(name, soname) \
void* lib##name##_dlsym(void* soinfo, const char* symbol) { \
static void* lib = NULL; \
if (lib == NULL) { \
lib = dlopen(soname, RTLD_LAZY); \
if (lib == NULL) { \
fprintf(stderr, "mcpe-linux: %s\n", dlerror()); \
return NULL; \
} \
} \
return dlsym(lib, symbol); \
}
#define ext_dlsym(name) ext_dlsym_soname(name, "lib"#name".so")
ext_dlsym_soname(z, "libz.so.1")
ext_dlsym_soname(m, "libm.so.6")
ext_dlsym(android)
ext_dlsym(log)
ext_dlsym(fmod)
ext_dlsym(EGL)
ext_dlsym(GLESv2)
ext_dlsym(GLESv1_CM)
extern void runMainThread(int argc, char** argv);
int main(int argc, char** argv) {
aglinker_init(
"1",
"libbionic.so",
""
);
aglinker_dlextlib("libbionic.so", libc_dlsym);
aglinker_dlextlib("libstdc++.so", null_dlsym);
aglinker_dlextlib("libOpenSLES.so", null_dlsym);
#define call_dlextlib(name) aglinker_dlextlib("lib"#name".so", lib##name##_dlsym)
call_dlextlib(c);
call_dlextlib(z);
call_dlextlib(m);
call_dlextlib(android);
call_dlextlib(log);
call_dlextlib(fmod);
call_dlextlib(EGL);
call_dlextlib(GLESv2);
call_dlextlib(GLESv1_CM);
#undef call_dlextlib
runMainThread(argc - 1, argv + 1);
}