-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTweak.xm
254 lines (185 loc) · 7.53 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
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
#include <sys/types.h>
@interface NSTask : NSObject
- (id)init;
- (void)setLaunchPath:(NSString *)path;
- (void)setArguments:(NSArray *)arguments;
- (void)launch;
- (int)processIdentifier;
@end
@interface UIView(findvc)
-(UIViewController*)findViewController;
@end
@implementation UIView(find)
-(UIViewController*)findViewController
{
UIResponder* target= self;
while (target) {
target = target.nextResponder;
if ([target isKindOfClass:[UIViewController class]]) {
break;
}
}
return (UIViewController*)target;
}
@end
@interface LSApplicationProxy : NSObject
+ (id) applicationProxyForIdentifier:(id)arg1;
@property (readonly, nonatomic) NSString* canonicalExecutablePath;
@end
@interface TaskManager : NSObject
+ (TaskManager*)sharedManager;
@property (nonatomic,strong) NSTask * runningTask;
@end
@implementation TaskManager
+ (TaskManager*)sharedManager {
static TaskManager *_sharedSingleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedSingleton = [[self alloc] init];
});
return _sharedSingleton;
}
@end
@interface SBIconView : UIView
@property(nullable, nonatomic,copy) NSArray *gestureRecognizers;
@property(nonatomic,copy) NSString *applicationBundleIdentifierForShortcuts;
@end
%hook SBIconView
%new
-(void)handleDoubleClick:(UITapGestureRecognizer*)doubleTap
{
NSLog(@"double click begin");
NSString * bundle = self.applicationBundleIdentifierForShortcuts;
if(!bundle){
NSLog(@"error bundleid is null");
return;
}
UIViewController * vc = [self findViewController];
NSString * debugserver = @"/iOSRE/tools/debugserver";
NSString * ip_port = @"127.0.0.1:1234";
NSString * last_server = [[NSUserDefaults standardUserDefaults] objectForKey:@"server_bin_path"] ;
NSString * last_ip =[[NSUserDefaults standardUserDefaults] objectForKey:@"ip_port"] ;
if(last_server!=nil){
debugserver = last_server;
}
if(last_ip!=nil){
ip_port = last_ip;
}
Class LSApplicationProxy_class = objc_getClass("LSApplicationProxy");
NSObject* proxyObj = [LSApplicationProxy_class performSelector:@selector(applicationProxyForIdentifier:) withObject:bundle];
NSString * canonicalExecutablePath = [proxyObj performSelector:@selector(canonicalExecutablePath)];
UIAlertController * panel = [UIAlertController alertControllerWithTitle:@"🍎 SERVER LAUNCHER" message:canonicalExecutablePath preferredStyle:UIAlertControllerStyleAlert];
[panel addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"server path(not null)";
textField.text = debugserver;
}];
[panel addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"ip:port(nullable)";
textField.text = ip_port;
}];
[panel addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"executable path(not null)";
textField.text = canonicalExecutablePath;
textField.enabled = NO;
textField.textColor = [UIColor lightGrayColor];
}];
[panel addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"-x";
textField.text = @"-x";
textField.enabled = NO;
textField.textColor = [UIColor lightGrayColor];
}];
[panel addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"backboard";
textField.text = @"backboard";
textField.enabled = NO;
textField.textColor = [UIColor lightGrayColor];
}];
UIAlertAction * okaction = [UIAlertAction actionWithTitle:@"▶ START️ SERVER" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
UITextField * tf_server = panel.textFields[0];
UITextField * tf_ip = panel.textFields[1];
UITextField * tf_exepath = panel.textFields[2];
UITextField * tf_x = panel.textFields[3];
UITextField * tf_board = panel.textFields[4];
NSString * bin_serverpath = [tf_server.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (!bin_serverpath || bin_serverpath.length == 0) {
NSLog(@"server path is null,stop");
return ;
}
NSString * arg_ipport = [tf_ip.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (!arg_ipport || arg_ipport.length == 0) {
NSLog(@"ipport is null,continue");
}
NSString * arg_exepath = [tf_exepath.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (!arg_exepath || arg_exepath.length == 0) {
NSLog(@"exe path is null,stop");
return ;
}
NSString * arg_x = [tf_x.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (!arg_x || arg_x.length == 0) {
NSLog(@"arg_x is null,user default -x");
arg_x = @"-x";
}
NSString * arg_board = [tf_board.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (!arg_board || arg_board.length == 0) {
NSLog(@"arg_board is null,user default -x backboard");
arg_board = @"-x backboard";
}
NSLog(@"launch path %@",bin_serverpath);
NSLog(@"%@ %@ %@ %@",bin_serverpath,arg_ipport,arg_exepath,arg_board);
NSMutableArray * args = [NSMutableArray array];
[args addObject:arg_ipport];
[args addObject:arg_exepath];
[args addObject:arg_x];
[args addObject:arg_board];
[[NSUserDefaults standardUserDefaults] setObject:bin_serverpath forKey:@"server_bin_path"] ;
[[NSUserDefaults standardUserDefaults] setObject:arg_ipport forKey:@"ip_port"] ;
[[NSUserDefaults standardUserDefaults] synchronize];
NSTask * task = [TaskManager sharedManager].runningTask;
if(task){
kill(task.processIdentifier,SIGKILL);
task = nil;
}
task = [[NSTask alloc]init];
[task setLaunchPath:bin_serverpath];
[task setArguments:args];
[task launch];
[TaskManager sharedManager].runningTask = task;
}];
UIAlertAction * cancelaction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"cancel");
}];
UIAlertAction * stopAction = [UIAlertAction actionWithTitle:@"⏹ STOP SERVER" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSTask * task = [TaskManager sharedManager].runningTask;
if(task){
kill(task.processIdentifier,SIGKILL);
task = nil;
}
}];
[panel addAction:okaction];
[panel addAction:stopAction];
[panel addAction:cancelaction];
[vc presentViewController:panel animated:YES completion:nil];
NSLog(@"double click end");
}
%end
%hook SBIconView
- (void)didMoveToWindow
{
%orig;
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDoubleClick:)];
[doubleTap setNumberOfTapsRequired:2];
[self addGestureRecognizer:doubleTap];
NSArray * ges = self.gestureRecognizers;
for(UITapGestureRecognizer * each in ges){
if([each isKindOfClass:[UITapGestureRecognizer class]]){
[each requireGestureRecognizerToFail: doubleTap];
}
}
}
- (void)tapGestureDidChange:(id)ges
{
NSLog(@"single click");
%orig;
}
%end