This repository has been archived by the owner on Nov 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Tweak.mm
64 lines (58 loc) · 2.07 KB
/
Tweak.mm
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
#import <Foundation/Foundation.h>
#import <substrate.h>
static NSArray *NotAllowedPathPrefixes;
static BOOL allowAccess(NSString *filename) {
if ([filename hasPrefix:@"/private"]) {
filename = [filename substringFromIndex:@"/private".length];
}
if (filename.length == 0) {
return YES;
}
for (NSString *prefix in NotAllowedPathPrefixes) {
if ([filename hasPrefix:prefix]) {
return NO;
}
}
return YES;
}
static int (*original_stat)(const char *filename, struct stat *result);
static int optimized_stat(const char *filename, struct stat *result) {
if (!allowAccess([NSString stringWithUTF8String:filename])) {
filename = "";
}
return original_stat(filename, result);
}
static int (*original_lstat)(const char *filename, struct stat *result);
static int optimized_lstat(const char *filename, struct stat *result) {
if (!allowAccess([NSString stringWithUTF8String:filename])) {
filename = "";
}
return original_lstat(filename, result);
}
static FILE *(*original_fopen)(const char *filename, const char *mode);
static FILE *optimized_fopen(const char *filename, const char *mode) {
if (!allowAccess([NSString stringWithUTF8String:filename])) {
filename = "";
}
return original_fopen(filename, mode);
}
static void __attribute__((constructor)) constructor() {
@autoreleasepool {
NotAllowedPathPrefixes = @[
@"/bin",
@"/usr/bin",
@"/usr/sbin",
@"/usr/libexec",
@"/etc/passwd",
@"/etc/ssh",
@"/var/log",
@"/var/tmp",
@"/Applications",
@"/Library/MobileSubstrate",
@"/System/Library/LaunchDaemons"
];
MSHookFunction((int *)MSFindSymbol(NULL, "_stat"), (int *)optimized_stat, (int **)&original_stat);
MSHookFunction((int *)MSFindSymbol(NULL, "_lstat"), (int *)optimized_lstat, (int **)&original_lstat);
MSHookFunction((FILE **)MSFindSymbol(NULL, "_fopen"), (FILE **)optimized_fopen, (FILE ***)&original_fopen);
}
}