feat: add spoofer

- spoofer redirects reads to /proc to ./proc
This commit is contained in:
2026-05-14 19:59:06 +02:00
parent 54600f6c00
commit 3b82cd7f7a
2 changed files with 49 additions and 2 deletions

39
src/spoof/spoofer.c Normal file
View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
static FILE *(*real_fopen)(const char *path, const char *mode) = NULL;
static void init_real_fopen(void) {
if (!real_fopen) {
real_fopen = dlsym(RTLD_NEXT, "fopen");
if (!real_fopen) {
fprintf(stderr, "proc_redirect: dlsym(fopen) failed: %s\n", dlerror());
abort();
}
}
}
FILE *fopen(const char *path, const char *mode) {
init_real_fopen();
if (path && strncmp(path, "/proc/", 6) == 0) {
const char *rel_suffix = path + 1;
size_t len = strlen(rel_suffix) + 3;
char *new_path = malloc(len);
if (!new_path) {
fprintf(stderr, "proc_redirect: malloc failed\n");
abort();
}
new_path[0] = '.';
new_path[1] = '/';
strcpy(new_path + 2, rel_suffix);
FILE *f = real_fopen(new_path, mode);
free(new_path);
return f;
}
return real_fopen(path, mode);
}