diff options
Diffstat (limited to 'src/libirecovery.c')
| -rw-r--r-- | src/libirecovery.c | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c index 22bbc0c..9c1a04a 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c | |||
| @@ -747,14 +747,17 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) { | |||
| 747 | } | 747 | } |
| 748 | 748 | ||
| 749 | char serial_str[256]; | 749 | char serial_str[256]; |
| 750 | char *p = result + strlen(result) - 1; | 750 | |
| 751 | while (p-- && p > result) { | 751 | serial_str[0] = '\0'; |
| 752 | if (*p == '\\' && (strncmp(p, "\\usb", 4) == 0)) { | 752 | |
| 753 | char *p = result; | ||
| 754 | while ((p = strstr(p, "\\usb"))) { | ||
| 755 | if (sscanf(p, "\\usb#vid_%*04x&pid_%*04x#%s", serial_str) == 1) | ||
| 753 | break; | 756 | break; |
| 754 | } | 757 | p += 4; |
| 755 | } | 758 | } |
| 756 | serial_str[0] = '\0'; | 759 | |
| 757 | if (!p || (sscanf(p, "\\usb#vid_%*04x&pid_%*04x#%s", serial_str) != 1) || (serial_str[0] == '\0')) { | 760 | if (serial_str[0] == '\0') { |
| 758 | mobiledevice_closepipes(_client); | 761 | mobiledevice_closepipes(_client); |
| 759 | continue; | 762 | continue; |
| 760 | } | 763 | } |
| @@ -829,14 +832,16 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) { | |||
| 829 | } | 832 | } |
| 830 | 833 | ||
| 831 | char serial_str[256]; | 834 | char serial_str[256]; |
| 832 | char *p = result + strlen(result) - 1; | 835 | serial_str[0] = '\0'; |
| 833 | while (p-- && p > result) { | 836 | |
| 834 | if (*p == '\\' && (strncmp(p, "\\usb", 4) == 0)) { | 837 | char *p = result; |
| 838 | while ((p = strstr(p, "\\usb"))) { | ||
| 839 | if (sscanf(p, "\\usb#vid_%*04x&pid_%*04x#%s", serial_str) == 1) | ||
| 835 | break; | 840 | break; |
| 836 | } | 841 | p += 4; |
| 837 | } | 842 | } |
| 838 | serial_str[0] = '\0'; | 843 | |
| 839 | if (!p || (sscanf(p, "\\usb#vid_%*04x&pid_%*04x#%s", serial_str) != 1) || (serial_str[0] == '\0')) { | 844 | if (serial_str[0] == '\0') { |
| 840 | mobiledevice_closepipes(_client); | 845 | mobiledevice_closepipes(_client); |
| 841 | continue; | 846 | continue; |
| 842 | } | 847 | } |
| @@ -1850,18 +1855,20 @@ static void* _irecv_handle_device_add(void *userdata) | |||
| 1850 | LPSTR result = (LPSTR)details->DevicePath; | 1855 | LPSTR result = (LPSTR)details->DevicePath; |
| 1851 | location = win_ctx->location; | 1856 | location = win_ctx->location; |
| 1852 | 1857 | ||
| 1853 | char *p = result + strlen(result) - 1; | 1858 | unsigned int pid = 0; |
| 1854 | while (p-- && p > result) { | 1859 | |
| 1855 | if (*p == '\\' && (strncmp(p, "\\usb", 4) == 0)) { | 1860 | char *p = result; |
| 1861 | while ((p = strstr(p, "\\usb"))) { | ||
| 1862 | if (sscanf(p, "\\usb#vid_%*04x&pid_%04x#%s", &pid, serial_str) == 2) | ||
| 1856 | break; | 1863 | break; |
| 1857 | } | 1864 | p += 4; |
| 1858 | } | 1865 | } |
| 1859 | 1866 | ||
| 1860 | unsigned int pid = 0; | 1867 | if (serial_str[0] == '\0') { |
| 1861 | if (!p || (sscanf(p, "\\usb#vid_%*04x&pid_%04x#%s", &pid, serial_str) != 2) || (serial_str[0] == '\0')) { | ||
| 1862 | debug("%s: ERROR: failed to parse DevicePath?!\n", __func__); | 1868 | debug("%s: ERROR: failed to parse DevicePath?!\n", __func__); |
| 1863 | return NULL; | 1869 | return NULL; |
| 1864 | } | 1870 | } |
| 1871 | |||
| 1865 | if (!_irecv_is_recovery_device(p)) { | 1872 | if (!_irecv_is_recovery_device(p)) { |
| 1866 | return NULL; | 1873 | return NULL; |
| 1867 | } | 1874 | } |
| @@ -2105,6 +2112,11 @@ static void *_irecv_event_handler(void* unused) | |||
| 2105 | HDEVINFO usbDevices; | 2112 | HDEVINFO usbDevices; |
| 2106 | DWORD i; | 2113 | DWORD i; |
| 2107 | int k; | 2114 | int k; |
| 2115 | |||
| 2116 | FOREACH(struct irecv_usb_device_info *devinfo, &devices) { | ||
| 2117 | devinfo->alive = 0; | ||
| 2118 | } ENDFOREACH | ||
| 2119 | |||
| 2108 | for (k = 0; guids[k]; k++) { | 2120 | for (k = 0; guids[k]; k++) { |
| 2109 | usbDevices = SetupDiGetClassDevs(guids[k], NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); | 2121 | usbDevices = SetupDiGetClassDevs(guids[k], NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); |
| 2110 | if (!usbDevices) { | 2122 | if (!usbDevices) { |
| @@ -2112,9 +2124,6 @@ static void *_irecv_event_handler(void* unused) | |||
| 2112 | return NULL; | 2124 | return NULL; |
| 2113 | } | 2125 | } |
| 2114 | 2126 | ||
| 2115 | FOREACH(struct irecv_usb_device_info *devinfo, &devices) { | ||
| 2116 | devinfo->alive = 0; | ||
| 2117 | } ENDFOREACH | ||
| 2118 | 2127 | ||
| 2119 | memset(¤tInterface, '\0', sizeof(SP_DEVICE_INTERFACE_DATA)); | 2128 | memset(¤tInterface, '\0', sizeof(SP_DEVICE_INTERFACE_DATA)); |
| 2120 | currentInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); | 2129 | currentInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); |
| @@ -2139,6 +2148,7 @@ static void *_irecv_event_handler(void* unused) | |||
| 2139 | free(details); | 2148 | free(details); |
| 2140 | continue; | 2149 | continue; |
| 2141 | } | 2150 | } |
| 2151 | |||
| 2142 | char *p = strrchr(driver, '\\'); | 2152 | char *p = strrchr(driver, '\\'); |
| 2143 | if (!p) { | 2153 | if (!p) { |
| 2144 | debug("%s: ERROR: Failed to parse device location\n", __func__); | 2154 | debug("%s: ERROR: Failed to parse device location\n", __func__); |
