Repository navigation
fix(ddi): mount the classic personalized DDI on iOS 17-18 (#185) - #186
Conversation
… on iOS 17-26 On iOS 18 the cryptexd push of the cryptex DDI is reset by the device (device socket io failed), so WDA never starts. Below iOS 27 mount the personalized DDI through mobile_image_mounter instead, read from ICTL_LEGACY_DDI_DIR (Image.dmg, Image.dmg.trustcache, BuildManifest.plist). iOS 27+ keeps the cryptexd path unchanged. Fixes Derrors#185 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors
left a comment
There was a problem hiding this comment.
Thanks for tracking down the root cause of #185 with the debug logs and verifying mobile_image_mounter::mount_personalized on a real iOS 18.7.12 device! The direction is right, and adding "mobile_image_mounter" to Cargo.toml doesn't require a Cargo.lock change since idevice already depends on sha2.
However, there are a few blockers and logic bugs that need to be addressed before this can be merged:
Blockers
-
Version threshold breaks existing iOS 26 devices (
crates/ictl-daemon/src/supervise.rs:legacy_ddi)legacy_ddicurrently checks(1..27).contains(&major), which puts iOS 26 on the legacy path too.- Apple jumped from iOS 18 straight to iOS 26, and iOS 26 devices (verified in this repo on iPhone 12 mini / iOS 26.4.1 and iPad mini 5 / iPadOS 26.6.1–26.7.3) already work out of the box with
cryptexdand the auto-downloadedXcode_iOS_DDI_Crypteximage. - Routing iOS 26 into
mount_legacy_ddi()will break all existing iOS 26 users as soon as their phone reboots. The legacy path should only apply to iOS 17–18 (i.e.major < 26, such as(1..26).contains(&major)).
-
Hardcoded env var name will fail
cargo testand bypassesConfig(crates/ictl-device/src/lib.rs:mount_legacy_ddi)crates/ictl-protocol/src/env.rshas a test (the_code_uses_the_names_from_here) that rejects anyICTL_*/IPHONE_CONTROL_*string literal outsideictl_protocol::env, andthe_documentation_matches_the_listenforces parity withpackaging/env.exampleandwebsite/{,en/}guide/configuration.md. Hardcoding"ICTL_LEGACY_DDI_DIR"inictl-devicewill fail CI.- Reading
std::env::var_osdirectly also doesn't trim/ignore empty values (a bareICTL_LEGACY_DDI_DIR=in~/.config/iphone-control/envbecomesPathBuf::from("")and reads from the current working directory).
-
No automatic download (and Xcode's
Restorefilenames don't match)- A core goal of
iphone-controlis working on Linux and macOS without requiring Xcode. Requiring users to manually extract files and set a new env var leaves Linux / non-Xcode users unable to use iOS 17–18. - Moreover, Xcode's
iOS_DDI/Restoreships hashed filenames (e.g.022-22446-061.dmgas noted in #185), so pointing the env var directly at Xcode's directory fails withNotFoundunless files are manually renamed toImage.dmg/Image.dmg.trustcache. - The upstream repo we already use in
crates/ictl-device/src/ddi.rs(doronz88/DeveloperDiskImage) already hosts the classic personalized image atPersonalizedImages/Xcode_iOS_DDI_Personalizedwith the exact three files (BuildManifest.plist,Image.dmg,Image.dmg.trustcache). Ideallyddi.rsshould auto-download and cache this image (e.g. underddi/personalized/) just like the cryptex image, and reuseICTL_DDI_DIR(or properly register any new env var inictl_protocol::env,Config,packaging/env.example, and the configuration docs).
- A core goal of
Important Logic Fixes
-
Order of checks in
ensure_ddiandmount_legacy_ddi(crates/ictl-daemon/src/supervise.rs,crates/ictl-device/src/lib.rs)ensure_ddicallst.ddi_mounted()(which queriescryptexd.remote) before checkinglegacy_ddi. On older iOS 17 builds wherecryptexd.remoteisn't available or errors, this will fail early and never reach the legacy path. Even when it returnsNone, every reconnect on iOS 18 pays an unnecessarycryptexdround trip plus an extra lockdown connection fordevice.info()(the daemon already has the device'smajor_versioning.infoand can pass it in).- Inside
mount_legacy_ddi, checking the env var beforemounter.lookup_image("Personalized")prevents starting WDA even when the DDI is already mounted on the phone (e.g. via Xcode/devicectl). Check whether it's mounted first, and only locate/download/read the image files if it isn't.
-
lookup_image("Personalized")swallows non-NotFounderrors (crates/ictl-device/src/lib.rs)if mounter.lookup_image("Personalized").await.is_ok()treats any error (includingPasswordProtectedwhen the phone is locked, or USB disconnect) as "not mounted", then proceeds to read disk files and returns a misleading error instead of letting the daemon transition toDeviceState::NeedsUnlock.- Please match explicitly on
Ok(_) => return Ok(false),Err(IdeviceError::NotFound) => {}, and propagate other errors withErr(e) => return Err(e.into()).
-
mount_failed = trueinvalidates the wrong cache (crates/ictl-daemon/src/supervise.rs)device.mount_legacy_ddi().await.map_err(|e| (e, true))?marks every error (including missing env var / missing files) asmount_failed = true. After 3 retries,ddi_failed()deletesself.cfg.ddi_cache()(the cryptex cache) and logs a confusing message about clearing cache and re-downloading.- Only set
mount_failed = truewhen using the daemon-managed cache and the actual mount step fails (and invalidate only the corresponding cache).
-
Minor polish & repo conventions
- Missing image files currently surface as a raw
No such file or directoryerror without naming which file or directory is missing; reusing arequire_complete-style helper inddi.rswould make errors much clearer. - Drop the
LockdownClientbefore openingImageMounter, and note that the comment onmount_legacy_ddireverses the upstreammobile_image_mounter.rsnote. - Please add unit tests covering
17,18,26,27, and0for the version routing (and cache/validation logic), and add an entry todocs/dev/regression-cases.mdperCONTRIBUTING.md.
- Missing image files currently surface as a raw
…e, review fixes - route only iOS 17-18 (1..26) to mobile_image_mounter; 26+, 0 stay on cryptexd - download PersonalizedImages/Xcode_iOS_DDI_Personalized into ddi/personalized/ (sibling of ICTL_DDI_URL), or take it from ICTL_DDI_DIR; no new env var - legacy path skips cryptexd and uses the major from g.info; lookup_image first, NotFound explicit, other errors propagated (NeedsUnlock keeps working) - mount_failed and invalidation only for the cache in use; require_complete names missing files; lockdown dropped before ImageMounter - tests for 0/17/18/26/27 and the personalized cache; regression case Derrors#169 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the thorough review. Pushed 402a7fa addressing all points:
Tested routing with unit tests ( 🤖 Generated with Claude Code |
Derrors
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround! 402a7fa cleanly addresses the core architecture points from the first round (narrowing the threshold to (1..26), auto-downloading Xcode_iOS_DDI_Personalized into ddi/personalized/, skipping cryptexd on the legacy path, explicit NotFound handling, and per-cache invalidation).
There are still a few CI/merge blockers and logic issues to resolve before merging:
Blockers (will fail CI / cannot merge)
-
apps/iphone-control/src/debug.rswasn't updated for the newensure_cachesignatureapps/iphone-control/src/debug.rs:232still callsictl_device::ddi::ensure_cache(&restore_dir, &url).await?(missing the newfilesargument).- CI runs both
clippyandtestwith--all-features(which enablesdebug-cmds), so this fails to compile. - Please update
debug.rs(ideally supporting the legacy personalized image indebug ddias well, or at minimum passing the file list) and verify locally with:cargo clippy --workspace --all-targets --all-features --locked -- -D warnings cargo test --workspace --all-features --locked
-
rustfmt --checkfails incrates/ictl-daemon/src/supervise.rs- With the repo's
rustfmt.toml(max_width = 120,use_small_heuristics = "Max"), theNone if legacy =>arm inensure_ddishould be a single line:- None if legacy => { - ictl_device::ddi::ensure_cache(cache, &ictl_device::ddi::personalized_url(url), files).await - } + None if legacy => ictl_device::ddi::ensure_cache(cache, &ictl_device::ddi::personalized_url(url), files).await,
- Please run per-crate
cargo fmt -p <crate> -- --check(don't runcargo fmt --all, as that reformatsvendor/).
- With the repo's
-
Merge conflict with
mainindocs/dev/regression-cases.mdmainnow has cases#169and#170(from #184), so this PR is currentlyCONFLICTING.- Please rebase onto the latest
mainand renumber the new regression case to#171(and update the PR title fromiOS 17-26toiOS 17-18).
Important Logic Fixes
-
Map
IdeviceError::DeviceLockedtoDeviceError::PasswordProtected(crates/ictl-device/src/lib.rs)- Lockdown returns
"PasswordProtected"(IdeviceError::PasswordProtected), whereasmobile_image_mounterreturns"DeviceLocked"(IdeviceError::DeviceLocked) when the phone is locked. - Currently
From<IdeviceError> for DeviceErroronly matchesIdeviceError::PasswordProtected. If the phone locks before/duringlegacy_ddi_mounted()ormount_legacy_ddi(),DeviceLockedfalls through toDeviceError::Ideviceinstead ofStartOutcome::NeedsUnlock, and counts towardddi_failures(potentially clearing theddi/personalized/cache after 3 locked attempts). - Please match
IdeviceError::PasswordProtected | IdeviceError::DeviceLocked => Self::PasswordProtected.
- Lockdown returns
-
Start a lockdown session before reading
UniqueChipIDinmount_legacy_ddi(crates/ictl-device/src/lib.rs)- Calling
lockdown.get_value(Some("UniqueChipID"), None)withoutstart_sessioncan be rejected withGetProhibiteddepending on iOS version/state. Upstreamidevice'stools/src/mounter.rsandffi/examples/mount_personalized.c(as well ascrates/ictl-device/src/coredevice.rs:95-99in this repo) start a paired lockdown session before querying protected values. - Please call
lockdown.start_session(&self.provider.get_pairing_file().await?).await?before readingUniqueChipID(or fall back tostart_sessionon error).
- Calling
-
Refresh the tunnel's RSD handshake after freshly mounting the DDI (
crates/ictl-daemon/src/supervise.rs:619-630)- In
spawn_start,device.open_tunnel()runs beforeensure_ddi, andprepare_detached(&mut t, ...)then reuses that same tunnelt. - On the legacy path,
ensure_ddidoesn't even uset, leaving the tunnel idle across potentially long DDI downloads/uploads. More importantly, whenensure_ddijust mounted the DDI (Ok(Some(_))),t.handshakestill holds the pre-mount RSD service snapshot (beforecom.apple.instruments.dtservicehubis advertised), so the firstprepare_detachedafter a reboot can fail and wait for a backoff retry. - If
ensure_ddireturnsOk(Some(_)), closingtand reopeningdevice.open_tunnel().awaitrefreshes the RSD service list so WDA starts on the first attempt.
- In
Minor / Verification
personalized_urledge case (crates/ictl-device/src/ddi.rs): for a bare origin like"https://mirror.example",rsplit_once('/')splits at"https:/"and produces"https://Xcode_iOS_DDI_Personalized". Guarding withSome((parent, _)) if !parent.ends_with(":/")avoids mangling the scheme.- On-device verification: once you have access to the iPhone XS (iOS 18.7.12) again, please re-test the full auto-download → mount → WDA start flow on this revision and update the verification note in regression case
#171.
# Conflicts: # docs/dev/regression-cases.md
…resh tunnel - debug ddi: new ensure_cache signature, legacy personalized image on iOS 17-18 - legacy/files_for moved to ictl_device::ddi (shared by daemon and debug) - IdeviceError::DeviceLocked maps to PasswordProtected (NeedsUnlock, not a mount failure) - start a paired lockdown session before reading UniqueChipID - reopen the tunnel after a fresh mount so the RSD service list includes the image's services - personalized_url leaves a bare origin alone; rustfmt - regression case renumbered to Derrors#171 after merging main Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks again. Pushed 3cac1ca (on top of a merge of current
Locally: 🤖 Generated with Claude Code |
- Sync regression case Derrors#171 with the renamed test in ictl-device::ddi so tests/check_regression_cases.py passes. - Check the classic personalized image in debug e2e on iOS 17-18 instead of querying cryptexd. Co-Authored-By: Claude Code <noreply@anthropic.com>
Fixes #185.
Problem: on an iPhone XS with iOS 18.7.12, WDA never starts. The cryptexd push of the cryptex DDI gets reset by the device ("Device reset finished file transfer stream", then
device socket io failed), even though TSS succeeds.Change: for devices below iOS 27,
ensure_ddinow mounts the classic personalized DDI throughmobile_image_mounter:LookupImage("Personalized")already returns a signature;mount_personalizedwith the ECID read from lockdown.The image, its trustcache and
BuildManifest.plistare read fromICTL_LEGACY_DDI_DIR(asImage.dmg,Image.dmg.trustcache,BuildManifest.plist). Xcode'siOS_DDI/Restorefiles work. iOS 27+ keeps the cryptexd path unchanged.Tested:
Not done: no automatic download of the legacy image when the env var is unset; the daemon returns a clear error instead.
🤖 Generated with Claude Code