Skip to content

Instantly share code, notes, and snippets.

@sen0rxol0
Created July 3, 2023 10:25
Show Gist options
  • Save sen0rxol0/af3cf9c8acbbfd234c0fac760d796c45 to your computer and use it in GitHub Desktop.
Save sen0rxol0/af3cf9c8acbbfd234c0fac760d796c45 to your computer and use it in GitHub Desktop.
SSH ramdisk mount filesystems in 64bit iOS devices, sep devices
/* compile with: xcrun -sdk iphoneos clang -arch arm64 -Wall -o ./mountfs ./mountfs.c */
#include <stdio.h>
#include <sys/wait.h>
#include <spawn.h>
#include <unistd.h>
/*
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s3) == 'Preboot' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s3 /mnt6 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s4) == 'Preboot' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s4 /mnt6 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s5) == 'Preboot' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s5 /mnt6 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s6) == 'Preboot' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s6 /mnt6 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s7) == 'Preboot' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s7 /mnt6 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s3) == 'xART' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s3 /mnt7 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s4) == 'xART' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s4 /mnt7 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s5) == 'xART' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s5 /mnt7 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s6) == 'xART' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s6 /mnt7 \n\
fi \n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s7) == 'xART' ]]; then \n\
/sbin/mount_apfs /dev/disk0s1s7 /mnt7 \n\
fi \n\
*/
#define SHELL_SCRIPT "\
/sbin/mount_apfs /dev/disk0s1s1 /mnt1\n\
for n in {3..7}\n\
do\n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s$n) == 'Preboot' ]];then\n\
/sbin/mount_apfs /dev/disk0s1s$n /mnt6\n\
fi\n\
done\n\
for n in {3..7}\n\
do\n\
if [[ $(/System/Library/Filesystems/apfs.fs/apfs.util -p /dev/disk0s1s$n) == 'xART' ]];then\n\
/sbin/mount_apfs /dev/disk0s1s$n /mnt7\n\
fi\n\
done\n\
/usr/libexec/seputil --gigalocker-init 1> /dev/null\n\
if [[ -e /mnt6/active ]];then\n\
/usr/libexec/seputil --load /mnt6/$(cat /mnt6/active)/usr/standalone/firmware/sep-firmware.img4\n\
else\n\
/usr/libexec/seputil --load /mnt1/usr/standalone/firmware/sep-firmware.img4\n\
fi\n\
/sbin/mount_apfs /dev/disk0s1s2 /mnt2\n\
echo\n"
extern char **environ;
int main()
{
char *mountfs[] = {"/bin/bash", "-c", SHELL_SCRIPT, NULL};
pid_t child;
posix_spawn(&child, mountfs[0], NULL, NULL, mountfs, environ);
waitpid(child, NULL, 0);
sleep(2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment