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(-) (limited to 'src/idevicerestore.c') 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 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'src/idevicerestore.c') 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; -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/idevicerestore.c') 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; } -- 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/idevicerestore.c') 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) { -- 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(-) (limited to 'src/idevicerestore.c') 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 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/idevicerestore.c') 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; -- cgit v1.1-32-gdbae