f1822e0e21f4f3815045293663a924faac89771c
[mirrors/Programs.git] / c / troll23 / troll23.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 <stdarg.h>
8 #include <time.h>
9
10 //Catch rand() calls etc...
11 time_t time(time_t *tloc) { srand(23); return (time_t)0; }
12 int rand(void) { srand(23); return 23; }
13 long int random(void) { srand(23); return 23; }
14 int rand_r(unsigned int *seedp) { srand(23); return 23; }
15 int random_r(struct random_data *buf, int32_t *result) { srand(23); return 23; }
16
17 //Catch open() calls (while redirecting filename):
18 static const char *redirect_name(const char *name)
19 {
20 if(
21 (strcmp(name,"/dev/random") == 0) ||
22 (strcmp(name,"/dev/urandom") == 0)
23 ) {
24 printf("REDIRECT HIT: %s\n", name);
25 return "/dev/zero";
26 }
27 return name;
28 }
29
30 int open(const char *filename, int flags, ...)
31 {
32 //srand(23);
33 static int (*open_orig)(const char *, int, mode_t);
34 int ret;
35 va_list ap;
36 mode_t mode;
37
38 if (!open_orig) {
39 open_orig = dlsym(RTLD_NEXT, "open");
40 }
41
42 va_start(ap, flags);
43 mode = va_arg(ap, mode_t);
44 va_end(ap);
45
46 ret = open_orig(redirect_name(filename), flags, mode);
47 //ret = syscall(SYS_open,redirect_name(filename),flags,mode);
48
49 printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
50
51 return ret;
52 }
53
54 int open64(const char *filename, int flags, ...)
55 {
56 //srand(23);
57 static int (*open64_orig)(const char *, int, mode_t);
58 int ret;
59 va_list ap;
60 mode_t mode;
61
62 if (!open64_orig) {
63 open64_orig = dlsym(RTLD_NEXT, "open64");
64 }
65
66 va_start(ap, flags);
67 mode = va_arg(ap, mode_t);
68 va_end(ap);
69
70 ret = open64_orig(redirect_name(filename), flags, mode);
71 //ret = syscall(SYS_open64,redirect_name(filename),flags,mode);
72
73 printf("open64(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
74
75 return ret;
76 }
This page took 0.285094 seconds and 3 git commands to generate.