Skip to content

fix: prevent cleanup() from corrupting user preferences#13

Open
playday3008 wants to merge 1 commit intostaturnzz:mainfrom
playday3008:fix/cleanup-preferences-corruption
Open

fix: prevent cleanup() from corrupting user preferences#13
playday3008 wants to merge 1 commit intostaturnzz:mainfrom
playday3008:fix/cleanup-preferences-corruption

Conversation

@playday3008
Copy link
Copy Markdown

cleanup() writes to NSUserDefaults after the process has escalated to root via set_permissions(). At that point, NSUserDefaults no longer operates on the app's sandboxed plist — it overwrites it with only {restrap: "no"}, losing the tweaks key.

On subsequent boots, stringForKey:@"tweaks" returns nil, [nil isEqual:@"yes"] is NO, and load_daemons() silently gets skipped. No Substrate injection, no LaunchDaemons, no rc.d scripts. The UI toggle still appears ON because the storyboard default is ON and viewDidLoad only explicitly sets it for @"yes" with no else clause.

The legacy branch avoided this by writing both keys back in cleanup():

[[NSUserDefaults standardUserDefaults] setObject:@"yes" forKey:@"tweaks"];
[[NSUserDefaults standardUserDefaults] setObject:@"no" forKey:@"restrap"];

When this was rewritten for main, the tweaks re-write was dropped, exposing the bug.

This PR moves the restrap reset to the ViewController, before run_jailbreak() — still running as mobile, NSUserDefaults works correctly, and flags have already been read.

cleanup() runs after UID escalation to root. Writing to NSUserDefaults
as root causes it to overwrite the app's preference plist, losing keys
like "tweaks". This makes the "Load Tweaks" toggle appear enabled in
the UI (storyboard default) while the actual preference is nil, so
load_daemons() is silently skipped on subsequent boots.

Move the restrap flag reset to ViewController before run_jailbreak()
is called, where the process still runs as the mobile user and
NSUserDefaults operates on the correct plist.
@playday3008
Copy link
Copy Markdown
Author

playday3008 commented Apr 9, 2026

Also, on side note, maybe make Socket also add it's own repo (https://socket-jb.app/repo/) in:

socket/socket/jailbreak.m

Lines 82 to 103 in 89026d2

int update_zebra_sources(void) {
mkdir(ZEBRA_SOURCES_PATH, 0755);
chown(ZEBRA_SOURCES_PATH, 501, 501);
unlink(ZEBRA_SOURCES_FILE);
FILE *file = fopen(ZEBRA_SOURCES_FILE, "w+");
if (file == NULL) return -1;
fprintf(file, "%s\n", APT_TELESPHOREO_REPO);
fprintf(file, "%s\n", APT_BIGBOSS_REPO);
fprintf(file, "%s\n", APT_MODMYI);
fprintf(file, "%s\n", APT_CHARIZ_REPO);
fprintf(file, "%s\n", APT_PACKIX_REPO);
fprintf(file, "%s\n", APT_HAVOC_REPO);
fprintf(file, "%s\n", APT_ZEBRA_REPO);
fprintf(file, "%s\n", APT_LUKEZGD_REPO);
fflush(file);
fclose(file);
sync();
return 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant