Skip to content

Commit

Permalink
ipsw: fix version data parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Sep 27, 2013
1 parent 8b71e09 commit f68f234
Showing 1 changed file with 9 additions and 41 deletions.
50 changes: 9 additions & 41 deletions src/ipsw.c
Expand Up @@ -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");
Expand All @@ -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);
Expand Down

0 comments on commit f68f234

Please sign in to comment.