forked from XXTouchNG/XXTouchNG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ohmyjetsam.mm
137 lines (117 loc) · 5.25 KB
/
ohmyjetsam.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#import <Foundation/Foundation.h>
OBJC_EXTERN
void plugin_i_love_xxtouch(void);
__attribute__((used)) __attribute__ ((visibility("default")))
void plugin_i_love_xxtouch(void) {}
#pragma mark -
int main(int argc, char *argv[]) {
@autoreleasepool {
static NSFileManager *fileManager = [NSFileManager defaultManager];
static NSString *launchDaemonRoot = @"/System/Library/LaunchDaemons";
static NSDictionary <NSString *, NSDictionary *> *migrateDict = @{
@"ch.xxtou.tfcontainermanagerd": @{
@"ExecuteAllowed": @(YES),
@"EnablePressuredExit": @(NO),
@"JetsamPriority": @(14),
@"ActiveSoftMemoryLimit": @(36),
@"InactiveHardMemoryLimit": @(36),
@"ThreadLimit": @(32),
},
@"ch.xxtou.authpolicyd": @{
@"ExecuteAllowed": @(YES),
@"EnablePressuredExit": @(NO),
@"JetsamPriority": @(14),
@"ActiveSoftMemoryLimit": @(36),
@"InactiveHardMemoryLimit": @(36),
@"ThreadLimit": @(32),
},
@"ch.xxtou.simulatetouchd": @{
@"ExecuteAllowed": @(YES),
@"EnablePressuredExit": @(NO),
@"JetsamPriority": @(17),
@"ActiveSoftMemoryLimit": @(12),
@"InactiveHardMemoryLimit": @(12),
@"ThreadLimit": @(32),
},
@"ch.xxtou.procqueued": @{
@"ExecuteAllowed": @(YES),
@"EnablePressuredExit": @(NO),
@"JetsamPriority": @(14),
@"ActiveSoftMemoryLimit": @(36),
@"InactiveHardMemoryLimit": @(36),
@"ThreadLimit": @(32),
},
@"ch.xxtou.supervisord": @{
@"ExecuteAllowed": @(YES),
@"EnablePressuredExit": @(NO),
@"JetsamPriority": @(21),
@"ActiveSoftMemoryLimit": @(1536),
@"InactiveHardMemoryLimit": @(1536),
@"ThreadLimit": @(512),
},
@"ch.xxtou.webserv": @{
@"ExecuteAllowed": @(YES),
@"EnablePressuredExit": @(NO),
@"JetsamPriority": @(14),
@"ActiveSoftMemoryLimit": @(36),
@"InactiveHardMemoryLimit": @(12),
@"ThreadLimit": @(32),
},
@"ch.xxtou.elfclient": @{
@"ExecuteAllowed": @(YES),
@"EnablePressuredExit": @(NO),
@"JetsamPriority": @(14),
@"ActiveSoftMemoryLimit": @(36),
@"InactiveHardMemoryLimit": @(12),
@"ThreadLimit": @(32),
},
};
NSError *err = nil;
NSArray <NSString *> *daemonItemNames = [fileManager contentsOfDirectoryAtPath:launchDaemonRoot error:&err];
for (NSString *daemonItemName in daemonItemNames) {
if (![daemonItemName hasPrefix:@"com.apple.jetsamproperties."] || ![daemonItemName hasSuffix:@".plist"]) {
continue;
}
NSString *daemonItemPath = [launchDaemonRoot stringByAppendingPathComponent:daemonItemName];
NSMutableDictionary *daemonItemDict = [NSMutableDictionary dictionaryWithContentsOfFile:daemonItemPath];
if (!daemonItemDict) {
continue;
}
NSMutableDictionary *version4Dict = [daemonItemDict[@"Version4"] mutableCopy];
if (!version4Dict) {
continue;
}
NSMutableDictionary *version4DaemonDict = [version4Dict[@"Daemon"] mutableCopy];
if (!version4DaemonDict) {
continue;
}
NSMutableDictionary *version4DaemonDefaultDict = [version4DaemonDict[@"Default"] mutableCopy];
if (!version4DaemonDefaultDict) {
continue;
}
NSMutableDictionary *version4DaemonOverrideDict = [version4DaemonDict[@"Override"] mutableCopy];
if (!version4DaemonOverrideDict) {
continue;
}
for (NSString *key in migrateDict) {
NSDictionary *migrateDictItem = migrateDict[key];
version4DaemonDefaultDict[key] = migrateDictItem;
version4DaemonOverrideDict[key] = migrateDictItem;
}
version4DaemonDict[@"Default"] = version4DaemonDefaultDict;
version4DaemonDict[@"Override"] = version4DaemonOverrideDict;
version4Dict[@"Daemon"] = version4DaemonDict;
daemonItemDict[@"Version4"] = version4Dict;
#if DEBUG
daemonItemPath = [[daemonItemPath stringByDeletingPathExtension] stringByAppendingPathExtension:@"plist.debug"];
#endif
NSData *plistData = [NSPropertyListSerialization dataWithPropertyList:daemonItemDict format:NSPropertyListBinaryFormat_v1_0 options:0 error:&err];
BOOL didWrite = [plistData writeToFile:daemonItemPath options:NSDataWritingAtomic error:&err];
if (!didWrite) {
fprintf(stderr, "ohmyjetsam: failed to write to %s\n", daemonItemPath.UTF8String);
}
}
fprintf(stderr, "ohmyjetsam: done\n");
return EXIT_SUCCESS;
}
}