Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
A shell on the running phone: OpenSSH over its own Wi-Fi, and the prefix's user database
vcvkkc8a690696eaa
diff --git a/tools/mk-jb.sh b/tools/mk-jb.shindex 497bfa0..5896b08 100755--- a/tools/mk-jb.sh+++ b/tools/mk-jb.sh@@ -103,7 +103,12 @@ ln -s /var/jb/usr/lib/TweakInject "$OUT/root/var/jb/Library/MobileSubstrate/Dyna# apt on the phone would upgrade them, but only over the network and only after a boot, while what is# in the image is what a first boot has. PREINSTALL names them; mobilesubstrate is not among them# because there is no such package -- ElleKit above Provides it.-PREINSTALL=${PREINSTALL-"debianutils launchctl preferenceloader"}+# OpenSSH among them: with the phone's radio up (wifi=1) a shell on the running system costs+# seconds instead of a rebuilt image and a six-minute boot, which changes how the rest of this+# port can be worked on. Nothing starts it -- a scenario does (userland/rc.jobs.ssh) -- and the+# key that lets anyone in is not in the repository. dropbear would have been smaller, but its+# package here depends on libtomcrypt1 and libtommath1, which are in no suite of this repository.+PREINSTALL=${PREINSTALL-"debianutils launchctl preferenceloader openssh-server openssh-client openssh-sftp-server libssl3 libmd0"}if [ -n "$PREINSTALL" ]; thenget "$MIRROR/dists/iphoneos-arm64-rootless/$SUITE/main/binary-iphoneos-arm64/Packages" PackagesMIRROR="$MIRROR" python3 "$ROOT/tools/jb-preinstall.py" "$OUT/root" "$OUT/debs/Packages" "$OUT/debs" $PREINSTALLdiff --git a/userland/build.sh b/userland/build.shindex 209a361..4d2d17b 100755--- a/userland/build.sh+++ b/userland/build.sh@@ -250,6 +250,23 @@ if [ -d $IOS/rootfs/usr/lib ]; then# the prefix with the root on the flash, downloads every package and index there, and without it each# download ended in "No such file or directory"printf 'd\t700\t501\t501\t/private/var/mobile/tmp\n' >> root/etc/var.skel+ # A key of ours for root, when there is one: ssh/authorized_keys, never in the repository (like+ # fw-*). dropbear from the package manager's prefix reads it and lets us in over the phone's+ # Wi-Fi, which saves rebuilding an image for every question one wants to ask a running iOS. It+ # refuses a key whose directory anyone but its owner may write, hence the 700.+ if [ -f ../ssh/authorized_keys ]; then+ mkdir -p root/var/root/.ssh+ printf 'd\t700\t0\t0\t/private/var/root/.ssh\n' >> root/etc/var.skel+ # the key that lets us in, and the host's own key beside it: made here and not on the+ # phone, because ssh-keygen asks the system who uid 0 is and gets "No user exists for+ # uid 0" -- the job that answers that (com.apple.mobile.usermanagerd) is loaded into+ # the user's domain, where a program of root's does not find it+ for k in authorized_keys ssh_host_ed25519_key ssh_host_ed25519_key.pub; do+ [ -f ../ssh/$k ] || continue+ cp ../ssh/$k root/var/root/.ssh/$k+ printf 'f\t600\t0\t0\t/private/var/root/.ssh/%s\t/var/root/.ssh/%s\n' $k $k >> root/etc/var.skel+ done+ ficp ${RC:-rc.launchd} root/etc/rccp ${RC_JOBS:-rc.jobs} root/etc/rc.jobs# QUIET=1: launchd's own standard error goes nowhere (src/init.c). It says a few thousanddiff --git a/userland/rc.jobs.ssh b/userland/rc.jobs.sshnew file mode 100644index 0000000..5d432a7--- /dev/null+++ b/userland/rc.jobs.ssh@@ -0,0 +1,26 @@+# Commands run by the launchd job com.redwood.demo (see com.redwood.demo.plist).+# A way in over the network (RC_JOBS=rc.jobs.ssh, with wifi=1 among XL_CMDLINE and a long XL_SECS):+# the phone's radio joins the network named in fw-wifi/network, configd gives en0 an address, and+# OpenSSH from the package manager's prefix lets us log in as root with the key in+# ssh/authorized_keys, which build.sh puts on the data volume. That spares a rebuilt image and a+# six-minute boot for every question one wants to ask a running iOS.+# (dropbear would be smaller, but its package in Procursus depends on libtomcrypt1 and libtommath1,+# which are in no suite of that repository: it cannot be installed at all.)+# The host key is made on the computer and shipped with the image (build.sh), because ssh-keygen on+# the phone answers "No user exists for uid 0": the job that serves the user database,+# com.apple.mobile.usermanagerd, is loaded into the user's domain and a program of root's does not+# find it there. launchctl is asked to put it into the system domain first, since sshd must look up+# the user it lets in. PAM is turned off on the command line: there is no pam.d for sshd in the+# prefix, and the key is all we want anyway.+# The switcher of running applications is opened on the way, so that a run serves both purposes:+# the purple cards are there to look at while the shell is open (see rc.jobs.switcher).+/redwood/bin/sound_test springboard+/redwood/bin/rwtouch wait 25 swipe 0.5 0.985 0.5 0.3 200 wait 70+/redwood/bin/net_test show+/var/jb/usr/sbin/sshd -D -e -h /var/root/.ssh/ssh_host_ed25519_key -o UsePAM=no -o PasswordAuthentication=no -o PermitRootLogin=prohibit-password -o AuthorizedKeysFile=/var/root/.ssh/authorized_keys &+/redwood/bin/rwtouch tap 0.151 0.358 wait 20 button home wait 8+/redwood/bin/rwtouch tap 0.383 0.358 wait 20 button home wait 8+/redwood/bin/rwtouch tap 0.614 0.481 wait 20+/redwood/bin/rwtouch drag 0.5 0.995 0.5 0.62 600 2500 wait 8+/redwood/bin/net_test show+/redwood/bin/rwtouch wait 900diff --git a/userland/src/init.c b/userland/src/init.cindex 3673c8d..1803880 100644--- a/userland/src/init.c+++ b/userland/src/init.c@@ -856,7 +856,7 @@ mount_writable(void)stat("/private/preboot/jb", &st) == 0 && (st.st_mode & S_IFMT) == S_IFDIR ? "/private/preboot/jb" : NULL;if (ok && jb != NULL) {const char *to = "/private/var/jb";- int dirs = 0, entries = 0, grafted;+ int dirs = 0, entries = 0, grafted, users = 0;/** With the root on the flash, the prefix's writable copy goes into a memory filesystem of its own@@ -896,7 +896,32 @@ mount_writable(void)grafted = chown(mobiles[i], 501, 501) == 0 && grafted;}grafted = own_tree("/private/var/jb/var/mobile", 501) && grafted;- printf(" /var/jb from %s, in %s: %d directories, %d files and links\n", jb, to, dirs, entries);+ /*+ * The prefix's own user database. Its programs do not ask iOS who a user is: they are+ * built against libiosexec, which carries an ie_getpwnam of its own and reads+ * /var/jb/etc/pwd.db -- a Berkeley database that pwd_mkdb makes from master.passwd and+ * that the bootstrap does not ship, only the text it is made from. Without it every+ * program of the prefix answers "no such user": an sshd from here refused every login+ * with "Invalid user root" while iOS's own /bin/ps resolved users perfectly. The+ * writable copy of the prefix is new at every boot, so the database is made at every+ * boot; it takes milliseconds.+ */+ if (stat("/private/var/jb/usr/sbin/pwd_mkdb", &st) == 0) {+ char *argv[] = { "/var/jb/usr/sbin/pwd_mkdb", "-p", "/var/jb/etc/master.passwd", NULL };+ char *envp[] = { "PATH=/var/jb/usr/sbin:/var/jb/usr/bin:/usr/bin:/bin", NULL };+ int status = 0;+ pid_t pid = fork();++ if (pid == 0) {+ execve(argv[0], argv, envp);+ _exit(127);+ }+ if (pid > 0 && wait4(pid, &status, 0, NULL) == pid && WIFEXITED(status) && WEXITSTATUS(status) == 0) {+ users = 1;+ }+ }+ printf(" /var/jb from %s, in %s: %d directories, %d files and links%s\n", jb, to, dirs, entries,+ users ? ", users resolvable" : "");check(grafted, "graft the package manager's prefix onto the data volume");}}