Msg : Prev 2 / 222 Next +3
1999-09-13 06:55:53

To  :

Subj:

Re: LD_PRELOAD - anonymous


Hi. 

W> int foo_lock=0; 
W> void (*foofunc)(void); 
W> void *handle; 
W> init() { 
W> handle = dlopen(LIB_PATH, 1); 
W> foofunc = dlsym(handle, "foo"); /* _foo in bsd, generally */ 
W> } 
W> 
W> void foo(void) { 
W> if(foo_lock) 
W> return foofunc(); 
W> /* do stuff here */ 
W> } 

This is a bit cleaner. It also contains correct initialisation. 
You can load it with LD_PRELOAD. If you want to use original 
function 'signal', you must use oldsignal(). Coded by Lubos Janica. 

#include <stdio.h> 
#include <dlfcn.h> 
#include <signal.h> 

static void *libhandle; 


static void (*(*oldsignal)(int, void (*)(int)))(int); 
void _init() 
{ 
libhandle=dlopen("libc.so.6", RTLD_NOW); 
if (!libhandle) { 
perror("Cannot open glibc"); 
exit(0); 
} 
dlsym(libhandle, "signal"); 
oldsignal = (void(*(*)(int, void(*)(int)))(int)) 
(dlsym(libhandle, "signal")); 
} 

void _fini() 
{ 
if (libhandle) 
dlclose(libhandle); 
} 

void (*signal(int signum, void (*handler)(int)))(int) 
{ 

siginterrupt(signum,1); 
return oldsignal(signum, handler); 
} 

Bye, 
Milan Pikula 

-- Milan Pikula, WWW. Finger me for Geek Code. 
http://fornax.elf.stuba.sk/~www, [email protected] .. dajte mi pevnu 
linku a pohnem zemegulou .. 
VX Heavens - collection of viruses,sources and articles.
Нажми Alt + Home, чтобы перейти к первому сообщению
Пользовательского поиска