-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTweak.xm
351 lines (300 loc) · 11.8 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
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
//#define NSLog(fmt, ...)
@interface SBClockDataProvider : NSObject
+ (id)sharedInstance;
@end
@interface PCSimpleTimer : NSObject
@property BOOL disableSystemWaking;
- (BOOL)disableSystemWaking;
- (id)initWithFireDate:(id)arg1 serviceIdentifier:(id)arg2 target:(id)arg3 selector:(SEL)arg4 userInfo:(id)arg5;
- (id)initWithTimeInterval:(double)arg1 serviceIdentifier:(id)arg2 target:(id)arg3 selector:(SEL)arg4 userInfo:(id)arg5;
- (void)invalidate;
- (BOOL)isValid;
- (void)scheduleInRunLoop:(id)arg1;
- (void)setDisableSystemWaking:(BOOL)arg1;
- (id)userInfo;
@end
@interface MFMessage : NSObject <NSCopying>
- (id)messageIDHeader;
- (id)subject;
@end
@interface MFMailMessage : MFMessage
@end
@interface MailboxContentSelectionModel : NSObject
-(id)selectedMessages;
@end
@interface MailboxContentViewCell : UITableViewCell
- (MFMailMessage *)message;
@end
@interface MailboxContentViewController : UIViewController
//@property (nonatomic,retain) UITableView * tableView;
-(id)currentTableView;
@end
#define timerExamplePList @"/private/var/mobile/Library/Preferences/net.tateu.timerexample.plist"
#define timerExampleBundleID @"net.tateu.timerexample"
#define timerExampleNotification "net.tateu.timerexample/starttimer"
static PCSimpleTimer *timerExample = nil;
static UIAlertView *timerExampleAlert = nil;
static void TimerExampleLoadTimer();
%group MAIL
%hook MailboxContentViewController
%new
-(void)longPressEmailET:(UILongPressGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
CGPoint p = [gestureRecognizer locationInView:[self currentTableView]];
NSIndexPath *indexPath = [[self currentTableView] indexPathForRowAtPoint:p];
if (indexPath == nil) {
} else {
NSString *title = @"ERROR";
NSString *msg = nil;
MailboxContentViewCell *cell = (MailboxContentViewCell *)[[self currentTableView] cellForRowAtIndexPath:indexPath];
if (cell) {
float fireDateOffsetSeconds = 0;
if ((p.x - cell.frame.origin.x) < (cell.frame.size.width / 2.0)) {
fireDateOffsetSeconds = 120;
} else {
fireDateOffsetSeconds = 240;
}
// Failed attempt to use userInfo passed from a sandboxed process to SpringBoard
//
//
//// CFDictionaryKeyCallBacks keyCallbacks = {0, NULL, NULL, CFCopyDescription, CFEqual, NULL};
//// CFDictionaryValueCallBacks valueCallbacks = {0, NULL, NULL, CFCopyDescription, CFEqual};
//// CFMutableDictionaryRef dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &keyCallbacks, &valueCallbacks);
// CFMutableDictionaryRef dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
//
// CFNumberRef fireDateOffsetSecondsNum = CFNumberCreate(kCFAllocatorDefault, kCFNumberFloatType, &fireDateOffsetSeconds);
// CFDictionaryAddValue(dictionary, CFSTR("fireDateOffsetSeconds"), fireDateOffsetSecondsNum);
//
// if ([[cell message] messageIDHeader]) {
// NSString *deepLink = [NSString stringWithFormat:@"message://%@", [[[cell message] messageIDHeader] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// CFDictionaryAddValue(dictionary, CFSTR("deepLink"), (__bridge CFStringRef)deepLink);
// }
//
// if ([[cell message] subject]) {
// CFDictionaryAddValue(dictionary, CFSTR("subject"), (__bridge CFStringRef)[[cell message] subject]);
// }
//
// CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR(timerExampleNotification), NULL, dictionary, TRUE);
// CFRelease(dictionary);
//
//
// Failed attempt to use userInfo passed from a sandboxed process to SpringBoard
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
NSDate *fireDate = [NSDate dateWithTimeInterval:fireDateOffsetSeconds sinceDate:[NSDate date]];
[data setObject:fireDate forKey:@"fireDate"];
if ([[cell message] messageIDHeader]) {
NSString *deepLink = [NSString stringWithFormat:@"message://%@", [[[cell message] messageIDHeader] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[data setObject:deepLink forKey:@"deepLink"];
}
if ([[cell message] subject]) {
[data setObject:[[cell message] subject] forKey:@"subject"];
}
[data writeToFile:timerExamplePList atomically:YES];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.25 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
NSLog(@"[TimerExample] sending CFNotificationCenterPostNotification");
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR(timerExampleNotification), NULL, NULL, TRUE);
});
} else {
msg = @"Unable to locate email cell. Maybe you did not tap and hold directly on an email!";
}
if (msg) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:title
message:msg
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
}
}
}
}
-(void)viewWillAppear:(BOOL)animated
{
%orig;
UILongPressGestureRecognizer *gesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressEmailET:)];
gesture.minimumPressDuration = 1.0; //seconds
[[self currentTableView] addGestureRecognizer:gesture];
}
%end //hook MailboxContentViewController
%end //group MAIL
%group SPRINGBOARD
%hook SpringBoard
-(void)applicationDidFinishLaunching:(id)application
{
%orig;
NSLog(@"[TimerExample] SpringBoard applicationDidFinishLaunching");
TimerExampleLoadTimer();
}
%end
%hook SBClockDataProvider
%new
- (void)TimerExampleOpenURL:(id)sender
{
UIButton *button = (UIButton *)sender;
[[UIApplication sharedApplication] openURL:[[NSURL alloc] initWithString:button.currentTitle]];
if (timerExampleAlert) {
[timerExampleAlert dismissWithClickedButtonIndex:0 animated:YES];
timerExampleAlert = nil;
}
}
%new
- (void)TimerExampleFired
{
NSLog(@"[TimerExample] TimerExampleFired");
NSDictionary *userInfo = [timerExample userInfo];
NSString *title = @"Example Timer Fired";
NSString *msg = @"No Subject";
UIView *buttonView = nil;
if (userInfo) {
if ([userInfo objectForKey:@"subject"]) {
msg = [userInfo objectForKey:@"subject"];
}
if ([userInfo objectForKey:@"deepLink"]) {
buttonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
[buttonView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
buttonView.backgroundColor = [UIColor clearColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0, 0, 100, 44);
[button setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
button.backgroundColor = [UIColor colorWithRed:0.8 green: 0.0 blue:0.0 alpha:1.0];
[button setTitle:[userInfo objectForKey:@"deepLink"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(TimerExampleOpenURL:) forControlEvents:UIControlEventTouchUpInside];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[buttonView addSubview:button];
}
}
timerExampleAlert = [[UIAlertView alloc]
initWithTitle:title
message:msg
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
timerExampleAlert.tag = 4615;
if (buttonView) {
[timerExampleAlert setValue:buttonView forKey:@"accessoryView"];
}
[timerExampleAlert show];
if (timerExample) {
[timerExample invalidate];
timerExample = nil;
}
}
%end //hook SBClockDataProvider
%end //group SPRINGBOARD
static void TimerExampleLoadTimer()
{
NSDictionary *userInfoDictionary = nil;
NSString *deepLink = nil;
NSString *subject = nil;
userInfoDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:timerExamplePList];
if (!userInfoDictionary) {
return;
}
deepLink = [userInfoDictionary objectForKey:@"deepLink"];
subject = [userInfoDictionary objectForKey:@"subject"];
NSDate *fireDate = [userInfoDictionary objectForKey:@"fireDate"];
if (!fireDate || [[NSDate date] compare:fireDate] == NSOrderedDescending) {
NSLog(@"[TimerExample] TimerExampleLoadTimer - invalid or in the past");
return;
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
if (deepLink) {
[data setObject:deepLink forKey:@"deepLink"];;
}
if (subject) {
[data setObject:subject forKey:@"subject"];
}
timerExample = [[%c(PCSimpleTimer) alloc] initWithFireDate:fireDate serviceIdentifier:timerExampleBundleID target:[%c(SBClockDataProvider) sharedInstance] selector:@selector(TimerExampleFired) userInfo:data];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
[formatter setTimeZone:[NSTimeZone defaultTimeZone]];
NSLog(@"[TimerExample] Added Timer %@", [formatter stringFromDate:fireDate]);
if ([NSThread isMainThread]) {
[timerExample scheduleInRunLoop:[NSRunLoop mainRunLoop]];
} else {
dispatch_async(dispatch_get_main_queue(), ^ {
[timerExample scheduleInRunLoop:[NSRunLoop mainRunLoop]];
});
}
}
static void TimerExampleNotified(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
// Failed attempt to use userInfo passed from a sandboxed process to SpringBoard
//
//
// NSDictionary *userInfoDictionary = nil;
// float fireDateOffsetSeconds = 5;
// NSString *deepLink = nil;
// NSString *subject = nil;
//
//
// Failed attempt to use userInfo passed from a sandboxed process to SpringBoard
NSLog(@"[TimerExample] received CFNotificationCenterPostNotification");
// kill old timer
if (timerExample) {
[timerExample invalidate];
timerExample = nil;
}
TimerExampleLoadTimer();
// Failed attempt to use userInfo passed from a sandboxed process to SpringBoard
//
//
//// if (userInfo) {
//// CFNumberRef fireDateOffsetSecondsNum = (CFNumberRef)CFDictionaryGetValue(userInfo, CFSTR("fireDateOffsetSeconds"));
//// if (fireDateOffsetSecondsNum) {
//// CFNumberGetValue(fireDateOffsetSecondsNum, kCFNumberFloatType, &fireDateOffsetSeconds);
//// }
////
//// CFNumberRef fireDateOffsetSecondsNum = (CFNumberRef)CFDictionaryGetValue(userInfo, CFSTR("fireDateOffsetSeconds"));
//// if (fireDateOffsetSecondsNum) {
//// CFNumberGetValue(fireDateOffsetSecondsNum, kCFNumberFloatType, &fireDateOffsetSeconds);
//// }
//// }
// userInfoDictionary = (__bridge NSDictionary *)dictionary;
//
// if (!userInfoDictionary) {
// return;
// }
//
// deepLink = [userInfoDictionary objectForKey:@"deepLink"];
// subject = [userInfoDictionary objectForKey:@"subject"];
// fireDateOffsetSeconds = [userInfoDictionary objectForKey:@"fireDateOffsetSeconds"] ? [[userInfoDictionary objectForKey:@"fireDateOffsetSeconds"] floatValue] : fireDateOffsetSeconds;
//
// NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
//
// if (deepLink) {
// [data setObject:deepLink forKey:@"deepLink"];;
// }
//
// if (subject) {
// [data setObject:subject forKey:@"subject"];
// }
//
// NSDate *fireDate = [NSDate dateWithTimeInterval:fireDateOffsetSeconds sinceDate:[NSDate date]];
// [timerExample setMinimumEarlyFireProportion:86400];
// timerExample = [[%c(PCPersistentTimer) alloc] initWithFireDate:fireDate serviceIdentifier:TimerExampleBundleID target:[%c(SBClockDataProvider) sharedInstance] selector:@selector(TimerExampleFired) userInfo:data];
//
// if ([NSThread isMainThread]) {
// [timerExample scheduleInRunLoop:[NSRunLoop mainRunLoop]];
// } else {
// dispatch_async(dispatch_get_main_queue(), ^ {
// [timerExample scheduleInRunLoop:[NSRunLoop mainRunLoop]];
// });
// }
//
//
// Failed attempt to use userInfo passed from a sandboxed process to SpringBoard
}
%ctor
{
@autoreleasepool {
if (%c(SpringBoard)) {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, TimerExampleNotified, CFSTR(timerExampleNotification), NULL, CFNotificationSuspensionBehaviorCoalesce);
%init(SPRINGBOARD);
} else {
%init(MAIL);
}
}
}