libimobiledevice / libirecovery

Library and utility to talk to iBoot/iBSS via USB on Mac OS X, Windows, and Linux
https://libimobiledevice.org
GNU Lesser General Public License v2.1
566 stars 208 forks source link

properly handle device enumeration on windows #76

Closed DanyL closed 3 years ago

DanyL commented 3 years ago

This fixes 2 issues preventing libirecovery from properly detecting devices on windows:

  1. In _irecv_event_handler, the loop where devinfo->alive = 0; is being set was mastaknly put under the inner loop, rather than the outer one. This caused libirecovery to constantly remove devices when not needed.
  2. The way DevicePath is being parsed assumes the last entry would always be the correct one, however, in some odd cases (i.e using VM, hubs, etc) this would fail. The change I made here makes it enumerate the entries until it finds the correct one.
nikias commented 3 years ago

@DanyL merged with slightly different commit message.

airwolf2026 commented 3 years ago

This fix will read a fake dfu device when device's really state is recovery , in latest win10

DanyL commented 3 years ago

@airwolf2026 What do you mean by "a fake dfu device"? does it have an ECID? If so, is it the correct one or just random data? What APIs are you trying to use? Please print the values of DevicePath and DfuPath and attach them here so we could try to debug it.

Also, given that before this commit device detection was completely broken on windows, I doubt its the root cause of the problem you are experiencing, its more likely to be an older, unrelated bug surfacing now when this works correctly.

Edit: just for the record - it has been tested more than a dozen times, repeatedly switching between recovery and dfu modes, both on bare metal and VM machines with fully updated (as of ~10 days ago) windows 10 build and latest iTunes drivers as well as through USB hubs.

airwolf2026 commented 3 years ago

@airwolf2026 What do you mean by "a fake dfu device"? does it have an ECID? If so, is it the correct one or just random data? What APIs are you trying to use? Please print the values of DevicePath and DfuPath and attach them here so we could try to debug it.

Also, given that before this commit device detection was completely broken on windows, I doubt its the root cause of the problem you are experiencing, its more likely to be an older, unrelated bug surfacing now when this works correctly.

Edit: just for the record - it has been tested more than a dozen times, repeatedly switching between recovery and dfu modes, both on bare metal and VM machines with fully updated (as of ~10 days ago) windows 10 build and latest iTunes drivers as well as through USB hubs.

I just want to restore a iPhone 12 pro max, but it failed in the last some step with the latest code .

Ok, i'll attach some logs ,and if I can reproduce this problem.