Skip to content

Commit

Permalink
add force revert alert
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfugil committed Jul 21, 2024
1 parent ee920f1 commit f1f8b20
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
2 changes: 2 additions & 0 deletions include/payload/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <xpc/xpc.h>
#include <CoreFoundation/CoreFoundation.h>
#include <os/log.h>
#include <IOKit/IOKitLib.h>

#ifndef __OBJC__
void NSLog(CFStringRef, ...);
Expand Down Expand Up @@ -101,6 +102,7 @@ void reload_launchd_env(void);
void perform_reboot3(xpc_object_t peer, xpc_object_t xreply, xpc_object_t request, struct paleinfo* pinfo_p);
void runcmd(xpc_object_t xrequest, xpc_object_t xreply, struct paleinfo* __unused pinfo);
int bootscreend_main(void);
kern_return_t enter_recovery();
ssize_t write_fdout(int fd, void* buf, size_t len);
_Noreturn void _panic(char* fmt, ...);
extern bool panic_did_enter;
Expand Down
42 changes: 40 additions & 2 deletions src/payload/loader/launchdaemons.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <libjailbreak/libjailbreak.h>
#include <dlfcn.h>

#define RB2_FULLREBOOT (0x8000000000000000llu)
int reboot3(uint64_t flags, ...);
mach_port_t (*SBSSpringBoardServerPort)(void);
static CFRunLoopRef loop;

Expand All @@ -16,6 +18,35 @@ void sb_launched(CFNotificationCenterRef __unused center, void __unused *observe
CFRunLoopStop(loop);
}

void* force_revert_notif_thread(__unused void* arg) {
CFUserNotificationRef force_revert_notif = NULL;
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
if (dict) {
CFDictionarySetValue(dict, kCFUserNotificationAlertHeaderKey, CFSTR("Reboot required"));
CFDictionarySetValue(dict, kCFUserNotificationAlertMessageKey, CFSTR(
"A reboot is required to complete the force revert.\n\n"
"If you wish to jailbreak again, you can choose to enter recovery mode instead.\n"
));
CFDictionarySetValue(dict, kCFUserNotificationDefaultButtonTitleKey, CFSTR("Reboot now"));
CFDictionarySetValue(dict, kCFUserNotificationAlternateButtonTitleKey, CFSTR("Enter recovery mode"));
CFDictionarySetValue(dict, kCFUserNotificationOtherButtonTitleKey, CFSTR("Reboot later"));

force_revert_notif = CFUserNotificationCreate(kCFAllocatorDefault, 0, 0, NULL, dict);
CFRelease(dict);

CFOptionFlags cfres;
CFUserNotificationReceiveResponse(force_revert_notif, 0, &cfres);
if ((cfres & 0x3) == kCFUserNotificationDefaultResponse) {
reboot3(RB2_FULLREBOOT);
} else if ((cfres & 0x3) == kCFUserNotificationAlternateResponse) {
enter_recovery();
reboot3(RB2_FULLREBOOT);
}
CFRelease(force_revert_notif);
}
return NULL;
}

int launchdaemons(uint32_t payload_options, uint64_t pflags) {
printf("plooshInit launchdaemons...\n");
int platform = get_platform();
Expand Down Expand Up @@ -70,6 +101,11 @@ int launchdaemons(uint32_t payload_options, uint64_t pflags) {
else if (platform != PLATFORM_BRIDGEOS)
runCommand((char*[]){ "/cores/binpack/usr/bin/uicache", "-a", NULL });

pthread_t fr_notif_thread = NULL;
if (pflags & palerain_option_force_revert) {
pthread_create(&fr_notif_thread, NULL, &force_revert_notif_thread, NULL);
}

/* just in case the above commands are bad, we run them last so the user can still get the loader */
switch (platform) {
case PLATFORM_IOS:
Expand All @@ -82,8 +118,10 @@ int launchdaemons(uint32_t payload_options, uint64_t pflags) {
default:
fprintf(stderr, "uicache_loader: unsupported platform\n");
}



if (pflags & palerain_option_force_revert) {
pthread_join(fr_notif_thread, NULL);
}
printf("plooshInit launchdaemons: Goodbye!\n");
return 0;
}
18 changes: 11 additions & 7 deletions src/payload/loader/setup_fakefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ void notch_clear(char* machine) {
}
}

kern_return_t enter_recovery(void) {
io_registry_entry_t nvram = IORegistryEntryFromPath(kIOMasterPortDefault, kIODeviceTreePlane ":/options");
kern_return_t ret = IORegistryEntrySetCFProperty(nvram, CFSTR("auto-boot"), CFSTR("false"));
printf("set nvram auto-boot=false ret: %d\n",ret);
ret = IORegistryEntrySetCFProperty(nvram, CFSTR(kIONVRAMForceSyncNowPropertyKey), CFSTR("auto-boot"));
printf("sync nvram ret: %d\n",ret);
IOObjectRelease(nvram);
return ret;
}

int copyfile_fakefs_cb(int what, int __unused stage, copyfile_state_t __unused state, const char * src, const char * __unused dst, void * ctx) {
char basename_buf[PATH_MAX];
struct paleinfo* pinfo_p = ((struct cb_context*)ctx)->pinfo_p;
Expand Down Expand Up @@ -227,13 +237,7 @@ int setup_fakefs(uint32_t __unused payload_options, struct paleinfo* pinfo_p) {
if (access("/sbin/umount", F_OK) == 0)
runCommand((char*[]){ "/sbin/umount", "-a", NULL });

io_registry_entry_t nvram = IORegistryEntryFromPath(kIOMasterPortDefault, kIODeviceTreePlane ":/options");
kern_return_t ret = IORegistryEntrySetCFProperty(nvram, CFSTR("auto-boot"), CFSTR("false"));
printf("set nvram auto-boot=false ret: %d\n",ret);
ret = IORegistryEntrySetCFProperty(nvram, CFSTR(kIONVRAMForceSyncNowPropertyKey), CFSTR("auto-boot"));
printf("sync nvram ret: %d\n",ret);
IOObjectRelease(nvram);

enter_recovery();
sync();
return 0;
}

0 comments on commit f1f8b20

Please sign in to comment.