From 927194759cdb1b56077b469ac44121169b4af9ed Mon Sep 17 00:00:00 2001 From: Harvie Date: Sun, 31 Oct 2010 20:02:43 +0100 Subject: [PATCH] Added unlink-wrapper, syscall wrapper example --- c/unlink-wrapper/Makefile | 8 ++++++++ c/unlink-wrapper/unlink-wrapper.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 c/unlink-wrapper/Makefile create mode 100644 c/unlink-wrapper/unlink-wrapper.c diff --git a/c/unlink-wrapper/Makefile b/c/unlink-wrapper/Makefile new file mode 100644 index 0000000..2d2f1f2 --- /dev/null +++ b/c/unlink-wrapper/Makefile @@ -0,0 +1,8 @@ +proj=unlink-wrapper + +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/unlink-wrapper/unlink-wrapper.c b/c/unlink-wrapper/unlink-wrapper.c new file mode 100644 index 0000000..e97e86c --- /dev/null +++ b/c/unlink-wrapper/unlink-wrapper.c @@ -0,0 +1,16 @@ +#define _GNU_SOURCE +#include +#include +//#include +//#define RTLD_NEXT ((void *) -1l) + + +int unlinkat(int dirfd, const char *pathname, int flags) +{ + puts("unlinkat"); + int (*orig_unlinkat)(int, const char*, int) = dlsym(RTLD_NEXT, "unlinkat"); + return orig_unlinkat(dirfd,pathname,flags); +} + +//int unlink(const char *pathname) +//ssize_t write(int fd, const void *buf, size_t count) -- 2.30.2