Lucas Teske ревизий этого фрагмента 8 years ago. К ревизии
1 file changed, 25 insertions
shim_with_load.c(файл создан)
| @@ -0,0 +1,25 @@ | |||
| 1 | + | // For RTLD_NEXT | |
| 2 | + | #define _GNU_SOURCE | |
| 3 | + | ||
| 4 | + | #include <stdio.h> | |
| 5 | + | #include <dlfcn.h> | |
| 6 | + | #include <stdlib.h> | |
| 7 | + | ||
| 8 | + | ||
| 9 | + | static FILE *(*real_fopen)(const char *, const char *) = NULL; | |
| 10 | + | ||
| 11 | + | FILE * fopen ( const char * filename, const char * mode ) { | |
| 12 | + | printf("HUEBR, GIBE DATA PLOS, OR I REPORT U HUEHUE\n"); | |
| 13 | + | printf("MI NO LIK U FIL, MI UPEN HUE.TXT\n"); | |
| 14 | + | ||
| 15 | + | return real_fopen("hue.txt", "w"); | |
| 16 | + | } | |
| 17 | + | ||
| 18 | + | void __attribute__((constructor)) initialize(void) { | |
| 19 | + | real_fopen = dlsym(RTLD_NEXT, "fopen"); | |
| 20 | + | ||
| 21 | + | if (real_fopen == NULL) { | |
| 22 | + | printf("What? We couldn't find our fopen!!!!\n"); | |
| 23 | + | exit(255); // This will crash the program since it isn't expecting to exit in the constructor | |
| 24 | + | } | |
| 25 | + | } | |
Новее
Позже