From 15010f466a4a6437b5c46a37625386565e1e5091 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 15:17:52 +0200 Subject: Correctly assign the client flags from command line --- src/idevicerestore.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 7982ed7..b5d4858 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -81,20 +81,20 @@ int main(int argc, char* argv[]) { return 0; case 'd': - client->flags &= FLAG_DEBUG; + client->flags |= FLAG_DEBUG; idevicerestore_debug = 1; break; case 'e': - client->flags &= FLAG_ERASE; + client->flags |= FLAG_ERASE; break; case 'c': - client->flags &= FLAG_CUSTOM; + client->flags |= FLAG_CUSTOM; break; case 'x': - client->flags &= FLAG_EXCLUDE; + client->flags |= FLAG_EXCLUDE; break; case 'u': -- cgit v1.1-32-gdbae From d80d5b462061022fac7e1a57d6a05c54499e042d Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 15:58:25 +0200 Subject: Add helper functions to dump information from a manifest of the IPSW --- src/idevicerestore.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/idevicerestore.h | 2 ++ 2 files changed, 75 insertions(+) diff --git a/src/idevicerestore.c b/src/idevicerestore.c index b5d4858..dde163d 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -154,6 +154,9 @@ int main(int argc, char* argv[]) { return -1; } + /* print iOS information from the manifest */ + build_manifest_print_information(buildmanifest); + // devices are listed in order from oldest to newest // so we'll need their ECID if (client->device->index > DEVICE_IPOD2G) { @@ -188,6 +191,9 @@ int main(int argc, char* argv[]) { } } + /* print information about current build identity */ + build_identity_print_information(buildidentity); + if (client->flags & FLAG_CUSTOM > 0) { if (client->device->index > DEVICE_IPOD2G) { if (get_shsh_blobs(client, ecid, build_identity, &client->tss) < 0) { @@ -616,6 +622,73 @@ int ipsw_get_component_by_path(const char* ipsw, plist_t tss, const char* path, return 0; } +void build_manifest_print_information(plist_t build_manifest) { + char* value = NULL; + plist_t node = NULL; + + node = plist_dict_get_item(build_manifest, "ProductVersion"); + if (!node || plist_get_node_type(node) != PLIST_STRING) { + error("ERROR: Unable to find ProductVersion node\n"); + return; + } + plist_get_string_val(node, &value); + + info("Product Version: %s\n", value); + free(value); + + node = plist_dict_get_item(build_manifest, "ProductBuildVersion"); + if (!node || plist_get_node_type(node) != PLIST_STRING) { + error("ERROR: Unable to find ProductBuildVersion node\n"); + return; + } + plist_get_string_val(node, &value); + + info("Product Build: %s\n", value); + free(value); + + node = NULL; +} + +void build_identity_print_information(plist_t build_identity) { + char* value = NULL; + plist_t info_node = NULL; + plist_t node = NULL; + + info_node = plist_dict_get_item(build_identity, "Info"); + if (!info_node || plist_get_node_type(info_node) != PLIST_DICT) { + error("ERROR: Unable to find Info node\n"); + return; + } + + node = plist_dict_get_item(info_node, "Variant"); + if (!node || plist_get_node_type(node) != PLIST_STRING) { + error("ERROR: Unable to find Variant node\n"); + return; + } + plist_get_string_val(node, &value); + + info("Variant: %s\n", value); + free(value); + + node = plist_dict_get_item(info_node, "RestoreBehavior"); + if (!node || plist_get_node_type(node) != PLIST_STRING) { + error("ERROR: Unable to find RestoreBehavior node\n"); + return; + } + plist_get_string_val(node, &value); + + if (!strcmp(value, "Erase")) + info("This restore will erase your device data.\n"); + + if (!strcmp(value, "Update")) + info("This restore will update your device without loosing data.\n"); + + free(value); + + info_node = NULL; + node = NULL; +} + int build_identity_get_component_path(plist_t build_identity, const char* component, char** path) { char* filename = NULL; diff --git a/src/idevicerestore.h b/src/idevicerestore.h index f529b5b..f42ed6f 100644 --- a/src/idevicerestore.h +++ b/src/idevicerestore.h @@ -43,6 +43,8 @@ plist_t get_build_identity(struct idevicerestore_client_t* client, plist_t build int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, plist_t build_identity, plist_t* tss); int extract_filesystem(struct idevicerestore_client_t* client, const char* ipsw, plist_t buildmanifest, char** filesystem); int ipsw_get_component_by_path(const char* ipsw, plist_t tss, const char* path, char** data, uint32_t* size); +void build_manifest_print_information(plist_t build_manifest); +void build_identity_print_information(plist_t build_identity); int build_identity_get_component_path(plist_t build_identity, const char* component, char** path); #ifdef __cplusplus -- cgit v1.1-32-gdbae From bfcd784574ace78f9923213e3d260302d28b54c8 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 16:35:17 +0200 Subject: Refactor manifest extraction --- src/idevicerestore.c | 2 +- src/idevicerestore.h | 1 - src/ipsw.c | 22 ++++++++++++++++++++++ src/ipsw.h | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/idevicerestore.c b/src/idevicerestore.c index dde163d..6b3dee4 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -149,7 +149,7 @@ int main(int argc, char* argv[]) { // extract buildmanifest plist_t buildmanifest = NULL; info("Extracting BuildManifest from IPSW\n"); - if (extract_buildmanifest(client, ipsw, &buildmanifest) < 0) { + if (ipsw_extract_build_manifest(ipsw, &buildmanifest) < 0) { error("ERROR: Unable to extract BuildManifest from %s\n", ipsw); return -1; } diff --git a/src/idevicerestore.h b/src/idevicerestore.h index f42ed6f..27128a7 100644 --- a/src/idevicerestore.h +++ b/src/idevicerestore.h @@ -38,7 +38,6 @@ int get_build_count(plist_t buildmanifest); int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid); int get_bdid(struct idevicerestore_client_t* client, uint32_t* bdid); int get_cpid(struct idevicerestore_client_t* client, uint32_t* cpid); -int extract_buildmanifest(struct idevicerestore_client_t* client, const char* ipsw, plist_t* buildmanifest); plist_t get_build_identity(struct idevicerestore_client_t* client, plist_t buildmanifest, uint32_t identity); int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, plist_t build_identity, plist_t* tss); int extract_filesystem(struct idevicerestore_client_t* client, const char* ipsw, plist_t buildmanifest, char** filesystem); diff --git a/src/ipsw.c b/src/ipsw.c index f08e2fd..9cd7290 100644 --- a/src/ipsw.c +++ b/src/ipsw.c @@ -173,6 +173,28 @@ int ipsw_extract_to_memory(const char* ipsw, const char* infile, char** pbuffer, return 0; } +int ipsw_extract_build_manifest(const char* ipsw, plist_t* buildmanifest) { + int size = 0; + char* data = NULL; + + /* older devices don't require personalized firmwares and use a BuildManifesto.plist */ + if (ipsw_extract_to_memory(ipsw, "BuildManifesto.plist", &data, &size) == 0) { + plist_from_xml(data, size, buildmanifest); + return 0; + } + + data = NULL; + size = 0; + + /* whereas newer devices do not require personalized firmwares and use a BuildManifest.plist */ + if (ipsw_extract_to_memory(ipsw, "BuildManifest.plist", &data, &size) == 0) { + plist_from_xml(data, size, buildmanifest); + return 0; + } + + return -1; +} + void ipsw_close(ipsw_archive* archive) { if (archive != NULL) { zip_unchange_all(archive->zip); diff --git a/src/ipsw.h b/src/ipsw.h index cd11406..f1694ef 100644 --- a/src/ipsw.h +++ b/src/ipsw.h @@ -28,6 +28,7 @@ extern "C" { #include #include +#include typedef struct { int index; @@ -37,6 +38,7 @@ typedef struct { } ipsw_file; int ipsw_extract_to_memory(const char* ipsw, const char* infile, char** pbuffer, uint32_t* psize); +int ipsw_extract_build_manifest(const char* ipsw, plist_t* buildmanifest); void ipsw_free_file(ipsw_file* file); #ifdef __cplusplus -- cgit v1.1-32-gdbae From f05bbae5f00c57f3d08936159212d3e20678a8d6 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 16:37:04 +0200 Subject: Fix crash due to not passing client handle for callback as userdata --- src/restore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/restore.c b/src/restore.c index 5d45296..44dc2aa 100644 --- a/src/restore.c +++ b/src/restore.c @@ -225,7 +225,7 @@ int restore_open_with_timeout(struct idevicerestore_client_t* client) { } } - device_error = idevice_event_subscribe(&restore_device_callback, NULL); + device_error = idevice_event_subscribe(&restore_device_callback, client); if (device_error != IDEVICE_E_SUCCESS) { error("ERROR: Unable to subscribe to device events\n"); return -1; -- cgit v1.1-32-gdbae From 515f26d28667b4790a4c1db1126f68b015ed1bce Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 16:37:57 +0200 Subject: Fix idevice handle being NULL which leads to failure to connect to ASR --- src/restore.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/restore.c b/src/restore.c index 44dc2aa..e4652bf 100644 --- a/src/restore.c +++ b/src/restore.c @@ -606,6 +606,7 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit info("Device has successfully entered restore mode\n"); restore = client->restore->client; + device = client->restore->device; // start the restore process restore_error = restored_start_restore(restore); -- cgit v1.1-32-gdbae From 77576d1848d6be1d73f0f860d6a4f350536f75bd Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 16:47:42 +0200 Subject: Refactor filesystem extraction --- src/idevicerestore.c | 4 ++-- src/idevicerestore.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 6b3dee4..9b0b98e 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -212,7 +212,7 @@ int main(int argc, char* argv[]) { // Extract filesystem from IPSW and return its name char* filesystem = NULL; - if (extract_filesystem(client, client->ipsw, build_identity, &filesystem) < 0) { + if (ipsw_extract_filesystem(client->ipsw, buildidentity, &filesystem) < 0) { error("ERROR: Unable to extract filesystem from IPSW\n"); if (client->tss) plist_free(client->tss); @@ -541,7 +541,7 @@ int get_build_count(plist_t buildmanifest) { return plist_array_get_size(build_identities_array); } -int extract_filesystem(struct idevicerestore_client_t* client, const char* ipsw, plist_t build_identity, char** filesystem) { +int ipsw_extract_filesystem(const char* ipsw, plist_t build_identity, char** filesystem) { char* filename = NULL; if (build_identity_get_component_path(build_identity, "OS", &filename) < 0) { diff --git a/src/idevicerestore.h b/src/idevicerestore.h index 27128a7..47482d7 100644 --- a/src/idevicerestore.h +++ b/src/idevicerestore.h @@ -40,11 +40,11 @@ int get_bdid(struct idevicerestore_client_t* client, uint32_t* bdid); int get_cpid(struct idevicerestore_client_t* client, uint32_t* cpid); plist_t get_build_identity(struct idevicerestore_client_t* client, plist_t buildmanifest, uint32_t identity); int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, plist_t build_identity, plist_t* tss); -int extract_filesystem(struct idevicerestore_client_t* client, const char* ipsw, plist_t buildmanifest, char** filesystem); int ipsw_get_component_by_path(const char* ipsw, plist_t tss, const char* path, char** data, uint32_t* size); void build_manifest_print_information(plist_t build_manifest); void build_identity_print_information(plist_t build_identity); int build_identity_get_component_path(plist_t build_identity, const char* component, char** path); +int ipsw_extract_filesystem(const char* ipsw, plist_t build_identity, char** filesystem); #ifdef __cplusplus } -- cgit v1.1-32-gdbae From 232e116e48612ffec0351704a431f4174544887e Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 16:59:36 +0200 Subject: Correctly set QUIT flag during restore --- src/restore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/restore.c b/src/restore.c index e4652bf..40b24d3 100644 --- a/src/restore.c +++ b/src/restore.c @@ -178,7 +178,7 @@ void restore_device_callback(const idevice_event_t* event, void* userdata) { } else if (event->event == IDEVICE_DEVICE_REMOVE) { restore_device_connected = 0; - client->flags &= FLAG_QUIT; + client->flags |= FLAG_QUIT; } } @@ -575,7 +575,7 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev return -1; } } else { - client->flags &= 1; + client->flags |= FLAG_QUIT; } } else { @@ -667,7 +667,7 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit // an unrecoverable error, so we need to bail. if (error < 0) { error("ERROR: Unable to successfully restore device\n"); - client->flags &= FLAG_QUIT; + client->flags |= FLAG_QUIT; } plist_free(message); -- cgit v1.1-32-gdbae From f90bdde9fc347f02a857cc26f14c4d2d5c55f64e Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 17:02:50 +0200 Subject: Remove leftover of extract_manifest helper --- src/idevicerestore.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 9b0b98e..778673f 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -461,29 +461,6 @@ int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { return 0; } -int extract_buildmanifest(struct idevicerestore_client_t* client, const char* ipsw, plist_t* buildmanifest) { - int size = 0; - char* data = NULL; - int device = client->device->index; - - /* older devices don't require personalized firmwares and use a BuildManifesto.plist */ - if (ipsw_extract_to_memory(ipsw, "BuildManifesto.plist", &data, &size) == 0) { - plist_from_xml(data, size, buildmanifest); - return 0; - } - - data = NULL; - size = 0; - - /* whereas newer devices do not require personalized firmwares and use a BuildManifest.plist */ - if (ipsw_extract_to_memory(ipsw, "BuildManifest.plist", &data, &size) == 0) { - plist_from_xml(data, size, buildmanifest); - return 0; - } - - return -1; -} - plist_t get_build_identity(struct idevicerestore_client_t* client, plist_t buildmanifest, uint32_t identity) { // fetch build identities array from BuildManifest plist_t build_identities_array = plist_dict_get_item(buildmanifest, "BuildIdentities"); -- cgit v1.1-32-gdbae From 4ac94fe7a174f841b13734f98d237a8afac6cbab Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 17:07:28 +0200 Subject: Rename some variables and functions to fit thier context --- src/idevicerestore.c | 20 ++++++++++---------- src/idevicerestore.h | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/idevicerestore.c b/src/idevicerestore.c index 778673f..00c35c1 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -160,7 +160,7 @@ int main(int argc, char* argv[]) { // devices are listed in order from oldest to newest // so we'll need their ECID if (client->device->index > DEVICE_IPOD2G) { - debug("Creating TSS request\n"); + debug("Getting device's ECID for TSS request\n"); // fetch the device's ECID for the TSS request if (get_ecid(client, &client->ecid) < 0) { error("ERROR: Unable to find device ECID\n"); @@ -173,7 +173,7 @@ int main(int argc, char* argv[]) { client->tss = NULL; plist_t build_identity = NULL; if (client->flags & FLAG_ERASE) { - build_identity = get_build_identity(client, buildmanifest, 0); + build_identity = build_manifest_get_build_identity(buildmanifest, 0); if (build_identity == NULL) { error("ERROR: Unable to find any build identities\n"); plist_free(buildmanifest); @@ -184,15 +184,15 @@ int main(int argc, char* argv[]) { // and list the valid ones int i = 0; int valid_builds = 0; - int build_count = get_build_count(buildmanifest); + int build_count = build_manifest_get_identity_count(buildmanifest); for (i = 0; i < build_count; i++) { - build_identity = get_build_identity(client, buildmanifest, i); + build_identity = build_manifest_get_build_identity(buildmanifest, i); valid_builds++; } } /* print information about current build identity */ - build_identity_print_information(buildidentity); + build_identity_print_information(build_identity); if (client->flags & FLAG_CUSTOM > 0) { if (client->device->index > DEVICE_IPOD2G) { @@ -212,7 +212,7 @@ int main(int argc, char* argv[]) { // Extract filesystem from IPSW and return its name char* filesystem = NULL; - if (ipsw_extract_filesystem(client->ipsw, buildidentity, &filesystem) < 0) { + if (ipsw_extract_filesystem(client->ipsw, build_identity, &filesystem) < 0) { error("ERROR: Unable to extract filesystem from IPSW\n"); if (client->tss) plist_free(client->tss); @@ -461,9 +461,9 @@ int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { return 0; } -plist_t get_build_identity(struct idevicerestore_client_t* client, plist_t buildmanifest, uint32_t identity) { +plist_t build_manifest_get_build_identity(plist_t build_manifest, uint32_t identity) { // fetch build identities array from BuildManifest - plist_t build_identities_array = plist_dict_get_item(buildmanifest, "BuildIdentities"); + plist_t build_identities_array = plist_dict_get_item(build_manifest, "BuildIdentities"); if (!build_identities_array || plist_get_node_type(build_identities_array) != PLIST_ARRAY) { error("ERROR: Unable to find build identities node\n"); return NULL; @@ -506,9 +506,9 @@ int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, plist_ return 0; } -int get_build_count(plist_t buildmanifest) { +int build_manifest_get_identity_count(plist_t build_manifest) { // fetch build identities array from BuildManifest - plist_t build_identities_array = plist_dict_get_item(buildmanifest, "BuildIdentities"); + plist_t build_identities_array = plist_dict_get_item(build_manifest, "BuildIdentities"); if (!build_identities_array || plist_get_node_type(build_identities_array) != PLIST_ARRAY) { error("ERROR: Unable to find build identities node\n"); return -1; diff --git a/src/idevicerestore.h b/src/idevicerestore.h index 47482d7..4f59a02 100644 --- a/src/idevicerestore.h +++ b/src/idevicerestore.h @@ -34,17 +34,17 @@ extern "C" { void usage(int argc, char* argv[]); int check_mode(struct idevicerestore_client_t* client); int check_device(struct idevicerestore_client_t* client); -int get_build_count(plist_t buildmanifest); int get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid); int get_bdid(struct idevicerestore_client_t* client, uint32_t* bdid); int get_cpid(struct idevicerestore_client_t* client, uint32_t* cpid); -plist_t get_build_identity(struct idevicerestore_client_t* client, plist_t buildmanifest, uint32_t identity); int get_shsh_blobs(struct idevicerestore_client_t* client, uint64_t ecid, plist_t build_identity, plist_t* tss); -int ipsw_get_component_by_path(const char* ipsw, plist_t tss, const char* path, char** data, uint32_t* size); void build_manifest_print_information(plist_t build_manifest); +plist_t build_manifest_get_build_identity(plist_t build_manifest, uint32_t identity); +int build_manifest_get_build_count(plist_t build_manifest); void build_identity_print_information(plist_t build_identity); int build_identity_get_component_path(plist_t build_identity, const char* component, char** path); int ipsw_extract_filesystem(const char* ipsw, plist_t build_identity, char** filesystem); +int ipsw_get_component_by_path(const char* ipsw, plist_t tss, const char* path, char** data, uint32_t* size); #ifdef __cplusplus } -- cgit v1.1-32-gdbae From 333b7b972a52162de00940dfa75a2cbd87efd9de Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 23:32:43 +0200 Subject: Try five times to retrieve validation plist if it failed This fixes hanging as the following payload message is not received initially but after polling the second time. --- src/asr.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/asr.c b/src/asr.c index 2331660..3f9b392 100644 --- a/src/asr.c +++ b/src/asr.c @@ -137,6 +137,7 @@ int asr_perform_validation(idevice_connection_t asr, const char* filesystem) { plist_t packet = NULL; plist_t packet_info = NULL; plist_t payload_info = NULL; + int attempts = 0; file = fopen(filesystem, "rb"); if (file == NULL) { @@ -172,6 +173,17 @@ int asr_perform_validation(idevice_connection_t asr, const char* filesystem) { return -1; } + if (packet == NULL) { + if (attempts < 5) { + info("Retrying to receive validation packet... %d\n", attempts); + attempts++; + sleep(1); + continue; + } + } + + attempts = 0; + node = plist_dict_get_item(packet, "Command"); if (!node || plist_get_node_type(node) != PLIST_STRING) { error("ERROR: Unable to find command node in validation request\n"); @@ -181,10 +193,7 @@ int asr_perform_validation(idevice_connection_t asr, const char* filesystem) { if (!strcmp(command, "OOBData")) { asr_handle_oob_data_request(asr, packet, file); - - plist_free(packet); - } else if(!strcmp(command, "Payload")) { plist_free(packet); break; -- cgit v1.1-32-gdbae From 9a404feafc3a738d5aad999491c6c0fd23b4da01 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 23:35:13 +0200 Subject: Add more known status messages and report them --- src/restore.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/restore.c b/src/restore.c index 40b24d3..4b5d0fd 100644 --- a/src/restore.c +++ b/src/restore.c @@ -348,8 +348,27 @@ int restore_handle_progress_msg(restored_client_t client, plist_t msg) { } int restore_handle_status_msg(restored_client_t client, plist_t msg) { + uint64_t value = 0; info("Got status message\n"); debug_plist(msg); + + plist_t node = plist_dict_get_item(msg, "Status"); + plist_get_uint_val(node, &value); + + switch(value) { + case 0: + info("Status: Restore Finished\n"); + break; + case 6: + info("Status: Disk Failure\n"); + break; + case 14: + info("Status: Fail\n"); + break; + default: + info("Unknown status message.\n"); + } + return 0; } @@ -366,8 +385,7 @@ int restore_send_filesystem(idevice_t device, const char* filesystem) { } info("Connected to ASR\n"); - // we don't really need to do anything with this, - // we're just clearing the output buffer + /* receive Initiate command message */ if (asr_receive(asr, &data) < 0) { error("ERROR: Unable to receive data from ASR\n"); asr_close(asr); -- cgit v1.1-32-gdbae From 853e499d97d2dd0c2b9dcc0ff3398f0295832132 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 23:37:31 +0200 Subject: Add more known progress messages and report them --- src/restore.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/restore.c b/src/restore.c index 4b5d0fd..0916665 100644 --- a/src/restore.c +++ b/src/restore.c @@ -29,6 +29,7 @@ #include "common.h" #include "restore.h" +#define WAIT_FOR_STORAGE 11 #define CREATE_PARTITION_MAP 12 #define CREATE_FILESYSTEM 13 #define RESTORE_IMAGE 14 @@ -39,6 +40,8 @@ #define UPDATE_BASEBAND 20 #define FINIALIZE_NAND 21 #define MODIFY_BOOTARGS 26 +#define LOAD_KERNEL_CACHE 27 +#define PARTITION_NAND_DEVICE 28 #define WAIT_FOR_NAND 29 #define UNMOUNT_FILESYSTEM 30 #define WAIT_FOR_DEVICE 33 @@ -271,6 +274,9 @@ int restore_open_with_timeout(struct idevicerestore_client_t* client) { const char* restore_progress_string(unsigned int operation) { switch (operation) { + case WAIT_FOR_STORAGE: + return "Waiting for Storage Device..."; + case CREATE_PARTITION_MAP: return "Creating partition map"; @@ -304,12 +310,18 @@ const char* restore_progress_string(unsigned int operation) { case UNMOUNT_FILESYSTEM: return "Unmounting filesystems"; + case PARTITION_NAND_DEVICE: + return "Partition NAND device"; + case WAIT_FOR_NAND: return "Waiting for NAND..."; case WAIT_FOR_DEVICE: return "Waiting for Device..."; + case LOAD_KERNEL_CACHE: + return "Loading kernelcache..."; + case LOAD_NOR: return "Loading NOR data to flash"; @@ -339,7 +351,6 @@ int restore_handle_progress_msg(restored_client_t client, plist_t msg) { if ((progress > 0) && (progress < 100)) { print_progress_bar((double) progress); - } else { info("%s\n", restore_progress_string(operation)); } -- cgit v1.1-32-gdbae From 9433af8a8c8f6d8718712d59547d3c333402551b Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 23:38:53 +0200 Subject: Only debug a plist if debugging flag was set --- src/asr.c | 9 +++++++-- src/restore.c | 12 ++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/asr.c b/src/asr.c index 3f9b392..f48170a 100644 --- a/src/asr.c +++ b/src/asr.c @@ -87,7 +87,9 @@ int asr_receive(idevice_connection_t asr, plist_t* data) { *data = request; - debug("Received %d bytes:\n%s\n", size, buffer); + debug("Received %d bytes:\n", size); + if (idevicerestore_debug) + debug_plist(request); free(buffer); return 0; } @@ -104,7 +106,8 @@ int asr_send(idevice_connection_t asr, plist_t* data) { } debug("Sent %d bytes:\n", size); - debug_plist(data); + if (idevicerestore_debug) + debug_plist(*data); free(buffer); return 0; } @@ -119,6 +122,8 @@ int asr_send_buffer(idevice_connection_t asr, const char* data, uint32_t size) { return -1; } + debug("Sent %d bytes buffer\n", bytes); + return 0; } diff --git a/src/restore.c b/src/restore.c index 0916665..0170ac3 100644 --- a/src/restore.c +++ b/src/restore.c @@ -559,7 +559,8 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t* } plist_dict_insert_item(dict, "NorImageData", norimage_array); - debug_plist(dict); + if (idevicerestore_debug) + debug_plist(dict); ret = restored_send(restore, dict); if (ret != RESTORE_E_SUCCESS) { @@ -610,7 +611,8 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev } else { // Unknown DataType!! debug("Unknown data request received\n"); - debug_plist(message); + if (idevicerestore_debug) + debug_plist(message); } } return 0; @@ -659,7 +661,8 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit node = plist_dict_get_item(message, "MsgType"); if (!node || plist_get_node_type(node) != PLIST_STRING) { debug("Unknown message received\n"); - debug_plist(message); + if (idevicerestore_debug) + debug_plist(message); plist_free(message); message = NULL; continue; @@ -689,7 +692,8 @@ int restore_device(struct idevicerestore_client_t* client, plist_t build_identit // at least the "previous error logs" messages usually end up here else { debug("Unknown message type received\n"); - debug_plist(message); + if (idevicerestore_debug) + debug_plist(message); } // finally, if any of these message handlers returned -1 then we encountered -- cgit v1.1-32-gdbae From ae0451c0b1de4419dd97614a4068a8f37522412e Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 23:39:29 +0200 Subject: Fix typo in nor data message --- src/restore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/restore.c b/src/restore.c index 0170ac3..d40d294 100644 --- a/src/restore.c +++ b/src/restore.c @@ -564,7 +564,7 @@ int restore_send_nor(restored_client_t restore, struct idevicerestore_client_t* ret = restored_send(restore, dict); if (ret != RESTORE_E_SUCCESS) { - error("ERROR: Unable to send kernelcache data\n"); + error("ERROR: Unable to send NOR image data data\n"); plist_free(dict); return -1; } -- cgit v1.1-32-gdbae From c41bfdcfc9c8da11249422c70de6bc0884ebd32b Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 9 Jul 2010 23:39:58 +0200 Subject: Correctly check when to send the NORData --- src/restore.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/restore.c b/src/restore.c index d40d294..bb3ed96 100644 --- a/src/restore.c +++ b/src/restore.c @@ -599,12 +599,14 @@ int restore_handle_data_request_msg(struct idevicerestore_client_t* client, idev } else if (!strcmp(type, "NORData")) { - if(client->flags & FLAG_EXCLUDE > 0) { + if((client->flags & FLAG_EXCLUDE) == 0) { + info("Sending NORData\n"); if(restore_send_nor(restore, client, build_identity) < 0) { error("ERROR: Unable to send NOR data\n"); return -1; } } else { + info("Not sending NORData... Quitting...\n"); client->flags |= FLAG_QUIT; } -- cgit v1.1-32-gdbae