forked from kpwn/uikittools-ng
-
Notifications
You must be signed in to change notification settings - Fork 14
/
sbreload.m
96 lines (79 loc) · 2.39 KB
/
sbreload.m
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
#import <Foundation/Foundation.h>
#import <dlfcn.h>
#import <objc/runtime.h>
#include <TargetConditionals.h>
#if NLS
# include <libintl.h>
# define _(a) gettext(a)
# define PACKAGE "uikittools-ng"
#else
# define _(a) a
#endif
#ifndef LOCALEDIR
# define LOCALEDIR "/usr/share/locale"
#endif
typedef NS_OPTIONS(NSUInteger, SBSRelaunchActionOptions) {
SBSRelaunchActionOptionsNone,
SBSRelaunchActionOptionsRestartRenderServer = 1 << 0,
SBSRelaunchActionOptionsSnapshotTransition = 1 << 1,
SBSRelaunchActionOptionsFadeToBlackTransition = 1 << 2
};
@interface SBSRelaunchAction : NSObject
+ (instancetype)actionWithReason:(NSString *)reason
options:(SBSRelaunchActionOptions)options
targetURL:(NSURL *)targetURL;
@end
@interface FBSSystemService : NSObject
+ (instancetype)sharedService;
- (void)sendActions:(NSSet *)actions withResult:(id)result;
@end
@interface PBSSystemService : NSObject
+ (instancetype)sharedInstance;
- (void)relaunch;
@end
pid_t springboardPID;
pid_t backboarddPID;
int stopService(const char *ServiceName);
int updatePIDs(void);
int main() {
#if NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#endif
@autoreleasepool {
springboardPID = 0;
backboarddPID = 0;
updatePIDs();
dlopen("/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices", RTLD_NOW);
#if TARGET_OS_TV
dlopen("/System/Library/PrivateFrameworks/PineBoardServices.framework/PineBoardServices", RTLD_NOW);
[[objc_getClass("PBSSystemService") sharedInstance] relaunch];
#else
dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_NOW);
SBSRelaunchAction *restartAction = [objc_getClass("SBSRelaunchAction")
actionWithReason:@"respring"
options:(SBSRelaunchActionOptionsRestartRenderServer |
SBSRelaunchActionOptionsFadeToBlackTransition)
targetURL:nil];
[(FBSSystemService *)[objc_getClass("FBSSystemService") sharedService]
sendActions:[NSSet setWithObject:restartAction]
withResult:nil];
#endif
sleep(2);
int old_springboardPID = springboardPID;
int old_backboarddPID = backboarddPID;
updatePIDs();
if (springboardPID == old_springboardPID) {
#if TARGET_OS_TV
stopService("com.apple.PineBoard");
#else
stopService("com.apple.SpringBoard");
#endif
}
if (backboarddPID == old_backboarddPID) {
stopService("com.apple.backboardd");
}
}
return 0;
}