From a915466200f3105949fd4c95d1b5b2087a6c7e6b Mon Sep 17 00:00:00 2001 From: Aaron Burghardt Date: Tue, 1 Oct 2013 06:12:26 -0400 Subject: Prefer the WTF file in the restore IPSW, fallback to downloading the WTF IPSW. Signed-off-by: Martin Szulecki --- src/idevicerestore.c | 80 +++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/src/idevicerestore.c b/src/idevicerestore.c index c32db88..b27ea8c 100644 --- a/src/idevicerestore.c +++ b/src/idevicerestore.c @@ -207,47 +207,55 @@ int idevicerestore_start(struct idevicerestore_client_t* client) return -1; } - char* s_wtfurl = NULL; - plist_t wtfurl = plist_access_path(client->version_data, 7, "MobileDeviceSoftwareVersionsByVersion", "5", "RecoverySoftwareVersions", "WTF", "304218112", "5", "FirmwareURL"); - if (wtfurl && (plist_get_node_type(wtfurl) == PLIST_STRING)) { - plist_get_string_val(wtfurl, &s_wtfurl); - } - if (!s_wtfurl) { - info("Using hardcoded x12220000_5_Recovery.ipsw URL\n"); - s_wtfurl = strdup("http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-6618.20090617.Xse7Y/x12220000_5_Recovery.ipsw"); - } - - // make a local file name - char* fnpart = strrchr(s_wtfurl, '/'); - if (!fnpart) { - fnpart = "x12220000_5_Recovery.ipsw"; - } else { - fnpart++; - } - struct stat fst; - char wtfipsw[1024]; - if (client->cache_dir) { - if (stat(client->cache_dir, &fst) < 0) { - mkdir_with_parents(client->cache_dir, 0755); - } - strcpy(wtfipsw, client->cache_dir); - strcat(wtfipsw, "/"); - strcat(wtfipsw, fnpart); - } else { - strcpy(wtfipsw, fnpart); - } - if (stat(wtfipsw, &fst) != 0) { - download_to_file(s_wtfurl, wtfipsw, 0); - } - char wtfname[256]; sprintf(wtfname, "Firmware/dfu/WTF.s5l%04xxall.RELEASE.dfu", cpid); unsigned char* wtftmp = NULL; unsigned int wtfsize = 0; - ipsw_extract_to_memory(wtfipsw, wtfname, &wtftmp, &wtfsize); + + // Prefer to get WTF file from the restore IPSW + ipsw_extract_to_memory(client->ipsw, wtfname, &wtftmp, &wtfsize); if (!wtftmp) { - error("ERROR: Could not extract WTF\n"); - } else { + // Download WTF IPSW + char* s_wtfurl = NULL; + plist_t wtfurl = plist_access_path(client->version_data, 7, "MobileDeviceSoftwareVersionsByVersion", "5", "RecoverySoftwareVersions", "WTF", "304218112", "5", "FirmwareURL"); + if (wtfurl && (plist_get_node_type(wtfurl) == PLIST_STRING)) { + plist_get_string_val(wtfurl, &s_wtfurl); + } + if (!s_wtfurl) { + info("Using hardcoded x12220000_5_Recovery.ipsw URL\n"); + s_wtfurl = strdup("http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iPhone/061-6618.20090617.Xse7Y/x12220000_5_Recovery.ipsw"); + } + + // make a local file name + char* fnpart = strrchr(s_wtfurl, '/'); + if (!fnpart) { + fnpart = "x12220000_5_Recovery.ipsw"; + } else { + fnpart++; + } + struct stat fst; + char wtfipsw[1024]; + if (client->cache_dir) { + if (stat(client->cache_dir, &fst) < 0) { + mkdir_with_parents(client->cache_dir, 0755); + } + strcpy(wtfipsw, client->cache_dir); + strcat(wtfipsw, "/"); + strcat(wtfipsw, fnpart); + } else { + strcpy(wtfipsw, fnpart); + } + if (stat(wtfipsw, &fst) != 0) { + download_to_file(s_wtfurl, wtfipsw, 0); + } + + ipsw_extract_to_memory(wtfipsw, wtfname, &wtftmp, &wtfsize); + if (!wtftmp) { + error("ERROR: Could not extract WTF\n"); + } + } + + if (wtftmp) { if (dfu_send_buffer(client, wtftmp, wtfsize) != 0) { error("ERROR: Could not send WTF...\n"); } -- cgit v1.1-32-gdbae