Skip to content

Commit

Permalink
completionHandler improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rA9stuff committed Jun 25, 2023
1 parent 9cf9b1f commit 421cc1d
Showing 1 changed file with 78 additions and 79 deletions.
157 changes: 78 additions & 79 deletions LeetDown_M/LeetDownMain.mm
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@ - (int)exploitDevice {
[self updateStatus:@"Exploit failed, please re-enter DFU mode to try again" color:[NSColor redColor]];
[_uselessIndicator stopAnimation:nil];
_downgradeButtonOut.enabled = true;
_versionLabel.alphaValue = 0;
_versionLabel.alphaValue = 0.0;
_versionLabel.enabled = false;
_dfuhelpoutlet.alphaValue = 1;
_dfuhelpoutlet.alphaValue = 1.0;
_dfuhelpoutlet.enabled = true;
});
return -1;
Expand Down Expand Up @@ -940,6 +940,29 @@ - (IBAction)selectIPSW:(id)sender {
}];
}

- (void) backupBlob {

NSString *bloblocation = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/LDResources/SHSH/blob.shsh"];
NSSavePanel *panel = [NSSavePanel savePanel];

[panel setMessage:@"Please select a location to save SHSH blob."];
[panel setAllowsOtherFileTypes:YES];
[panel setExtensionHidden:NO];
[panel setCanCreateDirectories:YES];
[panel setTitle:@"Save your blob"];
[panel setNameFieldStringValue:@"(give a name to your blob)"];
[panel beginWithCompletionHandler:^(NSInteger result) {

if (result == NSModalResponseOK) {
NSString *path = [[panel URL] path];
NSURL *saveLocation = [NSURL fileURLWithPath:path];
NSURL *origBlobLoc = [NSURL fileURLWithPath:bloblocation];
[[NSFileManager defaultManager] copyItemAtURL:origBlobLoc toURL:saveLocation error:nil];
[self updateStatus:[NSString stringWithFormat:@"Saved blob to %@. Keep it safe!", saveLocation] color:[NSColor cyanColor]];
}
}];
}

