Skip to content

fix(ddi): mount the classic personalized DDI on iOS 17-18 (#185) - #186

Merged
Derrors merged 5 commits into
Derrors:mainfrom
k69pk85m45-cmyk:fix/ios18-ddi
Nov 25, 2026
Merged

Derrors merged 5 commits into
Derrors:mainfrom
k69pk85m45-cmyk:fix/ios18-ddi

Conversation

@k69pk85m45-cmyk

Copy link
Copy Markdown
Contributor

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_ddi now mounts the classic personalized DDI through mobile_image_mounter:

  • it skips the mount when LookupImage("Personalized") already returns a signature;
  • otherwise it calls mount_personalized with the ECID read from lockdown.

The image, its trustcache and BuildManifest.plist are read from ICTL_LEGACY_DDI_DIR (as Image.dmg, Image.dmg.trustcache, BuildManifest.plist). Xcode's iOS_DDI/Restore files work. iOS 27+ keeps the cryptexd path unchanged.

Tested:

  • iPhone XS on iOS 18.7.12: the DDI step passes, WDA launches in the background, and the device reaches Ready; home button and screenshot work.
  • iPhone SE (2nd gen) on iOS 27.2.1: unchanged, native control Ready.

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

… 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 Derrors left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Version threshold breaks existing iOS 26 devices (crates/ictl-daemon/src/supervise.rs: legacy_ddi)

    • legacy_ddi currently 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 cryptexd and the auto-downloaded Xcode_iOS_DDI_Cryptex image.
    • 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)).
  2. Hardcoded env var name will fail cargo test and bypasses Config (crates/ictl-device/src/lib.rs: mount_legacy_ddi)

    • crates/ictl-protocol/src/env.rs has a test (the_code_uses_the_names_from_here) that rejects any ICTL_* / IPHONE_CONTROL_* string literal outside ictl_protocol::env, and the_documentation_matches_the_list enforces parity with packaging/env.example and website/{,en/}guide/configuration.md. Hardcoding "ICTL_LEGACY_DDI_DIR" in ictl-device will fail CI.
    • Reading std::env::var_os directly also doesn't trim/ignore empty values (a bare ICTL_LEGACY_DDI_DIR= in ~/.config/iphone-control/env becomes PathBuf::from("") and reads from the current working directory).
  3. No automatic download (and Xcode's Restore filenames don't match)

    • A core goal of iphone-control is 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/Restore ships hashed filenames (e.g. 022-22446-061.dmg as noted in #185), so pointing the env var directly at Xcode's directory fails with NotFound unless files are manually renamed to Image.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 at PersonalizedImages/Xcode_iOS_DDI_Personalized with the exact three files (BuildManifest.plist, Image.dmg, Image.dmg.trustcache). Ideally ddi.rs should auto-download and cache this image (e.g. under ddi/personalized/) just like the cryptex image, and reuse ICTL_DDI_DIR (or properly register any new env var in ictl_protocol::env, Config, packaging/env.example, and the configuration docs).

Important Logic Fixes

  1. Order of checks in ensure_ddi and mount_legacy_ddi (crates/ictl-daemon/src/supervise.rs, crates/ictl-device/src/lib.rs)

    • ensure_ddi calls t.ddi_mounted() (which queries cryptexd.remote) before checking legacy_ddi. On older iOS 17 builds where cryptexd.remote isn't available or errors, this will fail early and never reach the legacy path. Even when it returns None, every reconnect on iOS 18 pays an unnecessary cryptexd round trip plus an extra lockdown connection for device.info() (the daemon already has the device's major_version in g.info and can pass it in).
    • Inside mount_legacy_ddi, checking the env var before mounter.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.
  2. lookup_image("Personalized") swallows non-NotFound errors (crates/ictl-device/src/lib.rs)

    • if mounter.lookup_image("Personalized").await.is_ok() treats any error (including PasswordProtected when 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 to DeviceState::NeedsUnlock.
    • Please match explicitly on Ok(_) => return Ok(false), Err(IdeviceError::NotFound) => {}, and propagate other errors with Err(e) => return Err(e.into()).
  3. mount_failed = true invalidates 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) as mount_failed = true. After 3 retries, ddi_failed() deletes self.cfg.ddi_cache() (the cryptex cache) and logs a confusing message about clearing cache and re-downloading.
    • Only set mount_failed = true when using the daemon-managed cache and the actual mount step fails (and invalidate only the corresponding cache).
  4. Minor polish & repo conventions

    • Missing image files currently surface as a raw No such file or directory error without naming which file or directory is missing; reusing a require_complete-style helper in ddi.rs would make errors much clearer.
    • Drop the LockdownClient before opening ImageMounter, and note that the comment on mount_legacy_ddi reverses the upstream mobile_image_mounter.rs note.
    • Please add unit tests covering 17, 18, 26, 27, and 0 for the version routing (and cache/validation logic), and add an entry to docs/dev/regression-cases.md per CONTRIBUTING.md.

…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>
@k69pk85m45-cmyk

Copy link
Copy Markdown
Contributor Author

Thanks for the thorough review. Pushed 402a7fa addressing all points:

  1. Legacy path only for iOS 17–18: (1..26); 26, 27 and 0 stay on cryptexd. Unit test covers 0/17/18/26/27.
  2. No new env var: the classic image is auto-downloaded from PersonalizedImages/Xcode_iOS_DDI_Personalized (sibling of ICTL_DDI_URL) into ddi/personalized/, or taken from ICTL_DDI_DIR. ddi.rs functions now take the file list; docs and packaging/env.example updated.
  3. Legacy path never calls cryptexd; the major comes from g.info. lookup_image runs first with explicit NotFound, other errors propagate (so NeedsUnlock still works). Files are located/downloaded only when not mounted.
  4. mount_failed only for the mount step; invalidation clears only the cache of the image in use. require_complete names missing files. Lockdown is dropped before ImageMounter; comment fixed.
  5. Regression case release: 0.2.10 #169 added.

