opendir.c 704 B

123456789101112131415161718192021222324
  1. #include <stdio.h>
  2. #include <dlfcn.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <dirent.h>
  6. static DIR * (*original_opendir)(const char *pathname);
  7. static const char *HookPath = "/media/mmc/time_lapse/time_Task_";
  8. static const char *MediaPath = "/media/mmc/";
  9. char TimeLapsePath[256];
  10. static void __attribute ((constructor)) opendir_hook_init(void) {
  11. original_opendir = dlsym(dlopen ("/lib/libc.so.0", RTLD_LAZY), "opendir");
  12. }
  13. DIR *opendir(const char *pathname) {
  14. if(!strncmp(pathname, HookPath, strlen(HookPath))) {
  15. strncpy(TimeLapsePath, pathname + strlen(MediaPath), 255);
  16. printf("[webhook] time_lapse_event %s\n", TimeLapsePath);
  17. }
  18. return original_opendir(pathname);
  19. }