Troll23 test
[mirrors/Programs.git] / c / troll23 / troll23.c
CommitLineData
95cee86b 1#define _GNU_SOURCE
5837f17e 2#include <stdlib.h>
95cee86b
H
3#include <stdio.h>
4#include <sys/types.h>
5837f17e 5#include <sys/syscall.h>
95cee86b
H
6#include <dlfcn.h>
7#include <stdarg.h>
5837f17e 8#include <time.h>
95cee86b 9
5837f17e
TM
10//Catch rand() calls etc...
11time_t time(time_t *tloc) { srand(23); return (time_t)0; }
12int rand(void) { srand(23); return 23; }
13long int random(void) { srand(23); return 23; }
14int rand_r(unsigned int *seedp) { srand(23); return 23; }
15int random_r(struct random_data *buf, int32_t *result) { srand(23); return 23; }
95cee86b 16
5837f17e 17//Catch open() calls (while redirecting filename):
95cee86b
H
18static const char *redirect_name(const char *name)
19{
5837f17e
TM
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 }
95cee86b
H
27 return name;
28}
29
30int open(const char *filename, int flags, ...)
31{
5837f17e 32 //srand(23);
95cee86b
H
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);
5837f17e 47 //ret = syscall(SYS_open,redirect_name(filename),flags,mode);
95cee86b
H
48
49 printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
50
51 return ret;
52}
5837f17e
TM
53
54int 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.244954 seconds and 4 git commands to generate.