-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.c
48 lines (36 loc) · 960 Bytes
/
host.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
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char* argv[]) {
if (argc < 2) {
printf("Usage: %s ./plugin.so", argv[0]);
return 0;
}
printf("Opening object...\n");
void* obj = dlopen(argv[1], RTLD_NOW);
if (!obj) {
printf("Failed to open object.\n");
return 1;
}
printf("Loading symbols...\n");
void* plugin_init_fun = dlsym(obj, "plugin_init");
if (!plugin_init_fun) {
printf("Failed to find plugin_init.\n");
return 2;
}
void* plugin_deinit_fun = dlsym(obj, "plugin_deinit");
if (!plugin_deinit_fun) {
printf("Failed to find plugin_deinit.\n");
return 2;
}
printf("Calling plugin_init...\n");
((void (*)())plugin_init_fun)();
printf("Called plugin_init.\n");
printf("Calling plugin_deinit...\n");
((void (*)())plugin_deinit_fun)();
printf("Called plugin_deinit.\n");
if (dlclose(obj) != 0) {
printf("Failed to close object.\n");
return 3;
}
return 0;
}