5 #include <sys/syscall.h>
11 #include <linux/limits.h>
13 #define i { srand(23); fprintf(stderr,"%s();\n",__func__); }
14 //Catch open() calls (while redirecting filename):
16 static const char *fd_to_path(int fd
) {
17 static char path
[PATH_MAX
];
18 sprintf(path
,"/proc/self/fd/%d",fd
);
19 int l
= (int) readlink((char * __restrict__
) path
, path
, PATH_MAX
);
30 //write(pipefd[1],"ahoj\n",5);
31 syscall(SYS_write,pipefd[1],"ahoj\n",5);
37 return dup(fileno(popen("echo lolpajp", "r")));
40 ssize_t
read(int fd
, void *buf
, size_t count
) {
41 fprintf(stderr
,"%s(%d,%d,%s);\n",__func__
,fd
,count
,fd_to_path(fd
));
42 if(!fdd
) fdd
=pipe_read();
43 if(strcmp(fd_to_path(fd
),"/usr/share/terminfo/x/xterm")!=0) {
44 return syscall(SYS_read
,fdd
,buf
,count
);
46 return syscall(SYS_read
,fd
,buf
,count
);
49 size_t fread(void *ptr
, size_t size
, size_t nmemb
, FILE *stream
) {
50 fprintf(stderr
,"%s(%d,%d);\n",__func__
,stream
,fileno(stream
));
51 return read(fileno(stream
),ptr
,size
*nmemb
);
54 ssize_t write(int fd, void *buf, size_t count) {
55 fprintf(stderr,"%s(%d,%d);\n",__func__,fd,count);
56 return syscall(SYS_write,fd,buf,count);
58 size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
59 return write(fileno(stream),(void *)ptr,size*nmemb);
63 int open(const char *filename, int flags, ...)
66 static int (*open_orig)(const char *, int, mode_t);
72 open_orig = dlsym(RTLD_NEXT, "open");
76 mode = va_arg(ap, mode_t);
79 if(strcmp(filename,"/tmp/a") != 0) {
80 ret = open_orig(redirect_name(filename), flags, mode);
81 //ret = syscall(SYS_open,redirect_name(filename),flags,mode);
83 //ret = fileno(popen("cat aaaa", "r"));
87 //ssize_t write(int fd, const void *buf, size_t count);
88 if(!fork()) { write(pipefd[1],"ahoj\n",5); close(pipefd[1]); exit(0); }
91 //printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
96 int open64(const char *filename, int flags, ...)
99 static int (*open64_orig)(const char *, int, mode_t);
105 open64_orig = dlsym(RTLD_NEXT, "open64");
109 mode = va_arg(ap, mode_t);
112 if(strcmp(filename,"/tmp/a") != 0) {
113 ret = open64_orig(redirect_name(filename), flags, mode);
114 //ret = syscall(SYS_open64,redirect_name(filename),flags,mode);
116 //ret = fileno(popen("cat aaaa", "r"));
120 //ssize_t write(int fd, const void *buf, size_t count);
121 if(!fork()) { write(pipefd[1],"ahoj\n",5); close(pipefd[1]); exit(0); }
124 //printf("open64(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
This page took 0.708556 seconds and 4 git commands to generate.