diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd6661..f2b0592 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ is on main, the release is published with that section as its notes (AGENTS.md, ## [Unreleased] +### Command line + +- The iPhone 5's GPU firmware and its graphics event template now build from + Apple's files, as the iPad mini 1's and iPad 2's do: the firmware build for + the iPhone 5 used to stop without them (brkosebay). + ## [0.3.17] - 2026-12-05 ### Installer and launcher diff --git a/crates/boards/src/catalog.rs b/crates/boards/src/catalog.rs index 3150ac8..fd83160 100644 --- a/crates/boards/src/catalog.rs +++ b/crates/boards/src/catalog.rs @@ -145,6 +145,12 @@ pub enum Location { Member(String), /// A file in the system volume, relative to its root. System(String), + /// Hash-pinned region of a file in the IPSW system volume. + SystemRange { + path: String, + offset: u64, + bytes: u64, + }, /// The decoded kernel (the Mach-O inside the IM4P), which is what a /// recipe's hash for it covers. `board` names another board's kernel by /// its device class, such as `n102ap`; `restore` another restore image, @@ -168,6 +174,11 @@ impl std::fmt::Display for Location { write!(f, "member {member} in {} {}", restore.version, restore.build) } Location::System(p) => write!(f, "system file {p}"), + Location::SystemRange { + path, + offset, + bytes, + } => write!(f, "system file {path}, {bytes} bytes at {offset}"), Location::Kernelcache { board, restore } => { write!(f, "kernelcache")?; if let Some(board) = board { @@ -875,6 +886,7 @@ struct InputFile { struct InputLocation { zip: Option, rootfs: Option, + range: Option<[u64; 2]>, kernelcache: Option, restore: Option, } @@ -900,6 +912,7 @@ fn convert_input((name, input): (String, InputFile)) -> Result<(String, Input)> let InputLocation { zip, rootfs, + range, kernelcache, restore, } = input.ipsw; @@ -921,12 +934,27 @@ fn convert_input((name, input): (String, InputFile)) -> Result<(String, Input)> ) .context(format!("input {name}"))); } + if range.is_some() && (rootfs.is_none() || input.sha256.is_none()) { + return Err( + Error::new(Code::Format, "a file range requires rootfs and sha256").context(&name), + ); + } let location = match (zip, rootfs, kernelcache) { (Some(member), None, None) => match restore { Some(restore) => Location::MemberOf { member, restore }, None => Location::Member(member), }, - (None, Some(path), None) => Location::System(path), + (None, Some(path), None) => match range { + Some([offset, bytes]) if bytes > 0 && offset.checked_add(bytes).is_some() => { + Location::SystemRange { + path, + offset, + bytes, + } + } + Some(_) => return Err(Error::new(Code::Format, "invalid file range").context(&name)), + None => Location::System(path), + }, (None, None, Some(board)) => Location::Kernelcache { board, restore }, _ => { return Err(Error::new(Code::Format, "needs exactly one location") @@ -1190,6 +1218,39 @@ mod tests { } } + #[test] + fn reads_a_pinned_range_of_a_system_file() { + let recipe = |input: &str| { + peripheral_recipe(&format!( + r#"{{"schema": 2, {IPSW}, "inputs": {{"pds": {input}}}, "outputs": []}}"# + )) + }; + let read = + recipe(r#"{"ipsw": {"rootfs": "System/cache", "range": [4096, 168]}, "sha256": "ee"}"#) + .unwrap(); + assert_eq!( + read.inputs["pds"].location, + Location::SystemRange { + path: "System/cache".into(), + offset: 4096, + bytes: 168 + } + ); + assert_eq!( + read.inputs["pds"].location.to_string(), + "system file System/cache, 168 bytes at 4096" + ); + // A range is always pinned, never empty and never past the end of u64. + for refused in [ + r#"{"ipsw": {"rootfs": "System/cache", "range": [0, 168]}}"#, + r#"{"ipsw": {"rootfs": "System/cache", "range": [0, 0]}, "sha256": "ee"}"#, + r#"{"ipsw": {"rootfs": "System/cache", "range": [18446744073709551615, 2]}, "sha256": "ee"}"#, + r#"{"ipsw": {"zip": "Firmware/x.im4p", "range": [0, 1]}, "sha256": "ee"}"#, + ] { + assert_eq!(recipe(refused).unwrap_err().code, Code::Format, "{refused}"); + } + } + #[test] fn reads_a_kernelcache_from_another_restore_image() { let restore = r#""restore": {"version": "12.4", "build": "16G77", "url": "https://example.com/y.ipsw", "bytes": 200, "sha256": "11"}"#; diff --git a/crates/boards/src/data/firmware.rs b/crates/boards/src/data/firmware.rs index 4377df0..1037a22 100644 --- a/crates/boards/src/data/firmware.rs +++ b/crates/boards/src/data/firmware.rs @@ -199,7 +199,7 @@ impl Firmware { Location::Member(member) | Location::MemberOf { member, .. } => { self.member(member, limit)? } - Location::System(path) => { + Location::System(path) | Location::SystemRange { path, .. } => { let class = self .manifest .identity_for(board.chip, board.board)? @@ -211,7 +211,24 @@ impl Firmware { volume: None, path: &format!("/{path}"), }; - self.read(&at, limit)? + if let Location::SystemRange { offset, bytes, .. } = &input.location { + if *bytes > limit { + return Err(Error::new(Code::TooLarge, "file range exceeds size limit")); + } + // Bound the source as well as the returned bytes for remote disk images. + let file = self.read(&at, 512 << 20)?; + let start = usize::try_from(*offset).ok(); + let end = offset + .checked_add(*bytes) + .and_then(|n| usize::try_from(n).ok()); + start + .zip(end) + .and_then(|(a, b)| file.get(a..b)) + .ok_or_else(|| Error::new(Code::Format, "range outside system file"))? + .to_vec() + } else { + self.read(&at, limit)? + } } Location::Kernelcache { board: named, .. } => { // Another board's kernel by its device class; it need not be diff --git a/crates/formats/src/sgx.rs b/crates/formats/src/sgx.rs index a716fc3..a381b7c 100644 --- a/crates/formats/src/sgx.rs +++ b/crates/formats/src/sgx.rs @@ -3,6 +3,10 @@ //! sections of the IMGSGX543 kext in a 32-bit prelinked kernel, behind a //! header with their sizes, their addresses and the kernel's build. //! +//! The A5's kext (S5L8940X/8942X) names its driver class `SGXDriver543`, +//! the A6's (S5L8950X, an SGX543MP3) `SGXDriver543RC2`: another build of +//! the kext with a microkernel of its own, taken the same way. +//! //! The driver's offsets into these sections hold for one kernel build only, //! so the recipe pins the whole container's hash, addresses and build //! included. @@ -10,6 +14,9 @@ use crate::{Error, Result}; use std::collections::BTreeMap; const MAGIC_32: &[u8] = b"\xce\xfa\xed\xfe"; +/// The GPU kext's driver class, as its strings name it: the A5's, then +/// the A6's. +const DRIVER_CLASSES: [&[u8]; 2] = [b"SGXDriver543\0", b"SGXDriver543RC2\0"]; const LC_SEGMENT: u32 = 1; /// A segment of a 32-bit Mach-O: where it is in memory and in the file, and @@ -117,7 +124,8 @@ pub fn extract(kernel: &[u8], build: &str) -> Result> { let kext = segments(kernel, base)?; let strings = kext.get("__TEXT").and_then(|text| text.sections.get("__cstring").copied()); if let Some(strings) = strings { - if contains(section(strings)?, b"SGXDriver543\0") { + let strings = section(strings)?; + if DRIVER_CLASSES.iter().any(|class| contains(strings, class)) { matches.push(kext); } }