summaryrefslogtreecommitdiffstats
path: root/src/restore.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-11-02 12:54:47 +0100
committerGravatar Nikias Bassen2023-11-02 12:54:47 +0100
commitc871c591e36d2a4083e3dda4c70144a0321ce70f (patch)
treece6a990c037c78a84a5d2f99038a7e98e1425bf6 /src/restore.c
parent4072cd965eab44993700b980d8848b46ec3be72e (diff)
downloadidevicerestore-c871c591e36d2a4083e3dda4c70144a0321ce70f.tar.gz
idevicerestore-c871c591e36d2a4083e3dda4c70144a0321ce70f.tar.bz2
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.
Diffstat (limited to 'src/restore.c')
-rw-r--r--src/restore.c17
1 files changed, 16 insertions, 1 deletions
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 <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <libgen.h>
#include <libimobiledevice/restore.h>
#ifdef HAVE_REVERSE_PROXY
#include <libimobiledevice/reverse_proxy.h>
@@ -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");