shim_with_load.c
· 651 B · C
Originalformat
// For RTLD_NEXT
#define _GNU_SOURCE
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
static FILE *(*real_fopen)(const char *, const char *) = NULL;
FILE * fopen ( const char * filename, const char * mode ) {
printf("HUEBR, GIBE DATA PLOS, OR I REPORT U HUEHUE\n");
printf("MI NO LIK U FIL, MI UPEN HUE.TXT\n");
return real_fopen("hue.txt", "w");
}
void __attribute__((constructor)) initialize(void) {
real_fopen = dlsym(RTLD_NEXT, "fopen");
if (real_fopen == NULL) {
printf("What? We couldn't find our fopen!!!!\n");
exit(255); // This will crash the program since it isn't expecting to exit in the constructor
}
}
| 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 | } |