-
Notifications
You must be signed in to change notification settings - Fork 3
/
Tweak.xm
592 lines (513 loc) · 17.3 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
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
#import "Global.h"
#import <tweet2weibo/UIPushButton.h>
#import <tweet2weibo/UIActionSheet-Private.h>
#import <tweet2weibo/QuartzCore.h>
#import <tweet2weibo/GSEvent.h>
#import <tweet2weibo/TWTweetComposeViewController.h>
#import <tweet2weibo/TWUserRecord.h>
#import <tweet2weibo/TWMentionTableViewCell.h>
#import <tweet2weibo/TWTweetSheetLocationAssembly.h>
#import <tweet2weibo/TWTweetComposeViewController-TWTweetComposeViewControllerMentionAdditions.h>
#import "weiboSearchFriendsViewViewController.h"
#import "WBAuthorize.h"
#import "SendAgent.h"
#import "substrate.h"
#import "sqlService.h"
//API key
#define AppKey @"972468350"
#define AppSecret @"a0aaeb3074a4ed4e0aa493c34084e046"
//////////////////////////
/////// IPC LOGIN////////
//////////////////////////
BOOL getStatus(){
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
NSDictionary* reply = [center sendMessageAndReceiveReplyName:@"com.icenuts.photo2weibo.login" userInfo: nil];
if([[reply valueForKey: @"msg"] isEqualToString: @"1"]){
return YES;
}else{
return NO;
}
}
//////////////////////////
/////// IPC LOGIN////////
//////////////////////////
//Variables for runtime Objects
static id mySheet = nil;
static id rootView = nil;
static id myView = nil;
static id fullPath = nil;
static id PLViewController = nil;
static BOOL pwflag = false;
static TWTweetComposeViewController *sendView = nil;
//////////////////////////
/////// Twitter UI////////
//////////////////////////
//Hook for twitter UI
id cell;
id searchBarText = [[NSString alloc] init];
BOOL isCancelTapped = NO;
%hook UIButton
- (void)setEnabled:(BOOL)arg1{
if(pwflag){
%orig(YES);
return;
}
%orig(arg1);
}
%end
%hook TWTweetComposeViewController
+ (BOOL)canSendTweet{
if(pwflag){
return true;
}
return %orig;
}
+ (BOOL)canSendTweetViaTwitterd{
if(pwflag){
return true;
}
return %orig;
}
- (void)send:(id)arg1{
if(pwflag){
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: [self enteredText], @"text", fullPath, @"imgPath",nil ];
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
[center sendMessageName:@"com.icenuts.photo2weibo.send" userInfo: dictionary];
pwflag = false;
[self complete: 0];
}else{
%orig;
}
}
- (void)sendButtonTapped:(id)arg1{
isCancelTapped = NO;
if(pwflag){
[self send: arg1];
return;
}
%orig;
}
- (void)cancelButtonTapped:(id)arg1{
NSLog(@"----%@----", [self class]);
isCancelTapped = YES;
%orig;
}
- (void)viewWillDisappear:(BOOL)arg1{
if(arg1 && pwflag && isCancelTapped){
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
[center sendMessageName:@"com.icenuts.photo2weibo.cleardb" userInfo: nil];
pwflag = false;
isCancelTapped = NO;
}
%orig;
}
- (void)textViewDidChange:(id)arg1{
//B: IPC For Renew Content
if(pwflag){
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: [self enteredText], @"text", nil ];
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
[center sendMessageName:@"com.icenuts.photo2weibo.renew" userInfo: dictionary];
}
//E: IPC For Renew Content
%orig;
}
//hook to grab the superclass's variable
- (void)viewDidAppear:(BOOL)arg1{
if(pwflag){
Ivar var;
const char *name = "_tweetTitleLabel";
var = class_getInstanceVariable([self class], name);
id label = object_getIvar(self, var);
if([[label text] isEqualToString:@"Tweet"] || [[label text] isEqualToString:@"Weibo"]){
[label setText: @"Weibo"];
}else{
[label setText: @"新浪微博"];
}
var = class_getInstanceVariable([self class], "_locationAssembly");
id assembly = object_getIvar(self, var);
var = class_getInstanceVariable([TWTweetSheetLocationAssembly self], "_assemblyView");
id geo = object_getIvar(assembly, var);
[geo setHidden: YES];
var = class_getInstanceVariable([self class], "_sendButton");
id sendButton = object_getIvar(self, var);
[sendButton setEnabled: YES];
}
%orig;
}
/////////////////////////
//HOOK FOR MULTIACCOUNTS
/////////////////////////
- (BOOL)showAccountFieldForOrientation:(int)arg1{
//get account number
return NO;
}
/////////////////////////
//HOOK FOR MULTIACCOUNTS
/////////////////////////
- (void)appWillMoveToBackground:(id)arg1{
pwflag = false;
%orig;
}
- (void)presentNoAccountsDialog{
if(!pwflag){
%orig;
}
}
- (int)characterCountForEnteredText:(id)arg1 attachments:(id)arg2 allImagesDownsampled:(char *)arg3{
if(pwflag){
arg2 = nil;
}
return %orig;
}
- (void)tableView:(id)arg1 didSelectRowAtIndexPath:(id)arg2{
cell = [arg1 cellForRowAtIndexPath:arg2];
%orig;
}
- (void)searchBar:(id)arg1 textDidChange:(id)arg2{
searchBarText = [arg2 copy];
if(pwflag){
[self noteMentionsResultsChanged];
}
%orig;
}
- (void)searchBarWillClear:(id)arg1{
%orig;
}
- (id)currentResults{
if(pwflag){
//Use weibodb
NSMutableArray *specs = [NSMutableArray array];
if([searchBarText isEqualToString: @""]){
NSLog(@"------CLEAR------");
return nil;
}
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
NSDictionary *Result = [center sendMessageAndReceiveReplyName:@"com.icenuts.photo2weibo.query" userInfo: [NSDictionary dictionaryWithObjectsAndKeys: searchBarText, @"msg",nil ]];
TWUserRecord *item1 = [TWUserRecord userRecordWithScreenName: searchBarText];
[specs addObject: item1];
int number = [Result count];
NSString *object;
NSRange myRange;
NSString *screenName = nil;
NSString *alias = nil;
NSString *sqlAliasdelete1;
NSString *screenAliasTemp;
for(int i = 0; i < number; i++){
object = [Result valueForKey:[NSString stringWithFormat:@"%i",i]];
myRange = [object rangeOfString:@"("];
if(myRange.length > 0){
screenName = [object substringToIndex: myRange.location];
screenAliasTemp = [object substringFromIndex:myRange.location];
sqlAliasdelete1 = [screenAliasTemp stringByReplacingOccurrencesOfString:@"(" withString:@""];
alias = [sqlAliasdelete1 stringByReplacingOccurrencesOfString:@")" withString:@""];
}else{
screenName = [object copy];
}
TWUserRecord *item = [TWUserRecord userRecordWithScreenName: screenName];
[item setName: alias];
[specs addObject: item];
}
return [specs retain];
}else{
return %orig;
}
}
- (struct _NSRange)applyMention:(id)arg1{
if(pwflag && [[cell userRecord] screen_name] != nil){
arg1 = [[[cell userRecord] screen_name] stringByAppendingString: @" "];
}else if(arg1 == nil){
Ivar var;
const char *name = "_searchField";
var = class_getInstanceVariable([self class], name);
id searchBar = object_getIvar(self, var);
arg1 = [searchBar text];
}
return %orig;
}
%end
//////////////////////////
/////// Twitter UI////////
//////////////////////////
@interface handleAlertView: NSObject<UIAlertViewDelegate>
@end
@implementation handleAlertView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag == 100){
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
[center sendMessageName:@"com.icenuts.photo2weibo.redirect" userInfo: nil];
}
}
@end
//Basic hook method for PhotoBrowser
@interface PLPhotoBrowserController
- (id)_actionViewRootView;
@end
//Basic hook for adding button in ActionSheet
%hook UIActionSheet
- (void)presentSheetInView:(id)arg1{
NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
if ([bundleId isEqualToString:@"com.apple.mobileslideshow"] || [bundleId isEqualToString:@"com.apple.camera"]);
id button = [self buttons];
BOOL x1 = [[[button objectAtIndex:0] title] isEqualToString: @"Email Photo"];
BOOL x2 = [[[button objectAtIndex:0] title] isEqualToString: @"用电子邮件发送照片"];
BOOL x3 = [[[button objectAtIndex:0] title] isEqualToString: @"透過電子郵件傳送照片"];
if(x1 || x2 || x3){
NSLog(@"----I INJECT U-----");
if(x1){
[self addButtonWithTitle:@"Weibo"];
}else if(x2){
[self addButtonWithTitle:@"新浪微博"];
}else if(x3){
[self addButtonWithTitle:@"新浪微薄"];
}
[button exchangeObjectAtIndex:[button count] - 2 withObjectAtIndex:[button count] - 1];
id cancelButton = [button objectAtIndex:[button count] - 1];
if (cancelButton) {
[cancelButton setTag:[button count]];
}
id weiboButton = [button objectAtIndex:[button count] - 2];
if (weiboButton) {
[weiboButton setTag:[button count] - 1];
}
self.cancelButtonIndex = [button count] - 1;
//Get sheet
mySheet = self;
}
%orig;
}
- (void)_presentFromBarButtonItem:(id)arg1 orFromRect:(struct CGRect)arg2 inView:(id)arg3 direction:(int)arg4 allowInteractionWithViews:(id)arg5 backgroundStyle:(int)arg6 animated:(BOOL)arg7{
NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
BOOL iPad = [[[UIDevice currentDevice] model] isEqualToString: @"iPad"];
if (([bundleId isEqualToString:@"com.apple.mobileslideshow"] || [bundleId isEqualToString:@"com.apple.camera"]) && iPad){
id button = [self buttons];
BOOL x1 = [[[button objectAtIndex:0] title] isEqualToString: @"Email Photo"];
BOOL x2 = [[[button objectAtIndex:0] title] isEqualToString: @"用电子邮件发送照片"];
BOOL x3 = [[[button objectAtIndex:0] title] isEqualToString: @"透過電子郵件傳送照片"];
if(x1 || x2 || x3){
NSLog(@"----I INJECT U-----");
if(x1){
[self addButtonWithTitle:@"Weibo"];
}else if(x2){
[self addButtonWithTitle:@"新浪微博"];
}else if(x3){
[self addButtonWithTitle:@"新浪微薄"];
}
//Get sheet
mySheet = self;
}
}
%orig;
}
- (void)dismissWithClickedButtonIndex:(int)arg1 animated:(BOOL)arg2{
if(arg1 == -1){
%orig(-1,1);
return;
}
NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
BOOL iPad = [[[UIDevice currentDevice] model] isEqualToString: @"iPad"];
if ((([bundleId isEqualToString:@"com.apple.mobileslideshow"] || [bundleId isEqualToString:@"com.apple.camera"]) && iPad)){
BOOL x1 = [[self buttonTitleAtIndex: arg1] isEqualToString: @"Weibo"];
BOOL x2 = [[self buttonTitleAtIndex: arg1] isEqualToString: @"新浪微博"];
BOOL x3 = [[self buttonTitleAtIndex: arg1] isEqualToString: @"新浪微薄"];
if(x1 || x2 || x3){
NSLog(@"----I CREATE------");
pwflag = true;
UIImage *tmp = [UIImage imageWithContentsOfFile: fullPath];
CGSize newSize = CGSizeMake(100, 100);
UIGraphicsBeginImageContext(newSize);
[tmp drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"-----LOGIN? %i-----", getStatus());
if(getStatus()){
Class $TWTweetComposeViewController = objc_getClass("TWTweetComposeViewController");
if(sendView == nil){
sendView = [[$TWTweetComposeViewController alloc] init];
}
[sendView addImage: myImage];
//B: IPC For Remnant
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
NSDictionary* reply = [center sendMessageAndReceiveReplyName:@"com.icenuts.photo2weibo.remnant" userInfo: nil];
[sendView _setText: [reply valueForKey: @"msg"]];
//E: IPC For Remnant
[PLViewController presentModalViewController: sendView animated: NO];
[sendView noteStatusChanged];
[sendView noteCheckedInWithDaemon];
}else{
//redirect
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
[center sendMessageName:@"com.icenuts.photo2weibo.redirect" userInfo: nil];
}
}else{
pwflag = false;
}
}
%orig;
}
%end
//For iPad
%hook PLPhotoBrowserController
- (void)viewWillAppear{
PLViewController = self;
%orig;
}
%end
//Basic hook for fetching the image
@interface PLManagedAsset
@property(retain, nonatomic) NSString *originalPath;
@property int originalFilesizeValue;
@property(retain, nonatomic) NSString *filename; // @dynamic filename;
@property(retain, nonatomic) NSString *directory; // @dynamic directory;
@end
@interface PLPhotoTileViewController
@property(readonly, nonatomic) PLManagedAsset *photo;
- (id)imageView;
@end
%hook PLPhotoTileViewController
- (void)viewDidAppear:(BOOL)arg1{
PLManagedAsset *info = [self photo];
NSString *filename = [info filename];
NSString *directory = [info directory];
if(!directory){
%orig;
return;
}
NSString *path = [[@"/User/Media/" stringByAppendingString: directory] stringByAppendingString: @"/"];
fullPath = [[path stringByAppendingString: filename] copy];
NSLog(@"PATH: %@ : I am here to fetch your photo", fullPath);
myView = [self imageView];
%orig;
}
%end
//Basic hook for
@interface PLPhotoScrollerViewController
- (id)_actionViewRootView;
- (void)disableAutohideControls;
- (void)enableAutohideControls;
- (void)setRotationDisabled:(BOOL)arg1;
- (void)_cancelToolbarTimer;
- (void)_setAutohidesControls:(BOOL)arg1;
- (void)setStatusBarIsLocked:(BOOL)arg1;
- (BOOL)autohideControlsIsEnabled;
- (void)hideOverlaysWithDuration:(float)arg1 hideStatusBar:(BOOL)arg2;
- (id)_currentToolbarItems;
@property(nonatomic) BOOL isCameraApp; // @synthesize isCameraApp=_isCameraApp;
@end
%hook PLPhotoScrollerViewController
- (void)actionSheet:(id)sheet clickedButtonAtIndex:(int)index{
BOOL x1 = [[sheet buttonTitleAtIndex: index] isEqualToString: @"Weibo"];
BOOL x2 = [[sheet buttonTitleAtIndex: index] isEqualToString: @"新浪微博"];
BOOL x3 = [[sheet buttonTitleAtIndex: index] isEqualToString: @"新浪微薄"];
if([sheet isEqual: mySheet] && (x1 || x2 || x3)){
rootView = [self _actionViewRootView];
PLViewController = self;
NSLog(@"----I CREATE------");
pwflag = true;
UIImage *tmp = [UIImage imageWithContentsOfFile: fullPath];
CGSize newSize = CGSizeMake(100, 100);
UIGraphicsBeginImageContext(newSize);
[tmp drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* myImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"-----LOGIN? %i-----", getStatus());
if(getStatus()){
Class $TWTweetComposeViewController = objc_getClass("TWTweetComposeViewController");
if(sendView == nil){
sendView = [[$TWTweetComposeViewController alloc] init];
}
[sendView addImage: myImage];
//B: IPC For Remnant
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
NSDictionary* reply = [center sendMessageAndReceiveReplyName:@"com.icenuts.photo2weibo.remnant" userInfo: nil];
[sendView _setText: [reply valueForKey: @"msg"]];
//E: IPC For Remnant
[PLViewController presentViewController: sendView animated: NO completion: NULL];
[sendView noteStatusChanged];
[sendView noteCheckedInWithDaemon];
}else{
//redirect
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Photo2Weibo"]];
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
[center sendMessageName:@"com.icenuts.photo2weibo.redirect" userInfo: nil];
}
}else{
pwflag = false;
}
%orig;
}
%end
//Hook for Keyboard
static CGPoint myAtArea;
static CGPoint myAtRadii;
static CGPoint myHitPoint;
static CGPoint mySArea;
static CGPoint mySRadii;
@interface UIKeyboardImpl
-(int)returnKeyType;
@end
%hook UIKeyboardImpl
-(void)longPressAction{
if(!pwflag){
%orig;
return;
}
NSString *bundleId = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
if ([bundleId isEqualToString:@"com.apple.mobileslideshow"] || [bundleId isEqualToString:@"com.apple.camera"]){
//judge for @
int Atmax_x = myAtArea.x + myAtRadii.x;
int Atmin_x = myAtArea.x - myAtRadii.x;
int Atmax_y = myAtArea.y + myAtRadii.y;
int Atmin_y = myAtArea.y - myAtRadii.y;
//judge for S
int Smax_x = mySArea.x + mySRadii.x;
int Smin_x = mySArea.x - mySRadii.x;
int Smax_y = mySArea.y + mySRadii.y;
int Smin_y = mySArea.y - mySRadii.y;
BOOL isAt = NO;
BOOL isS = NO;
if(myHitPoint.x <= Atmax_x && myHitPoint.x >= Atmin_x && myHitPoint.y <= Atmax_y && myHitPoint.y >= Atmin_y){
isAt = YES;
}
if(myHitPoint.x <= Smax_x && myHitPoint.x >= Smin_x && myHitPoint.y <= Smax_y && myHitPoint.y >= Smin_y){
isS = YES;
}
if(isAt)
{
}else if(isS){
//Redirect to preference
CPDistributedMessagingCenter *center;
center = [CPDistributedMessagingCenter centerNamed:@"com.icenuts.photo2weibo.bannerserver"];
[center sendMessageName:@"com.icenuts.photo2weibo.redirect" userInfo: nil];
}else{
%orig;
}
}else{
%orig;
}
}
-(void)setInputPoint:(CGPoint)point{
myHitPoint = point;
%orig;
}
-(void)registerKeyArea:(CGPoint)area withRadii:(CGPoint)radii forKeyCode:(unsigned short)keyCode forLowerKey:(id)lowerKey forUpperKey:(id)upperKey{
if([upperKey isEqualToString: @"@"]){
myAtArea = area;
myAtRadii = radii;
}
if([upperKey isEqualToString: @"S"] || [lowerKey isEqualToString: @"s"]){
mySArea = area;
mySRadii = radii;
}
%orig;
}
%end