From 1ce973146571da59921cb56e27fc44ee037ee450 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 11 Nov 2020 17:50:19 -0800 Subject: [PATCH] [AltServer] Supports sideloading apps to Apple TV --- .../ALTDeviceManager+Installation.swift | 20 +++++----- AltServer/Devices/ALTDeviceManager.mm | 40 ++++++++++++++++++- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/AltServer/Devices/ALTDeviceManager+Installation.swift b/AltServer/Devices/ALTDeviceManager+Installation.swift index 9048232d..b52d7c6d 100644 --- a/AltServer/Devices/ALTDeviceManager+Installation.swift +++ b/AltServer/Devices/ALTDeviceManager+Installation.swift @@ -99,7 +99,7 @@ extension ALTDeviceManager let anisetteData = try result.get() session.anisetteData = anisetteData - self.prepareAllProvisioningProfiles(for: application, team: team, session: session) { (result) in + self.prepareAllProvisioningProfiles(for: application, device: device, team: team, session: session) { (result) in do { let profiles = try result.get() @@ -397,10 +397,10 @@ To prevent this from happening, feel free to try again with another Apple ID. } } - func prepareAllProvisioningProfiles(for application: ALTApplication, team: ALTTeam, session: ALTAppleAPISession, + func prepareAllProvisioningProfiles(for application: ALTApplication, device: ALTDevice, team: ALTTeam, session: ALTAppleAPISession, completion: @escaping (Result<[String: ALTProvisioningProfile], Error>) -> Void) { - self.prepareProvisioningProfile(for: application, parentApp: nil, team: team, session: session) { (result) in + self.prepareProvisioningProfile(for: application, parentApp: nil, device: device, team: team, session: session) { (result) in do { let profile = try result.get() @@ -414,7 +414,7 @@ To prevent this from happening, feel free to try again with another Apple ID. { dispatchGroup.enter() - self.prepareProvisioningProfile(for: appExtension, parentApp: application, team: team, session: session) { (result) in + self.prepareProvisioningProfile(for: appExtension, parentApp: application, device: device, team: team, session: session) { (result) in switch result { case .failure(let e): error = e @@ -443,7 +443,7 @@ To prevent this from happening, feel free to try again with another Apple ID. } } - func prepareProvisioningProfile(for application: ALTApplication, parentApp: ALTApplication?, team: ALTTeam, session: ALTAppleAPISession, completionHandler: @escaping (Result) -> Void) + func prepareProvisioningProfile(for application: ALTApplication, parentApp: ALTApplication?, device: ALTDevice, team: ALTTeam, session: ALTAppleAPISession, completionHandler: @escaping (Result) -> Void) { let parentBundleID = parentApp?.bundleIdentifier ?? application.bundleIdentifier let updatedParentBundleID: String @@ -486,7 +486,7 @@ To prevent this from happening, feel free to try again with another Apple ID. { let appID = try result.get() - self.fetchProvisioningProfile(for: appID, team: team, session: session) { (result) in + self.fetchProvisioningProfile(for: appID, device: device, team: team, session: session) { (result) in completionHandler(result) } } @@ -666,7 +666,7 @@ To prevent this from happening, feel free to try again with another Apple ID. func register(_ device: ALTDevice, team: ALTTeam, session: ALTAppleAPISession, completionHandler: @escaping (Result) -> Void) { - ALTAppleAPI.shared.fetchDevices(for: team, session: session) { (devices, error) in + ALTAppleAPI.shared.fetchDevices(for: team, types: device.type, session: session) { (devices, error) in do { let devices = try Result(devices, error).get() @@ -677,7 +677,7 @@ To prevent this from happening, feel free to try again with another Apple ID. } else { - ALTAppleAPI.shared.registerDevice(name: device.name, identifier: device.identifier, team: team, session: session) { (device, error) in + ALTAppleAPI.shared.registerDevice(name: device.name, identifier: device.identifier, type: device.type, team: team, session: session) { (device, error) in completionHandler(Result(device, error)) } } @@ -689,9 +689,9 @@ To prevent this from happening, feel free to try again with another Apple ID. } } - func fetchProvisioningProfile(for appID: ALTAppID, team: ALTTeam, session: ALTAppleAPISession, completionHandler: @escaping (Result) -> Void) + func fetchProvisioningProfile(for appID: ALTAppID, device: ALTDevice, team: ALTTeam, session: ALTAppleAPISession, completionHandler: @escaping (Result) -> Void) { - ALTAppleAPI.shared.fetchProvisioningProfile(for: appID, team: team, session: session) { (profile, error) in + ALTAppleAPI.shared.fetchProvisioningProfile(for: appID, deviceType: device.type, team: team, session: session) { (profile, error) in completionHandler(Result(profile, error)) } } diff --git a/AltServer/Devices/ALTDeviceManager.mm b/AltServer/Devices/ALTDeviceManager.mm index 219cbc46..ce1267e7 100644 --- a/AltServer/Devices/ALTDeviceManager.mm +++ b/AltServer/Devices/ALTDeviceManager.mm @@ -1113,13 +1113,51 @@ NSNotificationName const ALTDeviceManagerDeviceDidDisconnectNotification = @"ALT 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); + + continue; + } + + ALTDeviceType deviceType = ALTDeviceTypeiPhone; + + char *device_type_string = NULL; + plist_get_string_val(device_type_plist, &device_type_string); + + if ([@(device_type_string) hasPrefix:@"iPhone"]) + { + deviceType = ALTDeviceTypeiPhone; + } + else if ([@(device_type_string) hasPrefix:@"iPad"]) + { + deviceType = ALTDeviceTypeiPad; + } + else if ([@(device_type_string) hasPrefix:@"AppleTV"]) + { + deviceType = ALTDeviceTypeAppleTV; + } + else + { + fprintf(stderr, "ERROR: Unknown device type %s for %s!\n", device_type_string, device_name); + + lockdownd_client_free(client); + idevice_free(device); + + 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:ALTDeviceTypeiPhone]; + ALTDevice *altDevice = [[ALTDevice alloc] initWithName:name identifier:identifier type:deviceType]; [connectedDevices addObject:altDevice]; if (device_name != NULL)