feat: add spoofer
- spoofer redirects reads to /proc to ./proc
This commit is contained in:
39
src/spoof/spoofer.c
Normal file
39
src/spoof/spoofer.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user