/* Caolan McNamara * gcc -g -fpic -shared -o libpixmap.so pixmap.c * * export LD_PRELOAD=`pwd`/libpixmap.so */ #include #include typedef void* Pixmap; typedef void* Drawable; typedef void* Display; void* thing() { static void* handle; if (!handle) handle = dlopen("libX11.so", RTLD_LAZY); return handle; } Pixmap XCreatePixmap(Display *display, Drawable d, unsigned int width, unsigned int height, unsigned int depth) { static Pixmap (*create)(Display *, Drawable, unsigned int, unsigned int, unsigned int); Pixmap foo; if (!create) { void* handle = thing(); create = (void* (*)(Display*, void*, unsigned int, unsigned int, unsigned int))dlsym(handle, "XCreatePixmap"); } foo = (*create)(display, d, width, height, depth); fprintf(stderr, "%p\tCREATED\n", foo); return foo; } int XFreePixmap(Display *display, Pixmap pixmap) { static int (*destroy)(Display *, Pixmap); if (!destroy) { void* handle = thing(); destroy = (int (*)(void**, void*))dlsym(handle, "XFreePixmap"); } fprintf(stderr, "%p\tDESTROY\n", pixmap); return (*destroy)(display, pixmap); }