Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <errno.h>
- #include <dlfcn.h>
- #include <stdio.h>
- #include <strings.h>
- #include <string.h>
- #include <sys/_timespec.h>
- #include <sys/stat.h>
- #include <sys/mount.h>
- #ifndef RTLD_NEXT
- #define RTLD_NEXT ((void *) -1l)
- #endif
- int (*getdirentries_orig)(int fd, char *buf, int nbytes, long *basep);
- int (*lstat_orig)(const char *path, struct stat *sb);
- int (*fstatfs_orig)(int fd, struct statfs *buf);
- int (*chmod_orig)(const char *path, mode_t mode);
- #define HOOK(func) func##_##orig = dlsym(RTLD_NEXT,#func)
- int getdirentries(int fd, char *buf, int nbytes, long *basep) {
- HOOK(getdirentries);
- printf("getdirentriesn");
- return getdirentries_orig(fd, buf, nbytes, basep);
- }
- int lstat(const char *path, struct stat *sb) {
- HOOK(lstat);
- printf("lstatn");
- return (lstat_orig(path, sb));
- }
- int fstatfs(int fd, struct statfs *buf) {
- HOOK(fstatfs);
- printf("fstatfsn");
- return fstatfs_orig(fd, buf);
- }
- int chmod(const char *path, mode_t mode) {
- HOOK(chmod);
- printf("chmodn");
- return chmod_orig(path, mode);
- }
- cc -Wall -g -O2 -fPIC -shared -o preload.so preload.c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement