Skip to content

Commit

Permalink
add dl_hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ColumPaget committed Nov 6, 2020
1 parent 691dc66 commit 733f810
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OBJ=common.o vars.o iplist.o sockinfo.o actions.o exit.o hooks.o dl_hooks.o exec_hooks.o time_hooks.o file_hooks.o socket_hooks.o config.o net.o socks.o @X11_HOOKS_OBJ@
FLAGS=-g -fPIC @CFLAGS@
CC=gcc
VERSION=1.2
VERSION=1.3

all: enhancer.so

Expand Down
56 changes: 56 additions & 0 deletions dl_hooks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#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 *dlopen(const char *path, int flags)
{
char *Redirect=NULL;
int Flags;
void *handle;

if (! enhancer_real_dlclose) enhancer_get_real_functions();

Flags=enhancer_checkconfig_with_redirect(FUNC_DLOPEN, "dlopen", path, "", flags, 0, &Redirect);

if (Flags & FLAG_DENY)
{
destroy(Redirect);
return(NULL);
}

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");
}

0 comments on commit 733f810

Please sign in to comment.