Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <errno.h>
  2. #include <dlfcn.h>
  3. #include <stdio.h>
  4. #include <strings.h>
  5. #include <string.h>
  6. #include <sys/_timespec.h>
  7. #include <sys/stat.h>
  8. #include <sys/mount.h>
  9.  
  10. #ifndef RTLD_NEXT
  11. #define RTLD_NEXT ((void *) -1l)
  12. #endif
  13.  
  14. int (*getdirentries_orig)(int fd, char *buf, int nbytes, long *basep);
  15. int (*lstat_orig)(const char *path, struct stat *sb);
  16. int (*fstatfs_orig)(int fd, struct statfs *buf);
  17. int (*chmod_orig)(const char *path, mode_t mode);
  18.  
  19. #define HOOK(func) func##_##orig = dlsym(RTLD_NEXT,#func)
  20.  
  21. int getdirentries(int fd, char *buf, int nbytes, long *basep) {
  22. HOOK(getdirentries);
  23. printf("getdirentriesn");
  24. return getdirentries_orig(fd, buf, nbytes, basep);
  25. }
  26.  
  27. int lstat(const char *path, struct stat *sb) {
  28. HOOK(lstat);
  29. printf("lstatn");
  30. return (lstat_orig(path, sb));
  31. }
  32.  
  33. int fstatfs(int fd, struct statfs *buf) {
  34. HOOK(fstatfs);
  35. printf("fstatfsn");
  36. return fstatfs_orig(fd, buf);
  37. }
  38.  
  39. int chmod(const char *path, mode_t mode) {
  40. HOOK(chmod);
  41. printf("chmodn");
  42. return chmod_orig(path, mode);
  43. }
  44.  
  45. cc -Wall -g -O2 -fPIC -shared -o preload.so preload.c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement