diff options
author | Nikias Bassen | 2023-11-02 12:54:47 +0100 |
---|---|---|
committer | Nikias Bassen | 2023-11-02 12:54:47 +0100 |
commit | c871c591e36d2a4083e3dda4c70144a0321ce70f (patch) | |
tree | ce6a990c037c78a84a5d2f99038a7e98e1425bf6 /src/ipsw.c | |
parent | 4072cd965eab44993700b980d8848b46ec3be72e (diff) | |
download | idevicerestore-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/ipsw.c')
-rw-r--r-- | src/ipsw.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -1308,7 +1308,8 @@ ipsw_file_handle_t ipsw_file_open(ipsw_archive_t ipsw, const char* path) { ipsw_file_handle_t handle = (ipsw_file_handle_t)calloc(1, sizeof(struct ipsw_file_handle)); if (ipsw->zip) { - int zindex = zip_name_locate(ipsw->zip, path, 0); + zip_stat_t zst; + zip_int64_t zindex = zip_name_locate(ipsw->zip, path, 0); if (zindex < 0) { error("ERROR: zip_name_locate: %s not found\n", path); free(handle); @@ -1320,8 +1321,12 @@ ipsw_file_handle_t ipsw_file_open(ipsw_archive_t ipsw, const char* path) free(handle); return NULL; } - + zip_stat_init(&zst); + zip_stat(ipsw->zip, path, 0, &zst); + handle->size = zst.size; + handle->seekable = (zst.comp_method == ZIP_CM_STORE); } else { + struct stat st; char *filepath = build_path(ipsw->path, path); handle->file = fopen(filepath, "rb"); free(filepath); @@ -1330,6 +1335,9 @@ ipsw_file_handle_t ipsw_file_open(ipsw_archive_t ipsw, const char* path) free(handle); return NULL; } + fstat(fileno(handle->file), &st); + handle->size = st.st_size; + handle->seekable = 1; } return handle; } @@ -1344,6 +1352,14 @@ void ipsw_file_close(ipsw_file_handle_t handle) free(handle); } +uint64_t ipsw_file_size(ipsw_file_handle_t handle) +{ + if (handle) { + return handle->size; + } + return 0; +} + int64_t ipsw_file_read(ipsw_file_handle_t handle, void* buffer, size_t size) { if (handle && handle->zfile) { |