doronz88 / pymobiledevice3

Pure python3 implementation for working with iDevices (iPhone, etc...).
https://discord.gg/52mZGC3JXJ
GNU General Public License v3.0
1.36k stars 190 forks source link

Pymobiledevice3 usbmux list not work with more than 30 connected iphone devices #1208

Open yourchanges opened 2 days ago

yourchanges commented 2 days ago

Test environment

Describe the bug When running on a pc connected more than 30 iphone devices, I can't get all device list via 'pymobiledevice3 usbmux list',

If I disconnected the some iphone devices, make sure the number lower than 30, for example ,29 28 ,26 ,it works well. I can get correct device list.

To Reproduce just run : pymobiledevice3 usbmux list

Expected behavior display all device list

Logs

F:\>pymobiledevice3 usbmux list
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Python311\Scripts\pymobiledevice3.exe\__main__.py", line 7, in <module>
  File "C:\Python311\Lib\site-packages\pymobiledevice3\__main__.py", line 110, in main
    cli()
  File "C:\Python311\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\pymobiledevice3\cli\usbmux.py", line 55, in usbmux_list
    for device in usbmux.list_devices(usbmux_address=usbmux_address):
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\site-packages\pymobiledevice3\usbmux.py", line 411, in list_devices
    mux.get_device_list(0.1)
  File "C:\Python311\Lib\site-packages\pymobiledevice3\usbmux.py", line 357, in get_device_list
    for response in self._receive(self._tag - 1)['DeviceList']:
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'DeviceList'

F:\>pymobiledevice3 version
4.13.19
doronz88 commented 2 days ago

Could you print the response you are getting?

yourchanges commented 1 day ago

modify the code in File "C:\Python311\Lib\site-packages\pymobiledevice3\usbmux.py", line 357, in get_device_list

    def get_device_list(self, timeout: float = None) -> None:
        """ get device list synchronously without waiting the timeout """
        self.devices = []
        self._send({'MessageType': 'ListDevices'})
        print(self._receive(self._tag - 1))
        for response in self._receive(self._tag - 1)['DeviceList']:
            print(response)
            if response['MessageType'] == 'Attached':
                super()._add_device(MuxDevice(response['DeviceID'], response['Properties']['SerialNumber'],
                                              response['Properties']['ConnectionType']))
            elif response['MessageType'] == 'Detached':
                super()._remove_device(response['DeviceID'])
            else:
                raise MuxException(f'Invalid packet type received: {response}')

just got


F:\mobileErasure\build\windows>pymobiledevice3 usbmux list
{'MessageType': 'Result', 'Number': 4294967295}

seems the "4294967295 is not a valid UsbmuxReplyCode" related.

AnNEDoMini commented 1 day ago

It is not pmd3 related. This relates to "Apple Mobile Devices Service" win service. It poorly handles a lot of connected devices, also it depends on usb controllers and OS itself. 20 devices at one time seems work stable

yourchanges commented 23 hours ago

@AnNEDoMini do you means I can try it on linux os, it can work around "Apple Mobile Devices Service" win itune service ?

AnNEDoMini commented 12 hours ago

@AnNEDoMini do you means I can try it on linux os, it can work around "Apple Mobile Devices Service" win itune service ?

Technically yes. But you still may encounter some problems. Also it heavily dependent on USB controllers on your PC and USB hubs.