Skip to content

Instantly share code, notes, and snippets.

@LukeZGD
Last active July 26, 2026 01:08
Show Gist options
  • Select an option

  • Save LukeZGD/2d4a2416775f88c8c9fd20e2e12179b7 to your computer and use it in GitHub Desktop.

Select an option

Save LukeZGD/2d4a2416775f88c8c9fd20e2e12179b7 to your computer and use it in GitHub Desktop.
reboot4 binary for setting up ios 4 powdersn0w
// clang -isysroot iPhoneOS5.1.sdk -arch armv7 reboot4.c -o reboot4
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <spawn.h>
extern char **environ;
/**
* Spawns a process and waits for it to complete.
* Returns the process exit status, or -1 on error.
*/
int easy_spawn(const char *path, char *const argv[]) {
pid_t pid;
int status;
// Spawn child process
int res = posix_spawn(&pid, path, NULL, NULL, argv, environ);
if (res != 0) {
perror("posix_spawn failed");
return -1;
}
// Wait for completion
if (waitpid(pid, &status, 0) == -1) {
perror("waitpid failed");
return -1;
}
return status;
}
int main(void) {
printf("1. Initial file system checks\n");
easy_spawn("/sbin/fsck_hfs", (char *[]){"/sbin/fsck_hfs", "-f", "/dev/disk0s1", NULL});
easy_spawn("/sbin/fsck_hfs", (char *[]){"/sbin/fsck_hfs", "-f", "/dev/disk0s2s1", NULL});
printf("2. Mount data partition\n");
easy_spawn("/sbin/mount_hfs", (char *[]){"/sbin/mount_hfs", "/dev/disk0s2s1", "/mnt2", NULL});
printf("3. Remount ramdisk read-write\n");
easy_spawn("/sbin/mount", (char *[]){"/sbin/mount", "-u", "-o", "rw", "/", NULL});
sync();
sleep(1);
printf("4. Run partition4\n");
easy_spawn("/sbin/partition4", (char *[]){"/sbin/partition4", NULL});
sync();
sync();
sync();
sleep(1);
printf("5. Unmount data partition\n");
easy_spawn("/sbin/umount", (char *[]){"/sbin/umount", "/mnt2", NULL});
sync();
sleep(1);
printf("5. Write partition information\n");
easy_spawn("/bin/dd", (char *[]){"/bin/dd", "if=/TwistedMind2", "of=/dev/rdisk0", "bs=8192", NULL});
sync();
sync();
sync();
sleep(3);
printf("6. Write exploit\n");
easy_spawn("/bin/dd", (char *[]){"/bin/dd", "if=/exploit", "of=/dev/rdisk0s4", "bs=512k", NULL});
sync();
sync();
sync();
sleep(3);
printf("7. Post-write file system checks\n");
easy_spawn("/sbin/fsck_hfs", (char *[]){"/sbin/fsck_hfs", "-f", "/dev/disk0s1", NULL});
easy_spawn("/sbin/fsck_hfs", (char *[]){"/sbin/fsck_hfs", "-f", "/dev/disk0s2s1", NULL});
printf("8. Set nvram variables\n");
easy_spawn("/usr/sbin/nvram", (char *[]){"/usr/sbin/nvram", "-c", NULL});
easy_spawn("/usr/sbin/nvram", (char *[]){"/usr/sbin/nvram", "boot-partition=2", NULL});
// comment out below for no boot-ramdisk (nbr)
easy_spawn("/usr/sbin/nvram", (char *[]){"/usr/sbin/nvram", "boot-ramdisk=/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/0/1/2/3/4/5/6/7/8/9/A/B/C/disk.dmg", NULL});
sync();
sync();
sync();
sleep(1);
printf("9. System reboot\n");
reboot(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment