Compare commits

..
64 Commits
Author SHA1 Message Date
Nathan Moinvaziri 30e859be0b Version 2.3.2. 2018-05-29 08:48:05 -07:00
Nathan Moinvaziri 5b204622cc Modified pkcrypt to use crc32 table from zlib or lzma. 2018-05-23 20:39:12 -07:00
Nathan Moinvaziri b07ab3e9b9 Merge branch 'dev' of https://github.com/nmoinvaz/minizip into dev 2018-05-23 20:27:23 -07:00
Nathan Moinvaziri 3dc4334d38 Rename crypt to pkcrypt. 2018-05-23 20:27:17 -07:00
Nathan Moinvaziri ca30682447 Fixed formatting 2018-05-23 20:23:41 -07:00
Nathan Moinvaziri 0e5c9dcdf4 Renamed traditional PKware encryption to pkcrypt.
Don't link mz_os_rand if encryption is not turned on. #267
2018-05-23 20:21:48 -07:00
Nathan Moinvaziri ea99a46b6d Define possibly missing #defines from zlib header. #264 2018-05-22 14:19:50 -07:00
Nathan Moinvaziri 23bc9fd943 Merge pull request #266 from asmaloney/dev
Fix build on macOS
2018-05-22 13:00:00 -07:00
Andy Maloney cfcb729f79 Fix build on macOS
(Only Windows needs this __declspec)
2018-05-22 13:01:03 -04:00
Nathan Moinvaziri 51521bddc8 Fixed formatting. 2018-05-22 09:47:53 -07:00
Nathan Moinvaziri 41331dd3ec Fixed issues not being able to compile without zlib. #264 2018-05-22 09:46:03 -07:00
Nathan Moinvaziri 9c155991d7 Merge branch 'master' into dev 2018-05-22 09:35:45 -07:00
Nathan Moinvaziri 43e787bd88 Merge pull request #265 from asmaloney/asm_master
Partial fix for building without zlib
2018-05-22 09:32:42 -07:00
Andy Maloney 3909c23817 Partial fix for building without zlib
(See issue nmoinvaz/minizip#264)
2018-05-22 09:02:09 -04:00
Nathan Moinvaziri c0d3dbf537 Make #define names consistent. 2018-05-09 20:06:12 -07:00
Nathan Moinvaziri 0388124aad Simplify parsing of filename from path. 2018-05-09 20:03:26 -07:00
Nathan Moinvaziri e1aad8c445 Version 2.3.1. 2018-05-09 19:48:55 -07:00
Nathan Moinvaziri b5fb12503d Fixed more warnings. #263 2018-05-09 09:52:43 -07:00
Nathan Moinvaziri bd2f162009 Fixed more warnings. #263 2018-05-09 09:45:15 -07:00
Nathan Moinvaziri 408940f16c Fixed more warnings. #263 2018-05-09 09:42:31 -07:00
Nathan Moinvaziri a710bd714a Fixed reported warnings. #263 2018-05-09 00:46:47 -07:00
Nathan Moinvaziri 7a3b698578 Fixed more mac warnings. #263 2018-05-09 00:45:02 -07:00
Nathan Moinvaziri e275fcf017 Removed ZIP_UNUSED. #263 2018-05-09 00:34:16 -07:00
Nathan Moinvaziri 0e2e1a0b05 Fixed compiler warnings on mac. #263 2018-05-09 00:31:25 -07:00
Nathan Moinvaziri 3431a6635b Fixed more compiler warnings. #263 2018-05-06 16:59:31 -07:00
Nathan Moinvaziri 521a42a4c3 Fixed some compiler warnings. #263 2018-05-06 16:32:46 -07:00
Nathan Moinvaziri a4b83e8e95 Version 2.3.0. 2018-05-03 17:59:04 -07:00
Nathan Moinvaziri 121e088a7d Add back auto detection of zip64. #258 2018-05-03 17:57:20 -07:00
Nathan Moinvaziri 46f714348e Simplification & fixed formatting. #258 2018-05-03 17:24:32 -07:00
Nathan Moinvaziri a56a08cf79 Allow configuration of zip64 support. #258 2018-05-03 09:35:37 -07:00
Nathan Moinvaziri 8a50b4b5df Merge pull request #261 from vszakats/ws2
whitespace fixes
2018-05-02 20:09:48 -07:00
Nathan Moinvaziri 37ceb026db Merge branch 'dev' into ws2 2018-05-02 20:09:25 -07:00
Nathan Moinvaziri 586300a787 Use MZ_UNUSED where applicable. #262 2018-05-02 20:07:45 -07:00
Nathan Moinvaziri 92c8d77cfb Merge pull request #262 from vszakats/warn2
silence various warnings
2018-05-02 20:04:57 -07:00
Nathan Moinvaziri c546a57f90 Fixed wrong defined MZ_ALLOC and MZ_FREE. #249 2018-05-02 20:02:30 -07:00
Nathan Moinvaziri 5244fc00c4 Added MZ_UNUSED #262
Added #define for malloc and free. #249
2018-05-02 20:01:35 -07:00
Viktor Szakats 4c76400cce silence various warnings
- unused parameters
- trivial const stripping cases
- missing NULL initializers from vtbls
- missing static scope for vtbls

Missing newlines at EOF addressed in a separate PR.
It's be nice to replace `ZIP_UNUSED var` and `(void)var`
with a global and non-gcc-specific solution, such as:
   #define MZ_UNUSED(symbol)  (void)symbol
2018-05-02 21:40:29 +00:00
Nathan Moinvaziri 240b3b6709 Added comment for slash appending for dirs. 2018-05-02 13:38:14 -07:00
Nathan Moinvaziri e54582384a Remove any existing slash at the end of filename. 2018-05-02 13:07:03 -07:00
Nathan Moinvaziri 3ad1a92279 Append slash to directories for compatibility. #257 2018-05-02 13:04:41 -07:00
Viktor Szakats 447dd06750 whitespace fixes
- remove line-ending spaces
- always have a file-ending newline
- remove duplicate file-ending newlines
2018-05-02 19:59:38 +00:00
Nathan Moinvaziri 4827f71a08 Fixed formatting. 2018-05-02 10:50:47 -07:00
Nathan Moinvaziri bb3b75bc09 Fixed directory compression method.
Move zip attribute detection to mz_zip. #257
2018-05-02 10:48:51 -07:00
Nathan Moinvaziri b7bd0421c5 Merge branch 'dev' of https://github.com/nmoinvaz/minizip into dev 2018-05-02 09:55:15 -07:00
Nathan Moinvaziri 9a3ae75a48 Fixed print out of directories. #257 2018-05-02 09:54:44 -07:00
Nathan Moinvaziri 120bea1a6f Merge pull request #260 from vszakats/castwarn
fix cast warning (seen with LLVM/Clang)
2018-05-02 09:26:21 -07:00
Nathan Moinvaziri 4a41245099 Added msdos host system and dir detection. 2018-05-02 09:24:09 -07:00
Viktor Szakats 0f0535fcaa fix cast warning (seen with LLVM/Clang)
```
mz_compat.c:390:62: warning: passing 'uint32_t *' (aka 'unsigned int *') to parameter of type
      'int32_t *' (aka 'int *') converts between pointers to integer types with different sign [-Wpointer-sign]
        err = mz_zip_get_disk_number_with_cd(compat->handle, &pglobal_info->number_disk_with_CD);
                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mz_zip.h:112:70: note: passing argument to parameter 'disk_number_with_cd' here
extern int32_t mz_zip_get_disk_number_with_cd(void *handle, int32_t *disk_number_with_cd);
                                                                     ^
```
2018-05-02 13:15:58 +00:00
Nathan Moinvaziri 8d8deb4e5d Added listing of attributes. 2018-05-01 21:54:15 -07:00
Nathan Moinvaziri 83bce6e82a Allow version_needed to be less than customized. #258 2018-05-01 18:10:17 -07:00
Nathan Moinvaziri 739f03f951 Updated comment. 2018-05-01 13:57:28 -07:00
Nathan Moinvaziri 7583be518c Fixed is directory check on linux. 2018-05-01 13:55:28 -07:00
Nathan Moinvaziri 0619c3e6c4 Merge branch 'dev' of https://github.com/nmoinvaz/minizip into dev 2018-05-01 13:51:13 -07:00
Nathan Moinvaziri e33916b608 Added support for directory entries in minizip. #257
Added support for file attributes.
2018-05-01 13:45:08 -07:00
Nathan Moinvaziri 596f19f79e Merge pull request #256 from vszakats/rawlzmaflag
fix to set MZ_ZIP_FLAG_LZMA_EOS_MARKER flag in raw mode
2018-04-30 09:34:30 -07:00
Viktor Szakats 2884e67a1a fix to set MZ_ZIP_FLAG_LZMA_EOS_MARKER flag in raw mode
in function mz_zip_entry_write_open()

Fixes https://github.com/nmoinvaz/minizip/issues/255
2018-04-30 08:16:09 +00:00
Nathan Moinvaziri ae5740b19c Merge pull request #253 from vszakats/eolws
remove whitespace @ eol
2018-04-24 08:50:47 -07:00
Nathan Moinvaziri b14ded7d01 Merge pull request #254 from vszakats/patch-1
README.md: switch an URL to use HTTPS
2018-04-24 08:49:48 -07:00
Viktor Szakats 914049d19c README.md: switch an URL to use HTTPS 2018-04-24 14:20:35 +02:00
Viktor Szakats 915b82e95b remove whitespace @ eol 2018-04-24 10:02:39 +00:00
Nathan Moinvaziri 0f09a00810 Fixed formatting. 2018-04-23 18:48:30 -07:00
Nathan Moinvaziri f5f23217b3 Fixed formatting. 2018-04-23 18:46:09 -07:00
Nathan Moinvaziri 5d362f43eb Merge pull request #252 from vszakats/fixes
improve compatibility with original minizip
2018-04-23 18:31:31 -07:00
Viktor Szakats ce26dba5ba improve compatibility with original minizip
* Fix NULL pointer dereference when calling zipOpen*()
  or unzOpen2*() with NULL filefunc table.
* Rename dos_date to dosDate in zip/unzip structures to
  be compatible with original minizip.
* Add tm struct timestamps to zip/unzip structures and
  populate them with the dosDate value for unzip and
  use the value passed into it on zip, if dosDate is
  zero (mimicing original minizip behaviour.)
* Change zipWriteInFileInZip() return value to be a
  status code (ZIP_OK or ZIP_ERRNO) instead of the
  number of bytes written. This way it's minizip
  compatible.
* Add zipCloseFileInZipRaw64() compatibility wrapper.
* Add these compatibility functions:
  unzGetOffset()
  unzGetOffset64()
  unzSetOffset()
  unzSetOffset64()
* Add stub for compatibility: unzGetLocalExtrafield()
  It will always return zero for now.
* Add original minizip types for compatiblity:
  tm_unz, tm_zip, ZPOS64_T
* Add these minizip (non-compatiblity) APIs:
  mz_zip_get_entry()
  mz_zip_goto_entry()
* zipOpenNewFileInZip*() to use the default filename of
  "-" if filename parameter was NULL. For minizip
  compatibility.
* Fix mz_zip_entry_open_int() and mz_zip_entry_read_open()
  failing with MZ_PARAM_ERROR in raw mode
* Add/cleanup some date-related comments
* mz_zip_time_t_to_tm() to clear the `tm` structure in
  case localtime() call failed.
* Fix mz_zip_tm_to_dosdate() to do the date validation
  on the normalized date (the year in particular), not on
  the raw value passed by the caller. This makes it work
  correctly when year is passed as-is, such as 1990.

The reference minizip was the version that comes with
the latest zlib, currently at 1.2.11.
2018-04-23 22:38:05 +00:00
39 changed files with 1319 additions and 905 deletions
+15 -13
View File
@@ -5,12 +5,12 @@
#***************************************************************************
cmake_minimum_required(VERSION 2.8)
option(USE_ZLIB "Enables building with ZLIB library" ON)
option(USE_BZIP2 "Enables building with BZIP2 library" ON)
option(USE_LZMA "Enables building with LZMA library" ON)
option(USE_CRYPT "Enables building with PKWARE traditional encryption" ON)
option(USE_AES "Enables building with AES library" ON)
option(BUILD_TEST "Enables building of minizip executable." OFF)
option(USE_ZLIB "Enables ZLIB compression" ON)
option(USE_BZIP2 "Enables BZIP2 compression" ON)
option(USE_LZMA "Enables LZMA compression" ON)
option(USE_PKCRYPT "Enables PKWARE traditional encryption" ON)
option(USE_AES "Enables AES encryption" ON)
option(BUILD_TEST "Builds minizip test executable" OFF)
# Set a consistent MACOSX_RPATH default across all CMake versions.
# When CMake 2.8.12 is required, change this default to 1.
@@ -30,7 +30,7 @@ set(INSTALL_MAN_DIR ${CMAKE_INSTALL_MANDIR} CACHE PATH "Installation directory f
set(INSTALL_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE PATH "Installation directory for pkgconfig (.pc) files")
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/minizip CACHE PATH "Installation directory for cmake files.")
set(VERSION "2.2.9")
set(VERSION "2.3.2")
# Set cmake debug postfix to d
set(CMAKE_DEBUG_POSTFIX "d")
@@ -58,7 +58,6 @@ set(MINIZIP_SRC
mz_strm_mem.c
mz_strm_posix.c
mz_strm_split.c
mz_strm_zlib.c
mz_zip.c)
set(MINIZIP_PUBLIC_HEADERS
@@ -70,7 +69,6 @@ set(MINIZIP_PUBLIC_HEADERS
mz_strm_mem.h
mz_strm_posix.h
mz_strm_split.h
mz_strm_zlib.h
mz_zip.h)
if(WIN32)
@@ -117,11 +115,11 @@ if(UNIX)
endif()
endif()
if(USE_CRYPT)
add_definitions(-DHAVE_CRYPT)
if(USE_PKCRYPT)
add_definitions(-DHAVE_PKCRYPT)
list(APPEND MINIZIP_SRC "mz_strm_crypt.c")
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_crypt.h")
list(APPEND MINIZIP_SRC "mz_strm_pkcrypt.c")
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_pkcrypt.h")
endif()
if(USE_AES)
@@ -156,6 +154,9 @@ endif()
if(USE_ZLIB)
add_definitions(-DHAVE_ZLIB)
list(APPEND MINIZIP_SRC "mz_strm_zlib.c")
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_zlib.h")
include(CheckFunctionExists)
set(CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB)
CHECK_FUNCTION_EXISTS(z_get_crc_table
@@ -165,6 +166,7 @@ if(USE_ZLIB)
add_definitions(-DZ_PREFIX)
endif()
endif()
if(USE_BZIP2)
add_definitions(-DHAVE_BZIP2)
add_definitions(-DBZ_NO_STDIO)
+1 -1
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Minizip'
s.version = '2.2.9'
s.version = '2.3.2'
s.license = 'zlib'
s.summary = 'Minizip contrib in zlib with the latest bug fixes and advanced features'
s.description = <<-DESC
+16 -4
View File
@@ -1,4 +1,4 @@
# Minizip 2.2.9
# Minizip 2.3.2
This library is a refactoring of the minizip contribution found in the zlib distribution and is supported on Windows, macOS, and Linux. The motivation for this work has been the inclusion of advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. It is based on the original work of [Gilles Vollant](http://www.winimage.com/zLibDll/minizip.html) that has been contributed to by many people over the years.
@@ -14,9 +14,21 @@ To generate the project files for your platform and IDE download and run cmake i
```
cmake .
cmake . -DBUILD_TEST=ON
cmake --build .
```
## Build Options
| Name | Description | Default Value |
|:- |:-|:-:|
| USE_ZLIB | Enables ZLIB compression | ON |
| USE_BZIP2 | Enables BZIP2 compression | ON |
| USE_LZMA | Enables LZMA compression | ON |
| USE_PKCRYPT | Enables PKWARE traditional encryption | ON |
| USE_AES | Enables AES encryption | ON |
| BUILD_TEST | Builds minizip test executable | OFF |
## Contents
| File(s) | Description | Required |
@@ -29,10 +41,10 @@ cmake --build .
| mz_strm_aes.\* | WinZIP AES stream | No |
| mz_strm_buf.\* | Buffered stream | No |
| mz_strm_bzip.\* | BZIP2 stream using libbzip2 | No |
| mz_strm_crypt.\* | PKWARE traditional encryption stream | No |
| mz_strm_lzma.\* | LZMA stream using liblzma | zlib or liblzma |
| mz_strm_mem.\* | Memory stream | Yes |
| mz_strm_split.\* | Disk splitting stream | No |
| mz_strm_pkcrypt.\* | PKWARE traditional encryption stream | No |
| mz_strm_posix.\* | File stream using Posix functions | Non-windows systems |
| mz_strm_win32.\* | File stream using Win32 API functions | Windows systems |
| mz_strm_zlib.\* | Deflate stream using zlib | zlib or liblzma |
@@ -54,7 +66,7 @@ cmake --build .
### Encryption
#### [WinZIP AES Encryption](http://www.winzip.com/aes_info.htm)
#### [WinZIP AES Encryption](https://www.winzip.com/aes_info.htm)
+ Requires ``cmake . -DUSE_AES=ON`` or ``#define HAVE_AES``
+ Requires Brian Gladman's [AES](https://github.com/BrianGladman/aes) and [SHA](https://github.com/BrianGladman/sha) libraries
@@ -68,7 +80,7 @@ To disable encryption use the following cmake commands:
```
cmake . -DUSE_AES=OFF
cmake . -DUSE_CRYPT=OFF
cmake . -DUSE_PKCRYPT=OFF
```
### NTFS Timestamps
+113 -113
View File
@@ -1,5 +1,5 @@
/* minizip.c
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -32,13 +32,13 @@
/***************************************************************************/
void minizip_banner()
void minizip_banner(void)
{
printf("Minizip %s - https://github.com/nmoinvaz/minizip\n", MZ_VERSION);
printf("---------------------------------------------------\n");
}
void minizip_help()
void minizip_help(void)
{
printf("Usage : minizip [-x -d dir|-l] [-o] [-a] [-j] [-0 to -9] [-b|-m] [-k 512] [-p pwd] [-s] file.zip [files]\n\n" \
" -x Extract files\n" \
@@ -47,7 +47,7 @@ void minizip_help()
" -o Overwrite existing files\n" \
" -a Append to existing zip file\n" \
" -u Buffered reading and writing\n" \
" -j Exclude path of files\n" \
" -i Include full path of files\n" \
" -0 Store only\n" \
" -1 Compress faster\n" \
" -9 Compress better\n" \
@@ -68,10 +68,10 @@ void minizip_help()
/***************************************************************************/
typedef struct minizip_opt_s {
uint8_t exclude_path;
int16_t include_path;
int16_t compress_level;
int16_t compress_method;
uint8_t overwrite;
int16_t overwrite;
#ifdef HAVE_AES
int16_t aes;
#endif
@@ -79,48 +79,33 @@ typedef struct minizip_opt_s {
/***************************************************************************/
int32_t minizip_add_file(void *handle, const char *path, const char *password, minizip_opt *options)
int32_t minizip_add_path(void *handle, const char *path, const char *filenameinzip, const char *password, int16_t is_dir, minizip_opt *options)
{
mz_zip_file file_info = { 0 };
mz_zip_file file_info;
int32_t read = 0;
int32_t written = 0;
int32_t err = MZ_OK;
int32_t err_close = MZ_OK;
void *stream = NULL;
const char *filenameinzip = NULL;
char buf[INT16_MAX];
// Construct the filename that our file will be stored in the zip as.
// The path name saved, should not include a leading slash.
// If it did, windows/xp and dynazip couldn't read the zip file.
memset(&file_info, 0, sizeof(file_info));
filenameinzip = path;
// The path name saved, should not include a leading slash.
// If it did, windows/xp and dynazip couldn't read the zip file.
if (filenameinzip == NULL)
filenameinzip = path;
while (filenameinzip[0] == '\\' || filenameinzip[0] == '/')
filenameinzip += 1;
// Should the file be stored with any path info at all?
if (options->exclude_path)
{
const char *match = NULL;
const char *last_slash = NULL;
for (match = filenameinzip; *match; match += 1)
{
if (*match == '\\' || *match == '/')
last_slash = match;
}
if (last_slash != NULL)
filenameinzip = last_slash + 1; // base filename follows last slash
}
// Get information about the file on disk so we can store it in zip
printf("Adding: %s\n", filenameinzip);
file_info.version_madeby = MZ_VERSION_MADEBY;
file_info.compression_method = options->compress_method;
file_info.filename = (char *)filenameinzip;
file_info.filename = filenameinzip;
file_info.uncompressed_size = mz_os_get_file_size(path);
#ifdef HAVE_AES
@@ -128,8 +113,9 @@ int32_t minizip_add_file(void *handle, const char *path, const char *password, m
file_info.aes_version = MZ_AES_VERSION;
#endif
mz_os_get_file_date(path, &file_info.modified_date, &file_info.accessed_date,
mz_os_get_file_date(path, &file_info.modified_date, &file_info.accessed_date,
&file_info.creation_date);
mz_os_get_file_attribs(path, &file_info.external_fa);
// Add to zip
err = mz_zip_entry_write_open(handle, &file_info, options->compress_level, password);
@@ -139,43 +125,45 @@ int32_t minizip_add_file(void *handle, const char *path, const char *password, m
return err;
}
mz_stream_os_create(&stream);
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
if (err == MZ_OK)
if (!is_dir)
{
// Read contents of file and write it to zip
do
mz_stream_os_create(&stream);
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
if (err == MZ_OK)
{
read = mz_stream_os_read(stream, buf, sizeof(buf));
if (read < 0)
// Read contents of file and write it to zip
do
{
err = mz_stream_os_error(stream);
printf("Error %d in reading %s\n", err, filenameinzip);
break;
}
if (read == 0)
break;
read = mz_stream_os_read(stream, buf, sizeof(buf));
if (read < 0)
{
err = mz_stream_os_error(stream);
printf("Error %d in reading %s\n", err, filenameinzip);
break;
}
if (read == 0)
break;
written = mz_zip_entry_write(handle, buf, read);
if (written != read)
{
err = mz_stream_os_error(stream);
printf("Error in writing %s in the zip file (%d)\n", filenameinzip, err);
break;
}
written = mz_zip_entry_write(handle, buf, read);
if (written != read)
{
err = mz_stream_os_error(stream);
printf("Error in writing %s in the zip file (%d)\n", filenameinzip, err);
break;
}
} while (err == MZ_OK);
mz_stream_os_close(stream);
}
else
{
printf("Error in opening %s for reading\n", path);
}
while (err == MZ_OK);
mz_stream_os_close(stream);
mz_stream_os_delete(&stream);
}
else
{
printf("Error in opening %s for reading\n", path);
}
mz_stream_os_delete(&stream);
err_close = mz_zip_entry_close(handle);
if (err_close != MZ_OK)
@@ -187,16 +175,43 @@ int32_t minizip_add_file(void *handle, const char *path, const char *password, m
return err;
}
int32_t minizip_add(void *handle, const char *path, const char *password, minizip_opt *options, uint8_t recursive)
int32_t minizip_add(void *handle, const char *path, const char *root_path, const char *password, minizip_opt *options, uint8_t recursive)
{
DIR *dir = NULL;
struct dirent *entry = NULL;
int32_t err = 0;
int32_t err = MZ_OK;
int16_t is_dir = 0;
char full_path[320];
const char *filename = NULL;
const char *filenameinzip = path;
if (mz_os_is_dir(path) != MZ_OK)
return minizip_add_file(handle, path, password, options);
if (mz_os_is_dir(path) == MZ_OK)
is_dir = 1;
// Construct the filename that our file will be stored in the zip as
if (root_path == NULL)
root_path = path;
// Should the file be stored with any path info at all?
if (!options->include_path)
{
if (!is_dir && root_path == path)
{
if (mz_path_get_filename(filenameinzip, &filename) == MZ_OK)
filenameinzip = filename;
}
else
{
filenameinzip += strlen(root_path);
}
}
if (*filenameinzip != 0)
err = minizip_add_path(handle, path, filenameinzip, password, is_dir, options);
if (!is_dir)
return err;
dir = mz_os_open_dir(path);
@@ -218,7 +233,7 @@ int32_t minizip_add(void *handle, const char *path, const char *password, minizi
if (!recursive && mz_os_is_dir(full_path))
continue;
err = minizip_add(handle, full_path, password, options, recursive);
err = minizip_add(handle, full_path, root_path, password, options, recursive);
if (err != MZ_OK)
return err;
}
@@ -235,7 +250,7 @@ int32_t minizip_list(void *handle)
uint32_t ratio = 0;
int16_t level = 0;
int32_t err = MZ_OK;
struct tm tmu_date = { 0 };
struct tm tmu_date;
const char *string_method = NULL;
char crypt = ' ';
@@ -248,8 +263,8 @@ int32_t minizip_list(void *handle)
return err;
}
printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
printf(" Length Method Size Attribs Ratio Date Time CRC-32 Name\n");
printf(" ------ ------ ---- ------- ----- ---- ---- ------ ----\n");
while (err == MZ_OK)
{
@@ -261,9 +276,10 @@ int32_t minizip_list(void *handle)
break;
}
ratio = 0;
if (file_info->uncompressed_size > 0)
ratio = (uint32_t)((file_info->compressed_size * 100) / file_info->uncompressed_size);
// Display a '*' if the file is encrypted
if (file_info->flag & MZ_ZIP_FLAG_ENCRYPTED)
crypt = '*';
@@ -271,7 +287,7 @@ int32_t minizip_list(void *handle)
switch (file_info->compression_method)
{
case MZ_COMPRESS_METHOD_RAW:
string_method = "Stored";
string_method = "Stored";
break;
case MZ_COMPRESS_METHOD_DEFLATE:
level = (int16_t)((file_info->flag & 0x6) / 2);
@@ -296,9 +312,10 @@ int32_t minizip_list(void *handle)
mz_zip_time_t_to_tm(file_info->modified_date, &tmu_date);
printf(" %7"PRIu64" %6s%c %7"PRIu64" %3"PRIu32"%% %2.2"PRIu32"-%2.2"PRIu32\
printf(" %7"PRIu64" %6s%c %7"PRIu64" %8"PRIx32" %3"PRIu32"%% %2.2"PRIu32"-%2.2"PRIu32\
"-%2.2"PRIu32" %2.2"PRIu32":%2.2"PRIu32" %8.8"PRIx32" %s\n",
file_info->uncompressed_size, string_method, crypt, file_info->compressed_size, ratio,
file_info->uncompressed_size, string_method, crypt,
file_info->compressed_size, file_info->external_fa, ratio,
(uint32_t)tmu_date.tm_mon + 1, (uint32_t)tmu_date.tm_mday,
(uint32_t)tmu_date.tm_year % 100,
(uint32_t)tmu_date.tm_hour, (uint32_t)tmu_date.tm_min,
@@ -329,10 +346,8 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
int32_t written = 0;
int32_t err = MZ_OK;
int32_t err_close = MZ_OK;
uint8_t skip = 0;
void *stream = NULL;
char *match = NULL;
char *filename = NULL;
const char *filename = NULL;
char out_path[512];
char directory[512];
@@ -345,32 +360,27 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
return err;
}
match = filename = file_info->filename;
while (*match != 0)
{
if ((*match == '/') || (*match == '\\'))
filename = match + 1;
match += 1;
}
if (mz_path_get_filename(file_info->filename, &filename) != MZ_OK)
filename = file_info->filename;
// Construct output path
out_path[0] = 0;
if (destination != NULL)
mz_path_combine(out_path, destination, sizeof(out_path));
if (options->exclude_path)
mz_path_combine(out_path, filename, sizeof(out_path));
if ((*file_info->filename == '/') || (file_info->filename[1] == ':'))
{
strncpy(out_path, file_info->filename, sizeof(out_path));
}
else
{
if (destination != NULL)
mz_path_combine(out_path, destination, sizeof(out_path));
mz_path_combine(out_path, file_info->filename, sizeof(out_path));
}
// If zip entry is a directory then create it on disk
if (*filename == 0)
if (mz_zip_attrib_is_dir(file_info->external_fa, file_info->version_madeby) == MZ_OK)
{
if (options->exclude_path == 0)
{
printf("Creating directory: %s\n", out_path);
mz_make_dir(out_path);
}
printf("Creating directory: %s\n", out_path);
mz_make_dir(out_path);
return err;
}
@@ -399,7 +409,7 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
while ((rep != 'Y') && (rep != 'N') && (rep != 'A'));
if (rep == 'N')
skip = 1;
return err;
if (rep == 'A')
options->overwrite = 1;
}
@@ -407,25 +417,16 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
mz_stream_os_create(&stream);
// Create the file on disk so we can unzip to it
if ((skip == 0) && (err == MZ_OK))
if (err == MZ_OK)
{
// Some zips don't contain directory alone before file
if ((mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE) != MZ_OK) &&
(options->exclude_path == 0) && (filename != file_info->filename))
(filename != file_info->filename))
{
// Create the directory of the output path
strncpy(directory, out_path, sizeof(directory));
match = directory + strlen(directory) - 1;
while (match > directory)
{
if ((*match == '/') || (*match == '\\'))
{
*match = 0;
break;
}
match -= 1;
}
mz_path_remove_filename(directory);
mz_make_dir(directory);
mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE);
@@ -460,7 +461,7 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
// Set the time of the file that has been unzipped
if (err == MZ_OK)
mz_os_set_file_date(out_path, file_info->modified_date, file_info->accessed_date,
mz_os_set_file_date(out_path, file_info->modified_date, file_info->accessed_date,
file_info->creation_date);
}
else
@@ -483,7 +484,6 @@ int32_t minizip_extract_currentfile(void *handle, const char *destination, const
int32_t minizip_extract_all(void *handle, const char *destination, const char *password, minizip_opt *options)
{
int32_t err = MZ_OK;
err = mz_zip_goto_first_entry(handle);
@@ -580,8 +580,8 @@ int main(int argc, char *argv[])
buffered = 1;
if ((c == 'o') || (c == 'O'))
options.overwrite = 1;
if ((c == 'j') || (c == 'J'))
options.exclude_path = 1;
if ((c == 'i') || (c == 'I'))
options.include_path = 1;
if ((c >= '0') && (c <= '9'))
{
options.compress_level = (c - '0');
@@ -694,7 +694,7 @@ int main(int argc, char *argv[])
{
mz_stream_set_base(split_stream, file_stream);
}
mz_stream_split_set_prop_int64(split_stream, MZ_STREAM_PROP_DISK_SIZE, disk_size);
err = mz_stream_open(split_stream, path, mode);
@@ -737,7 +737,7 @@ int main(int argc, char *argv[])
// Go through command line args looking for files to add to zip
for (i = path_arg + 1; (i < argc) && (err == MZ_OK); i += 1)
err = minizip_add(handle, argv[i], password, &options, 1);
err = minizip_add(handle, argv[i], NULL, password, &options, 1);
mz_zip_set_version_madeby(handle, MZ_VERSION_MADEBY);
}
+25 -4
View File
@@ -1,5 +1,5 @@
/* mz.h -- Errors codes, zip flags and magic
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_H
#define _MZ_H
#ifndef MZ_H
#define MZ_H
#ifdef __cplusplus
extern "C" {
@@ -19,7 +19,7 @@ extern "C" {
/***************************************************************************/
// MZ_VERSION
#define MZ_VERSION ("2.2.9")
#define MZ_VERSION ("2.3.2")
// MZ_ERROR
#define MZ_OK (0)
@@ -71,12 +71,33 @@ extern "C" {
MZ_ZIP_FLAG_DEFLATE_MAX)
#define MZ_ZIP_FLAG_DATA_DESCRIPTOR (1 << 3)
// MZ_ZIP64
#define MZ_ZIP64_AUTO (0)
#define MZ_ZIP64_FORCE (1)
#define MZ_ZIP64_DISABLE (2)
// MZ_HOST_SYSTEM
#define MZ_HOST_SYSTEM_MSDOS (0)
#define MZ_HOST_SYSTEM_UNIX (3)
#define MZ_HOST_SYSTEM_WINDOWS_NTFS (10)
#define MZ_HOST_SYSTEM_OSX_DARWIN (19)
// MZ_AES
#define MZ_AES_VERSION (1)
#define MZ_AES_ENCRYPTION_MODE_128 (0x01)
#define MZ_AES_ENCRYPTION_MODE_192 (0x02)
#define MZ_AES_ENCRYPTION_MODE_256 (0x03)
// MZ_UTILITY
#define MZ_UNUSED(SYMBOL) ((void)SYMBOL)
#ifndef MZ_CUSTOM_ALLOC
#define MZ_ALLOC(SIZE) (malloc(SIZE))
#endif
#ifndef MZ_CUSTOM_FREE
#define MZ_FREE(PTR) (free(PTR))
#endif
/***************************************************************************/
#ifdef __cplusplus
+143 -60
View File
@@ -1,5 +1,5 @@
/* mz_compat.c -- Backwards compatible interface for older versions
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -50,17 +50,24 @@ extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globa
return zipOpen2_64(path, append, globalcomment, pzlib_filefunc_def);
}
extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
zlib_filefunc64_def *pzlib_filefunc_def)
{
mz_compat *compat = NULL;
int32_t mode = MZ_OPEN_MODE_READWRITE;
int32_t open_existing = 0;
void *handle = NULL;
void *stream = NULL;
if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
return NULL;
if (pzlib_filefunc_def)
{
if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
return NULL;
}
else
{
if (mz_stream_os_create(&stream) == NULL)
return NULL;
}
switch (append)
{
@@ -71,7 +78,6 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
mode |= MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_APPEND;
break;
case APPEND_STATUS_ADDINZIP:
open_existing = 1;
break;
}
@@ -92,7 +98,7 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
if (globalcomment != NULL)
mz_zip_get_comment(handle, globalcomment);
compat = (mz_compat *)malloc(sizeof(mz_compat));
compat = (mz_compat *)MZ_ALLOC(sizeof(mz_compat));
compat->handle = handle;
compat->stream = stream;
@@ -101,34 +107,55 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
{
mz_compat *compat = (mz_compat *)file;
mz_zip_file file_info = { 0 };
mz_zip_file file_info;
uint64_t dos_date = 0;
MZ_UNUSED(strategy);
MZ_UNUSED(memLevel);
MZ_UNUSED(windowBits);
MZ_UNUSED(size_extrafield_local);
MZ_UNUSED(extrafield_local);
MZ_UNUSED(crc_for_crypting);
if (compat == NULL)
return MZ_PARAM_ERROR;
return ZIP_PARAMERROR;
memset(&file_info, 0, sizeof(file_info));
if (zipfi != NULL)
{
file_info.modified_date = mz_zip_dosdate_to_time_t(zipfi->dos_date);
if (zipfi->dosDate != 0)
dos_date = zipfi->dosDate;
else
dos_date = mz_zip_tm_to_dosdate(&zipfi->tmz_date);
file_info.modified_date = mz_zip_dosdate_to_time_t(dos_date);
file_info.external_fa = zipfi->external_fa;
file_info.internal_fa = zipfi->internal_fa;
}
if (filename == NULL)
filename = "-";
file_info.compression_method = compression_method;
file_info.filename = (char *)filename;
file_info.filename = filename;
//file_info.extrafield_local = extrafield_local;
//file_info.extrafield_local_size = size_extrafield_local;
file_info.extrafield = (uint8_t *)extrafield_global;
file_info.extrafield = extrafield_global;
file_info.extrafield_size = size_extrafield_global;
file_info.version_madeby = version_madeby;
file_info.comment = (char *)comment;
file_info.comment = comment;
file_info.flag = flag_base;
if (zip64)
file_info.zip64 = MZ_ZIP64_FORCE;
else
file_info.zip64 = MZ_ZIP64_DISABLE;
#ifdef HAVE_AES
if (password)
file_info.aes_version = MZ_AES_VERSION;
@@ -142,61 +169,70 @@ extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, cons
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
{
return zipOpenNewFileInZip5(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
return zipOpenNewFileInZip5(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
memLevel, strategy, password, crc_for_crypting, version_madeby, flag_base, zip64);
}
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base)
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
memLevel, strategy, password, crc_for_crypting, version_madeby, flag_base, 0);
}
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting)
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
uint32_t crc_for_crypting)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
memLevel, strategy, password, crc_for_crypting, MZ_VERSION_MADEBY, 0, 0);
}
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting, int zip64)
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
uint32_t crc_for_crypting, int zip64)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
memLevel, strategy, password, crc_for_crypting, MZ_VERSION_MADEBY, 0, zip64);
}
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len)
{
mz_compat *compat = (mz_compat *)file;
int32_t written = 0;
if (compat == NULL)
return MZ_PARAM_ERROR;
return mz_zip_entry_write(compat->handle, buf, len);
return ZIP_PARAMERROR;
written = mz_zip_entry_write(compat->handle, buf, len);
if ((written < 0) || ((uint32_t)written != len))
return ZIP_ERRNO;
return ZIP_OK;
}
extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32)
{
return zipCloseFileInZipRaw64(file, uncompressed_size, crc32);
}
extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32)
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return MZ_PARAM_ERROR;
return ZIP_PARAMERROR;
return mz_zip_entry_close_raw(compat->handle, uncompressed_size, crc32);
}
@@ -226,7 +262,7 @@ extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16
int32_t err = MZ_OK;
if (compat == NULL)
return MZ_PARAM_ERROR;
return ZIP_PARAMERROR;
if (global_comment != NULL)
mz_zip_set_comment(compat->handle, global_comment);
@@ -240,7 +276,7 @@ extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16
mz_stream_delete(&compat->stream);
}
free(compat);
MZ_FREE(compat);
return err;
}
@@ -270,9 +306,17 @@ extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_
void *handle = NULL;
void *stream = NULL;
if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
return NULL;
if (pzlib_filefunc_def)
{
if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
return NULL;
}
else
{
if (mz_stream_os_create(&stream) == NULL)
return NULL;
}
if (mz_stream_open(stream, path, mode) != MZ_OK)
{
mz_stream_delete(&stream);
@@ -287,7 +331,7 @@ extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_
return NULL;
}
compat = (mz_compat *)malloc(sizeof(mz_compat));
compat = (mz_compat *)MZ_ALLOC(sizeof(mz_compat));
compat->handle = handle;
compat->stream = stream;
@@ -301,7 +345,7 @@ extern int ZEXPORT unzClose(unzFile file)
int32_t err = MZ_OK;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
err = mz_zip_close(compat->handle);
@@ -311,7 +355,7 @@ extern int ZEXPORT unzClose(unzFile file)
mz_stream_delete(&compat->stream);
}
free(compat);
MZ_FREE(compat);
return err;
}
@@ -324,7 +368,7 @@ extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info3
memset(pglobal_info32, 0, sizeof(unz_global_info));
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
err = unzGetGlobalInfo64(file, &global_info64);
if (err == MZ_OK)
@@ -344,7 +388,7 @@ extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_i
memset(pglobal_info, 0, sizeof(unz_global_info64));
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
err = mz_zip_get_comment(compat->handle, &comment_ptr);
if (err == MZ_OK)
pglobal_info->size_comment = (uint16_t)strlen(comment_ptr);
@@ -362,7 +406,7 @@ extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t com
int32_t err = MZ_OK;
if (comment == NULL || comment_size == 0)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
err = mz_zip_get_comment(compat->handle, &comment_ptr);
if (err == MZ_OK)
strncpy(comment, comment_ptr, comment_size);
@@ -373,7 +417,7 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
if (method != NULL)
*method = 0;
if (level != NULL)
@@ -396,11 +440,11 @@ extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, in
return unzOpenCurrentFile3(file, method, level, raw, NULL);
}
extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len)
extern int ZEXPORT unzReadCurrentFile(unzFile file, void *buf, uint32_t len)
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
return mz_zip_entry_read(compat->handle, buf, len);
}
@@ -408,7 +452,7 @@ extern int ZEXPORT unzCloseCurrentFile(unzFile file)
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
return mz_zip_entry_close(compat->handle);
}
@@ -421,7 +465,8 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info
int32_t err = MZ_OK;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
err = mz_zip_entry_get_info(compat->handle, &file_info);
if ((err == MZ_OK) && (pfile_info != NULL))
@@ -430,7 +475,9 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info
pfile_info->version_needed = file_info->version_needed;
pfile_info->flag = file_info->flag;
pfile_info->compression_method = file_info->compression_method;
pfile_info->dos_date = mz_zip_time_t_to_dos_date(file_info->modified_date);
pfile_info->dosDate = mz_zip_time_t_to_dos_date(file_info->modified_date);
mz_zip_time_t_to_tm(file_info->modified_date, &pfile_info->tmu_date);
pfile_info->tmu_date.tm_year += 1900;
pfile_info->crc = file_info->crc;
pfile_info->size_filename = file_info->filename_size;
@@ -478,7 +525,7 @@ extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile
int32_t err = MZ_OK;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
err = mz_zip_entry_get_info(compat->handle, &file_info);
@@ -488,7 +535,9 @@ extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile
pfile_info->version_needed = file_info->version_needed;
pfile_info->flag = file_info->flag;
pfile_info->compression_method = file_info->compression_method;
pfile_info->dos_date = mz_zip_time_t_to_dos_date(file_info->modified_date);
pfile_info->dosDate = mz_zip_time_t_to_dos_date(file_info->modified_date);
mz_zip_time_t_to_tm(file_info->modified_date, &pfile_info->tmu_date);
pfile_info->tmu_date.tm_year += 1900;
pfile_info->crc = file_info->crc;
pfile_info->size_filename = file_info->filename_size;
@@ -537,7 +586,7 @@ extern int ZEXPORT unzGoToFirstFile(unzFile file)
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
return mz_zip_goto_first_entry(compat->handle);
}
@@ -545,7 +594,7 @@ extern int ZEXPORT unzGoToNextFile(unzFile file)
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
return mz_zip_goto_next_entry(compat->handle);
}
@@ -553,10 +602,45 @@ extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileName
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return MZ_PARAM_ERROR;
return UNZ_PARAMERROR;
return mz_zip_locate_entry(compat->handle, filename, filename_compare_func);
}
extern int32_t ZEXPORT unzGetOffset(unzFile file)
{
return (int32_t)unzGetOffset64(file);
}
extern int64_t ZEXPORT unzGetOffset64(unzFile file)
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return UNZ_PARAMERROR;
return mz_zip_get_entry(compat->handle);
}
extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos)
{
return unzSetOffset64(file, pos);
}
extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos)
{
mz_compat *compat = (mz_compat *)file;
if (compat == NULL)
return UNZ_PARAMERROR;
return (int)mz_zip_goto_entry(compat->handle, pos);
}
extern int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned len) // TODO
{
MZ_UNUSED(file);
MZ_UNUSED(buf);
MZ_UNUSED(len);
return 0;
}
/***************************************************************************/
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
@@ -595,4 +679,3 @@ void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
if (pzlib_filefunc_def != NULL)
*pzlib_filefunc_def = mz_stream_os_get_interface();
}
+67 -60
View File
@@ -1,5 +1,5 @@
/* mz_compat.h -- Backwards compatible interface for older versions
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -11,8 +11,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_COMPAT_H
#define _MZ_COMPAT_H
#ifndef MZ_COMPAT_H
#define MZ_COMPAT_H
#include <stdint.h>
@@ -20,24 +20,16 @@
extern "C" {
#endif
#ifdef HAVE_ZLIB
#include "zlib.h"
#else
#define ZEXPORT
#define MAX_WBITS (15)
#define DEF_MEM_LEVEL (8)
#endif
/***************************************************************************/
#ifdef __GNUC__
# define ZIP_UNUSED __attribute__((__unused__))
#else
# define ZIP_UNUSED
#endif
#ifndef DEF_MEM_LEVEL
# if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
# else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
# endif
#endif
#if defined(USE_FILE32API)
# define MZ_USE_FILE32API
# define fopen64 fopen
@@ -70,7 +62,7 @@ extern "C" {
typedef struct TagzipFile__ { int unused; } zip_file__;
typedef zip_file__ *zipFile;
#else
typedef voidp zipFile;
typedef void *zipFile;
#endif
/***************************************************************************/
@@ -79,11 +71,17 @@ typedef void *zlib_filefunc_def;
typedef void *zlib_filefunc64_def;
typedef const char *zipcharpc;
typedef struct tm tm_unz;
typedef struct tm tm_zip;
typedef uint64_t ZPOS64_T;
/***************************************************************************/
typedef struct
{
uint32_t dos_date;
uint32_t dosDate;
struct tm tmz_date;
uint16_t internal_fa; // internal file attributes 2 bytes
uint32_t external_fa; // external file attributes 4 bytes
} zip_fileinfo;
@@ -92,7 +90,7 @@ typedef struct
#define ZIP_OK (0)
#define ZIP_EOF (0)
#define ZIP_ERRNO (Z_ERRNO)
#define ZIP_ERRNO (-1)
#define ZIP_PARAMERROR (-102)
#define ZIP_BADZIPFILE (-103)
#define ZIP_INTERNALERROR (-104)
@@ -109,38 +107,39 @@ extern zipFile ZEXPORT zipOpen(const char *path, int append);
extern zipFile ZEXPORT zipOpen64(const void *path, int append);
extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
zlib_filefunc_def *pzlib_filefunc_def);
extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
zlib_filefunc64_def *pzlib_filefunc_def);
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting);
uint32_t crc_for_crypting);
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting, int zip64);
uint32_t crc_for_crypting, int zip64);
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
int raw, int windowBits, int memLevel, int strategy, const char *password,
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);
extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32);
extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32);
extern int ZEXPORT zipCloseFileInZip(zipFile file);
extern int ZEXPORT zipCloseFileInZip64(zipFile file);
@@ -156,14 +155,14 @@ extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16
typedef struct TagunzFile__ { int unused; } unz_file__;
typedef unz_file__ *unzFile;
#else
typedef voidp unzFile;
typedef void *unzFile;
#endif
/***************************************************************************/
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_ERRNO (-1)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
@@ -175,35 +174,36 @@ typedef voidp unzFile;
typedef struct unz_global_info64_s
{
uint64_t number_entry; // total number of entries in the central dir on this disk
uint64_t number_entry; // total number of entries in the central dir on this disk
uint32_t number_disk_with_CD; // number the the disk with central dir, used for spanning ZIP
uint16_t size_comment; // size of the global comment of the zipfile
uint16_t size_comment; // size of the global comment of the zipfile
} unz_global_info64;
typedef struct unz_global_info_s
{
uint32_t number_entry; // total number of entries in the central dir on this disk
uint32_t number_entry; // total number of entries in the central dir on this disk
uint32_t number_disk_with_CD; // number the the disk with central dir, used for spanning ZIP
uint16_t size_comment; // size of the global comment of the zipfile
uint16_t size_comment; // size of the global comment of the zipfile
} unz_global_info;
typedef struct unz_file_info64_s
{
uint16_t version; // version made by 2 bytes
uint16_t version_needed; // version needed to extract 2 bytes
uint16_t flag; // general purpose bit flag 2 bytes
uint16_t compression_method; // compression method 2 bytes
uint32_t dos_date; // last mod file date in Dos fmt 4 bytes
uint32_t crc; // crc-32 4 bytes
uint64_t compressed_size; // compressed size 8 bytes
uint64_t uncompressed_size; // uncompressed size 8 bytes
uint16_t size_filename; // filename length 2 bytes
uint16_t size_file_extra; // extra field length 2 bytes
uint16_t size_file_comment; // file comment length 2 bytes
uint16_t version; // version made by 2 bytes
uint16_t version_needed; // version needed to extract 2 bytes
uint16_t flag; // general purpose bit flag 2 bytes
uint16_t compression_method; // compression method 2 bytes
uint32_t dosDate; // last mod file date in Dos fmt 4 bytes
struct tm tmu_date;
uint32_t crc; // crc-32 4 bytes
uint64_t compressed_size; // compressed size 8 bytes
uint64_t uncompressed_size; // uncompressed size 8 bytes
uint16_t size_filename; // filename length 2 bytes
uint16_t size_file_extra; // extra field length 2 bytes
uint16_t size_file_comment; // file comment length 2 bytes
uint32_t disk_num_start; // disk number start 4 bytes
uint16_t internal_fa; // internal file attributes 2 bytes
uint32_t external_fa; // external file attributes 4 bytes
uint32_t disk_num_start; // disk number start 4 bytes
uint16_t internal_fa; // internal file attributes 2 bytes
uint32_t external_fa; // external file attributes 4 bytes
uint64_t disk_offset;
@@ -212,20 +212,21 @@ typedef struct unz_file_info64_s
typedef struct unz_file_info_s
{
uint16_t version; // version made by 2 bytes
uint16_t version_needed; // version needed to extract 2 bytes
uint16_t flag; // general purpose bit flag 2 bytes
uint16_t compression_method; // compression method 2 bytes
uint32_t dos_date; // last mod file date in Dos fmt 4 bytes
uint32_t crc; // crc-32 4 bytes
uint32_t compressed_size; // compressed size 4 bytes
uint32_t uncompressed_size; // uncompressed size 4 bytes
uint16_t size_filename; // filename length 2 bytes
uint16_t size_file_extra; // extra field length 2 bytes
uint16_t size_file_comment; // file comment length 2 bytes
uint16_t version; // version made by 2 bytes
uint16_t version_needed; // version needed to extract 2 bytes
uint16_t flag; // general purpose bit flag 2 bytes
uint16_t compression_method; // compression method 2 bytes
uint32_t dosDate; // last mod file date in Dos fmt 4 bytes
struct tm tmu_date;
uint32_t crc; // crc-32 4 bytes
uint32_t compressed_size; // compressed size 4 bytes
uint32_t uncompressed_size; // uncompressed size 4 bytes
uint16_t size_filename; // filename length 2 bytes
uint16_t size_file_extra; // extra field length 2 bytes
uint16_t size_file_comment; // file comment length 2 bytes
uint16_t disk_num_start; // disk number start 2 bytes
uint16_t internal_fa; // internal file attributes 2 bytes
uint16_t disk_num_start; // disk number start 2 bytes
uint16_t internal_fa; // internal file attributes 2 bytes
uint32_t external_fa; // external file attributes 4 bytes
uint64_t disk_offset;
@@ -253,7 +254,7 @@ extern int ZEXPORT unzOpenCurrentFile(unzFile file);
extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password);
extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len);
extern int ZEXPORT unzReadCurrentFile(unzFile file, void *buf, uint32_t len);
extern int ZEXPORT unzCloseCurrentFile(unzFile file);
extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
@@ -264,6 +265,12 @@ extern int ZEXPORT unzGoToFirstFile(unzFile file);
extern int ZEXPORT unzGoToNextFile(unzFile file);
extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
extern int64_t ZEXPORT unzGetOffset64(unzFile file);
extern int32_t ZEXPORT unzGetOffset(unzFile file);
extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos);
extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos);
extern int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned len);
/***************************************************************************/
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
+47 -4
View File
@@ -1,5 +1,5 @@
/* mz_os.c -- System functions
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -40,7 +40,7 @@ int32_t mz_make_dir(const char *path)
if (len <= 0)
return 0;
current_dir = (char *)malloc(len + 1);
current_dir = (char *)MZ_ALLOC(len + 1);
if (current_dir == NULL)
return MZ_MEM_ERROR;
@@ -71,7 +71,7 @@ int32_t mz_make_dir(const char *path)
}
}
free(current_dir);
MZ_FREE(current_dir);
return err;
}
@@ -98,6 +98,49 @@ int32_t mz_path_combine(char *path, const char *join, int32_t max_path)
return MZ_OK;
}
int32_t mz_path_remove_filename(const char *path)
{
char *path_ptr = NULL;
if (path == NULL)
return MZ_PARAM_ERROR;
path_ptr = (char *)(path + strlen(path) - 1);
while (path_ptr > path)
{
if ((*path_ptr == '/') || (*path_ptr == '\\'))
{
*path_ptr = 0;
break;
}
path_ptr -= 1;
}
return MZ_OK;
}
int32_t mz_path_get_filename(const char *path, const char **filename)
{
const char *match = NULL;
if (path == NULL || filename == NULL)
return MZ_PARAM_ERROR;
*filename = NULL;
for (match = path; *match != 0; match += 1)
{
if ((*match == '\\') || (*match == '/'))
*filename = match + 1;
}
if (*filename == NULL)
return MZ_EXIST_ERROR;
return MZ_OK;
}
int32_t mz_get_file_crc(const char *path, uint32_t *result_crc)
{
void *stream = NULL;
@@ -149,4 +192,4 @@ int32_t mz_get_file_crc(const char *path, uint32_t *result_crc)
mz_stream_os_delete(&stream);
return err;
}
}
+9 -3
View File
@@ -1,5 +1,5 @@
/* mz_os.h -- System functions
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -11,8 +11,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_OS_H
#define _MZ_OS_H
#ifndef MZ_OS_H
#define MZ_OS_H
#include <stdint.h>
@@ -53,6 +53,12 @@ int32_t mz_make_dir(const char *path);
int32_t mz_path_combine(char *path, const char *join, int32_t max_path);
// Combines two paths
int32_t mz_path_remove_filename(const char *path);
// Remove the filename from a path
int32_t mz_path_get_filename(const char *path, const char **filename);
// Get the filename from a path
int32_t mz_get_file_crc(const char *path, uint32_t *result_crc);
// Gets the crc32 hash of a file
+26 -2
View File
@@ -1,5 +1,5 @@
/* mz_os_posix.c -- System functions for posix
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -34,11 +34,13 @@
/***************************************************************************/
#if defined(HAVE_PKCRYPT) || defined(HAVE_AES)
int32_t mz_posix_rand(uint8_t *buf, int32_t size)
{
arc4random_buf(buf, size);
return size;
}
#endif
int32_t mz_posix_file_exists(const char *path)
{
@@ -69,7 +71,6 @@ int32_t mz_posix_get_file_date(const char *path, time_t *modified_date, time_t *
size_t len = 0;
int32_t err = MZ_INTERNAL_ERROR;
memset(&stat_info, 0, sizeof(stat_info));
if (strcmp(path, "-") != 0)
@@ -108,6 +109,7 @@ int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t ac
ut.actime = accessed_date;
ut.modtime = modified_date;
// Creation date not supported
(void)creation_date;
if (utime(path, &ut) != 0)
return MZ_INTERNAL_ERROR;
@@ -115,6 +117,28 @@ int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t ac
return MZ_OK;
}
int32_t mz_posix_get_file_attribs(const char *path, uint32_t *attributes)
{
struct stat stat_info;
int32_t err = MZ_OK;
memset(&stat_info, 0, sizeof(stat_info));
if (stat(path, &stat_info) == -1)
err = MZ_INTERNAL_ERROR;
*attributes = stat_info.st_mode;
return err;
}
int32_t mz_posix_set_file_attribs(const char *path, uint32_t attributes)
{
int32_t err = MZ_OK;
if (chmod(path, (mode_t)attributes) == -1)
err = MZ_INTERNAL_ERROR;
return err;
}
int32_t mz_posix_make_dir(const char *path)
{
int32_t err = 0;
+20 -16
View File
@@ -1,5 +1,5 @@
/* mz_os_posix.h -- System functions for posix
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_OS_POSIX_H
#define _MZ_OS_POSIX_H
#ifndef MZ_OS_POSIX_H
#define MZ_OS_POSIX_H
#include <stdint.h>
#include <time.h>
@@ -23,9 +23,9 @@ extern "C" {
/***************************************************************************/
#if defined(__APPLE__)
#define MZ_VERSION_MADEBY_HOST_SYSTEM (19)
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_OSX_DARWIN)
#elif defined(unix)
#define MZ_VERSION_MADEBY_HOST_SYSTEM (3)
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_UNIX)
#endif
/***************************************************************************/
@@ -35,25 +35,29 @@ int32_t mz_posix_file_exists(const char *path);
int64_t mz_posix_get_file_size(const char *path);
int32_t mz_posix_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
int32_t mz_posix_get_file_attribs(const char *path, uint32_t *attributes);
int32_t mz_posix_set_file_attribs(const char *path, uint32_t attributes);
int32_t mz_posix_make_dir(const char *path);
DIR* mz_posix_open_dir(const char *path);
struct
struct
dirent* mz_posix_read_dir(DIR *dir);
int32_t mz_posix_close_dir(DIR *dir);
int32_t mz_posix_is_dir(const char *path);
/***************************************************************************/
#define mz_os_rand mz_posix_rand
#define mz_os_file_exists mz_posix_file_exists
#define mz_os_get_file_size mz_posix_get_file_size
#define mz_os_get_file_date mz_posix_get_file_date
#define mz_os_set_file_date mz_posix_set_file_date
#define mz_os_make_dir mz_posix_make_dir
#define mz_os_open_dir mz_posix_open_dir
#define mz_os_read_dir mz_posix_read_dir
#define mz_os_close_dir mz_posix_close_dir
#define mz_os_is_dir mz_posix_is_dir
#define mz_os_rand mz_posix_rand
#define mz_os_file_exists mz_posix_file_exists
#define mz_os_get_file_size mz_posix_get_file_size
#define mz_os_get_file_date mz_posix_get_file_date
#define mz_os_set_file_date mz_posix_set_file_date
#define mz_os_get_file_attribs mz_posix_get_file_attribs
#define mz_os_set_file_attribs mz_posix_set_file_attribs
#define mz_os_make_dir mz_posix_make_dir
#define mz_os_open_dir mz_posix_open_dir
#define mz_os_read_dir mz_posix_read_dir
#define mz_os_close_dir mz_posix_close_dir
#define mz_os_is_dir mz_posix_is_dir
/***************************************************************************/
+41 -11
View File
@@ -1,5 +1,5 @@
/* mz_os_win32.c -- System functions for Windows
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -43,6 +43,7 @@ typedef struct DIR_int_s {
/***************************************************************************/
#if defined(HAVE_PKCRYPT) || defined(HAVE_AES)
int32_t mz_win32_rand(uint8_t *buf, int32_t size)
{
HCRYPTPROV provider;
@@ -68,6 +69,7 @@ int32_t mz_win32_rand(uint8_t *buf, int32_t size)
return len;
}
#endif
wchar_t *mz_win32_unicode_path_create(const char *path)
{
@@ -75,7 +77,7 @@ wchar_t *mz_win32_unicode_path_create(const char *path)
uint32_t path_wide_size = 0;
path_wide_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
path_wide = (wchar_t *)malloc((path_wide_size + 1) * sizeof(wchar_t));
path_wide = (wchar_t *)MZ_ALLOC((path_wide_size + 1) * sizeof(wchar_t));
memset(path_wide, 0, sizeof(wchar_t) * (path_wide_size + 1));
MultiByteToWideChar(CP_UTF8, 0, path, -1, path_wide, path_wide_size);
@@ -87,7 +89,7 @@ void mz_win32_unicode_path_delete(wchar_t **path)
{
if (path != NULL)
{
free(*path);
MZ_FREE(*path);
*path = NULL;
}
}
@@ -159,7 +161,7 @@ int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *
path_wide = mz_win32_unicode_path_create(path);
handle = FindFirstFileW(path_wide, &ff32);
free(path_wide);
MZ_FREE(path_wide);
if (handle != INVALID_HANDLE_VALUE)
{
@@ -213,6 +215,34 @@ int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t ac
return err;
}
int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes)
{
wchar_t *path_wide = NULL;
int32_t err = MZ_OK;
path_wide = mz_win32_unicode_path_create(path);
*attributes = GetFileAttributesW(path_wide);
MZ_FREE(path_wide);
if (*attributes == INVALID_FILE_ATTRIBUTES)
err = MZ_INTERNAL_ERROR;
return err;
}
int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes)
{
wchar_t *path_wide = NULL;
int32_t err = MZ_OK;
path_wide = mz_win32_unicode_path_create(path);
if (SetFileAttributesW(path_wide, attributes) == 0)
err = MZ_INTERNAL_ERROR;
MZ_FREE(path_wide);
return err;
}
int32_t mz_win32_make_dir(const char *path)
{
wchar_t *path_wide = NULL;
@@ -249,7 +279,7 @@ DIR *mz_win32_open_dir(const char *path)
if (handle == INVALID_HANDLE_VALUE)
return NULL;
dir_int = (DIR_int *)malloc(sizeof(DIR_int));
dir_int = (DIR_int *)MZ_ALLOC(sizeof(DIR_int));
dir_int->find_handle = handle;
dir_int->end = 0;
@@ -269,9 +299,9 @@ struct dirent* mz_win32_read_dir(DIR *dir)
if (dir_int->end)
return NULL;
WideCharToMultiByte(CP_UTF8, 0, dir_int->find_data.cFileName, -1,
WideCharToMultiByte(CP_UTF8, 0, dir_int->find_data.cFileName, -1,
dir_int->entry.d_name, sizeof(dir_int->entry.d_name), NULL, NULL);
if (FindNextFileW(dir_int->find_handle, &dir_int->find_data) == 0)
{
if (GetLastError() != ERROR_NO_MORE_FILES)
@@ -279,7 +309,7 @@ struct dirent* mz_win32_read_dir(DIR *dir)
dir_int->end = 1;
}
return &dir_int->entry;
}
@@ -293,14 +323,14 @@ int32_t mz_win32_close_dir(DIR *dir)
dir_int = (DIR_int *)dir;
if (dir_int->find_handle != INVALID_HANDLE_VALUE)
FindClose(dir_int->find_handle);
free(dir_int);
MZ_FREE(dir_int);
return MZ_OK;
}
int32_t mz_win32_is_dir(const char *path)
{
wchar_t *path_wide = NULL;
int32_t attribs = 0;
uint32_t attribs = 0;
path_wide = mz_win32_unicode_path_create(path);
attribs = GetFileAttributesW(path_wide);
@@ -313,4 +343,4 @@ int32_t mz_win32_is_dir(const char *path)
}
return MZ_EXIST_ERROR;
}
}
+19 -15
View File
@@ -1,5 +1,5 @@
/* mz_os_win32.h -- System functions for Windows
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_OS_WIN32_H
#define _MZ_OS_WIN32_H
#ifndef MZ_OS_WIN32_H
#define MZ_OS_WIN32_H
#include <stdint.h>
@@ -20,7 +20,7 @@ extern "C" {
/***************************************************************************/
#define MZ_VERSION_MADEBY_HOST_SYSTEM (10)
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_WINDOWS_NTFS)
/***************************************************************************/
@@ -36,25 +36,29 @@ int32_t mz_win32_file_exists(const char *path);
int64_t mz_win32_get_file_size(const char *path);
int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes);
int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes);
int32_t mz_win32_make_dir(const char *path);
DIR* mz_win32_open_dir(const char *path);
struct
struct
dirent* mz_win32_read_dir(DIR *dir);
int32_t mz_win32_close_dir(DIR *dir);
int32_t mz_win32_is_dir(const char *path);
/***************************************************************************/
#define mz_os_rand mz_win32_rand
#define mz_os_file_exists mz_win32_file_exists
#define mz_os_get_file_size mz_win32_get_file_size
#define mz_os_get_file_date mz_win32_get_file_date
#define mz_os_set_file_date mz_win32_set_file_date
#define mz_os_make_dir mz_win32_make_dir
#define mz_os_open_dir mz_win32_open_dir
#define mz_os_read_dir mz_win32_read_dir
#define mz_os_close_dir mz_win32_close_dir
#define mz_os_is_dir mz_win32_is_dir
#define mz_os_rand mz_win32_rand
#define mz_os_file_exists mz_win32_file_exists
#define mz_os_get_file_size mz_win32_get_file_size
#define mz_os_get_file_date mz_win32_get_file_date
#define mz_os_set_file_date mz_win32_set_file_date
#define mz_os_get_file_attribs mz_win32_get_file_attribs
#define mz_os_set_file_attribs mz_win32_set_file_attribs
#define mz_os_make_dir mz_win32_make_dir
#define mz_os_open_dir mz_win32_open_dir
#define mz_os_read_dir mz_win32_read_dir
#define mz_os_close_dir mz_win32_close_dir
#define mz_os_is_dir mz_win32_is_dir
/***************************************************************************/
+20 -9
View File
@@ -1,5 +1,5 @@
/* mz_strm.c -- Stream interface
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -173,7 +173,7 @@ int32_t mz_stream_copy(void *target, void *source, int32_t len)
while (len > 0)
{
bytes_to_copy = len;
if (bytes_to_copy > sizeof(buf))
if (bytes_to_copy > (int32_t)sizeof(buf))
bytes_to_copy = sizeof(buf);
read = mz_stream_read(source, buf, bytes_to_copy);
if (read < 0)
@@ -270,7 +270,7 @@ void mz_stream_delete(void **stream)
/***************************************************************************/
mz_stream_vtbl mz_stream_crc32_vtbl = {
static mz_stream_vtbl mz_stream_crc32_vtbl = {
mz_stream_crc32_open,
mz_stream_crc32_is_open,
mz_stream_crc32_read,
@@ -281,7 +281,8 @@ mz_stream_vtbl mz_stream_crc32_vtbl = {
mz_stream_crc32_error,
mz_stream_crc32_create,
mz_stream_crc32_delete,
mz_stream_crc32_get_prop_int64
mz_stream_crc32_get_prop_int64,
NULL
};
/***************************************************************************/
@@ -301,6 +302,10 @@ typedef struct mz_stream_crc32_s {
int32_t mz_stream_crc32_open(void *stream, const char *path, int32_t mode)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
MZ_UNUSED(path);
MZ_UNUSED(mode);
crc32->initialized = 1;
crc32->value = 0;
return MZ_OK;
@@ -393,7 +398,7 @@ void *mz_stream_crc32_create(void **stream)
{
mz_stream_crc32 *crc32 = NULL;
crc32 = (mz_stream_crc32 *)malloc(sizeof(mz_stream_crc32));
crc32 = (mz_stream_crc32 *)MZ_ALLOC(sizeof(mz_stream_crc32));
if (crc32 != NULL)
{
memset(crc32, 0, sizeof(mz_stream_crc32));
@@ -412,7 +417,7 @@ void mz_stream_crc32_delete(void **stream)
return;
crc32 = (mz_stream_crc32 *)*stream;
if (crc32 != NULL)
free(crc32);
MZ_FREE(crc32);
*stream = NULL;
}
@@ -434,6 +439,10 @@ typedef struct mz_stream_raw_s {
int32_t mz_stream_raw_open(void *stream, const char *path, int32_t mode)
{
MZ_UNUSED(stream);
MZ_UNUSED(path);
MZ_UNUSED(mode);
return MZ_OK;
}
@@ -486,6 +495,8 @@ int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin)
int32_t mz_stream_raw_close(void *stream)
{
MZ_UNUSED(stream);
return MZ_OK;
}
@@ -524,7 +535,7 @@ int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value)
/***************************************************************************/
mz_stream_vtbl mz_stream_raw_vtbl = {
static mz_stream_vtbl mz_stream_raw_vtbl = {
mz_stream_raw_open,
mz_stream_raw_is_open,
mz_stream_raw_read,
@@ -545,7 +556,7 @@ void *mz_stream_raw_create(void **stream)
{
mz_stream_raw *raw = NULL;
raw = (mz_stream_raw *)malloc(sizeof(mz_stream_raw));
raw = (mz_stream_raw *)MZ_ALLOC(sizeof(mz_stream_raw));
if (raw != NULL)
{
memset(raw, 0, sizeof(mz_stream_raw));
@@ -564,6 +575,6 @@ void mz_stream_raw_delete(void **stream)
return;
raw = (mz_stream_raw *)*stream;
if (raw != NULL)
free(raw);
MZ_FREE(raw);
*stream = NULL;
}
+3 -3
View File
@@ -1,5 +1,5 @@
/* mz_strm.h -- Stream interface
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_H
#define _MZ_STREAM_H
#ifndef MZ_STREAM_H
#define MZ_STREAM_H
#include <stdint.h>
+10 -9
View File
@@ -1,5 +1,5 @@
/* mz_strm_aes.c -- Stream for WinZip AES encryption
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -38,7 +38,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_aes_vtbl = {
static mz_stream_vtbl mz_stream_aes_vtbl = {
mz_stream_aes_open,
mz_stream_aes_is_open,
mz_stream_aes_read,
@@ -49,7 +49,8 @@ mz_stream_vtbl mz_stream_aes_vtbl = {
mz_stream_aes_error,
mz_stream_aes_create,
mz_stream_aes_delete,
mz_stream_aes_get_prop_int64
mz_stream_aes_get_prop_int64,
NULL
};
/***************************************************************************/
@@ -66,7 +67,7 @@ typedef struct mz_stream_aes_s {
const char *password;
aes_encrypt_ctx encr_ctx[1];
hmac_ctx auth_ctx[1];
uint8_t nonce[AES_BLOCK_SIZE];
uint8_t nonce[AES_BLOCK_SIZE];
uint8_t encr_bfr[AES_BLOCK_SIZE];
uint32_t encr_pos;
} mz_stream_aes;
@@ -219,7 +220,7 @@ int32_t mz_stream_aes_write(void *stream, const void *buf, int32_t size)
mz_stream_aes *aes = (mz_stream_aes *)stream;
int32_t written = 0;
if (size > sizeof(aes->buffer))
if (size > (int32_t)sizeof(aes->buffer))
return MZ_STREAM_ERROR;
memcpy(aes->buffer, buf, size);
@@ -299,10 +300,10 @@ int32_t mz_stream_aes_get_prop_int64(void *stream, int32_t prop, int64_t *value)
mz_stream_aes *aes = (mz_stream_aes *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN:
case MZ_STREAM_PROP_TOTAL_IN:
*value = aes->total_in;
return MZ_OK;
case MZ_STREAM_PROP_TOTAL_OUT:
case MZ_STREAM_PROP_TOTAL_OUT:
*value = aes->total_out;
return MZ_OK;
case MZ_STREAM_PROP_HEADER_SIZE:
@@ -319,7 +320,7 @@ void *mz_stream_aes_create(void **stream)
{
mz_stream_aes *aes = NULL;
aes = (mz_stream_aes *)malloc(sizeof(mz_stream_aes));
aes = (mz_stream_aes *)MZ_ALLOC(sizeof(mz_stream_aes));
if (aes != NULL)
{
memset(aes, 0, sizeof(mz_stream_aes));
@@ -339,7 +340,7 @@ void mz_stream_aes_delete(void **stream)
return;
aes = (mz_stream_aes *)*stream;
if (aes != NULL)
free(aes);
MZ_FREE(aes);
*stream = NULL;
}
+3 -3
View File
@@ -1,5 +1,5 @@
/* mz_strm_aes.h -- Stream for WinZIP AES encryption
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_AES_H
#define _MZ_STREAM_AES_H
#ifndef MZ_STREAM_AES_H
#define MZ_STREAM_AES_H
#include <stdint.h>
+19 -17
View File
@@ -1,5 +1,5 @@
/* mz_strm_buf.c -- Stream for buffering reads/writes
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
This version of ioapi is designed to buffer IO.
@@ -31,7 +31,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_buffered_vtbl = {
static mz_stream_vtbl mz_stream_buffered_vtbl = {
mz_stream_buffered_open,
mz_stream_buffered_is_open,
mz_stream_buffered_read,
@@ -41,7 +41,9 @@ mz_stream_vtbl mz_stream_buffered_vtbl = {
mz_stream_buffered_close,
mz_stream_buffered_error,
mz_stream_buffered_create,
mz_stream_buffered_delete
mz_stream_buffered_delete,
NULL,
NULL
};
/***************************************************************************/
@@ -89,7 +91,7 @@ static int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
while (bytes_left_to_write > 0)
{
bytes_written = mz_stream_write(buffered->stream.base,
bytes_written = mz_stream_write(buffered->stream.base,
buffered->writebuf + (bytes_to_write - bytes_left_to_write), bytes_left_to_write);
if (bytes_written != bytes_left_to_write)
@@ -97,7 +99,7 @@ static int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
buffered->writebuf_misses += 1;
mz_stream_buffered_print(stream, "write flush [%d:%d len %d]\n",
mz_stream_buffered_print(stream, "write flush [%d:%d len %d]\n",
bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
total_bytes_written += bytes_written;
@@ -124,7 +126,7 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
mz_stream_buffered_print(stream, "read [size %ld pos %lld]\n", size, buffered->position);
if (buffered->writebuf_len > 0)
mz_stream_buffered_print(stream, "switch from write to read, not yet supported [%lld]\n",
mz_stream_buffered_print(stream, "switch from write to read, not yet supported [%lld]\n",
buffered->position);
while (bytes_left_to_read > 0)
@@ -146,7 +148,7 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
buffered->readbuf_len += bytes_read;
buffered->position += bytes_read;
mz_stream_buffered_print(stream, "filled [read %d/%d buf %d:%d pos %lld]\n",
mz_stream_buffered_print(stream, "filled [read %d/%d buf %d:%d pos %lld]\n",
bytes_read, bytes_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
if (bytes_read == 0)
@@ -167,7 +169,7 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
buffered->readbuf_hits += 1;
buffered->readbuf_pos += bytes_to_copy;
mz_stream_buffered_print(stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n",
mz_stream_buffered_print(stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n",
bytes_to_copy, bytes_left_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
}
}
@@ -185,7 +187,7 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
int32_t bytes_flushed = 0;
mz_stream_buffered_print(stream, "write [size %ld len %d pos %lld]\n",
mz_stream_buffered_print(stream, "write [size %ld len %d pos %lld]\n",
size, buffered->writebuf_len, buffered->position);
if (buffered->readbuf_len > 0)
@@ -221,9 +223,9 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
continue;
}
memcpy(buffered->writebuf + buffered->writebuf_pos, (char *)buf + (bytes_to_write - bytes_left_to_write), bytes_to_copy);
memcpy(buffered->writebuf + buffered->writebuf_pos, (const char *)buf + (bytes_to_write - bytes_left_to_write), bytes_to_copy);
mz_stream_buffered_print(stream, "write copy [remaining %d write %d:%d len %d]\n",
mz_stream_buffered_print(stream, "write copy [remaining %d write %d:%d len %d]\n",
bytes_to_copy, bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
bytes_left_to_write -= bytes_to_copy;
@@ -274,7 +276,7 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
}
}
if ((buffered->readbuf_len > 0) && (offset < buffered->position) &&
if ((buffered->readbuf_len > 0) && (offset < buffered->position) &&
(offset >= buffered->position - buffered->readbuf_len))
{
buffered->readbuf_pos = (uint32_t)(offset - (buffered->position - buffered->readbuf_len));
@@ -338,14 +340,14 @@ int32_t mz_stream_buffered_close(void *stream)
int32_t bytes_flushed = 0;
mz_stream_buffered_flush(stream, &bytes_flushed);
mz_stream_buffered_print(stream, "close\n");
mz_stream_buffered_print(stream, "close [flushed %d]\n", bytes_flushed);
if (buffered->readbuf_hits + buffered->readbuf_misses > 0)
mz_stream_buffered_print(stream, "read efficency %.02f%%\n",
mz_stream_buffered_print(stream, "read efficency %.02f%%\n",
(buffered->readbuf_hits / ((float)buffered->readbuf_hits + buffered->readbuf_misses)) * 100);
if (buffered->writebuf_hits + buffered->writebuf_misses > 0)
mz_stream_buffered_print(stream, "write efficency %.02f%%\n",
mz_stream_buffered_print(stream, "write efficency %.02f%%\n",
(buffered->writebuf_hits / ((float)buffered->writebuf_hits + buffered->writebuf_misses)) * 100);
return mz_stream_close(buffered->stream.base);
@@ -361,7 +363,7 @@ void *mz_stream_buffered_create(void **stream)
{
mz_stream_buffered *buffered = NULL;
buffered = (mz_stream_buffered *)malloc(sizeof(mz_stream_buffered));
buffered = (mz_stream_buffered *)MZ_ALLOC(sizeof(mz_stream_buffered));
if (buffered != NULL)
{
memset(buffered, 0, sizeof(mz_stream_buffered));
@@ -380,7 +382,7 @@ void mz_stream_buffered_delete(void **stream)
return;
buffered = (mz_stream_buffered *)*stream;
if (buffered != NULL)
free(buffered);
MZ_FREE(buffered);
*stream = NULL;
}
+3 -3
View File
@@ -1,5 +1,5 @@
/* mz_strm_buf.h -- Stream for buffering reads/writes
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
This version of ioapi is designed to buffer IO.
@@ -11,8 +11,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_BUFFERED_H
#define _MZ_STREAM_BUFFERED_H
#ifndef MZ_STREAM_BUFFERED_H
#define MZ_STREAM_BUFFERED_H
#include <stdint.h>
+19 -11
View File
@@ -1,5 +1,5 @@
/* mz_strm_bzip.c -- Stream for bzip inflate/deflate
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -23,7 +23,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_bzip_vtbl = {
static mz_stream_vtbl mz_stream_bzip_vtbl = {
mz_stream_bzip_open,
mz_stream_bzip_is_open,
mz_stream_bzip_read,
@@ -61,6 +61,7 @@ int32_t mz_stream_bzip_open(void *stream, const char *path, int32_t mode)
{
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
MZ_UNUSED(path);
bzip->bzstream.bzalloc = 0;
bzip->bzstream.bzfree = 0;
@@ -134,9 +135,9 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
bytes_to_read = sizeof(bzip->buffer);
if (bzip->max_total_in > 0)
{
if ((bzip->max_total_in - bzip->total_in) < sizeof(bzip->buffer))
if ((bzip->max_total_in - bzip->total_in) < (int64_t)sizeof(bzip->buffer))
bytes_to_read = (int32_t)(bzip->max_total_in - bzip->total_in);
}
}
read = mz_stream_read(bzip->stream.base, bzip->buffer, bytes_to_read);
@@ -153,13 +154,13 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
}
total_in_before = bzip->bzstream.avail_in;
total_out_before = bzip->bzstream.total_out_lo32 +
total_out_before = bzip->bzstream.total_out_lo32 +
(((uint64_t)bzip->bzstream.total_out_hi32) << 32);
err = BZ2_bzDecompress(&bzip->bzstream);
total_in_after = bzip->bzstream.avail_in;
total_out_after = bzip->bzstream.total_out_lo32 +
total_out_after = bzip->bzstream.total_out_lo32 +
(((uint64_t)bzip->bzstream.total_out_hi32) << 32);
in_bytes = (uint32_t)(total_in_before - total_in_after);
@@ -222,12 +223,12 @@ static int32_t mz_stream_bzip_compress(void *stream, int flush)
bzip->buffer_len = 0;
}
total_out_before = bzip->bzstream.total_out_lo32 +
total_out_before = bzip->bzstream.total_out_lo32 +
(((uint64_t)bzip->bzstream.total_out_hi32) << 32);
err = BZ2_bzCompress(&bzip->bzstream, flush);
total_out_after = bzip->bzstream.total_out_lo32 +
total_out_after = bzip->bzstream.total_out_lo32 +
(((uint64_t)bzip->bzstream.total_out_hi32) << 32);
out_bytes = (uint32_t)(total_out_after - total_out_before);
@@ -253,7 +254,7 @@ int32_t mz_stream_bzip_write(void *stream, const void *buf, int32_t size)
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
bzip->bzstream.next_in = (char *)buf;
bzip->bzstream.next_in = (char *)(intptr_t)buf;
bzip->bzstream.avail_in = (unsigned int)size;
mz_stream_bzip_compress(stream, BZ_RUN);
@@ -265,11 +266,17 @@ int32_t mz_stream_bzip_write(void *stream, const void *buf, int32_t size)
int64_t mz_stream_bzip_tell(void *stream)
{
MZ_UNUSED(stream);
return MZ_STREAM_ERROR;
}
int32_t mz_stream_bzip_seek(void *stream, int64_t offset, int32_t origin)
{
MZ_UNUSED(stream);
MZ_UNUSED(offset);
MZ_UNUSED(origin);
return MZ_STREAM_ERROR;
}
@@ -342,7 +349,7 @@ void *mz_stream_bzip_create(void **stream)
{
mz_stream_bzip *bzip = NULL;
bzip = (mz_stream_bzip *)malloc(sizeof(mz_stream_bzip));
bzip = (mz_stream_bzip *)MZ_ALLOC(sizeof(mz_stream_bzip));
if (bzip != NULL)
{
memset(bzip, 0, sizeof(mz_stream_bzip));
@@ -362,7 +369,7 @@ void mz_stream_bzip_delete(void **stream)
return;
bzip = (mz_stream_bzip *)*stream;
if (bzip != NULL)
free(bzip);
MZ_FREE(bzip);
*stream = NULL;
}
@@ -373,4 +380,5 @@ void *mz_stream_bzip_get_interface(void)
extern void bz_internal_error(int errcode)
{
MZ_UNUSED(errcode);
}
+3 -3
View File
@@ -1,5 +1,5 @@
/* mz_strm_bzip.h -- Stream for bzip inflate/deflate
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_BZIP_H
#define _MZ_STREAM_BZIP_H
#ifndef MZ_STREAM_BZIP_H
#define MZ_STREAM_BZIP_H
#include <stdint.h>
-325
View File
@@ -1,325 +0,0 @@
/* mz_strm_crypt.c -- Code for traditional PKWARE encryption
Version 2.2.9, April 18th, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
This encryption code is a direct transcription of the algorithm from
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
file (appnote.txt) is distributed with the PKZIP program (even in the
version without encryption capabilities).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zlib.h"
#include "mz.h"
#include "mz_os.h"
#include "mz_strm.h"
#include "mz_strm_crypt.h"
/***************************************************************************/
#define RAND_HEAD_LEN 12
/***************************************************************************/
mz_stream_vtbl mz_stream_crypt_vtbl = {
mz_stream_crypt_open,
mz_stream_crypt_is_open,
mz_stream_crypt_read,
mz_stream_crypt_write,
mz_stream_crypt_tell,
mz_stream_crypt_seek,
mz_stream_crypt_close,
mz_stream_crypt_error,
mz_stream_crypt_create,
mz_stream_crypt_delete,
mz_stream_crypt_get_prop_int64
};
/***************************************************************************/
typedef struct mz_stream_crypt_s {
mz_stream stream;
int32_t error;
int16_t initialized;
uint8_t buffer[INT16_MAX];
int64_t total_in;
int64_t total_out;
uint32_t keys[3]; // keys defining the pseudo-random sequence
const uint32_t *crc_32_tab;
uint8_t verify1;
uint8_t verify2;
const char *password;
} mz_stream_crypt;
/***************************************************************************/
#define zdecode(keys,crc_32_tab,c) \
(mz_stream_crypt_update_keys(keys,crc_32_tab, c ^= mz_stream_crypt_decrypt_byte(keys)))
#define zencode(keys,crc_32_tab,c,t) \
(t = mz_stream_crypt_decrypt_byte(keys), mz_stream_crypt_update_keys(keys,crc_32_tab,c), t^(c))
/***************************************************************************/
static uint8_t mz_stream_crypt_decrypt_byte(uint32_t *keys)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
temp = ((uint32_t)(*(keys+2)) & 0xffff) | 2;
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
static uint8_t mz_stream_crypt_update_keys(uint32_t *keys, const uint32_t *crc_32_tab, int32_t c)
{
#define CRC32(c, b) ((*(crc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
(*(keys+0)) = (uint32_t)CRC32((*(keys+0)), c);
(*(keys+1)) += (*(keys+0)) & 0xff;
(*(keys+1)) = (*(keys+1)) * 134775813L + 1;
{
register int32_t keyshift = (int32_t)((*(keys + 1)) >> 24);
(*(keys+2)) = (uint32_t)CRC32((*(keys+2)), keyshift);
}
return (uint8_t)c;
}
static void mz_stream_crypt_init_keys(const char *password, uint32_t *keys, const uint32_t *crc_32_tab)
{
*(keys+0) = 305419896L;
*(keys+1) = 591751049L;
*(keys+2) = 878082192L;
while (*password != 0)
{
mz_stream_crypt_update_keys(keys, crc_32_tab, *password);
password += 1;
}
}
/***************************************************************************/
int32_t mz_stream_crypt_open(void *stream, const char *path, int32_t mode)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
uint16_t t = 0;
int16_t i = 0;
uint8_t verify1 = 0;
uint8_t verify2 = 0;
uint8_t header[RAND_HEAD_LEN];
const char *password = path;
crypt->total_in = 0;
crypt->total_out = 0;
crypt->initialized = 0;
if (mz_stream_is_open(crypt->stream.base) != MZ_OK)
return MZ_STREAM_ERROR;
if (password == NULL)
password = crypt->password;
if (password == NULL)
return MZ_STREAM_ERROR;
crypt->crc_32_tab = get_crc_table();
if (crypt->crc_32_tab == NULL)
return MZ_STREAM_ERROR;
mz_stream_crypt_init_keys(password, crypt->keys, crypt->crc_32_tab);
if (mode & MZ_OPEN_MODE_WRITE)
{
// First generate RAND_HEAD_LEN - 2 random bytes.
mz_os_rand(header, RAND_HEAD_LEN - 2);
// Encrypt random header (last two bytes is high word of crc)
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
header[i] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, header[i], t);
header[i++] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, crypt->verify1, t);
header[i++] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, crypt->verify2, t);
if (mz_stream_write(crypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
return MZ_STREAM_ERROR;
crypt->total_out += RAND_HEAD_LEN;
}
else if (mode & MZ_OPEN_MODE_READ)
{
if (mz_stream_read(crypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
return MZ_STREAM_ERROR;
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
header[i] = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i]);
verify1 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
verify2 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
// Older versions used 2 byte check, newer versions use 1 byte check.
if ((verify2 != 0) && (verify2 != crypt->verify2))
return MZ_PASSWORD_ERROR;
crypt->total_in += RAND_HEAD_LEN;
}
crypt->initialized = 1;
return MZ_OK;
}
int32_t mz_stream_crypt_is_open(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
if (crypt->initialized == 0)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_crypt_read(void *stream, void *buf, int32_t size)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
uint8_t *buf_ptr = (uint8_t *)buf;
uint32_t read = 0;
uint32_t i = 0;
read = mz_stream_read(crypt->stream.base, buf, size);
for (i = 0; i < read; i++)
buf_ptr[i] = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, buf_ptr[i]);
crypt->total_in += read;
return read;
}
int32_t mz_stream_crypt_write(void *stream, const void *buf, int32_t size)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
uint8_t *buf_ptr = (uint8_t *)buf;
uint32_t written = 0;
uint16_t t = 0;
int32_t i = 0;
if (size > sizeof(crypt->buffer))
return MZ_STREAM_ERROR;
for (i = 0; i < size; i++)
crypt->buffer[i] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, buf_ptr[i], t);
written = mz_stream_write(crypt->stream.base, crypt->buffer, size);
if (written > 0)
crypt->total_out += written;
return written;
}
int64_t mz_stream_crypt_tell(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
return mz_stream_tell(crypt->stream.base);
}
int32_t mz_stream_crypt_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
return mz_stream_seek(crypt->stream.base, offset, origin);
}
int32_t mz_stream_crypt_close(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
crypt->initialized = 0;
return MZ_OK;
}
int32_t mz_stream_crypt_error(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
return crypt->error;
}
void mz_stream_crypt_set_password(void *stream, const char *password)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
crypt->password = password;
}
void mz_stream_crypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
crypt->verify1 = verify1;
crypt->verify2 = verify2;
}
void mz_stream_crypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
*verify1 = crypt->verify1;
*verify2 = crypt->verify2;
}
int32_t mz_stream_crypt_get_prop_int64(void *stream, int32_t prop, int64_t *value)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = crypt->total_in;
return MZ_OK;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = crypt->total_out;
return MZ_OK;
}
return MZ_EXIST_ERROR;
}
void *mz_stream_crypt_create(void **stream)
{
mz_stream_crypt *crypt = NULL;
crypt = (mz_stream_crypt *)malloc(sizeof(mz_stream_crypt));
if (crypt != NULL)
{
memset(crypt, 0, sizeof(mz_stream_crypt));
crypt->stream.vtbl = &mz_stream_crypt_vtbl;
}
if (stream != NULL)
*stream = crypt;
return crypt;
}
void mz_stream_crypt_delete(void **stream)
{
mz_stream_crypt *crypt = NULL;
if (stream == NULL)
return;
crypt = (mz_stream_crypt *)*stream;
if (crypt != NULL)
free(crypt);
*stream = NULL;
}
void *mz_stream_crypt_get_interface(void)
{
return (void *)&mz_stream_crypt_vtbl;
}
-56
View File
@@ -1,56 +0,0 @@
/* mz_strm_crypt.h -- Code for traditional PKWARE encryption
Version 2.2.9, April 18th, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_CRYPT_H
#define _MZ_STREAM_CRYPT_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
int32_t mz_stream_crypt_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_crypt_is_open(void *stream);
int32_t mz_stream_crypt_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_crypt_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_crypt_tell(void *stream);
int32_t mz_stream_crypt_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_crypt_close(void *stream);
int32_t mz_stream_crypt_error(void *stream);
void mz_stream_crypt_set_password(void *stream, const char *password);
void mz_stream_crypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2);
void mz_stream_crypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2);
int32_t mz_stream_crypt_get_prop_int64(void *stream, int32_t prop, int64_t *value);
void* mz_stream_crypt_create(void **stream);
void mz_stream_crypt_delete(void **stream);
void* mz_stream_crypt_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif
+28 -12
View File
@@ -1,5 +1,5 @@
/* mz_strm_lzma.c -- Stream for lzma inflate/deflate
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -28,7 +28,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_lzma_vtbl = {
static mz_stream_vtbl mz_stream_lzma_vtbl = {
mz_stream_lzma_open,
mz_stream_lzma_is_open,
mz_stream_lzma_read,
@@ -66,11 +66,15 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
{
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
lzma_filter filters[LZMA_FILTERS_MAX + 1];
lzma_options_lzma opt_lzma = { 0 };
lzma_options_lzma opt_lzma;
uint32_t size = 0;
uint8_t major = 0;
uint8_t minor = 0;
MZ_UNUSED(path);
memset(&opt_lzma, 0, sizeof(opt_lzma));
lzma->lstream.total_in = 0;
lzma->lstream.total_out = 0;
@@ -92,7 +96,7 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
filters[1].id = LZMA_VLI_UNKNOWN;
lzma_properties_size(&size, (lzma_filter *)&filters);
mz_stream_write_uint8(lzma->stream.base, LZMA_VERSION_MAJOR);
mz_stream_write_uint8(lzma->stream.base, LZMA_VERSION_MINOR);
mz_stream_write_uint16(lzma->stream.base, (uint16_t)size);
@@ -114,7 +118,7 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
lzma->error = lzma_alone_decoder(&lzma->lstream, UINT64_MAX);
}
if (lzma->error != LZMA_OK)
return MZ_STREAM_ERROR;
@@ -157,10 +161,10 @@ int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
bytes_to_read = sizeof(lzma->buffer);
if (lzma->max_total_in > 0)
{
if ((lzma->max_total_in - lzma->total_in) < sizeof(lzma->buffer))
if ((lzma->max_total_in - lzma->total_in) < (int64_t)sizeof(lzma->buffer))
bytes_to_read = (int32_t)(lzma->max_total_in - lzma->total_in);
}
read = mz_stream_read(lzma->stream.base, lzma->buffer, bytes_to_read);
if (read < 0)
@@ -182,9 +186,9 @@ int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
total_in_after = lzma->lstream.avail_in;
total_out_after = lzma->lstream.total_out;
if (lzma->max_total_out != -1 && total_out_after > lzma->max_total_out)
if ((lzma->max_total_out != -1) && (int64_t)total_out_after > lzma->max_total_out)
total_out_after = lzma->max_total_out;
in_bytes = (uint32_t)(total_in_before - total_in_after);
out_bytes = (uint32_t)(total_out_after - total_out_before);
@@ -268,7 +272,7 @@ int32_t mz_stream_lzma_write(void *stream, const void *buf, int32_t size)
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
lzma->lstream.next_in = (uint8_t*)buf;
lzma->lstream.next_in = (uint8_t*)(intptr_t)buf;
lzma->lstream.avail_in = (size_t)size;
mz_stream_lzma_code(stream, LZMA_RUN);
@@ -280,11 +284,17 @@ int32_t mz_stream_lzma_write(void *stream, const void *buf, int32_t size)
int64_t mz_stream_lzma_tell(void *stream)
{
MZ_UNUSED(stream);
return MZ_STREAM_ERROR;
}
int32_t mz_stream_lzma_seek(void *stream, int64_t offset, int32_t origin)
{
MZ_UNUSED(stream);
MZ_UNUSED(offset);
MZ_UNUSED(origin);
return MZ_STREAM_ERROR;
}
@@ -362,7 +372,7 @@ void *mz_stream_lzma_create(void **stream)
{
mz_stream_lzma *lzma = NULL;
lzma = (mz_stream_lzma *)malloc(sizeof(mz_stream_lzma));
lzma = (mz_stream_lzma *)MZ_ALLOC(sizeof(mz_stream_lzma));
if (lzma != NULL)
{
memset(lzma, 0, sizeof(mz_stream_lzma));
@@ -383,7 +393,7 @@ void mz_stream_lzma_delete(void **stream)
return;
lzma = (mz_stream_lzma *)*stream;
if (lzma != NULL)
free(lzma);
MZ_FREE(lzma);
*stream = NULL;
}
@@ -397,6 +407,12 @@ static int32_t mz_stream_lzma_crc32(int32_t value, const void *buf, int32_t size
return lzma_crc32(buf, size, value);
}
void *mz_stream_lzma_get_crc32_table(void)
{
extern const uint32_t lzma_crc32_table;
return (void *)lzma_crc32_table;
}
void *mz_stream_lzma_get_crc32_update(void)
{
return (void *)mz_stream_lzma_crc32;
+4 -3
View File
@@ -1,5 +1,5 @@
/* mz_strm_lzma.h -- Stream for lzma inflate/deflate
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_LZMA_H
#define _MZ_STREAM_LZMA_H
#ifndef MZ_STREAM_LZMA_H
#define MZ_STREAM_LZMA_H
#include <stdint.h>
@@ -36,6 +36,7 @@ void* mz_stream_lzma_create(void **stream);
void mz_stream_lzma_delete(void **stream);
void* mz_stream_lzma_get_interface(void);
void* mz_stream_lzma_get_crc32_table(void);
void* mz_stream_lzma_get_crc32_update(void);
/***************************************************************************/
+20 -13
View File
@@ -1,9 +1,9 @@
/* mz_strm_mem.c -- Stream for memory access
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
This interface is designed to access memory rather than files.
We do use a region of memory to put data in to and take it out of.
We do use a region of memory to put data in to and take it out of.
Based on Unzip ioapi.c version 0.22, May 19th, 2003
@@ -28,7 +28,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_mem_vtbl = {
static mz_stream_vtbl mz_stream_mem_vtbl = {
mz_stream_mem_open,
mz_stream_mem_is_open,
mz_stream_mem_read,
@@ -38,7 +38,9 @@ mz_stream_vtbl mz_stream_mem_vtbl = {
mz_stream_mem_close,
mz_stream_mem_error,
mz_stream_mem_create,
mz_stream_mem_delete
mz_stream_mem_delete,
NULL,
NULL
};
/***************************************************************************/
@@ -46,7 +48,7 @@ mz_stream_vtbl mz_stream_mem_vtbl = {
typedef struct mz_stream_mem_s {
mz_stream stream;
int32_t mode;
char *buffer; // Memory buffer pointer
char *buffer; // Memory buffer pointer
int32_t size; // Size of the memory buffer
int32_t limit; // Furthest we've written
int32_t position; // Current position in the memory
@@ -62,11 +64,11 @@ static void mz_stream_mem_set_size(void *stream, int32_t size)
char *new_buf = NULL;
new_buf = (char *)malloc(new_size);
new_buf = (char *)MZ_ALLOC(new_size);
if (mem->buffer)
{
memcpy(new_buf, mem->buffer, mem->size);
free(mem->buffer);
MZ_FREE(mem->buffer);
}
mem->buffer = new_buf;
@@ -77,6 +79,7 @@ int32_t mz_stream_mem_open(void *stream, const char *path, int32_t mode)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
MZ_UNUSED(path);
mem->mode = mode;
mem->limit = 0;
@@ -189,12 +192,16 @@ int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin)
int32_t mz_stream_mem_close(void *stream)
{
MZ_UNUSED(stream);
// We never return errors
return MZ_OK;
}
int32_t mz_stream_mem_error(void *stream)
{
MZ_UNUSED(stream);
// We never return errors
return MZ_OK;
}
@@ -207,12 +214,12 @@ void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size)
mem->limit = size;
}
int32_t mz_stream_mem_get_buffer(void *stream, void **buf)
int32_t mz_stream_mem_get_buffer(void *stream, const void **buf)
{
return mz_stream_mem_get_buffer_at(stream, 0, buf);
}
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, void **buf)
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, const void **buf)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
if (buf == NULL || position < 0 || mem->size < position || mem->buffer == NULL)
@@ -231,7 +238,7 @@ void *mz_stream_mem_create(void **stream)
{
mz_stream_mem *mem = NULL;
mem = (mz_stream_mem *)malloc(sizeof(mz_stream_mem));
mem = (mz_stream_mem *)MZ_ALLOC(sizeof(mz_stream_mem));
if (mem != NULL)
{
memset(mem, 0, sizeof(mz_stream_mem));
@@ -253,8 +260,8 @@ void mz_stream_mem_delete(void **stream)
if (mem != NULL)
{
if ((mem->mode & MZ_OPEN_MODE_CREATE) && (mem->buffer != NULL))
free(mem->buffer);
free(mem);
MZ_FREE(mem->buffer);
MZ_FREE(mem);
}
*stream = NULL;
}
@@ -262,4 +269,4 @@ void mz_stream_mem_delete(void **stream)
void *mz_stream_mem_get_interface(void)
{
return (void *)&mz_stream_mem_vtbl;
}
}
+5 -5
View File
@@ -1,5 +1,5 @@
/* mz_strm_mem.h -- Stream for memory access
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -11,8 +11,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_MEM_H
#define _MZ_STREAM_MEM_H
#ifndef MZ_STREAM_MEM_H
#define MZ_STREAM_MEM_H
#include <stdint.h>
@@ -32,8 +32,8 @@ int32_t mz_stream_mem_close(void *stream);
int32_t mz_stream_mem_error(void *stream);
void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size);
int32_t mz_stream_mem_get_buffer(void *stream, void **buf);
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, void **buf);
int32_t mz_stream_mem_get_buffer(void *stream, const void **buf);
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, const void **buf);
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size);
void* mz_stream_mem_create(void **stream);
+352
View File
@@ -0,0 +1,352 @@
/* mz_strm_pkcrypt.c -- Code for traditional PKWARE encryption
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
This encryption code is a direct transcription of the algorithm from
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
file (appnote.txt) is distributed with the PKZIP program (even in the
version without encryption capabilities).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_ZLIB
#include "zlib.h"
#endif
#include "mz.h"
#include "mz_os.h"
#include "mz_strm.h"
#ifdef HAVE_LZMA
#include "mz_strm_lzma.h"
#endif
#include "mz_strm_pkcrypt.h"
#ifdef HAVE_ZLIB
#include "mz_strm_zlib.h"
#endif
/***************************************************************************/
#define RAND_HEAD_LEN 12
/***************************************************************************/
// Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng
#if (ZLIB_VERNUM < 0x1270) || defined(ZLIBNG_VERNUM) || !defined(HAVE_ZLIB)
#ifdef HAVE_ZLIB
typedef unsigned long z_crc_t;
#else
typedef uint32_t z_crc_t;
#endif
#endif
/***************************************************************************/
static mz_stream_vtbl mz_stream_pkcrypt_vtbl = {
mz_stream_pkcrypt_open,
mz_stream_pkcrypt_is_open,
mz_stream_pkcrypt_read,
mz_stream_pkcrypt_write,
mz_stream_pkcrypt_tell,
mz_stream_pkcrypt_seek,
mz_stream_pkcrypt_close,
mz_stream_pkcrypt_error,
mz_stream_pkcrypt_create,
mz_stream_pkcrypt_delete,
mz_stream_pkcrypt_get_prop_int64,
NULL
};
/***************************************************************************/
typedef struct mz_stream_pkcrypt_s {
mz_stream stream;
int32_t error;
int16_t initialized;
uint8_t buffer[INT16_MAX];
int64_t total_in;
int64_t total_out;
uint32_t keys[3]; // keys defining the pseudo-random sequence
const z_crc_t *crc_32_tab;
uint8_t verify1;
uint8_t verify2;
const char *password;
} mz_stream_pkcrypt;
/***************************************************************************/
#define zdecode(keys,crc_32_tab,c) \
(mz_stream_pkcrypt_update_keys(keys,crc_32_tab, c ^= mz_stream_pkcrypt_decrypt_byte(keys)))
#define zencode(keys,crc_32_tab,c,t) \
(t = mz_stream_pkcrypt_decrypt_byte(keys), mz_stream_pkcrypt_update_keys(keys,crc_32_tab,c), t^(c))
/***************************************************************************/
static uint8_t mz_stream_pkcrypt_decrypt_byte(uint32_t *keys)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
temp = ((uint32_t)(*(keys+2)) & 0xffff) | 2;
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
static uint8_t mz_stream_pkcrypt_update_keys(uint32_t *keys, const z_crc_t *crc_32_tab, int32_t c)
{
#define CRC32(c, b) ((*(crc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
(*(keys+0)) = (uint32_t)CRC32((*(keys+0)), c);
(*(keys+1)) += (*(keys+0)) & 0xff;
(*(keys+1)) = (*(keys+1)) * 134775813L + 1;
{
register int32_t keyshift = (int32_t)((*(keys + 1)) >> 24);
(*(keys+2)) = (uint32_t)CRC32((*(keys+2)), keyshift);
}
return (uint8_t)c;
}
static void mz_stream_pkcrypt_init_keys(const char *password, uint32_t *keys, const z_crc_t *crc_32_tab)
{
*(keys+0) = 305419896L;
*(keys+1) = 591751049L;
*(keys+2) = 878082192L;
while (*password != 0)
{
mz_stream_pkcrypt_update_keys(keys, crc_32_tab, *password);
password += 1;
}
}
/***************************************************************************/
int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
uint16_t t = 0;
int16_t i = 0;
//uint8_t verify1 = 0;
uint8_t verify2 = 0;
uint8_t header[RAND_HEAD_LEN];
const char *password = path;
pkcrypt->total_in = 0;
pkcrypt->total_out = 0;
pkcrypt->initialized = 0;
if (mz_stream_is_open(pkcrypt->stream.base) != MZ_OK)
return MZ_STREAM_ERROR;
if (password == NULL)
password = pkcrypt->password;
if (password == NULL)
return MZ_STREAM_ERROR;
#ifdef HAVE_ZLIB
pkcrypt->crc_32_tab = (z_crc_t *)mz_stream_zlib_get_crc32_table();
#elif defined(HAVE_LZMA)
pkcrypt->crc_32_tab = (z_crc_t *)mz_stream_lzma_get_crc32_table();
#else
#error ZLIB or LZMA required for CRC32
#endif
if (pkcrypt->crc_32_tab == NULL)
return MZ_STREAM_ERROR;
mz_stream_pkcrypt_init_keys(password, pkcrypt->keys, pkcrypt->crc_32_tab);
if (mode & MZ_OPEN_MODE_WRITE)
{
// First generate RAND_HEAD_LEN - 2 random bytes.
mz_os_rand(header, RAND_HEAD_LEN - 2);
// Encrypt random header (last two bytes is high word of crc)
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
header[i] = (uint8_t)zencode(pkcrypt->keys, pkcrypt->crc_32_tab, header[i], t);
header[i++] = (uint8_t)zencode(pkcrypt->keys, pkcrypt->crc_32_tab, pkcrypt->verify1, t);
header[i++] = (uint8_t)zencode(pkcrypt->keys, pkcrypt->crc_32_tab, pkcrypt->verify2, t);
if (mz_stream_write(pkcrypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
return MZ_STREAM_ERROR;
pkcrypt->total_out += RAND_HEAD_LEN;
}
else if (mode & MZ_OPEN_MODE_READ)
{
if (mz_stream_read(pkcrypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
return MZ_STREAM_ERROR;
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
header[i] = (uint8_t)zdecode(pkcrypt->keys, pkcrypt->crc_32_tab, header[i]);
//verify1 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
verify2 = (uint8_t)zdecode(pkcrypt->keys, pkcrypt->crc_32_tab, header[i++]);
// Older versions used 2 byte check, newer versions use 1 byte check.
if ((verify2 != 0) && (verify2 != pkcrypt->verify2))
return MZ_PASSWORD_ERROR;
pkcrypt->total_in += RAND_HEAD_LEN;
}
pkcrypt->initialized = 1;
return MZ_OK;
}
int32_t mz_stream_pkcrypt_is_open(void *stream)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
if (pkcrypt->initialized == 0)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_pkcrypt_read(void *stream, void *buf, int32_t size)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
uint8_t *buf_ptr = (uint8_t *)buf;
int32_t read = 0;
int32_t i = 0;
read = mz_stream_read(pkcrypt->stream.base, buf, size);
for (i = 0; i < read; i++)
buf_ptr[i] = (uint8_t)zdecode(pkcrypt->keys, pkcrypt->crc_32_tab, buf_ptr[i]);
pkcrypt->total_in += read;
return read;
}
int32_t mz_stream_pkcrypt_write(void *stream, const void *buf, int32_t size)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
const uint8_t *buf_ptr = (const uint8_t *)buf;
int32_t written = 0;
int32_t i = 0;
uint16_t t = 0;
if (size > (int32_t)sizeof(pkcrypt->buffer))
return MZ_STREAM_ERROR;
for (i = 0; i < size; i++)
pkcrypt->buffer[i] = (uint8_t)zencode(pkcrypt->keys, pkcrypt->crc_32_tab, buf_ptr[i], t);
written = mz_stream_write(pkcrypt->stream.base, pkcrypt->buffer, size);
if (written > 0)
pkcrypt->total_out += written;
return written;
}
int64_t mz_stream_pkcrypt_tell(void *stream)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
return mz_stream_tell(pkcrypt->stream.base);
}
int32_t mz_stream_pkcrypt_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
return mz_stream_seek(pkcrypt->stream.base, offset, origin);
}
int32_t mz_stream_pkcrypt_close(void *stream)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
pkcrypt->initialized = 0;
return MZ_OK;
}
int32_t mz_stream_pkcrypt_error(void *stream)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
return pkcrypt->error;
}
void mz_stream_pkcrypt_set_password(void *stream, const char *password)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
pkcrypt->password = password;
}
void mz_stream_pkcrypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
pkcrypt->verify1 = verify1;
pkcrypt->verify2 = verify2;
}
void mz_stream_pkcrypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
*verify1 = pkcrypt->verify1;
*verify2 = pkcrypt->verify2;
}
int32_t mz_stream_pkcrypt_get_prop_int64(void *stream, int32_t prop, int64_t *value)
{
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
switch (prop)
{
case MZ_STREAM_PROP_TOTAL_IN:
*value = pkcrypt->total_in;
return MZ_OK;
case MZ_STREAM_PROP_TOTAL_OUT:
*value = pkcrypt->total_out;
return MZ_OK;
}
return MZ_EXIST_ERROR;
}
void *mz_stream_pkcrypt_create(void **stream)
{
mz_stream_pkcrypt *pkcrypt = NULL;
pkcrypt = (mz_stream_pkcrypt *)MZ_ALLOC(sizeof(mz_stream_pkcrypt));
if (pkcrypt != NULL)
{
memset(pkcrypt, 0, sizeof(mz_stream_pkcrypt));
pkcrypt->stream.vtbl = &mz_stream_pkcrypt_vtbl;
}
if (stream != NULL)
*stream = pkcrypt;
return pkcrypt;
}
void mz_stream_pkcrypt_delete(void **stream)
{
mz_stream_pkcrypt *pkcrypt = NULL;
if (stream == NULL)
return;
pkcrypt = (mz_stream_pkcrypt *)*stream;
if (pkcrypt != NULL)
MZ_FREE(pkcrypt);
*stream = NULL;
}
void *mz_stream_pkcrypt_get_interface(void)
{
return (void *)&mz_stream_pkcrypt_vtbl;
}
+56
View File
@@ -0,0 +1,56 @@
/* mz_strm_pkcrypt.h -- Code for traditional PKWARE encryption
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef MZ_STREAM_PKCRYPT_H
#define MZ_STREAM_PKCRYPT_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
int32_t mz_stream_pkcrypt_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_pkcrypt_is_open(void *stream);
int32_t mz_stream_pkcrypt_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_pkcrypt_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_pkcrypt_tell(void *stream);
int32_t mz_stream_pkcrypt_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_pkcrypt_close(void *stream);
int32_t mz_stream_pkcrypt_error(void *stream);
void mz_stream_pkcrypt_set_password(void *stream, const char *password);
void mz_stream_pkcrypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2);
void mz_stream_pkcrypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2);
int32_t mz_stream_pkcrypt_get_prop_int64(void *stream, int32_t prop, int64_t *value);
void* mz_stream_pkcrypt_create(void **stream);
void mz_stream_pkcrypt_delete(void **stream);
void* mz_stream_pkcrypt_get_interface(void);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif
+8 -6
View File
@@ -1,5 +1,5 @@
/* mz_strm_posix.c -- Stream for filesystem access for posix/linux
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -50,7 +50,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_posix_vtbl = {
static mz_stream_vtbl mz_stream_posix_vtbl = {
mz_stream_posix_open,
mz_stream_posix_is_open,
mz_stream_posix_read,
@@ -60,7 +60,9 @@ mz_stream_vtbl mz_stream_posix_vtbl = {
mz_stream_posix_close,
mz_stream_posix_error,
mz_stream_posix_create,
mz_stream_posix_delete
mz_stream_posix_delete,
NULL,
NULL
};
/***************************************************************************/
@@ -201,7 +203,7 @@ void *mz_stream_posix_create(void **stream)
{
mz_stream_posix *posix = NULL;
posix = (mz_stream_posix *)malloc(sizeof(mz_stream_posix));
posix = (mz_stream_posix *)MZ_ALLOC(sizeof(mz_stream_posix));
if (posix != NULL)
{
memset(posix, 0, sizeof(mz_stream_posix));
@@ -209,7 +211,7 @@ void *mz_stream_posix_create(void **stream)
}
if (stream != NULL)
*stream = posix;
return posix;
}
@@ -220,7 +222,7 @@ void mz_stream_posix_delete(void **stream)
return;
posix = (mz_stream_posix *)*stream;
if (posix != NULL)
free(posix);
MZ_FREE(posix);
*stream = NULL;
}
+3 -3
View File
@@ -1,5 +1,5 @@
/* mz_strm_posix.h -- Stream for filesystem access for posix/linux
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -14,8 +14,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_POSIX_H
#define _MZ_STREAM_POSIX_H
#ifndef MZ_STREAM_POSIX_H
#define MZ_STREAM_POSIX_H
#include <stdint.h>
+11 -11
View File
@@ -1,5 +1,5 @@
/* mz_strm_split.c -- Stream for split files
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -29,7 +29,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_split_vtbl = {
static mz_stream_vtbl mz_stream_split_vtbl = {
mz_stream_split_open,
mz_stream_split_is_open,
mz_stream_split_read,
@@ -181,11 +181,11 @@ int32_t mz_stream_split_open(void *stream, const char *path, int32_t mode)
split->mode = mode;
split->path_cd_size = strlen(path) + 1;
split->path_cd = (char *)malloc(split->path_cd_size);
split->path_cd = (char *)MZ_ALLOC(split->path_cd_size);
strncpy(split->path_cd, path, split->path_cd_size);
split->path_disk_size = strlen(path) + 10;
split->path_disk = (char *)malloc(split->path_disk_size);
split->path_disk = (char *)MZ_ALLOC(split->path_disk_size);
strncpy(split->path_disk, path, split->path_disk_size);
if (mode & MZ_OPEN_MODE_WRITE)
@@ -255,7 +255,7 @@ int32_t mz_stream_split_write(void *stream, const void *buf, int32_t size)
int32_t bytes_avail = 0;
int32_t number_disk = -1;
int32_t err = MZ_OK;
uint8_t *buf_ptr = (uint8_t *)buf;
const uint8_t *buf_ptr = (const uint8_t *)buf;
while (bytes_left > 0)
{
@@ -281,11 +281,11 @@ int32_t mz_stream_split_write(void *stream, const void *buf, int32_t size)
bytes_to_write = bytes_avail;
}
}
written = mz_stream_write(split->stream.base, buf_ptr, bytes_to_write);
if (written != bytes_to_write)
return MZ_STREAM_ERROR;
bytes_left -= written;
buf_ptr += written;
split->total_out += written;
@@ -368,7 +368,7 @@ void *mz_stream_split_create(void **stream)
{
mz_stream_split *split = NULL;
split = (mz_stream_split *)malloc(sizeof(mz_stream_split));
split = (mz_stream_split *)MZ_ALLOC(sizeof(mz_stream_split));
if (split != NULL)
{
memset(split, 0, sizeof(mz_stream_split));
@@ -389,11 +389,11 @@ void mz_stream_split_delete(void **stream)
if (split != NULL)
{
if (split->path_cd)
free(split->path_cd);
MZ_FREE(split->path_cd);
if (split->path_disk)
free(split->path_disk);
MZ_FREE(split->path_disk);
free(split);
MZ_FREE(split);
}
*stream = NULL;
}
+3 -3
View File
@@ -1,5 +1,5 @@
/* mz_strm_split.h -- Stream for split files
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_SPLIT_H
#define _MZ_STREAM_SPLIT_H
#ifndef MZ_STREAM_SPLIT_H
#define MZ_STREAM_SPLIT_H
#include <stdint.h>
+11 -9
View File
@@ -1,5 +1,5 @@
/* mz_strm_win32.c -- Stream for filesystem access for windows
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -40,7 +40,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_win32_vtbl = {
static mz_stream_vtbl mz_stream_win32_vtbl = {
mz_stream_win32_open,
mz_stream_win32_is_open,
mz_stream_win32_read,
@@ -50,7 +50,9 @@ mz_stream_vtbl mz_stream_win32_vtbl = {
mz_stream_win32_close,
mz_stream_win32_error,
mz_stream_win32_create,
mz_stream_win32_delete
mz_stream_win32_delete,
NULL,
NULL
};
/***************************************************************************/
@@ -99,7 +101,7 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
}
path_wide_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
path_wide = (wchar_t *)malloc((path_wide_size + 1) * sizeof(wchar_t));
path_wide = (wchar_t *)MZ_ALLOC((path_wide_size + 1) * sizeof(wchar_t));
memset(path_wide, 0, sizeof(wchar_t) * (path_wide_size + 1));
MultiByteToWideChar(CP_UTF8, 0, path, -1, path_wide, path_wide_size);
@@ -110,7 +112,7 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
win32->handle = CreateFileW(path_wide, desired_access, share_mode, NULL, creation_disposition, flags_attribs, NULL);
#endif
free(path_wide);
MZ_FREE(path_wide);
if (mz_stream_win32_is_open(stream) != MZ_OK)
{
@@ -121,7 +123,7 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
if (mode & MZ_OPEN_MODE_APPEND)
return mz_stream_win32_seek(stream, 0, MZ_SEEK_END);
return MZ_OK;
return MZ_OK;
}
int32_t mz_stream_win32_is_open(void *stream)
@@ -261,7 +263,7 @@ void *mz_stream_win32_create(void **stream)
{
mz_stream_win32 *win32 = NULL;
win32 = (mz_stream_win32 *)malloc(sizeof(mz_stream_win32));
win32 = (mz_stream_win32 *)MZ_ALLOC(sizeof(mz_stream_win32));
if (win32 != NULL)
{
memset(win32, 0, sizeof(mz_stream_win32));
@@ -280,11 +282,11 @@ void mz_stream_win32_delete(void **stream)
return;
win32 = (mz_stream_win32 *)*stream;
if (win32 != NULL)
free(win32);
MZ_FREE(win32);
*stream = NULL;
}
void *mz_stream_win32_get_interface(void)
{
return (void *)&mz_stream_win32_vtbl;
}
}
+3 -3
View File
@@ -1,5 +1,5 @@
/* mz_sstrm_win32.h -- Stream for filesystem access for windows
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -14,8 +14,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_WIN32_H
#define _MZ_STREAM_WIN32_H
#ifndef MZ_STREAM_WIN32_H
#define MZ_STREAM_WIN32_H
#include <stdint.h>
+19 -7
View File
@@ -1,5 +1,5 @@
/* mz_strm_zlib.c -- Stream for zlib inflate/deflate
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -33,7 +33,7 @@
/***************************************************************************/
mz_stream_vtbl mz_stream_zlib_vtbl = {
static mz_stream_vtbl mz_stream_zlib_vtbl = {
mz_stream_zlib_open,
mz_stream_zlib_is_open,
mz_stream_zlib_read,
@@ -70,6 +70,7 @@ int32_t mz_stream_zlib_open(void *stream, const char *path, int32_t mode)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
MZ_UNUSED(path);
zlib->zstream.data_type = Z_BINARY;
zlib->zstream.zalloc = Z_NULL;
@@ -138,7 +139,7 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
bytes_to_read = sizeof(zlib->buffer);
if (zlib->max_total_in > 0)
{
if ((zlib->max_total_in - zlib->total_in) < sizeof(zlib->buffer))
if ((zlib->max_total_in - zlib->total_in) < (int64_t)sizeof(zlib->buffer))
bytes_to_read = (int32_t)(zlib->max_total_in - zlib->total_in);
}
@@ -180,7 +181,7 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
if (err == Z_STREAM_END)
break;
if (err != Z_OK)
{
zlib->error = err;
@@ -255,7 +256,7 @@ int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size)
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
zlib->zstream.next_in = (Bytef*)buf;
zlib->zstream.next_in = (Bytef*)(intptr_t)buf;
zlib->zstream.avail_in = (uInt)size;
mz_stream_zlib_deflate(stream, Z_NO_FLUSH);
@@ -267,11 +268,17 @@ int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size)
int64_t mz_stream_zlib_tell(void *stream)
{
MZ_UNUSED(stream);
return MZ_STREAM_ERROR;
}
int32_t mz_stream_zlib_seek(void *stream, int64_t offset, int32_t origin)
{
MZ_UNUSED(stream);
MZ_UNUSED(offset);
MZ_UNUSED(origin);
return MZ_STREAM_ERROR;
}
@@ -342,7 +349,7 @@ void *mz_stream_zlib_create(void **stream)
{
mz_stream_zlib *zlib = NULL;
zlib = (mz_stream_zlib *)malloc(sizeof(mz_stream_zlib));
zlib = (mz_stream_zlib *)MZ_ALLOC(sizeof(mz_stream_zlib));
if (zlib != NULL)
{
memset(zlib, 0, sizeof(mz_stream_zlib));
@@ -362,7 +369,7 @@ void mz_stream_zlib_delete(void **stream)
return;
zlib = (mz_stream_zlib *)*stream;
if (zlib != NULL)
free(zlib);
MZ_FREE(zlib);
*stream = NULL;
}
@@ -376,6 +383,11 @@ static int32_t mz_stream_zlib_crc32(int32_t value, const void *buf, int32_t size
return crc32(value, buf, size);
}
void *mz_stream_zlib_get_crc32_table(void)
{
return (void *)get_crc_table();
}
void *mz_stream_zlib_get_crc32_update(void)
{
return (void *)mz_stream_zlib_crc32;
+4 -3
View File
@@ -1,5 +1,5 @@
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -9,8 +9,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_ZLIB_H
#define _MZ_STREAM_ZLIB_H
#ifndef MZ_STREAM_ZLIB_H
#define MZ_STREAM_ZLIB_H
#include <stdint.h>
@@ -36,6 +36,7 @@ void* mz_stream_zlib_create(void **stream);
void mz_stream_zlib_delete(void **stream);
void* mz_stream_zlib_get_interface(void);
void* mz_stream_zlib_get_crc32_table(void);
void* mz_stream_zlib_get_crc32_update(void);
/***************************************************************************/
+148 -70
View File
@@ -1,5 +1,5 @@
/* zip.c -- Zip manipulation
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -30,12 +30,12 @@
#ifdef HAVE_BZIP2
# include "mz_strm_bzip.h"
#endif
#ifdef HAVE_CRYPT
# include "mz_strm_crypt.h"
#endif
#ifdef HAVE_LZMA
# include "mz_strm_lzma.h"
#endif
#ifdef HAVE_PKCRYPT
# include "mz_strm_pkcrypt.h"
#endif
#ifdef HAVE_ZLIB
# include "mz_strm_zlib.h"
#endif
@@ -54,7 +54,6 @@
#define MZ_ZIP_SIZE_CD_ITEM (0x2e)
#define MZ_ZIP_SIZE_CD_LOCATOR64 (0x14)
#define MZ_ZIP_SIZE_LOCALHEADER (0x1e)
#define MZ_ZIP_EXTENSION_ZIP64 (0x0001)
#define MZ_ZIP_EXTENSION_NTFS (0x000a)
@@ -85,7 +84,7 @@ typedef struct mz_zip_s
uint64_t cd_offset; // offset of start of central directory
uint64_t cd_size; // size of the central directory
uint16_t entry_scanned;
uint16_t entry_scanned;
uint16_t entry_opened; // 1 if a file in the zip is currently writ.
uint64_t entry_read;
@@ -312,7 +311,7 @@ static int32_t mz_zip_read_cd(void *handle)
if ((err == MZ_OK) && (comment_size > 0))
{
zip->comment = (char *)malloc(comment_size + 1);
zip->comment = (char *)MZ_ALLOC(comment_size + 1);
if (zip->comment)
{
if (mz_stream_read(zip->stream, zip->comment, comment_size) != comment_size)
@@ -336,7 +335,7 @@ static int32_t mz_zip_write_cd(void *handle)
if (zip == NULL)
return MZ_PARAM_ERROR;
if (mz_stream_get_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_NUMBER, &disk_number) == MZ_OK)
zip->disk_number_with_cd = (uint32_t)disk_number;
if (mz_stream_get_prop_int64(zip->stream, MZ_STREAM_PROP_DISK_SIZE, &disk_size) == MZ_OK && disk_size > 0)
@@ -347,7 +346,7 @@ static int32_t mz_zip_write_cd(void *handle)
mz_stream_seek(zip->cd_mem_stream, 0, MZ_SEEK_END);
zip->cd_size = (uint32_t)mz_stream_tell(zip->cd_mem_stream);
mz_stream_seek(zip->cd_mem_stream, 0, MZ_SEEK_SET);
err = mz_stream_copy(zip->stream, zip->cd_mem_stream, (int32_t)zip->cd_size);
// Write the ZIP64 central directory header
@@ -400,7 +399,7 @@ static int32_t mz_zip_write_cd(void *handle)
// Write the central directory header
// Signature
// Signature
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, MZ_ZIP_MAGIC_ENDHEADER);
// Number of this disk
@@ -456,7 +455,7 @@ extern void* mz_zip_open(void *stream, int32_t mode)
int32_t err = MZ_OK;
zip = (mz_zip *)malloc(sizeof(mz_zip));
zip = (mz_zip *)MZ_ALLOC(sizeof(mz_zip));
if (zip == NULL)
return NULL;
@@ -558,9 +557,9 @@ extern int32_t mz_zip_close(void *handle)
}
if (zip->comment)
free(zip->comment);
MZ_FREE(zip->comment);
free(zip);
MZ_FREE(zip);
return err;
}
@@ -583,9 +582,9 @@ extern int32_t mz_zip_set_comment(void *handle, const char *comment)
if (zip == NULL || comment == NULL)
return MZ_PARAM_ERROR;
if (zip->comment != NULL)
free(zip->comment);
MZ_FREE(zip->comment);
comment_size = (uint16_t)(strlen(comment) + 1);
zip->comment = (char *)malloc(comment_size);
zip->comment = (char *)MZ_ALLOC(comment_size);
strncpy(zip->comment, comment, comment_size);
return MZ_OK;
}
@@ -608,27 +607,6 @@ extern int32_t mz_zip_set_version_madeby(void *handle, uint16_t version_madeby)
return MZ_OK;
}
static int16_t mz_zip_entry_get_version_needed(int16_t zip64, mz_zip_file *file_info)
{
int16_t version_needed = 20;
if (file_info == NULL)
return MZ_PARAM_ERROR;
if (file_info->version_needed > 0)
version_needed = file_info->version_needed;
if (zip64)
version_needed = 45;
#ifdef HAVE_AES
if ((file_info->flag & MZ_ZIP_FLAG_ENCRYPTED) && (file_info->aes_version))
version_needed = 51;
#endif
#ifdef HAVE_LZMA
if (file_info->compression_method == MZ_COMPRESS_METHOD_LZMA)
version_needed = 63;
#endif
return version_needed;
}
// Get info about the current file in the zip file
static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file *file_info, void *file_info_stream)
{
@@ -662,7 +640,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
err = MZ_FORMAT_ERROR;
else if ((!local) && (magic != MZ_ZIP_MAGIC_CENTRALHEADER))
err = MZ_FORMAT_ERROR;
// Read header fields
if (err == MZ_OK)
{
@@ -716,7 +694,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
if ((err == MZ_OK) && (file_info->filename_size > 0))
{
mz_stream_mem_get_buffer(file_info_stream, (void **)&file_info->filename);
mz_stream_mem_get_buffer(file_info_stream, (const void **)&file_info->filename);
err = mz_stream_copy(file_info_stream, stream, file_info->filename_size);
if (err == MZ_OK)
@@ -727,7 +705,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
if ((err == MZ_OK) && (file_info->extrafield_size > 0))
{
mz_stream_mem_get_buffer_at(file_info_stream, seek, (void **)&file_info->extrafield);
mz_stream_mem_get_buffer_at(file_info_stream, seek, (const void **)&file_info->extrafield);
err = mz_stream_copy(file_info_stream, stream, file_info->extrafield_size);
if (err == MZ_OK)
@@ -761,7 +739,8 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
// NTFS extra field
else if (extra_header_id == MZ_ZIP_EXTENSION_NTFS)
{
err = mz_stream_read_uint32(file_info_stream, &reserved);
if (err == MZ_OK)
err = mz_stream_read_uint32(file_info_stream, &reserved);
extra_data_size_read = 4;
while ((err == MZ_OK) && (extra_data_size_read < extra_data_size))
@@ -770,7 +749,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
if (err == MZ_OK)
err = mz_stream_read_uint16(file_info_stream, &ntfs_attrib_size);
if ((ntfs_attrib_id == 0x01) && (ntfs_attrib_size == 24))
if ((err == MZ_OK) && (ntfs_attrib_id == 0x01) && (ntfs_attrib_size == 24))
{
err = mz_stream_read_uint64(file_info_stream, &ntfs_time);
mz_zip_ntfs_to_unix_time(ntfs_time, &file_info->modified_date);
@@ -788,7 +767,8 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
}
else
{
err = mz_stream_seek(file_info_stream, ntfs_attrib_size, MZ_SEEK_CUR);
if (err == MZ_OK)
err = mz_stream_seek(file_info_stream, ntfs_attrib_size, MZ_SEEK_CUR);
}
extra_data_size_read += ntfs_attrib_size + 4;
@@ -833,7 +813,7 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
if ((err == MZ_OK) && (file_info->comment_size > 0))
{
mz_stream_mem_get_buffer_at(file_info_stream, seek, (void **)&file_info->comment);
mz_stream_mem_get_buffer_at(file_info_stream, seek, (const void **)&file_info->comment);
err = mz_stream_copy(file_info_stream, stream, file_info->comment_size);
if (err == MZ_OK)
@@ -852,13 +832,16 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
uint16_t extrafield_zip64_size = 0;
uint16_t extrafield_ntfs_size = 0;
uint16_t filename_size = 0;
uint16_t filename_length = 0;
uint16_t comment_size = 0;
uint16_t version_needed = 0;
uint8_t zip64 = 0;
int32_t err = MZ_OK;
if (file_info == NULL)
return MZ_PARAM_ERROR;
// Calculate extra field sizes
extrafield_size = file_info->extrafield_size;
if (file_info->uncompressed_size >= UINT32_MAX)
@@ -868,8 +851,19 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
if (file_info->disk_offset >= UINT32_MAX)
extrafield_zip64_size += 8;
// Use 64-bit data descriptor if we don't know uncompressed size ahead of time
zip64 = (local && file_info->uncompressed_size == 0) || (extrafield_zip64_size > 0);
if (file_info->zip64 == MZ_ZIP64_AUTO)
{
// If uncompressed size is unknown, assume zip64 for 64-bit data descriptors
zip64 = (local && file_info->uncompressed_size == 0) || (extrafield_zip64_size > 0);
}
else if (file_info->zip64 == MZ_ZIP64_FORCE)
zip64 = 1;
else if (file_info->zip64 == MZ_ZIP64_DISABLE)
{
// Zip64 extension is required to zip file
if (extrafield_zip64_size > 0)
return MZ_PARAM_ERROR;
}
if (zip64)
{
@@ -890,8 +884,6 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
extrafield_size += extrafield_ntfs_size;
}
file_info->version_needed = mz_zip_entry_get_version_needed(zip64, file_info);
if (local)
err = mz_stream_write_uint32(stream, MZ_ZIP_MAGIC_LOCALHEADER);
else
@@ -901,8 +893,26 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
err = mz_stream_write_uint16(stream, file_info->version_madeby);
}
// Calculate version needed to extract
if (err == MZ_OK)
err = mz_stream_write_uint16(stream, file_info->version_needed);
{
version_needed = file_info->version_needed;
if (version_needed == 0)
{
version_needed = 20;
if (zip64)
version_needed = 45;
#ifdef HAVE_AES
if ((file_info->flag & MZ_ZIP_FLAG_ENCRYPTED) && (file_info->aes_version))
version_needed = 51;
#endif
#ifdef HAVE_LZMA
if (file_info->compression_method == MZ_COMPRESS_METHOD_LZMA)
version_needed = 63;
#endif
}
err = mz_stream_write_uint16(stream, version_needed);
}
if (err == MZ_OK)
err = mz_stream_write_uint16(stream, file_info->flag);
if (err == MZ_OK)
@@ -938,9 +948,20 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
err = mz_stream_write_uint32(stream, (uint32_t)file_info->uncompressed_size);
}
filename_size = (uint16_t)strlen(file_info->filename);
filename_length = (uint16_t)strlen(file_info->filename);
if (err == MZ_OK)
{
filename_size = filename_length;
if (mz_zip_attrib_is_dir(file_info->external_fa, file_info->version_madeby) == MZ_OK)
{
if ((file_info->filename[filename_length - 1] == '/') ||
(file_info->filename[filename_length - 1] == '\\'))
filename_length -= 1;
else
filename_size += 1;
}
err = mz_stream_write_uint16(stream, filename_size);
}
if (err == MZ_OK)
err = mz_stream_write_uint16(stream, extrafield_size);
@@ -967,8 +988,14 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
if (err == MZ_OK)
{
if (mz_stream_write(stream, file_info->filename, filename_size) != filename_size)
if (mz_stream_write(stream, file_info->filename, filename_length) != filename_length)
err = MZ_STREAM_ERROR;
if (err == MZ_OK)
{
// Ensure that directories have a slash appended to them for compatibility
if (mz_zip_attrib_is_dir(file_info->external_fa, file_info->version_madeby) == MZ_OK)
err = mz_stream_write_uint8(stream, '/');
}
}
if (err == MZ_OK)
{
@@ -1073,10 +1100,10 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
return MZ_PARAM_ERROR;
}
if ((zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (password == NULL))
if ((zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (password == NULL) && (zip->compression_method != MZ_COMPRESS_METHOD_RAW))
return MZ_PARAM_ERROR;
if ((err == MZ_OK) && (zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED))
if ((err == MZ_OK) && (zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (zip->compression_method != MZ_COMPRESS_METHOD_RAW))
{
#ifdef HAVE_AES
if (zip->file_info.aes_version)
@@ -1088,7 +1115,7 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
else
#endif
{
#ifdef HAVE_CRYPT
#ifdef HAVE_PKCRYPT
uint8_t verify1 = 0;
uint8_t verify2 = 0;
@@ -1110,9 +1137,9 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
verify2 = (uint8_t)((zip->file_info.crc >> 24) & 0xff);
}
mz_stream_crypt_create(&zip->crypt_stream);
mz_stream_crypt_set_password(zip->crypt_stream, password);
mz_stream_crypt_set_verify(zip->crypt_stream, verify1, verify2);
mz_stream_pkcrypt_create(&zip->crypt_stream);
mz_stream_pkcrypt_set_password(zip->crypt_stream, password);
mz_stream_pkcrypt_set_verify(zip->crypt_stream, verify1, verify2);
#endif
}
}
@@ -1131,8 +1158,10 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
{
if (zip->compression_method == MZ_COMPRESS_METHOD_RAW)
mz_stream_raw_create(&zip->compress_stream);
#ifdef HAVE_ZLIB
else if (zip->compression_method == MZ_COMPRESS_METHOD_DEFLATE)
mz_stream_zlib_create(&zip->compress_stream);
#endif
#ifdef HAVE_BZIP2
else if (zip->compression_method == MZ_COMPRESS_METHOD_BZIP2)
mz_stream_bzip_create(&zip->compress_stream);
@@ -1205,7 +1234,7 @@ extern int32_t mz_zip_entry_read_open(void *handle, int16_t raw, const char *pas
int16_t compression_method = 0;
int32_t err = MZ_OK;
#if !defined(HAVE_CRYPT) && !defined(HAVE_AES)
#if !defined(HAVE_PKCRYPT) && !defined(HAVE_AES)
if (password != NULL)
return MZ_PARAM_ERROR;
#endif
@@ -1215,7 +1244,7 @@ extern int32_t mz_zip_entry_read_open(void *handle, int16_t raw, const char *pas
return MZ_PARAM_ERROR;
if (zip->entry_scanned == 0)
return MZ_PARAM_ERROR;
if ((zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (password == NULL))
if ((zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (password == NULL) && (!raw))
return MZ_PARAM_ERROR;
if (zip->file_info.disk_number == zip->disk_number_with_cd)
@@ -1237,8 +1266,7 @@ extern int32_t mz_zip_entry_read_open(void *handle, int16_t raw, const char *pas
return err;
}
extern int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
int16_t compress_level, const char *password)
extern int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info, int16_t compress_level, const char *password)
{
mz_zip *zip = (mz_zip *)handle;
int64_t disk_number = 0;
@@ -1246,7 +1274,7 @@ extern int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_inf
int16_t compression_method = 0;
#if !defined(HAVE_CRYPT) && !defined(HAVE_AES)
#if !defined(HAVE_PKCRYPT) && !defined(HAVE_AES)
if (password != NULL)
return MZ_PARAM_ERROR;
#endif
@@ -1263,8 +1291,6 @@ extern int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_inf
memcpy(&zip->file_info, file_info, sizeof(mz_zip_file));
compression_method = zip->file_info.compression_method;
if (compress_level == 0)
compression_method = MZ_COMPRESS_METHOD_RAW;
if (compression_method == MZ_COMPRESS_METHOD_DEFLATE)
{
@@ -1299,6 +1325,9 @@ extern int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_inf
zip->file_info.aes_encryption_mode = MZ_AES_ENCRYPTION_MODE_256;
#endif
if ((compress_level == 0) || (mz_zip_attrib_is_dir(zip->file_info.external_fa, zip->file_info.version_madeby) == MZ_OK))
compression_method = MZ_COMPRESS_METHOD_RAW;
if (err == MZ_OK)
err = mz_zip_entry_write_header(zip->stream, 1, &zip->file_info);
if (err == MZ_OK)
@@ -1449,7 +1478,7 @@ static int32_t mz_zip_goto_next_entry_int(void *handle)
zip->entry_scanned = 0;
mz_stream_set_prop_int64(zip->cd_stream, MZ_STREAM_PROP_DISK_NUMBER, -1);
err = mz_stream_seek(zip->cd_stream, zip->cd_current_pos, MZ_SEEK_SET);
if (err == MZ_OK)
err = mz_zip_entry_read_header(zip->cd_stream, 0, &zip->file_info, zip->file_info_stream);
@@ -1467,7 +1496,7 @@ extern int32_t mz_zip_get_number_entry(void *handle, int64_t *number_entry)
return MZ_OK;
}
extern int32_t mz_zip_get_disk_number_with_cd(void *handle, int32_t *disk_number_with_cd)
extern int32_t mz_zip_get_disk_number_with_cd(void *handle, uint32_t *disk_number_with_cd)
{
mz_zip *zip = (mz_zip *)handle;
if (zip == NULL || disk_number_with_cd == NULL)
@@ -1476,6 +1505,31 @@ extern int32_t mz_zip_get_disk_number_with_cd(void *handle, int32_t *disk_number
return MZ_OK;
}
extern int64_t mz_zip_get_entry(void *handle)
{
mz_zip *zip = (mz_zip *)handle;
if (zip == NULL)
return MZ_PARAM_ERROR;
return zip->cd_current_pos;
}
extern int32_t mz_zip_goto_entry(void *handle, uint64_t cd_pos)
{
mz_zip *zip = (mz_zip *)handle;
if (zip == NULL)
return MZ_PARAM_ERROR;
if (cd_pos < zip->cd_start_pos || cd_pos > zip->cd_start_pos + zip->cd_size)
return MZ_PARAM_ERROR;
zip->cd_current_pos = cd_pos;
return mz_zip_goto_next_entry_int(handle);
}
extern int32_t mz_zip_goto_first_entry(void *handle)
{
mz_zip *zip = (mz_zip *)handle;
@@ -1529,10 +1583,30 @@ extern int32_t mz_zip_locate_entry(void *handle, const char *filename, mz_filena
/***************************************************************************/
int32_t mz_zip_attrib_is_dir(int32_t attributes, int32_t version_madeby)
{
int32_t host_system = (uint8_t)(version_madeby >> 8);
if (host_system == MZ_HOST_SYSTEM_MSDOS || host_system == MZ_HOST_SYSTEM_WINDOWS_NTFS)
{
if ((attributes & 0x10) == 0x10) // FILE_ATTRIBUTE_DIRECTORY
return MZ_OK;
}
else if (host_system == MZ_HOST_SYSTEM_UNIX || host_system == MZ_HOST_SYSTEM_OSX_DARWIN)
{
if ((attributes & 00170000) == 0040000) // S_ISDIR
return MZ_OK;
}
return MZ_EXIST_ERROR;
}
/***************************************************************************/
static int32_t mz_zip_invalid_date(const struct tm *ptm)
{
#define datevalue_in_range(min, max, value) ((min) <= (value) && (value) <= (max))
return (!datevalue_in_range(0, 207, ptm->tm_year) ||
return (!datevalue_in_range(0, 127 + 80, ptm->tm_year) || // 1980-based year, allow 80 extra
!datevalue_in_range(0, 11, ptm->tm_mon) ||
!datevalue_in_range(1, 31, ptm->tm_mday) ||
!datevalue_in_range(0, 23, ptm->tm_hour) ||
@@ -1582,9 +1656,13 @@ int32_t mz_zip_time_t_to_tm(time_t unix_time, struct tm *ptm)
struct tm *ltm = NULL;
if (ptm == NULL)
return MZ_PARAM_ERROR;
ltm = localtime(&unix_time);
ltm = localtime(&unix_time); // Returns a 1900-based year
if (ltm == NULL)
{
// Invalid date stored, so don't return it
memset(ptm, 0, sizeof(struct tm));
return MZ_INTERNAL_ERROR;
}
memcpy(ptm, ltm, sizeof(struct tm));
return MZ_OK;
}
@@ -1598,7 +1676,7 @@ uint32_t mz_zip_time_t_to_dos_date(time_t unix_time)
uint32_t mz_zip_tm_to_dosdate(const struct tm *ptm)
{
struct tm fixed_tm = { 0 };
struct tm fixed_tm;
// Years supported:
@@ -1610,12 +1688,12 @@ uint32_t mz_zip_tm_to_dosdate(const struct tm *ptm)
memcpy(&fixed_tm, ptm, sizeof(struct tm));
if (fixed_tm.tm_year >= 1980) // range [1980, 2107]
fixed_tm.tm_year -= 1980;
else if (fixed_tm.tm_year >= 80) // range [80, 99]
else if (fixed_tm.tm_year >= 80) // range [80, 207]
fixed_tm.tm_year -= 80;
else // range [00, 79]
fixed_tm.tm_year += 20;
if (mz_zip_invalid_date(ptm))
if (mz_zip_invalid_date(&fixed_tm))
return 0;
return (uint32_t)(((fixed_tm.tm_mday) + (32 * (fixed_tm.tm_mon + 1)) + (512 * fixed_tm.tm_year)) << 16) |
+22 -12
View File
@@ -1,5 +1,5 @@
/* mz_zip.h -- Zip manipulation
Version 2.2.9, April 18th, 2018
Version 2.3.2, May 29, 2018
part of the MiniZip project
Copyright (C) 2010-2018 Nathan Moinvaziri
@@ -14,8 +14,8 @@
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_ZIP_H
#define _MZ_ZIP_H
#ifndef MZ_ZIP_H
#define MZ_ZIP_H
#include <stdint.h>
#include <time.h>
@@ -30,9 +30,9 @@ extern "C" {
typedef struct mz_zip_file_s
{
uint16_t version_madeby; // version made by
uint16_t version_madeby; // version made by
uint16_t version_needed; // version needed to extract
uint16_t flag; // general purpose bit flag
uint16_t flag; // general purpose bit flag
uint16_t compression_method; // compression method
time_t modified_date; // last modified date in unix time
time_t accessed_date; // last accessed date in unix time
@@ -47,10 +47,11 @@ typedef struct mz_zip_file_s
uint64_t disk_offset; // relative offset of local header
uint16_t internal_fa; // internal file attributes
uint32_t external_fa; // external file attributes
uint16_t zip64; // zip64 extension mode
char *filename; // filename string
uint8_t *extrafield; // extrafield data
char *comment; // comment string
const char *filename; // filename string
const uint8_t *extrafield; // extrafield data
const char *comment; // comment string
#ifdef HAVE_AES
uint16_t aes_version; // winzip aes extension if not 0
@@ -108,22 +109,31 @@ extern int32_t mz_zip_entry_close(void *handle);
extern int32_t mz_zip_get_number_entry(void *handle, int64_t *number_entry);
// Get the total number of entries
extern int32_t mz_zip_get_disk_number_with_cd(void *handle, int32_t *disk_number_with_cd);
extern int32_t mz_zip_get_disk_number_with_cd(void *handle, uint32_t *disk_number_with_cd);
// Get the the disk number containing the central directory record
extern int64_t mz_zip_get_entry(void *handle);
// Return offset of the current entry in the zip file
extern int32_t mz_zip_goto_entry(void *handle, uint64_t cd_pos);
// Go to specified entry in the zip file
extern int32_t mz_zip_goto_first_entry(void *handle);
// Go to the first entry in the zip file
// Go to the first entry in the zip file
extern int32_t mz_zip_goto_next_entry(void *handle);
// Go to the next entry in the zip file or MZ_END_OF_LIST if reaching the end
typedef int32_t (*mz_filename_compare_cb)(void *handle, const char *filename1, const char *filename2);
extern int32_t mz_zip_locate_entry(void *handle, const char *filename,
extern int32_t mz_zip_locate_entry(void *handle, const char *filename,
mz_filename_compare_cb filename_compare_cb);
// Locate the file with the specified name in the zip file or MZ_END_LIST if not found
/***************************************************************************/
int32_t mz_zip_attrib_is_dir(int32_t attributes, int32_t version_madeby);
// Checks to see if the attribute is a directory based on platform
int32_t mz_zip_dosdate_to_tm(uint64_t dos_date, struct tm *ptm);
// Convert dos date/time format to struct tm
@@ -131,7 +141,7 @@ time_t mz_zip_dosdate_to_time_t(uint64_t dos_date);
// Convert dos date/time format to time_t
int32_t mz_zip_time_t_to_tm(time_t unix_time, struct tm *ptm);
// Convert time_t to time struct
// Convert time_t to time struct
uint32_t mz_zip_time_t_to_dos_date(time_t unix_time);
// Convert time_t to dos date/time format