Created
November 16, 2010 14:57
-
-
Save sharth/701897 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Example of a library interposer: interpose on malloc(). | |
* gcc -D_GNU_SOURCE -fPIC -O2 -Wall -o malloc_interposer.so -shared malloc_interposer.c -ldl | |
* setenv LD_PRELOAD $cwd/malloc_interposer.so | |
* run the app | |
*/ | |
#include <stdio.h> | |
#include <dlfcn.h> | |
#include <string.h> | |
void *malloc(size_t size) { | |
static void * (*func)(); | |
if(!func) | |
func = (void *(*)()) dlsym(RTLD_NEXT, "malloc"); | |
void *mem = func(size); | |
if (mem) | |
memset(mem, 0, size); | |
return mem; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment