From 7fd59d571648b0b418b4c3728b0fb64898feba8c Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 21 Dec 2020 23:45:21 +0100 Subject: recovery: Upload RestoreSEP image if present in BuildManifest This fixes restoring iPhone 12 family devices and possibly others on iOS 14.3 --- src/recovery.c | 65 +++++++++++++++++++++++++++++----------------------------- src/recovery.h | 1 + 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/recovery.c b/src/recovery.c index c518b28..db489b2 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -221,11 +221,19 @@ int recovery_enter_restore(struct idevicerestore_client_t* client, plist_t build } /* send devicetree and load it */ - if (recovery_send_devicetree(client, build_identity) < 0) { + if (recovery_send_component_and_command(client, build_identity, "RestoreDeviceTree", "devicetree") < 0) { error("ERROR: Unable to send DeviceTree\n"); return -1; } + if (build_identity_has_component(build_identity, "RestoreSEP")) { + /* send rsepfirmware and load it */ + if (recovery_send_component_and_command(client, build_identity, "RestoreSEP", "rsepfirmware") < 0) { + error("ERROR: Unable to send RestoreSEP\n"); + return -1; + } + } + mutex_lock(&client->device_event_mutex); if (recovery_send_kernelcache(client, build_identity) < 0) { mutex_unlock(&client->device_event_mutex); @@ -276,7 +284,8 @@ int recovery_send_ticket(struct idevicerestore_client_t* client) return 0; } -int recovery_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component) { +int recovery_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component) +{ unsigned int size = 0; unsigned char* data = NULL; char* path = NULL; @@ -324,6 +333,24 @@ int recovery_send_component(struct idevicerestore_client_t* client, plist_t buil return 0; } +int recovery_send_component_and_command(struct idevicerestore_client_t* client, plist_t build_identity, const char* component, const char* command) +{ + irecv_error_t recovery_error = IRECV_E_SUCCESS; + + if (recovery_send_component(client, build_identity, component) < 0) { + error("ERROR: Unable to send %s to device.\n", component); + return -1; + } + + recovery_error = irecv_send_command(client->recovery->client, command); + if (recovery_error != IRECV_E_SUCCESS) { + error("ERROR: Unable to execute %s\n", component); + return -1; + } + + return 0; +} + int recovery_send_ibec(struct idevicerestore_client_t* client, plist_t build_identity) { const char* component = "iBEC"; irecv_error_t recovery_error = IRECV_E_SUCCESS; @@ -384,31 +411,8 @@ int recovery_send_applelogo(struct idevicerestore_client_t* client, plist_t buil return 0; } -int recovery_send_devicetree(struct idevicerestore_client_t* client, plist_t build_identity) { - const char* component = "RestoreDeviceTree"; - irecv_error_t recovery_error = IRECV_E_SUCCESS; - - if(client->recovery == NULL) { - if (recovery_client_new(client) < 0) { - return -1; - } - } - - if (recovery_send_component(client, build_identity, component) < 0) { - error("ERROR: Unable to send %s to device.\n", component); - return -1; - } - - recovery_error = irecv_send_command(client->recovery->client, "devicetree"); - if (recovery_error != IRECV_E_SUCCESS) { - error("ERROR: Unable to execute %s\n", component); - return -1; - } - - return 0; -} - -int recovery_send_loaded_by_iboot(struct idevicerestore_client_t* client, plist_t build_identity) { +int recovery_send_loaded_by_iboot(struct idevicerestore_client_t* client, plist_t build_identity) +{ if (client->recovery == NULL) { if (recovery_client_new(client) < 0) { return -1; @@ -436,14 +440,9 @@ int recovery_send_loaded_by_iboot(struct idevicerestore_client_t* client, plist_ plist_get_bool_val(iboot_node, &b); if (b) { debug("DEBUG: %s is loaded by iBoot.\n", key); - if (recovery_send_component(client, build_identity, key) < 0) { + if (recovery_send_component_and_command(client, build_identity, key, "firmware") < 0) { error("ERROR: Unable to send component '%s' to device.\n", key); err++; - } else { - if (irecv_send_command(client->recovery->client, "firmware") != IRECV_E_SUCCESS) { - error("ERROR: iBoot command 'firmware' failed for component '%s'\n", key); - err++; - } } } } diff --git a/src/recovery.h b/src/recovery.h index 872b0be..714943a 100644 --- a/src/recovery.h +++ b/src/recovery.h @@ -45,6 +45,7 @@ int recovery_client_new(struct idevicerestore_client_t* client); void recovery_client_free(struct idevicerestore_client_t* client); int recovery_enter_restore(struct idevicerestore_client_t* client, plist_t build_identity); int recovery_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component); +int recovery_send_component_and_command(struct idevicerestore_client_t* client, plist_t build_identity, const char* component, const char* command); int recovery_send_ibec(struct idevicerestore_client_t* client, plist_t build_identity); int recovery_send_applelogo(struct idevicerestore_client_t* client, plist_t build_identity); int recovery_send_devicetree(struct idevicerestore_client_t* client, plist_t build_identity); -- cgit v1.1-32-gdbae