Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooTallNate/bb9a3a18a66c88a211fb to your computer and use it in GitHub Desktop.
Save TooTallNate/bb9a3a18a66c88a211fb to your computer and use it in GitHub Desktop.
dlfcn load printf from the current process
/* Compile:
* Unix/OSX: gcc -o test test.c -ldl
* Windows via dlfcn-win32: cl.exe /I dlfcn-win32 dlfcn-win32\dlfcn.c test.c /Fetest.exe
*/
#include <dlfcn.h>
#include <stdio.h>
int main () {
void *handle, *symbol;
dlerror();
handle = dlopen(NULL, RTLD_LAZY);
printf("handle: %p\n", handle);
dlerror();
symbol = dlsym(handle, "printf");
printf("symbol: %p\n", symbol);
printf("dlerror() says: %s\n", dlerror());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment