From 60f4f45d6614d8eeedd90f0099bc138605e73d2a Mon Sep 17 00:00:00 2001 From: nearohen Date: Thu, 28 Mar 2024 16:55:42 +0200 Subject: [PATCH] beforechanges --- src/Makefile.am | 1 + src/common.c | 21 ++++++++------------- src/dfu.c | 2 +- src/idevicerestore.c | 3 ++- src/normal.c | 21 +++++++++++++-------- src/recovery.c | 2 +- src/restore.c | 15 +++++++++------ src/tss.c | 1 + 8 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index a89a9c66..a7f27612 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,6 +42,7 @@ idevicerestore_SOURCES = \ restore.c restore.h \ asr.c asr.h \ fdr.c fdr.h \ + ace3.c ace3.h \ limera1n_payload.h \ limera1n.c limera1n.h \ download.c download.h \ diff --git a/src/common.c b/src/common.c index 886b9a7b..bc15dc4d 100644 --- a/src/common.c +++ b/src/common.c @@ -80,33 +80,28 @@ static int debug_disabled = 0; void info(const char* format, ...) { - if (info_disabled) return; + va_list vargs; va_start(vargs, format); - vfprintf((info_stream) ? info_stream : stdout, format, vargs); + vfprintf((debug_stream) ? debug_stream : stderr, format, vargs); va_end(vargs); + fflush(stderr); } void error(const char* format, ...) { - va_list vargs, vargs2; + + printf("format format:%s\n",format); + va_list vargs; va_start(vargs, format); - va_copy(vargs2, vargs); - vsnprintf(idevicerestore_err_buff, idevicerestore_err_buff_size, format, vargs); + vfprintf((debug_stream) ? debug_stream : stderr, format, vargs); va_end(vargs); - if (!error_disabled) { - vfprintf((error_stream) ? error_stream : stderr, format, vargs2); - } - va_end(vargs2); fflush(stderr); } void debug(const char* format, ...) { - if (debug_disabled) return; - if (!idevicerestore_debug) { - return; - } + va_list vargs; va_start(vargs, format); vfprintf((debug_stream) ? debug_stream : stderr, format, vargs); diff --git a/src/dfu.c b/src/dfu.c index 51c85ab0..e5c087cb 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -121,7 +121,7 @@ int dfu_send_buffer(struct idevicerestore_client_t* client, unsigned char* buffe int dfu_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component) { char* path = NULL; - + debug("dfu_send_component"); // Use a specific TSS ticket for the Ap,LocalPolicy component plist_t tss = client->tss; if (strcmp(component, "Ap,LocalPolicy") == 0) { diff --git a/src/idevicerestore.c b/src/idevicerestore.c index febaad05..2adc6345 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -45,6 +45,7 @@ #define SHA384 sha384 #endif +#include "ace3.h" #include "dfu.h" #include "tss.h" #include "img3.h" @@ -1218,7 +1219,7 @@ int idevicerestore_start(struct idevicerestore_client_t* client) // if the device is in normal mode, place device into recovery mode if (client->mode == MODE_NORMAL) { - info("Entering recovery mode...\n"); + info("Entering recovery mode... WELL\n"); if (normal_enter_recovery(client) < 0) { error("ERROR: Unable to place device into recovery mode from normal mode\n"); if (client->tss) diff --git a/src/normal.c b/src/normal.c index c642d593..d5fe4176 100644 --- a/src/normal.c +++ b/src/normal.c @@ -219,17 +219,18 @@ irecv_device_t normal_get_irecv_device(struct idevicerestore_client_t* client) int normal_enter_recovery(struct idevicerestore_client_t* client) { + printf("0\n"); idevice_t device = NULL; lockdownd_client_t lockdown = NULL; idevice_error_t device_error = IDEVICE_E_SUCCESS; lockdownd_error_t lockdown_error = LOCKDOWN_E_SUCCESS; - + error("1"); device_error = idevice_new(&device, client->udid); if (device_error != IDEVICE_E_SUCCESS) { error("ERROR: Unable to find device\n"); return -1; } - + error("2"); lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore"); if (lockdown_error != LOCKDOWN_E_SUCCESS) { error("ERROR: Unable to connect to lockdownd: %s (%d)\n", lockdownd_strerror(lockdown_error), lockdown_error); @@ -242,7 +243,7 @@ int normal_enter_recovery(struct idevicerestore_client_t* client) //if (lockdown_error != LOCKDOWN_E_SUCCESS) { // error("WARNING: Could not unpair device\n"); //} - + error("3"); lockdown_error = lockdownd_enter_recovery(lockdown); if (lockdown_error == LOCKDOWN_E_SESSION_INACTIVE) { lockdownd_client_free(lockdown); @@ -254,19 +255,23 @@ int normal_enter_recovery(struct idevicerestore_client_t* client) } lockdown_error = lockdownd_enter_recovery(lockdown); } + error("5"); if (lockdown_error != LOCKDOWN_E_SUCCESS) { error("ERROR: Unable to place device in recovery mode: %s (%d)\n", lockdownd_strerror(lockdown_error), lockdown_error); lockdownd_client_free(lockdown); idevice_free(device); return -1; } - - lockdownd_client_free(lockdown); - idevice_free(device); + error("lockdownd_client_free"); + //lockdownd_client_free(lockdown); + error("idevice_free"); + //idevice_free(device); + error("7"); lockdown = NULL; device = NULL; - + error("mutex_lock"); mutex_lock(&client->device_event_mutex); + error("Waiting"); debug("DEBUG: Waiting for device to disconnect...4\n"); cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 60000); int tries = 3 ; @@ -301,7 +306,7 @@ int normal_enter_recovery(struct idevicerestore_client_t* client) error("ERROR: Unable to enter recovery mode\n"); return -1; } - + error("7"); return 0; } diff --git a/src/recovery.c b/src/recovery.c index 432530f2..554d4e8a 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -284,7 +284,7 @@ int recovery_send_component(struct idevicerestore_client_t* client, plist_t buil unsigned char* data = NULL; char* path = NULL; irecv_error_t err = 0; - + debug("recovery_send_component"); if (client->tss) { if (tss_response_get_path_by_entry(client->tss, component, &path) < 0) { debug("NOTE: No path for component %s in TSS, will fetch from build_identity\n", component); diff --git a/src/restore.c b/src/restore.c index 9d419b7e..ce52a56a 100644 --- a/src/restore.c +++ b/src/restore.c @@ -1048,7 +1048,7 @@ int restore_send_component(restored_client_t restore, struct idevicerestore_clie plist_t blob = NULL; plist_t dict = NULL; restored_error_t restore_error = RESTORE_E_SUCCESS; - + debug("recovery_send_component 2"); if (component_name == NULL) { component_name = component; } @@ -1061,6 +1061,7 @@ int restore_send_component(restored_client_t restore, struct idevicerestore_clie } } if (!path) { + debug("no Path"); if (build_identity_get_component_path(build_identity, component, &path) < 0) { error("ERROR: Unable to find %s path from build identity\n", component); return -1; @@ -1069,6 +1070,7 @@ int restore_send_component(restored_client_t restore, struct idevicerestore_clie unsigned char* component_data = NULL; unsigned int component_size = 0; + debug("extract_component"); int ret = extract_component(client->ipsw, path, &component_data, &component_size); free(path); path = NULL; @@ -1123,14 +1125,14 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t* plist_t norimage = NULL; plist_t firmware_files = NULL; int flash_version_1 = 0; - + debug("restore_send_nor"); info("About to send NORData...\n"); plist_t arguments = plist_dict_get_item(message, "Arguments"); if (arguments && plist_get_node_type(arguments) == PLIST_DICT) { flash_version_1 = plist_dict_get_item(arguments, "FlashVersion1") ? 1 : 0; } - + if (client->tss) { if (tss_response_get_path_by_entry(client->tss, "LLB", &llb_path) < 0) { debug("NOTE: Could not get LLB path from TSS data, will fetch from build identity\n"); @@ -3533,7 +3535,7 @@ int restore_send_personalized_boot_object_v3(restored_client_t restore, struct i plist_t dict = NULL; restored_error_t restore_error = RESTORE_E_SUCCESS; - info("About to send %s...\n", component); + info("boot_object_v3 About to send %s...\n", component); if (strcmp(image_name, "__GlobalManifest__") == 0) { int ret = extract_global_manifest(client, build_identity, NULL, &data, &size); @@ -3614,6 +3616,7 @@ int restore_send_personalized_boot_object_v3(restored_client_t restore, struct i int restore_send_source_boot_object_v4(restored_client_t restore, struct idevicerestore_client_t* client, plist_t msg, plist_t build_identity) { + debug("restore_send_source_boot_object_v4"); debug_plist(msg); char *image_name = NULL; @@ -3638,7 +3641,7 @@ int restore_send_source_boot_object_v4(restored_client_t restore, struct idevice plist_t dict = NULL; restored_error_t restore_error = RESTORE_E_SUCCESS; - info("About to send %s...\n", component); + info("ource_boot_object_v4 About to send %s...\n", component); if (strcmp(image_name, "__GlobalManifest__") == 0) { char *variant = NULL; @@ -3679,7 +3682,7 @@ int restore_send_source_boot_object_v4(restored_client_t restore, struct idevice return -1; } - info("Sending %s now...\n", component); + info("Sending %s now... path:%s\n", component,path ? path : "null"); if (ipsw_extract_send(client->ipsw, path, 8192, (ipsw_send_cb)_restore_send_file_data, restore) < 0) { free(path); diff --git a/src/tss.c b/src/tss.c index ac81dc3e..3d7eed3c 100644 --- a/src/tss.c +++ b/src/tss.c @@ -1663,6 +1663,7 @@ int tss_response_get_baseband_ticket(plist_t response, unsigned char** ticket, u int tss_response_get_path_by_entry(plist_t response, const char* entry, char** path) { + debug("tss_response_get_path_by_entry %s %s ",entry ? entry : "null",path ? path : "null"); char* path_string = NULL; plist_t path_node = NULL; plist_t entry_node = NULL;