-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTweak.x
More file actions
54 lines (46 loc) · 1.81 KB
/
Copy pathTweak.x
File metadata and controls
54 lines (46 loc) · 1.81 KB
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
// Headers
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSUserDefaults+Private.h>
#import <libSandy.h>
// Required for the actual hook
@interface _WKProcessPoolConfiguration : NSObject
- (void)setJITEnabled:(BOOL)enabled;
@end
// Log macro, an absolute staple.
#define LOG(fmt, ...) NSLog(@"[Lightshield] " fmt, ##__VA_ARGS__)
// Not sure if you can tell, but I didn't initially plan for this tweak to support preferences.
// The original game plan was to include a Control Center module that would reload WebContent with JIT enabled/disabled, but I just absolutely could not get that to cooperate. For those smarter than me, keep _allProcessPoolsForTesting and _terminateAllWebContentProcesses in mind.
static NSUserDefaults *defaults;
static BOOL enabled;
%hook _WKProcessPoolConfiguration
- (id)init {
id result = %orig;
if (result && enabled) {
[result setJITEnabled:NO];
LOG(@"hit init hook");
}
return result;
}
// This is the most important hook, the init hook can be skipped but this cannot be
- (void)setJITEnabled:(BOOL)jitEnabled {
if (enabled) {
LOG(@"setJITEnabled called, responding no");
%orig(NO);
} else {
%orig(jitEnabled);
}
}
%end
%ctor {
// Apply sandbox profile via libSandy so we can actually read our preferences (and check that libSandy actually worked).
int result = libSandy_applyProfile("Lightshield_Preferences");
if (result != 0) {
LOG(@"unable to apply sandbox profile.");
// Results from here on out are basically unexpected.
}
defaults = [[NSUserDefaults alloc] initWithSuiteName:@"/var/mobile/Library/Preferences/cc.forcequit.lightshield.plist"];
// Set enabled variable
NSNumber *enabledValue = [defaults objectForKey:@"enabled"];
enabled = (enabledValue)? [enabledValue boolValue] : YES;
}