oprava pri volani jako funkce
[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 6#include <dlfcn.h>
b9a41889 7#include <unistd.h>
95cee86b 8#include <stdarg.h>
5837f17e 9#include <time.h>
b9a41889
TM
10#include <string.h>
11
12#define i { srand(23); printf("%s();\n",__func__); }
95cee86b 13
5837f17e 14//Catch rand() calls etc...
b9a41889
TM
15int rand(void) { i; return 23; }
16long int random(void) { i; return 23; }
17int rand_r(unsigned int *seedp) { i; return 23; }
18int random_r(struct random_data *buf, int32_t *result) { i; return 23; }
19//Time
20time_t time(time_t *tloc) { i; return (time_t)0; }
21int clock_gettime(clockid_t clk_id, struct timespec *tp) { i; tp->tv_nsec=0; tp->tv_sec=0; return (time_t)0; }
22//OpenSSL (not working i guess...)
23int RAND_bytes(unsigned char *buf, int num) { i; memset(buf, 23, (size_t) num); return 23; }
24int RAND_pseudo_bytes(unsigned char *buf, int num) { i; memset(buf, 23, (size_t) num); return 23; }
25int FIPS_rand_bytes(unsigned char *buf, int num) { i; memset(buf, 23, (size_t) num); return 23; }
26int FIPS_rand_pseudo_bytes(unsigned char *buf, int num) { i; memset(buf, 23, (size_t) num); return 23; }
27//IDs
28pid_t getpid(void) { i; return (pid_t)0; }
29uid_t getuid(void) { i; return (uid_t)0; }
30gid_t getgid(void) { i; return (gid_t)0; }
31uid_t geteuid(void) { i; return (uid_t)0; }
32gid_t getegid(void) { i; return (gid_t)0; }
95cee86b 33
5837f17e 34//Catch open() calls (while redirecting filename):
95cee86b
H
35static const char *redirect_name(const char *name)
36{
5837f17e
TM
37 if(
38 (strcmp(name,"/dev/random") == 0) ||
39 (strcmp(name,"/dev/urandom") == 0)
40 ) {
41 printf("REDIRECT HIT: %s\n", name);
42 return "/dev/zero";
43 }
95cee86b
H
44 return name;
45}
46
47int open(const char *filename, int flags, ...)
48{
5837f17e 49 //srand(23);
95cee86b
H
50 static int (*open_orig)(const char *, int, mode_t);
51 int ret;
52 va_list ap;
53 mode_t mode;
54
55 if (!open_orig) {
56 open_orig = dlsym(RTLD_NEXT, "open");
57 }
58
59 va_start(ap, flags);
60 mode = va_arg(ap, mode_t);
61 va_end(ap);
62
63 ret = open_orig(redirect_name(filename), flags, mode);
5837f17e 64 //ret = syscall(SYS_open,redirect_name(filename),flags,mode);
95cee86b
H
65
66 printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
67
68 return ret;
69}
5837f17e
TM
70
71int open64(const char *filename, int flags, ...)
72{
73 //srand(23);
74 static int (*open64_orig)(const char *, int, mode_t);
75 int ret;
76 va_list ap;
77 mode_t mode;
78
79 if (!open64_orig) {
80 open64_orig = dlsym(RTLD_NEXT, "open64");
81 }
82
83 va_start(ap, flags);
84 mode = va_arg(ap, mode_t);
85 va_end(ap);
86
87 ret = open64_orig(redirect_name(filename), flags, mode);
88 //ret = syscall(SYS_open64,redirect_name(filename),flags,mode);
89
90 printf("open64(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret);
91
92 return ret;
93}
This page took 1.561026 seconds and 4 git commands to generate.