Skip to content

Commit

Permalink
Add an option to make the device automatically respring once the jail…
Browse files Browse the repository at this point in the history
…break is completed instead of waiting for the user to tap the OK button as requested by a Redditor
  • Loading branch information
pwn20wndstuff committed May 24, 2019
1 parent 7d59e3c commit e957ee8
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 55 deletions.
129 changes: 82 additions & 47 deletions Undecimus/Main.storyboard

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Undecimus/source/SettingsTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@property (weak, nonatomic) IBOutlet UISwitch *SSHOnlySwitch;
@property (weak, nonatomic) IBOutlet UISwitch *EnableGetTaskAllowSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *SetCSDebuggedSwitch;
@property (weak, nonatomic) IBOutlet UISwitch *AutoRespringSwitch;

+ (NSDictionary *)provisioningProfileAtPath:(NSString *)path;

Expand Down
9 changes: 9 additions & 0 deletions Undecimus/source/SettingsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ - (void)reloadData {
[self.SSHOnlySwitch setOn:(BOOL)prefs->ssh_only];
[self.EnableGetTaskAllowSwitch setOn:(BOOL)prefs->enable_get_task_allow];
[self.SetCSDebuggedSwitch setOn:(BOOL)prefs->set_cs_debugged];
[self.AutoRespringSwitch setOn:(BOOL)prefs->auto_respring];
[self.RestartSpringBoardButton setEnabled:respringSupported()];
[self.restartButton setEnabled:restartSupported()];
release_prefs(&prefs);
Expand Down Expand Up @@ -403,6 +404,14 @@ - (IBAction)setCSDebugged:(id)sender {
[self reloadData];
}

- (IBAction)setAutoRespring:(id)sender {
prefs_t *prefs = copy_prefs();
prefs->auto_respring = (bool)self.AutoRespringSwitch.isOn;
set_prefs(prefs);
release_prefs(&prefs);
[self reloadData];
}

- (IBAction)tappedOnResetAppPreferences:(id)sender {
void (^const block)(void) = ^(void) {
reset_prefs();
Expand Down
21 changes: 13 additions & 8 deletions Undecimus/source/jailbreak.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void jailbreak()
bool needSubstrate = NO;
bool skipSubstrate = NO;
NSString *const homeDirectory = NSHomeDirectory();
NSString *const temporaryDirectory = NSTemporaryDirectory();
NSMutableArray *debsToInstall = [NSMutableArray new];
NSMutableString *status = [NSMutableString new];
bool const betaFirmware = isBetaFirmware();
Expand All @@ -117,6 +118,8 @@ void jailbreak()
NSMutableArray *resources = [NSMutableArray new];
NSFileManager *const fileManager = [NSFileManager defaultManager];
bool const doInject = (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_12_0);
const char *success_file = [temporaryDirectory stringByAppendingPathComponent:@"jailbreak.completed"].UTF8String;
_assert(clean_file(success_file), localize(@"Unable to clean success file."), true);
#define insertstatus(x) do { [status appendString:x]; } while (false)
#define progress(x) do { LOG("Progress: %@", x); updateProgressHUD(hud, x); } while (false)
#define sync_prefs() do { _assert(set_prefs(prefs), localize(@"Unable to synchronize app preferences. Please restart the app and try again."), true); } while (false)
Expand Down Expand Up @@ -1567,23 +1570,24 @@ void jailbreak()
// Load Tweaks.

progress(localize(@"Loading Tweaks..."));
NSMutableString *waitCommand = [NSMutableString new];
[waitCommand appendFormat:@"while [[ ! -f %s ]]; do :; done;", success_file];
if (!prefs->auto_respring) {
[waitCommand appendFormat:@"while ps -p %d; do :; done;", myPid];
}
if (prefs->reload_system_daemons && !needStrap) {
rv = systemf("nohup bash -c \""
"while ps -p %d;"
"do :;"
"done;"
"%s"
"launchctl unload /System/Library/LaunchDaemons/com.apple.backboardd.plist && "
"ldrestart ;"
"launchctl load /System/Library/LaunchDaemons/com.apple.backboardd.plist"
"\" >/dev/null 2>&1 &", myPid);
"\" >/dev/null 2>&1 &", waitCommand.UTF8String);
} else {
rv = systemf("nohup bash -c \""
"while ps -p %d;"
"do :;"
"done;"
"%s"
"launchctl stop com.apple.mDNSResponder ;"
"sbreload"
"\" >/dev/null 2>&1 &", myPid);
"\" >/dev/null 2>&1 &", waitCommand.UTF8String);
}
_assert(WEXITSTATUS(rv) == ERR_SUCCESS, localize(@"Unable to load tweaks."), true);
LOG("Successfully loaded Tweaks.");
Expand Down Expand Up @@ -1627,6 +1631,7 @@ void jailbreak()
bool willRespring = (forceRespring);
willRespring |= (prefs->load_tweaks);
release_prefs(&prefs);
_assert(create_file(success_file, 501, 644), localize(@"Unable to create success file."), true);
showAlert(@"Jailbreak Completed", [NSString stringWithFormat:@"%@\n\n%@\n%@", localize(@"Jailbreak Completed with Status:"), status, localize(willRespring ? @"The device will now respring." : @"The app will now exit.")], true, false);
if (sharedController.canExit) {
if (forceRespring) {
Expand Down
2 changes: 2 additions & 0 deletions Undecimus/source/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define K_SSH_ONLY "SSHOnly"
#define K_ENABLE_GET_TASK_ALLOW "DoEnableGetTaskAllow"
#define K_SET_CS_DEBUGGED "SetCSDebugged"
#define K_AUTO_RESPRING "AutoRespring"

typedef struct {
bool load_tweaks;
Expand All @@ -55,6 +56,7 @@ typedef struct {
bool enable_get_task_allow;
bool set_cs_debugged;
bool hide_log_window;
bool auto_respring;
int exploit;
} prefs_t;

Expand Down
3 changes: 3 additions & 0 deletions Undecimus/source/prefs.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ bool load_prefs(prefs_t *prefs) {
prefs->set_cs_debugged = (bool)[[userDefaults objectForKey:@K_SET_CS_DEBUGGED inDomain:prefsFile] boolValue];
prefs->exploit = (int)[[userDefaults objectForKey:@K_EXPLOIT inDomain:prefsFile] intValue];
prefs->hide_log_window = (bool)[[userDefaults objectForKey:@K_HIDE_LOG_WINDOW inDomain:prefsFile] boolValue];
prefs->auto_respring = (bool)[[userDefaults objectForKey:@K_AUTO_RESPRING inDomain:prefsFile] boolValue];
return true;
}

Expand Down Expand Up @@ -91,6 +92,7 @@ bool set_prefs(prefs_t *prefs) {
[userDefaults setObject:[NSNumber numberWithBool:(BOOL)prefs->set_cs_debugged] forKey:@K_SET_CS_DEBUGGED inDomain:prefsFile];
[userDefaults setObject:[NSNumber numberWithInt:(int)prefs->exploit] forKey:@K_EXPLOIT inDomain:prefsFile];
[userDefaults setObject:[NSNumber numberWithBool:(BOOL)prefs->hide_log_window] forKey:@K_HIDE_LOG_WINDOW inDomain:prefsFile];
[userDefaults setObject:[NSNumber numberWithBool:(BOOL)prefs->auto_respring] forKey:@K_AUTO_RESPRING inDomain:prefsFile];
[userDefaults synchronize];
return true;
}
Expand All @@ -116,6 +118,7 @@ void register_default_prefs() {
defaults[@K_ENABLE_GET_TASK_ALLOW] = @YES;
defaults[@K_SET_CS_DEBUGGED] = @NO;
defaults[@K_HIDE_LOG_WINDOW] = @NO;
defaults[@K_AUTO_RESPRING] = @NO;
defaults[@K_EXPLOIT] = [NSNumber numberWithInteger:recommendedJailbreakSupport()];
[userDefaults registerDefaults:defaults];
}
Expand Down

1 comment on commit e957ee8

@abear1619
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still does not work for me on iPn 7* 11.3.1

Please sign in to comment.