From c871c591e36d2a4083e3dda4c70144a0321ce70f Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 2 Nov 2023 12:54:47 +0100 Subject: Extract OS component when using older ipsw archives Older ipsw archives have the root filesystem stored in compressed format rather than just "stored". The "Verifying Filesystem" step would then fail as compressed files are not seekable in ZIP files. This commit introduces a detection for this and has the filesystem extracted should it be required. If not using a cache path, the temp file used for extraction will be deleted after the procedure is completed. --- src/restore.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/restore.c') diff --git a/src/restore.c b/src/restore.c index 8063f08..9e0268a 100644 --- a/src/restore.c +++ b/src/restore.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #ifdef HAVE_REVERSE_PROXY #include @@ -903,13 +904,23 @@ int restore_send_filesystem(struct idevicerestore_client_t* client, idevice_t de info("About to send filesystem...\n"); + ipsw_archive_t ipsw_dummy = NULL; ipsw_file_handle_t file = NULL; char* fsname = NULL; if (build_identity_get_component_path(build_identity, "OS", &fsname) < 0) { error("ERROR: Unable to get path for filesystem component\n"); return -1; } - file = ipsw_file_open(client->ipsw, fsname); + if (client->filesystem) { + char* path = strdup(client->filesystem); + char* fsname_base = path_get_basename(path); + char* parent_dir = dirname(path); + ipsw_dummy = ipsw_open(parent_dir); + free(path); + file = ipsw_file_open(ipsw_dummy, fsname_base); + } else { + file = ipsw_file_open(client->ipsw, fsname); + } if (!file) { error("ERROR: Unable to open '%s' in ipsw\n", fsname); free(fsname); @@ -917,6 +928,7 @@ int restore_send_filesystem(struct idevicerestore_client_t* client, idevice_t de if (asr_open_with_timeout(device, &asr) < 0) { ipsw_file_close(file); + ipsw_close(ipsw_dummy); error("ERROR: Unable to connect to ASR\n"); return -1; } @@ -929,6 +941,7 @@ int restore_send_filesystem(struct idevicerestore_client_t* client, idevice_t de info("Validating the filesystem\n"); if (asr_perform_validation(asr, file) < 0) { ipsw_file_close(file); + ipsw_close(ipsw_dummy); error("ERROR: ASR was unable to validate the filesystem\n"); asr_free(asr); return -1; @@ -940,11 +953,13 @@ int restore_send_filesystem(struct idevicerestore_client_t* client, idevice_t de info("Sending filesystem now...\n"); if (asr_send_payload(asr, file) < 0) { ipsw_file_close(file); + ipsw_close(ipsw_dummy); error("ERROR: Unable to send payload to ASR\n"); asr_free(asr); return -1; } ipsw_file_close(file); + ipsw_close(ipsw_dummy); info("Done sending filesystem\n"); -- cgit v1.1-32-gdbae