📄 libhidefile.c
字号:
#define _GNU_SOURCE#include <stdlib.h>#include <dlfcn.h>#include <stdio.h>#include <dirent.h>#include <string.h>static char *hidefileenv;static char *hidefilestr;// Ezt mi閞t nem szedi ki a dlfcn.h-b髄???#define RTLD_NEXT ((void *) -1l)static struct dirent *(*next_readdir)(DIR *dir);static struct dirent64 *(*next_readdir64)(DIR *dir);static int (*next_readdir_r)(DIR *dir, struct dirent *result, struct dirent **resultp);static int (*next_readdir64_r)(DIR *dir, struct dirent64 *result, struct dirent64 **resultp);static int do_wrap = 0;void hidefile_init (void) __attribute((constructor));void hidefile_init (void){ next_readdir = dlsym(RTLD_NEXT, "readdir"); next_readdir64 = dlsym(RTLD_NEXT, "readdir64"); next_readdir_r = dlsym(RTLD_NEXT, "readdir_r"); next_readdir64_r = dlsym(RTLD_NEXT, "readdir64_r"); if ((hidefileenv = getenv("HIDEFILE")) != NULL) { hidefilestr = malloc(strlen(hidefileenv) + 3); sprintf(hidefilestr, "/%s/", hidefileenv); do_wrap = 1; }}struct dirent *readdir (DIR *dir){ char dirstr[NAME_MAX + 3]; struct dirent *dirent; if (!do_wrap) return next_readdir(dir); while (1) { dirent = next_readdir(dir); if (dirent == NULL) return NULL; sprintf(dirstr, "/%s/", dirent->d_name); if (strstr(hidefilestr, dirstr) == NULL) return dirent; }}struct dirent64 *readdir64 (DIR *dir){ char dirstr[NAME_MAX + 3]; struct dirent64 *dirent; if (!do_wrap) return next_readdir64(dir); while (1) { dirent = next_readdir64(dir); if (dirent == NULL) return NULL; sprintf(dirstr, "/%s/", dirent->d_name); if (strstr(hidefilestr, dirstr) == NULL) return dirent; }}int readdir_r (DIR *dir, struct dirent *result, struct dirent **resultp){ char dirstr[NAME_MAX + 3]; int retval; if (!do_wrap) return next_readdir_r(dir, result, resultp); while (1) { retval = next_readdir_r(dir, result, resultp); if (retval < 0) return -1; sprintf(dirstr, "/%s/", result->d_name); if (strstr(hidefilestr, dirstr) == NULL) return 0; }}int readdir64_r (DIR *dir, struct dirent64 *result, struct dirent64 **resultp){ char dirstr[NAME_MAX + 3]; int retval; if (!do_wrap) return next_readdir64_r(dir, result, resultp); while (1) { retval = next_readdir64_r(dir, result, resultp); if (retval < 0) return -1; sprintf(dirstr, "/%s/", result->d_name); if (strstr(hidefilestr, dirstr) == NULL) return 0; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -