-
Notifications
You must be signed in to change notification settings - Fork 3
/
Common.xmi
401 lines (335 loc) · 14.6 KB
/
Common.xmi
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/*
* Copyright (c) 2011-2013, Xuzz Productions, LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "Common.h"
#import "LayerSnapshotter.h"
NSString *ZephyrDescriptionForOrientation(UIInterfaceOrientation orientation) {
switch (orientation) {
case UIInterfaceOrientationPortrait:
return @"portrait";
break;
case UIInterfaceOrientationPortraitUpsideDown:
return @"portrait upside-down";
break;
case UIInterfaceOrientationLandscapeLeft:
return @"landscape left";
break;
case UIInterfaceOrientationLandscapeRight:
return @"landscape right";
break;
}
return @"invalid orientation";
}
UIInterfaceOrientation ZephyrOrientationFlip(UIInterfaceOrientation orientation) {
switch (orientation) {
case UIInterfaceOrientationPortrait:
return UIInterfaceOrientationPortraitUpsideDown;
case UIInterfaceOrientationPortraitUpsideDown:
return UIInterfaceOrientationPortrait;
case UIInterfaceOrientationLandscapeLeft:
return UIInterfaceOrientationLandscapeRight;
case UIInterfaceOrientationLandscapeRight:
return UIInterfaceOrientationLandscapeLeft;
}
return orientation;
}
void ZephyrRotateViewFromOrientationToOrientation(UIView *view, UIInterfaceOrientation fromOrientation, UIInterfaceOrientation toOrientation, BOOL inPlace) {
CGAffineTransform transform = [view transform];
CGRect frame = [view frame];
CGFloat rotation = 0.0f;
BOOL perpendicular = NO;
BOOL clockwise = NO;
switch (fromOrientation) {
case UIInterfaceOrientationPortrait:
switch (toOrientation) {
case UIInterfaceOrientationPortrait:
rotation = 0.0f;
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotation = M_PI;
break;
case UIInterfaceOrientationLandscapeLeft:
rotation = -(M_PI / 2.0f);
clockwise = YES;
perpendicular = YES;
break;
case UIInterfaceOrientationLandscapeRight:
rotation = (M_PI / 2.0f);
perpendicular = YES;
break;
}
break;
case UIInterfaceOrientationPortraitUpsideDown:
switch (toOrientation) {
case UIInterfaceOrientationPortrait:
rotation = M_PI;
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotation = 0.0f;
break;
case UIInterfaceOrientationLandscapeLeft:
rotation = (M_PI / 2.0f);
perpendicular = YES;
break;
case UIInterfaceOrientationLandscapeRight:
rotation = -(M_PI / 2.0f);
clockwise = YES;
perpendicular = YES;
break;
}
break;
case UIInterfaceOrientationLandscapeLeft:
switch (toOrientation) {
case UIInterfaceOrientationPortrait:
rotation = (M_PI / 2.0f);
perpendicular = YES;
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotation = -(M_PI / 2.0f);
clockwise = YES;
perpendicular = YES;
break;
case UIInterfaceOrientationLandscapeLeft:
rotation = 0.0f;
break;
case UIInterfaceOrientationLandscapeRight:
rotation = M_PI;
break;
}
break;
case UIInterfaceOrientationLandscapeRight:
switch (toOrientation) {
case UIInterfaceOrientationPortrait:
rotation = -(M_PI / 2.0f);
clockwise = YES;
perpendicular = YES;
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotation = (M_PI / 2.0f);
perpendicular = YES;
break;
case UIInterfaceOrientationLandscapeLeft:
rotation = M_PI;
break;
case UIInterfaceOrientationLandscapeRight:
rotation = 0.0f;
break;
}
break;
}
transform = CGAffineTransformRotate(transform, rotation);
if (perpendicular) {
if (inPlace) {
CGRect frame = [view frame];
frame.size.width = [view frame].size.height;
frame.size.height = [view frame].size.width;
[view setFrame:frame];
}
if (clockwise) {
transform = CGAffineTransformTranslate(transform, (frame.size.width - frame.size.height) / 2.0f, (frame.size.height - frame.size.width) / -2.0f);
} else {
transform = CGAffineTransformTranslate(transform, (frame.size.width - frame.size.height) / -2.0f, (frame.size.height - frame.size.width) / 2.0f);
}
}
[view setTransform:transform];
}
UIView *ZephyrViewForApplication(SBApplication *app) {
SBGestureViewVendor *vendor = [objc_getClass("SBGestureViewVendor") sharedInstance];
[vendor clearCacheForApp:app reason:@"SwitchApp"];
return [vendor viewForApp:app gestureType:kSBGestureTypeSwitchApp includeStatusBar:YES];
}
%group GestureViewStatusBar
// Switch app orientation depends on gestures flag, so hook it and apply it ourselves.
static BOOL switchAppOrientationFlag = NO;
%hook SBApplication
- (UIInterfaceOrientation)launchingInterfaceOrientationForCurrentOrientation {
if (switchAppOrientationFlag) {
return ZephyrCurrentInterfaceOrientation();
} else {
return %orig;
}
}
%end
%hook SBUIController
- (id)systemGestureSnapshotForApp:(SBApplication *)app includeStatusBar:(BOOL)include decodeImage:(BOOL)decode {
switchAppOrientationFlag = YES;
id result = %orig;
switchAppOrientationFlag = NO;
return result;
}
%end
%hook SBGestureViewVendor
- (void)maskViewIfNeeded:(UIView *)view gestureType:(SBGestureType)type viewType:(int)viewType contextHostViewRequester:(NSString *)requester app:(SBApplication *)app {
switchAppOrientationFlag = YES;
%orig;
switchAppOrientationFlag = NO;
}
%end
%end
%ctor {
%init(GestureViewStatusBar);
}
CGFloat ZephyrScreenRounded(CGFloat value) {
CGFloat scale = [UIScreen mainScreen].scale;
return roundf(value * scale) / scale;
}
UIView *ZephyrViewWithScreenshotOfView(UIView *view) {
dlopen("/usr/lib/liblayersnapshotter.dylib", RTLD_LAZY);
if ([view respondsToSelector:@selector(renderSnapshot)]) {
UIImage *viewImage = [view renderSnapshot];
UIImageView *screenshotView = [[UIImageView alloc] initWithImage:viewImage];
[screenshotView setFrame:[view frame]];
return [screenshotView autorelease];
} else {
return [[[UIView alloc] initWithFrame:view.frame] autorelease];
}
}
UIView *ZephyrViewWithScreenshotOfHomeScreen() {
// XXX: using contentView here isn't necessarily the best option, but it works.
UIView *homeView = ZephyrViewWithScreenshotOfView([[objc_getClass("SBUIController") sharedInstance] contentView]);
[homeView setBackgroundColor:[UIColor blackColor]];
CGRect statusFrame = [homeView bounds];
statusFrame.size.height = UIStatusBarHeight;
UIStatusBar *statusView = [[objc_getClass("UIStatusBar") alloc] initWithFrame:statusFrame];
[statusView requestStyle:UIStatusBarStyleBlackTranslucent animated:NO];
[homeView addSubview:statusView];
[statusView release];
return homeView;
}
CGFloat ZephyrHeightForOrientation(UIInterfaceOrientation orientation) {
if (UIInterfaceOrientationIsLandscape(orientation)) {
return [[UIScreen mainScreen] bounds].size.width;
} else {
return [[UIScreen mainScreen] bounds].size.height;
}
}
CGFloat ZephyrWidthForOrientation(UIInterfaceOrientation orientation) {
if (UIInterfaceOrientationIsLandscape(orientation)) {
return [[UIScreen mainScreen] bounds].size.height;
} else {
return [[UIScreen mainScreen] bounds].size.width;
}
}
CGFloat ZephyrHeightFromScreenPercentage(CGFloat percentage, UIInterfaceOrientation orientation) {
return ZephyrHeightForOrientation(orientation) * percentage;
}
UIInterfaceOrientation ZephyrCurrentInterfaceOrientation() {
UIInterfaceOrientation orientation = [SBApp _frontMostAppOrientation];
return orientation;
}
UIInterfaceOrientation ZephyrDeviceInterfaceOrientation() {
return [SBApp interfaceOrientationForCurrentDeviceOrientation];
}
UIInterfaceOrientation ZephyrHomeInterfaceOrientation() {
UIInterfaceOrientation orientation = ZephyrCurrentInterfaceOrientation();
// Often, the Current interface orientation is different than the home screen's.
// In that case, we prefer what the user is seeing: the Current one. However,
// if that isn't a valid home orientation, then return what we know is valid.
if (!ZephyrHomeShouldRotateToInterfaceOrientation(orientation)) {
orientation = [SBApp interfaceOrientation];
}
return orientation;
}
BOOL ZephyrHomeShouldRotateToInterfaceOrientation(UIInterfaceOrientation orientation) {
SBUIController *controller = [objc_getClass("SBUIController") sharedInstance];
return [controller window:[controller window] shouldAutorotateToInterfaceOrientation:orientation];
}
BOOL ZephyrAssistantIsVisible() {
Class $SBAssistantController = objc_getClass("SBAssistantController");
if ([$SBAssistantController respondsToSelector:@selector(isAssistantVisible)]) {
return [$SBAssistantController isAssistantVisible];
} else if ([[$SBAssistantController sharedInstance] respondsToSelector:@selector(isAssistantVisible)]) {
return [[$SBAssistantController sharedInstance] isAssistantVisible];
} else {
return NO;
}
}
BOOL ZephyrMultitaskingSupported() {
Class $SBApplication = objc_getClass("SBApplication");
if ([$SBApplication respondsToSelector:@selector(multitaskingIsSupported)]) {
return [$SBApplication multitaskingIsSupported];
}
return YES;
}
static BOOL disableUnscatterFlag = NO;
void ZephyrDeactivateFrontmostApplication() {
SBApplication *app = [SBApp _accessibilityFrontMostApplication];
if (objc_getClass("SBDisplayStack") != nil) {
// XXX: the "disableIconUnscatter" display flag there does not work, so:
disableUnscatterFlag = YES;
// Stolen from SwitchApp.xmi; this is a bad decompliation of
// what a different function does than the one I am reversing.
[app setDeactivationSetting:24 flag:YES];
[app setDeactivationSetting:18 flag:YES];
/* sub_2C330 */ {
if ([SBWActiveDisplayStack containsDisplay:app] || [SBWSuspendedEventOnlyDisplayStack containsDisplay:app]) {
/* sub_2B9B8 */ {
// this is a crude approximation of sorta kinda what this gigantic
// function does, since I'm waaaaay too lazy to reverse the whole
// thing: even just the graph in IDA is quite scary to look at! :(
[SBWActiveDisplayStack popDisplay:app];
[SBWSuspendingDisplayStack pushDisplay:app];
}
} else if (![SBWSuspendingDisplayStack containsDisplay:app]) {
[app clearDeactivationSettings];
}
}
} else {
// Force iPhone devices to portrait for the home screen.
// Should be generalized; the iPhone might be hacked for more orientations.
if (!ZephyrHomeShouldRotateToInterfaceOrientation(ZephyrCurrentInterfaceOrientation())) {
UIInterfaceOrientation currentOrientation = ZephyrHomeInterfaceOrientation();
[[UIDevice currentDevice] setOrientation:currentOrientation animated:NO];
[SBApp noteInterfaceOrientationChanged:currentOrientation];
}
[app setDeactivationSetting:0x15 flag:YES];
[app setDeactivationSetting:0x16 flag:YES];
NSString *label = @"ActivateSpringBoard";
SBWorkspaceEvent *event = [objc_getClass("SBWorkspaceEvent") eventWithLabel:label handler:^{
BKSWorkspace *workspace = [SBWSharedWorkspace bksWorkspace];
SBAppToAppWorkspaceTransaction *transaction = [[objc_getClass("SBAppToAppWorkspaceTransaction") alloc] initWithWorkspace:workspace alertManager:nil from:app to:nil];
[SBWSharedWorkspace setCurrentTransaction:transaction];
[transaction release];
}];
[[objc_getClass("SBWorkspaceEventQueue") sharedInstance] executeOrAppendEvent:event];
}
}
%group ForceDisableAnimatedRestore
%hook SBUIController
- (void)restoreIconListAnimated:(BOOL)animated animateWallpaper:(BOOL)wallpaper keepSwitcher:(BOOL)switcher {
if (disableUnscatterFlag) {
disableUnscatterFlag = NO;
animated = NO;
}
%orig(animated, wallpaper, switcher);
}
%end
%end
%ctor {
%init(ForceDisableAnimatedRestore);
}
CGFloat ZephyrAppSwitcherHeight() {
CGFloat bottomBarHeight = [[objc_getClass("SBAppSwitcherController") sharedInstance] bottomBarHeight];
return bottomBarHeight;
}