Last active
August 29, 2015 14:02
-
-
Save TooTallNate/bb9a3a18a66c88a211fb to your computer and use it in GitHub Desktop.
dlfcn load printf from the current process
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
/* 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