Skip to content
Browse files

hopefully fixed two major bugs

  • Loading branch information...
1 parent 3715269 commit 4f2b954129278c2fc6479a6008fff478dc1bd5db @lechium lechium committed
Showing with 480 additions and 126 deletions.
  1. +5 −4 Credits.rtf
  2. +2 −2 TSS/TSSManager.h
  3. +62 −3 nitoUtility.m
  4. +1 −1 tetherKit-Info.plist
  5. +410 −116 tetherKitAppDelegate.m
View
9 Credits.rtf
@@ -1,5 +1,5 @@
-{\rtf1\ansi\ansicpg1252\cocoartf1138\cocoasubrtf470
-{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
+{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf340
+\cocoascreenfonts1{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720
@@ -19,12 +19,13 @@
mstf_guy (sandbox patch for 5.0/4.4)\
pod2g (4.4 corona untether)\
pod2g+westbaer+planetbeing+cdev (5.1+ untether)\
+ Jay Freeman (some of the core TSS code from cydia)\
\
\b Bundled Software:\
\b0 Dustin Howett (beigelist)\
- Jay Freeman (mobile substrate)\
+ Jay Freeman (mobile substrate, cydia payload)\
Brandon Holland (exposed)\
\
@@ -33,4 +34,4 @@
Kevin Bradley (layout)\
Louis Cohen (icon / image design)\
\
-Special Thanks to James Abeler, (making this all possible), Joshua Hill, Scott Davilla and Thomas Cool for testing and linking/building troubleshooting, iPhone + Chronic Dev teams for all the work that paved the way for applications like this!! Thanks to DjayB6 for the bundle(s) and to lilstevie for his test notes!!! Stefan Esser for his amazingly quick work on the latest untether!! iH8Sn0w for most recent bundle + tethered booting info. Thanks to comex for his awesome kernel patching tools and just for being awesome in general :) iH8sn0w for some patching tips. pod2g, deserves another mention, epic as always. Another thanks to iH8Sn0w for the help on the SHSH stitching/signing information. Thanks to saurik (cant believe he didnt have a thanks in here already) for the code in Cydia that helped shed some light on fetching ecid on device (and for everything else he has done for this community in general) Thanks to pod2g, planetbeing, westbaer (everyone in cdev that worked on it) for the latest absinthe 2.0 jailbreak and untether. thanks again to iH8sn0w for the new iBEC/iBSS patches to accomodate 5.1 untether. another thanks to planetbeing for generating the absinthe 2.0 payload for 5.0.2 and iH8Sn0w for the iBEC/iBSS patches again.}
+For help and troubleshooting tips please visit: http://seas0npass.com/}
View
4 TSS/TSSManager.h
@@ -9,8 +9,8 @@
#import <Foundation/Foundation.h>
#import "FWBundle.h"
-#define BLOB_PLIST_BASE_URL @"https://dl.dropbox.com/u/16129573/FW"
- //#define BLOB_PLIST_BASE_URL @"http://files.firecore.com/FW"
+ //#define BLOB_PLIST_BASE_URL @"https://dl.dropbox.com/u/16129573/FW"
+#define BLOB_PLIST_BASE_URL @"http://files.firecore.com/FW"
#define BLOB_PLIST_URL @"http://files.firecore.com/FW/k66ap.plist"
enum {
View
65 nitoUtility.m
@@ -95,7 +95,7 @@ + (NSString *)mountImageWithoutOwners:(NSString *)irString
[irArgs release];
- [irTask setStandardError:hdip];
+ //[irTask setStandardError:hdip];
[irTask setStandardOutput:hdip];
//NSLog(@"hdiutil %@", [[irTask arguments] componentsJoinedByString:@" "]);
[irTask launch];
@@ -183,7 +183,7 @@ + (NSString *)mountImage:(NSString *)irString
[irArgs release];
- [irTask setStandardError:hdip];
+ //[irTask setStandardError:hdip];
[irTask setStandardOutput:hdip];
//NSLog(@"hdiutil %@", [[irTask arguments] componentsJoinedByString:@" "]);
[irTask launch];
@@ -276,10 +276,69 @@ + (int)scanForRestore:(NSString *)drivepath
return termStatus;
}
-+ (BOOL)validateFile:(NSString *)inputFile withChecksum:(NSString *)checksum
++ (void)altValidateFile:(NSString *)inputFile withChecksum:(NSString *)checksum
{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSTask *sslTask = [[NSTask alloc] init];
+ NSPipe *sspipe = [[NSPipe alloc] init];
+ NSFileHandle *ssh = [sspipe fileHandleForReading];
+
+ [sslTask setLaunchPath:@"/usr/bin/openssl"];
+
+ [sslTask setArguments:[NSArray arrayWithObjects:@"sha1", inputFile, nil]];
+ [sslTask setStandardOutput:sspipe];
+ [sslTask setStandardError:sspipe];
+ [sslTask launch];
+
+ NSData *outData = [ssh readDataToEndOfFile];
+
+ [sslTask waitUntilExit];
+
+ NSString *outputString = [[[NSString alloc] initWithData:outData
+ encoding:NSASCIIStringEncoding]
+ stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+
+ //example outputString: SHA1(~/Documents/Tether/AppleTV2,1_4.3_8F455_Restore.ipsw)= b6a2b0baae79daf95f75044c12946839c662d01d
+
+ //b6a2b0baae79daf95f75044c12946839c662d01d cleaned up
+ NSString *outputSHA = [[[outputString componentsSeparatedByString:@"="] lastObject] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+
+ NSLog(@"sha1: %@ against: %@", outputSHA, checksum);
+ if ([outputSHA isEqualToString:checksum])
+ {
+ [sslTask release];
+ sslTask = nil;
+ [sspipe release];
+ sspipe = nil;
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:inputFile, @"file", @"1", @"status", nil];
+ //return YES;
+ [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"checksumFinished" object:nil userInfo:userInfo deliverImmediately:YES];
+ [pool release];
+ return;
+ }
+ [sslTask release];
+ sslTask = nil;
+ [sspipe release];
+ sspipe = nil;
+ //return NO;
+
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:inputFile, @"file", @"0", @"status", nil];
+ //return YES;
+ [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"checksumFinished" object:nil userInfo:userInfo deliverImmediately:YES];
+
+ [pool release];
+
+}
+
+
+
+
++ (BOOL)validateFile:(NSString *)inputFile withChecksum:(NSString *)checksum
+{
+ //LOG_SELF;
+
NSTask *sslTask = [[NSTask alloc] init];
NSPipe *sspipe = [[NSPipe alloc] init];
NSFileHandle *ssh = [sspipe fileHandleForReading];
View
2 tetherKit-Info.plist
@@ -25,7 +25,7 @@
<key>CFBundleURLTypes</key>
<array/>
<key>CFBundleVersion</key>
- <string>610</string>
+ <string>620</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
View
526 tetherKitAppDelegate.m
@@ -431,7 +431,7 @@ - (void)cleanupHomeFolder
}
-- (BOOL)filesToDownload
+- (BOOL)filesToDownload //deprecated pre threaded throwback
{
NSFileManager *man = [NSFileManager defaultManager];
NSString *ipsw = [tetherKitAppDelegate ipswFile];
@@ -1800,6 +1800,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(pwnFailed:) name:@"pwnFailed" object:nil];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(blobsFinished:) name:@"blobsFinished" object:nil];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(statusChanged:) name:@"statusChanged" object:nil];
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(checksumFinished:) name:@"checksumFinished" object:nil];
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(shouldDownloadFinished:) name:@"shouldDownloadFinish" object:nil];
//[self startupAlert];
//check the ownership to make sure we can continue on our merry way
@@ -1860,6 +1862,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
+
}
- (void)failedWithReason:(NSString *)theReason
@@ -1895,6 +1898,15 @@ - (void)showProgressViewWithText:(NSString *)theString
[window display];
}
+- (void)validateFileThreaded:(NSString *)ipsw
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ FWBundle *ourBundle = [FWBundle bundleForFile:ipsw];
+ NSString *sha = [ourBundle SHA];
+ [nitoUtility altValidateFile:ipsw withChecksum:sha];
+ [pool release];
+}
+
#pragma mark we start here
- (IBAction)processOne:(id)sender //download and modify ipsw
@@ -1914,27 +1926,6 @@ - (IBAction)processOne:(id)sender //download and modify ipsw
self.currentBundle = [FWBundle bundleWithName:CURRENT_BUNDLE];
- //NSString *fullDeviceType = [self.currentBundle fullDeviceType];
-//
-// NSLog(@"fullDeviceType: %@", fullDeviceType);
-//
-// if ([fullDeviceType isEqualToString:@"AppleTV3,1"]) //not going to happen, there are no built in bundles with appletv3,1
-// {
-// NSLog(@"BAIL! AppleTV3,1 not supported!");
-//
-// return;
-// }
-
-
- //if (![self.deviceClass isEqualToString:APPLETV_21_DEVICE_CLASS])
-// {
-//
-// NSLog(@"only AppleTV2,1 / k66ap is supported in default mode!");
-// [self showIncompatDeviceAlert];
-// return;
-// }
-
-
if ([self optionKeyIsDown]) //choose custom firmware version
@@ -1958,91 +1949,18 @@ - (IBAction)processOne:(id)sender //download and modify ipsw
return;
}
self.currentBundle = ourBundle;
-
- //okay we need a way to validate this shit without holding up the woodworks
-
- NSString *sha = [[self currentBundle] SHA];
- NSString *downloadLink = [[self currentBundle] downloadURL];
-
- sleep(2);
-
- [self showProgressViewWithText:NSLocalizedString(@"Validating IPSW...", @"Validating IPSW...")];
- BOOL isValid = [nitoUtility validateFile:ipsw withChecksum:sha];
-
- if (!isValid)
- {
- NSLog(@"invalid file: %@, redownloading...", ipsw);
- if([downloadLink length] > 2)
- {
- [downloadFiles addObject:downloadLink];
- [window setContentView:self.secondView];
- [window display];
-
- self.processing = TRUE;
- [buttonOne setEnabled:FALSE];
- [bootButton setEnabled:FALSE];
- [instructionImage setImage:[self imageForMode:kSPIPSWImage]];
- [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
- [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
- [self downloadTheFiles];
- }
- return;
-
- }
- [self showProgressViewWithText:NSLocalizedString(@"Checking firmware compatibility...",@"Checking firmware compatibility..." )];
- theRestoreMode = [self restoreMode];
- _restoreMode = theRestoreMode;
-
- NSLog(@"restoreMode: %i", theRestoreMode);
- id object = nil;
- switch (theRestoreMode) {
-
- case -1:
- case kRestoreUnavailableMode: //shouldn't get this anymore. deprecated
- NSLog(@"bailing!!!!");
- object = [NSAlert alertWithMessageText:NSLocalizedString(@"Unspecified Error", @"Unspecified Error") defaultButton:NSLocalizedString(@"OK", @"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedString(@"The firmware %@ is either not being signed by Apple anymore, not backed up to cydia, or the device cannot be detected: kRestoreUnavailableMode.", @"The firmware %@ is either not being signed by Apple anymore, not backed up to cydia, or the device cannot be detected: kRestoreUnavailableMode."), [ipsw lastPathComponent]];
- [object runModal];
- return;
-
- case kRestoreNoDevice: //already showed alert, just bail
- [self showInitialView];
- [self hideProgress];
- return;
-
-
- case kRestoreFirmwareIneligible:
- [self showInitialView];
- [self hideProgress];
- [self showDeviceIneligibleAlert];
- return;
-
-
- case kRestoreUnsupportedDevice:
- [self showInitialView];
- [self hideProgress];
- [self showIncompatDeviceAlert];
-
- return;
-
- default:
- break;
- }
-
+ /*
+
+ no more lock ups when option clicking to choose a bundle, also happens to validate much quicker now too, only 3 more places to thread!
+
+
+ */
- NSLog(@"Seas0nPass: Software payload: %@ (option key)", [self.currentBundle bundleName]);
-
- [window setContentView:self.secondView];
- [window display];
+ [self showProgressViewWithText:NSLocalizedString(@"Validating IPSW...", @"Validating IPSW...")];
- self.processing = TRUE;
- [buttonOne setEnabled:FALSE];
- [bootButton setEnabled:FALSE];
- [instructionImage setImage:[self imageForMode:kSPIPSWImage]];
+ [NSThread detachNewThreadSelector:@selector(validateFileThreaded:) toTarget:self withObject:ipsw];
- NSDictionary *customFwDict = [NSDictionary dictionaryWithObjectsAndKeys:ipsw, @"file", [NSString stringWithFormat:@"%i", theRestoreMode], @"restoreMode", nil];
- [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
- [NSThread detachNewThreadSelector:@selector(customFW:) toTarget:self withObject:customFwDict];
return;
} //end option key down if / custom payload selection
@@ -2058,7 +1976,15 @@ - (IBAction)processOne:(id)sender //download and modify ipsw
[buttonOne setEnabled:FALSE];
[bootButton setEnabled:FALSE];
[instructionImage setImage:[self imageForMode:kSPIPSWImage]];
+
+ /*
+
+ one more instance of validating the file with 'proper' threading
+
+ */
+ [NSThread detachNewThreadSelector:@selector(checkFileDownload:) toTarget:self withObject:self.currentBundle];
+ /*
BOOL download = [self filesToDownload];
theRestoreMode = 0;
@@ -2079,9 +2005,96 @@ - (IBAction)processOne:(id)sender //download and modify ipsw
NSDictionary *customFwDict = [NSDictionary dictionaryWithObjectsAndKeys:HCIPSW, @"file", [NSString stringWithFormat:@"%i", theRestoreMode], @"restoreMode", nil];
[NSThread detachNewThreadSelector:@selector(customFW:) toTarget:self withObject:customFwDict];
}
+
+ */
} //end process one
+- (void)checkFileDownload:(FWBundle *)theBundle
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSFileManager *man = [NSFileManager defaultManager];
+ NSString *ipsw = [tetherKitAppDelegate ipswFile];
+ NSString *sha = [theBundle SHA];
+ NSString *downloadLink = [theBundle 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];
+ }
+
+ } else {
+
+ NSLog(@"Seas0nPass: Software payload: %@", [theBundle bundleName]);
+ [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+
+ NSDictionary *customFwDict = [NSDictionary dictionaryWithObjectsAndKeys:HCIPSW, @"file", [NSString stringWithFormat:@"%i", 0], @"restoreMode", nil];
+ [self customFW:customFwDict];
+ [pool release];
+ return;
+ }
+
+ }
+
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:ipsw forKey:@"file"];
+ [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"shouldDownloadFinish" object:nil userInfo:userInfo deliverImmediately:YES];
+
+
+
+ [pool release];
+}
+
+/*
+
+ //thoughts of disabling keyboard / mouse when running applescript
+
+bool dontForwardTap = false;
+
+CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {
+
+
+ //NSLog(@"Event Tap: %d", (int) CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode));
+
+ if (dontForwardTap)
+ return nil;
+ else
+ return event;
+}
+
+void tap_keyboard(void) {
+ CFRunLoopSourceRef runLoopSource;
+
+ CGEventMask mask = kCGEventMaskForAllEvents;
+ //CGEventMask mask = CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventKeyDown);
+
+ CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, mask, myCGEventCallback, NULL);
+
+ if (!eventTap) {
+ NSLog(@"Couldn't create event tap!");
+ exit(1);
+ }
+
+ runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
+
+ CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
+
+ CGEventTapEnable(eventTap, true);
+
+ CFRelease(eventTap);
+ CFRelease(runLoopSource);
+
+}
+
+ */
+
- (void)customFW:(NSDictionary *)theDict //called inside process one
{
@@ -2786,11 +2799,25 @@ - (BOOL)isFullScreen:(NSSize)theSize
}
+/*
+
+ this method first gets iTunes up and running, then uses AXUIElement interaction from ApplicationServices/HIServices to anaylze itunes for full screen / sidebar visibility
+
+ fortunately the splitter is always item 13, we check the count of the children of the AXSplitGroup, if its 1, then we know we dont have a sidebar, if its greater than 1 we do!
+
+
+
+
+ */
+
+
- (void)analyzeiTunes
{
+
NSDictionary *theError = nil;
NSMutableString *asString = [[NSMutableString alloc] init];
[asString appendString:@"activate application \"iTunes\"\n"];
+ [asString appendString:@"activate application \"iTunes\"\n"];
NSAppleScript *as = [[NSAppleScript alloc] initWithSource:asString];
[as executeAndReturnError:&theError];
[asString release];
@@ -2829,11 +2856,20 @@ - (void)analyzeiTunes
AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow, (CFStringRef)kAXChildrenAttribute, (CFTypeRef *)&_children);
- if ([_children count] < 13)
+ while ([_children count] < 14)
{
+ NSLog(@"iTunes window children count was less than 14, looping until 14 is reached."); //item count is 14 WITH sidebar and 17 without
AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow, (CFStringRef)kAXChildrenAttribute, (CFTypeRef *)&_children);
}
-
+
+ /*
+
+ another thought here because while investigating this issue... again.. the child item count WITH sidebar APPEARS to always be 14. so if the count is greater than 14
+ we should be able to assume that the sidebar is showing, without an appletv connected the code below creates a false positive. hence the concern.
+
+
+ */
+
AXUIElementRef splitter = [_children objectAtIndex:13]; //if our children count is more than 1 (probably 6) we are showing sidebar
AXUIElementCopyAttributeValue((AXUIElementRef)splitter, (CFStringRef)kAXChildrenAttribute, (CFTypeRef *)&_splitterChildren);
@@ -2899,6 +2935,8 @@ - (void)analyzeiTunes
- (BOOL)loadiTunes11WithIPSW:(NSString *)ipsw
{
[self analyzeiTunes];
+ //[self analyzeiTunes];
+
NSDictionary *theError = nil;
@@ -2958,7 +2996,7 @@ - (BOOL)loadiTunes11WithIPSW:(NSString *)ipsw
[asString appendString:@"delay 3\n"];
[asString appendString:@"key code 36\n"];
- [asString appendString:@"delay 3\n"];
+ [asString appendString:@"delay 5\n"];
[asString appendString:@"key code 36\n"];
[asString appendString:@"delay 3\n"];
//[asString appendString:@"click button 4 of window 1\n"];
@@ -3175,7 +3213,7 @@ + (NSString *)formattedStringFromBundle:(NSString *)theBundle
+ (NSArray *)filteredBundleNames
{
- NSArray *betaBundles = [NSArray arrayWithObjects:@"AppleTV2,1_5.0_9B5127c.bundle", @"AppleTV2,1_5.0_9B5141a.bundle", nil];
+ NSArray *betaBundles = [NSArray arrayWithObjects:@"AppleTV2,1_5.0_9B5127c.bundle", @"AppleTV2,1_5.0_9B5141a.bundle", @"AppleTV2,1_5.2_10B5105c.bundle", @"AppleTV2,1_5.2_10B5126b.bundle", nil];
NSMutableArray *finalArray = [[NSMutableArray alloc] init];
for (id object in BUNDLES)
@@ -3309,9 +3347,33 @@ - (void)showDeviceIneligibleAlert
}
+- (NSString *)threadedBundleFirmware:(FWBundle *)theBundle
+{
+ NSString *theFirmwareDownload = [DL stringByAppendingPathComponent:[theBundle filename]];
+ NSLog(@"theFirmwareDownload: %@", theFirmwareDownload);
+ NSString *sha = [theBundle SHA];
+ if ([FM fileExistsAtPath:theFirmwareDownload])
+ {
+ [self showProgressViewWithText:NSLocalizedString(@"Validating IPSW...", @"Validating IPSW...")];
+ if([nitoUtility validateFile:theFirmwareDownload withChecksum:sha] == FALSE)
+ {
+ NSLog(@"failed to validate file, delete file and continue to new download");
+ [FM removeItemAtPath:theFirmwareDownload error:nil];
+ return nil;
+ } else {
+
+ NSLog(@"firmware exists, no need to download!");
+
+ return theFirmwareDownload;
+
+ }
+ }
+
+ return nil; //default to nil right?
+
+}
-
-- (NSString *)currentBundleFirmware
+- (NSString *)currentBundleFirmware //deprecated
{
NSString *theFirmwareDownload = [DL stringByAppendingPathComponent:[[self currentBundle] filename]];
NSLog(@"theFirmwareDownload: %@", theFirmwareDownload);
@@ -3337,11 +3399,79 @@ - (NSString *)currentBundleFirmware
}
+- (void)shouldDownloadFinished:(NSNotification *)n
+{
+ id userInfo = [n userInfo];
+ NSString *theFile = [userInfo valueForKey:@"file"];
+ FWBundle *ourBundle = [FWBundle bundleForFile:theFile];
+
+ NSString *downloadLink = [ourBundle downloadURL];
+
+ if([downloadLink length] > 2)
+ {
+ [downloadFiles addObject:downloadLink];
+ [window setContentView:self.secondView];
+ [window display];
+
+ self.processing = TRUE;
+ [buttonOne setEnabled:FALSE];
+ [bootButton setEnabled:FALSE];
+ [instructionImage setImage:[self imageForMode:kSPIPSWImage]];
+ [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+ [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+ [self downloadTheFiles];
+ }
+
+}
+
+- (void)shouldDownloadThreaded:(NSString *)theFile
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ FWBundle *ourBundle = [FWBundle bundleForFile:theFile];
+ if (ourBundle == nil)
+ {
+ NSLog(@"nil bundle??: %@", theFile);
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:theFile forKey:@"file"];
+ [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"shouldDownloadFinish" object:nil userInfo:userInfo deliverImmediately:YES];
+ return;
+
+ }
+
+
+ NSString *cbf = [self threadedBundleFirmware:ourBundle];
+ if (cbf != nil)
+ {
+ NSLog(@"we already have the firmware, no need to download!");
+ [FM removeItemAtPath:TMP_ROOT error:nil];
+ [window setContentView:self.secondView];
+ [window display];
+
+ self.processing = TRUE;
+ [buttonOne setEnabled:FALSE];
+ [bootButton setEnabled:FALSE];
+ [instructionImage setImage:[self imageForMode:kSPIPSWImage]];
+
+ NSDictionary *customFwDict = [NSDictionary dictionaryWithObjectsAndKeys:cbf, @"file", [NSString stringWithFormat:@"%i", _restoreMode], @"restoreMode", nil];
+ //[self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+ //[NSThread detachNewThreadSelector:@selector(customFW:) toTarget:self withObject:customFwDict];
+ [self customFW:customFwDict];
+ return;
+ } else {
+
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:theFile forKey:@"file"];
+ [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"shouldDownloadFinish" object:nil userInfo:userInfo deliverImmediately:YES];
+
+
+ }
+
+ [pool release];
+}
+
- (void)downloadBundle:(NSString *)theFile
{
NSString *bundleName = [tetherKitAppDelegate bundleNameFromLabel:theFile];
- // NSLog(@"bundleName: %@", bundleName);
+ //NSLog(@"bundleName: %@", bundleName);
self.currentBundle = [FWBundle bundleForFile:bundleName];
//NSLog(@"currentBundle: %@", self.currentBundle);
@@ -3397,6 +3527,16 @@ - (void)downloadBundle:(NSString *)theFile
break;
}
+ [NSThread detachNewThreadSelector:@selector(shouldDownloadThreaded:) toTarget:self withObject:bundleName];
+
+ /*
+
+ fixed the lockup in two places now when validating files.
+
+ */
+
+
+ /*
NSString *cbf = [self currentBundleFirmware];
//NSLog(@"cbf: %@", cbf);
@@ -3435,6 +3575,7 @@ - (void)downloadBundle:(NSString *)theFile
[self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
[self downloadTheFiles];
}
+ */
}
- (void)downloadTheFiles
@@ -3447,11 +3588,7 @@ - (void)downloadTheFiles
[downloadFile setHandler:self];
[downloadFile setDownloadLocation:ptFile];
[downloadFile downloadFile:currentDownload];
- //[downloadFile autorelease];
- //if ([downloadFiles count] > 1)
- //{
- downloadIndex = 1;
- //}
+ downloadIndex = 1;
}
@@ -3488,9 +3625,69 @@ - (void)downloadFailed:(NSString *)adownloadFile
[self hideProgress];
}
-- (void)downloadFinished:(NSString *)adownloadFile
+ //FIXME: the last place i need to make sure we properly thread when validating the file to prevent UI lockup
+
+- (void)threadedDownloadFinished:(NSString *)adownloadFile
{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *sha = [[self currentBundle] SHA];
+ [self showProgressViewWithText:NSLocalizedString(@"Validating IPSW...", @"Validating IPSW...")];
+ if ([nitoUtility validateFile:adownloadFile withChecksum:sha] == FALSE)
+ {
+ if (_downloadRetries > 0)
+ {
+ NSLog(@"already tried to redownload, still corrupt, bail!");
+ [self setDownloadText:NSLocalizedString(@"Firmware download corrupt upon two tries, failed!",@"Firmware download corrupt upon two tries, failed!") ];
+ [self hideProgress];
+ _downloadRetries = 0;
+ [pool release];
+ return;
+
+ } else { //we downloaded once, and it was corrupt, trying again.
+
+ self.downloadIndex = 0;
+ NSLog(@"download corrupt on first try, trying once more!");
+ [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+ [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:adownloadFile forKey:@"file"];
+ [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"shouldDownloadFinish" object:nil userInfo:userInfo deliverImmediately:YES];
+ //[self downloadTheFiles];
+ _downloadRetries++;
+ return;
+ }
+
+ }
+ _downloadRetries = 0;
+
+ [FM removeItemAtPath:TMP_ROOT error:nil];
+ NSLog(@"download complete: %@", adownloadFile);
+ [downloadBar stopAnimation:self];
+ [downloadBar setHidden:YES];
+ [downloadBar setNeedsDisplay:YES];
+ [downloadFile release];
+ downloadFile = nil;
+ if (downloadIndex == 1)
+ {
+
+
+ [self setDownloadText:NSLocalizedString(@"Downloads complete", @"Downloads complete")];
+ NSLog(@"downloads complete!!");
+ [self setDownloadProgress:0];
+ NSLog(@"_restoreMode: %i", _restoreMode);
+ NSDictionary *customFwDict = [NSDictionary dictionaryWithObjectsAndKeys:adownloadFile, @"file", [NSString stringWithFormat:@"%i", _restoreMode], @"restoreMode", nil];
+ // [NSThread detachNewThreadSelector:@selector(customFW:) toTarget:self withObject:customFwDict];
+ [self customFW:customFwDict];
+
+ }
+
+ [pool release];
+}
+- (void)downloadFinished:(NSString *)adownloadFile
+{
+ [NSThread detachNewThreadSelector:@selector(threadedDownloadFinished:) toTarget:self withObject:adownloadFile];
+ return;
NSString *sha = [[self currentBundle] SHA];
[self showProgressViewWithText:NSLocalizedString(@"Validating IPSW...", @"Validating IPSW...")];
@@ -3646,6 +3843,103 @@ - (void)statusChanged:(NSNotification *)n
}
+- (void)checksumFinished:(NSNotification *)n
+{
+ NSLog(@"checksumFinished: %@", n);
+
+ int status = [[[n userInfo] objectForKey:@"status"] intValue];
+
+ NSString *ipsw = [[n userInfo] objectForKey:@"file"];
+
+ NSLog(@"ipsw: %@ status: %i", ipsw, status);
+
+ FWBundle *ourBundle = [FWBundle bundleForFile:ipsw];
+ NSString *downloadLink = [ourBundle downloadURL];
+
+ if (status == 0)
+ {
+ NSLog(@"checksum failed!, do somethin!");
+ NSLog(@"invalid file: %@, redownloading...", ipsw);
+ if([downloadLink length] > 2)
+ {
+ [downloadFiles addObject:downloadLink];
+ [window setContentView:self.secondView];
+ [window display];
+
+ self.processing = TRUE;
+ [buttonOne setEnabled:FALSE];
+ [bootButton setEnabled:FALSE];
+ [instructionImage setImage:[self imageForMode:kSPIPSWImage]];
+ [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+ [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+ [self downloadTheFiles];
+ }
+ return;
+
+ } else {
+
+ [self showProgressViewWithText:NSLocalizedString(@"Checking firmware compatibility...",@"Checking firmware compatibility..." )];
+ int theRestoreMode = [self restoreMode];
+ _restoreMode = theRestoreMode;
+
+ NSLog(@"restoreMode: %i", theRestoreMode);
+ id object = nil;
+ switch (theRestoreMode) {
+
+ case -1:
+ case kRestoreUnavailableMode: //shouldn't get this anymore. deprecated
+ NSLog(@"bailing!!!!");
+ object = [NSAlert alertWithMessageText:NSLocalizedString(@"Unspecified Error", @"Unspecified Error") defaultButton:NSLocalizedString(@"OK", @"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedString(@"The firmware %@ is either not being signed by Apple anymore, not backed up to cydia, or the device cannot be detected: kRestoreUnavailableMode.", @"The firmware %@ is either not being signed by Apple anymore, not backed up to cydia, or the device cannot be detected: kRestoreUnavailableMode."), [ipsw lastPathComponent]];
+ [object runModal];
+ return;
+
+ case kRestoreNoDevice: //already showed alert, just bail
+ [self showInitialView];
+ [self hideProgress];
+ return;
+
+
+ case kRestoreFirmwareIneligible:
+ [self showInitialView];
+ [self hideProgress];
+ [self showDeviceIneligibleAlert];
+ return;
+
+
+ case kRestoreUnsupportedDevice:
+ [self showInitialView];
+ [self hideProgress];
+ [self showIncompatDeviceAlert];
+
+ return;
+
+ default:
+ break;
+ }
+
+
+
+ NSLog(@"Seas0nPass: Software payload: %@ (option key)", [self.currentBundle bundleName]);
+
+ [window setContentView:self.secondView];
+ [window display];
+
+ self.processing = TRUE;
+ [buttonOne setEnabled:FALSE];
+ [bootButton setEnabled:FALSE];
+ [instructionImage setImage:[self imageForMode:kSPIPSWImage]];
+
+ NSDictionary *customFwDict = [NSDictionary dictionaryWithObjectsAndKeys:ipsw, @"file", [NSString stringWithFormat:@"%i", theRestoreMode], @"restoreMode", nil];
+ [self performSelectorOnMainThread:@selector(showProgress) withObject:nil waitUntilDone:YES];
+ [NSThread detachNewThreadSelector:@selector(customFW:) toTarget:self withObject:customFwDict];
+ return;
+
+ }
+
+ // [self setDownloadText:[userI valueForKey:@"Status"]];
+
+}
+
- (BOOL)pwnHelperCheckOwner
{

0 comments on commit 4f2b954

Please sign in to comment.
Something went wrong with that request. Please try again.