From bc2dae1b214ac4d5044e7e3a3d75ff69e690db71 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 19 May 2021 16:21:07 -0700 Subject: [PATCH] [AltServer] Updates libimobiledevice dependency --- AltServer/Devices/ALTDeviceManager.mm | 84 +++++++++++++++------------ AltStore.xcodeproj/project.pbxproj | 2 + Dependencies/libimobiledevice | 2 +- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/AltServer/Devices/ALTDeviceManager.mm b/AltServer/Devices/ALTDeviceManager.mm index 80f2a3f9..75e12845 100644 --- a/AltServer/Devices/ALTDeviceManager.mm +++ b/AltServer/Devices/ALTDeviceManager.mm @@ -206,7 +206,7 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT } /* Find Device */ - if (idevice_new(&device, udid.UTF8String) != IDEVICE_E_SUCCESS) + if (idevice_new_with_options(&device, udid.UTF8String, (enum idevice_options)((int)IDEVICE_LOOKUP_NETWORK | (int)IDEVICE_LOOKUP_USBMUX)) != IDEVICE_E_SUCCESS) { return finish([NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorDeviceNotFound userInfo:nil]); } @@ -544,7 +544,7 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT }; /* Find Device */ - if (idevice_new(&device, udid.UTF8String) != IDEVICE_E_SUCCESS) + if (idevice_new_with_options(&device, udid.UTF8String, (enum idevice_options)((int)IDEVICE_LOOKUP_NETWORK | (int)IDEVICE_LOOKUP_USBMUX)) != IDEVICE_E_SUCCESS) { return finish([NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorDeviceNotFound userInfo:nil]); } @@ -621,7 +621,7 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT }; /* Find Device */ - if (idevice_new(&device, udid.UTF8String) != IDEVICE_E_SUCCESS) + if (idevice_new_with_options(&device, udid.UTF8String, (enum idevice_options)((int)IDEVICE_LOOKUP_NETWORK | (int)IDEVICE_LOOKUP_USBMUX)) != IDEVICE_E_SUCCESS) { return finish([NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorDeviceNotFound userInfo:nil]); } @@ -709,7 +709,7 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT }; /* Find Device */ - if (idevice_new(&device, udid.UTF8String) != IDEVICE_E_SUCCESS) + if (idevice_new_with_options(&device, udid.UTF8String, (enum idevice_options)((int)IDEVICE_LOOKUP_NETWORK | (int)IDEVICE_LOOKUP_USBMUX)) != IDEVICE_E_SUCCESS) { return finish([NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorDeviceNotFound userInfo:nil]); } @@ -995,7 +995,7 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT idevice_connection_t connection = NULL; /* Find Device */ - if (idevice_new_ignore_network(&device, altDevice.identifier.UTF8String) != IDEVICE_E_SUCCESS) + if (idevice_new_with_options(&device, altDevice.identifier.UTF8String, IDEVICE_LOOKUP_USBMUX) != IDEVICE_E_SUCCESS) { return finish(nil, [NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorDeviceNotFound userInfo:nil]); } @@ -1030,7 +1030,7 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT np_client_t client = NULL; /* Find Device */ - if (idevice_new_ignore_network(&device, altDevice.identifier.UTF8String) != IDEVICE_E_SUCCESS) + if (idevice_new_with_options(&device, altDevice.identifier.UTF8String, IDEVICE_LOOKUP_USBMUX) != IDEVICE_E_SUCCESS) { return finish(nil, [NSError errorWithDomain:AltServerErrorDomain code:ALTServerErrorDeviceNotFound userInfo:nil]); } @@ -1078,8 +1078,9 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT NSMutableSet *connectedDevices = [NSMutableSet set]; int count = 0; - char **udids = NULL; - if (idevice_get_device_list(&udids, &count) < 0) + idevice_info_t *devices = NULL; + + if (idevice_get_device_list_extended(&devices, &count) < 0) { fprintf(stderr, "ERROR: Unable to retrieve device list!\n"); return @[]; @@ -1087,17 +1088,46 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT for (int i = 0; i < count; i++) { - char *udid = udids[i]; + idevice_info_t device_info = devices[i]; + char *udid = device_info->udid; idevice_t device = NULL; + lockdownd_client_t client = NULL; + + char *device_name = NULL; + char *device_type_string = NULL; + + plist_t device_type_plist = NULL; + + void (^cleanUp)(void) = ^{ + if (device_type_plist) { + plist_free(device_type_plist); + } + + if (device_type_string) { + free(device_type_string); + } + + if (device_name) { + free(device_name); + } + + if (client) { + lockdownd_client_free(client); + } + + if (device) { + idevice_free(device); + } + }; if (includingNetworkDevices) { - idevice_new(&device, udid); + idevice_new_with_options(&device, udid, (enum idevice_options)((int)IDEVICE_LOOKUP_NETWORK | (int)IDEVICE_LOOKUP_USBMUX)); } else { - idevice_new_ignore_network(&device, udid); + idevice_new_with_options(&device, udid, IDEVICE_LOOKUP_USBMUX); } if (!device) @@ -1105,44 +1135,34 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT continue; } - lockdownd_client_t client = NULL; int result = lockdownd_client_new(device, &client, "altserver"); if (result != LOCKDOWN_E_SUCCESS) { fprintf(stderr, "ERROR: Connecting to device %s failed! (%d)\n", udid, result); - idevice_free(device); - + cleanUp(); continue; } - char *device_name = NULL; if (lockdownd_get_device_name(client, &device_name) != LOCKDOWN_E_SUCCESS || device_name == NULL) { fprintf(stderr, "ERROR: Could not get device name!\n"); - lockdownd_client_free(client); - idevice_free(device); - + cleanUp(); continue; } - plist_t device_type_plist = NULL; if (lockdownd_get_value(client, NULL, "ProductType", &device_type_plist) != LOCKDOWN_E_SUCCESS) { fprintf(stderr, "ERROR: Could not get device type for %s!\n", device_name); - lockdownd_client_free(client); - idevice_free(device); - + cleanUp(); continue; } - ALTDeviceType deviceType = ALTDeviceTypeiPhone; - - char *device_type_string = NULL; plist_get_string_val(device_type_plist, &device_type_string); + ALTDeviceType deviceType = ALTDeviceTypeiPhone; if ([@(device_type_string) hasPrefix:@"iPhone"]) { deviceType = ALTDeviceTypeiPhone; @@ -1159,28 +1179,20 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT { fprintf(stderr, "ERROR: Unknown device type %s for %s!\n", device_type_string, device_name); - lockdownd_client_free(client); - idevice_free(device); - + cleanUp(); continue; } - lockdownd_client_free(client); - idevice_free(device); - NSString *name = [NSString stringWithCString:device_name encoding:NSUTF8StringEncoding]; NSString *identifier = [NSString stringWithCString:udid encoding:NSUTF8StringEncoding]; ALTDevice *altDevice = [[ALTDevice alloc] initWithName:name identifier:identifier type:deviceType]; [connectedDevices addObject:altDevice]; - if (device_name != NULL) - { - free(device_name); - } + cleanUp(); } - idevice_device_list_free(udids); + idevice_device_list_extended_free(devices); return connectedDevices.allObjects; } diff --git a/AltStore.xcodeproj/project.pbxproj b/AltStore.xcodeproj/project.pbxproj index 81965a3d..a4acc286 100644 --- a/AltStore.xcodeproj/project.pbxproj +++ b/AltStore.xcodeproj/project.pbxproj @@ -2805,6 +2805,7 @@ HAVE_VASPRINTF, HAVE_ASPRINTF, "\"PACKAGE_STRING=\\\"AltServer 1.0\\\"\"", + HAVE_GETIFADDRS, ); GCC_WARN_INHIBIT_ALL_WARNINGS = YES; HEADER_SEARCH_PATHS = ( @@ -2842,6 +2843,7 @@ HAVE_VASPRINTF, HAVE_ASPRINTF, "\"PACKAGE_STRING=\\\"AltServer 1.0\\\"\"", + HAVE_GETIFADDRS, ); GCC_WARN_INHIBIT_ALL_WARNINGS = YES; HEADER_SEARCH_PATHS = ( diff --git a/Dependencies/libimobiledevice b/Dependencies/libimobiledevice index df4f2b0a..9b98387d 160000 --- a/Dependencies/libimobiledevice +++ b/Dependencies/libimobiledevice @@ -1 +1 @@ -Subproject commit df4f2b0ac56479f8952e8159c9c64ab68a935301 +Subproject commit 9b98387dd8c78a3db388f10d0ac9bf980bbab777