-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Tweak.xm
180 lines (150 loc) · 5.56 KB
/
Tweak.xm
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
// Tweak.m
// FLEXing
//
// Created by Tanner Bennett on 2016-07-11
// Copyright © 2016 Tanner Bennett. All rights reserved.
//
#import "Interfaces.h"
#import <rootless.h>
BOOL initialized = NO;
id manager = nil;
SEL show = nil;
static NSHashTable *windowsWithGestures = nil;
static id (*FLXGetManager)();
static SEL (*FLXRevealSEL)();
static Class (*FLXWindowClass)();
/// This isn't perfect, but works for most cases as intended
inline bool isLikelyUIProcess() {
NSString *executablePath = NSProcessInfo.processInfo.arguments[0];
return [executablePath hasPrefix:@"/var/containers/Bundle/Application"] ||
[executablePath hasPrefix:@"/Applications"] ||
[executablePath containsString:@"/procursus/Applications"] ||
[executablePath hasSuffix:@"CoreServices/SpringBoard.app/SpringBoard"];
}
inline bool isSnapchatApp() {
// See: near line 44 below
return [NSBundle.mainBundle.bundleIdentifier isEqualToString:@"com.toyopagroup.picaboo"];
}
inline BOOL flexAlreadyLoaded() {
return NSClassFromString(@"FLEXExplorerToolbar") != nil;
}
%ctor {
NSString *standardPath = ROOT_PATH_NS(@"/Library/MobileSubstrate/DynamicLibraries/libFLEX.dylib");
NSString *reflexPath = ROOT_PATH_NS(@"/Library/MobileSubstrate/DynamicLibraries/libreflex.dylib");
NSFileManager *disk = NSFileManager.defaultManager;
NSString *libflex = nil;
NSString *libreflex = nil;
void *handle = nil;
if ([disk fileExistsAtPath:standardPath]) {
libflex = standardPath;
if ([disk fileExistsAtPath:reflexPath]) {
libreflex = reflexPath;
}
} else {
// Check if libFLEX resides in the same folder as me
NSString *executablePath = NSProcessInfo.processInfo.arguments[0];
NSString *whereIam = executablePath.stringByDeletingLastPathComponent;
NSString *possibleFlexPath = [whereIam stringByAppendingPathComponent:@"Frameworks/libFLEX.dylib"];
NSString *possibleRelexPath = [whereIam stringByAppendingPathComponent:@"Frameworks/libreflex.dylib"];
if ([disk fileExistsAtPath:possibleFlexPath]) {
libflex = possibleFlexPath;
if ([disk fileExistsAtPath:possibleRelexPath]) {
libreflex = possibleRelexPath;
}
} else {
// libFLEX not found
// ...
}
}
if (libflex) {
// Hey Snapchat / Snap Inc devs,
// This is so users don't get their accounts locked.
if (isLikelyUIProcess() && !isSnapchatApp()) {
handle = dlopen(libflex.UTF8String, RTLD_LAZY);
if (libreflex) {
dlopen(libreflex.UTF8String, RTLD_NOW);
}
}
}
if (handle || flexAlreadyLoaded()) {
// FLEXing.dylib itself does not hard-link against libFLEX.dylib,
// instead libFLEX.dylib provides getters for the relevant class
// objects so that it can be updated independently of THIS tweak.
FLXGetManager = (id(*)())dlsym(handle, "FLXGetManager");
FLXRevealSEL = (SEL(*)())dlsym(handle, "FLXRevealSEL");
FLXWindowClass = (Class(*)())dlsym(handle, "FLXWindowClass");
if (FLXGetManager && FLXRevealSEL) {
manager = FLXGetManager();
show = FLXRevealSEL();
windowsWithGestures = [NSHashTable weakObjectsHashTable];
initialized = YES;
}
}
}
%hook UIWindow
- (BOOL)_shouldCreateContextAsSecure {
return (initialized && [self isKindOfClass:FLXWindowClass()]) ? YES : %orig;
}
- (void)becomeKeyWindow {
%orig;
if (!initialized) {
return;
}
BOOL needsGesture = ![windowsWithGestures containsObject:self];
BOOL isFLEXWindow = [self isKindOfClass:FLXWindowClass()];
BOOL isStatusBar = [self isKindOfClass:[UIStatusBarWindow class]];
if (needsGesture && !isFLEXWindow && !isStatusBar) {
[windowsWithGestures addObject:self];
// Add 3-finger long-press gesture for apps without a status bar
UILongPressGestureRecognizer *tap = [[UILongPressGestureRecognizer alloc] initWithTarget:manager action:show];
tap.minimumPressDuration = .5;
tap.numberOfTouchesRequired = 3;
[self addGestureRecognizer:tap];
}
}
%end
%hook UIStatusBarWindow
- (id)initWithFrame:(CGRect)frame {
self = %orig;
if (initialized) {
// Add long-press gesture to status bar
[self addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:manager action:show]];
}
return self;
}
%end
%hook FLEXExplorerViewController
- (BOOL)_canShowWhileLocked {
return YES;
}
%end
%hook _UISheetPresentationController
- (id)initWithPresentedViewController:(id)present presentingViewController:(id)presenter {
self = %orig;
if ([present isKindOfClass:%c(FLEXNavigationController)]) {
// Enable half height sheet
if ([self respondsToSelector:@selector(_presentsAtStandardHalfHeight)]) {
self._presentsAtStandardHalfHeight = YES;
} else {
self._detents = @[[%c(_UISheetDetent) _mediumDetent], [%c(_UISheetDetent) _largeDetent]];
}
// Start fullscreen, 0 for half height
self._indexOfCurrentDetent = 1;
// Don't expand unless dragged up
self._prefersScrollingExpandsToLargerDetentWhenScrolledToEdge = NO;
// Don't dim first detent
self._indexOfLastUndimmedDetent = 1;
}
return self;
}
%end
%hook FLEXManager
%new
+ (NSString *)dlopen:(NSString *)path {
if (!dlopen(path.UTF8String, RTLD_NOW)) {
return @(dlerror());
}
return @"OK";
}
%end