From: Harvie Date: Fri, 3 Aug 2012 03:33:36 +0000 (+0200) Subject: Added some incomplete hack, that is not currently working X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=95cee86bcb48d2036726e41e1efbb4dbc55b39a4;p=mirrors%2FPrograms.git Added some incomplete hack, that is not currently working --- diff --git a/c/troll23/Makefile b/c/troll23/Makefile new file mode 100644 index 0000000..d09d74f --- /dev/null +++ b/c/troll23/Makefile @@ -0,0 +1,8 @@ +proj=troll23 + +unexport LD_PRELOAD +$(proj).so: $(proj).c + $(CC) -shared -fPIC -ldl $? -o $@ + # To test: + # export LD_PRELOAD=$(PWD)/$@ + # touch /tmp/deleteme; rm /tmp/deleteme diff --git a/c/troll23/test.c b/c/troll23/test.c new file mode 100644 index 0000000..32cda63 --- /dev/null +++ b/c/troll23/test.c @@ -0,0 +1,3 @@ +int main() { + printf("%d\n", rand()); +} diff --git a/c/troll23/troll23.c b/c/troll23/troll23.c new file mode 100644 index 0000000..5ff84e1 --- /dev/null +++ b/c/troll23/troll23.c @@ -0,0 +1,37 @@ +#define _GNU_SOURCE +#include +#include +#include +#include + +int rand(void) { return 23; } +int random(void) { return 23; } + +static const char *redirect_name(const char *name) +{ + if(strcmp(name,"/dev/random") == 0) return "/dev/zero"; + if(strcmp(name,"/dev/urandom") == 0) return "/dev/zero"; + return name; +} + +int open(const char *filename, int flags, ...) +{ + static int (*open_orig)(const char *, int, mode_t); + int ret; + va_list ap; + mode_t mode; + + if (!open_orig) { + open_orig = dlsym(RTLD_NEXT, "open"); + } + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + + ret = open_orig(redirect_name(filename), flags, mode); + + printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret); + + return ret; +}