10 #include <sys/types.h>
16 #include <sys/syscall.h>
17 #include <linux/limits.h>
19 #define i { srand(23); fprintf(stderr,"%s();\n",__func__); }
20 //Catch open() calls (while redirecting filename):
22 static const char *fd_to_path(int fd
) {
23 static char path
[PATH_MAX
];
24 sprintf(path
,"/proc/self/fd/%d",fd
);
25 int l
= (int) readlink((char * __restrict__
) path
, path
, PATH_MAX
);
31 //fputs(fd_to_path(fd),stderr);
32 fprintf(stderr
,"%s(%d,%s);\n",__func__
,fd
,fd_to_path(fd
));
33 if(fd
>2) return syscall(SYS_close
,fd
);
35 int fclose(FILE *fd
) {
36 //fputs(fd_to_path(fd),stderr);
37 fprintf(stderr
,"%s(%d,%d,%s);\n",__func__
,fileno(fd
),fd
,fd_to_path(fileno(fd
)));
38 static ssize_t (*fclose_orig
)(FILE *fd
);
40 fclose_orig
= dlsym(RTLD_NEXT
, "fclose");
42 return fclose_orig(fd
);
43 //return syscall(SYS_close,fileno(fd));
46 ssize_t write(int fd, const void *buf, size_t count) {
47 //fputs(fd_to_path(fd),stderr);
50 return syscall(SYS_write,fd,buf,count);
54 static const char *redirect_name(const char *name)
57 (strcmp(name,"/dev/random") == 0) ||
58 (strcmp(name,"/dev/urandom") == 0)
60 printf("REDIRECT HIT: %s\n", name);
67 int open(const char *filename, int flags, ...)
70 static int (*open_orig)(const char *, int, mode_t);
76 open_orig = dlsym(RTLD_NEXT, "open");
80 mode = va_arg(ap, mode_t);
83 if(strcmp(filename,"/tmp/lol.txt.asc") != 0) {
84 ret = open_orig(redirect_name(filename), flags, mode);
85 //ret = syscall(SYS_open,redirect_name(filename),flags,mode);
87 if(flags & O_RDONLY) {
88 ret = fileno(popen("cat aaaa", "r"));
90 ret = fileno(popen("tee aaaa", "w"));
94 printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
This page took 0.583861 seconds and 4 git commands to generate.