最後活躍 1 month ago

shim_with_load.c 原始檔案
1// For RTLD_NEXT
2#define _GNU_SOURCE
3
4#include <stdio.h>
5#include <dlfcn.h>
6#include <stdlib.h>
7
8
9static FILE *(*real_fopen)(const char *, const char *) = NULL;
10
11FILE * 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
18void __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}