Repository navigation
Expand file tree
/
Copy pathTweak.x
More file actions
120 lines (101 loc) · 4.67 KB
/
Copy pathTweak.x
File metadata and controls
120 lines (101 loc) · 4.67 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
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
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSUserDefaults+Private.h>
#import <dlfcn.h>
// Hey Siri, define laziness
typedef void (*EKHookFunction_t)(void *, void *, void **);
static EKHookFunction_t ElleKitHook = NULL;
// Log shortcut. Wow.
#define LOG(fmt, ...) NSLog(@"[Solaria] " fmt, ##__VA_ARGS__)
// All of these are for preferences
static NSString * const tweakDomain = @"cc.forcequit.solaria";
static NSString * const tweakNotificationListener = @"cc.forcequit.solaria/preferences.changed";
static bool enabled = YES;
static bool allowUnsupported = NO;
static bool allowOptedOut = NO;
static bool hooked = false; // Tracks if the hook's already been installed
static bool (*original)(void); // Original function pointer
// Checks that Solaria's enabled, gets values for the incoming global UserDefaults writing
static void updatePreferences(void) {
NSNumber *enabledValue = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"enabled" inDomain:tweakDomain];
if (enabledValue != nil) {
enabled = [enabledValue boolValue];
}
NSNumber *allowUnsupportedValue = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"allowUnsupported" inDomain:tweakDomain];
if (allowUnsupportedValue != nil) {
allowUnsupported = [allowUnsupportedValue boolValue];
}
NSNumber *allowOptedOutValue = (NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"allowOptedOut" inDomain:tweakDomain];
if (allowOptedOutValue != nil) {
allowOptedOut = [allowOptedOutValue boolValue];
}
}
// Notification callback
static void notificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
updatePreferences();
LOG(@"Preferences modified!");
}
// Writes values for Apple's SwiftUICore overrides to the global domain to match the values I have for Solaria's UserDefaults keys
static void applyPreferenceOverrides(void) {
CFPreferencesSetValue(CFSTR("com.apple.SwiftUI.IgnoreSolariumLinkedOnCheck"),
allowUnsupported ? kCFBooleanTrue : NULL,
kCFPreferencesAnyApplication,
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
CFPreferencesSetValue(CFSTR("com.apple.SwiftUI.IgnoreSolariumOptOut"),
allowOptedOut ? kCFBooleanTrue : NULL,
kCFPreferencesAnyApplication,
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
CFPreferencesSynchronize(kCFPreferencesAnyApplication,
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
}
// Loads ElleKit's EKHookFunction method manually (This is horrible and you probably should not ever do this but I was too lazy to just add a header or whatever)
// This was originally just a part of the install() function, but modularizing it made more sense during development when I was trying different hooks for extra stuff
static void loadElleKit(void) {
if (ElleKitHook) return;
dlopen("/usr/lib/libellekit.dylib", RTLD_NOW);
ElleKitHook = (EKHookFunction_t)dlsym(RTLD_DEFAULT, "EKHookFunction");
if (ElleKitHook) {
LOG(@"Loaded ElleKit successfully!");
} else {
LOG(@"Failed to load ElleKit (what?)");
}
}
// My replacement function that literally just returns true.
static bool replacement(void) {
return true;
}
// Attempts to install hook to replace original function
static void install(void) {
// Skip if we've hooked already
if (hooked) return;
// Skip if tweak's disabled
if (!enabled) return;
loadElleKit();
// Verifies we have the symbol loaded
void *symbol = dlsym(RTLD_DEFAULT, "_CUIAppleTVDeviceSupportsSolarium");
if (!symbol) {
LOG(@"Unable to find symbol to patch Solarium support.");
return;
}
// Actual hook that replaces function
ElleKitHook(symbol, (void *)replacement, (void **)&original);
hooked = true;
LOG(@"WE OUTSIDE!!! #A10XGANG #A8GANG");
}
%ctor {
// Updates preferences
updatePreferences();
applyPreferenceOverrides();
// Notification listener thing I think for when preferences are modified
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
notificationCallback,
(CFStringRef)tweakNotificationListener,
NULL,
CFNotificationSuspensionBehaviorCoalesce);
// Installs the hook!
install();
}