- (IBAction)downgradeButtonAct:(id)sender {

NSAlert *alert = [[NSAlert alloc] init];
Expand All @@ -954,7 +977,7 @@ - (IBAction)downgradeButtonAct:(id)sender {
[self updateStatus:@"Restore was cancelled by user" color:[NSColor yellowColor]];
return;
}

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
restoreStarted = true;
dispatch_async(dispatch_get_main_queue(), ^(){
Expand All @@ -974,7 +997,7 @@ - (IBAction)downgradeButtonAct:(id)sender {
[self updateStatus:@"Device was already pwned, skipping exploitation" color:[NSColor cyanColor]];
});
}

else {
dfuDevPtr -> freeDevice(); // need to free the device so that iPwnder32 can take over
if ([self exploitDevice] != 0) {
Expand All @@ -985,19 +1008,19 @@ - (IBAction)downgradeButtonAct:(id)sender {
dfuDevPtr -> setAllDeviceInfo(); // set the rest
}
}

dispatch_async(dispatch_get_main_queue(), ^(){
[self updateStatus:@"Fetching OTA blob" color:[NSColor greenColor]];
});

if ([self saveOTABlob] == -2) {
dispatch_async(dispatch_get_main_queue(), ^(){

[self updateStatus:[NSString stringWithFormat: @"Failed to save %@ OTA blob. Is it being signed?", destination.getPref(@"destinationFW")] color: [NSColor redColor]];
return;
});
}

dispatch_async(dispatch_get_main_queue(), ^(){
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Backup your blob"];
Expand All @@ -1006,85 +1029,61 @@ - (IBAction)downgradeButtonAct:(id)sender {
[alert addButtonWithTitle:@"Skip"];
[alert setAlertStyle:NSAlertStyleWarning];
[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) {
/*
===================== BEWARE! ====================
|| YOU ARE ABOUT TO WITNESS MADNESS !!! ||
|| MADNESS OF A GUY WHO COULDN'T FIGURE OUT ||
|| HOW TO PROPERLY USE completionHandler ||
|| THERE IS NO GOING BACK, YOU HAVE BEEN WARNED ||
==================================================
*/
if (returnCode == NSAlertFirstButtonReturn) {
NSString *bloblocation = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/LDResources/SHSH/blob.shsh"];
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setMessage:@"Please select a location to save SHSH blob."];
[panel setAllowsOtherFileTypes:YES];
[panel setExtensionHidden:NO];
[panel setCanCreateDirectories:YES];
[panel setTitle:@"Save your blob"];
[panel setNameFieldStringValue:@"(give a name to your blob)"];
[panel beginWithCompletionHandler:^(NSInteger result) {

if (result == NSModalResponseOK) {
NSString *path = [[panel URL] path];
NSURL *saveLocation = [NSURL fileURLWithPath:path];
NSURL *a = [NSURL fileURLWithPath:bloblocation];
NSError *e = nil;
[[NSFileManager defaultManager] copyItemAtURL:a toURL:saveLocation error:&e];
[self updateStatus: [NSString stringWithFormat:@"Saved blob to %@. Keep it safe!", saveLocation] color:[NSColor cyanColor]];
}
else {
[self updateStatus:@"Skipped saving a copy of the blob" color:[NSColor yellowColor]];
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

PlistUtils destinationObject;
if (strcmp(destinationObject.getPref(@"destinationFW").UTF8String, "10.3.3") == 0) {
[self restore64];
[self -> _uselessIndicator stopAnimation:nil];
_selectIPSWoutlet.enabled = true;
return;
}
dfuDevPtr -> freeDevice();
[self restore32];
dispatch_async(dispatch_get_main_queue(), ^{
[self -> _uselessIndicator stopAnimation:nil];
_selectIPSWoutlet.enabled = true;
});
});
[self backupBlobWithCompletion:^{
[self restoreWrapper];
}];

} else {
[self restoreWrapper];
}

else if (returnCode == NSAlertSecondButtonReturn) {

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{


PlistUtils destinationObject;
if (strcmp(destinationObject.getPref(@"destinationFW").UTF8String, "10.3.3") == 0) {
[self restore64];
dispatch_async(dispatch_get_main_queue(), ^(){
[self -> _uselessIndicator stopAnimation:nil];
_selectIPSWoutlet.enabled = true;
});
return;
}
dfuDevPtr -> freeDevice();
[self restore32];
dispatch_async(dispatch_get_main_queue(), ^(){
[self -> _uselessIndicator stopAnimation:nil];
_selectIPSWoutlet.enabled = true;

});
});
}
}];
}];
});
});
});
}];
}

- (void)backupBlobWithCompletion:(void (^)(void))completion {
NSString *bloblocation = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/LDResources/SHSH/blob.shsh"];
NSSavePanel *panel = [NSSavePanel savePanel];
[panel setMessage:@"Please select a location to save SHSH blob."];
[panel setAllowsOtherFileTypes:YES];
[panel setExtensionHidden:NO];
[panel setCanCreateDirectories:YES];
[panel setTitle:@"Save your blob"];
[panel setNameFieldStringValue:@"(give a name to your blob)"];
[panel beginWithCompletionHandler:^(NSInteger result) {
if (result == NSModalResponseOK) {
NSString *path = [[panel URL] path];
NSURL *saveLocation = [NSURL fileURLWithPath:path];
NSURL *a = [NSURL fileURLWithPath:bloblocation];
NSError *e = nil;
[[NSFileManager defaultManager] copyItemAtURL:a toURL:saveLocation error:&e];
[self updateStatus:[NSString stringWithFormat:@"Saved blob to %@. Keep it safe!", saveLocation] color:[NSColor cyanColor]];
}
completion();
}];
}

- (void)restoreWrapper {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
PlistUtils destinationObject;
if (strcmp(destinationObject.getPref(@"destinationFW").UTF8String, "10.3.3") == 0) {
[self restore64];
dispatch_async(dispatch_get_main_queue(), ^(){
[self -> _uselessIndicator stopAnimation:nil];
_selectIPSWoutlet.enabled = true;
});
return;
}
dfuDevPtr -> freeDevice();
[self restore32];
dispatch_async(dispatch_get_main_queue(), ^(){
[self -> _uselessIndicator stopAnimation:nil];
_selectIPSWoutlet.enabled = true;
});
});
}

- (void)redirectLogToDocuments {
NSArray *allPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [allPaths objectAtIndex:0];
Expand Down

0 comments on commit 421cc1d

Please sign in to comment.