diff options
author | Nikias Bassen | 2013-09-27 14:45:09 +0200 |
---|---|---|
committer | Nikias Bassen | 2013-09-27 14:45:09 +0200 |
commit | f68f234b4006d49be3c335df0d8bbff1b7376adf (patch) | |
tree | 90774c8032288ea2969ec5242b9e0ac31a10ef47 | |
parent | 8b71e0945b6ab843b3528b03fdb22d6ff02b0c55 (diff) | |
download | idevicerestore-f68f234b4006d49be3c335df0d8bbff1b7376adf.tar.gz idevicerestore-f68f234b4006d49be3c335df0d8bbff1b7376adf.tar.bz2 |
ipsw: fix version data parsing
-rw-r--r-- | src/ipsw.c | 50 |
1 files changed, 9 insertions, 41 deletions
@@ -278,69 +278,37 @@ int ipsw_get_latest_fw(plist_t version_data, const char* product, char** fwurl, memset(sha1buf, '\0', 20); } - plist_t n1 = plist_access_path(version_data, 2, "MobileDeviceMajorVersionsByProductType", product); - if (!n1 || (plist_dict_get_size(n1) == 0)) { - error("%s: ERROR: Can't find MobileDeviceMajorVersionsByProductType/%s dict in version data\n", __func__, product); + plist_t n1 = plist_dict_get_item(version_data, "MobileDeviceSoftwareVersionsByVersion"); + if (!n1) { + error("%s: ERROR: Can't find MobileDeviceSoftwareVersionsByVersion dict in version data\n", __func__); return -1; } - char* strval = NULL; - plist_t n2 = plist_dict_get_item(n1, "SameAs"); - if (n2) { - plist_get_string_val(n2, &strval); - } - if (strval) { - n1 = plist_access_path(version_data, 2, "MobileDeviceMajorVersionsByProductType", strval); - free(strval); - strval = NULL; - if (!n1 || (plist_dict_get_size(n1) == 0)) { - error("%s: ERROR: Can't find MobileDeviceMajorVersionsByProductType/%s dict in version data\n", __func__, product); - return -1; - } - } - plist_dict_iter iter = NULL; plist_dict_new_iter(n1, &iter); if (!iter) { error("%s: ERROR: Can't get dict iter\n", __func__); return -1; } - n2 = NULL; char* key = NULL; + long long unsigned int major = 0; plist_t val = NULL; do { plist_dict_next_item(n1, iter, &key, &val); if (key) { - n2 = val; + long long unsigned int v = strtoull(key, NULL, 10); + if (v > major) + major = v; free(key); } } while (val); free(iter); - if (!n2) { - error("%s: ERROR: Can't get last node?!\n", __func__); - return -1; - } - - uint64_t major = 0; - if (plist_get_node_type(n2) == PLIST_ARRAY) { - uint32_t sz = plist_array_get_size(n2); - plist_t n3 = plist_array_get_item(n2, sz-1); - plist_get_uint_val(n3, &major); - } else { - plist_get_uint_val(n2, &major); - } - if (major == 0) { error("%s: ERROR: Can't find major version?!\n", __func__); return -1; } - if (major == 11) { - /* FIXME workaround as with the iOS 7 release, Apple broke their own XML structure and logic */ - major = 12; - } - char majstr[32]; // should be enough for a uint64_t value sprintf(majstr, FMT_qu, (long long unsigned int)major); n1 = plist_access_path(version_data, 7, "MobileDeviceSoftwareVersionsByVersion", majstr, "MobileDeviceSoftwareVersions", product, "Unknown", "Universal", "Restore"); @@ -355,13 +323,13 @@ int ipsw_get_latest_fw(plist_t version_data, const char* product, char** fwurl, } } - n2 = plist_dict_get_item(n1, "BuildVersion"); + plist_t n2 = plist_dict_get_item(n1, "BuildVersion"); if (!n2 || (plist_get_node_type(n2) != PLIST_STRING)) { error("%s: ERROR: Can't get build version node?!\n", __func__); return -1; } - strval = NULL; + char* strval = NULL; plist_get_string_val(n2, &strval); n1 = plist_access_path(version_data, 5, "MobileDeviceSoftwareVersionsByVersion", majstr, "MobileDeviceSoftwareVersions", product, strval); |