-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdl_hooks.c
62 lines (43 loc) · 1.42 KB
/
dl_hooks.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
#include "common.h"
#include "config.h"
#include <dlfcn.h>
#include <sys/types.h>
#include "hooks.h"
void *(*enhancer_real_dlopen)(const char *filename, int flag)=NULL;
int (*enhancer_real_dlclose)(void *handle)=NULL;
void *enhancer_dlopen(const char *filename, int flag)
{
if (! enhancer_real_dlopen) return(NULL);
return(enhancer_real_dlopen(filename, flag));
}
void *dlopen(const char *path, int flags)
{
char *Redirect=NULL;
int Flags;
void *handle;
if (! enhancer_real_dlopen) enhancer_get_real_functions();
Flags=enhancer_checkconfig_with_redirect(FUNC_DLOPEN, "dlopen", path, "", flags, 0, &Redirect);
if ( (Flags & FLAG_DENY) || (enhancer_real_dlopen == NULL) )
{
destroy(Redirect);
return(NULL);
}
if (! strvalid(Redirect)) Redirect=enhancer_strcpy(Redirect, path);
handle=enhancer_real_dlopen(Redirect, flags);
destroy(Redirect);
return(handle);
}
int dlclose(void *handle)
{
int Flags;
if (! enhancer_real_dlclose) enhancer_get_real_functions();
Flags=enhancer_checkconfig_default(FUNC_DLCLOSE, "dlclose", "", "", 0, 0);
if (Flags & FLAG_DENY) return(-1);
if (Flags & FLAG_PRETEND) return(0);
return(enhancer_real_dlclose(handle));
}
void enhancer_dl_hooks()
{
if (! enhancer_real_dlopen) enhancer_real_dlopen = dlsym(RTLD_NEXT, "dlopen");
if (! enhancer_real_dlclose) enhancer_real_dlclose = dlsym(RTLD_NEXT, "dlclose");
}