Tested routing with unit tests (cargo test for ictl-device, ictl-daemon, ictl-protocol passes); on-device retest pending (the iPhone XS isn't available on this machine right now).

🤖 Generated with Claude Code

@Derrors Derrors left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

  1. apps/iphone-control/src/debug.rs wasn't updated for the new ensure_cache signature

    • apps/iphone-control/src/debug.rs:232 still calls ictl_device::ddi::ensure_cache(&restore_dir, &url).await? (missing the new files argument).
    • CI runs both clippy and test with --all-features (which enables debug-cmds), so this fails to compile.
    • Please update debug.rs (ideally supporting the legacy personalized image in debug ddi as 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
  2. rustfmt --check fails in crates/ictl-daemon/src/supervise.rs

    • With the repo's rustfmt.toml (max_width = 120, use_small_heuristics = "Max"), the None if legacy => arm in ensure_ddi should 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 run cargo fmt --all, as that reformats vendor/).
  3. Merge conflict with main in docs/dev/regression-cases.md

    • main now has cases #169 and #170 (from #184), so this PR is currently CONFLICTING.
    • Please rebase onto the latest main and renumber the new regression case to #171 (and update the PR title from iOS 17-26 to iOS 17-18).

Important Logic Fixes

  1. Map IdeviceError::DeviceLocked to DeviceError::PasswordProtected (crates/ictl-device/src/lib.rs)

    • Lockdown returns "PasswordProtected" (IdeviceError::PasswordProtected), whereas mobile_image_mounter returns "DeviceLocked" (IdeviceError::DeviceLocked) when the phone is locked.
    • Currently From<IdeviceError> for DeviceError only matches IdeviceError::PasswordProtected. If the phone locks before/during legacy_ddi_mounted() or mount_legacy_ddi(), DeviceLocked falls through to DeviceError::Idevice instead of StartOutcome::NeedsUnlock, and counts toward ddi_failures (potentially clearing the ddi/personalized/ cache after 3 locked attempts).
    • Please match IdeviceError::PasswordProtected | IdeviceError::DeviceLocked => Self::PasswordProtected.
  2. Start a lockdown session before reading UniqueChipID in mount_legacy_ddi (crates/ictl-device/src/lib.rs)

    • Calling lockdown.get_value(Some("UniqueChipID"), None) without start_session can be rejected with GetProhibited depending on iOS version/state. Upstream idevice's tools/src/mounter.rs and ffi/examples/mount_personalized.c (as well as crates/ictl-device/src/coredevice.rs:95-99 in this repo) start a paired lockdown session before querying protected values.
    • Please call lockdown.start_session(&self.provider.get_pairing_file().await?).await? before reading UniqueChipID (or fall back to start_session on error).
  3. 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 before ensure_ddi, and prepare_detached(&mut t, ...) then reuses that same tunnel t.
    • On the legacy path, ensure_ddi doesn't even use t, leaving the tunnel idle across potentially long DDI downloads/uploads. More importantly, when ensure_ddi just mounted the DDI (Ok(Some(_))), t.handshake still holds the pre-mount RSD service snapshot (before com.apple.instruments.dtservicehub is advertised), so the first prepare_detached after a reboot can fail and wait for a backoff retry.
    • If ensure_ddi returns Ok(Some(_)), closing t and reopening device.open_tunnel().await refreshes the RSD service list so WDA starts on the first attempt.

Minor / Verification

  1. personalized_url edge 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 with Some((parent, _)) if !parent.ends_with(":/") avoids mangling the scheme.
  2. 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.

k69pk85m45-cmyk and others added 2 commits November 25, 2026 01:37
# 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>
@k69pk85m45-cmyk k69pk85m45-cmyk changed the title fix(ddi): mount the classic personalized DDI on iOS 17-26 (#185) fix(ddi): mount the classic personalized DDI on iOS 17-18 (#185) Nov 25, 2026
@k69pk85m45-cmyk

Copy link
Copy Markdown
Contributor Author

Thanks again. Pushed 3cac1ca (on top of a merge of current main; I merged instead of rebasing to avoid force-pushing, happy to squash on merge):

  1. debug ddi uses the new ensure_cache signature and mounts the classic personalized image on iOS 17–18 (<restore_dir>/personalized). legacy / files_for now live in ictl_device::ddi, shared by the daemon and debug.
  2. rustfmt: cargo fmt -p ictl-device|ictl-daemon|iphone-control -- --check clean.
  3. Conflict resolved, regression case renumbered to login always 403 from GSA: get_header() lowercases X-MMe-Client-Info value #171, title now says iOS 17-18.
  4. IdeviceError::DeviceLocked maps to PasswordProtected.
  5. Paired lockdown session started before reading UniqueChipID.
  6. After a fresh mount the tunnel is closed and reopened before prepare_detached.
  7. personalized_url leaves a bare origin alone (test added).
  8. On-device retest still pending: the iPhone XS isn't attached to this machine right now; I'll update login always 403 from GSA: get_header() lowercases X-MMe-Client-Info value #171 once it's re-tested.

Locally: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings and cargo test --workspace --all-features --locked both pass.

🤖 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>
@Derrors
Derrors self-requested a review November 25, 2026 01:09
@Derrors
Derrors merged commit fe9971b into Derrors:main Nov 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WDA never starts on iOS 18.7.12 (iPhone XS): Developer disk image: idevice: device socket io failed

2 participants