Skip to content

Commit

Permalink
use posix_spawn as fallback for NSTask
Browse files Browse the repository at this point in the history
  • Loading branch information
Samgisaninja committed Jan 28, 2020
1 parent 9625b5d commit a904469
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Binary file not shown.
27 changes: 27 additions & 0 deletions SuccessionRestore/RestoreViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "RestoreViewController.h"
#include <sys/sysctl.h>
#import "NSTask.h"
#import <spawn.h>

@interface RestoreViewController ()

Expand Down Expand Up @@ -204,6 +205,32 @@ -(void)attachDiskImage{
[self logToFile:[NSString stringWithFormat:@"found attached diskpath %@", diskPath] atLineNumber:__LINE__];
[self prepareMountAttachedDisk:diskPath];
}
} else if ([outString containsString:@"must be run by root"]) {
pid_t pid;
const char* args[] = {"hdik", "/var/mobile/Media/Succession/rfs.dmg", NULL};
posix_spawn(&pid, "/Applications/SuccessionRestore.app/hdik", NULL, NULL, (char* const*)args, NULL);
NSMutableArray *changedDevContents = [NSMutableArray arrayWithArray:[[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/dev/" error:nil]];
[changedDevContents removeObjectsInArray:beforeAttachDevContents];
[self logToFile:[NSString stringWithFormat:@"changedDevContents: %@", [changedDevContents componentsJoinedByString:@" "]] atLineNumber:__LINE__];
if ([[changedDevContents componentsJoinedByString:@" "] containsString:@"s2"]) {
for (NSString *attachedDisk in changedDevContents) {
if (![attachedDisk containsString:@"r"]) {
if ([attachedDisk containsString:@"s2"]) {
NSString *diskPath = [NSString stringWithFormat:@"/dev/%@", attachedDisk];
[self logToFile:[NSString stringWithFormat:@"found attached diskpath %@", diskPath] atLineNumber:__LINE__];
[self prepareMountAttachedDisk:diskPath];
}
}
}
} else {
for (NSString *attachedDisk in changedDevContents) {
if ([attachedDisk hasPrefix:@"disk"]) {
NSString *diskPath = [NSString stringWithFormat:@"/dev/%@", attachedDisk];
[self logToFile:[NSString stringWithFormat:@"found attached diskpath %@", diskPath] atLineNumber:__LINE__];
[self prepareMountAttachedDisk:diskPath];
}
}
}
} else {
NSMutableArray *changedDevContents = [NSMutableArray arrayWithArray:[[NSFileManager defaultManager] contentsOfDirectoryAtPath:@"/dev/" error:nil]];
[changedDevContents removeObjectsInArray:beforeAttachDevContents];
Expand Down

0 comments on commit a904469

Please sign in to comment.