danielpaulus / go-ios

This is an operating system independent implementation of iOS device features. You can run UI tests, launch or kill apps, install apps etc. with it.
MIT License
964 stars 184 forks source link

Erase command fails with error 'CommandFormatError' #489

Open tudorcraciun opened 1 month ago

tudorcraciun commented 1 month ago

Hello!

On iPhone 5C (iOS 10.3.3, unconfigured, activated), I have executed the command ios erase --force -v. It did not reset the device, but failed with the error {"err":"failed command: map[Status:CommandFormatError]","level":"fatal","msg":"failed erasing","time":"2024-10-01T06:53:16Z"}. Executed using commit 4120842602ce23fb736cfa5f6bbbb974d91e76fb (latest at the time).

Full logs:

{"level":"info","msg":"Set Debug mode","time":"2024-10-01T06:53:16Z"} {"level":"debug","msg":"map[--address:\u003cnil\u003e --all:false --apps:false --arg:[] --basedir:\u003cnil\u003e --binary:false --bundle-id:\u003cnil\u003e --bundleid:\u003cnil\u003e --certfile:\u003cnil\u003e --details:false --dstPath:\u003cnil\u003e --enable-post-restart:false --env:[] --filesharing:false --font:\u003cnil\u003e --force:true --gpxfilepath:\u003cnil\u003e --help:false --iface:\u003cnil\u003e --lang:false --lat:\u003cnil\u003e --list:false --locale:false --log-output:\u003cnil\u003e --lon:\u003cnil\u003e --mode:\u003cnil\u003e --nojson:false --orgname:\u003cnil\u003e --output:\u003cnil\u003e --p12file:\u003cnil\u003e --pair-record-path:\u003cnil\u003e --password:\u003cnil\u003e --path:\u003cnil\u003e --pid:\u003cnil\u003e --plist:false --port:\u003cnil\u003e --pretty:false --process:\u003cnil\u003e --r:false --rsd-port:\u003cnil\u003e --setlang:\u003cnil\u003e --setlocale:\u003cnil\u003e --skip:[] --skip-all:false --srcPath:\u003cnil\u003e --stop-at-entry:false --stream:false --system:false --test-runner-bundle-id:\u003cnil\u003e --test-to-run:[] --test-to-skip:[] --testrunnerbundleid:\u003cnil\u003e --trace:false --tunnel-info-port:\u003cnil\u003e --udid:\u003cnil\u003e --verbose:true --version:false --wait:false --xctest-config:\u003cnil\u003e --xctestconfig:\u003cnil\u003e 12h:false 24h:false \u003capp_path\u003e:\u003cnil\u003e \u003cbundleID\u003e:\u003cnil\u003e \u003ccwd\u003e:\u003cnil\u003e \u003chost\u003e:\u003cnil\u003e \u003chostPort\u003e:\u003cnil\u003e \u003ckey\u003e:[] \u003cpass\u003e:\u003cnil\u003e \u003cpattern\u003e:\u003cnil\u003e \u003cport\u003e:\u003cnil\u003e \u003cprofileFile\u003e:\u003cnil\u003e \u003cprofileId\u003e:\u003cnil\u003e \u003cprofileName\u003e:\u003cnil\u003e \u003cprofileTypeId\u003e:\u003cnil\u003e \u003csrcpattern\u003e:\u003cnil\u003e \u003ctarget\u003e:\u003cnil\u003e \u003ctargetPort\u003e:\u003cnil\u003e \u003cuser\u003e:\u003cnil\u003e activate:false add:false apps:false assistivetouch:false auto:false ax:false batterycheck:false cp:false crash:false create-cert:false date:false debug:false devicename:false devicestate:false devmode:false diagnostics:false disable:false diskspace:false display:false dproxy:false enable:false erase:true forward:false fsync:false get:false httpproxy:false image:false info:false install:false instruments:false ip:false kill:false lang:false launch:false list:false listen:false lockdown:false ls:false mkdir:false mobilegestalt:false mount:false notifications:false pair:false pcap:false prepare:false printskip:false profile:false ps:false pull:false push:false readpair:false reboot:false remove:false resetlocation:false rm:false runtest:false runwda:false screenshot:false setlocation:false setlocationgpx:false start:false syslog:false timeformat:false toggle:false tree:false tunnel:false uninstall:false version:false voiceover:false zoomtouch:false]","time":"2024-10-01T06:53:16Z"} {"level":"debug","msg":"Looking for device ''","time":"2024-10-01T06:53:16Z"} {"level":"info","msg":"no udid specified using first device in list","time":"2024-10-01T06:53:16Z","udid":"<removed_udid_from_logs>"} {"level":"warning","msg":"failed to get tunnel info","time":"2024-10-01T06:53:16Z","udid":"<removed_udid_from_logs>"} {"EnableServiceSSL":false,"Port":49167,"Request":"StartService","Service":"com.apple.mobile.MCInstall","level":"debug","msg":"Service started on device","time":"2024-10-01T06:53:16Z"} {"level":"info","msg":"start erasing","time":"2024-10-01T06:53:16Z"} {"level":"debug","msg":"send flush request","time":"2024-10-01T06:53:16Z"} {"level":"debug","msg":"get cloud config","time":"2024-10-01T06:53:16Z"} {"level":"debug","msg":"config: map[Status:Acknowledged]","time":"2024-10-01T06:53:16Z"} {"level":"debug","msg":"send erase request","time":"2024-10-01T06:53:16Z"} {"err":"failed command: map[Status:CommandFormatError]","level":"fatal","msg":"failed erasing","time":"2024-10-01T06:53:16Z"}

My goal is to modify the PreserveDataPlan flag to 0 to also erase any eUICC data.

Do you have any idea what might be wrong? Thank you!

tudorcraciun commented 1 month ago

Hello,

It seems that the command fails on iPhone 5 (iOS 10.3.3) and below, but works on iPhone 6 (iOS 12.5.7) and above.

I believe that on older iOS versions the EraseDevice command has to be sent as a MessageName instead of a RequestType (similar to https://github.com/libimobiledevice/libimobiledevice/pull/1029/files).