From 8988bb735344c2bddce17ece315dd95e317ad4ff Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Fri, 4 Dec 2026 15:55:48 +0800 Subject: [PATCH] resize: the amethyst access route, without DFU on iOS 12.2 to 13.7 `orchard resize --amethyst` (or --access amethyst) installs Resize APFS inside the pinned official Amethyst 1.1 app, signed with the person's Apple ID through xtool, as the dopamine route does with Dopamine. It reaches every device on iOS 12.2 to 13.7 from any computer, so the iPhone 5s, iPad Air and iPad mini 2 and 3 can make room without checkra1n, whose Linux build leaves out A7 (OrchardLinux/tools#115). The Resize APFS release brings the Amethyst part in out/device-ios12/access, with Amethyst's executable built from its source (the released one is stripped, so its functions have no names to call); prepare() puts that executable in place of the official one and refuses a stripped one, as resize-apfs's embed.py does (OrchardLinux/resize-apfs#43). Xcode builds nothing for iOS 12 and 13, so only xtool signs, and there is no Developer Mode step. The route needs its entry in routes.toml (orchard) and a Resize APFS release that has the part. Assisted-by: LLM --- CHANGELOG.md | 5 + crates/cli/src/commands/resize.rs | 43 ++++- crates/runtime/examples/dopamine_prepare.rs | 2 +- crates/runtime/src/access_dopamine.rs | 170 ++++++++++++++++++-- crates/runtime/src/helper_app.rs | 2 +- crates/runtime/src/resize_app.rs | 42 +++-- docs/resize.md | 25 ++- 7 files changed, 254 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f0ea6a8..a1e368c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,11 @@ is on main, the release is published with that section as its notes (AGENTS.md, iOS 10.3.4, boots past its iBSS after a Pico's checkm8: Orchard sends the plain iBEC there instead of stopping for an encrypted one. +- `orchard resize --amethyst` makes room on iOS 12.2 to 13.7 without DFU + mode and from any computer, Linux included: Resize APFS comes inside the + Amethyst app, signed with your Apple ID. The iPhone 5s, iPad Air and iPad + mini 2 and 3 can now make room without a Mac. + - Touch firmware builds for the iPad Pro 9.7-inch Cellular (J128), whose touch settings leave out the "Power Off On Reset" flag. Firmware for devices whose settings carry the flag is unchanged. diff --git a/crates/cli/src/commands/resize.rs b/crates/cli/src/commands/resize.rs index e8704a89..57a04932 100644 --- a/crates/cli/src/commands/resize.rs +++ b/crates/cli/src/commands/resize.rs @@ -27,6 +27,9 @@ pub struct AccessFlags { /// Short for --access dopamine #[arg(long, conflicts_with = "access")] dopamine: bool, + /// Short for --access amethyst + #[arg(long, conflicts_with = "access")] + amethyst: bool, } #[derive(clap::Args)] @@ -56,14 +59,14 @@ pub struct Args { pub fn run(global: &Global, args: &Args) -> Result { let started = Instant::now(); let say = |message: &str| output::progress(global, &format!("[{:.3}s] {message}", started.elapsed().as_secs_f64())); - let short = [(args.short.palera1n, "palera1n"), (args.short.checkra1n, "checkra1n"), (args.short.dopamine, "dopamine")]; + let short = [(args.short.palera1n, "palera1n"), (args.short.checkra1n, "checkra1n"), (args.short.dopamine, "dopamine"), (args.short.amethyst, "amethyst")]; let route = args.access.as_deref().or(short.into_iter().find_map(|(set, name)| set.then_some(name))).unwrap_or("palera1n"); let data = global.data_dir()?; let catalog = Catalog::open(&data)?; let routes = routes::read(&catalog)?; routes.named(Kind::Access, route)?; - if !matches!(route, "palera1n" | "checkra1n" | "dopamine") { + if !matches!(route, "palera1n" | "checkra1n" | "dopamine" | "amethyst") { return Err(Error::new(Code::Unsupported, format!("this version does not run the {route} access route"))); } // checkra1n's session ends when the person says so: that needs a terminal. @@ -96,6 +99,9 @@ pub fn run(global: &Global, args: &Args) -> Result { if route == "dopamine" { return dopamine(&executor, &app, args, &say, started); } + if route == "amethyst" { + return amethyst(&executor, &app, args, &say, started); + } let found = super::run::find(global, Duration::from_secs(args.wait))?; let selector = Selector { ecid: found.identity.ecid.clone(), location: Some(found.location.clone()), mode: Some(Mode::Dfu) }; let mut session = Session::start(Host, &selector, None)?; @@ -221,17 +227,48 @@ fn dopamine(executor: &orchard_runtime::exec::Executor, app: &orchard_runtime::r // Developer Mode comes after the install: iOS lists that setting only // once an app signed this way is on the device. access_dopamine::install(executor, access, &signer, &udid, access_dopamine::RESIZE_APFS, say)?; - Ok(Installed { version: app.version.clone(), seconds: started.elapsed().as_secs_f64() }.into()) + Ok(Installed { version: app.version.clone(), seconds: started.elapsed().as_secs_f64(), developer_mode: true }.into()) +} + +/// The route without DFU on iOS 12.2 to 13.7: as [`dopamine`], with the +/// pinned Amethyst, always signed by xtool (Xcode builds nothing for iOS 12 +/// and 13), and without Developer Mode, which those versions do not have. +fn amethyst(executor: &orchard_runtime::exec::Executor, app: &orchard_runtime::resize_app::App, args: &Args, say: &dyn Fn(&str), started: Instant) -> Result { + use orchard_runtime::access_dopamine; + if args.team.is_some() { + return Err(Error::new(Code::Unsupported, "the amethyst route signs with xtool: Xcode builds nothing for iOS 12 and 13")); + } + let access = app.amethyst.as_ref().ok_or_else(|| Error::new(Code::NotFound, format!("Resize APFS {} has no build for the amethyst route", app.version)))?; + if !access_dopamine::xtool_here() { + return Err(Error::new(Code::Unsupported, "nothing on this computer signs the app: xtool publishes no build for it")); + } + let udid = access_dopamine::device()?; + say("Signing with xtool and your Apple ID"); + access_dopamine::install_into(executor, access_dopamine::Host::Amethyst, access, &access_dopamine::Signer::Xtool, &udid, access_dopamine::RESIZE_APFS, say)?; + Ok(Installed { version: app.version.clone(), seconds: started.elapsed().as_secs_f64(), developer_mode: false }.into()) } #[derive(Serialize)] struct Installed { version: String, seconds: f64, + /// iOS 15 and later: Developer Mode must be on (the dopamine route). + developer_mode: bool, } impl Report for Installed { fn human(&self) -> Vec { + if !self.developer_mode { + return format!( + "Resize APFS {} is installed ({:.0} s).\n\ + Trust your Apple ID on the device: Settings > General > Profiles & Device Management.\n\ + Then open Resize APFS and tap Continue. The first time, the device restarts once: open Resize APFS \ + again when it is back and tap Continue again. Then the screen restarts; unlock the device when it comes back.\n\ + A free Apple ID signs the app for 7 days: run this again when it stops opening.\n", + self.version, self.seconds + ) + .into_bytes(); + } format!( "Resize APFS {} is installed ({:.0} s).\n\ Turn on Developer Mode on the device: Settings > Privacy & Security > Developer Mode \ diff --git a/crates/runtime/examples/dopamine_prepare.rs b/crates/runtime/examples/dopamine_prepare.rs index 8b4403ff..b367c27a 100644 --- a/crates/runtime/examples/dopamine_prepare.rs +++ b/crates/runtime/examples/dopamine_prepare.rs @@ -21,7 +21,7 @@ fn main() { let dir = Path::new(&args[2]); let mut resources = Vec::new(); files(&dir.join("Resources"), &dir.join("Resources"), &mut resources); - let access = Access { info: std::fs::read(dir.join("Info.plist")).unwrap(), library: std::fs::read(dir.join("ResizeAccess.dylib")).unwrap(), resources }; + let access = Access { info: std::fs::read(dir.join("Info.plist")).unwrap(), library: std::fs::read(dir.join("ResizeAccess.dylib")).unwrap(), resources, host: None }; let prepared = prepare(std::fs::read(&args[1]).unwrap(), &access, Path::new(&args[3])).unwrap(); // With a fourth argument, also the IPA a signing tool is given. if let Some(ipa) = args.get(4) { diff --git a/crates/runtime/src/access_dopamine.rs b/crates/runtime/src/access_dopamine.rs index 6efe1df8..6749fe27 100644 --- a/crates/runtime/src/access_dopamine.rs +++ b/crates/runtime/src/access_dopamine.rs @@ -21,6 +21,13 @@ //! //! Signing happens on the person's computer, with their account, for their //! device. +//! +//! On iOS 12 and 13 the same is done with the pinned official Amethyst +//! release ([`Host::Amethyst`], resize-apfs's `scripts/amethyst_route.py`). +//! Its released executable is stripped, so the Resize APFS release brings +//! the same executable built from Amethyst's source (`host/Amethyst`), which +//! takes the official one's place; every other file is the release's. +//! xtool always signs it: Xcode builds nothing for iOS 12 and 13. use crate::exec::Executor; use crate::resize_app::Access; use crate::usbmux; @@ -36,7 +43,58 @@ use std::time::{Duration, Instant}; const DOPAMINE: &str = "https://github.com/opa334/Dopamine/releases/download/3.0.13/Dopamine.ipa"; const DOPAMINE_BYTES: u64 = 55_422_988; const DOPAMINE_SHA256: &str = "3664edd737cc672af5d9036d2d1513fb1d50784f0c0cfd49cc6e651b8c665e14"; +/// Amethyst 1.1, the official release (resize-apfs `scripts/tools.py`). +const AMETHYST: &str = "https://github.com/staturnzz/amethyst/releases/download/v1.1/Amethyst.ipa"; +const AMETHYST_BYTES: u64 = 115_881_245; +const AMETHYST_SHA256: &str = "65fad9542e3d73246d602b7ee259055928978650f4e93b8f93a513da8266f3b4"; +const AMETHYST_IDENTIFIER: &str = "com.staturnz.amethyst"; +/// What Resize APFS's Access/AmethystBridge.m looks up in Amethyst: the +/// exported functions and globals (with their leading underscore), then the +/// names of the objects' properties and methods. A stripped executable has +/// none of the first. +const AMETHYST_INTERFACE: &[&str] = &[ + "_run_jailbreak", + "_jbserver_heartbeat", + "_jbserver_post_jailbreak", + "_run_jbutil", + "_amethyst", + "_mainController", + "exploit", + "generator", + "installAlert", + "installSileo", + "installZebra", + "setSwitchValue:", + "isOpen", + "closeAlert", + "fade", +]; const LIBRARY: &str = "@executable_path/Frameworks/ResizeAccess.dylib"; + +/// The app Resize APFS is put into. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Host { + /// iOS 15 and later. + Dopamine, + /// iOS 12.2 to 13.7. + Amethyst, +} + +impl Host { + fn receipt(self) -> Receipt { + match self { + Host::Dopamine => Receipt { url: DOPAMINE.into(), bytes: DOPAMINE_BYTES, sha256: DOPAMINE_SHA256.into(), expanded_bytes: None }, + Host::Amethyst => Receipt { url: AMETHYST.into(), bytes: AMETHYST_BYTES, sha256: AMETHYST_SHA256.into(), expanded_bytes: None }, + } + } + + fn name(self) -> &'static str { + match self { + Host::Dopamine => "Dopamine", + Host::Amethyst => "Amethyst", + } + } +} /// What the app's interface calls in Dopamine. A Dopamine release without /// one of these names is refused here instead of failing on the device. const INTERFACE: &[&str] = &[ @@ -83,7 +141,7 @@ fn format(message: impl Into) -> Error { } fn le32(data: &[u8], at: usize) -> Result { - data.get(at..at + 4).map(|b| u32::from_le_bytes(b.try_into().expect("4 bytes"))).ok_or_else(|| format("the Dopamine executable is cut short")) + data.get(at..at + 4).map(|b| u32::from_le_bytes(b.try_into().expect("4 bytes"))).ok_or_else(|| format("the app's executable is cut short")) } fn is_macho(data: &[u8]) -> bool { @@ -96,7 +154,7 @@ fn is_macho(data: &[u8]) -> bool { fn add_to_slice(data: &[u8], path: &str) -> Result> { const HEADER: usize = 32; if le32(data, 0)? != 0xfeed_facf { - return Err(format("the Dopamine executable is not a 64-bit program")); + return Err(format("the app's executable is not a 64-bit program")); } let (count, size) = (le32(data, 16)? as usize, le32(data, 20)? as usize); let end = HEADER + size; @@ -105,7 +163,7 @@ fn add_to_slice(data: &[u8], path: &str) -> Result> { for _ in 0..count { let (command, length) = (le32(data, at)?, le32(data, at + 4)? as usize); if length < 8 || at + length > end { - return Err(format("the Dopamine executable has damaged load commands")); + return Err(format("the app's executable has damaged load commands")); } // LC_LOAD_DYLIB: the name starts at the offset its third word gives. if command == 0xc { @@ -135,7 +193,7 @@ fn add_to_slice(data: &[u8], path: &str) -> Result> { } added.extend(name); if end + added.len() > first_section || data[end..end + added.len()].iter().any(|b| *b != 0) { - return Err(format("the Dopamine executable has no room for another library")); + return Err(format("the app's executable has no room for another library")); } let mut out = data.to_vec(); out[16..20].copy_from_slice(&(count as u32 + 1).to_le_bytes()); @@ -150,11 +208,11 @@ fn add_library(data: &[u8]) -> Result> { if data.get(..4) != Some(&[0xca, 0xfe, 0xba, 0xbe]) { return add_to_slice(data, LIBRARY); } - let be32 = |at: usize| data.get(at..at + 4).map(|b| u32::from_be_bytes(b.try_into().expect("4 bytes")) as usize).ok_or_else(|| format("the Dopamine executable is cut short")); + let be32 = |at: usize| data.get(at..at + 4).map(|b| u32::from_be_bytes(b.try_into().expect("4 bytes")) as usize).ok_or_else(|| format("the app's executable is cut short")); let mut out = data.to_vec(); for index in 0..be32(4)? { let (offset, size) = (be32(8 + index * 20 + 8)?, be32(8 + index * 20 + 12)?); - let slice = data.get(offset..offset + size).ok_or_else(|| format("the Dopamine executable is cut short"))?; + let slice = data.get(offset..offset + size).ok_or_else(|| format("the app's executable is cut short"))?; out[offset..offset + size].copy_from_slice(&add_to_slice(slice, LIBRARY)?); } Ok(out) @@ -194,7 +252,7 @@ pub fn prepare(ipa: Vec, access: &Access, work: &Path) -> Result { let modes = archive.entries().filter(|e| e.mode != 0).map(|e| (e.name.clone(), e.mode & 0o7777)).collect(); for name in &names { if name.starts_with('/') || name.split('/').any(|part| part == "..") { - return Err(format("an unsafe path in the Dopamine IPA")); + return Err(format("an unsafe path in the IPA")); } if !name.ends_with('/') { write(&work.join(name), &archive.read(name, MEMBER)?)?; @@ -202,16 +260,23 @@ pub fn prepare(ipa: Vec, access: &Access, work: &Path) -> Result { } let mut apps = std::fs::read_dir(work.join("Payload"))?.flatten().map(|e| e.path()).filter(|p| p.extension().is_some_and(|e| e == "app")); let (Some(app), None) = (apps.next(), apps.next()) else { - return Err(format("the Dopamine IPA does not hold exactly one app")); + return Err(format("the IPA does not hold exactly one app")); }; - let mut info = dictionary(&std::fs::read(app.join("Info.plist"))?, "Dopamine's Info.plist")?; + let mut info = dictionary(&std::fs::read(app.join("Info.plist"))?, "the host app's Info.plist")?; let ours = dictionary(&access.info, "the app's Info.plist")?; - let executable = app.join(info.get("CFBundleExecutable").and_then(Value::as_string).ok_or_else(|| format("Dopamine names no executable"))?); - let program = std::fs::read(&executable)?; + let executable = app.join(info.get("CFBundleExecutable").and_then(Value::as_string).ok_or_else(|| format("the host app names no executable"))?); + let amethyst = info.get("CFBundleIdentifier").and_then(Value::as_string) == Some(AMETHYST_IDENTIFIER); + let program = match (amethyst, &access.host) { + (true, Some(built)) => built.clone(), + (true, None) => return Err(format("this Resize APFS part has no Amethyst executable built from source: Amethyst takes the part for iOS 12 and 13")), + (false, Some(_)) => return Err(format("this Resize APFS part is for Amethyst (iOS 12 and 13), not Dopamine")), + (false, None) => std::fs::read(&executable)?, + }; let has = |name: &str| program.windows(name.len() + 1).any(|w| &w[..name.len()] == name.as_bytes() && w[name.len()] == 0); - let missing: Vec<&str> = INTERFACE.iter().copied().filter(|name| !has(name)).collect(); + let (interface, which) = if amethyst { (AMETHYST_INTERFACE, "Amethyst executable") } else { (INTERFACE, "Dopamine release") }; + let missing: Vec<&str> = interface.iter().copied().filter(|name| !has(name)).collect(); if !missing.is_empty() { - return Err(format(format!("this Dopamine release does not fit this Resize APFS: it has no {}", missing.join(", ")))); + return Err(format(format!("this {which} does not fit this Resize APFS: it has no {}", missing.join(", ")))); } write(&executable, &add_library(&program)?)?; write(&app.join("Frameworks/ResizeAccess.dylib"), &access.library)?; @@ -783,10 +848,17 @@ pub enum Signer { /// the pinned Dopamine, signs it and installs it on the device `udid`. /// `base` is the app's identifier, as [`RESIZE_APFS`]. `say` is told each step. pub fn install(executor: &Executor, access: &Access, signer: &Signer, udid: &str, base: &str, say: &dyn Fn(&str)) -> Result<()> { + install_into(executor, Host::Dopamine, access, signer, udid, base, say) +} + +/// [`install`] into the given host app. Amethyst is signed by xtool only. +pub fn install_into(executor: &Executor, host: Host, access: &Access, signer: &Signer, udid: &str, base: &str, say: &dyn Fn(&str)) -> Result<()> { + if host == Host::Amethyst && !matches!(signer, Signer::Xtool) { + return Err(fail("Xcode builds nothing for iOS 12 and 13: the Amethyst app is signed with xtool")); + } let udid = &apple_form(udid); - say("Fetching Dopamine"); - let receipt = Receipt { url: DOPAMINE.into(), bytes: DOPAMINE_BYTES, sha256: DOPAMINE_SHA256.into(), expanded_bytes: None }; - let ipa = std::fs::read(executor.download(&receipt)?)?; + say(&std::format!("Fetching {}", host.name())); + let ipa = std::fs::read(executor.download(&host.receipt())?)?; let work = executor.cache().join("work").join(format!("resize-sign-{}", std::process::id())); let _ = std::fs::remove_dir_all(&work); std::fs::create_dir_all(&work)?; @@ -1050,6 +1122,72 @@ mod tests { assert_eq!(&after[..64], &fat[..64]); } + /// An IPA of one app named `name`, with `executable` and an Info.plist + /// naming `identifier`. + fn ipa(name: &str, identifier: &str, executable: &[u8]) -> Vec { + let mut info = plist::Dictionary::new(); + info.insert("CFBundleExecutable".into(), name.into()); + info.insert("CFBundleIdentifier".into(), identifier.into()); + info.insert("UIApplicationSceneManifest".into(), plist::Dictionary::new().into()); + let mut bytes = Vec::new(); + Value::Dictionary(info).to_writer_xml(&mut bytes).unwrap(); + let app = format!("Payload/{name}.app/"); + orchard_formats::zip::write(&[ + (format!("{app}{name}"), executable.to_vec(), 0o755), + (format!("{app}Info.plist"), bytes, 0o644), + (format!("{app}basebins.tar"), b"theirs".to_vec(), 0o644), + ]) + .unwrap() + } + + /// `program` with each of `names` after it, as an executable holds them. + fn with_names(names: &[&str]) -> Vec { + let mut m = program(4096); + for name in names { + m.extend(name.as_bytes()); + m.push(0); + } + m + } + + fn part(host: Option>) -> Access { + let mut info = plist::Dictionary::new(); + info.insert("CFBundleDisplayName".into(), "Resize APFS".into()); + let mut bytes = Vec::new(); + Value::Dictionary(info).to_writer_xml(&mut bytes).unwrap(); + Access { info: bytes, library: b"library".to_vec(), resources: vec![("resize-helper.payload".into(), b"helper".to_vec())], host } + } + + #[test] + fn amethysts_executable_built_from_source_takes_the_official_ones_place() { + let dir = std::env::temp_dir().join(format!("orchard-amethyst-test-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + let official = ipa("Amethyst", AMETHYST_IDENTIFIER, &with_names(&AMETHYST_INTERFACE[6..])); + let built = with_names(AMETHYST_INTERFACE); + let prepared = prepare(official.clone(), &part(Some(built)), &dir.join("a")).unwrap(); + let executable = std::fs::read(prepared.app.join("Amethyst")).unwrap(); + assert!(executable.windows(14).any(|w| w == b"_run_jailbreak"), "the built executable is in place"); + assert!(executable.windows(LIBRARY.len()).any(|w| w == LIBRARY.as_bytes()), "and loads the library"); + assert_eq!(std::fs::read(prepared.app.join("basebins.tar")).unwrap(), b"theirs"); + assert_eq!(std::fs::read(prepared.app.join("Frameworks/ResizeAccess.dylib")).unwrap(), b"library"); + // The official executable alone is stripped: refused, by name. + let stripped = prepare(official.clone(), &part(Some(with_names(&AMETHYST_INTERFACE[6..]))), &dir.join("b")).err().unwrap(); + assert!(stripped.to_string().contains("_run_jailbreak"), "{stripped}"); + // Amethyst needs the part with the built executable, and Dopamine refuses it. + assert!(prepare(official, &part(None), &dir.join("c")).is_err()); + let dopamine = ipa("Dopamine", "com.opa334.Dopamine", &with_names(INTERFACE)); + assert!(prepare(dopamine.clone(), &part(Some(with_names(AMETHYST_INTERFACE))), &dir.join("d")).is_err()); + assert!(prepare(dopamine, &part(None), &dir.join("e")).is_ok()); + let _ = std::fs::remove_dir_all(&dir); + } + + #[test] + fn the_amethyst_interface_is_the_one_resize_apfs_checks() { + // resize-apfs scripts/embed.py: AMETHYST_SYMBOLS with an underscore, then AMETHYST_NAMES. + assert_eq!(AMETHYST_INTERFACE.iter().filter(|n| n.starts_with('_')).count(), 6); + assert!(AMETHYST_INTERFACE[6..].iter().all(|n| !n.starts_with('_'))); + } + /// xtool's sign-in played by the shell: it repeats what it is given, /// as a careless tool might. #[test] diff --git a/crates/runtime/src/helper_app.rs b/crates/runtime/src/helper_app.rs index f228a0d0..59ef53d8 100644 --- a/crates/runtime/src/helper_app.rs +++ b/crates/runtime/src/helper_app.rs @@ -71,7 +71,7 @@ fn access(token: &str) -> Result { // Split on spaces on the device: a space in the name goes as %20. let system = orchard_flow::system_name().replace(' ', "%20"); resources.push(("helper-arguments.txt".to_owned(), format!("--token {token}\n--system {system}\n").into_bytes())); - Ok(Access { info: info.ok_or_else(|| missing("no Info.plist"))?, library: library.ok_or_else(|| missing("no library"))?, resources }) + Ok(Access { info: info.ok_or_else(|| missing("no Info.plist"))?, library: library.ok_or_else(|| missing("no library"))?, resources, host: None }) } /// What installing the helper app came to. diff --git a/crates/runtime/src/resize_app.rs b/crates/runtime/src/resize_app.rs index 941d39ff..67c67938 100644 --- a/crates/runtime/src/resize_app.rs +++ b/crates/runtime/src/resize_app.rs @@ -22,6 +22,10 @@ const HELPER: &str = "out/device/resize-helper"; const OLDER_APP: &str = "out/device-ios12/ResizeAPFS.app/"; const OLDER_HELPER: &str = "out/device-ios12/resize-helper"; const ACCESS: &str = "out/device/access/"; +/// The app's part for Amethyst (iOS 12 and 13), with Amethyst's executable +/// built from its source in `host/`. +const AMETHYST_ACCESS: &str = "out/device-ios12/access/"; +const AMETHYST_HOST: &str = "host/Amethyst"; const ENTRY: &str = "out/device/resize-overlay-entry"; /// The helper's launchd job: the one property list in the release's Device /// folder. Its file name is the one the release's entry program loads. @@ -43,16 +47,21 @@ pub struct App { pub older: Option, /// The app's part for the route without DFU, where the release has one. pub access: Option, + /// The same for Amethyst (iOS 12 and 13), where the release has one. + pub amethyst: Option, } -/// What goes into the pinned Dopamine app to make it Resize APFS: the -/// library with the app's interface, its Info.plist to take names, icon and -/// fonts from, and its resources (the helper among them). +/// What goes into the pinned Dopamine or Amethyst app to make it Resize +/// APFS: the library with the app's interface, its Info.plist to take names, +/// icon and fonts from, and its resources (the helper among them). pub struct Access { pub info: Vec, pub library: Vec, /// Path below the app bundle and contents. pub resources: Vec<(String, Vec)>, + /// Amethyst's executable built from its source, in place of the + /// official stripped one; None for Dopamine. + pub host: Option>, } /// The app and its helper as built for iOS 12 to 14, which the checkra1n @@ -126,22 +135,31 @@ pub fn latest(executor: &Executor) -> Result { true => None, false => Some(Older { app: older_app, helper: read(OLDER_HELPER)? }), }; - let mut resources = Vec::new(); - for name in &names { - if let Some(path) = name.strip_prefix(&top).and_then(|n| n.strip_prefix(ACCESS)).and_then(|n| n.strip_prefix("Resources/")).filter(|p| !p.is_empty() && !p.ends_with('/')) { - resources.push((path.to_owned(), read(&format!("{ACCESS}Resources/{path}"))?)); + let has = |name: &str| names.iter().any(|n| n.strip_prefix(&top) == Some(name)); + let mut part = |prefix: &str, host: Option<&str>| -> Result> { + if !has(&format!("{prefix}ResizeAccess.dylib")) || host.is_some_and(|h| !has(&format!("{prefix}{h}"))) { + return Ok(None); } - } - let access = match names.iter().any(|n| n.strip_prefix(&top) == Some(&format!("{ACCESS}ResizeAccess.dylib")[..])) { - true => Some(Access { info: read(&format!("{ACCESS}Info.plist"))?, library: read(&format!("{ACCESS}ResizeAccess.dylib"))?, resources }), - false => None, + let mut resources = Vec::new(); + for name in &names { + if let Some(path) = name.strip_prefix(&top).and_then(|n| n.strip_prefix(prefix)).and_then(|n| n.strip_prefix("Resources/")).filter(|p| !p.is_empty() && !p.ends_with('/')) { + resources.push((path.to_owned(), read(&format!("{prefix}Resources/{path}"))?)); + } + } + let host = match host { + Some(h) => Some(read(&format!("{prefix}{h}"))?), + None => None, + }; + Ok(Some(Access { info: read(&format!("{prefix}Info.plist"))?, library: read(&format!("{prefix}ResizeAccess.dylib"))?, resources, host })) }; + let access = part(ACCESS, None)?; + let amethyst = part(AMETHYST_ACCESS, Some(AMETHYST_HOST))?; let info = files.iter().find(|(p, _, _)| p == "Info.plist").ok_or_else(|| format("the app has no Info.plist"))?; let executable = Value::from_reader(std::io::Cursor::new(&info.1)) .ok() .and_then(|v| v.as_dictionary()?.get("CFBundleExecutable")?.as_string().map(str::to_owned)) .ok_or_else(|| format("the app names no executable"))?; - Ok(App { version, files, executable, helper, entry, job, job_name, older, access }) + Ok(App { version, files, executable, helper, entry, job, job_name, older, access, amethyst }) } impl App { diff --git a/docs/resize.md b/docs/resize.md index 93edbdf4..71332548 100644 --- a/docs/resize.md +++ b/docs/resize.md @@ -32,9 +32,10 @@ and the iOS version it runs, by `routes.toml` in the board data. | `palera1n` | palera1n starts iPadOS from DFU mode with the app in the place of its own loader app | A8 to A11, iOS 15 or later | | `checkra1n` | checkra1n starts iOS and the app is copied in over the cable | A7 to A11, iOS 12 to 14 | | `dopamine` | the app is installed and gets access by itself, without DFU mode | A8 to A13 and later, by iOS version | +| `amethyst` | the same without DFU mode, for iOS 12 and 13 | every device, iOS 12.2 to 13.7 | -`--access ROUTE` names one; `--palera1n`, `--checkra1n` and `--dopamine` -are its short forms. palera1n is taken when none is named. +`--access ROUTE` names one; `--palera1n`, `--checkra1n`, `--dopamine` and +`--amethyst` are its short forms. palera1n is taken when none is named. ### checkra1n @@ -90,6 +91,26 @@ your device. A device that was started through DFU never opens this installed copy by itself: its helper stays idle there. +### amethyst + +The dopamine route for iOS 12.2 to 13.7, the iPhone 5s, iPad Air and iPad +mini 2 and 3 included, from any computer. + +1. Connect the device, unlock it and trust the computer. +2. `orchard resize --amethyst` puts Resize APFS into the pinned official + Amethyst app, signs it with your Apple ID through xtool (Xcode builds + nothing for iOS 12 and 13) and installs it. +3. On the device, trust your Apple ID: Settings > General > Profiles & + Device Management. +4. Open Resize APFS and tap Continue. The first time, the device restarts + once: open Resize APFS again when it is back and tap Continue again. + Then the screen restarts; unlock the device when it comes back. + +Before a shrink, Resize APFS offers to remove the `orig-fs` snapshot that +first restart sets aside: iOS can't shrink while it is there. A free Apple +ID signs the app for 7 days; run the command again when it stops opening. +iOS 12.0 and 12.1 take the checkra1n route. + ## Options - `--wait SECONDS` waits for the device in DFU mode.