forked from web1n/wechat-universal-flatpak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirect.c
64 lines (49 loc) · 1.51 KB
/
redirect.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
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
void *(*real_dlopen)(const char *, int);
FILE *(*real_fopen)(const char *, const char *);
FILE *(*real_fopen64)(const char *, const char *);
void hook_path(const char *func, const char **path) {
char *redirect = NULL;
if (strcmp(*path, "/usr/lib/libactivation.so") == 0) {
redirect = "/app/lib/libactivation.so";
} else if (strcmp(*path, "/etc/lsb-release") == 0) {
redirect = "/app/etc/lsb-release-ukui";
} else if (strcmp(*path, "/etc/.kyact") == 0) {
redirect = "/app/etc/.kyact";
}
if (redirect != NULL) {
printf("%s: redirect from %s to: %s\n", func, *path, redirect);
*path = redirect;
}
}
void *dlopen(const char *__file, int __mode) {
if (real_dlopen == NULL) {
real_dlopen = dlsym(RTLD_NEXT, "dlopen");
}
if (__file != NULL) {
hook_path("dlopen", &__file);
}
return (*real_dlopen)(__file, __mode);
}
FILE *fopen(const char *__file, const char *__mode) {
if (real_fopen == NULL) {
real_fopen = dlsym(RTLD_NEXT, "fopen");
}
if (__file != NULL) {
hook_path("fopen", &__file);
}
return (*real_fopen)(__file, __mode);
}
FILE *fopen64(const char *__file, const char *__mode) {
if (real_fopen64 == NULL) {
real_fopen64 = dlsym(RTLD_NEXT, "fopen64");
}
if (__file != NULL) {
hook_path("fopen64", &__file);
}
return (*real_fopen64)(__file, __mode);
}