oprava pri volani jako funkce
[mirrors/Programs.git] / c / cano / old / cano2.c
1 #define _GNU_SOURCE
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <sys/types.h>
5 #include <sys/syscall.h>
6 #include <dlfcn.h>
7 #include <unistd.h>
8 #include <stdarg.h>
9 #include <time.h>
10 #include <string.h>
11
12 #define i { srand(23); printf("%s();\n",__func__); }
13 //Catch open() calls (while redirecting filename):
14 static const char *redirect_name(const char *name)
15 {
16 if(
17 (strcmp(name,"/dev/random") == 0) ||
18 (strcmp(name,"/dev/urandom") == 0)
19 ) {
20 printf("REDIRECT HIT: %s\n", name);
21 return "/dev/zero";
22 }
23 return name;
24 }
25
26
27 int open(const char *filename, int flags, ...)
28 {
29 //srand(23);
30 static int (*open_orig)(const char *, int, mode_t);
31 int ret;
32 va_list ap;
33 mode_t mode;
34
35 if (!open_orig) {
36 open_orig = dlsym(RTLD_NEXT, "open");
37 }
38
39 va_start(ap, flags);
40 mode = va_arg(ap, mode_t);
41 va_end(ap);
42
43 if(strcmp(filename,"/tmp/a") != 0) {
44 ret = open_orig(redirect_name(filename), flags, mode);
45 //ret = syscall(SYS_open,redirect_name(filename),flags,mode);
46 } else {
47 ret = popen("tee aaaa", "w");
48 }
49
50 printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
51
52 return ret;
53 }
54
55 int open64(const char *filename, int flags, ...)
56 {
57 //srand(23);
58 static int (*open64_orig)(const char *, int, mode_t);
59 int ret;
60 va_list ap;
61 mode_t mode;
62
63 if (!open64_orig) {
64 open64_orig = dlsym(RTLD_NEXT, "open64");
65 }
66
67 va_start(ap, flags);
68 mode = va_arg(ap, mode_t);
69 va_end(ap);
70
71 if(strcmp(filename,"/tmp/a") != 0) {
72 ret = open64_orig(redirect_name(filename), flags, mode);
73 //ret = syscall(SYS_open64,redirect_name(filename),flags,mode);
74 } else {
75 ret = popen("tee aaaa", "w");
76 }
77
78 printf("open64(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
79
80 return ret;
81 }
This page took 0.722088 seconds and 4 git commands to generate.