forked from firecore/Seas0nPass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtetherKitAppDelegate.m
More file actions
3720 lines (2822 loc) · 111 KB
/
tetherKitAppDelegate.m
File metadata and controls
3720 lines (2822 loc) · 111 KB
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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// tetherKitAppDelegate.m
// Seas0nPass
//
// Created by Kevin Bradley on 12/27/10.
// Copyright 2011 Fire Core, LLC. All rights reserved.
//
// Portions Copyright 2010 Joshua Hill & Chronic-Dev Team
// Portions Copyright 2010 planetbeing & iPhone-Dev Team
// libpois0n/libsyringe by Joshua Hill & Chronic-Dev Team. ( feel free to help me update these credits )
// xpwntool by planetbeing
// limera1n exploit by George Hotz
// 4.3.x exploit by i0n1c (steffan esser)
// 4.3.3 exploit by comex
// 4.4.x exploit by pod2g
//4.3b1 md5 for iBSS 0b03c11af9bd013a6cf98be65eb0e146
//4.3b1 patched md5 for iBSS
#import <Security/Authorization.h>
#include <Security/AuthorizationTags.h>
#import "tetherKitAppDelegate.h"
#import "include/libpois0n.h"
#import <Foundation/Foundation.h>
//CURRENT_BUNDLE is the finally the only place that the bundle name needs to be replaced to change default version for future versions.
//previous @"AppleTV2,1_4.4.4_9A406a"
#define CURRENT_BUNDLE @"AppleTV2,1_5.0.2_9B830"
#define CURRENT_IPSW [NSString stringWithFormat:@"%@_Restore.ipsw", CURRENT_BUNDLE]
#define DL [tetherKitAppDelegate downloadLocation]
#define KCACHE @"kernelcache.release.k66"
#define iBSSDFU @"iBSS.k66ap.RELEASE.dfu"
#define iBECDFU @"iBEC.k66ap.RELEASE.dfu"
#define HCIPSW [DL stringByAppendingPathComponent:CURRENT_IPSW]
#define BUNDLE_LOCATION [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"bundles"]
#define BUNDLES [FM contentsOfDirectoryAtPath:BUNDLE_LOCATION error:nil]
#define BLOB_KEY @"sentLocalBlobs"
#define BLOBS_SENT [[NSUserDefaults standardUserDefaults] boolForKey:BLOB_KEY]
#define DID_MIGRATE [[NSUserDefaults standardUserDefaults] boolForKey:@"newVersionMigrate"]
#define LAST_BUNDLE [[NSUserDefaults standardUserDefaults] valueForKey:@"lastUsedBundle"]
#define KILL_ITUNES [[NSUserDefaults standardUserDefaults] boolForKey:@"killiTunes"]
#define DEFAULTS [NSUserDefaults standardUserDefaults]
int received_cb(irecv_client_t client, const irecv_event_t* event);
int progress_cb(irecv_client_t client, const irecv_event_t* event);
static NSString *ChipID_ = nil;
@implementation tetherKitAppDelegate
@synthesize window, downloadIndex, processing, enableScripting, firstView, secondView, poisoning, currentBundle, bundleController, counter, otherWindow, commandTextField, tetherLabel, countdownField, runMode, theEcid;
@synthesize deviceClass;
/*
this application is a bit of an amalgam of code from libsyringe, a few random classes from hawkeye and atvPwn and then iphone wiki notes / deciphering what pwnagetool does
by hand / creation of the bundles for PwnageTool
this could be seperated into several (or at least a few) different classes, but TBH, im lazy. The only reason im even putting these comments in here are the inevitability
of having to open source this because i know at very least libsyringe is GPL (and i wouldn't be surprised if xpwn is as well).
*/
/* probably not using this callback data variable properly, but i couldnt figure out how else to set download progress from the double values sent during uploading of iBSS and kernelcache */
void print_progress(double progress, void* data) {
int i = 0;
if(progress < 0) {
return;
}
if(progress > 100) {
progress = 100;
}
[data setDownloadProgress:progress];
printf("\r[");
for(i = 0; i < 50; i++) {
if(i < progress / 2) {
printf("=");
} else {
printf(" ");
}
}
printf("] %3.1f%%", progress);
if(progress == 100) {
printf("\n");
}
}
/*
code for in case i ever add a fancy timer
- (void)nextCountdown
{
counter = 7;
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(secondTimer:) userInfo:nil repeats:YES];
}
- (void)firstTimer:(NSTimer *)timer
{
[self setCounter:(counter -1)];
//[countdownField setIntegerValue:counter];
if (counter <= 1) {
[timer invalidate];
[self nextCountdown];
}
}
- (void)secondTimer:(NSTimer *)timer
{
[self setCounter:(counter -1)];
[countdownField setIntegerValue:counter];
if (counter <= 1) {
[timer invalidate];
}
}
- (IBAction)startCountdown:(id)sender
{
counter = 5;
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(firstTimer:) userInfo:nil repeats:YES];
}
*/
//if ([theEvent modifierFlags] == 262401){
- (BOOL) optionKeyIsDown
{
return (GetCurrentKeyModifiers() & optionKey) != 0;
}
- (__strong const char *)iBEC
{
NSString *iBEC = [[self currentBundle] localiBEC];
//NSLog(@"self current bundle: %@", self.currentBundle);
//NSLog(@"iBEC: %@", iBEC);
return [iBEC UTF8String];
}
- (__strong const char *)iBSS
{
NSString *iBSS = [[self currentBundle] localiBSS];
return [iBSS UTF8String];
}
- (__strong const char *)kernelcache
{
NSString *kc = [[self currentBundle] localKernel];
return [kc UTF8String];
}
- (NSString *)kcacheString
{
return [[self currentBundle] localKernel];
}
- (NSString *)iBSSString
{
return [[self currentBundle] localiBSS];
}
- (NSImage *)imageForMode:(int)inputMode
{
NSImage *theImage = nil;
switch (inputMode) {
case kSPATVRestoreImage:
theImage = [NSImage imageNamed:@"restore"];
break;
case kSPATVTetheredImage:
theImage = [NSImage imageNamed:@"tether"];
break;
case kSPSuccessImage:
theImage = [NSImage imageNamed:@"success"];
break;
case kSPIPSWImage:
theImage = [NSImage imageNamed:@"ipsw"];
break;
case kSPATVTetheredRemoteImage:
theImage = [NSImage imageNamed:@"tetheredRemote"];
break;
case kSPATVUntetheredImage:
theImage = [NSImage imageNamed:@"untethered"];
break;
}
return theImage;
}
- (void)dealloc
{
[downloadFiles release];
downloadFiles = nil;
[theEcid release];
theEcid = nil;
[[NSDistributedNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (void)startupAlert //deprecated till theres a tethered default version again.
{
NSUserDefaults *defaults = DEFAULTS;
BOOL warningShown = [defaults boolForKey:@"SPWarningShown"];
if (warningShown == TRUE)
return;
NSAlert *startupAlert = [NSAlert alertWithMessageText:@"Warning! Please read carefully." defaultButton:@"OK" alternateButton:@"More Info" otherButton:@"Cancel" informativeTextWithFormat:@"Currently the jailbreak for the 4.1.1 (iOS 4.2.1) software is 'tethered'. A tethered jailbreak requires the Apple TV to be connected to a computer for a brief moment during startup.\n\nSeas0nPass makes this as easy as possible, but please do not proceed unless you are comfortable with this process."];
int button = [startupAlert runModal];
switch (button) {
case 0: //more info
[self userGuides:nil];
break;
case 1: //okay
break;
case -1: //cancel and quit!!
[[NSApplication sharedApplication] terminate:self];
break;
}
[defaults setBool:YES forKey:@"SPWarningShown"];
}
- (NSString *)ipswOutputPath
{
return [[self currentBundle] outputFile];
}
void LogIt (NSString *format, ...)
{
va_list args;
va_start (args, format);
NSString *string;
string = [[NSString alloc] initWithFormat: format arguments: args];
va_end (args);
printf ("%s", [string UTF8String]);
[string release];
} // LogIt
- (BOOL)isMountainLion
{
unsigned major, minor, bugFix;
[[NSApplication sharedApplication] getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
NSString *comparisonVersion = @"10.8.0";
NSString *osVersion = [NSString stringWithFormat:@"%u.%u.%u", major, minor, bugFix];
NSComparisonResult theResult = [osVersion compare:comparisonVersion options:NSNumericSearch];
//NSLog(@"theversion: %@ installed version %@", theVersion, installedVersion);
if ( theResult == NSOrderedDescending )
{
//NSLog(@"%@ is greater than %@", osVersion, comparisonVersion);
return YES;
} else if ( theResult == NSOrderedAscending ){
//NSLog(@"%@ is greater than %@", comparisonVersion, osVersion);
return NO;
} else if ( theResult == NSOrderedSame ) {
// NSLog(@"%@ is equal to %@", osVersion, comparisonVersion);
return YES;
}
return NO;
}
- (void)printEnvironment
{
unsigned major, minor, bugFix;
[[NSApplication sharedApplication] getSystemVersionMajor:&major minor:&minor bugFix:&bugFix];
NSDictionary *bundle = [[NSBundle mainBundle] infoDictionary];
//NSLog(@"info: %@", [[NSBundle mainBundle] infoDictionary]);
NSString *bv = [self buildVersion];
NSString *process = [NSString stringWithFormat:@"Process:\t\t%@\n", [bundle valueForKey:@"CFBundleExecutable"] ];
NSString *path = [NSString stringWithFormat:@"Path:\t\t%@\n", [bundle valueForKey:@"CFBundleExecutablePath"] ];
NSString *ident = [NSString stringWithFormat:@"Identifier:\t\t%@\n", [bundle valueForKey:@"CFBundleIdentifier"] ];
NSString *vers = [NSString stringWithFormat:@"Version:\t\t%@ (%@)\n", [bundle valueForKey:@"CFBundleShortVersionString"], [bundle valueForKey:@"CFBundleVersion"]];
//NSString *ct = [NSString stringWithFormat:@"Code Type:\t\t%@\n", @"idontknow"];
//NSString *pp = [NSString stringWithFormat:@"Parent Process:\t\t%@\n\n", [bundle valueForKey:@"CFBundleIdentifier"] ];
NSString *date = [NSString stringWithFormat:@"Date/Time:\t\t%@\n", [[NSDate date] description]];
NSString *osvers = [NSString stringWithFormat:@"OS Version:\t\t%u.%u.%u (%@)\n\n\n", major, minor, bugFix, bv];
NSLog(@"\n");
NSLog(@"BEGIN NEW SESSION\n");
NSLog(@"************************\n");
NSLog(@"%@", process);
NSLog(@"%@", path);
NSLog(@"%@", ident);
NSLog(@"%@", vers);
NSLog(@"%@", date);
NSLog(@"%@", osvers);
//[self gestaltFun];
}
+ (NSString *)applicationSupportFolder {
NSFileManager *man = [NSFileManager defaultManager];
NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,
NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:
0] : NSTemporaryDirectory();
basePath = [basePath stringByAppendingPathComponent:@"Seas0nPass"];
if (![man fileExistsAtPath:basePath])
[man createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:nil];
return basePath;
}
+ (NSString *)wifiFile
{
NSString *wf = [[tetherKitAppDelegate applicationSupportFolder] stringByAppendingPathComponent:@"com.apple.wifi.plist"];
if ([FM fileExistsAtPath:wf]) { return wf; }
return nil;
}
+ (NSString *)ipswFile
{
return HCIPSW;
}
+ (NSRange)customRangeFromString:(NSString *)inputFile
{
//NSLog(@"inputFile: %@", inputFile);
NSString *baseName = [inputFile stringByDeletingPathExtension];
int length = [baseName length];
int start = length - 10;
//NSLog(@"range: (%i, %i)", start, 10);
return NSMakeRange(start, 10);
}
- (void)cleanupHomeFolder
{
/*
search through the ~ folder for any item that ends with SP_Restore.ipsw and move it to the proper folder.
*/
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSFileManager *man = [NSFileManager defaultManager];
NSArray *homeContents = [man contentsOfDirectoryAtPath:NSHomeDirectory() error:nil];
NSEnumerator *homeEnum = [homeContents objectEnumerator];
//NSDirectoryEnumerator *homeEnum = [man enumeratorAtPath:NSHomeDirectory()];
for (id currentObject in homeEnum)
{
if ([[currentObject pathExtension] isEqualToString:@"ipsw"])
{
NSString *endString = [currentObject substringWithRange:[tetherKitAppDelegate customRangeFromString:currentObject]];
//NSLog(@"endString: %@ fromString: %@", endString, currentObject);
if ([endString isEqualToString:@"SP_Restore"])
{
NSLog(@"is sp restore file, migrate: %@", currentObject);
NSString *fullOldPath = [NSHomeDirectory() stringByAppendingPathComponent:currentObject];
NSString *newPath = [[nitoUtility firmwareFolder] stringByAppendingPathComponent:currentObject];
if([man moveItemAtPath:fullOldPath toPath:newPath error:nil])
{
NSLog(@"moved: %@ successfully!", currentObject);
}
}
}
}
[DEFAULTS setBool:YES forKey:@"newVersionMigrate"];
[pool release];
}
- (BOOL)filesToDownload
{
NSFileManager *man = [NSFileManager defaultManager];
NSString *ipsw = [tetherKitAppDelegate ipswFile];
NSString *sha = [[self currentBundle] SHA];
NSString *downloadLink = [[self currentBundle] downloadURL];
NSLog(@"ipsw: %@", ipsw);
if ([man fileExistsAtPath:ipsw])
{
NSLog(@"validating file: %@", ipsw);
[self showProgressViewWithText:NSLocalizedString(@"Validating IPSW...", @"Validating IPSW...")];
if ([nitoUtility validateFile:ipsw withChecksum:sha] == FALSE)
{
NSLog(@"ipsw SHA Invalid, not removing file (for now, need to make sure its not a beta)");
if (downloadLink != nil)
{
NSLog(@"there is a download url!, we can safely delete and then re-download");
[ man removeItemAtPath:ipsw error:nil];
}
}
}
if (![man fileExistsAtPath:ipsw])
{
[downloadFiles addObject:downloadLink];
}
if ([downloadFiles count] > 0)
{
return TRUE;
} else {
return FALSE;
}
return FALSE;
}
- (void)showProgress
{
//LOG_SELF;
[buttonOne setEnabled:FALSE];
[bootButton setEnabled:FALSE];
self.processing = TRUE;
[downloadBar startAnimation:self];
[downloadBar setHidden:FALSE];
[downloadBar setNeedsDisplay:TRUE];
[downloadBar display];
[self setDownloadProgress:0];
[cancelButton setEnabled:FALSE];
}
- (void)hideProgress
{
[buttonOne setEnabled:TRUE];
[bootButton setEnabled:TRUE];
self.processing = FALSE;
[downloadBar stopAnimation:self];
[downloadBar setHidden:YES];
[downloadBar setNeedsDisplay:YES];
[cancelButton setEnabled:TRUE];
}
- (IBAction)versionChanged:(id)sender
{
//NSLog(@"version changed");
self.currentBundle = [FWBundle bundleWithName:LAST_BUNDLE];
//NSLog(@"self.currentBundle: %@", self.currentBundle);
if ([[self currentBundle] untethered])
{
[bootButton setImage:[self imageForMode:kSPATVUntetheredImage]];
[tetherLabel setTextColor:[NSColor lightGrayColor]];
} else {
[bootButton setImage:[self imageForMode:kSPATVTetheredImage]];
[tetherLabel setTextColor:[NSColor blackColor]];
}
}
//NSFileSize
- (BOOL)sufficientSpaceOnDevice:(NSString *)theDevice
{
NSFileManager *man = [NSFileManager defaultManager];
float available = [[[man attributesOfFileSystemForPath:theDevice error:nil] objectForKey:NSFileSystemFreeSize] floatValue];
float totalSize = 3000.0f;
float avail2 = available / 1024 / 1024;
if (avail2 < totalSize)
{
NSAlert *space = [NSAlert alertWithMessageText:NSLocalizedString(@"Free Space needed", nil)
defaultButton:NSLocalizedString(@"OK", nil)
alternateButton:@""
otherButton:@""
informativeTextWithFormat:NSLocalizedString(@"Not enough free space.\n\n Space needed: %.2f MB\n Space Available: %.2f MB", nil), totalSize, avail2 ];
[space runModal];
return NO;
}
return YES;
}
- (IBAction)cancel:(id)sender
{
if (downloadFile != nil)
{
if ([downloadFile isKindOfClass:[ripURL class]])
{
NSLog(@"downloadFile: %@", downloadFile);
if ([downloadFile respondsToSelector:@selector(cancel)])
{
//NSLog(@"cancel?");
[downloadFile cancel];
//self.processing = FALSE;
[self hideProgress];
}
}
}
if (self.poisoning == TRUE)
{
pois0n_exit();
self.poisoning = FALSE;
self.processing = FALSE;
}
if (self.processing == FALSE)
{
[window setContentView:self.firstView];
[self versionChanged:nil];
[window display];
}
}
void print_progress_bar(double progress) {
int i = 0;
if(progress < 0) {
return;
}
if(progress > 100) {
progress = 100;
}
printf("\r[");
for(i = 0; i < 50; i++) {
if(i < progress / 2) {
printf("=");
} else {
printf(" ");
}
}
printf("] %3.1f%%", progress);
fflush(stdout);
if(progress == 100) {
printf("\n");
}
}
int progress_cb(irecv_client_t client, const irecv_event_t* event) {
//NSLog(@"progress");
if (event->type == IRECV_PROGRESS) {
print_progress_bar(event->progress);
}
return 0;
}
- (int)inject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self killiTunes];
self.poisoning = TRUE;
[self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
int result = 0;
//irecv_error_t ir_error = IRECV_E_SUCCESS;
pois0n_init();
pois0n_set_callback(&print_progress, self);
[self setDownloadText:NSLocalizedString(@"Waiting for device to enter DFU mode...", @"Waiting for device to enter DFU mode...")];
[self setInstructionText:NSLocalizedString(@"Connect USB then press and hold MENU and PLAY/PAUSE for 7 seconds.", @"Connect USB then press and hold MENU and PLAY/PAUSE for 7 seconds.")];
[instructionImage setImage:[self imageForMode:kSPATVRestoreImage]];
while(pois0n_is_ready()) {
sleep(1);
}
irecv_event_subscribe(client, IRECV_RECEIVED, &print_progress, NULL);
[self setDownloadText:NSLocalizedString(@"Found device in DFU mode", @"Found device in DFU mode")];
[self setInstructionText:@""];
result = pois0n_is_compatible();
if (result < 0) {
[self setDownloadText:NSLocalizedString(@"Your device is not compatible with this exploit!", @"Your device is not compatible with this exploit!")];
return result;
}
[self setDownloadText:NSLocalizedString(@"Injecting Pois0n", @"Injecting Pois0n")];
result = pois0n_inject();
if (result < 0) {
[self setDownloadText:NSLocalizedString(@"Exploit injection failed!", @"Exploit injection failed!")];
[self hideProgress];
pois0n_exit();
self.poisoning = FALSE;
[pool release];
return result;
}
[self setDownloadText:@"pois0n successfully administered"];
NSString *command = [commandTextField stringValue];
irecv_send_command(client, [command UTF8String]);
[self hideProgress];
[cancelButton setTitle:@"Done"];
[instructionImage setImage:[self imageForMode:kSPSuccessImage]];
pois0n_exit();
self.poisoning = FALSE;
[pool release];
return 0;
}
- (IBAction)showHelpLog:(id)sender;
{
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSString *logLocation = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Logs/SP_Debug.log"];
[workspace selectFile:logLocation inFileViewerRootedAtPath:[logLocation stringByDeletingLastPathComponent]];
}
#pragma mark •• a note about libsyringe
/*
in the version of syringe used there was changes to irecv_open_*_old, i assume i just changed _open_ to the old code, and then all the
other functions just changed to call the new version. i reference the old a few times in here. needed to update limera1n for 6.x, lost
the source code to the version of syringe i changed that actually works in here. dont remember if i changed anything else to make it work
initially, hope i didnt. if i compile from scratch of other copies iTunes always gets 2001 error upon trying to restore.
ended up just replacing the limera1n.o file in the static library, thankfully that works, hacky, but it works.
*/
- (int)enterDFUNEW
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//NSLog(@"iSDFUNEW");
[self killiTunes];
self.poisoning = TRUE;
[self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
//[cancelButton setEnabled:TRUE];
int result = 0;
irecv_error_t ir_error = IRECV_E_SUCCESS;
//int index;
const char *ibssFile = [self iBSS];
const char *ibecFile = [self iBEC];
pois0n_init();
pois0n_set_callback(&print_progress, self);
//printf("Waiting for device to enter DFU mode\n");
[self setDownloadText:NSLocalizedString(@"Waiting for device to enter DFU mode...", @"Waiting for device to enter DFU mode...")];
[self setInstructionText:NSLocalizedString(@"Connect USB then press and hold MENU and PLAY/PAUSE for 7 seconds.", @"Connect USB then press and hold MENU and PLAY/PAUSE for 7 seconds.")];
//NSImage *theImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tether" ofType:@"png"]];
//NSImage *theImage = [NSImage imageNamed:@"tether"];
[instructionImage setImage:[self imageForMode:kSPATVRestoreImage]];
//[theImage release];
while(pois0n_is_ready()) {
if (self.deviceClass == nil)
{
[self _fetchDeviceInfo];
sleep(5);
}
if ([self isAppleTV3])
{
[self hideProgress];
//pois0n_exit();
self.poisoning = FALSE;
[pool release];
return -1;
}
sleep(1);
}
[self setDownloadText:NSLocalizedString(@"Found device in DFU mode", @"Found device in DFU mode")];
[self setInstructionText:@""];
result = pois0n_is_compatible();
if (result < 0) {
[self setDownloadText:NSLocalizedString(@"Your device is not compatible with this exploit!", @"Your device is not compatible with this exploit!")];
return result;
}
result = pois0n_injectonly();
if (result < 0) {
[self setDownloadText:NSLocalizedString(@"Exploit injection failed!", @"Exploit injection failed!")];
return result;
}
if (ibssFile != NULL) {
[self setDownloadText:[NSString stringWithFormat:@"Uploading %@ to device...", iBSSDFU]];
ir_error = irecv_send_file(client, ibssFile, 1);
if(ir_error != IRECV_E_SUCCESS) {
[self setDownloadText:NSLocalizedString(@"Unable to upload iBSS!", @"Unable to upload iBSS!")];
debug("%s\n", irecv_strerror(ir_error));
return -1;
}
} else {
return 0;
}
client = irecv_reconnect(client, 10);
if (ibecFile != NULL) {
[self setDownloadText:[NSString stringWithFormat:@"Uploading %@ to device...", iBECDFU]];
ir_error = irecv_send_file(client, ibecFile, 1);
if(ir_error != IRECV_E_SUCCESS) {
[self setDownloadText:NSLocalizedString(@"Unable to upload iBEC!", @"Unable to upload iBEC!")];
debug("%s\n", irecv_strerror(ir_error));
return -1;
}
} else {
return 0;
}
client = irecv_reconnect(client, 10);
[self setDownloadText:NSLocalizedString(@"DFU mode entered successfully!", @"DFU mode entered successfully!")];
[self hideProgress];
pois0n_exit();
self.poisoning = FALSE;
[pool release];
return 0;
}
//this code is almost identical to the tetheredboot code
- (int)enterDFU
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self killiTunes];
self.poisoning = TRUE;
[self showProgress];
//[cancelButton setEnabled:TRUE];
int result = 0;
irecv_error_t ir_error = IRECV_E_SUCCESS;
//int index;
const char *ibssFile = [self iBSS];
pois0n_init();
pois0n_set_callback(&print_progress, self);
//printf("Waiting for device to enter DFU mode\n");
[self setDownloadText:NSLocalizedString(@"Waiting for device to enter DFU mode...", @"Waiting for device to enter DFU mode...")];
[self setInstructionText:NSLocalizedString(@"Connect USB then press and hold MENU and PLAY/PAUSE for 7 seconds.", @"Connect USB then press and hold MENU and PLAY/PAUSE for 7 seconds.")];
[instructionImage setImage:[self imageForMode:kSPATVRestoreImage]];
while(pois0n_is_ready()) {
if (self.deviceClass == nil)
{
[self _fetchDeviceInfo];
sleep(5);
}
if ([self isAppleTV3])
{
[self hideProgress];
pois0n_exit();
self.poisoning = FALSE;
[pool release];
return -1;
}
sleep(1);
}
[self setDownloadText:NSLocalizedString(@"Found device in DFU mode", @"Found device in DFU mode")];
[self setInstructionText:@""];
result = pois0n_is_compatible();
if (result < 0) {
[self setDownloadText:NSLocalizedString(@"Your device is not compatible with this exploit!", @"Your device is not compatible with this exploit!")];
return result;
}
result = pois0n_injectonly();
if (result < 0) {
[self setDownloadText:NSLocalizedString(@"Exploit injection failed!", @"Exploit injection failed!")];
return result;
}
if (ibssFile != NULL) {
[self setDownloadText:[NSString stringWithFormat:NSLocalizedString(@"Uploading %@ to device...", @"Uploading %@ to device..."), iBSSDFU]];
ir_error = irecv_send_file(client, ibssFile, 1);
if(ir_error != IRECV_E_SUCCESS) {
[self setDownloadText:NSLocalizedString(@"Unable to upload iBSS!", @"Unable to upload iBSS!")];
debug("%s\n", irecv_strerror(ir_error));
return -1;
}
} else {
return 0;
}
client = irecv_reconnect(client, 10);
[self setDownloadText:NSLocalizedString(@"DFU mode entered successfully!", @"DFU mode entered successfully!")];
[self hideProgress];
pois0n_exit();
self.poisoning = FALSE;
[pool release];
return 0;
}
int received_cb(irecv_client_t client, const irecv_event_t* event) {
//NSLog(@"received_cb");
if (event->type == IRECV_RECEIVED) {
int i = 0;
int size = event->size;
char* data = event->data;
for (i = 0; i < size; i++) {
printf("%c", data[i]);
}
}
return 0;
}
void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) {
//NSLog(@"parse command");
char* cmd = strdup(command);
char* action = strtok(cmd, " ");
debug("Executing %s\n", action);
if (!strcmp(cmd, "/exit")) {
} else
if (!strcmp(cmd, "/help")) {
} else
if (!strcmp(cmd, "/upload")) {
char* filename = strtok(NULL, " ");
debug("Uploading files %s\n", filename);
if (filename != NULL) {
irecv_send_file(client, filename, 0);
}
} else
if (!strcmp(cmd, "/exploit")) {
char* filename = strtok(NULL, " ");
debug("Sending exploit %s\n", filename);
if (filename != NULL) {
irecv_send_file(client, filename, 0);
}
irecv_send_exploit(client);
} else
if (!strcmp(cmd, "/execute")) {
char* filename = strtok(NULL, " ");
debug("Executing script %s\n", filename);
if (filename != NULL) {
irecv_execute_script(client, filename);
}
}
free(action);
}
- (IBAction)poison:(id)sender
{
NSString *lastUsedbundle = LAST_BUNDLE;
self.currentBundle = [FWBundle bundleWithName:lastUsedbundle];
[window setContentView:self.secondView];
[window display];
[NSThread detachNewThreadSelector:@selector(inject) toTarget:self withObject:nil];
}
- (int)tetheredBootNew
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self killiTunes];
self.poisoning = TRUE;
[self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
int result = 0;
irecv_error_t ir_error = IRECV_E_SUCCESS;
//int index;
const char
*ibssFile = [self iBSS],
*kernelcacheFile = [self kernelcache],
*ibecFile = [self iBEC];
pois0n_init();
pois0n_set_callback(&print_progress, self);
//printf("Waiting for device to enter DFU mode\n");
[self setDownloadText:NSLocalizedString(@"Waiting for device to enter DFU mode...", @"Waiting for device to enter DFU mode...")];
[self setInstructionText:NSLocalizedString(@"Connect USB, POWER then press and hold MENU and PLAY/PAUSE for 7 seconds", @"Connect USB, POWER then press and hold MENU and PLAY/PAUSE for 7 seconds")];
[instructionImage setImage:[self imageForMode:kSPATVTetheredRemoteImage]];
while(pois0n_is_ready()) {
sleep(1);
}
//irecv_set_debug_level(3);
[self setDownloadText:NSLocalizedString(@"Found device in DFU mode", @"Found device in DFU mode")];
[self setInstructionText:@""];
result = pois0n_is_compatible();
if (result < 0) {
[self setDownloadText:NSLocalizedString(@"Your device is not compatible with this exploit!", @"Your device is not compatible with this exploit!")];
[self hideProgress];
pois0n_exit();
self.poisoning = FALSE;
[pool release];
return result;
}
//irecv_send_command(client, "go kernel bootargs -v");
result = pois0n_injectonly();
if (result < 0) {
[self setDownloadText:NSLocalizedString(@"Exploit injection failed!",@"Exploit injection failed!" )];
[self hideProgress];
pois0n_exit();
self.poisoning = FALSE;
[pool release];
return result;
}
if (ibssFile != NULL) {
[self setDownloadText:[NSString stringWithFormat:NSLocalizedString(@"Uploading %@ to device...",@"Uploading %@ to device..."), iBSSDFU]];
ir_error = irecv_send_file(client, ibssFile, 1);
if(ir_error != IRECV_E_SUCCESS) {
[self setDownloadText:NSLocalizedString(@"Unable to upload iBSS!", @"Unable to upload iBSS!")];
debug("%s\n", irecv_strerror(ir_error));
[self hideProgress];
pois0n_exit();
self.poisoning = FALSE;
[pool release];
return -1;
}
} else {
return 0;
}
NSLog(@"iBSS upload successful! Reconnecting in 10 seconds...");
[self setDownloadText:NSLocalizedString(@"iBSS upload successful! Reconnecting in 10 seconds...", @"iBSS upload successful! Reconnecting in 10 seconds...")];
sleep(10);
client = irecv_reconnect(client, 10);
if (ibecFile != NULL) {
[self setDownloadText:[NSString stringWithFormat:NSLocalizedString(@"Uploading %@ to device...",@"Uploading %@ to device..."), iBECDFU]];
ir_error = irecv_send_file(client, ibecFile, 1);
if(ir_error != IRECV_E_SUCCESS) {