From: Harvie Date: Sun, 31 Oct 2010 19:02:43 +0000 (+0100) Subject: Added unlink-wrapper, syscall wrapper example X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=927194759cdb1b56077b469ac44121169b4af9ed;p=mirrors%2FPrograms.git Added unlink-wrapper, syscall wrapper example --- 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)