Added some incomplete hack, that is not currently working
authorHarvie <tomas@mudrunka.cz>
Fri, 3 Aug 2012 03:33:36 +0000 (05:33 +0200)
committerHarvie <tomas@mudrunka.cz>
Fri, 3 Aug 2012 03:33:36 +0000 (05:33 +0200)
c/troll23/Makefile [new file with mode: 0644]
c/troll23/test.c [new file with mode: 0644]
c/troll23/troll23.c [new file with mode: 0644]

diff --git a/c/troll23/Makefile b/c/troll23/Makefile
new file mode 100644 (file)
index 0000000..d09d74f
--- /dev/null
@@ -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 (file)
index 0000000..32cda63
--- /dev/null
@@ -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 (file)
index 0000000..5ff84e1
--- /dev/null
@@ -0,0 +1,37 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/types.h>
+#include <dlfcn.h>
+#include <stdarg.h>
+
+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;
+}
This page took 0.146846 seconds and 4 git commands to generate.