Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ca7f3950c | ||
|
|
b150432588 | ||
|
|
c78c782f63 | ||
|
|
1ff40343b5 | ||
|
|
c1fd2edbd2 | ||
|
|
2df1ecbce4 | ||
|
|
a893e6f678 | ||
|
|
8ff664da01 | ||
|
|
d931843012 | ||
|
|
b99b3bf3fc | ||
|
|
f2b2dad2c9 | ||
|
|
9df028d532 | ||
|
|
d058fdb3a1 | ||
|
|
6675c44613 | ||
|
|
4ff891a638 | ||
|
|
f9e344888f | ||
|
|
9e9d0299f1 | ||
|
|
5a16351708 | ||
|
|
5cb88b8f09 | ||
|
|
536a250734 | ||
|
|
e8c94b0570 | ||
|
|
9bd8e85399 | ||
|
|
41eaa4c0ab | ||
|
|
025212f6dc | ||
|
|
6295dcf005 | ||
|
|
62f435adbb | ||
|
|
fa0c9c8edc | ||
|
|
7f73943486 | ||
|
|
2ce1fe2732 | ||
|
|
6b64b924af | ||
|
|
2eb2907823 | ||
|
|
b4d88d426b | ||
|
|
ba1db16a28 | ||
|
|
6ac5fe69d0 | ||
|
|
4c642fc296 | ||
|
|
d8f00c57cb | ||
|
|
54b9939845 | ||
|
|
13a51b9389 | ||
|
|
1b6fcaca41 | ||
|
|
cdac37e1fe | ||
|
|
9897259b04 | ||
|
|
e9ae46ba27 | ||
|
|
3e2d07451c | ||
|
|
d31c5de5b0 | ||
|
|
ad82950a53 | ||
|
|
39365dd10d | ||
|
|
76fb8903e1 | ||
|
|
e849627093 | ||
|
|
6f3a0a6ad0 | ||
|
|
b066fd9677 | ||
|
|
b578fa5ba5 | ||
|
|
bacef206da | ||
|
|
d96f23f925 | ||
|
|
a5bc018ecc | ||
|
|
83aa562e32 | ||
|
|
8a35deab70 | ||
|
|
783d258c68 | ||
|
|
b16ab566ef | ||
|
|
ddeeae3388 | ||
|
|
e231cfd9d8 | ||
|
|
f96e8636a4 | ||
|
|
f4207b7a23 | ||
|
|
02c9edb3af | ||
|
|
d4f27376aa | ||
|
|
9475829f15 | ||
|
|
19cdb10201 | ||
|
|
d46559398f | ||
|
|
90d31c791d | ||
|
|
0a60d2ca2a | ||
|
|
0c59898b2d | ||
|
|
53c3d0ae2f | ||
|
|
1ee609b759 | ||
|
|
0ecfd22443 | ||
|
|
7de94cf921 | ||
|
|
c1e07aaeb0 | ||
|
|
329ac651d8 | ||
|
|
4d0897361b | ||
|
|
fd2fb24b4e | ||
|
|
82fa1b39c0 | ||
|
|
2d37e12f36 | ||
|
|
fe9ec41c49 | ||
|
|
a8b23065cd | ||
|
|
08b01ca7b7 | ||
|
|
bc64e9f899 | ||
|
|
abb508eabe | ||
|
|
1139b468c1 | ||
|
|
c4916c971a | ||
|
|
d8b232a6e9 | ||
|
|
fb8a1cc220 | ||
|
|
a2a3858e05 | ||
|
|
ea2bd795a3 | ||
|
|
51b050e0b8 | ||
|
|
09e41030a5 | ||
|
|
7817f5c8d5 | ||
|
|
a4549e0689 | ||
|
|
4d29ba4782 | ||
|
|
4d4c9db5b0 | ||
|
|
a93a2ad678 | ||
|
|
e0b2477114 | ||
|
|
264dc189b3 | ||
|
|
b2b082c67d | ||
|
|
12d03f4e61 | ||
|
|
dd103f4fc1 | ||
|
|
d82579a400 | ||
|
|
98cbf2296a | ||
|
|
9320beab03 | ||
|
|
f47e75303d | ||
|
|
11a44ecf33 | ||
|
|
5498bb6c4f | ||
|
|
278770c5f3 | ||
|
|
e71d8776be | ||
|
|
3c2b4da788 | ||
|
|
c6443ff336 | ||
|
|
a7af82f8cf | ||
|
|
146fa3a663 | ||
|
|
96b401b2c5 | ||
|
|
771856888c | ||
|
|
5502aeaeb2 | ||
|
|
2805bd4688 | ||
|
|
4d6530cd88 | ||
|
|
1f9efeae4f | ||
|
|
0687386d8b | ||
|
|
d5911f4524 | ||
|
|
23b9d094d7 | ||
|
|
258d42c566 | ||
|
|
8ce54b4a8d | ||
|
|
f07057a85e | ||
|
|
e440f1e9d5 | ||
|
|
6fab9297d2 | ||
|
|
1d6d183af6 | ||
|
|
f274ae0649 | ||
|
|
95fec96e05 | ||
|
|
3c7568fa67 | ||
|
|
05a45d61ab | ||
|
|
d4d49df0b1 | ||
|
|
f9b4d20535 | ||
|
|
cf622bb55c | ||
|
|
57b65f8a15 | ||
|
|
effc1428ff | ||
|
|
286a8174f6 | ||
|
|
b08bd9a3fa | ||
|
|
07b0ecadc6 | ||
|
|
0dfcdf91ba | ||
|
|
23342c44d4 | ||
|
|
65dbda889d | ||
|
|
e39032376e | ||
|
|
30a5288bf4 | ||
|
|
4cceb2f6c8 | ||
|
|
2ff079d5d8 | ||
|
|
0d85193f89 | ||
|
|
c000e8f1f8 | ||
|
|
761d28e30d | ||
|
|
6000844769 | ||
|
|
51834cd9f9 | ||
|
|
c47090678d | ||
|
|
79138fe17c | ||
|
|
9e8d7a8c76 | ||
|
|
79244df024 | ||
|
|
87a668fd64 | ||
|
|
a18f49f6d3 | ||
|
|
aacf87304e | ||
|
|
130f0591ba | ||
|
|
c8501a4216 | ||
|
|
a90e29704a | ||
|
|
69e3549034 | ||
|
|
a4fc2c5e85 | ||
|
|
8edafb620a | ||
|
|
b4923cd155 | ||
|
|
71295ce78d | ||
|
|
088b819ec0 | ||
|
|
a8f23236e8 | ||
|
|
b11b6cfe63 | ||
|
|
feb86c551a | ||
|
|
826113fd6c | ||
|
|
4d5a9a66c9 | ||
|
|
25634010c9 | ||
|
|
6cda2a7e76 | ||
|
|
7c2005dcf0 | ||
|
|
cb5798a6b9 | ||
|
|
cdef32b909 | ||
|
|
8721aaf7ec | ||
|
|
d15b704c85 | ||
|
|
1b87a5a358 | ||
|
|
e52a3b5732 | ||
|
|
e63d231fa5 | ||
|
|
24280b68e8 |
+20
-23
@@ -4,72 +4,69 @@ matrix:
|
||||
include:
|
||||
- os: windows
|
||||
compiler: clang
|
||||
env: TESTTOOL="--deflate --lzma --pkcrypt --wzaes --zipcd" BUILDDIR="..\build\Debug"
|
||||
env: BUILDDIR="..\build\Debug"
|
||||
- os: windows
|
||||
compiler: gcc
|
||||
env: TESTTOOL="--bzip2 --pkcrypt --wzaes --split" BUILDDIR="..\build\Debug"
|
||||
env: BUILDDIR="..\build\Debug"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TESTTOOL="--deflate --lzma --pkcrypt --wzaes" BUILDDIR="../build"
|
||||
env: BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_ZLIB=OFF" TESTTOOL="--lzma --bzip --pkcrypt --wzaes" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_ZLIB=OFF" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_BZIP=OFF" TESTTOOL="--deflate --lzma --pkcrypt --wzaes" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_BZIP=OFF" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_LZMA=OFF" TESTTOOL="--deflate --bzip --pkcrypt --wzaes" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_LZMA=OFF" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_AES=OFF" TESTTOOL="--deflate --pkcrypt --zipcd" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_WZAES=OFF" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_PKCRYPT=OFF" TESTTOOL="--deflate --wzaes" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_PKCRYPT=OFF" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DCOMPRESS_ONLY=ON" TESTTOOL="--deflate" BUILDDIR="../build"
|
||||
env: TOOL="-DCOMPRESS_ONLY=ON" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DDECOMPRESS_ONLY=ON" TESTTOOL="--deflate" BUILDDIR="../build"
|
||||
env: TOOL="-DDECOMPRESS_ONLY=ON" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_PKCRYPT=OFF -DUSE_AES=OFF" TESTTOOL="--deflate --bzip --lzma" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_PKCRYPT=OFF -DUSE_WZAES=OFF" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_OPENSSL=ON" TESTTOOL="--deflate --pkcrypt --wzaes --sign" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_OPENSSL=ON" BUILDDIR="../build"
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: TESTTOOL="--bzip2 --pkcrypt --wzaes --zipcd" BUILDDIR="../build"
|
||||
env: BUILDDIR="../build"
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: TESTTOOL="--deflate --lzma --pkcrypt --wzaes" BUILDDIR="../build"
|
||||
env: BUILDDIR="../build"
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
env: TESTTOOL="--bzip2 --pkcrypt --wzaes --split" BUILDDIR="../build"
|
||||
env: BUILDDIR="../build"
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_LIBCOMP=ON" TESTTOOL="--deflate --pkcrypt --wzaes" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_LIBCOMP=ON" BUILDDIR="../build"
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
env: TOOL="-DUSE_LIBCOMP=ON" TESTTOOL="--deflate --pkcrypt --wzaes" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_LIBCOMP=ON" BUILDDIR="../build"
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: TOOL="-DUSE_OPENSSL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_INCLUDE_DIRS=/usr/local/opt/openssl/include -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/libcrypto.dylib -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl/lib/libssl.dylib" TESTTOOL="--deflate --pkcrypt --wzaes --sign" BUILDDIR="../build"
|
||||
env: TOOL="-DUSE_OPENSSL=ON -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_INCLUDE_DIRS=/usr/local/opt/openssl/include -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/libcrypto.dylib -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl/lib/libssl.dylib" BUILDDIR="../build"
|
||||
|
||||
before_install:
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libbsd-dev; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libssl-dev; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install openssl; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then choco install python2; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then export PATH="/c/Python27:$PATH"; fi
|
||||
|
||||
before_script:
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake .. -DBUILD_TEST=ON $TOOL
|
||||
- cmake .. -DBUILD_TEST=ON -DBUILD_UNIT_TEST=ON $TOOL
|
||||
|
||||
script:
|
||||
- cmake --build .
|
||||
- cd ../test
|
||||
- python test.py --raw $TEST_TOOL --exe_dir=$BUILDDIR
|
||||
- ctest --output-on-failure -C Debug
|
||||
|
||||
+293
-112
@@ -1,5 +1,5 @@
|
||||
#***************************************************************************
|
||||
# Copyright (C) 2017-2018 Nathan Moinvaziri
|
||||
# Copyright (C) 2017-2019 Nathan Moinvaziri
|
||||
# https://github.com/nmoinvaz/minizip
|
||||
# Copyright (C) 2016 Matthias Schmieder
|
||||
# schmieder.matthias@gmail.com
|
||||
@@ -13,36 +13,38 @@ 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(USE_WZAES "Enables WinZIP AES encryption" ON)
|
||||
option(USE_LIBCOMP "Enables Apple compression" OFF)
|
||||
option(USE_OPENSSL "Enables OpenSSL for encryption" OFF)
|
||||
option(USE_BRG "Enables Brian Gladman's encryption library" OFF)
|
||||
option(COMPRESS_ONLY "Only support compression" OFF)
|
||||
option(DECOMPRESS_ONLY "Only support decompression" OFF)
|
||||
option(BUILD_TEST "Builds minizip test executable" OFF)
|
||||
option(BUILD_UNIT_TEST "Builds minizip unit test project" OFF)
|
||||
option(BUILD_FUZZ_TEST "Builds minizip fuzzer executables" OFF)
|
||||
|
||||
project("minizip" C)
|
||||
|
||||
include(CheckLibraryExists)
|
||||
include(CheckSymbolExists)
|
||||
include(GNUInstallDirs)
|
||||
include(ExternalProject)
|
||||
|
||||
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables")
|
||||
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Installation directory for libraries")
|
||||
set(INSTALL_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Installation directory for headers")
|
||||
set(INSTALL_MAN_DIR ${CMAKE_INSTALL_MANDIR} CACHE PATH "Installation directory for manual pages")
|
||||
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.")
|
||||
|
||||
# Minizip library version
|
||||
set(VERSION "2.7.2")
|
||||
set(VERSION "2.8.2")
|
||||
|
||||
# Minizip api version
|
||||
set(SOVERSION "2.5")
|
||||
|
||||
# Set cmake debug postfix to d
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
include(CheckLibraryExists)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckIncludeFile)
|
||||
include(CheckTypeSize)
|
||||
include(GNUInstallDirs)
|
||||
include(ExternalProject)
|
||||
|
||||
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_FULL_BINDIR} CACHE PATH "Installation directory for executables")
|
||||
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_FULL_LIBDIR} CACHE PATH "Installation directory for libraries")
|
||||
set(INSTALL_INC_DIR ${CMAKE_INSTALL_FULL_INCLUDEDIR} CACHE PATH "Installation directory for headers")
|
||||
set(INSTALL_MAN_DIR ${CMAKE_INSTALL_FULL_MANDIR} CACHE PATH "Installation directory for manual pages")
|
||||
set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
|
||||
set(INSTALL_CMAKE_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/minizip" CACHE PATH "Installation directory for cmake files.")
|
||||
|
||||
set(MINIZIP_PC ${CMAKE_CURRENT_BINARY_DIR}/minizip.pc)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/minizip.pc.cmakein ${MINIZIP_PC} @ONLY)
|
||||
@@ -50,13 +52,12 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/minizip.pc.cmakein ${MINIZIP_PC} @ONL
|
||||
set(PROJECT_NAME libminizip)
|
||||
|
||||
# Ensure correct version of zlib is referenced
|
||||
if(USE_ZLIB)
|
||||
if(USE_ZLIB AND NOT USE_LIBCOMP)
|
||||
set(ZLIB_ROOT ${DEF_ZLIB_ROOT} CACHE PATH "Parent directory of zlib installation")
|
||||
find_package(ZLIB)
|
||||
if(ZLIB_FOUND)
|
||||
message(STATUS "Using ZLIB ${ZLIB_VERSION_STRING}")
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
add_definitions(-DHAVE_ZLIB)
|
||||
else()
|
||||
if (NOT ZLIB_TAG)
|
||||
set(ZLIB_TAG master)
|
||||
@@ -98,14 +99,13 @@ if(USE_ZLIB)
|
||||
BUILD_IN_SOURCE 1
|
||||
INSTALL_DIR ${ZLIB_INSTALL_DIR}
|
||||
BUILD_BYPRODUCTS ${ZLIB_STATIC_LIBRARIES}
|
||||
UPDATE_COMMAND ""
|
||||
CMAKE_CACHE_ARGS
|
||||
-DCMAKE_INSTALL_PREFIX:STRING=${ZLIB_INSTALL_DIR}
|
||||
-DZLIB_COMPAT:STRING=ON
|
||||
)
|
||||
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
add_definitions(-DHAVE_ZLIB)
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -127,16 +127,15 @@ if (USE_OPENSSL)
|
||||
if (OPENSSL_FOUND)
|
||||
message(STATUS "Using OpenSSL ${OPENSSL_VERSION}")
|
||||
include_directories(${OPENSSL_INCLUDE_DIRS})
|
||||
link_directories(${OPENSSL_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Initial source files
|
||||
set(MINIZIP_SRC
|
||||
mz_crypt.c
|
||||
mz_os.c
|
||||
mz_strm.c
|
||||
mz_strm_buf.c
|
||||
mz_strm_crc32.c
|
||||
mz_strm_mem.c
|
||||
mz_strm_split.c
|
||||
mz_zip.c
|
||||
@@ -149,7 +148,6 @@ set(MINIZIP_PUBLIC_HEADERS
|
||||
mz_crypt.h
|
||||
mz_strm.h
|
||||
mz_strm_buf.h
|
||||
mz_strm_crc32.h
|
||||
mz_strm_mem.h
|
||||
mz_strm_split.h
|
||||
mz_strm_os.h
|
||||
@@ -165,61 +163,64 @@ endif()
|
||||
if(DECOMPRESS_ONLY)
|
||||
add_definitions(-DMZ_ZIP_NO_COMPRESSION)
|
||||
endif()
|
||||
if(NOT USE_PKCRYPT AND NOT USE_AES)
|
||||
if(NOT USE_PKCRYPT AND NOT USE_WZAES)
|
||||
add_definitions(-DMZ_ZIP_NO_ENCRYPTION)
|
||||
endif()
|
||||
|
||||
# Check for system includes
|
||||
check_include_file(stdint.h HAVE_STDINT_H)
|
||||
check_include_file(inttypes.h HAVE_INTTYPES_H)
|
||||
|
||||
if(HAVE_STDINT_H)
|
||||
add_definitions(-DHAVE_STDINT_H)
|
||||
endif()
|
||||
if(HAVE_INTTYPES_H)
|
||||
add_definitions(-DHAVE_INTTYPES_H)
|
||||
endif()
|
||||
|
||||
# Check for large file support
|
||||
check_type_size(off64_t OFF64_T)
|
||||
if(HAVE_OFF64_T)
|
||||
add_definitions(-D__USE_FILE_OFFSET64)
|
||||
add_definitions(-D__USE_LARGEFILE64)
|
||||
add_definitions(-D_LARGEFILE64_SOURCE)
|
||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||
endif()
|
||||
# Check for fseeko support
|
||||
check_function_exists(fseeko HAVE_FSEEKO)
|
||||
if(NOT HAVE_FSEEKO)
|
||||
add_definitions(-DNO_FSEEKO)
|
||||
endif()
|
||||
|
||||
# Windows specific
|
||||
if(WIN32)
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_os_win32.c" "mz_strm_os_win32.c")
|
||||
if (USE_PKCRYPT OR USE_AES)
|
||||
if (USE_PKCRYPT OR USE_WZAES)
|
||||
if (NOT USE_OPENSSL AND NOT OPENSSL_FOUND AND NOT USE_BRG)
|
||||
list(APPEND MINIZIP_SRC "mz_crypt_win32.c")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
endif()
|
||||
|
||||
# Windows store specific
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
|
||||
add_definitions(-DMZ_WINRT_API)
|
||||
endif()
|
||||
|
||||
# Create compatibility headers
|
||||
if (USE_COMPAT)
|
||||
set(COMPAT_HEADER "\
|
||||
/* file.h -- Compatibility layer shim\n\
|
||||
part of the MiniZip project\n\n\
|
||||
This program is distributed under the terms of the same license as zlib.\n\
|
||||
See the accompanying LICENSE file for the full text of the license.\n\
|
||||
*/\n\n\
|
||||
#ifndef MZ_COMPAT_FILE\n\
|
||||
#define MZ_COMPAT_FILE\n\
|
||||
#include \"mz_compat.h\"\n\
|
||||
#endif\n")
|
||||
string(REPLACE "file.h" "zip.h" ZIP_COMPAT_HEADER ${COMPAT_HEADER})
|
||||
string(REPLACE "MZ_COMPAT_FILE" "MZ_COMPAT_ZIP" ZIP_COMPAT_HEADER ${ZIP_COMPAT_HEADER})
|
||||
file(WRITE "zip.h" ${ZIP_COMPAT_HEADER})
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "zip.h")
|
||||
string(REPLACE "file.h" "unzip.h" UNZIP_COMPAT_HEADER ${COMPAT_HEADER})
|
||||
string(REPLACE "MZ_COMPAT_FILE" "MZ_COMPAT_UNZIP" UNZIP_COMPAT_HEADER ${UNZIP_COMPAT_HEADER})
|
||||
file(WRITE "unzip.h" ${UNZIP_COMPAT_HEADER})
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "unzip.h")
|
||||
endif()
|
||||
|
||||
# Unix specific
|
||||
if(UNIX)
|
||||
add_definitions(-D_POSIX_C_SOURCE=200112L)
|
||||
list(APPEND MINIZIP_SRC "mz_os_posix.c" "mz_strm_os_posix.c")
|
||||
|
||||
if ((USE_PKCRYPT OR USE_AES) AND (NOT USE_OPENSSL AND NOT OPENSSL_FOUND))
|
||||
if ((USE_PKCRYPT OR USE_WZAES) AND NOT (USE_OPENSSL AND OPENSSL_FOUND))
|
||||
|
||||
if (APPLE AND NOT USE_BRG)
|
||||
list(APPEND MINIZIP_SRC "mz_crypt_apple.c")
|
||||
else()
|
||||
set(USE_BRG TRUE)
|
||||
endif()
|
||||
|
||||
|
||||
# Check to see which random generation functions we have
|
||||
check_symbol_exists("getrandom" "sys/random.h" HAVE_GETRANDOM)
|
||||
if (HAVE_GETRANDOM)
|
||||
@@ -240,7 +241,8 @@ if(UNIX)
|
||||
|
||||
pkg_check_modules(LIBBSD libbsd)
|
||||
if (LIBBSD_FOUND)
|
||||
check_library_exists("${LIBBSD_LIBRARIES}" "arc4random_buf" "${LIBBSD_LIBRARY_DIRS}" HAVE_LIBBSD_ARC4RANDOM_BUF)
|
||||
check_library_exists("${LIBBSD_LIBRARIES}" "arc4random_buf"
|
||||
"${LIBBSD_LIBRARY_DIRS}" HAVE_LIBBSD_ARC4RANDOM_BUF)
|
||||
if (HAVE_LIBBSD_ARC4RANDOM_BUF)
|
||||
add_definitions(-DHAVE_LIBBSD)
|
||||
add_definitions(-DHAVE_ARC4RANDOM_BUF)
|
||||
@@ -251,24 +253,6 @@ if(UNIX)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Setup and use large file macros if necessary
|
||||
set(define_lfs_macros TRUE)
|
||||
|
||||
if(ANDROID)
|
||||
string(REGEX REPLACE "android-([0-9+])" "\\1"
|
||||
android_api "${ANDROID_PLATFORM}")
|
||||
if(android_api LESS 24)
|
||||
set(define_lfs_macros FALSE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(define_lfs_macros)
|
||||
add_definitions(-D__USE_FILE_OFFSET64)
|
||||
add_definitions(-D__USE_LARGEFILE64)
|
||||
add_definitions(-D_LARGEFILE64_SOURCE)
|
||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||
endif()
|
||||
|
||||
find_package(Iconv)
|
||||
if (Iconv_FOUND)
|
||||
message(STATUS "Using Iconv")
|
||||
@@ -281,6 +265,27 @@ endif()
|
||||
if(USE_COMPAT)
|
||||
list(APPEND MINIZIP_SRC "mz_compat.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_compat.h")
|
||||
|
||||
set(COMPAT_HEADER "\
|
||||
/* file.h -- Compatibility layer shim\n\
|
||||
part of the MiniZip project\n\n\
|
||||
This program is distributed under the terms of the same license as zlib.\n\
|
||||
See the accompanying LICENSE file for the full text of the license.\n\
|
||||
*/\n\n\
|
||||
#ifndef MZ_COMPAT_FILE\n\
|
||||
#define MZ_COMPAT_FILE\n\n\
|
||||
#include \"mz_compat.h\"\n\n\
|
||||
#endif\n")
|
||||
|
||||
string(REPLACE "file.h" "zip.h" ZIP_COMPAT_HEADER ${COMPAT_HEADER})
|
||||
string(REPLACE "MZ_COMPAT_FILE" "MZ_COMPAT_ZIP" ZIP_COMPAT_HEADER ${ZIP_COMPAT_HEADER})
|
||||
file(WRITE "zip.h" ${ZIP_COMPAT_HEADER})
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "zip.h")
|
||||
|
||||
string(REPLACE "file.h" "unzip.h" UNZIP_COMPAT_HEADER ${COMPAT_HEADER})
|
||||
string(REPLACE "MZ_COMPAT_FILE" "MZ_COMPAT_UNZIP" UNZIP_COMPAT_HEADER ${UNZIP_COMPAT_HEADER})
|
||||
file(WRITE "unzip.h" ${UNZIP_COMPAT_HEADER})
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "unzip.h")
|
||||
endif()
|
||||
|
||||
# Include PKCRYPT
|
||||
@@ -291,9 +296,9 @@ if(USE_PKCRYPT)
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_pkcrypt.h")
|
||||
endif()
|
||||
|
||||
# Include AES
|
||||
if(USE_AES)
|
||||
add_definitions(-DHAVE_AES)
|
||||
# Include WinZIP AES
|
||||
if(USE_WZAES)
|
||||
add_definitions(-DHAVE_WZAES)
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_strm_wzaes.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_wzaes.h")
|
||||
@@ -335,21 +340,20 @@ endif()
|
||||
|
||||
# Include ZLIB
|
||||
if(USE_ZLIB)
|
||||
add_definitions(-DHAVE_ZLIB)
|
||||
|
||||
if(USE_LIBCOMP)
|
||||
add_definitions(-DHAVE_LIBCOMP)
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_strm_libcomp.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_libcomp.h")
|
||||
else()
|
||||
else()
|
||||
add_definitions(-DHAVE_ZLIB)
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_strm_zlib.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_zlib.h")
|
||||
|
||||
if (ZLIB_FOUND)
|
||||
include(CheckFunctionExists)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ZLIB)
|
||||
CHECK_FUNCTION_EXISTS(z_get_crc_table
|
||||
NEEDS_Z_PREFIX)
|
||||
|
||||
check_function_exists(z_get_crc_table NEEDS_Z_PREFIX)
|
||||
if(NEEDS_Z_PREFIX)
|
||||
add_definitions(-DZ_PREFIX)
|
||||
endif()
|
||||
@@ -364,9 +368,7 @@ if(USE_BZIP2)
|
||||
list(APPEND MINIZIP_SRC "mz_strm_bzip.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_bzip.h")
|
||||
|
||||
if(BZIP2_FOUND)
|
||||
set(CMAKE_REQUIRED_LIBRARIES BZip2::BZip2)
|
||||
else()
|
||||
if(NOT BZIP2_FOUND)
|
||||
add_definitions(-DBZ_NO_STDIO)
|
||||
|
||||
set(BZIP2_SRC
|
||||
@@ -391,8 +393,34 @@ endif()
|
||||
# Include LZMA
|
||||
if(USE_LZMA)
|
||||
add_definitions(-DHAVE_LZMA)
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
add_definitions(-DLZMA_API_STATIC)
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
|
||||
check_include_file(limits.h HAVE_LIMITS_H)
|
||||
check_include_file(string.h HAVE_STRING_H)
|
||||
check_include_file(strings.h HAVE_STRINGS_H)
|
||||
check_include_file(memory.h HAVE_MEMORY_H)
|
||||
check_include_file(stdbool.h HAVE_STDBOOL_H)
|
||||
check_include_file(immintrin.h HAVE_IMMINTRIN_H)
|
||||
|
||||
if(HAVE_LIMITS_H)
|
||||
add_definitions(-DHAVE_LIMITS_H)
|
||||
endif()
|
||||
if(HAVE_STRING_H)
|
||||
add_definitions(-DHAVE_STRING_H)
|
||||
endif()
|
||||
if(HAVE_STRINGS_H)
|
||||
add_definitions(-DHAVE_STRINGS_H)
|
||||
endif()
|
||||
if(HAVE_MEMORY_H)
|
||||
add_definitions(-DHAVE_MEMORY_H)
|
||||
endif()
|
||||
if(HAVE_STDBOOL_H)
|
||||
add_definitions(-DHAVE_STDBOOL_H)
|
||||
endif()
|
||||
if(HAVE_IMMINTRIN_H)
|
||||
add_definitions(-DHAVE_IMMINTRIN_H)
|
||||
endif()
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_strm_lzma.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_lzma.h")
|
||||
@@ -498,22 +526,38 @@ if(USE_LZMA)
|
||||
endif()
|
||||
|
||||
# Enable x86 optimizations if supported
|
||||
if(CMAKE_C_COMPILER MATCHES ".*clang")
|
||||
include(CheckCCompilerFlag)
|
||||
macro(enable_option_if_supported option variable)
|
||||
check_c_compiler_flag("-Werror=unused-command-line-argument ${option}" ${variable})
|
||||
if(${variable})
|
||||
add_compile_options(${option})
|
||||
endif()
|
||||
endmacro()
|
||||
if(CMAKE_BUILD_TYPE MATCHES Release)
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
include(CheckCCompilerFlag)
|
||||
|
||||
enable_option_if_supported(-msse3 check_opt_sse3)
|
||||
enable_option_if_supported(-msse4.1 check_opt_sse41)
|
||||
enable_option_if_supported(-maes check_opt_aes)
|
||||
macro(enable_option_if_supported option variable)
|
||||
check_c_compiler_flag("-Werror=unused-command-line-argument ${option}" ${variable})
|
||||
if(${variable})
|
||||
add_compile_options(${option})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
enable_option_if_supported(-msse3 check_opt_sse3)
|
||||
enable_option_if_supported(-msse4.1 check_opt_sse41)
|
||||
enable_option_if_supported(-maes check_opt_aes)
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
add_compile_options(-O3)
|
||||
endif()
|
||||
else()
|
||||
if(MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Zi")
|
||||
else()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
|
||||
endif()
|
||||
endif()
|
||||
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
|
||||
|
||||
# Enable compiler warnings
|
||||
if(MSVC)
|
||||
add_compile_options(/W3)
|
||||
else()
|
||||
add_compile_options(-W -Wall)
|
||||
add_compile_options(-O3)
|
||||
endif()
|
||||
|
||||
# Create minizip library
|
||||
@@ -525,17 +569,21 @@ add_library(${PROJECT_NAME}
|
||||
${BZIP2_SRC} ${BZIP2_PUBLIC_HEADERS}
|
||||
${LZMA_SRC} ${LZMA_PUBLIC_HEADERS})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
VERSION ${VERSION}
|
||||
SOVERSION ${SOVERSION}
|
||||
LINKER_LANGUAGE C
|
||||
PREFIX ""
|
||||
POSITION_INDEPENDENT_CODE 1)
|
||||
if(USE_LZMA)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99)
|
||||
endif()
|
||||
if (MSVC AND BUILD_SHARED_LIBS)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_NAME "minizip")
|
||||
endif ()
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${VERSION} SOVERSION ${SOVERSION})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C PREFIX ""
|
||||
POSITION_INDEPENDENT_CODE 1)
|
||||
|
||||
# Link with external libraries
|
||||
if(USE_ZLIB)
|
||||
if(USE_ZLIB AND NOT USE_LIBCOMP)
|
||||
target_link_libraries(${PROJECT_NAME} ${ZLIB_LIBRARIES})
|
||||
if(NOT ZLIB_FOUND)
|
||||
add_dependencies(${PROJECT_NAME} zlib)
|
||||
@@ -544,9 +592,6 @@ endif()
|
||||
if(USE_BZIP2 AND BZIP2_FOUND)
|
||||
target_link_libraries(${PROJECT_NAME} ${BZIP2_LIBRARIES})
|
||||
endif()
|
||||
if(USE_LZMA)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99)
|
||||
endif()
|
||||
if(USE_LIBCOMP)
|
||||
target_link_libraries(${PROJECT_NAME} compression)
|
||||
endif()
|
||||
@@ -592,7 +637,143 @@ if(BUILD_TEST)
|
||||
target_link_libraries(minizip ${PROJECT_NAME})
|
||||
|
||||
if(NOT SKIP_INSTALL_BINARIES AND NOT SKIP_INSTALL_ALL)
|
||||
install(TARGETS minizip
|
||||
RUNTIME DESTINATION "bin")
|
||||
install(TARGETS minizip RUNTIME DESTINATION "bin")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_UNIT_TEST)
|
||||
enable_testing()
|
||||
|
||||
function(create_compress_tests EXTRA_NAME EXTRA_ARGS)
|
||||
if(DECOMPRESS_ONLY)
|
||||
return()
|
||||
endif()
|
||||
list(FIND EXTRA_ARGS "-z" ZIPCD_IDX)
|
||||
if(${ZIPCD_IDX} EQUAL -1)
|
||||
set(COMPRESS_METHOD_NAMES "raw")
|
||||
set(COMPRESS_METHOD_ARGS "-0")
|
||||
endif()
|
||||
if (USE_ZLIB OR USE_LIBCOMP)
|
||||
list(APPEND COMPRESS_METHOD_NAMES "deflate")
|
||||
list(APPEND COMPRESS_METHOD_ARGS "-9")
|
||||
endif()
|
||||
if (USE_BZIP2)
|
||||
list(APPEND COMPRESS_METHOD_NAMES "bzip2")
|
||||
list(APPEND COMPRESS_METHOD_ARGS "-b")
|
||||
endif()
|
||||
if (USE_LZMA)
|
||||
list(APPEND COMPRESS_METHOD_NAMES "lzma")
|
||||
list(APPEND COMPRESS_METHOD_ARGS "-m")
|
||||
endif()
|
||||
list(LENGTH COMPRESS_METHOD_NAMES COMPRESS_METHOD_COUNT)
|
||||
math(EXPR COMPRESS_METHOD_COUNT "${COMPRESS_METHOD_COUNT}-1")
|
||||
foreach(INDEX RANGE ${COMPRESS_METHOD_COUNT})
|
||||
list(GET COMPRESS_METHOD_NAMES ${INDEX} COMPRESS_METHOD_NAME)
|
||||
list(GET COMPRESS_METHOD_ARGS ${INDEX} COMPRESS_METHOD_ARG)
|
||||
add_test(NAME ${COMPRESS_METHOD_NAME}-zip-${EXTRA_NAME}
|
||||
COMMAND minizip ${COMPRESS_METHOD_ARG} -o ${EXTRA_ARGS}
|
||||
result.zip test.c test.h empty.txt random.bin uniform.bin fuzz
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
add_test(NAME ${COMPRESS_METHOD_NAME}-list-${EXTRA_NAME}
|
||||
COMMAND minizip -l ${EXTRA_ARGS} result.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
if(NOT COMPRESS_ONLY)
|
||||
add_test(NAME ${COMPRESS_METHOD_NAME}-unzip-${EXTRA_NAME}
|
||||
COMMAND minizip -x -o ${EXTRA_ARGS} -d out result.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
||||
add_test(NAME ${COMPRESS_METHOD_NAME}-append-${EXTRA_NAME}
|
||||
COMMAND minizip ${COMPRESS_METHOD_ARG} -a ${EXTRA_ARGS}
|
||||
result.zip single.txt
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
if(NOT COMPRESS_ONLY)
|
||||
add_test(NAME ${COMPRESS_METHOD_NAME}-append-unzip-${EXTRA_NAME}
|
||||
COMMAND minizip -x -o ${EXTRA_ARGS} -d out result.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
||||
add_test(NAME ${COMPRESS_METHOD_NAME}-erase-${EXTRA_NAME}
|
||||
COMMAND minizip -o -e result.zip test.c test.h
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
if(NOT COMPRESS_ONLY)
|
||||
add_test(NAME ${COMPRESS_METHOD_NAME}-erase-unzip-${EXTRA_NAME}
|
||||
COMMAND minizip -x -o ${EXTRA_ARGS} -d out result.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# Perform tests against ourself
|
||||
create_compress_tests("generic" "")
|
||||
create_compress_tests("span" "-k;1024")
|
||||
create_compress_tests("zipcd" "-z")
|
||||
if(USE_PKCRYPT)
|
||||
create_compress_tests("pkcrypt" "-p;test123")
|
||||
endif()
|
||||
if(USE_WZAES)
|
||||
create_compress_tests("wzaes" "-s;-p;test123")
|
||||
endif()
|
||||
if(USE_OPENSSL AND OPENSSL_FOUND)
|
||||
create_compress_tests("signed" "-h;ia.p12;-w;test")
|
||||
create_compress_tests("secure" "-z;-h;ia.p12;-w;test")
|
||||
endif()
|
||||
# Perform tests on others
|
||||
if(NOT COMPRESS_ONLY)
|
||||
if(USE_ZLIB)
|
||||
add_test(NAME unzip-tiny
|
||||
COMMAND minizip -x -o ${EXTRA_ARGS} -d out
|
||||
fuzz/unzip_fuzzer_seed_corpus/tiny.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
||||
if(USE_BZIP2)
|
||||
add_test(NAME unzip-bzip2
|
||||
COMMAND minizip -x -o ${EXTRA_ARGS} -d out
|
||||
fuzz/unzip_fuzzer_seed_corpus/bzip2.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
||||
if(USE_LZMA)
|
||||
add_test(NAME unzip-lzma
|
||||
COMMAND minizip -x -o ${EXTRA_ARGS} -d out
|
||||
fuzz/unzip_fuzzer_seed_corpus/lzma.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
||||
if(USE_PKCRYPT)
|
||||
add_test(NAME unzip-pkcrypt
|
||||
COMMAND minizip -x -o ${EXTRA_ARGS} -d out -p test123
|
||||
fuzz/unzip_fuzzer_seed_corpus/encrypted_pkcrypt.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
||||
if(USE_WZAES)
|
||||
add_test(NAME unzip-wzaes
|
||||
COMMAND minizip -x -o ${EXTRA_ARGS} -d out -p test123
|
||||
fuzz/unzip_fuzzer_seed_corpus/encrypted_wzaes.zip
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
#Build fuzzer executables
|
||||
if(BUILD_FUZZ_TEST)
|
||||
if (NOT CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
set(FUZZER_SRC "test/fuzz/standalone.c")
|
||||
endif()
|
||||
|
||||
add_executable(zip_fuzzer "test/fuzz/zip_fuzzer.c" ${FUZZER_SRC})
|
||||
add_executable(unzip_fuzzer "test/fuzz/unzip_fuzzer.c" ${FUZZER_SRC})
|
||||
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
enable_language(CXX)
|
||||
target_link_libraries(zip_fuzzer "FuzzingEngine")
|
||||
set_target_properties(zip_fuzzer PROPERTIES LINKER_LANGUAGE CXX)
|
||||
target_link_libraries(unzip_fuzzer "FuzzingEngine")
|
||||
set_target_properties(unzip_fuzzer PROPERTIES LINKER_LANGUAGE CXX)
|
||||
endif()
|
||||
|
||||
target_link_libraries(zip_fuzzer ${PROJECT_NAME})
|
||||
target_link_libraries(unzip_fuzzer ${PROJECT_NAME})
|
||||
|
||||
if(NOT SKIP_INSTALL_BINARIES AND NOT SKIP_INSTALL_ALL)
|
||||
install(TARGETS zip_fuzzer RUNTIME DESTINATION "bin")
|
||||
install(TARGETS unzip_fuzzer RUNTIME DESTINATION "bin")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'Minizip'
|
||||
s.version = '2.7.2'
|
||||
s.version = '2.8.2'
|
||||
s.license = 'zlib'
|
||||
s.summary = 'Minizip contrib in zlib with the latest bug fixes and advanced features'
|
||||
s.description = <<-DESC
|
||||
|
||||
@@ -1,32 +1,33 @@
|
||||
# minizip 2.7.2
|
||||
# minizip 2.8.2
|
||||
|
||||
minizip is a zip manipulation library written in C that is supported on Windows, macOS, and Linux.
|
||||
|
||||
[](https://github.com/nmoinvaz/minizip/blob/master/LICENSE)
|
||||
[](https://lgtm.com/projects/g/nmoinvaz/minizip/context:cpp)
|
||||
|
||||
Maintained by Nathan Moinvaziri.
|
||||
|
||||
## Branches
|
||||
|
||||
| Name | State | Version | Description | Travis CI |
|
||||
|:- |:-:|:-:|:-|:-:|
|
||||
|[master](https://github.com/nmoinvaz/minizip/tree/master)|Active|2.x|Modern refactoring of 1.2 branch that includes more advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. Compatibility layer provided for older versions.|[](https://travis-ci.org/nmoinvaz/minizip/branches)|
|
||||
|[dev](https://github.com/nmoinvaz/minizip/tree/dev)|Active|2.x|Latest development code|[](https://travis-ci.org/nmoinvaz/minizip/branches)|
|
||||
|[1.2](https://github.com/nmoinvaz/minizip/tree/1.2)|Stale| 1.x|Drop-in replacement for zlib's minizip that includes WinZip AES encryption, disk splitting, I/O buffering and some additional fixes.||
|
||||
|[1.1](https://github.com/nmoinvaz/minizip/tree/1.1)|Stale| 1.x|Original minizip as of zlib 1.2.11.||
|
||||
| Name | State | Version | Description |
|
||||
|:- |:-:|:-:|:-|
|
||||
|[master](https://github.com/nmoinvaz/minizip/tree/master)|Active [](https://travis-ci.org/nmoinvaz/minizip/branches)|2.x|Modern rewrite of 1.2 branch that includes more advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. Compatibility layer provided for older versions.|
|
||||
|[dev](https://github.com/nmoinvaz/minizip/tree/dev)|Active [](https://travis-ci.org/nmoinvaz/minizip/branches)|2.x|Latest development code|
|
||||
|[1.2](https://github.com/nmoinvaz/minizip/tree/1.2)|Stale| 1.x|Drop-in replacement for zlib's minizip that includes WinZip AES encryption, disk splitting, I/O buffering and some additional fixes.|
|
||||
|[1.1](https://github.com/nmoinvaz/minizip/tree/1.1)|Stale| 1.x|Original minizip as of zlib 1.2.11.|
|
||||
|
||||
## History
|
||||
|
||||
Minizip was originally developed by [Gilles Vollant](https://www.winimage.com/zLibDll/minizip.html) and
|
||||
had been contributed to by many people. As part of the zlib distribution, Mark Adler has maintained the
|
||||
original [minizip](https://github.com/madler/zlib/tree/master/contrib/minizip) project.
|
||||
had been contributed to by many people. As part of the zlib distribution, Mark Adler still maintains the
|
||||
original [minizip](https://github.com/madler/zlib/tree/master/contrib/minizip) project which is included in this repository as a reference.
|
||||
|
||||
In 2006, I began working with the minizip project and started submitting bugs I found in the library to
|
||||
Gilles Vollant via e-mail. In 2010, I implemented some additional features like disk splitting,
|
||||
I/O buffering, and WinZip AES encryption. My continued work on the project necessitated setting up a public
|
||||
repository so I could share these and other improvements with the rest of the world. I have been maintaining
|
||||
and actively developing this fork of the library ever since. In 2017, I refactored and rewrote most of
|
||||
the code as version 2 because it had become difficult to maintain and code readability had suffered over the years.
|
||||
My work with the minizip library began in 2006 when I started submitting bugs I found to
|
||||
Gilles Vollant. In 2010, I implemented some additional features like WinZip AES encryption, disk splitting, and
|
||||
I/O buffering that were necessary for another project I was working on. Shortly after, I created this public repository
|
||||
so I could share these and other improvements with the rest of the world. I have been maintaining and actively
|
||||
developing this code base ever since. At the beginning of 2017, I began the work to refactor and rewrite
|
||||
the library as version 2 because it had become difficult to maintain and code readability suffered over the years.
|
||||
|
||||
## Features
|
||||
|
||||
@@ -49,6 +50,7 @@ the code as version 2 because it had become difficult to maintain and code reada
|
||||
+ Zero out local file header information.
|
||||
+ Zip/unzip of central directory to reduce size.
|
||||
+ Ability to generate and verify CMS signature for each entry.
|
||||
+ Recover the central directory if it is corrupt or missing.
|
||||
+ Example minizip command line tool.
|
||||
|
||||
## Build
|
||||
@@ -72,37 +74,38 @@ cmake --build .
|
||||
| USE_BZIP2 | Enables BZIP2 compression | ON |
|
||||
| USE_LZMA | Enables LZMA compression | ON |
|
||||
| USE_PKCRYPT | Enables PKWARE traditional encryption | ON |
|
||||
| USE_AES | Enables WinZIP AES encryption | ON |
|
||||
| USE_WZAES | Enables WinZIP AES encryption | ON |
|
||||
| USE_LIBCOMP | Enables Apple compression | OFF |
|
||||
| USE_OPENSSL | Enables OpenSSL encryption | OFF |
|
||||
| USE_BRG | Enables Brian Gladman's library | OFF |
|
||||
| COMPRESS_ONLY | Only support compression | OFF |
|
||||
| DECOMPRESS_ONLY | Only support decompression | OFF |
|
||||
| BUILD_TEST | Builds minizip test executable | OFF |
|
||||
| BUILD_UNIT_TEST | Builds minizip unit test project | OFF |
|
||||
| BUILD_FUZZ_TEST | Builds minizip fuzz executables | OFF |
|
||||
|
||||
## Contents
|
||||
|
||||
| File(s) | Description | Required |
|
||||
|:- |:-|:-:|
|
||||
| minizip.c | Sample application | No |
|
||||
| mz_compat.\* | Minizip 1.0 compatibility layer | No |
|
||||
| mz.h | Error codes and flags | Yes |
|
||||
| mz_os\* | Platform specific file/utility functions | Likely |
|
||||
| mz_crypt\* | Configuration specific crypto/hashing functions | Encryption, Signing |
|
||||
| mz_strm.\* | Stream interface | Yes |
|
||||
| mz_strm_buf.\* | Buffered stream | No |
|
||||
| mz_strm_bzip.\* | BZIP2 stream using libbzip2 | No |
|
||||
| mz_strm_crc32.\* | CRC32 stream | Yes |
|
||||
| mz_strm_libcomp.\* | Apple compression 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_os\* | Platform specific file stream | Yes |
|
||||
| mz_strm_wzaes.\* | WinZIP AES stream | No |
|
||||
| mz_strm_zlib.\* | Deflate stream using zlib | zlib or liblzma |
|
||||
| mz_zip.\* | Zip format | Yes |
|
||||
| mz_zip_rw.\* | Zip reader/writer | No |
|
||||
| File(s) | Description |
|
||||
|:- |:-|
|
||||
| minizip.c | Sample application |
|
||||
| mz_compat.\* | Minizip 1.x compatibility layer |
|
||||
| mz.h | Error codes and flags |
|
||||
| mz_os\* | Platform specific file/utility functions |
|
||||
| mz_crypt\* | Configuration specific crypto/hashing functions |
|
||||
| mz_strm.\* | Stream interface |
|
||||
| mz_strm_buf.\* | Buffered stream |
|
||||
| mz_strm_bzip.\* | BZIP2 stream using libbzip2 |
|
||||
| mz_strm_libcomp.\* | Apple compression stream |
|
||||
| mz_strm_lzma.\* | LZMA stream using liblzma |
|
||||
| mz_strm_mem.\* | Memory stream |
|
||||
| mz_strm_split.\* | Disk splitting stream |
|
||||
| mz_strm_pkcrypt.\* | PKWARE traditional encryption stream |
|
||||
| mz_strm_os\* | Platform specific file stream |
|
||||
| mz_strm_wzaes.\* | WinZIP AES stream |
|
||||
| mz_strm_zlib.\* | Deflate stream using zlib |
|
||||
| mz_zip.\* | Zip format |
|
||||
| mz_zip_rw.\* | Zip reader/writer |
|
||||
|
||||
## Third-Party Libraries
|
||||
|
||||
|
||||
+12
-6
@@ -393,8 +393,10 @@ AES_RETURN aes_xi(decrypt_key192)(const unsigned char *key, aes_decrypt_ctx cx[1
|
||||
cx->ks[v(48,(3))] = ss[3] = word_in(key, 3);
|
||||
|
||||
#ifdef DEC_KS_UNROLL
|
||||
cx->ks[v(48,(4))] = ff(ss[4] = word_in(key, 4));
|
||||
cx->ks[v(48,(5))] = ff(ss[5] = word_in(key, 5));
|
||||
ss[4] = word_in(key, 4);
|
||||
cx->ks[v(48,(4))] = ff(ss[4]);
|
||||
ss[5] = word_in(key, 5);
|
||||
cx->ks[v(48,(5))] = ff(ss[5]);
|
||||
kdf6(cx->ks, 0); kd6(cx->ks, 1);
|
||||
kd6(cx->ks, 2); kd6(cx->ks, 3);
|
||||
kd6(cx->ks, 4); kd6(cx->ks, 5);
|
||||
@@ -485,10 +487,14 @@ AES_RETURN aes_xi(decrypt_key256)(const unsigned char *key, aes_decrypt_ctx cx[1
|
||||
cx->ks[v(56,(3))] = ss[3] = word_in(key, 3);
|
||||
|
||||
#ifdef DEC_KS_UNROLL
|
||||
cx->ks[v(56,(4))] = ff(ss[4] = word_in(key, 4));
|
||||
cx->ks[v(56,(5))] = ff(ss[5] = word_in(key, 5));
|
||||
cx->ks[v(56,(6))] = ff(ss[6] = word_in(key, 6));
|
||||
cx->ks[v(56,(7))] = ff(ss[7] = word_in(key, 7));
|
||||
ss[4] = word_in(key, 4);
|
||||
cx->ks[v(56,(4))] = ff(ss[4]);
|
||||
ss[5] = word_in(key, 5);
|
||||
cx->ks[v(56,(5))] = ff(ss[5]);
|
||||
ss[6] = word_in(key, 6);
|
||||
cx->ks[v(56,(6))] = ff(ss[6]);
|
||||
ss[7] = word_in(key, 7);
|
||||
cx->ks[v(56,(7))] = ff(ss[7]);
|
||||
kdf8(cx->ks, 0); kd8(cx->ks, 1);
|
||||
kd8(cx->ks, 2); kd8(cx->ks, 3);
|
||||
kd8(cx->ks, 4); kd8(cx->ks, 5);
|
||||
|
||||
@@ -102,6 +102,7 @@ static
|
||||
void* default_bzalloc ( void* opaque, Int32 items, Int32 size )
|
||||
{
|
||||
void* v = malloc ( items * size );
|
||||
(void)opaque;
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -109,6 +110,7 @@ static
|
||||
void default_bzfree ( void* opaque, void* addr )
|
||||
{
|
||||
if (addr != NULL) free ( addr );
|
||||
(void)opaque;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ void sendMTFValues ( EState* s )
|
||||
{
|
||||
Int32 v, t, i, j, gs, ge, totc, bt, bc, iter;
|
||||
Int32 nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||
Int32 nGroups, nBytes;
|
||||
Int32 nGroups;
|
||||
|
||||
/*--
|
||||
UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
@@ -500,7 +500,6 @@ void sendMTFValues ( EState* s )
|
||||
if (s->inUse[i * 16 + j]) inUse16[i] = True;
|
||||
}
|
||||
|
||||
nBytes = s->numZ;
|
||||
for (i = 0; i < 16; i++)
|
||||
if (inUse16[i]) bsW(s,1,1); else bsW(s,1,0);
|
||||
|
||||
@@ -515,7 +514,6 @@ void sendMTFValues ( EState* s )
|
||||
}
|
||||
|
||||
/*--- Now the selectors. ---*/
|
||||
nBytes = s->numZ;
|
||||
bsW ( s, 3, nGroups );
|
||||
bsW ( s, 15, nSelectors );
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
@@ -526,8 +524,6 @@ void sendMTFValues ( EState* s )
|
||||
VPrintf1( "selectors %d, ", s->numZ-nBytes );
|
||||
|
||||
/*--- Now the coding tables. ---*/
|
||||
nBytes = s->numZ;
|
||||
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
Int32 curr = s->len[t][0];
|
||||
bsW ( s, 5, curr );
|
||||
@@ -542,7 +538,6 @@ void sendMTFValues ( EState* s )
|
||||
VPrintf1 ( "code lengths %d, ", s->numZ-nBytes );
|
||||
|
||||
/*--- And finally, the block data proper ---*/
|
||||
nBytes = s->numZ;
|
||||
selCtr = 0;
|
||||
gs = 0;
|
||||
while (True) {
|
||||
|
||||
@@ -287,7 +287,7 @@ Int32 BZ2_decompress ( DState* s )
|
||||
GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
|
||||
if (nGroups < 2 || nGroups > 6) RETURN(BZ_DATA_ERROR);
|
||||
GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
|
||||
if (nSelectors < 1) RETURN(BZ_DATA_ERROR);
|
||||
if (nSelectors < 1 || nSelectors > BZ_MAX_SELECTORS) RETURN(BZ_DATA_ERROR);
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
j = 0;
|
||||
while (True) {
|
||||
|
||||
@@ -163,7 +163,8 @@ static const lzma_filter_encoder encoders[] = {
|
||||
static const lzma_filter_encoder *
|
||||
encoder_find(lzma_vli id)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(encoders); ++i)
|
||||
size_t i = 0;
|
||||
for (i = 0; i < ARRAY_SIZE(encoders); ++i)
|
||||
if (encoders[i].id == id)
|
||||
return encoders + i;
|
||||
|
||||
@@ -182,8 +183,9 @@ extern uint64_t
|
||||
lzma_mt_block_size(const lzma_filter *filters)
|
||||
{
|
||||
uint64_t max = 0;
|
||||
size_t i = 0;
|
||||
|
||||
for (size_t i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
|
||||
for (i = 0; filters[i].id != LZMA_VLI_UNKNOWN; ++i) {
|
||||
const lzma_filter_encoder *const fe
|
||||
= encoder_find(filters[i].id);
|
||||
if (fe->block_size != NULL) {
|
||||
|
||||
+23
-23
@@ -5,7 +5,7 @@
|
||||
/* #undef AC_APPLE_UNIVERSAL_BUILD */
|
||||
|
||||
/* How many MiB of RAM to assume if the real amount cannot be determined. */
|
||||
#define ASSUME_RAM 128
|
||||
/* #undef ASSUME_RAM 128 */
|
||||
|
||||
/* Define to 1 if translation of program messages to the user's native
|
||||
language is requested. */
|
||||
@@ -47,7 +47,7 @@
|
||||
/* #undef HAVE_CHECK_SHA256 */
|
||||
|
||||
/* Define to 1 if you have the `clock_gettime' function. */
|
||||
#define HAVE_CLOCK_GETTIME 1
|
||||
/* #undef HAVE_CLOCK_GETTIME */
|
||||
|
||||
/* Define to 1 if you have the <CommonCrypto/CommonDigest.h> header file. */
|
||||
/* #undef HAVE_COMMONCRYPTO_COMMONDIGEST_H */
|
||||
@@ -58,11 +58,11 @@
|
||||
|
||||
/* Define to 1 if you have the declaration of `CLOCK_MONOTONIC', and to 0 if
|
||||
you don't. */
|
||||
#define HAVE_DECL_CLOCK_MONOTONIC 1
|
||||
/* #undef HAVE_DECL_CLOCK_MONOTONIC */
|
||||
|
||||
/* Define to 1 if you have the declaration of `program_invocation_name', and
|
||||
to 0 if you don't. */
|
||||
#define HAVE_DECL_PROGRAM_INVOCATION_NAME 0
|
||||
/* #undef HAVE_DECL_PROGRAM_INVOCATION_NAME */
|
||||
|
||||
/* Define to 1 if arm decoder is enabled. */
|
||||
/* #undef HAVE_DECODER_ARM */
|
||||
@@ -122,7 +122,7 @@
|
||||
/* #undef HAVE_ENCODER_X86 */
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
/* #undef HAVE_FCNTL_H 1 */
|
||||
|
||||
/* Define to 1 if you have the `futimens' function. */
|
||||
/* #undef HAVE_FUTIMENS */
|
||||
@@ -134,10 +134,10 @@
|
||||
/* #undef HAVE_FUTIMESAT */
|
||||
|
||||
/* Define to 1 if you have the <getopt.h> header file. */
|
||||
#define HAVE_GETOPT_H 1
|
||||
/* #undef HAVE_GETOPT_H */
|
||||
|
||||
/* Define to 1 if you have the `getopt_long' function. */
|
||||
#define HAVE_GETOPT_LONG 1
|
||||
/* #undef HAVE_GETOPT_LONG */
|
||||
|
||||
/* Define if the GNU gettext() function is already present or preinstalled. */
|
||||
/* #undef HAVE_GETTEXT */
|
||||
@@ -146,19 +146,19 @@
|
||||
/* #undef HAVE_ICONV */
|
||||
|
||||
/* Define to 1 if you have the <immintrin.h> header file. */
|
||||
#define HAVE_IMMINTRIN_H 1
|
||||
/* #undef HAVE_IMMINTRIN_H */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
/* #undef HAVE_INTTYPES_H */
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
/* #undef HAVE_LIMITS_H */
|
||||
|
||||
/* Define to 1 if mbrtowc and mbstate_t are properly declared. */
|
||||
#define HAVE_MBRTOWC 1
|
||||
/* #undef HAVE_MBRTOWC 1 */
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
/* #undef HAVE_MEMORY_H */
|
||||
|
||||
/* Define to 1 to enable bt2 match finder. */
|
||||
#define HAVE_MF_BT2 1
|
||||
@@ -215,10 +215,10 @@
|
||||
/* #undef HAVE_SMALL */
|
||||
|
||||
/* Define to 1 if stdbool.h conforms to C99. */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
/* #undef HAVE_STDBOOL_H */
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
/* #undef HAVE_STDINT_H */
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
@@ -227,7 +227,7 @@
|
||||
/* #undef HAVE_STRINGS_H */
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
/* #undef HAVE_STRING_H */
|
||||
|
||||
/* Define to 1 if `st_atimensec' is a member of `struct stat'. */
|
||||
/* #undef HAVE_STRUCT_STAT_ST_ATIMENSEC */
|
||||
@@ -251,25 +251,25 @@
|
||||
/* #undef HAVE_SYS_ENDIAN_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
/* #undef HAVE_SYS_PARAM_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
/* #undef HAVE_SYS_STAT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
/* #undef HAVE_SYS_TIME_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
/* #undef HAVE_SYS_TYPES_H */
|
||||
|
||||
/* Define to 1 if the system has the type `uintptr_t'. */
|
||||
#define HAVE_UINTPTR_T 1
|
||||
/* #undef HAVE_UINTPTR_T */
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
/* #undef HAVE_UNISTD_H */
|
||||
|
||||
/* Define to 1 if you have the `utime' function. */
|
||||
#define HAVE_UTIME 1
|
||||
/* #undef HAVE_UTIME */
|
||||
|
||||
/* Define to 1 if you have the `utimes' function. */
|
||||
/* #undef HAVE_UTIMES */
|
||||
@@ -434,7 +434,7 @@
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
/* #undef _FILE_OFFSET_BITS 64 */
|
||||
|
||||
/* Define for large files, on AIX-style hosts. */
|
||||
/* #undef _LARGE_FILES */
|
||||
|
||||
@@ -33,8 +33,9 @@ lzma_mf_find(lzma_mf *mf, uint32_t *count_ptr, lzma_match *matches)
|
||||
|
||||
if (count > 0) {
|
||||
#ifndef NDEBUG
|
||||
uint32_t i = 0;
|
||||
// Validate the matches.
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
for (i = 0; i < count; ++i) {
|
||||
assert(matches[i].len <= mf->nice_len);
|
||||
assert(matches[i].dist < mf->read_pos);
|
||||
assert(memcmp(mf_ptr(mf) - 1,
|
||||
@@ -108,14 +109,14 @@ static void
|
||||
normalize(lzma_mf *mf)
|
||||
{
|
||||
assert(mf->read_pos + mf->offset == MUST_NORMALIZE_POS);
|
||||
|
||||
uint32_t i = 0;
|
||||
// In future we may not want to touch the lowest bits, because there
|
||||
// may be match finders that use larger resolution than one byte.
|
||||
const uint32_t subvalue
|
||||
= (MUST_NORMALIZE_POS - mf->cyclic_size);
|
||||
// & (~(UINT32_C(1) << 10) - 1);
|
||||
|
||||
for (uint32_t i = 0; i < mf->hash_count; ++i) {
|
||||
for (i = 0; i < mf->hash_count; ++i) {
|
||||
// If the distance is greater than the dictionary size,
|
||||
// we can simply mark the hash element as empty.
|
||||
if (mf->hash[i] <= subvalue)
|
||||
@@ -124,7 +125,7 @@ normalize(lzma_mf *mf)
|
||||
mf->hash[i] -= subvalue;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < mf->sons_count; ++i) {
|
||||
for (i = 0; i < mf->sons_count; ++i) {
|
||||
// Do the same for mf->son.
|
||||
//
|
||||
// NOTE: There may be uninitialized elements in mf->son.
|
||||
|
||||
@@ -14,10 +14,7 @@
|
||||
#ifndef LZMA_RANGE_COMMON_H
|
||||
#define LZMA_RANGE_COMMON_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "common.h"
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
|
||||
///////////////
|
||||
// Constants //
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* minizip.c
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
https://www.winimage.com/zLibDll/minizip.html
|
||||
@@ -11,11 +11,6 @@
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
@@ -25,25 +20,23 @@
|
||||
#include "mz_zip.h"
|
||||
#include "mz_zip_rw.h"
|
||||
|
||||
#include <stdio.h> /* printf */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct minizip_opt_s {
|
||||
uint8_t include_path;
|
||||
int16_t compress_level;
|
||||
uint8_t compress_method;
|
||||
uint8_t overwrite;
|
||||
uint8_t append;
|
||||
int64_t disk_size;
|
||||
uint8_t zip_cd;
|
||||
int32_t encoding;
|
||||
uint8_t verbose;
|
||||
#ifdef HAVE_AES
|
||||
uint8_t aes;
|
||||
#endif
|
||||
#ifndef MZ_NO_ZIP_SIGNING
|
||||
uint8_t include_path;
|
||||
int16_t compress_level;
|
||||
uint8_t compress_method;
|
||||
uint8_t overwrite;
|
||||
uint8_t append;
|
||||
int64_t disk_size;
|
||||
uint8_t zip_cd;
|
||||
int32_t encoding;
|
||||
uint8_t verbose;
|
||||
uint8_t aes;
|
||||
const char *cert_path;
|
||||
const char *cert_pwd;
|
||||
#endif
|
||||
} minizip_opt;
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -90,19 +83,12 @@ int32_t minizip_help(void)
|
||||
" -9 Compress better\n" \
|
||||
" -k Disk size in KB\n" \
|
||||
" -z Zip central directory\n" \
|
||||
" -p Encryption password\n");
|
||||
#ifdef HAVE_AES
|
||||
printf(" -s AES encryption\n" \
|
||||
" -h Certificate path\n" \
|
||||
" -w Certificate password\n");
|
||||
#endif
|
||||
#ifdef HAVE_BZIP2
|
||||
printf(" -b BZIP2 compression\n");
|
||||
#endif
|
||||
#ifdef HAVE_LZMA
|
||||
printf(" -m LZMA compression\n");
|
||||
#endif
|
||||
printf("\n");
|
||||
" -p Encryption password\n" \
|
||||
" -s AES encryption\n" \
|
||||
" -h Pkcs12 certificate path\n" \
|
||||
" -w Pkcs12 certificate password\n" \
|
||||
" -b BZIP2 compression\n" \
|
||||
" -m LZMA compression\n\n");
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@@ -124,7 +110,7 @@ int32_t minizip_list(const char *path)
|
||||
err = mz_zip_reader_open_file(reader, path);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d opening zip file %s\n", err, path);
|
||||
printf("Error %"PRId32" opening zip file %s\n", err, path);
|
||||
mz_zip_reader_delete(&reader);
|
||||
return err;
|
||||
}
|
||||
@@ -133,21 +119,22 @@ int32_t minizip_list(const char *path)
|
||||
|
||||
if (err != MZ_OK && err != MZ_END_OF_LIST)
|
||||
{
|
||||
printf("Error %d going to first entry in zip file\n", err);
|
||||
printf("Error %"PRId32" going to first entry in zip file\n", err);
|
||||
mz_zip_reader_delete(&reader);
|
||||
return err;
|
||||
}
|
||||
|
||||
printf(" Length Method Size Attribs Ratio Date Time CRC-32 Name\n");
|
||||
printf(" ------ ------ ---- ------- ----- ---- ---- ------ ----\n");
|
||||
printf(" Packed Unpacked Ratio Method Attribs Date Time CRC-32 Name\n");
|
||||
printf(" ------ -------- ----- ------ ------- ---- ---- ------ ----\n");
|
||||
|
||||
/* Enumerate all entries in the zip */
|
||||
do
|
||||
{
|
||||
err = mz_zip_reader_entry_get_info(reader, &file_info);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d getting entry info in zip file\n", err);
|
||||
printf("Error %"PRId32" getting entry info in zip file\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -155,7 +142,7 @@ int32_t minizip_list(const char *path)
|
||||
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
|
||||
/* Display a '*' if the file is encrypted */
|
||||
if (file_info->flag & MZ_ZIP_FLAG_ENCRYPTED)
|
||||
crypt = '*';
|
||||
|
||||
@@ -171,7 +158,7 @@ int32_t minizip_list(const char *path)
|
||||
else if (level == 1)
|
||||
string_method = "Defl:X";
|
||||
else if ((level == 2) || (level == 3))
|
||||
string_method = "Defl:F"; // 2: fast , 3: extra fast
|
||||
string_method = "Defl:F"; /* 2: fast , 3: extra fast */
|
||||
else
|
||||
string_method = "Defl:?";
|
||||
break;
|
||||
@@ -187,10 +174,11 @@ int32_t minizip_list(const char *path)
|
||||
|
||||
mz_zip_time_t_to_tm(file_info->modified_date, &tmu_date);
|
||||
|
||||
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, file_info->external_fa, ratio,
|
||||
/* Print entry information */
|
||||
printf("%12"PRId64" %12"PRId64" %3"PRIu32"%% %6s%c %8"PRIx32" %2.2"PRIu32\
|
||||
"-%2.2"PRIu32"-%2.2"PRIu32" %2.2"PRIu32":%2.2"PRIu32" %8.8"PRIx32" %s\n",
|
||||
file_info->compressed_size, file_info->uncompressed_size, ratio,
|
||||
string_method, crypt, file_info->external_fa,
|
||||
(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,
|
||||
@@ -200,7 +188,7 @@ int32_t minizip_list(const char *path)
|
||||
|
||||
if (err != MZ_OK && err != MZ_END_OF_LIST)
|
||||
{
|
||||
printf("Error %d going to next entry in zip file\n", err);
|
||||
printf("Error %"PRId32" going to next entry in zip file\n", err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -221,6 +209,7 @@ int32_t minizip_add_entry_cb(void *handle, void *userdata, mz_zip_file *file_inf
|
||||
MZ_UNUSED(handle);
|
||||
MZ_UNUSED(userdata);
|
||||
|
||||
/* Print the current file we are trying to compress */
|
||||
printf("Adding %s\n", file_info->filename);
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -240,8 +229,9 @@ int32_t minizip_add_progress_cb(void *handle, void *userdata, mz_zip_file *file_
|
||||
else if (!raw && file_info->uncompressed_size > 0)
|
||||
progress = ((double)position / file_info->uncompressed_size) * 100;
|
||||
|
||||
/* Print the progress of the current compress operation */
|
||||
if (options->verbose)
|
||||
printf("%s - %"PRIu64" / %"PRIu64" (%.02f%%)\n", file_info->filename, position,
|
||||
printf("%s - %"PRId64" / %"PRId64" (%.02f%%)\n", file_info->filename, position,
|
||||
file_info->uncompressed_size, progress);
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -254,7 +244,7 @@ int32_t minizip_add_overwrite_cb(void *handle, void *userdata, const char *path)
|
||||
|
||||
if (options->overwrite == 0)
|
||||
{
|
||||
// If ask the user what to do because append and overwrite args not set
|
||||
/* If ask the user what to do because append and overwrite args not set */
|
||||
char rep = 0;
|
||||
do
|
||||
{
|
||||
@@ -293,11 +283,13 @@ int32_t minizip_add(const char *path, const char *password, minizip_opt *options
|
||||
|
||||
printf("Archive %s\n", path);
|
||||
|
||||
/* Create zip writer */
|
||||
mz_zip_writer_create(&writer);
|
||||
mz_zip_writer_set_password(writer, password);
|
||||
mz_zip_writer_set_compress_method(writer, options->compress_method);
|
||||
mz_zip_writer_set_compress_level(writer, options->compress_level);
|
||||
mz_zip_writer_set_overwrite_cb(writer, options, minizip_add_overwrite_cb);
|
||||
mz_zip_writer_set_comment(writer, "xyz");
|
||||
mz_zip_writer_set_progress_cb(writer, options, minizip_add_progress_cb);
|
||||
mz_zip_writer_set_entry_cb(writer, options, minizip_add_entry_cb);
|
||||
mz_zip_writer_set_zip_cd(writer, options->zip_cd);
|
||||
@@ -312,20 +304,21 @@ int32_t minizip_add(const char *path, const char *password, minizip_opt *options
|
||||
{
|
||||
filename_in_zip = args[i];
|
||||
|
||||
/* Add file system path to zip */
|
||||
err = mz_zip_writer_add_path(writer, filename_in_zip, NULL, options->include_path, 1);
|
||||
if (err != MZ_OK)
|
||||
printf("Error %d adding path to zip %s\n", err, filename_in_zip);
|
||||
printf("Error %"PRId32" adding path to zip %s\n", err, filename_in_zip);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error %d opening zip for writing\n", err);
|
||||
printf("Error %"PRId32" opening zip for writing\n", err);
|
||||
}
|
||||
|
||||
err_close = mz_zip_writer_close(writer);
|
||||
if (err_close != MZ_OK)
|
||||
{
|
||||
printf("Error %d closing zip for writing %s\n", err_close, path);
|
||||
printf("Error %"PRId32" closing zip for writing %s\n", err_close, path);
|
||||
err = err_close;
|
||||
}
|
||||
|
||||
@@ -341,6 +334,7 @@ int32_t minizip_extract_entry_cb(void *handle, void *userdata, mz_zip_file *file
|
||||
MZ_UNUSED(userdata);
|
||||
MZ_UNUSED(path);
|
||||
|
||||
/* Print the current entry extracting */
|
||||
printf("Extracting %s\n", file_info->filename);
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -360,8 +354,9 @@ int32_t minizip_extract_progress_cb(void *handle, void *userdata, mz_zip_file *f
|
||||
else if (!raw && file_info->uncompressed_size > 0)
|
||||
progress = ((double)position / file_info->uncompressed_size) * 100;
|
||||
|
||||
/* Print the progress of the current extraction */
|
||||
if (options->verbose)
|
||||
printf("%s - %"PRIu64" / %"PRIu64" (%.02f%%)\n", file_info->filename, position,
|
||||
printf("%s - %"PRId64" / %"PRId64" (%.02f%%)\n", file_info->filename, position,
|
||||
file_info->uncompressed_size, progress);
|
||||
|
||||
return MZ_OK;
|
||||
@@ -374,6 +369,7 @@ int32_t minizip_extract_overwrite_cb(void *handle, void *userdata, mz_zip_file *
|
||||
MZ_UNUSED(handle);
|
||||
MZ_UNUSED(file_info);
|
||||
|
||||
/* Verify if we want to overwrite current entry on disk */
|
||||
if (options->overwrite == 0)
|
||||
{
|
||||
char rep = 0;
|
||||
@@ -406,6 +402,7 @@ int32_t minizip_extract(const char *path, const char *pattern, const char *desti
|
||||
|
||||
printf("Archive %s\n", path);
|
||||
|
||||
/* Create zip reader */
|
||||
mz_zip_reader_create(&reader);
|
||||
mz_zip_reader_set_pattern(reader, pattern, 1);
|
||||
mz_zip_reader_set_password(reader, password);
|
||||
@@ -418,21 +415,23 @@ int32_t minizip_extract(const char *path, const char *pattern, const char *desti
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d opening zip file %s\n", err, path);
|
||||
printf("Error %"PRId32" opening zip file %s\n", err, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Save all entries in zip file to destination directory */
|
||||
err = mz_zip_reader_save_all(reader, destination);
|
||||
|
||||
if (err == MZ_END_OF_LIST && pattern != NULL)
|
||||
printf("Files matching %s not found in zip file\n", pattern);
|
||||
if (err != MZ_OK)
|
||||
printf("Error %d saving zip entries to disk %s\n", err, path);
|
||||
printf("Error %"PRId32" saving zip entries to disk %s\n", err, path);
|
||||
}
|
||||
|
||||
err_close = mz_zip_reader_close(reader);
|
||||
if (err_close != MZ_OK)
|
||||
{
|
||||
printf("Error %d closing zip for reading\n", err_close);
|
||||
printf("Error %"PRId32" closing zip for reading\n", err_close);
|
||||
err = err_close;
|
||||
}
|
||||
|
||||
@@ -446,26 +445,42 @@ int32_t minizip_erase(const char *src_path, const char *target_path, int32_t arg
|
||||
{
|
||||
mz_zip_file *file_info = NULL;
|
||||
const char *filename_in_zip = NULL;
|
||||
const char *target_path_ptr = target_path;
|
||||
void *reader = NULL;
|
||||
void *writer = NULL;
|
||||
int32_t skip = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t i = 0;
|
||||
uint8_t zip_cd = 0;
|
||||
char bak_path[256];
|
||||
char tmp_path[256];
|
||||
|
||||
if (target_path == NULL)
|
||||
{
|
||||
/* Construct temporary zip name */
|
||||
strncpy(tmp_path, src_path, sizeof(tmp_path) - 1);
|
||||
tmp_path[sizeof(tmp_path) - 1] = 0;
|
||||
strncat(tmp_path, ".tmp.zip", sizeof(tmp_path) - strlen(tmp_path) - 1);
|
||||
target_path_ptr = tmp_path;
|
||||
}
|
||||
|
||||
mz_zip_reader_create(&reader);
|
||||
mz_zip_writer_create(&writer);
|
||||
|
||||
/* Open original zip file we want to erase an entry in */
|
||||
err = mz_zip_reader_open_file(reader, src_path);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d opening zip for reading %s\n", err, src_path);
|
||||
printf("Error %"PRId32" opening zip for reading %s\n", err, src_path);
|
||||
mz_zip_reader_delete(&reader);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mz_zip_writer_open_file(writer, target_path, 0, 0);
|
||||
/* Open temporary zip file */
|
||||
err = mz_zip_writer_open_file(writer, target_path_ptr, 0, 0);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d opening zip for writing %s\n", err, target_path);
|
||||
printf("Error %"PRId32" opening zip for writing %s\n", err, target_path_ptr);
|
||||
mz_zip_reader_delete(&reader);
|
||||
mz_zip_writer_delete(&writer);
|
||||
return err;
|
||||
@@ -474,44 +489,52 @@ int32_t minizip_erase(const char *src_path, const char *target_path, int32_t arg
|
||||
err = mz_zip_reader_goto_first_entry(reader);
|
||||
|
||||
if (err != MZ_OK && err != MZ_END_OF_LIST)
|
||||
printf("Error %d going to first entry in zip file\n", err);
|
||||
printf("Error %"PRId32" going to first entry in zip file\n", err);
|
||||
|
||||
while (err == MZ_OK)
|
||||
{
|
||||
err = mz_zip_reader_entry_get_info(reader, &file_info);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d getting info from zip\n", err);
|
||||
printf("Error %"PRId32" getting info from zip\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < arg_count; i += 1)
|
||||
/* Copy all entries from original zip file to temporary zip file
|
||||
except the ones we don't want */
|
||||
for (i = 0, skip = 0; i < arg_count; i += 1)
|
||||
{
|
||||
filename_in_zip = args[i];
|
||||
|
||||
if (mz_path_compare_wc(file_info->filename, filename_in_zip, 1) != MZ_OK)
|
||||
{
|
||||
printf("Copying %s\n", file_info->filename);
|
||||
err = mz_zip_writer_copy_from_reader(writer, reader);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Skipping %s\n", file_info->filename);
|
||||
}
|
||||
if (mz_path_compare_wc(file_info->filename, filename_in_zip, 1) == MZ_OK)
|
||||
skip = 1;
|
||||
}
|
||||
|
||||
if (skip)
|
||||
{
|
||||
printf("Skipping %s\n", file_info->filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Copying %s\n", file_info->filename);
|
||||
err = mz_zip_writer_copy_from_reader(writer, reader);
|
||||
}
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d copying entry into new zip\n", err);
|
||||
printf("Error %"PRId32" copying entry into new zip\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
err = mz_zip_reader_goto_next_entry(reader);
|
||||
|
||||
if (err != MZ_OK && err != MZ_END_OF_LIST)
|
||||
printf("Error %d going to next entry in zip file\n", err);
|
||||
printf("Error %"PRId32" going to next entry in zip file\n", err);
|
||||
}
|
||||
|
||||
mz_zip_reader_get_zip_cd(reader, &zip_cd);
|
||||
mz_zip_writer_set_zip_cd(writer, zip_cd);
|
||||
|
||||
mz_zip_reader_close(reader);
|
||||
mz_zip_reader_delete(&reader);
|
||||
|
||||
@@ -519,14 +542,33 @@ int32_t minizip_erase(const char *src_path, const char *target_path, int32_t arg
|
||||
mz_zip_writer_delete(&writer);
|
||||
|
||||
if (err == MZ_END_OF_LIST)
|
||||
{
|
||||
if (target_path == NULL)
|
||||
{
|
||||
/* Swap original zip with temporary zip, backup old zip if possible */
|
||||
strncpy(bak_path, src_path, sizeof(bak_path) - 1);
|
||||
bak_path[sizeof(bak_path) - 1] = 0;
|
||||
strncat(bak_path, ".bak", sizeof(bak_path) - strlen(bak_path) - 1);
|
||||
|
||||
if (mz_os_file_exists(bak_path) == MZ_OK)
|
||||
mz_os_delete(bak_path);
|
||||
|
||||
if (mz_os_rename(src_path, bak_path) != MZ_OK)
|
||||
printf("Error backing up zip before replacing %s\n", bak_path);
|
||||
|
||||
if (mz_os_rename(tmp_path, src_path) != MZ_OK)
|
||||
printf("Error replacing zip with temp %s\n", tmp_path);
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(MZ_NO_MAIN)
|
||||
#if !defined(MZ_ZIP_NO_MAIN)
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
minizip_opt options;
|
||||
@@ -536,8 +578,6 @@ int main(int argc, const char *argv[])
|
||||
uint8_t do_list = 0;
|
||||
uint8_t do_extract = 0;
|
||||
uint8_t do_erase = 0;
|
||||
char bak_path[256];
|
||||
char tmp_path[256];
|
||||
const char *path = NULL;
|
||||
const char *password = NULL;
|
||||
const char *destination = NULL;
|
||||
@@ -556,9 +596,10 @@ int main(int argc, const char *argv[])
|
||||
options.compress_method = MZ_COMPRESS_METHOD_DEFLATE;
|
||||
options.compress_level = MZ_COMPRESS_LEVEL_DEFAULT;
|
||||
|
||||
// Parse command line options
|
||||
/* Parse command line options */
|
||||
for (i = 1; i < argc; i += 1)
|
||||
{
|
||||
printf("%s ", argv[i]);
|
||||
if (argv[i][0] == '-')
|
||||
{
|
||||
char c = argv[i][1];
|
||||
@@ -584,31 +625,44 @@ int main(int argc, const char *argv[])
|
||||
if (options.compress_level == 0)
|
||||
options.compress_method = MZ_COMPRESS_METHOD_STORE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
else if ((c == 'b') || (c == 'B'))
|
||||
#ifdef HAVE_BZIP2
|
||||
options.compress_method = MZ_COMPRESS_METHOD_BZIP2;
|
||||
#else
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#endif
|
||||
#ifdef HAVE_LZMA
|
||||
else if ((c == 'm') || (c == 'M'))
|
||||
#ifdef HAVE_LZMA
|
||||
options.compress_method = MZ_COMPRESS_METHOD_LZMA;
|
||||
#else
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#endif
|
||||
#ifdef HAVE_AES
|
||||
else if ((c == 's') || (c == 'S'))
|
||||
#ifdef HAVE_WZAES
|
||||
options.aes = 1;
|
||||
#else
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#endif
|
||||
#ifndef MZ_NO_ZIP_SIGNING
|
||||
else if (((c == 'h') || (c == 'H')) && (i + 1 < argc))
|
||||
{
|
||||
#ifndef MZ_ZIP_NO_SIGNING
|
||||
options.cert_path = argv[i + 1];
|
||||
printf("%s ", argv[i + 1]);
|
||||
#else
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#endif
|
||||
i += 1;
|
||||
}
|
||||
else if (((c == 'w') || (c == 'W')) && (i + 1 < argc))
|
||||
{
|
||||
#ifndef MZ_ZIP_NO_SIGNING
|
||||
options.cert_pwd = argv[i + 1];
|
||||
printf("%s ", argv[i + 1]);
|
||||
#else
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#endif
|
||||
i += 1;
|
||||
}
|
||||
#endif
|
||||
else if (((c == 'c') || (c == 'C')) && (i + 1 < argc))
|
||||
{
|
||||
options.encoding = (int32_t)atoi(argv[i + 1]);
|
||||
@@ -617,22 +671,36 @@ int main(int argc, const char *argv[])
|
||||
else if (((c == 'k') || (c == 'K')) && (i + 1 < argc))
|
||||
{
|
||||
options.disk_size = (int64_t)atoi(argv[i + 1]) * 1024;
|
||||
printf("%s ", argv[i + 1]);
|
||||
i += 1;
|
||||
}
|
||||
else if (((c == 'd') || (c == 'D')) && (i + 1 < argc))
|
||||
{
|
||||
destination = argv[i + 1];
|
||||
printf("%s ", argv[i + 1]);
|
||||
i += 1;
|
||||
}
|
||||
else if (((c == 'p') || (c == 'P')) && (i + 1 < argc))
|
||||
{
|
||||
#ifndef MZ_ZIP_NO_ENCRYPTION
|
||||
password = argv[i + 1];
|
||||
printf("*** ");
|
||||
#else
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#endif
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
else if (path_arg == 0)
|
||||
path_arg = i;
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (err == MZ_SUPPORT_ERROR)
|
||||
{
|
||||
printf("Feature not supported\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
if (path_arg == 0)
|
||||
{
|
||||
@@ -640,10 +708,12 @@ int main(int argc, const char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
path = argv[path_arg];
|
||||
|
||||
if (do_list)
|
||||
{
|
||||
/* List zip file contents */
|
||||
err = minizip_list(path);
|
||||
}
|
||||
else if (do_extract)
|
||||
@@ -651,37 +721,20 @@ int main(int argc, const char *argv[])
|
||||
if (argc > path_arg + 1)
|
||||
filename_to_extract = argv[path_arg + 1];
|
||||
|
||||
/* Extract zip file*/
|
||||
err = minizip_extract(path, filename_to_extract, destination, password, &options);
|
||||
}
|
||||
else if (do_erase)
|
||||
{
|
||||
strncpy(tmp_path, path, sizeof(tmp_path) - 1);
|
||||
tmp_path[sizeof(tmp_path) - 1] = 0;
|
||||
strncat(tmp_path, ".tmp", sizeof(tmp_path) - strlen(tmp_path) - 1);
|
||||
|
||||
err = minizip_erase(path, tmp_path, argc - (path_arg + 1), &argv[path_arg + 1]);
|
||||
/* Erase file from zip */
|
||||
err = minizip_erase(path, NULL, argc - (path_arg + 1), &argv[path_arg + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add files to zip */
|
||||
err = minizip_add(path, password, &options, argc - (path_arg + 1), &argv[path_arg + 1]);
|
||||
}
|
||||
|
||||
if (err == MZ_OK && do_erase)
|
||||
{
|
||||
// Swap zip with temporary zip, backup old zip if possible
|
||||
strncpy(bak_path, path, sizeof(bak_path) - 1);
|
||||
bak_path[sizeof(bak_path) - 1] = 0;
|
||||
strncat(bak_path, ".bak", sizeof(bak_path) - strlen(bak_path) - 1);
|
||||
|
||||
if (mz_os_file_exists(bak_path) == MZ_OK)
|
||||
mz_os_delete(bak_path);
|
||||
|
||||
if (mz_os_rename(path, bak_path) != MZ_OK)
|
||||
printf("Error backing up zip before replacing %s\n", bak_path);
|
||||
|
||||
if (mz_os_rename(tmp_path, path) != MZ_OK)
|
||||
printf("Error replacing zip with temp %s\n", tmp_path);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz.h -- Errors codes, zip flags and magic
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,22 +12,18 @@
|
||||
#ifndef MZ_H
|
||||
#define MZ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// MZ_VERSION
|
||||
#define MZ_VERSION ("2.7.2")
|
||||
/* MZ_VERSION */
|
||||
#define MZ_VERSION ("2.8.2")
|
||||
|
||||
// MZ_ERROR
|
||||
#define MZ_OK (0) // zlib
|
||||
#define MZ_STREAM_ERROR (-1) // zlib
|
||||
#define MZ_DATA_ERROR (-3) // zlib
|
||||
#define MZ_MEM_ERROR (-4) // zlib
|
||||
#define MZ_BUF_ERROR (-5) // zlib
|
||||
#define MZ_VERSION_ERROR (-6) // zlib
|
||||
/* MZ_ERROR */
|
||||
#define MZ_OK (0) /* zlib */
|
||||
#define MZ_STREAM_ERROR (-1) /* zlib */
|
||||
#define MZ_DATA_ERROR (-3) /* zlib */
|
||||
#define MZ_MEM_ERROR (-4) /* zlib */
|
||||
#define MZ_BUF_ERROR (-5) /* zlib */
|
||||
#define MZ_VERSION_ERROR (-6) /* zlib */
|
||||
|
||||
#define MZ_END_OF_LIST (-100)
|
||||
#define MZ_END_OF_STREAM (-101)
|
||||
@@ -49,7 +45,7 @@ extern "C" {
|
||||
#define MZ_WRITE_ERROR (-116)
|
||||
#define MZ_SIGN_ERROR (-117)
|
||||
|
||||
// MZ_OPEN
|
||||
/* MZ_OPEN */
|
||||
#define MZ_OPEN_MODE_READ (0x01)
|
||||
#define MZ_OPEN_MODE_WRITE (0x02)
|
||||
#define MZ_OPEN_MODE_READWRITE (MZ_OPEN_MODE_READ | MZ_OPEN_MODE_WRITE)
|
||||
@@ -57,12 +53,12 @@ extern "C" {
|
||||
#define MZ_OPEN_MODE_CREATE (0x08)
|
||||
#define MZ_OPEN_MODE_EXISTING (0x10)
|
||||
|
||||
// MZ_SEEK
|
||||
/* MZ_SEEK */
|
||||
#define MZ_SEEK_SET (0)
|
||||
#define MZ_SEEK_CUR (1)
|
||||
#define MZ_SEEK_END (2)
|
||||
|
||||
// MZ_COMPRESS
|
||||
/* MZ_COMPRESS */
|
||||
#define MZ_COMPRESS_METHOD_STORE (0)
|
||||
#define MZ_COMPRESS_METHOD_DEFLATE (8)
|
||||
#define MZ_COMPRESS_METHOD_BZIP2 (12)
|
||||
@@ -74,7 +70,7 @@ extern "C" {
|
||||
#define MZ_COMPRESS_LEVEL_NORMAL (6)
|
||||
#define MZ_COMPRESS_LEVEL_BEST (9)
|
||||
|
||||
// MZ_ZIP_FLAG
|
||||
/* MZ_ZIP_FLAG */
|
||||
#define MZ_ZIP_FLAG_ENCRYPTED (1 << 0)
|
||||
#define MZ_ZIP_FLAG_LZMA_EOS_MARKER (1 << 1)
|
||||
#define MZ_ZIP_FLAG_DEFLATE_MAX (1 << 1)
|
||||
@@ -86,7 +82,7 @@ extern "C" {
|
||||
#define MZ_ZIP_FLAG_UTF8 (1 << 11)
|
||||
#define MZ_ZIP_FLAG_MASK_LOCAL_INFO (1 << 13)
|
||||
|
||||
// MZ_ZIP_EXTENSION
|
||||
/* MZ_ZIP_EXTENSION */
|
||||
#define MZ_ZIP_EXTENSION_ZIP64 (0x0001)
|
||||
#define MZ_ZIP_EXTENSION_NTFS (0x000a)
|
||||
#define MZ_ZIP_EXTENSION_AES (0x9901)
|
||||
@@ -95,22 +91,22 @@ extern "C" {
|
||||
#define MZ_ZIP_EXTENSION_HASH (0x1a51)
|
||||
#define MZ_ZIP_EXTENSION_CDCD (0xcdcd)
|
||||
|
||||
// MZ_ZIP64
|
||||
/* MZ_ZIP64 */
|
||||
#define MZ_ZIP64_AUTO (0)
|
||||
#define MZ_ZIP64_FORCE (1)
|
||||
#define MZ_ZIP64_DISABLE (2)
|
||||
|
||||
// MZ_HOST_SYSTEM
|
||||
/* MZ_HOST_SYSTEM */
|
||||
#define MZ_HOST_SYSTEM(VERSION_MADEBY) ((uint8_t)(VERSION_MADEBY >> 8))
|
||||
#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_PKCRYPT
|
||||
/* MZ_PKCRYPT */
|
||||
#define MZ_PKCRYPT_HEADER_SIZE (12)
|
||||
|
||||
// MZ_AES
|
||||
/* MZ_AES */
|
||||
#define MZ_AES_VERSION (1)
|
||||
#define MZ_AES_ENCRYPTION_MODE_128 (0x01)
|
||||
#define MZ_AES_ENCRYPTION_MODE_192 (0x02)
|
||||
@@ -121,7 +117,7 @@ extern "C" {
|
||||
#define MZ_AES_HEADER_SIZE(MODE) ((4 * (MODE & 3) + 4) + 2)
|
||||
#define MZ_AES_FOOTER_SIZE (10)
|
||||
|
||||
// MZ_HASH
|
||||
/* MZ_HASH */
|
||||
#define MZ_HASH_MD5 (10)
|
||||
#define MZ_HASH_MD5_SIZE (16)
|
||||
#define MZ_HASH_SHA1 (20)
|
||||
@@ -130,14 +126,14 @@ extern "C" {
|
||||
#define MZ_HASH_SHA256_SIZE (32)
|
||||
#define MZ_HASH_MAX_SIZE (256)
|
||||
|
||||
// MZ_ENCODING
|
||||
/* MZ_ENCODING */
|
||||
#define MZ_ENCODING_CODEPAGE_437 (437)
|
||||
#define MZ_ENCODING_CODEPAGE_932 (932)
|
||||
#define MZ_ENCODING_CODEPAGE_936 (936)
|
||||
#define MZ_ENCODING_CODEPAGE_950 (950)
|
||||
#define MZ_ENCODING_UTF8 (65001)
|
||||
|
||||
// MZ_UTILITY
|
||||
/* MZ_UTILITY */
|
||||
#define MZ_UNUSED(SYMBOL) ((void)SYMBOL)
|
||||
|
||||
#ifndef MZ_CUSTOM_ALLOC
|
||||
@@ -149,8 +145,100 @@ extern "C" {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#include <stdlib.h> /* size_t, NULL, malloc */
|
||||
#include <time.h> /* time_t, time() */
|
||||
#include <string.h> /* memset, strncpy, strlen */
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#ifndef __INT8_TYPE__
|
||||
typedef signed char int8_t;
|
||||
#endif
|
||||
#ifndef __INT16_TYPE__
|
||||
typedef short int16_t;
|
||||
#endif
|
||||
#ifndef __INT32_TYPE__
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
#ifndef __INT64_TYPE__
|
||||
typedef long long int64_t;
|
||||
#endif
|
||||
#ifndef __UINT8_TYPE__
|
||||
typedef unsigned char uint8_t;
|
||||
#endif
|
||||
#ifndef __UINT16_TYPE__
|
||||
typedef unsigned short uint16_t;
|
||||
#endif
|
||||
#ifndef __UINT32_TYPE__
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
#ifndef __UINT64_TYPE__
|
||||
typedef unsigned long long uint64_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifndef PRId8
|
||||
# define PRId8 "hhd"
|
||||
#endif
|
||||
#ifndef PRId16
|
||||
# define PRId16 "hd"
|
||||
#endif
|
||||
#ifndef PRId32
|
||||
# define PRId32 "d"
|
||||
#endif
|
||||
#ifndef PRIu32
|
||||
# define PRIu32 "u"
|
||||
#endif
|
||||
#ifndef PRIx32
|
||||
# define PRIx32 "x"
|
||||
#endif
|
||||
#if ULONG_MAX == 4294967295UL
|
||||
# ifndef PRId64
|
||||
# define PRId64 "lld"
|
||||
# endif
|
||||
# ifndef PRIu64
|
||||
# define PRIu64 "llu"
|
||||
# endif
|
||||
# ifndef PRIx64
|
||||
# define PRIx64 "llx"
|
||||
# endif
|
||||
#else
|
||||
# ifndef PRId64
|
||||
# define PRId64 "ld"
|
||||
# endif
|
||||
# ifndef PRIu64
|
||||
# define PRIu64 "lu"
|
||||
# endif
|
||||
# ifndef PRIx64
|
||||
# define PRIx64 "lx"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
# define INT16_MAX 32767
|
||||
#endif
|
||||
#ifndef INT32_MAX
|
||||
# define INT32_MAX 2147483647L
|
||||
#endif
|
||||
#ifndef INT64_MAX
|
||||
# define INT64_MAX 9223372036854775807LL
|
||||
#endif
|
||||
#ifndef UINT16_MAX
|
||||
# define UINT16_MAX 65535U
|
||||
#endif
|
||||
#ifndef UINT32_MAX
|
||||
# define UINT32_MAX 4294967295UL
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
# define UINT64_MAX 18446744073709551615ULL
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#endif
|
||||
+12
-14
@@ -1,8 +1,8 @@
|
||||
/* mz_compat.c -- Backwards compatible interface for older versions
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
https://www.winimage.com/zLibDll/minizip.html
|
||||
@@ -11,10 +11,6 @@
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
@@ -24,6 +20,8 @@
|
||||
#include "mz_strm_zlib.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
#include <stdio.h> /* SEEK */
|
||||
|
||||
#include "mz_compat.h"
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -182,8 +180,8 @@ int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_f
|
||||
|
||||
file_info.compression_method = compression_method;
|
||||
file_info.filename = filename;
|
||||
//file_info.extrafield_local = extrafield_local;
|
||||
//file_info.extrafield_local_size = size_extrafield_local;
|
||||
/* file_info.extrafield_local = extrafield_local; */
|
||||
/* file_info.extrafield_local_size = size_extrafield_local; */
|
||||
file_info.extrafield = extrafield_global;
|
||||
file_info.extrafield_size = size_extrafield_global;
|
||||
file_info.version_madeby = version_madeby;
|
||||
@@ -193,7 +191,7 @@ int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_f
|
||||
file_info.zip64 = MZ_ZIP64_FORCE;
|
||||
else
|
||||
file_info.zip64 = MZ_ZIP64_DISABLE;
|
||||
#ifdef HAVE_AES
|
||||
#ifdef HAVE_WZAES
|
||||
if ((password != NULL) || (raw && (file_info.flag & MZ_ZIP_FLAG_ENCRYPTED)))
|
||||
file_info.aes_version = MZ_AES_VERSION;
|
||||
#endif
|
||||
@@ -312,13 +310,13 @@ int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t vers
|
||||
return err;
|
||||
}
|
||||
|
||||
// Only closes the zip handle, does not close the stream
|
||||
/* Only closes the zip handle, does not close the stream */
|
||||
int ZEXPORT zipClose_MZ(zipFile file, const char *global_comment)
|
||||
{
|
||||
return zipClose2_MZ(file, global_comment, MZ_VERSION_MADEBY);
|
||||
}
|
||||
|
||||
// Only closes the zip handle, does not close the stream
|
||||
/* Only closes the zip handle, does not close the stream */
|
||||
int ZEXPORT zipClose2_MZ(zipFile file, const char *global_comment, uint16_t version_madeby)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
@@ -449,7 +447,7 @@ int ZEXPORT unzClose(unzFile file)
|
||||
return err;
|
||||
}
|
||||
|
||||
// Only closes the zip handle, does not close the stream
|
||||
/* Only closes the zip handle, does not close the stream */
|
||||
int ZEXPORT unzClose_MZ(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
@@ -955,7 +953,7 @@ int ZEXPORT unzSeek64(unzFile file, int64_t offset, int origin)
|
||||
|
||||
err = mz_zip_get_stream(compat->handle, &stream);
|
||||
if (err == MZ_OK)
|
||||
err = mz_stream_seek(stream, compat->entry_pos + position, SEEK_SET);
|
||||
err = mz_stream_seek(stream, compat->entry_pos + position, MZ_SEEK_SET);
|
||||
if (err == MZ_OK)
|
||||
compat->total_out = position;
|
||||
return err;
|
||||
@@ -1019,7 +1017,7 @@ void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
|
||||
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
// NOTE: You should no longer pass in widechar string to open function
|
||||
/* NOTE: You should no longer pass in widechar string to open function */
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
+55
-76
@@ -1,8 +1,8 @@
|
||||
/* mz_compat.h -- Backwards compatible interface for older versions
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
https://www.winimage.com/zLibDll/minizip.html
|
||||
@@ -14,13 +14,14 @@
|
||||
#ifndef MZ_COMPAT_H
|
||||
#define MZ_COMPAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include "mz.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(HAVE_ZLIB) && defined(MAX_MEM_LEVEL)
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
@@ -43,31 +44,6 @@ extern "C" {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(USE_FILE32API)
|
||||
# define fopen64 fopen
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
#else
|
||||
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
|
||||
defined(__OpenBSD__) || defined(__APPLE__) || defined(__ANDROID__)
|
||||
# define fopen64 fopen
|
||||
# define ftello64 ftello
|
||||
# define fseeko64 fseeko
|
||||
# endif
|
||||
# ifdef _MSC_VER
|
||||
# define fopen64 fopen
|
||||
# if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
|
||||
# define ftello64 _ftelli64
|
||||
# define fseeko64 _fseeki64
|
||||
# else /* old MSC */
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
@@ -94,8 +70,8 @@ typedef struct
|
||||
{
|
||||
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
|
||||
uint16_t internal_fa; /* internal file attributes 2 bytes */
|
||||
uint32_t external_fa; /* external file attributes 4 bytes */
|
||||
} zip_fileinfo;
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -114,7 +90,7 @@ typedef struct
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
/***************************************************************************/
|
||||
// Writing a zip file
|
||||
/* Writing a zip file */
|
||||
|
||||
zipFile ZEXPORT zipOpen(const char *path, int append);
|
||||
zipFile ZEXPORT zipOpen64(const void *path, int append);
|
||||
@@ -191,36 +167,36 @@ typedef void *unzFile;
|
||||
|
||||
typedef struct unz_global_info64_s
|
||||
{
|
||||
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
|
||||
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 */
|
||||
} 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_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
|
||||
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 */
|
||||
} 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 dosDate; // last mod file date in Dos fmt 4 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 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;
|
||||
|
||||
@@ -229,22 +205,22 @@ 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 dosDate; // last mod file date in Dos fmt 4 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
|
||||
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
|
||||
uint32_t external_fa; // external file attributes 4 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;
|
||||
} unz_file_info;
|
||||
@@ -254,10 +230,11 @@ typedef struct unz_file_info_s
|
||||
typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
|
||||
typedef int (*unzIteratorFunction)(unzFile file);
|
||||
typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
|
||||
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
|
||||
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment,
|
||||
uint16_t comment_size);
|
||||
|
||||
/***************************************************************************/
|
||||
// Opening and close a zip file
|
||||
/* Reading a zip file */
|
||||
|
||||
unzFile ZEXPORT unzOpen(const char *path);
|
||||
unzFile ZEXPORT unzOpen64(const void *path);
|
||||
@@ -281,23 +258,25 @@ int ZEXPORT unzCloseCurrentFile(unzFile file);
|
||||
|
||||
|
||||
int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
|
||||
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
|
||||
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment,
|
||||
uint16_t comment_size);
|
||||
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_info, char *filename,
|
||||
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
|
||||
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment,
|
||||
uint16_t comment_size);
|
||||
|
||||
int ZEXPORT unzGoToFirstFile(unzFile file);
|
||||
int ZEXPORT unzGoToNextFile(unzFile file);
|
||||
int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
|
||||
|
||||
int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned len);
|
||||
int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned int len);
|
||||
|
||||
/***************************************************************************/
|
||||
// Raw access to zip file
|
||||
/* Raw access to zip file */
|
||||
|
||||
typedef struct unz_file_pos_s
|
||||
{
|
||||
uint32_t pos_in_zip_directory; // offset in zip file directory
|
||||
uint32_t num_of_file; // # of file
|
||||
uint32_t pos_in_zip_directory; /* offset in zip file directory */
|
||||
uint32_t num_of_file; /* # of file */
|
||||
} unz_file_pos;
|
||||
|
||||
int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos);
|
||||
@@ -305,8 +284,8 @@ int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
|
||||
|
||||
typedef struct unz64_file_pos_s
|
||||
{
|
||||
int64_t pos_in_zip_directory; // offset in zip file directory
|
||||
uint64_t num_of_file; // # of file
|
||||
int64_t pos_in_zip_directory; /* offset in zip file directory */
|
||||
uint64_t num_of_file; /* # of file */
|
||||
} unz64_file_pos;
|
||||
|
||||
int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos);
|
||||
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
/* mz_crypt.c -- Crypto/hash functions
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_crypt.h"
|
||||
|
||||
#if defined(HAVE_ZLIB)
|
||||
# include "zlib.h"
|
||||
#elif defined(HAVE_LZMA)
|
||||
# include "lzma.h"
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint32_t mz_crypt_crc32_update(uint32_t value, const uint8_t *buf, int32_t size)
|
||||
{
|
||||
#if defined(HAVE_ZLIB)
|
||||
/* Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng */
|
||||
#ifdef ZLIBNG_VERNUM
|
||||
typedef uint32_t z_crc_t;
|
||||
#elif (ZLIB_VERNUM < 0x1270)
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
return (uint32_t)crc32((z_crc_t)value, buf, (uInt)size);
|
||||
#elif defined(HAVE_LZMA)
|
||||
return (uint32_t)lzma_crc32(buf, (size_t)size, (uint32_t)value);
|
||||
#else
|
||||
static uint32_t crc32_table[256] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
value = ~value;
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
value = (value >> 8) ^ crc32_table[(value ^ *buf) & 0xFF];
|
||||
|
||||
buf += 1;
|
||||
size -= 1;
|
||||
}
|
||||
|
||||
return ~value;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef MZ_ZIP_NO_ENCRYPTION
|
||||
int32_t mz_crypt_pbkdf2(uint8_t *password, int32_t password_length, uint8_t *salt,
|
||||
int32_t salt_length, int32_t iteration_count, uint8_t *key, int32_t key_length)
|
||||
{
|
||||
void *hmac1 = NULL;
|
||||
void *hmac2 = NULL;
|
||||
void *hmac3 = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
uint16_t i = 0;
|
||||
uint16_t j = 0;
|
||||
uint16_t k = 0;
|
||||
uint16_t block_count = 0;
|
||||
uint8_t uu[MZ_HASH_SHA1_SIZE];
|
||||
uint8_t ux[MZ_HASH_SHA1_SIZE];
|
||||
|
||||
if (password == NULL || salt == NULL || key == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
memset(key, 0, key_length);
|
||||
|
||||
mz_crypt_hmac_create(&hmac1);
|
||||
mz_crypt_hmac_create(&hmac2);
|
||||
mz_crypt_hmac_create(&hmac3);
|
||||
|
||||
mz_crypt_hmac_set_algorithm(hmac1, MZ_HASH_SHA1);
|
||||
mz_crypt_hmac_set_algorithm(hmac2, MZ_HASH_SHA1);
|
||||
mz_crypt_hmac_set_algorithm(hmac3, MZ_HASH_SHA1);
|
||||
|
||||
err = mz_crypt_hmac_init(hmac1, password, password_length);
|
||||
if (err == MZ_OK)
|
||||
err = mz_crypt_hmac_init(hmac2, password, password_length);
|
||||
if (err == MZ_OK)
|
||||
err = mz_crypt_hmac_update(hmac2, salt, salt_length);
|
||||
|
||||
block_count = 1 + ((uint16_t)key_length - 1) / MZ_HASH_SHA1_SIZE;
|
||||
|
||||
for (i = 0; (err == MZ_OK) && (i < block_count); i += 1)
|
||||
{
|
||||
memset(ux, 0, sizeof(ux));
|
||||
|
||||
err = mz_crypt_hmac_copy(hmac2, hmac3);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
uu[0] = (uint8_t)((i + 1) >> 24);
|
||||
uu[1] = (uint8_t)((i + 1) >> 16);
|
||||
uu[2] = (uint8_t)((i + 1) >> 8);
|
||||
uu[3] = (uint8_t)(i + 1);
|
||||
|
||||
for (j = 0, k = 4; j < iteration_count; j += 1)
|
||||
{
|
||||
err = mz_crypt_hmac_update(hmac3, uu, k);
|
||||
if (err == MZ_OK)
|
||||
err = mz_crypt_hmac_end(hmac3, uu, sizeof(uu));
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
for(k = 0; k < MZ_HASH_SHA1_SIZE; k += 1)
|
||||
ux[k] ^= uu[k];
|
||||
|
||||
err = mz_crypt_hmac_copy(hmac1, hmac3);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
j = 0;
|
||||
k = i * MZ_HASH_SHA1_SIZE;
|
||||
|
||||
while (j < MZ_HASH_SHA1_SIZE && k < key_length)
|
||||
key[k++] = ux[j++];
|
||||
}
|
||||
|
||||
mz_crypt_hmac_delete(&hmac1);
|
||||
mz_crypt_hmac_delete(&hmac2);
|
||||
mz_crypt_hmac_delete(&hmac3);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
+9
-4
@@ -1,8 +1,8 @@
|
||||
/* mz_crypt.h -- Crypto/hash functions
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,14 +12,19 @@
|
||||
#ifndef MZ_CRYPT_H
|
||||
#define MZ_CRYPT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint32_t mz_crypt_crc32_update(uint32_t value, const uint8_t *buf, int32_t size);
|
||||
|
||||
int32_t mz_crypt_pbkdf2(uint8_t *password, int32_t password_length, uint8_t *salt,
|
||||
int32_t salt_length, int32_t iteration_count, uint8_t *key, int32_t key_length);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_crypt_rand(uint8_t *buf, int32_t size);
|
||||
|
||||
void mz_crypt_sha_reset(void *handle);
|
||||
|
||||
+5
-12
@@ -1,17 +1,16 @@
|
||||
/* mz_crypt_apple.c -- Crypto/hash functions for Apple
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CommonCrypto/CommonCryptor.h>
|
||||
@@ -21,11 +20,6 @@
|
||||
#include <Security/Security.h>
|
||||
#include <Security/SecPolicy.h>
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_crypt_rand(uint8_t *buf, int32_t size)
|
||||
@@ -482,12 +476,11 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
|
||||
CMSDecoderRef decoder = NULL;
|
||||
CMSSignerStatus signer_status = 0;
|
||||
CFDataRef message_out = NULL;
|
||||
SecTrustRef trust = NULL;
|
||||
SecPolicyRef trust_policy = NULL;
|
||||
OSStatus status = noErr;
|
||||
OSStatus verify_status = noErr;
|
||||
size_t signer_count = 0;
|
||||
int32_t i = 0;
|
||||
size_t i = 0;
|
||||
int32_t err = MZ_SIGN_ERROR;
|
||||
|
||||
if (message == NULL || signature == NULL)
|
||||
|
||||
+10
-13
@@ -1,25 +1,27 @@
|
||||
/* mz_crypt_brg.c -- Crypto/hash functions using Brian Gladman's library
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
|
||||
#if defined(HAVE_GETRANDOM)
|
||||
# include <sys/random.h>
|
||||
#endif
|
||||
#if defined(HAVE_LIBBSD)
|
||||
# include <bsd/stdlib.h> // arc4random_buf
|
||||
# include <sys/types.h>
|
||||
# ifndef __u_char_defined
|
||||
typedef unsigned char u_char;
|
||||
# endif
|
||||
# include <bsd/stdlib.h> /* arc4random_buf */
|
||||
#endif
|
||||
|
||||
#include "aes.h"
|
||||
@@ -27,11 +29,6 @@
|
||||
#include "sha2.h"
|
||||
#include "hmac.h"
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(HAVE_ARC4RANDOM_BUF)
|
||||
|
||||
+11
-13
@@ -1,17 +1,16 @@
|
||||
/* mz_crypt_openssl.c -- Crypto/hash functions for OpenSSL
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
@@ -22,11 +21,6 @@
|
||||
#include <openssl/cms.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static void mz_crypt_init(void)
|
||||
@@ -444,6 +438,9 @@ int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle)
|
||||
|
||||
if (source == NULL || target == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (target->ctx == NULL)
|
||||
target->ctx = HMAC_CTX_new();
|
||||
|
||||
result = HMAC_CTX_copy(target->ctx, source->ctx);
|
||||
if (!result)
|
||||
@@ -632,11 +629,12 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
|
||||
intercerts = CMS_get1_certs(cms);
|
||||
if (intercerts)
|
||||
{
|
||||
// Verify signer certificates
|
||||
/* Verify signer certificates */
|
||||
signer_count = sk_X509_num(signers);
|
||||
if (signer_count > 0)
|
||||
err = MZ_OK;
|
||||
|
||||
for (i = 0; i < sk_X509_num(signers); i++)
|
||||
for (i = 0; i < signer_count; i++)
|
||||
{
|
||||
store_ctx = X509_STORE_CTX_new();
|
||||
X509_STORE_CTX_init(store_ctx, cert_store, sk_X509_value(signers, i), intercerts);
|
||||
@@ -656,7 +654,7 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Verify the message
|
||||
/* Verify the message */
|
||||
if (((int32_t)buf_mem->length != message_size) ||
|
||||
(memcmp(buf_mem->data, message, message_size) != 0))
|
||||
err = MZ_SIGN_ERROR;
|
||||
|
||||
+24
-25
@@ -1,8 +1,8 @@
|
||||
/* mz_crypt_win32.c -- Crypto/hash functions for Windows
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -11,18 +11,13 @@
|
||||
|
||||
#pragma comment(lib, "crypt32.lib")
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_crypt.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_crypt_rand(uint8_t *buf, int32_t size)
|
||||
@@ -200,7 +195,6 @@ static void mz_crypt_aes_free(void *handle)
|
||||
|
||||
void mz_crypt_aes_reset(void *handle)
|
||||
{
|
||||
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
||||
mz_crypt_aes_free(handle);
|
||||
}
|
||||
|
||||
@@ -244,12 +238,12 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l
|
||||
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
||||
HCRYPTHASH hash = 0;
|
||||
ALG_ID alg_id = 0;
|
||||
ALG_ID hash_alg_id = 0;
|
||||
typedef struct key_blob_header_s {
|
||||
BLOBHEADER hdr;
|
||||
uint32_t key_length;
|
||||
} key_blob_header_s;
|
||||
key_blob_header_s *key_blob_s = NULL;
|
||||
uint32_t mode = CRYPT_MODE_ECB;
|
||||
uint8_t *key_blob = NULL;
|
||||
int32_t key_blob_size = 0;
|
||||
int32_t result = 0;
|
||||
@@ -285,8 +279,12 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l
|
||||
|
||||
memcpy(key_blob + sizeof(key_blob_header_s), key, key_length);
|
||||
|
||||
result = CryptImportKey(aes->provider, key_blob, key_blob_size, 0, CRYPT_IPSEC_HMAC_KEY, &aes->key);
|
||||
result = CryptImportKey(aes->provider, key_blob, key_blob_size, 0, 0, &aes->key);
|
||||
}
|
||||
|
||||
if (result)
|
||||
result = CryptSetKeyParam(aes->key, KP_MODE, (const uint8_t *)&mode, 0);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
aes->error = GetLastError();
|
||||
@@ -374,14 +372,12 @@ static void mz_crypt_hmac_free(void *handle)
|
||||
|
||||
void mz_crypt_hmac_reset(void *handle)
|
||||
{
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
mz_crypt_hmac_free(handle);
|
||||
}
|
||||
|
||||
int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length)
|
||||
{
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
HCRYPTHASH hash = 0;
|
||||
ALG_ID alg_id = 0;
|
||||
typedef struct key_blob_header_s {
|
||||
BLOBHEADER hdr;
|
||||
@@ -468,7 +464,6 @@ int32_t mz_crypt_hmac_end(void *handle, uint8_t *digest, int32_t digest_size)
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
int32_t result = 0;
|
||||
int32_t expected_size = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (hmac == NULL || digest == NULL || hmac->hash == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
@@ -506,7 +501,7 @@ int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle)
|
||||
target->error = GetLastError();
|
||||
err = MZ_HASH_ERROR;
|
||||
}
|
||||
return MZ_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
void *mz_crypt_hmac_create(void **handle)
|
||||
@@ -551,7 +546,6 @@ int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data
|
||||
wchar_t *password_wide = NULL;
|
||||
int32_t result = 0;
|
||||
int32_t err = MZ_OK;
|
||||
uint32_t key_spec = 0;
|
||||
uint32_t messages_sizes[1];
|
||||
uint8_t *messages[1];
|
||||
|
||||
@@ -600,7 +594,7 @@ int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data
|
||||
messages[0] = message;
|
||||
messages_sizes[0] = message_size;
|
||||
|
||||
#if 0 // Timestamp support
|
||||
#if 0 /* Timestamp support */
|
||||
CRYPT_ATTR_BLOB crypt_blob;
|
||||
CRYPT_TIMESTAMP_CONTEXT *ts_context = NULL;
|
||||
CRYPT_ATTRIBUTE unauth_attribs[1];
|
||||
@@ -684,14 +678,15 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
|
||||
if (result && decoded_size > 0)
|
||||
decoded = (uint8_t *)MZ_ALLOC(decoded_size);
|
||||
|
||||
if (result)
|
||||
if (result && decoded != NULL)
|
||||
result = CryptVerifyMessageSignature(&verify_params, 0, signature, signature_size,
|
||||
decoded, &decoded_size, NULL);
|
||||
|
||||
#if 0
|
||||
crypt_msg = CryptMsgOpenToDecode(PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, 0, 0, 0, NULL, NULL);
|
||||
if (crypt_msg != NULL)
|
||||
{
|
||||
#if 0 // Timestamp support
|
||||
/* Timestamp support */
|
||||
PCRYPT_ATTRIBUTES unauth_attribs = NULL;
|
||||
HCRYPTMSG ts_msg = 0;
|
||||
uint8_t *ts_content = NULL;
|
||||
@@ -735,12 +730,16 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
|
||||
|
||||
if (crypt_context != NULL)
|
||||
CryptMemFree(crypt_context);
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((crypt_msg != NULL) && (result) && (decoded_size == message_size))
|
||||
else
|
||||
{
|
||||
// Verify cms message with our stored message
|
||||
result = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((result) && (decoded != NULL) && (decoded_size == message_size))
|
||||
{
|
||||
/* Verify cms message with our stored message */
|
||||
if (memcmp(decoded, message, message_size) == 0)
|
||||
err = MZ_OK;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_os.c -- System functions
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
https://www.winimage.com/zLibDll/minizip.html
|
||||
@@ -11,17 +11,14 @@
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_crypt.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_crc32.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
#include <ctype.h> /* tolower */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path)
|
||||
@@ -70,7 +67,7 @@ int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignor
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
default:
|
||||
// Ignore differences in path slashes on platforms
|
||||
/* Ignore differences in path slashes on platforms */
|
||||
if ((*path == '\\' && *wildcard == '/') || (*path == '/' && *wildcard == '\\'))
|
||||
break;
|
||||
|
||||
@@ -115,7 +112,7 @@ int32_t mz_path_resolve(const char *path, char *output, int32_t max_output)
|
||||
|
||||
if ((source == path) || (check != source))
|
||||
{
|
||||
// Skip double paths
|
||||
/* Skip double paths */
|
||||
if ((*check == '\\') || (*check == '/'))
|
||||
{
|
||||
source += 1;
|
||||
@@ -125,10 +122,10 @@ int32_t mz_path_resolve(const char *path, char *output, int32_t max_output)
|
||||
{
|
||||
check += 1;
|
||||
|
||||
// Remove current directory . if at end of string
|
||||
/* Remove current directory . if at end of string */
|
||||
if ((*check == 0) && (source != path))
|
||||
{
|
||||
// Copy last slash
|
||||
/* Copy last slash */
|
||||
*target = *source;
|
||||
target += 1;
|
||||
max_output -= 1;
|
||||
@@ -136,10 +133,10 @@ int32_t mz_path_resolve(const char *path, char *output, int32_t max_output)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove current directory . if not at end of string
|
||||
/* Remove current directory . if not at end of string */
|
||||
if ((*check == 0) || (*check == '\\' || *check == '/'))
|
||||
{
|
||||
// Only proceed if .\ is not entire string
|
||||
/* Only proceed if .\ is not entire string */
|
||||
if (check[1] != 0 || (path != source))
|
||||
{
|
||||
source += (check - source);
|
||||
@@ -147,7 +144,7 @@ int32_t mz_path_resolve(const char *path, char *output, int32_t max_output)
|
||||
}
|
||||
}
|
||||
|
||||
// Go to parent directory ..
|
||||
/* Go to parent directory .. */
|
||||
if ((*check != 0) || (*check == '.'))
|
||||
{
|
||||
check += 1;
|
||||
@@ -155,7 +152,7 @@ int32_t mz_path_resolve(const char *path, char *output, int32_t max_output)
|
||||
{
|
||||
source += (check - source);
|
||||
|
||||
// Search backwards for previous slash
|
||||
/* Search backwards for previous slash */
|
||||
if (target != output)
|
||||
{
|
||||
target -= 1;
|
||||
@@ -216,6 +213,10 @@ int32_t mz_path_remove_filename(char *path)
|
||||
|
||||
path_ptr -= 1;
|
||||
}
|
||||
|
||||
if (path_ptr == path)
|
||||
*path_ptr = 0;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@@ -291,7 +292,7 @@ int32_t mz_dir_make(const char *path)
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc)
|
||||
{
|
||||
void *stream = NULL;
|
||||
void *crc32_stream = NULL;
|
||||
uint32_t crc32 = 0;
|
||||
int32_t read = 0;
|
||||
int32_t err = MZ_OK;
|
||||
uint8_t buf[16384];
|
||||
@@ -300,31 +301,26 @@ int32_t mz_file_get_crc(const char *path, uint32_t *result_crc)
|
||||
|
||||
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
|
||||
|
||||
mz_stream_crc32_create(&crc32_stream);
|
||||
mz_stream_crc32_open(crc32_stream, NULL, MZ_OPEN_MODE_READ);
|
||||
|
||||
mz_stream_set_base(crc32_stream, stream);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
do
|
||||
{
|
||||
read = mz_stream_crc32_read(crc32_stream, buf, sizeof(buf));
|
||||
read = mz_stream_os_read(stream, buf, sizeof(buf));
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
err = read;
|
||||
break;
|
||||
}
|
||||
|
||||
crc32 = mz_crypt_crc32_update(crc32, buf, read);
|
||||
}
|
||||
while ((err == MZ_OK) && (read > 0));
|
||||
|
||||
mz_stream_os_close(stream);
|
||||
}
|
||||
|
||||
mz_stream_crc32_close(crc32_stream);
|
||||
*result_crc = mz_stream_crc32_get_value(crc32_stream);
|
||||
mz_stream_crc32_delete(&crc32_stream);
|
||||
*result_crc = crc32;
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_os.h -- System functions
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,9 +12,6 @@
|
||||
#ifndef MZ_OS_H
|
||||
#define MZ_OS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -23,7 +20,7 @@ extern "C" {
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_OSX_DARWIN)
|
||||
#elif defined(unix)
|
||||
#elif defined(__unix__)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_UNIX)
|
||||
#elif defined(_WIN32)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_WINDOWS_NTFS)
|
||||
@@ -31,7 +28,7 @@ extern "C" {
|
||||
|
||||
#ifdef HAVE_LZMA
|
||||
#define MZ_VERSION_MADEBY_ZIP_VERSION (63)
|
||||
#elif HAVE_AES
|
||||
#elif HAVE_WZAES
|
||||
#define MZ_VERSION_MADEBY_ZIP_VERSION (51)
|
||||
#elif HAVE_BZIP2
|
||||
#define MZ_VERSION_MADEBY_ZIP_VERSION (46)
|
||||
@@ -54,88 +51,88 @@ typedef void* DIR;
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
// Shared functions
|
||||
/* Shared functions */
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path);
|
||||
// Combines two paths
|
||||
/* Combines two paths */
|
||||
|
||||
int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case);
|
||||
// Compare two paths with wildcard
|
||||
/* Compare two paths with wildcard */
|
||||
|
||||
int32_t mz_path_resolve(const char *path, char *target, int32_t max_target);
|
||||
// Resolves path
|
||||
/* Resolves path */
|
||||
|
||||
int32_t mz_path_remove_filename(char *path);
|
||||
// Remove the filename from a 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
|
||||
/* Get the filename from a path */
|
||||
|
||||
int32_t mz_dir_make(const char *path);
|
||||
// Creates a directory recursively
|
||||
/* Creates a directory recursively */
|
||||
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc);
|
||||
// Gets the crc32 hash of a file
|
||||
/* Gets the crc32 hash of a file */
|
||||
|
||||
/***************************************************************************/
|
||||
// Platform specific functions
|
||||
/* Platform specific functions */
|
||||
|
||||
wchar_t *mz_os_unicode_string_create(const char *string, int32_t encoding);
|
||||
// Create unicode string from a utf8 string
|
||||
/* Create unicode string from a utf8 string */
|
||||
|
||||
void mz_os_unicode_string_delete(wchar_t **string);
|
||||
// Delete a unicode string that was created
|
||||
/* Delete a unicode string that was created */
|
||||
|
||||
uint8_t *mz_os_utf8_string_create(const char *string, int32_t encoding);
|
||||
// Create a utf8 string from a string with another encoding
|
||||
/* Create a utf8 string from a string with another encoding */
|
||||
|
||||
void mz_os_utf8_string_delete(uint8_t **string);
|
||||
// Delete a utf8 string that was created
|
||||
/* Delete a utf8 string that was created */
|
||||
|
||||
int32_t mz_os_rand(uint8_t *buf, int32_t size);
|
||||
// Random number generator (not cryptographically secure)
|
||||
/* Random number generator (not cryptographically secure) */
|
||||
|
||||
int32_t mz_os_rename(const char *source_path, const char *target_path);
|
||||
// Rename a file
|
||||
/* Rename a file */
|
||||
|
||||
int32_t mz_os_delete(const char *path);
|
||||
// Delete an existing file
|
||||
/* Delete an existing file */
|
||||
|
||||
int32_t mz_os_file_exists(const char *path);
|
||||
// Check to see if a file exists
|
||||
/* Check to see if a file exists */
|
||||
|
||||
int64_t mz_os_get_file_size(const char *path);
|
||||
// Gets the length of a file
|
||||
/* Gets the length of a file */
|
||||
|
||||
int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
|
||||
// Gets a file's modified, access, and creation dates if supported
|
||||
/* Gets a file's modified, access, and creation dates if supported */
|
||||
|
||||
int32_t mz_os_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
|
||||
// Sets a file's modified, access, and creation dates if supported
|
||||
/* Sets a file's modified, access, and creation dates if supported */
|
||||
|
||||
int32_t mz_os_get_file_attribs(const char *path, uint32_t *attributes);
|
||||
// Gets a file's attributes
|
||||
/* Gets a file's attributes */
|
||||
|
||||
int32_t mz_os_set_file_attribs(const char *path, uint32_t attributes);
|
||||
// Sets a file's attributes
|
||||
/* Sets a file's attributes */
|
||||
|
||||
int32_t mz_os_make_dir(const char *path);
|
||||
// Recursively creates a directory
|
||||
/* Recursively creates a directory */
|
||||
|
||||
DIR* mz_os_open_dir(const char *path);
|
||||
// Opens a directory for listing
|
||||
/* Opens a directory for listing */
|
||||
struct
|
||||
dirent* mz_os_read_dir(DIR *dir);
|
||||
// Reads a directory listing entry
|
||||
/* Reads a directory listing entry */
|
||||
|
||||
int32_t mz_os_close_dir(DIR *dir);
|
||||
// Closes a directory that has been opened for listing
|
||||
/* Closes a directory that has been opened for listing */
|
||||
|
||||
int32_t mz_os_is_dir(const char *path);
|
||||
// Checks to see if path is a directory
|
||||
/* Checks to see if path is a directory */
|
||||
|
||||
uint64_t mz_os_ms_time(void);
|
||||
// Gets the time in milliseconds
|
||||
/* Gets the time in milliseconds */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
+41
-33
@@ -1,24 +1,26 @@
|
||||
/* mz_os_posix.c -- System functions for posix
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_os.h"
|
||||
|
||||
#include <stdio.h> /* rename */
|
||||
#include <errno.h>
|
||||
#include <iconv.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(__APPLE__) || defined(unix)
|
||||
#if defined(__APPLE__) || defined(__unix__)
|
||||
# include <utime.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
@@ -27,10 +29,6 @@
|
||||
# include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_os.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint8_t *mz_os_utf8_string_create(const char *string, int32_t encoding)
|
||||
@@ -103,7 +101,7 @@ int32_t mz_os_rand(uint8_t *buf, int32_t size)
|
||||
static unsigned calls = 0;
|
||||
int32_t i = 0;
|
||||
|
||||
// Ensure different random header each time
|
||||
/* Ensure different random header each time */
|
||||
if (++calls == 1)
|
||||
{
|
||||
#define PI_SEED 3141592654UL
|
||||
@@ -134,52 +132,58 @@ int32_t mz_os_delete(const char *path)
|
||||
|
||||
int32_t mz_os_file_exists(const char *path)
|
||||
{
|
||||
struct stat stat_info;
|
||||
struct stat path_stat;
|
||||
|
||||
memset(&stat_info, 0, sizeof(stat_info));
|
||||
if (stat(path, &stat_info) == 0)
|
||||
memset(&path_stat, 0, sizeof(path_stat));
|
||||
if (stat(path, &path_stat) == 0)
|
||||
return MZ_OK;
|
||||
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
int64_t mz_os_get_file_size(const char *path)
|
||||
{
|
||||
struct stat stat_info;
|
||||
struct stat path_stat;
|
||||
|
||||
memset(&stat_info, 0, sizeof(stat_info));
|
||||
if (stat(path, &stat_info) == 0)
|
||||
return stat_info.st_size;
|
||||
memset(&path_stat, 0, sizeof(path_stat));
|
||||
if (stat(path, &path_stat) == 0)
|
||||
{
|
||||
/* Stat returns size taken up by directory entry, so return 0 */
|
||||
if (S_ISDIR(path_stat.st_mode))
|
||||
return 0;
|
||||
|
||||
return path_stat.st_size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date)
|
||||
{
|
||||
struct stat stat_info;
|
||||
struct stat path_stat;
|
||||
char *name = NULL;
|
||||
size_t len = 0;
|
||||
int32_t err = MZ_INTERNAL_ERROR;
|
||||
|
||||
memset(&stat_info, 0, sizeof(stat_info));
|
||||
memset(&path_stat, 0, sizeof(path_stat));
|
||||
|
||||
if (strcmp(path, "-") != 0)
|
||||
{
|
||||
// Not all systems allow stat'ing a file with / appended
|
||||
/* Not all systems allow stat'ing a file with / appended */
|
||||
len = strlen(path);
|
||||
name = (char *)malloc(len + 1);
|
||||
strncpy(name, path, len);
|
||||
name[len] = 0;
|
||||
if (name[len - 1] == '/')
|
||||
|
||||
if (name[len - 1] == '/' || name[len - 1] == '\\')
|
||||
name[len - 1] = 0;
|
||||
|
||||
if (stat(name, &stat_info) == 0)
|
||||
if (stat(name, &path_stat) == 0)
|
||||
{
|
||||
if (modified_date != NULL)
|
||||
*modified_date = stat_info.st_mtime;
|
||||
*modified_date = path_stat.st_mtime;
|
||||
if (accessed_date != NULL)
|
||||
*accessed_date = stat_info.st_atime;
|
||||
// Creation date not supported
|
||||
*accessed_date = path_stat.st_atime;
|
||||
/* Creation date not supported */
|
||||
if (creation_date != NULL)
|
||||
*creation_date = 0;
|
||||
|
||||
@@ -198,8 +202,9 @@ int32_t mz_os_set_file_date(const char *path, time_t modified_date, time_t acces
|
||||
|
||||
ut.actime = accessed_date;
|
||||
ut.modtime = modified_date;
|
||||
// Creation date not supported
|
||||
(void)creation_date;
|
||||
|
||||
/* Creation date not supported */
|
||||
MZ_UNUSED(creation_date);
|
||||
|
||||
if (utime(path, &ut) != 0)
|
||||
return MZ_INTERNAL_ERROR;
|
||||
@@ -209,13 +214,13 @@ int32_t mz_os_set_file_date(const char *path, time_t modified_date, time_t acces
|
||||
|
||||
int32_t mz_os_get_file_attribs(const char *path, uint32_t *attributes)
|
||||
{
|
||||
struct stat stat_info;
|
||||
struct stat path_stat;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
memset(&stat_info, 0, sizeof(stat_info));
|
||||
if (stat(path, &stat_info) == -1)
|
||||
memset(&path_stat, 0, sizeof(path_stat));
|
||||
if (stat(path, &path_stat) == -1)
|
||||
err = MZ_INTERNAL_ERROR;
|
||||
*attributes = stat_info.st_mode;
|
||||
*attributes = path_stat.st_mode;
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -265,9 +270,12 @@ int32_t mz_os_close_dir(DIR *dir)
|
||||
int32_t mz_os_is_dir(const char *path)
|
||||
{
|
||||
struct stat path_stat;
|
||||
|
||||
memset(&path_stat, 0, sizeof(path_stat));
|
||||
stat(path, &path_stat);
|
||||
if (S_ISDIR(path_stat.st_mode))
|
||||
return MZ_OK;
|
||||
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
|
||||
+18
-19
@@ -1,28 +1,21 @@
|
||||
/* mz_os_win32.c -- System functions for Windows
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <direct.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(MZ_WINRT_API)))
|
||||
@@ -51,8 +44,10 @@ wchar_t *mz_os_unicode_string_create(const char *string, int32_t encoding)
|
||||
if (string_wide_size == 0)
|
||||
return NULL;
|
||||
string_wide = (wchar_t *)MZ_ALLOC((string_wide_size + 1) * sizeof(wchar_t));
|
||||
memset(string_wide, 0, sizeof(wchar_t) * (string_wide_size + 1));
|
||||
if (string_wide == NULL)
|
||||
return NULL;
|
||||
|
||||
memset(string_wide, 0, sizeof(wchar_t) * (string_wide_size + 1));
|
||||
MultiByteToWideChar(encoding, 0, string, -1, string_wide, string_wide_size);
|
||||
|
||||
return string_wide;
|
||||
@@ -82,7 +77,7 @@ uint8_t *mz_os_utf8_string_create(const char *string, int32_t encoding)
|
||||
if (string_utf8)
|
||||
{
|
||||
memset(string_utf8, 0, string_utf8_size + 1);
|
||||
WideCharToMultiByte(CP_UTF8, 0, string_wide, -1, string_utf8, string_utf8_size, NULL, NULL);
|
||||
WideCharToMultiByte(CP_UTF8, 0, string_wide, -1, (char *)string_utf8, string_utf8_size, NULL, NULL);
|
||||
}
|
||||
|
||||
mz_os_unicode_string_delete(&string_wide);
|
||||
@@ -352,7 +347,7 @@ int32_t mz_os_set_file_attribs(const char *path, uint32_t attributes)
|
||||
int32_t mz_os_make_dir(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (path == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
@@ -360,13 +355,15 @@ int32_t mz_os_make_dir(const char *path)
|
||||
if (path_wide == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
err = _wmkdir(path_wide);
|
||||
if (CreateDirectoryW(path_wide, NULL) == 0)
|
||||
{
|
||||
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
err = MZ_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
if (err != 0 && errno != EEXIST)
|
||||
return MZ_INTERNAL_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
DIR *mz_os_open_dir(const char *path)
|
||||
@@ -396,6 +393,8 @@ DIR *mz_os_open_dir(const char *path)
|
||||
return NULL;
|
||||
|
||||
dir_int = (DIR_int *)MZ_ALLOC(sizeof(DIR_int));
|
||||
if (dir_int == NULL)
|
||||
return NULL;
|
||||
dir_int->find_handle = handle;
|
||||
dir_int->end = 0;
|
||||
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
/* mz_strm.c -- Stream interface
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_STREAM_FIND_SIZE (1024)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream *strm = (mz_stream *)stream;
|
||||
@@ -135,7 +135,7 @@ static int32_t mz_stream_write_value(void *stream, uint64_t value, int32_t len)
|
||||
|
||||
if (value != 0)
|
||||
{
|
||||
// Data overflow - hack for ZIP64 (X Roche)
|
||||
/* Data overflow - hack for ZIP64 (X Roche) */
|
||||
for (n = 0; n < len; n += 1)
|
||||
buf[n] = 0xff;
|
||||
}
|
||||
@@ -171,20 +171,13 @@ int32_t mz_stream_write_uint64(void *stream, uint64_t value)
|
||||
return mz_stream_write_value(stream, value, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
int32_t mz_stream_write_chars(void *stream, const char *value, uint8_t null_terminate)
|
||||
{
|
||||
int32_t len = (int32_t)strlen(value);
|
||||
if (null_terminate)
|
||||
len += 1;
|
||||
return mz_stream_write(stream, value, len);
|
||||
}
|
||||
|
||||
int32_t mz_stream_copy(void *target, void *source, int32_t len)
|
||||
{
|
||||
return mz_stream_copy_stream(target, NULL, source, NULL, len);
|
||||
}
|
||||
|
||||
int32_t mz_stream_copy_stream(void *target, mz_stream_write_cb write_cb, void *source, mz_stream_read_cb read_cb, int32_t len)
|
||||
int32_t mz_stream_copy_stream(void *target, mz_stream_write_cb write_cb, void *source,
|
||||
mz_stream_read_cb read_cb, int32_t len)
|
||||
{
|
||||
uint8_t buf[16384];
|
||||
int32_t bytes_to_copy = 0;
|
||||
@@ -230,9 +223,142 @@ int32_t mz_stream_seek(void *stream, int64_t offset, int32_t origin)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (mz_stream_is_open(stream) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
if (origin == MZ_SEEK_SET && offset < 0)
|
||||
return MZ_SEEK_ERROR;
|
||||
return strm->vtbl->seek(strm, offset, origin);
|
||||
}
|
||||
|
||||
int32_t mz_stream_find(void *stream, const void *find, int32_t find_size, int64_t max_seek, int64_t *position)
|
||||
{
|
||||
uint8_t buf[MZ_STREAM_FIND_SIZE];
|
||||
int32_t buf_pos = 0;
|
||||
int32_t read_size = sizeof(buf);
|
||||
int32_t read = 0;
|
||||
int64_t read_pos = 0;
|
||||
int64_t start_pos = 0;
|
||||
int64_t disk_pos = 0;
|
||||
int32_t i = 0;
|
||||
uint8_t first = 1;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (stream == NULL || find == NULL || position == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (find_size < 0 || find_size >= (int32_t)sizeof(buf))
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
*position = -1;
|
||||
|
||||
start_pos = mz_stream_tell(stream);
|
||||
|
||||
while (read_pos < max_seek)
|
||||
{
|
||||
if (read_size > (int32_t)(max_seek - read_pos - buf_pos))
|
||||
read_size = (int32_t)(max_seek - read_pos - buf_pos);
|
||||
|
||||
read = mz_stream_read(stream, buf + buf_pos, read_size);
|
||||
if ((read < 0) || (read + buf_pos < find_size))
|
||||
break;
|
||||
|
||||
for (i = 0; i <= read + buf_pos - find_size; i += 1)
|
||||
{
|
||||
if (memcmp(&buf[i], find, find_size) != 0)
|
||||
continue;
|
||||
|
||||
disk_pos = mz_stream_tell(stream);
|
||||
|
||||
/* Seek to position on disk where the data was found */
|
||||
err = mz_stream_seek(stream, disk_pos - ((int64_t)read + buf_pos - i), MZ_SEEK_SET);
|
||||
if (err != MZ_OK)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
*position = start_pos + read_pos + i;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
if (first)
|
||||
{
|
||||
read -= find_size;
|
||||
read_size -= find_size;
|
||||
buf_pos = find_size;
|
||||
first = 0;
|
||||
}
|
||||
|
||||
memmove(buf, buf + read, find_size);
|
||||
read_pos += read;
|
||||
}
|
||||
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_find_reverse(void *stream, const void *find, int32_t find_size, int64_t max_seek, int64_t *position)
|
||||
{
|
||||
uint8_t buf[MZ_STREAM_FIND_SIZE];
|
||||
int32_t buf_pos = 0;
|
||||
int32_t read_size = MZ_STREAM_FIND_SIZE;
|
||||
int64_t read_pos = 0;
|
||||
int32_t read = 0;
|
||||
int64_t start_pos = 0;
|
||||
int64_t disk_pos = 0;
|
||||
uint8_t first = 1;
|
||||
int32_t i = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (stream == NULL || find == NULL || position == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (find_size < 0 || find_size >= (int32_t)sizeof(buf))
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
*position = -1;
|
||||
|
||||
start_pos = mz_stream_tell(stream);
|
||||
|
||||
while (read_pos < max_seek)
|
||||
{
|
||||
if (read_size > (int32_t)(max_seek - read_pos))
|
||||
read_size = (int32_t)(max_seek - read_pos);
|
||||
|
||||
if (mz_stream_seek(stream, start_pos - (read_pos + read_size), MZ_SEEK_SET) != MZ_OK)
|
||||
break;
|
||||
read = mz_stream_read(stream, buf, read_size);
|
||||
if ((read < 0) || (read + buf_pos < find_size))
|
||||
break;
|
||||
if (read + buf_pos < MZ_STREAM_FIND_SIZE)
|
||||
memmove(buf + MZ_STREAM_FIND_SIZE - (read + buf_pos), buf, read);
|
||||
|
||||
for (i = find_size; i <= (read + buf_pos); i += 1)
|
||||
{
|
||||
if (memcmp(&buf[MZ_STREAM_FIND_SIZE - i], find, find_size) != 0)
|
||||
continue;
|
||||
|
||||
disk_pos = mz_stream_tell(stream);
|
||||
|
||||
/* Seek to position on disk where the data was found */
|
||||
err = mz_stream_seek(stream, disk_pos + buf_pos - i, MZ_SEEK_SET);
|
||||
if (err != MZ_OK)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
*position = start_pos - (read_pos - buf_pos + i);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
if (first)
|
||||
{
|
||||
read -= find_size;
|
||||
read_size -= find_size;
|
||||
buf_pos = find_size;
|
||||
first = 0;
|
||||
}
|
||||
|
||||
if (read == 0)
|
||||
break;
|
||||
|
||||
memmove(buf + read_size, buf, find_size);
|
||||
read_pos += read;
|
||||
}
|
||||
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_close(void *stream)
|
||||
{
|
||||
mz_stream *strm = (mz_stream *)stream;
|
||||
@@ -336,14 +462,17 @@ int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size)
|
||||
|
||||
if (raw->max_total_in > 0)
|
||||
{
|
||||
if ((raw->max_total_in - raw->total_in) < size)
|
||||
if ((int64_t)bytes_to_read > (raw->max_total_in - raw->total_in))
|
||||
bytes_to_read = (int32_t)(raw->max_total_in - raw->total_in);
|
||||
}
|
||||
|
||||
read = mz_stream_read(raw->stream.base, buf, bytes_to_read);
|
||||
|
||||
if (read > 0)
|
||||
{
|
||||
raw->total_in += read;
|
||||
raw->total_out += read;
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
@@ -351,9 +480,16 @@ int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size)
|
||||
int32_t mz_stream_raw_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
int32_t written = mz_stream_write(raw->stream.base, buf, size);
|
||||
int32_t written = 0;
|
||||
|
||||
written = mz_stream_write(raw->stream.base, buf, size);
|
||||
|
||||
if (written > 0)
|
||||
{
|
||||
raw->total_out += written;
|
||||
raw->total_in += written;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
@@ -372,7 +508,6 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_strm.h -- Stream interface
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,8 +12,6 @@
|
||||
#ifndef MZ_STREAM_H
|
||||
#define MZ_STREAM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -47,6 +45,9 @@ typedef void (*mz_stream_destroy_cb) (void **stream);
|
||||
typedef int32_t (*mz_stream_get_prop_int64_cb) (void *stream, int32_t prop, int64_t *value);
|
||||
typedef int32_t (*mz_stream_set_prop_int64_cb) (void *stream, int32_t prop, int64_t value);
|
||||
|
||||
typedef int32_t (*mz_stream_find_cb) (void *stream, const void *find, int32_t find_size,
|
||||
int64_t max_seek, int64_t *position);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_vtbl_s
|
||||
@@ -87,11 +88,12 @@ int32_t mz_stream_write_uint16(void *stream, uint16_t value);
|
||||
int32_t mz_stream_write_uint32(void *stream, uint32_t value);
|
||||
int32_t mz_stream_write_int64(void *stream, int64_t value);
|
||||
int32_t mz_stream_write_uint64(void *stream, uint64_t value);
|
||||
int32_t mz_stream_write_chars(void *stream, const char *value, uint8_t null_terminate);
|
||||
int32_t mz_stream_copy(void *target, void *source, int32_t len);
|
||||
int32_t mz_stream_copy_stream(void *target, mz_stream_write_cb write_cb, void *source, mz_stream_read_cb read_cb, int32_t len);
|
||||
int64_t mz_stream_tell(void *stream);
|
||||
int32_t mz_stream_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_find(void *stream, const void *find, int32_t find_size, int64_t max_seek, int64_t *position);
|
||||
int32_t mz_stream_find_reverse(void *stream, const void *find, int32_t find_size, int64_t max_seek, int64_t *position);
|
||||
int32_t mz_stream_close(void *stream);
|
||||
int32_t mz_stream_error(void *stream);
|
||||
|
||||
|
||||
+29
-33
@@ -1,36 +1,22 @@
|
||||
/* mz_strm_buf.c -- Stream for buffering reads/writes
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
This version of ioapi is designed to buffer IO.
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_buf.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if 0
|
||||
# define mz_stream_buffered_print(s,f,...) printf(f,__VA_ARGS__);
|
||||
#else
|
||||
# define mz_stream_buffered_print(s,f,...)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_buffered_vtbl = {
|
||||
mz_stream_buffered_open,
|
||||
mz_stream_buffered_is_open,
|
||||
@@ -66,6 +52,14 @@ typedef struct mz_stream_buffered_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if 0
|
||||
# define mz_stream_buffered_print printf
|
||||
#else
|
||||
# define mz_stream_buffered_print(fmt,...)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static int32_t mz_stream_buffered_reset(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
@@ -82,7 +76,7 @@ static int32_t mz_stream_buffered_reset(void *stream)
|
||||
int32_t mz_stream_buffered_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
mz_stream_buffered_print(buffered, "open [mode %d]\n", mode);
|
||||
mz_stream_buffered_print("Buffered - Open (mode %"PRId32")\n", mode);
|
||||
mz_stream_buffered_reset(buffered);
|
||||
return mz_stream_open(buffered->stream.base, path, mode);
|
||||
}
|
||||
@@ -113,7 +107,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("Buffered - Write flush (%"PRId32":%"PRId32" len %"PRId32")\n",
|
||||
bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
|
||||
|
||||
total_bytes_written += bytes_written;
|
||||
@@ -137,11 +131,11 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
|
||||
int32_t bytes_left_to_read = size;
|
||||
int32_t bytes_read = 0;
|
||||
|
||||
mz_stream_buffered_print(stream, "read [size %ld pos %lld]\n", size, buffered->position);
|
||||
mz_stream_buffered_print("Buffered - Read (size %"PRId32" pos %"PRId64")\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("Buffered - Switch from write to read, not yet supported (pos %"PRId64")\n",
|
||||
buffered->position);
|
||||
}
|
||||
|
||||
@@ -164,7 +158,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("Buffered - Filled (read %"PRId32"/%"PRId32" buf %"PRId32":%"PRId32" pos %"PRId64")\n",
|
||||
bytes_read, bytes_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
|
||||
|
||||
if (bytes_read == 0)
|
||||
@@ -185,7 +179,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("Buffered - Emptied (copied %"PRId32" remaining %"PRId32" buf %"PRId32":%"PRId32" pos %"PRId64")\n",
|
||||
bytes_to_copy, bytes_left_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
|
||||
}
|
||||
}
|
||||
@@ -204,7 +198,7 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
|
||||
mz_stream_buffered_print(stream, "write [size %ld len %d pos %lld]\n",
|
||||
mz_stream_buffered_print("Buffered - Write (size %"PRId32" len %"PRId32" pos %"PRId64")\n",
|
||||
size, buffered->writebuf_len, buffered->position);
|
||||
|
||||
if (buffered->readbuf_len > 0)
|
||||
@@ -215,7 +209,7 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
buffered->readbuf_len = 0;
|
||||
buffered->readbuf_pos = 0;
|
||||
|
||||
mz_stream_buffered_print(stream, "switch from read to write [%lld]\n", buffered->position);
|
||||
mz_stream_buffered_print("Buffered - Switch from read to write (pos %"PRId64")\n", buffered->position);
|
||||
|
||||
err = mz_stream_seek(buffered->stream.base, buffered->position, MZ_SEEK_SET);
|
||||
if (err != MZ_OK)
|
||||
@@ -242,9 +236,10 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(buffered->writebuf + buffered->writebuf_pos, (const 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("Buffered - Write copy (remaining %"PRId32" write %"PRId32":%"PRId32" len %"PRId32")\n",
|
||||
bytes_to_copy, bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
|
||||
|
||||
bytes_left_to_write -= bytes_to_copy;
|
||||
@@ -265,8 +260,8 @@ int64_t mz_stream_buffered_tell(void *stream)
|
||||
|
||||
buffered->position = position;
|
||||
|
||||
mz_stream_buffered_print(stream, "tell [pos %llu readpos %d writepos %d err %d]\n",
|
||||
buffered->position, buffered->readbuf_pos, buffered->writebuf_pos, errno);
|
||||
mz_stream_buffered_print("Buffered - Tell (pos %"PRId64" readpos %"PRId32" writepos %"PRId32")\n",
|
||||
buffered->position, buffered->readbuf_pos, buffered->writebuf_pos);
|
||||
|
||||
if (buffered->readbuf_len > 0)
|
||||
position -= ((int64_t)buffered->readbuf_len - buffered->readbuf_pos);
|
||||
@@ -281,7 +276,8 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
int32_t bytes_flushed = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
mz_stream_buffered_print(stream, "seek [origin %d offset %llu pos %lld]\n", origin, offset, buffered->position);
|
||||
mz_stream_buffered_print("Buffered - Seek (origin %"PRId32" offset %"PRId64" pos %"PRId64")\n",
|
||||
origin, offset, buffered->position);
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
@@ -329,7 +325,7 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
buffered->writebuf_pos += (uint32_t)offset;
|
||||
return MZ_OK;
|
||||
}
|
||||
//offset -= (buffered->writebuf_len - buffered->writebuf_pos);
|
||||
/* offset -= (buffered->writebuf_len - buffered->writebuf_pos); */
|
||||
}
|
||||
|
||||
err = mz_stream_buffered_flush(stream, &bytes_flushed);
|
||||
@@ -362,17 +358,17 @@ 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 [flushed %d]\n", bytes_flushed);
|
||||
mz_stream_buffered_print("Buffered - Close (flushed %"PRId32")\n", bytes_flushed);
|
||||
|
||||
if (buffered->readbuf_hits + buffered->readbuf_misses > 0)
|
||||
{
|
||||
mz_stream_buffered_print(stream, "read efficiency %.02f%%\n",
|
||||
mz_stream_buffered_print("Buffered - Read efficiency %.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 efficiency %.02f%%\n",
|
||||
mz_stream_buffered_print("Buffered - Write efficiency %.02f%%\n",
|
||||
(buffered->writebuf_hits / ((float)buffered->writebuf_hits + buffered->writebuf_misses)) * 100);
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -1,10 +1,10 @@
|
||||
/* mz_strm_buf.h -- Stream for buffering reads/writes
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
This version of ioapi is designed to buffer IO.
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -14,8 +14,6 @@
|
||||
#ifndef MZ_STREAM_BUFFERED_H
|
||||
#define MZ_STREAM_BUFFERED_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+12
-11
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_bzip.c -- Stream for bzip inflate/deflate
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as bzip.
|
||||
@@ -10,16 +10,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "bzlib.h"
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_bzip.h"
|
||||
|
||||
#include "bzlib.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_bzip_vtbl = {
|
||||
@@ -116,6 +112,9 @@ int32_t mz_stream_bzip_is_open(void *stream)
|
||||
int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
MZ_UNUSED(stream);
|
||||
MZ_UNUSED(buf);
|
||||
MZ_UNUSED(size);
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
@@ -127,7 +126,7 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
int32_t total_out = 0;
|
||||
int32_t in_bytes = 0;
|
||||
int32_t out_bytes = 0;
|
||||
int32_t bytes_to_read = 0;
|
||||
int32_t bytes_to_read = sizeof(bzip->buffer);
|
||||
int32_t read = 0;
|
||||
int32_t err = BZ_OK;
|
||||
|
||||
@@ -142,10 +141,9 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
if (bzip->bzstream.avail_in == 0)
|
||||
{
|
||||
bytes_to_read = sizeof(bzip->buffer);
|
||||
if (bzip->max_total_in > 0)
|
||||
{
|
||||
if ((bzip->max_total_in - bzip->total_in) < (int64_t)sizeof(bzip->buffer))
|
||||
if ((int64_t)bytes_to_read > (bzip->max_total_in - bzip->total_in))
|
||||
bytes_to_read = (int32_t)(bzip->max_total_in - bzip->total_in);
|
||||
}
|
||||
|
||||
@@ -199,6 +197,7 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef MZ_ZIP_NO_COMPRESSION
|
||||
static int32_t mz_stream_bzip_flush(void *stream)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
@@ -254,6 +253,7 @@ static int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t mz_stream_bzip_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
@@ -262,6 +262,7 @@ int32_t mz_stream_bzip_write(void *stream, const void *buf, int32_t size)
|
||||
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(bzip);
|
||||
MZ_UNUSED(buf);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
bzip->bzstream.next_in = (char *)(intptr_t)buf;
|
||||
|
||||
+2
-4
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_bzip.h -- Stream for bzip inflate/deflate
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,8 +12,6 @@
|
||||
#ifndef MZ_STREAM_BZIP_H
|
||||
#define MZ_STREAM_BZIP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
-208
@@ -1,208 +0,0 @@
|
||||
/* mz_strm_crc32.c -- Stream for CRC32 hashing
|
||||
Version 2.7.2, November 2, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_crc32.h"
|
||||
#ifdef HAVE_LZMA
|
||||
#include "mz_strm_lzma.h"
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
#include "mz_strm_zlib.h"
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_crc32_vtbl = {
|
||||
mz_stream_crc32_open,
|
||||
mz_stream_crc32_is_open,
|
||||
mz_stream_crc32_read,
|
||||
mz_stream_crc32_write,
|
||||
mz_stream_crc32_tell,
|
||||
mz_stream_crc32_seek,
|
||||
mz_stream_crc32_close,
|
||||
mz_stream_crc32_error,
|
||||
mz_stream_crc32_create,
|
||||
mz_stream_crc32_delete,
|
||||
mz_stream_crc32_get_prop_int64,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_crc32_s {
|
||||
mz_stream stream;
|
||||
int8_t initialized;
|
||||
int64_t value;
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
mz_stream_crc32_update
|
||||
update;
|
||||
} mz_stream_crc32;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_is_open(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
if (crc32->initialized != 1)
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
|
||||
int32_t read = 0;
|
||||
read = mz_stream_read(crc32x->stream.base, buf, size);
|
||||
if (read > 0)
|
||||
{
|
||||
crc32x->value = crc32x->update(crc32x->value, buf, read);
|
||||
crc32x->total_in += read;
|
||||
}
|
||||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
|
||||
int32_t written = 0;
|
||||
written = mz_stream_write(crc32x->stream.base, buf, size);
|
||||
if (written > 0)
|
||||
{
|
||||
crc32x->value = crc32x->update(crc32x->value, buf, written);
|
||||
crc32x->total_out += written;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_crc32_tell(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return mz_stream_tell(crc32->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->value = 0;
|
||||
return mz_stream_seek(crc32->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_close(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->initialized = 0;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_error(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return mz_stream_error(crc32->stream.base);
|
||||
}
|
||||
|
||||
uint32_t mz_stream_crc32_get_value(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return (uint32_t)crc32->value;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = crc32->total_in;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = crc32->total_out;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_crc32_create(void **stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = NULL;
|
||||
|
||||
crc32 = (mz_stream_crc32 *)MZ_ALLOC(sizeof(mz_stream_crc32));
|
||||
if (crc32 != NULL)
|
||||
{
|
||||
memset(crc32, 0, sizeof(mz_stream_crc32));
|
||||
crc32->stream.vtbl = &mz_stream_crc32_vtbl;
|
||||
#ifdef HAVE_ZLIB
|
||||
crc32->update =
|
||||
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update();
|
||||
#elif defined(HAVE_LZMA)
|
||||
crc32->update =
|
||||
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update();
|
||||
#else
|
||||
#error ZLIB or LZMA required for CRC32
|
||||
#endif
|
||||
}
|
||||
|
||||
if (stream != NULL)
|
||||
*stream = crc32;
|
||||
|
||||
return crc32;
|
||||
}
|
||||
|
||||
void mz_stream_crc32_delete(void **stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = NULL;
|
||||
if (stream == NULL)
|
||||
return;
|
||||
crc32 = (mz_stream_crc32 *)*stream;
|
||||
if (crc32 != NULL)
|
||||
MZ_FREE(crc32);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_crc32_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_crc32_vtbl;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_get_update_func(mz_stream_crc32_update *update)
|
||||
{
|
||||
if (update == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
#ifdef HAVE_ZLIB
|
||||
*update =
|
||||
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update();
|
||||
#elif defined(HAVE_LZMA)
|
||||
*update =
|
||||
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update();
|
||||
#else
|
||||
#error ZLIB or LZMA required for CRC32
|
||||
#endif
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/* mz_strm_crc32.h -- Stream for CRC32 hashing
|
||||
Version 2.7.2, November 2, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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_CRC32_H
|
||||
#define MZ_STREAM_CRC32_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef int64_t (*mz_stream_crc32_update)(int64_t value, const void *buf, int32_t size);
|
||||
|
||||
int32_t mz_stream_crc32_open(void *stream, const char *filename, int32_t mode);
|
||||
int32_t mz_stream_crc32_is_open(void *stream);
|
||||
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size);
|
||||
int64_t mz_stream_crc32_tell(void *stream);
|
||||
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_crc32_close(void *stream);
|
||||
int32_t mz_stream_crc32_error(void *stream);
|
||||
|
||||
uint32_t mz_stream_crc32_get_value(void *stream);
|
||||
|
||||
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
|
||||
void* mz_stream_crc32_create(void **stream);
|
||||
void mz_stream_crc32_delete(void **stream);
|
||||
|
||||
void* mz_stream_crc32_get_interface(void);
|
||||
int32_t mz_stream_crc32_get_update_func(mz_stream_crc32_update *update);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+16
-37
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_libcomp.c -- Stream for apple compression
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -10,18 +10,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <compression.h>
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_libcomp.h"
|
||||
|
||||
#include <compression.h>
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_libcomp_vtbl = {
|
||||
@@ -114,6 +108,9 @@ int32_t mz_stream_libcomp_is_open(void *stream)
|
||||
int32_t mz_stream_libcomp_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
MZ_UNUSED(stream);
|
||||
MZ_UNUSED(buf);
|
||||
MZ_UNUSED(size);
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_libcomp *libcomp = (mz_stream_libcomp *)stream;
|
||||
@@ -125,10 +122,10 @@ int32_t mz_stream_libcomp_read(void *stream, void *buf, int32_t size)
|
||||
int32_t total_out = 0;
|
||||
int32_t in_bytes = 0;
|
||||
int32_t out_bytes = 0;
|
||||
int32_t bytes_to_read = 0;
|
||||
int32_t bytes_to_read = sizeof(libcomp->buffer);
|
||||
int32_t read = 0;
|
||||
int32_t err = Z_OK;
|
||||
|
||||
int32_t err = MZ_OK;
|
||||
int16_t flags = 0;
|
||||
|
||||
libcomp->cstream.dst_ptr = buf;
|
||||
libcomp->cstream.dst_size = (size_t)size;
|
||||
@@ -137,10 +134,9 @@ int32_t mz_stream_libcomp_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
if (libcomp->cstream.src_size == 0)
|
||||
{
|
||||
bytes_to_read = sizeof(libcomp->buffer);
|
||||
if (libcomp->max_total_in > 0)
|
||||
{
|
||||
if ((libcomp->max_total_in - libcomp->total_in) < (int64_t)sizeof(libcomp->buffer))
|
||||
if ((int64_t)bytes_to_read > (libcomp->max_total_in - libcomp->total_in))
|
||||
bytes_to_read = (int32_t)(libcomp->max_total_in - libcomp->total_in);
|
||||
}
|
||||
|
||||
@@ -149,8 +145,8 @@ int32_t mz_stream_libcomp_read(void *stream, void *buf, int32_t size)
|
||||
if (read < 0)
|
||||
return read;
|
||||
if (read == 0)
|
||||
break;
|
||||
|
||||
flags = COMPRESSION_STREAM_FINALIZE;
|
||||
|
||||
libcomp->cstream.src_ptr = libcomp->buffer;
|
||||
libcomp->cstream.src_size = (size_t)read;
|
||||
}
|
||||
@@ -158,7 +154,7 @@ int32_t mz_stream_libcomp_read(void *stream, void *buf, int32_t size)
|
||||
total_in_before = libcomp->cstream.src_size;
|
||||
total_out_before = libcomp->cstream.dst_size;
|
||||
|
||||
err = compression_stream_process(&libcomp->cstream, 0);
|
||||
err = compression_stream_process(&libcomp->cstream, flags);
|
||||
if (err == COMPRESSION_STATUS_ERROR)
|
||||
{
|
||||
libcomp->error = err;
|
||||
@@ -208,7 +204,7 @@ static int32_t mz_stream_libcomp_deflate(void *stream, int flush)
|
||||
uint64_t total_out_before = 0;
|
||||
uint64_t total_out_after = 0;
|
||||
uint32_t out_bytes = 0;
|
||||
int32_t err = Z_OK;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
|
||||
do
|
||||
@@ -310,7 +306,7 @@ int32_t mz_stream_libcomp_close(void *stream)
|
||||
|
||||
libcomp->initialized = 0;
|
||||
|
||||
if (libcomp->error != Z_OK)
|
||||
if (libcomp->error != MZ_OK)
|
||||
return MZ_CLOSE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -390,13 +386,6 @@ void mz_stream_libcomp_delete(void **stream)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// Define z_crc_t in zlib 1.2.5 and less
|
||||
#if (ZLIB_VERNUM < 0x1270)
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_zlib_vtbl = {
|
||||
mz_stream_libcomp_open,
|
||||
mz_stream_libcomp_is_open,
|
||||
@@ -432,13 +421,3 @@ void *mz_stream_zlib_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_zlib_vtbl;
|
||||
}
|
||||
|
||||
static int64_t mz_stream_zlib_crc32(int64_t value, const void *buf, int32_t size)
|
||||
{
|
||||
return (int64_t)crc32((z_crc_t)value, buf, (uint32_t)size);
|
||||
}
|
||||
|
||||
void *mz_stream_zlib_get_crc32_update(void)
|
||||
{
|
||||
return (void *)mz_stream_zlib_crc32;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_libcomp.h -- Stream for apple compression
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
|
||||
+16
-20
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_lzma.c -- Stream for lzma inflate/deflate
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as lzma.
|
||||
@@ -10,17 +10,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <lzma.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_lzma.h"
|
||||
|
||||
#include "lzma.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_LZMA_HEADER_SIZE (4)
|
||||
@@ -84,6 +79,8 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(filters);
|
||||
MZ_UNUSED(major);
|
||||
MZ_UNUSED(minor);
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma->lstream.next_out = lzma->buffer;
|
||||
@@ -112,6 +109,9 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
MZ_UNUSED(filters);
|
||||
MZ_UNUSED(major);
|
||||
MZ_UNUSED(minor);
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma->lstream.next_in = lzma->buffer;
|
||||
@@ -146,6 +146,9 @@ int32_t mz_stream_lzma_is_open(void *stream)
|
||||
int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
MZ_UNUSED(stream);
|
||||
MZ_UNUSED(buf);
|
||||
MZ_UNUSED(size);
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
@@ -172,7 +175,7 @@ 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) < (int64_t)sizeof(lzma->buffer))
|
||||
if ((int64_t)bytes_to_read > (lzma->max_total_in - lzma->total_in))
|
||||
bytes_to_read = (int32_t)(lzma->max_total_in - lzma->total_in);
|
||||
}
|
||||
|
||||
@@ -223,6 +226,7 @@ int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef MZ_ZIP_NO_COMPRESSION
|
||||
static int32_t mz_stream_lzma_flush(void *stream)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
@@ -273,6 +277,7 @@ static int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t mz_stream_lzma_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
@@ -281,6 +286,7 @@ int32_t mz_stream_lzma_write(void *stream, const void *buf, int32_t size)
|
||||
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(lzma);
|
||||
MZ_UNUSED(buf);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma->lstream.next_in = (uint8_t*)(intptr_t)buf;
|
||||
@@ -430,13 +436,3 @@ void *mz_stream_lzma_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_lzma_vtbl;
|
||||
}
|
||||
|
||||
static int64_t mz_stream_lzma_crc32(int64_t value, const void *buf, int32_t size)
|
||||
{
|
||||
return (int64_t)lzma_crc32(buf, (size_t)size, (uint32_t)value);
|
||||
}
|
||||
|
||||
void *mz_stream_lzma_get_crc32_update(void)
|
||||
{
|
||||
return (void *)mz_stream_lzma_crc32;
|
||||
}
|
||||
|
||||
+2
-5
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_lzma.h -- Stream for lzma inflate/deflate
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as lzma.
|
||||
@@ -12,8 +12,6 @@
|
||||
#ifndef MZ_STREAM_LZMA_H
|
||||
#define MZ_STREAM_LZMA_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -36,7 +34,6 @@ 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_update(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
+29
-17
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_mem.c -- Stream for memory access
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
This interface is designed to access memory rather than files.
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
Based on Unzip ioapi.c version 0.22, May 19th, 2003
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2003 Justin Fletcher
|
||||
Copyright (C) 1998-2003 Gilles Vollant
|
||||
@@ -18,9 +18,6 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_mem.h"
|
||||
@@ -47,16 +44,16 @@ static mz_stream_vtbl mz_stream_mem_vtbl = {
|
||||
typedef struct mz_stream_mem_s {
|
||||
mz_stream stream;
|
||||
int32_t mode;
|
||||
uint8_t *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
|
||||
int32_t grow_size; // Size to grow when full
|
||||
uint8_t *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 */
|
||||
int32_t grow_size; /* Size to grow when full */
|
||||
} mz_stream_mem;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static void mz_stream_mem_set_size(void *stream, int32_t size)
|
||||
static int32_t mz_stream_mem_set_size(void *stream, int32_t size)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
int32_t new_size = size;
|
||||
@@ -64,6 +61,9 @@ static void mz_stream_mem_set_size(void *stream, int32_t size)
|
||||
|
||||
|
||||
new_buf = (uint8_t *)MZ_ALLOC((uint32_t)new_size);
|
||||
if (new_buf == NULL)
|
||||
return MZ_BUF_ERROR;
|
||||
|
||||
if (mem->buffer)
|
||||
{
|
||||
memcpy(new_buf, mem->buffer, mem->size);
|
||||
@@ -72,11 +72,13 @@ static void mz_stream_mem_set_size(void *stream, int32_t size)
|
||||
|
||||
mem->buffer = new_buf;
|
||||
mem->size = new_size;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_mem_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
MZ_UNUSED(path);
|
||||
|
||||
@@ -85,11 +87,11 @@ int32_t mz_stream_mem_open(void *stream, const char *path, int32_t mode)
|
||||
mem->position = 0;
|
||||
|
||||
if (mem->mode & MZ_OPEN_MODE_CREATE)
|
||||
mz_stream_mem_set_size(stream, mem->grow_size);
|
||||
err = mz_stream_mem_set_size(stream, mem->grow_size);
|
||||
else
|
||||
mem->limit = mem->size;
|
||||
|
||||
return MZ_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_stream_mem_is_open(void *stream)
|
||||
@@ -120,6 +122,7 @@ int32_t mz_stream_mem_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
int32_t new_size = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (size == 0)
|
||||
return size;
|
||||
@@ -134,7 +137,9 @@ int32_t mz_stream_mem_write(void *stream, const void *buf, int32_t size)
|
||||
else
|
||||
new_size += size;
|
||||
|
||||
mz_stream_mem_set_size(stream, new_size);
|
||||
err = mz_stream_mem_set_size(stream, new_size);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -161,6 +166,7 @@ int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
int64_t new_pos = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
@@ -182,7 +188,13 @@ int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin)
|
||||
if ((mem->mode & MZ_OPEN_MODE_CREATE) == 0)
|
||||
return MZ_SEEK_ERROR;
|
||||
|
||||
mz_stream_mem_set_size(stream, (int32_t)new_pos);
|
||||
err = mz_stream_mem_set_size(stream, (int32_t)new_pos);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
}
|
||||
else if (new_pos < 0)
|
||||
{
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
mem->position = (int32_t)new_pos;
|
||||
@@ -193,7 +205,7 @@ int32_t mz_stream_mem_close(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
// We never return errors
|
||||
/* We never return errors */
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@@ -201,7 +213,7 @@ int32_t mz_stream_mem_error(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
// We never return errors
|
||||
/* We never return errors */
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_mem.h -- Stream for memory access
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,8 +12,6 @@
|
||||
#ifndef MZ_STREAM_MEM_H
|
||||
#define MZ_STREAM_MEM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+2
-4
@@ -1,8 +1,8 @@
|
||||
/* mz_sstrm_os.h -- Stream for filesystem access
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,8 +12,6 @@
|
||||
#ifndef MZ_STREAM_OS_H
|
||||
#define MZ_STREAM_OS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+20
-24
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_posix.c -- Stream for filesystem access for posix/linux
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
@@ -14,38 +14,31 @@
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
#include <stdio.h> /* fopen, fread.. */
|
||||
#include <errno.h>
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(MZ_FILE32_API)
|
||||
# define fopen64 fopen
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
#else
|
||||
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
|
||||
defined(__OpenBSD__) || defined(__APPLE__) || defined(__ANDROID__)
|
||||
# define fopen64 fopen
|
||||
#define fopen64 fopen
|
||||
#ifndef MZ_FILE32_API
|
||||
# ifndef NO_FSEEKO
|
||||
# define ftello64 ftello
|
||||
# define fseeko64 fseeko
|
||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1400)
|
||||
# define ftello64 _ftelli64
|
||||
# define fseeko64 _fseeki64
|
||||
# endif
|
||||
# ifdef _MSC_VER
|
||||
# define fopen64 fopen
|
||||
# if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
|
||||
# define ftello64 _ftelli64
|
||||
# define fseeko64 _fseeki64
|
||||
# else /* old MSC */
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#ifndef ftello64
|
||||
# define ftello64 ftell
|
||||
#endif
|
||||
#ifndef fseeko64
|
||||
# define fseeko64 fseek
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -100,6 +93,9 @@ int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
return MZ_OPEN_ERROR;
|
||||
}
|
||||
|
||||
if (mode & MZ_OPEN_MODE_APPEND)
|
||||
return mz_stream_os_seek(stream, 0, MZ_SEEK_END);
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
|
||||
+24
-7
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_win32.c -- Stream for filesystem access for windows
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
@@ -14,15 +14,14 @@
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifndef INVALID_HANDLE_VALUE
|
||||
@@ -67,6 +66,14 @@ typedef struct mz_stream_win32_s
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if 0
|
||||
# define mz_stream_os_print printf
|
||||
#else
|
||||
# define mz_stream_os_print(fmt,...)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
@@ -75,13 +82,12 @@ int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
uint32_t share_mode = FILE_SHARE_READ;
|
||||
uint32_t flags_attribs = FILE_ATTRIBUTE_NORMAL;
|
||||
wchar_t *path_wide = NULL;
|
||||
uint32_t path_wide_size = 0;
|
||||
|
||||
|
||||
if (path == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
// Some use cases require write sharing as well
|
||||
/* Some use cases require write sharing as well */
|
||||
share_mode |= FILE_SHARE_WRITE;
|
||||
|
||||
if ((mode & MZ_OPEN_MODE_READWRITE) == MZ_OPEN_MODE_READ)
|
||||
@@ -104,6 +110,8 @@ int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
return MZ_PARAM_ERROR;
|
||||
}
|
||||
|
||||
mz_stream_os_print("Win32 - Open - %s (mode %"PRId32")\n", path);
|
||||
|
||||
path_wide = mz_os_unicode_string_create(path, MZ_ENCODING_UTF8);
|
||||
if (path_wide == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
@@ -153,6 +161,8 @@ int32_t mz_stream_os_read(void *stream, void *buf, int32_t size)
|
||||
win32->error = 0;
|
||||
}
|
||||
|
||||
mz_stream_os_print("Win32 - Read - %"PRId32"\n", read);
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
@@ -171,6 +181,8 @@ int32_t mz_stream_os_write(void *stream, const void *buf, int32_t size)
|
||||
win32->error = 0;
|
||||
}
|
||||
|
||||
mz_stream_os_print("Win32 - Write - %"PRId32"\n", written);
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
@@ -212,6 +224,8 @@ int64_t mz_stream_os_tell(void *stream)
|
||||
if (mz_stream_os_seekinternal(win32->handle, large_pos, &large_pos, FILE_CURRENT) != MZ_OK)
|
||||
win32->error = GetLastError();
|
||||
|
||||
mz_stream_os_print("Win32 - Tell - %"PRId64"\n", large_pos.QuadPart);
|
||||
|
||||
return large_pos.QuadPart;
|
||||
}
|
||||
|
||||
@@ -241,6 +255,8 @@ int32_t mz_stream_os_seek(void *stream, int64_t offset, int32_t origin)
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
mz_stream_os_print("Win32 - Seek - %"PRId64" (origin %"PRId32")\n", offset, origin);
|
||||
|
||||
large_pos.QuadPart = offset;
|
||||
|
||||
err = mz_stream_os_seekinternal(win32->handle, large_pos, NULL, move_method);
|
||||
@@ -259,6 +275,7 @@ int32_t mz_stream_os_close(void *stream)
|
||||
|
||||
if (win32->handle != NULL)
|
||||
CloseHandle(win32->handle);
|
||||
mz_stream_os_print("Win32 - Close\n");
|
||||
win32->handle = NULL;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
+71
-46
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_pkcrypt.c -- Code for traditional PKWARE encryption
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Modifications for Info-ZIP crypting
|
||||
@@ -23,22 +23,13 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_crypt.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_crc32.h"
|
||||
#include "mz_strm_pkcrypt.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define RAND_HEAD_LEN (12)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_pkcrypt_vtbl = {
|
||||
mz_stream_pkcrypt_open,
|
||||
mz_stream_pkcrypt_is_open,
|
||||
@@ -51,7 +42,7 @@ static mz_stream_vtbl mz_stream_pkcrypt_vtbl = {
|
||||
mz_stream_pkcrypt_create,
|
||||
mz_stream_pkcrypt_delete,
|
||||
mz_stream_pkcrypt_get_prop_int64,
|
||||
NULL
|
||||
mz_stream_pkcrypt_set_prop_int64
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -60,15 +51,14 @@ typedef struct mz_stream_pkcrypt_s {
|
||||
mz_stream stream;
|
||||
int32_t error;
|
||||
int16_t initialized;
|
||||
uint8_t buffer[INT16_MAX];
|
||||
uint8_t buffer[UINT16_MAX];
|
||||
int64_t total_in;
|
||||
int64_t max_total_in;
|
||||
int64_t total_out;
|
||||
uint32_t keys[3]; // keys defining the pseudo-random sequence
|
||||
uint32_t keys[3]; /* keys defining the pseudo-random sequence */
|
||||
uint8_t verify1;
|
||||
uint8_t verify2;
|
||||
const char *password;
|
||||
mz_stream_crc32_update
|
||||
crc32_update;
|
||||
} mz_stream_pkcrypt;
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -87,9 +77,9 @@ static uint8_t mz_stream_pkcrypt_decrypt_byte(void *stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
|
||||
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.
|
||||
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 = pkcrypt->keys[2] | 2;
|
||||
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
@@ -100,14 +90,14 @@ static uint8_t mz_stream_pkcrypt_update_keys(void *stream, uint8_t c)
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
uint8_t buf = c;
|
||||
|
||||
pkcrypt->keys[0] = (uint32_t)~pkcrypt->crc32_update(~pkcrypt->keys[0], &buf, 1);
|
||||
pkcrypt->keys[0] = (uint32_t)~mz_crypt_crc32_update(~pkcrypt->keys[0], &buf, 1);
|
||||
|
||||
pkcrypt->keys[1] += pkcrypt->keys[0] & 0xff;
|
||||
pkcrypt->keys[1] *= 134775813L;
|
||||
pkcrypt->keys[1] += 1;
|
||||
|
||||
buf = (uint8_t)(pkcrypt->keys[1] >> 24);
|
||||
pkcrypt->keys[2] = (uint32_t)~pkcrypt->crc32_update(~pkcrypt->keys[2], &buf, 1);
|
||||
pkcrypt->keys[2] = (uint32_t)~mz_crypt_crc32_update(~pkcrypt->keys[2], &buf, 1);
|
||||
|
||||
return (uint8_t)c;
|
||||
}
|
||||
@@ -136,7 +126,7 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
int16_t i = 0;
|
||||
uint8_t verify1 = 0;
|
||||
uint8_t verify2 = 0;
|
||||
uint8_t header[RAND_HEAD_LEN];
|
||||
uint8_t header[MZ_PKCRYPT_HEADER_SIZE];
|
||||
const char *password = path;
|
||||
|
||||
pkcrypt->total_in = 0;
|
||||
@@ -151,9 +141,6 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
if (password == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (mz_stream_crc32_get_update_func(&pkcrypt->crc32_update) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
mz_stream_pkcrypt_init_keys(stream, password);
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
@@ -164,20 +151,20 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
// First generate RAND_HEAD_LEN - 2 random bytes.
|
||||
mz_crypt_rand(header, RAND_HEAD_LEN - 2);
|
||||
/* First generate RAND_HEAD_LEN - 2 random bytes. */
|
||||
mz_crypt_rand(header, MZ_PKCRYPT_HEADER_SIZE - 2);
|
||||
|
||||
// Encrypt random header (last two bytes is high word of crc)
|
||||
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
|
||||
/* Encrypt random header (last two bytes is high word of crc) */
|
||||
for (i = 0; i < MZ_PKCRYPT_HEADER_SIZE - 2; i++)
|
||||
header[i] = mz_stream_pkcrypt_encode(stream, header[i], t);
|
||||
|
||||
header[i++] = mz_stream_pkcrypt_encode(stream, pkcrypt->verify1, t);
|
||||
header[i++] = mz_stream_pkcrypt_encode(stream, pkcrypt->verify2, t);
|
||||
|
||||
if (mz_stream_write(pkcrypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
|
||||
if (mz_stream_write(pkcrypt->stream.base, header, sizeof(header)) != sizeof(header))
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
pkcrypt->total_out += RAND_HEAD_LEN;
|
||||
pkcrypt->total_out += MZ_PKCRYPT_HEADER_SIZE;
|
||||
#endif
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
@@ -190,21 +177,21 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
if (mz_stream_read(pkcrypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
|
||||
if (mz_stream_read(pkcrypt->stream.base, header, sizeof(header)) != sizeof(header))
|
||||
return MZ_READ_ERROR;
|
||||
|
||||
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
|
||||
for (i = 0; i < MZ_PKCRYPT_HEADER_SIZE - 2; i++)
|
||||
header[i] = mz_stream_pkcrypt_decode(stream, header[i]);
|
||||
|
||||
verify1 = mz_stream_pkcrypt_decode(stream, header[i++]);
|
||||
verify2 = mz_stream_pkcrypt_decode(stream, header[i++]);
|
||||
|
||||
// Older versions used 2 byte check, newer versions use 1 byte check.
|
||||
/* Older versions used 2 byte check, newer versions use 1 byte check. */
|
||||
MZ_UNUSED(verify1);
|
||||
if ((verify2 != 0) && (verify2 != pkcrypt->verify2))
|
||||
return MZ_PASSWORD_ERROR;
|
||||
|
||||
pkcrypt->total_in += RAND_HEAD_LEN;
|
||||
pkcrypt->total_in += MZ_PKCRYPT_HEADER_SIZE;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -224,15 +211,22 @@ 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 bytes_to_read = size;
|
||||
int32_t read = 0;
|
||||
int32_t i = 0;
|
||||
|
||||
read = mz_stream_read(pkcrypt->stream.base, buf, size);
|
||||
|
||||
if ((int64_t)bytes_to_read > (pkcrypt->max_total_in - pkcrypt->total_in))
|
||||
bytes_to_read = (int32_t)(pkcrypt->max_total_in - pkcrypt->total_in);
|
||||
|
||||
read = mz_stream_read(pkcrypt->stream.base, buf, bytes_to_read);
|
||||
|
||||
for (i = 0; i < read; i++)
|
||||
buf_ptr[i] = mz_stream_pkcrypt_decode(stream, buf_ptr[i]);
|
||||
|
||||
pkcrypt->total_in += read;
|
||||
if (read > 0)
|
||||
pkcrypt->total_in += read;
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
@@ -240,22 +234,36 @@ 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 bytes_to_write = sizeof(pkcrypt->buffer);
|
||||
int32_t total_written = 0;
|
||||
int32_t written = 0;
|
||||
int32_t i = 0;
|
||||
uint16_t t = 0;
|
||||
|
||||
if (size > (int32_t)sizeof(pkcrypt->buffer))
|
||||
return MZ_BUF_ERROR;
|
||||
if (size < 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
pkcrypt->buffer[i] = mz_stream_pkcrypt_encode(stream, buf_ptr[i], t);
|
||||
do
|
||||
{
|
||||
if (bytes_to_write > (size - total_written))
|
||||
bytes_to_write = (size - total_written);
|
||||
|
||||
written = mz_stream_write(pkcrypt->stream.base, pkcrypt->buffer, size);
|
||||
for (i = 0; i < bytes_to_write; i += 1)
|
||||
{
|
||||
pkcrypt->buffer[i] = mz_stream_pkcrypt_encode(stream, *buf_ptr, t);
|
||||
buf_ptr += 1;
|
||||
}
|
||||
|
||||
if (written > 0)
|
||||
pkcrypt->total_out += written;
|
||||
written = mz_stream_write(pkcrypt->stream.base, pkcrypt->buffer, bytes_to_write);
|
||||
if (written < 0)
|
||||
return written;
|
||||
|
||||
return written;
|
||||
total_written += written;
|
||||
}
|
||||
while (total_written < size && written > 0);
|
||||
|
||||
pkcrypt->total_out += total_written;
|
||||
return total_written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_pkcrypt_tell(void *stream)
|
||||
@@ -314,8 +322,11 @@ int32_t mz_stream_pkcrypt_get_prop_int64(void *stream, int32_t prop, int64_t *va
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = pkcrypt->total_out;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
*value = pkcrypt->max_total_in;
|
||||
break;
|
||||
case MZ_STREAM_PROP_HEADER_SIZE:
|
||||
*value = RAND_HEAD_LEN;
|
||||
*value = MZ_PKCRYPT_HEADER_SIZE;
|
||||
break;
|
||||
case MZ_STREAM_PROP_FOOTER_SIZE:
|
||||
*value = 0;
|
||||
@@ -326,6 +337,20 @@ int32_t mz_stream_pkcrypt_get_prop_int64(void *stream, int32_t prop, int64_t *va
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_pkcrypt_set_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_MAX:
|
||||
pkcrypt->max_total_in = value;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_pkcrypt_create(void **stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = NULL;
|
||||
|
||||
+3
-4
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_pkcrypt.h -- Code for traditional PKWARE encryption
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,8 +12,6 @@
|
||||
#ifndef MZ_STREAM_PKCRYPT_H
|
||||
#define MZ_STREAM_PKCRYPT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -33,6 +31,7 @@ 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);
|
||||
int32_t mz_stream_pkcrypt_set_prop_int64(void *stream, int32_t prop, int64_t value);
|
||||
|
||||
void* mz_stream_pkcrypt_create(void **stream);
|
||||
void mz_stream_pkcrypt_delete(void **stream);
|
||||
|
||||
+69
-18
@@ -1,34 +1,32 @@
|
||||
/* mz_strm_split.c -- Stream for split files
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_split.h"
|
||||
|
||||
/***************************************************************************/
|
||||
#include <stdio.h> /* snprintf */
|
||||
|
||||
#define MZ_ZIP_MAGIC_DISKHEADER (0x08074b50)
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_ZIP_MAGIC_DISKHEADER (0x08074b50)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_split_vtbl = {
|
||||
mz_stream_split_open,
|
||||
mz_stream_split_is_open,
|
||||
@@ -61,11 +59,20 @@ typedef struct mz_stream_split_s {
|
||||
uint32_t path_disk_size;
|
||||
int32_t number_disk;
|
||||
int32_t current_disk;
|
||||
int64_t current_disk_size;
|
||||
int32_t reached_end;
|
||||
} mz_stream_split;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if 0
|
||||
# define mz_stream_split_print printf
|
||||
#else
|
||||
# define mz_stream_split_print(fmt,...)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
@@ -75,7 +82,7 @@ static int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
int16_t disk_part = 0;
|
||||
|
||||
|
||||
// Check if we are reading or writing a disk part or the cd disk
|
||||
/* Check if we are reading or writing a disk part or the cd disk */
|
||||
if (number_disk >= 0)
|
||||
{
|
||||
if ((split->mode & MZ_OPEN_MODE_WRITE) == 0)
|
||||
@@ -84,7 +91,7 @@ static int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
disk_part = MZ_OPEN_MODE_WRITE;
|
||||
}
|
||||
|
||||
// Construct disk path
|
||||
/* Construct disk path */
|
||||
if (disk_part > 0)
|
||||
{
|
||||
for (i = (int32_t)strlen(split->path_disk) - 1; i >= 0; i -= 1)
|
||||
@@ -102,7 +109,9 @@ static int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
split->path_disk[split->path_disk_size - 1] = 0;
|
||||
}
|
||||
|
||||
// If disk part doesn't exist during reading then return MZ_EXIST_ERROR
|
||||
mz_stream_split_print("Split - Goto disk - %s (disk %"PRId32")\n", split->path_disk, number_disk);
|
||||
|
||||
/* If disk part doesn't exist during reading then return MZ_EXIST_ERROR */
|
||||
if (disk_part == MZ_OPEN_MODE_READ)
|
||||
err = mz_os_file_exists(split->path_disk);
|
||||
|
||||
@@ -128,6 +137,11 @@ static int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
{
|
||||
if (split->current_disk == 0)
|
||||
{
|
||||
/* Get the size of the current disk we are on for seeking */
|
||||
mz_stream_seek(split->stream.base, 0, MZ_SEEK_END);
|
||||
split->current_disk_size = mz_stream_tell(split->stream.base);
|
||||
mz_stream_seek(split->stream.base, 0, MZ_SEEK_SET);
|
||||
|
||||
err = mz_stream_read_uint32(split->stream.base, &magic);
|
||||
if (magic != MZ_ZIP_MAGIC_DISKHEADER)
|
||||
err = MZ_FORMAT_ERROR;
|
||||
@@ -148,6 +162,7 @@ static int32_t mz_stream_split_close_disk(void *stream)
|
||||
if (mz_stream_is_open(split->stream.base) != MZ_OK)
|
||||
return MZ_OK;
|
||||
|
||||
mz_stream_split_print("Split - Close disk\n");
|
||||
return mz_stream_close(split->stream.base);
|
||||
}
|
||||
|
||||
@@ -155,13 +170,16 @@ static int32_t mz_stream_split_goto_disk(void *stream, int32_t number_disk)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t err_is_open = MZ_OK;
|
||||
|
||||
err_is_open = mz_stream_is_open(split->stream.base);
|
||||
|
||||
if ((split->disk_size == 0) && (split->mode & MZ_OPEN_MODE_WRITE))
|
||||
{
|
||||
if (mz_stream_is_open(split->stream.base) != MZ_OK)
|
||||
if (err_is_open != MZ_OK)
|
||||
err = mz_stream_split_open_disk(stream, number_disk);
|
||||
}
|
||||
else if (number_disk != split->current_disk)
|
||||
else if ((number_disk != split->current_disk) || (err_is_open != MZ_OK))
|
||||
{
|
||||
err = mz_stream_split_close_disk(stream);
|
||||
if (err == MZ_OK)
|
||||
@@ -191,6 +209,8 @@ int32_t mz_stream_split_open(void *stream, const char *path, int32_t mode)
|
||||
strncpy(split->path_cd, path, split->path_cd_size - 1);
|
||||
split->path_cd[split->path_cd_size - 1] = 0;
|
||||
|
||||
mz_stream_split_print("Split - Open - %s (disk %"PRId32")\n", split->path_cd, number_disk);
|
||||
|
||||
split->path_disk_size = (uint32_t)strlen(path) + 10;
|
||||
split->path_disk = (char *)MZ_ALLOC(split->path_disk_size);
|
||||
|
||||
@@ -203,12 +223,12 @@ int32_t mz_stream_split_open(void *stream, const char *path, int32_t mode)
|
||||
strncpy(split->path_disk, path, split->path_disk_size - 1);
|
||||
split->path_disk[split->path_disk_size - 1] = 0;
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
if ((mode & MZ_OPEN_MODE_WRITE) && ((mode & MZ_OPEN_MODE_APPEND) == 0))
|
||||
{
|
||||
number_disk = 0;
|
||||
split->current_disk = -1;
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
else
|
||||
{
|
||||
number_disk = -1;
|
||||
split->current_disk = 0;
|
||||
@@ -240,15 +260,21 @@ int32_t mz_stream_split_read(void *stream, void *buf, int32_t size)
|
||||
while (bytes_left > 0)
|
||||
{
|
||||
read = mz_stream_read(split->stream.base, buf_ptr, bytes_left);
|
||||
|
||||
mz_stream_split_print("Split - Read disk - %"PRId32"\n", read);
|
||||
|
||||
if (read < 0)
|
||||
return read;
|
||||
if (read == 0)
|
||||
{
|
||||
if (split->current_disk < 0) // No more disks to goto
|
||||
if (split->current_disk < 0) /* No more disks to goto */
|
||||
break;
|
||||
err = mz_stream_split_goto_disk(stream, split->current_disk + 1);
|
||||
if (err == MZ_EXIST_ERROR)
|
||||
{
|
||||
split->current_disk = -1;
|
||||
break;
|
||||
}
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
}
|
||||
@@ -300,6 +326,8 @@ int32_t mz_stream_split_write(void *stream, const void *buf, int32_t size)
|
||||
written = mz_stream_write(split->stream.base, buf_ptr, bytes_to_write);
|
||||
if (written != bytes_to_write)
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
mz_stream_split_print("Split - Write disk - %"PRId32"\n", written);
|
||||
|
||||
bytes_left -= written;
|
||||
buf_ptr += written;
|
||||
@@ -323,10 +351,33 @@ int64_t mz_stream_split_tell(void *stream)
|
||||
int32_t mz_stream_split_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
int64_t disk_left = 0;
|
||||
int64_t position = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
err = mz_stream_split_goto_disk(stream, split->number_disk);
|
||||
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
mz_stream_split_print("Split - Seek disk - %"PRId64" (origin %"PRId32")\n", offset, origin);
|
||||
|
||||
if ((origin == MZ_SEEK_CUR) && (split->number_disk != -1))
|
||||
{
|
||||
position = mz_stream_tell(split->stream.base);
|
||||
disk_left = split->current_disk_size - position;
|
||||
|
||||
while (offset > disk_left)
|
||||
{
|
||||
err = mz_stream_split_goto_disk(stream, split->current_disk + 1);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
offset -= disk_left;
|
||||
disk_left = split->current_disk_size;
|
||||
}
|
||||
}
|
||||
|
||||
return mz_stream_seek(split->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_split.h -- Stream for split files
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,8 +12,6 @@
|
||||
#ifndef MZ_STREAM_SPLIT_H
|
||||
#define MZ_STREAM_SPLIT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+36
-102
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_wzaes.c -- Stream for WinZip AES encryption
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Brian Gladman, Worcester, UK
|
||||
|
||||
@@ -11,12 +11,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_crypt.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_wzaes.h"
|
||||
|
||||
@@ -68,83 +64,6 @@ typedef struct mz_stream_wzaes_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_wzaes_pbkdf2(uint8_t *password, int32_t password_length, uint8_t *salt,
|
||||
int32_t salt_length, int32_t iteration_count, uint8_t *key, int32_t key_length)
|
||||
{
|
||||
void *hmac1 = NULL;
|
||||
void *hmac2 = NULL;
|
||||
void *hmac3 = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
uint16_t i = 0;
|
||||
uint16_t j = 0;
|
||||
uint16_t k = 0;
|
||||
uint16_t block_count = 0;
|
||||
uint8_t uu[MZ_HASH_SHA1_SIZE];
|
||||
uint8_t ux[MZ_HASH_SHA1_SIZE];
|
||||
|
||||
if (password == NULL || salt == NULL || key == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
memset(key, 0, key_length);
|
||||
|
||||
mz_crypt_hmac_create(&hmac1);
|
||||
mz_crypt_hmac_create(&hmac2);
|
||||
mz_crypt_hmac_create(&hmac3);
|
||||
|
||||
mz_crypt_hmac_set_algorithm(hmac1, MZ_HASH_SHA1);
|
||||
mz_crypt_hmac_set_algorithm(hmac2, MZ_HASH_SHA1);
|
||||
mz_crypt_hmac_set_algorithm(hmac3, MZ_HASH_SHA1);
|
||||
|
||||
err = mz_crypt_hmac_init(hmac1, password, password_length);
|
||||
err = mz_crypt_hmac_init(hmac2, password, password_length);
|
||||
if (err == MZ_OK)
|
||||
err = mz_crypt_hmac_update(hmac2, salt, salt_length);
|
||||
|
||||
block_count = 1 + ((uint16_t)key_length - 1) / MZ_HASH_SHA1_SIZE;
|
||||
|
||||
for (i = 0; (err == MZ_OK) && (i < block_count); i += 1)
|
||||
{
|
||||
memset(ux, 0, sizeof(ux));
|
||||
|
||||
err = mz_crypt_hmac_copy(hmac2, hmac3);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
uu[0] = (uint8_t)((i + 1) >> 24);
|
||||
uu[1] = (uint8_t)((i + 1) >> 16);
|
||||
uu[2] = (uint8_t)((i + 1) >> 8);
|
||||
uu[3] = (uint8_t)(i + 1);
|
||||
|
||||
for (j = 0, k = 4; j < iteration_count; j += 1)
|
||||
{
|
||||
err = mz_crypt_hmac_update(hmac3, uu, k);
|
||||
err = mz_crypt_hmac_end(hmac3, uu, sizeof(uu));
|
||||
|
||||
for(k = 0; k < MZ_HASH_SHA1_SIZE; k += 1)
|
||||
ux[k] ^= uu[k];
|
||||
|
||||
err = mz_crypt_hmac_copy(hmac1, hmac3);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
j = 0;
|
||||
k = i * MZ_HASH_SHA1_SIZE;
|
||||
|
||||
while (j < MZ_HASH_SHA1_SIZE && k < key_length)
|
||||
key[k++] = ux[j++];
|
||||
}
|
||||
|
||||
mz_crypt_hmac_delete(&hmac1);
|
||||
mz_crypt_hmac_delete(&hmac2);
|
||||
mz_crypt_hmac_delete(&hmac3);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_wzaes_open(void *stream, const char *path, int32_t mode)
|
||||
@@ -199,20 +118,20 @@ int32_t mz_stream_wzaes_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
key_length = MZ_AES_KEY_LENGTH(wzaes->encryption_mode);
|
||||
|
||||
// Derive the encryption and authentication keys and the password verifier
|
||||
mz_stream_wzaes_pbkdf2((uint8_t *)password, password_length, salt_value, salt_length,
|
||||
/* Derive the encryption and authentication keys and the password verifier */
|
||||
mz_crypt_pbkdf2((uint8_t *)password, password_length, salt_value, salt_length,
|
||||
MZ_AES_KEYING_ITERATIONS, kbuf, 2 * key_length + MZ_AES_PW_VERIFY_SIZE);
|
||||
|
||||
// Initialize the encryption nonce and buffer pos
|
||||
/* Initialize the encryption nonce and buffer pos */
|
||||
wzaes->crypt_pos = MZ_AES_BLOCK_SIZE;
|
||||
memset(wzaes->nonce, 0, sizeof(wzaes->nonce));
|
||||
|
||||
// Initialize for encryption using key 1
|
||||
/* Initialize for encryption using key 1 */
|
||||
mz_crypt_aes_reset(wzaes->aes);
|
||||
mz_crypt_aes_set_mode(wzaes->aes, wzaes->encryption_mode);
|
||||
mz_crypt_aes_set_encrypt_key(wzaes->aes, kbuf, key_length);
|
||||
|
||||
// Initialize for authentication using key 2
|
||||
/* Initialize for authentication using key 2 */
|
||||
mz_crypt_hmac_reset(wzaes->hmac);
|
||||
mz_crypt_hmac_set_algorithm(wzaes->hmac, MZ_HASH_SHA1);
|
||||
mz_crypt_hmac_init(wzaes->hmac, kbuf + key_length, key_length);
|
||||
@@ -271,11 +190,11 @@ static int32_t mz_stream_wzaes_encrypt_data(void *stream, uint8_t *buf, int32_t
|
||||
{
|
||||
uint32_t j = 0;
|
||||
|
||||
// Increment encryption nonce
|
||||
/* Increment encryption nonce */
|
||||
while (j < 8 && !++wzaes->nonce[j])
|
||||
j += 1;
|
||||
|
||||
// Encrypt the nonce to form next xor buffer
|
||||
/* Encrypt the nonce to form next xor buffer */
|
||||
memcpy(wzaes->crypt_block, wzaes->nonce, MZ_AES_BLOCK_SIZE);
|
||||
mz_crypt_aes_encrypt(wzaes->aes, wzaes->crypt_block, sizeof(wzaes->crypt_block));
|
||||
pos = 0;
|
||||
@@ -296,7 +215,7 @@ int32_t mz_stream_wzaes_read(void *stream, void *buf, int32_t size)
|
||||
int32_t read = 0;
|
||||
|
||||
max_total_in = wzaes->max_total_in - MZ_AES_FOOTER_SIZE;
|
||||
if (bytes_to_read + wzaes->total_in > max_total_in)
|
||||
if ((int64_t)bytes_to_read > (max_total_in - wzaes->total_in))
|
||||
bytes_to_read = (int32_t)(max_total_in - wzaes->total_in);
|
||||
|
||||
read = mz_stream_read(wzaes->stream.base, buf, bytes_to_read);
|
||||
@@ -305,30 +224,45 @@ int32_t mz_stream_wzaes_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_crypt_hmac_update(wzaes->hmac, (uint8_t *)buf, read);
|
||||
mz_stream_wzaes_encrypt_data(stream, (uint8_t *)buf, read);
|
||||
|
||||
wzaes->total_in += read;
|
||||
}
|
||||
|
||||
wzaes->total_in += read;
|
||||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_wzaes_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_wzaes *wzaes = (mz_stream_wzaes *)stream;
|
||||
const uint8_t *buf_ptr = (const uint8_t *)buf;
|
||||
int32_t bytes_to_write = sizeof(wzaes->buffer);
|
||||
int32_t total_written = 0;
|
||||
int32_t written = 0;
|
||||
|
||||
if (size < 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (size > (int32_t)sizeof(wzaes->buffer))
|
||||
return MZ_BUF_ERROR;
|
||||
|
||||
memcpy(wzaes->buffer, buf, size);
|
||||
mz_stream_wzaes_encrypt_data(stream, (uint8_t *)wzaes->buffer, size);
|
||||
mz_crypt_hmac_update(wzaes->hmac, wzaes->buffer, size);
|
||||
do
|
||||
{
|
||||
if (bytes_to_write > (size - total_written))
|
||||
bytes_to_write = (size - total_written);
|
||||
|
||||
written = mz_stream_write(wzaes->stream.base, wzaes->buffer, size);
|
||||
if (written > 0)
|
||||
wzaes->total_out += written;
|
||||
return written;
|
||||
memcpy(wzaes->buffer, buf_ptr, bytes_to_write);
|
||||
buf_ptr += bytes_to_write;
|
||||
|
||||
mz_stream_wzaes_encrypt_data(stream, (uint8_t *)wzaes->buffer, bytes_to_write);
|
||||
mz_crypt_hmac_update(wzaes->hmac, wzaes->buffer, bytes_to_write);
|
||||
|
||||
written = mz_stream_write(wzaes->stream.base, wzaes->buffer, bytes_to_write);
|
||||
if (written < 0)
|
||||
return written;
|
||||
|
||||
total_written += written;
|
||||
}
|
||||
while (total_written < size && written > 0);
|
||||
|
||||
wzaes->total_out += total_written;
|
||||
return total_written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_wzaes_tell(void *stream)
|
||||
@@ -365,7 +299,7 @@ int32_t mz_stream_wzaes_close(void *stream)
|
||||
|
||||
wzaes->total_in += MZ_AES_AUTHCODE_SIZE;
|
||||
|
||||
// If entire entry was not read this will fail
|
||||
/* If entire entry was not read this will fail */
|
||||
if (memcmp(computed_hash, expected_hash, MZ_AES_AUTHCODE_SIZE) != 0)
|
||||
return MZ_CRC_ERROR;
|
||||
}
|
||||
|
||||
+2
-7
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_wzaes.h -- Stream for WinZIP AES encryption
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,17 +12,12 @@
|
||||
#ifndef MZ_STREAM_WZAES_SHA1_H
|
||||
#define MZ_STREAM_WZAES_SHA1_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_wzaes_pbkdf2(uint8_t *password, int32_t password_length, uint8_t *salt,
|
||||
int32_t salt_length, int32_t iteration_count, uint8_t *key, int32_t key_length);
|
||||
|
||||
int32_t mz_stream_wzaes_open(void *stream, const char *filename, int32_t mode);
|
||||
int32_t mz_stream_wzaes_is_open(void *stream);
|
||||
int32_t mz_stream_wzaes_read(void *stream, void *buf, int32_t size);
|
||||
|
||||
+12
-31
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_zlib.c -- Stream for zlib inflate/deflate
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -10,24 +10,11 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_zlib.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng
|
||||
#if defined(ZLIBNG_VERNUM)
|
||||
typedef uint32_t z_crc_t;
|
||||
#elif (ZLIB_VERNUM < 0x1270)
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
#include "zlib.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -133,6 +120,9 @@ int32_t mz_stream_zlib_is_open(void *stream)
|
||||
int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
MZ_UNUSED(stream);
|
||||
MZ_UNUSED(buf);
|
||||
MZ_UNUSED(size);
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
@@ -144,7 +134,7 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
uint32_t total_out = 0;
|
||||
uint32_t in_bytes = 0;
|
||||
uint32_t out_bytes = 0;
|
||||
int32_t bytes_to_read = 0;
|
||||
int32_t bytes_to_read = sizeof(zlib->buffer);
|
||||
int32_t read = 0;
|
||||
int32_t err = Z_OK;
|
||||
|
||||
@@ -156,10 +146,9 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
if (zlib->zstream.avail_in == 0)
|
||||
{
|
||||
bytes_to_read = sizeof(zlib->buffer);
|
||||
if (zlib->max_total_in > 0)
|
||||
{
|
||||
if ((zlib->max_total_in - zlib->total_in) < (int64_t)sizeof(zlib->buffer))
|
||||
if ((int64_t)bytes_to_read > (zlib->max_total_in - zlib->total_in))
|
||||
bytes_to_read = (int32_t)(zlib->max_total_in - zlib->total_in);
|
||||
}
|
||||
|
||||
@@ -167,7 +156,6 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
|
||||
if (read < 0)
|
||||
return read;
|
||||
|
||||
if (read == 0)
|
||||
break;
|
||||
|
||||
@@ -209,7 +197,7 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
|
||||
if (zlib->error != 0)
|
||||
{
|
||||
// Zlib errors are compatible with MZ
|
||||
/* Zlib errors are compatible with MZ */
|
||||
return zlib->error;
|
||||
}
|
||||
|
||||
@@ -217,6 +205,7 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef MZ_ZIP_NO_COMPRESSION
|
||||
static int32_t mz_stream_zlib_flush(void *stream)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
@@ -269,6 +258,7 @@ static int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
@@ -277,6 +267,7 @@ int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size)
|
||||
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(zlib);
|
||||
MZ_UNUSED(buf);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
zlib->zstream.next_in = (Bytef*)(intptr_t)buf;
|
||||
@@ -415,13 +406,3 @@ void *mz_stream_zlib_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_zlib_vtbl;
|
||||
}
|
||||
|
||||
static int64_t mz_stream_zlib_crc32(int64_t value, const void *buf, int32_t size)
|
||||
{
|
||||
return crc32((z_crc_t)value, buf, size);
|
||||
}
|
||||
|
||||
void *mz_stream_zlib_get_crc32_update(void)
|
||||
{
|
||||
return (void *)mz_stream_zlib_crc32;
|
||||
}
|
||||
|
||||
+2
-5
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,8 +12,6 @@
|
||||
#ifndef MZ_STREAM_ZLIB_H
|
||||
#define MZ_STREAM_ZLIB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -36,7 +34,6 @@ 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_update(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_zip.h -- Zip manipulation
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
@@ -17,11 +17,6 @@
|
||||
#ifndef MZ_ZIP_H
|
||||
#define MZ_ZIP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "mz_strm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -30,32 +25,31 @@ extern "C" {
|
||||
|
||||
typedef struct mz_zip_file_s
|
||||
{
|
||||
uint16_t version_madeby; // version made by
|
||||
uint16_t version_needed; // version needed to extract
|
||||
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
|
||||
time_t creation_date; // creation date in unix time
|
||||
uint32_t crc; // crc-32
|
||||
int64_t compressed_size; // compressed size
|
||||
int64_t uncompressed_size; // uncompressed size
|
||||
uint16_t filename_size; // filename length
|
||||
uint16_t extrafield_size; // extra field length
|
||||
uint16_t comment_size; // file comment length
|
||||
uint32_t disk_number; // disk number start
|
||||
int64_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
|
||||
#ifdef HAVE_AES
|
||||
uint16_t aes_version; // winzip aes extension if not 0
|
||||
uint8_t aes_encryption_mode; // winzip aes encryption mode
|
||||
#endif
|
||||
uint16_t version_madeby; /* version made by */
|
||||
uint16_t version_needed; /* version needed to extract */
|
||||
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 */
|
||||
time_t creation_date; /* creation date in unix time */
|
||||
uint32_t crc; /* crc-32 */
|
||||
int64_t compressed_size; /* compressed size */
|
||||
int64_t uncompressed_size; /* uncompressed size */
|
||||
uint16_t filename_size; /* filename length */
|
||||
uint16_t extrafield_size; /* extra field length */
|
||||
uint16_t comment_size; /* file comment length */
|
||||
uint32_t disk_number; /* disk number start */
|
||||
int64_t disk_offset; /* relative offset of local header */
|
||||
uint16_t internal_fa; /* internal file attributes */
|
||||
uint32_t external_fa; /* external file attributes */
|
||||
|
||||
const char *filename; // filename utf8 null-terminated string
|
||||
const uint8_t *extrafield; // extrafield data
|
||||
const char *comment; // comment utf8 null-terminated string
|
||||
const char *filename; /* filename utf8 null-terminated string */
|
||||
const uint8_t *extrafield; /* extrafield data */
|
||||
const char *comment; /* comment utf8 null-terminated string */
|
||||
|
||||
uint16_t zip64; /* zip64 extension mode */
|
||||
uint16_t aes_version; /* winzip aes extension if not 0 */
|
||||
uint8_t aes_encryption_mode; /* winzip aes encryption mode */
|
||||
|
||||
} mz_zip_file, mz_zip_entry;
|
||||
|
||||
@@ -66,158 +60,177 @@ typedef int32_t (*mz_zip_locate_entry_cb)(void *handle, void *userdata, mz_zip_f
|
||||
/***************************************************************************/
|
||||
|
||||
void * mz_zip_create(void **handle);
|
||||
// Create zip instance for opening
|
||||
/* Create zip instance for opening */
|
||||
|
||||
void mz_zip_delete(void **handle);
|
||||
// Delete zip object
|
||||
/* Delete zip object */
|
||||
|
||||
int32_t mz_zip_open(void *handle, void *stream, int32_t mode);
|
||||
// Create a zip file, no delete file in zip functionality
|
||||
/* Create a zip file, no delete file in zip functionality */
|
||||
|
||||
int32_t mz_zip_close(void *handle);
|
||||
// Close the zip file
|
||||
/* Close the zip file */
|
||||
|
||||
int32_t mz_zip_get_comment(void *handle, const char **comment);
|
||||
// Get a pointer to the global comment
|
||||
/* Get a pointer to the global comment */
|
||||
|
||||
int32_t mz_zip_set_comment(void *handle, const char *comment);
|
||||
// Set the global comment used for writing zip file
|
||||
/* Set the global comment used for writing zip file */
|
||||
|
||||
int32_t mz_zip_get_version_madeby(void *handle, uint16_t *version_madeby);
|
||||
// Get the version made by
|
||||
/* Get the version made by */
|
||||
|
||||
int32_t mz_zip_set_version_madeby(void *handle, uint16_t version_madeby);
|
||||
// Set the version made by used for writing zip file
|
||||
/* Set the version made by used for writing zip file */
|
||||
|
||||
int32_t mz_zip_set_recover(void *handle, uint8_t recover);
|
||||
/* Set the ability to recover the central dir by reading local file headers */
|
||||
|
||||
int32_t mz_zip_get_stream(void *handle, void **stream);
|
||||
// Get a pointer to the stream used to open
|
||||
/* Get a pointer to the stream used to open */
|
||||
|
||||
int32_t mz_zip_set_cd_stream(void *handle, int64_t cd_start_pos, void *cd_stream);
|
||||
// Sets the stream to use for reading the central dir
|
||||
/* Sets the stream to use for reading the central dir */
|
||||
|
||||
int32_t mz_zip_get_cd_mem_stream(void *handle, void **cd_mem_stream);
|
||||
// Get a pointer to the stream used to store the central dir in memory
|
||||
/* Get a pointer to the stream used to store the central dir in memory */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
|
||||
int16_t compress_level, uint8_t raw, const char *password);
|
||||
// Open for writing the current file in the zip file
|
||||
|
||||
int32_t mz_zip_entry_write(void *handle, const void *buf, int32_t len);
|
||||
// Write bytes from the current file in the zip file
|
||||
|
||||
int32_t mz_zip_entry_is_open(void *handle);
|
||||
// Check to see if entry is open for read/write
|
||||
|
||||
int32_t mz_zip_entry_is_dir(void *handle);
|
||||
// Checks to see if the entry is a directory
|
||||
/* Check to see if entry is open for read/write */
|
||||
|
||||
int32_t mz_zip_entry_read_open(void *handle, uint8_t raw, const char *password);
|
||||
// Open for reading the current file in the zip file
|
||||
/* Open for reading the current file in the zip file */
|
||||
|
||||
int32_t mz_zip_entry_read(void *handle, void *buf, int32_t len);
|
||||
// Read bytes from the current file in the zip file
|
||||
/* Read bytes from the current file in the zip file */
|
||||
|
||||
int32_t mz_zip_entry_read_close(void *handle, uint32_t *crc32, int64_t *compressed_size,
|
||||
int64_t *uncompressed_size);
|
||||
/* Close the current file for reading and get data descriptor values */
|
||||
|
||||
int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
|
||||
int16_t compress_level, uint8_t raw, const char *password);
|
||||
/* Open for writing the current file in the zip file */
|
||||
|
||||
int32_t mz_zip_entry_write(void *handle, const void *buf, int32_t len);
|
||||
/* Write bytes from the current file in the zip file */
|
||||
|
||||
int32_t mz_zip_entry_write_close(void *handle, uint32_t crc32, int64_t compressed_size,
|
||||
int64_t uncompressed_size);
|
||||
/* Close the current file for writing and set data descriptor values */
|
||||
|
||||
int32_t mz_zip_entry_is_dir(void *handle);
|
||||
/* Checks to see if the entry is a directory */
|
||||
|
||||
int32_t mz_zip_entry_get_info(void *handle, mz_zip_file **file_info);
|
||||
// Get info about the current file, only valid while current entry is open
|
||||
/* Get info about the current file, only valid while current entry is open */
|
||||
|
||||
int32_t mz_zip_entry_get_local_info(void *handle, mz_zip_file **local_file_info);
|
||||
// Get local info about the current file, only valid while current entry is being read
|
||||
/* Get local info about the current file, only valid while current entry is being read */
|
||||
|
||||
int32_t mz_zip_entry_set_extrafield(void *handle, const uint8_t *extrafield, uint16_t extrafield_size);
|
||||
// Sets or updates the extra field for the entry to be used before writing cd
|
||||
/* Sets or updates the extra field for the entry to be used before writing cd */
|
||||
|
||||
int32_t mz_zip_entry_close_raw(void *handle, int64_t uncompressed_size, uint32_t crc32);
|
||||
// Close the current file in the zip file where raw is compressed data
|
||||
/* Close the current file in the zip file where raw is compressed data */
|
||||
|
||||
int32_t mz_zip_entry_close(void *handle);
|
||||
// Close the current file in the zip file
|
||||
/* Close the current file in the zip file */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_set_number_entry(void *handle, uint64_t number_entry);
|
||||
// Sets the total number of entries
|
||||
/* Sets the total number of entries */
|
||||
|
||||
int32_t mz_zip_get_number_entry(void *handle, uint64_t *number_entry);
|
||||
// Get the total number of entries
|
||||
/* Get the total number of entries */
|
||||
|
||||
int32_t mz_zip_set_disk_number_with_cd(void *handle, uint32_t disk_number_with_cd);
|
||||
/* Sets the disk number containing the central directory record */
|
||||
|
||||
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
|
||||
/* Get the disk number containing the central directory record */
|
||||
|
||||
int64_t mz_zip_get_entry(void *handle);
|
||||
// Return offset of the current entry in the zip file
|
||||
/* Return offset of the current entry in the zip file */
|
||||
|
||||
int32_t mz_zip_goto_entry(void *handle, int64_t cd_pos);
|
||||
// Go to specified entry in the zip file
|
||||
/* Go to specified entry in the zip file */
|
||||
|
||||
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 */
|
||||
|
||||
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
|
||||
/* Go to the next entry in the zip file or MZ_END_OF_LIST if reaching the end */
|
||||
|
||||
int32_t mz_zip_locate_entry(void *handle, const char *filename, uint8_t ignore_case);
|
||||
// Locate the file with the specified name in the zip file or MZ_END_LIST if not found
|
||||
/* Locate the file with the specified name in the zip file or MZ_END_LIST if not found */
|
||||
|
||||
int32_t mz_zip_locate_first_entry(void *handle, void *userdata, mz_zip_locate_entry_cb cb);
|
||||
// Locate the first matching entry based on a match callback
|
||||
/* Locate the first matching entry based on a match callback */
|
||||
|
||||
int32_t mz_zip_locate_next_entry(void *handle, void *userdata, mz_zip_locate_entry_cb cb);
|
||||
// LOcate the next matching entry based on a match callback
|
||||
/* LOcate the next matching entry based on a match callback */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_attrib_is_dir(uint32_t attrib, int32_t version_madeby);
|
||||
// Checks to see if the attribute is a directory based on platform
|
||||
/* Checks to see if the attribute is a directory based on platform */
|
||||
|
||||
int32_t mz_zip_attrib_convert(uint8_t src_sys, uint32_t src_attrib, uint8_t target_sys, uint32_t *target_attrib);
|
||||
// Converts file attributes from one host system to another
|
||||
int32_t mz_zip_attrib_convert(uint8_t src_sys, uint32_t src_attrib, uint8_t target_sys,
|
||||
uint32_t *target_attrib);
|
||||
/* Converts file attributes from one host system to another */
|
||||
|
||||
int32_t mz_zip_attrib_posix_to_win32(uint32_t posix_attrib, uint32_t *win32_attrib);
|
||||
// Converts posix file attributes to win32 file attributes
|
||||
/* Converts posix file attributes to win32 file attributes */
|
||||
|
||||
int32_t mz_zip_attrib_win32_to_posix(uint32_t win32_attrib, uint32_t *posix_attrib);
|
||||
// Converts win32 file attributes to posix file attributes
|
||||
/* Converts win32 file attributes to posix file attributes */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_extrafield_find(void *stream, uint16_t type, uint16_t *length);
|
||||
// Seeks to extra field by its type and returns its length
|
||||
/* Seeks to extra field by its type and returns its length */
|
||||
|
||||
int32_t mz_zip_extrafield_contains(const uint8_t *extrafield, int32_t extrafield_size,
|
||||
uint16_t type, uint16_t *length);
|
||||
/* Gets whether an extrafield exists and its size */
|
||||
|
||||
int32_t mz_zip_extrafield_read(void *stream, uint16_t *type, uint16_t *length);
|
||||
// Reads and extrafield header from a stream
|
||||
/* Reads an extrafield header from a stream */
|
||||
|
||||
int32_t mz_zip_extrafield_write(void *stream, uint32_t type, uint16_t length);
|
||||
// Writes an extrafield header to a stream
|
||||
int32_t mz_zip_extrafield_write(void *stream, uint16_t type, uint16_t length);
|
||||
/* Writes an extrafield header to a stream */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_dosdate_to_tm(uint64_t dos_date, struct tm *ptm);
|
||||
// Convert dos date/time format to struct tm
|
||||
/* Convert dos date/time format to struct tm */
|
||||
|
||||
time_t mz_zip_dosdate_to_time_t(uint64_t dos_date);
|
||||
// Convert dos date/time format to time_t
|
||||
/* 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
|
||||
/* Convert time_t to dos date/time format */
|
||||
|
||||
uint32_t mz_zip_tm_to_dosdate(const struct tm *ptm);
|
||||
// Convert struct tm to dos date/time format
|
||||
/* Convert struct tm to dos date/time format */
|
||||
|
||||
int32_t mz_zip_ntfs_to_unix_time(uint64_t ntfs_time, time_t *unix_time);
|
||||
// Convert ntfs time to unix time
|
||||
/* Convert ntfs time to unix time */
|
||||
|
||||
int32_t mz_zip_unix_to_ntfs_time(time_t unix_time, uint64_t *ntfs_time);
|
||||
// Convert unix time to ntfs time
|
||||
/* Convert unix time to ntfs time */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_path_compare(const char *path1, const char *path2, uint8_t ignore_case);
|
||||
// Compare two paths without regard to slashes
|
||||
/* Compare two paths without regard to slashes */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
+279
-161
@@ -1,20 +1,14 @@
|
||||
/* mz_zip_rw.c -- Zip reader/writer
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_crypt.h"
|
||||
#include "mz_os.h"
|
||||
@@ -66,6 +60,9 @@ typedef struct mz_zip_reader_s {
|
||||
uint8_t buffer[UINT16_MAX];
|
||||
int32_t encoding;
|
||||
uint8_t sign_required;
|
||||
uint8_t cd_verified;
|
||||
uint8_t cd_zipped;
|
||||
uint8_t entry_verified;
|
||||
} mz_zip_reader;
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -85,7 +82,12 @@ int32_t mz_zip_reader_open(void *handle, void *stream)
|
||||
mz_zip_reader *reader = (mz_zip_reader *)handle;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
reader->cd_verified = 0;
|
||||
reader->cd_zipped = 0;
|
||||
|
||||
mz_zip_create(&reader->zip_handle);
|
||||
mz_zip_set_recover(reader->zip_handle, 1);
|
||||
|
||||
err = mz_zip_open(reader->zip_handle, stream, MZ_OPEN_MODE_READ);
|
||||
|
||||
if (err != MZ_OK)
|
||||
@@ -140,13 +142,13 @@ int32_t mz_zip_reader_open_file_in_memory(void *handle, const char *path)
|
||||
return err;
|
||||
}
|
||||
|
||||
mz_stream_os_seek(file_stream, 0, SEEK_END);
|
||||
mz_stream_os_seek(file_stream, 0, MZ_SEEK_END);
|
||||
file_size = mz_stream_os_tell(file_stream);
|
||||
mz_stream_os_seek(file_stream, 0, SEEK_SET);
|
||||
mz_stream_os_seek(file_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
if ((file_size <= 0) || (file_size > UINT32_MAX))
|
||||
{
|
||||
// Memory size is too large or too small
|
||||
/* Memory size is too large or too small */
|
||||
|
||||
mz_stream_os_close(file_stream);
|
||||
mz_stream_os_delete(&file_stream);
|
||||
@@ -185,7 +187,7 @@ int32_t mz_zip_reader_open_buffer(void *handle, uint8_t *buf, int32_t len, uint8
|
||||
mz_stream_mem_set_grow_size(reader->mem_stream, len);
|
||||
mz_stream_mem_open(reader->mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
mz_stream_mem_write(reader->mem_stream, buf, len);
|
||||
mz_stream_mem_seek(reader->mem_stream, 0, SEEK_SET);
|
||||
mz_stream_mem_seek(reader->mem_stream, 0, MZ_SEEK_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -274,16 +276,23 @@ int32_t mz_zip_reader_unzip_cd(void *handle)
|
||||
if (mz_stream_mem_is_open(cd_mem_stream) != MZ_OK)
|
||||
mz_stream_mem_open(cd_mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
err = mz_stream_copy_stream(cd_mem_stream, NULL, handle, mz_zip_reader_entry_read,
|
||||
(int32_t)cd_info->uncompressed_size);
|
||||
err = mz_stream_seek(cd_mem_stream, 0, MZ_SEEK_SET);
|
||||
if (err == MZ_OK)
|
||||
err = mz_stream_copy_stream(cd_mem_stream, NULL, handle, mz_zip_reader_entry_read,
|
||||
(int32_t)cd_info->uncompressed_size);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
reader->cd_zipped = 1;
|
||||
|
||||
mz_zip_set_cd_stream(reader->zip_handle, 0, cd_mem_stream);
|
||||
mz_zip_set_number_entry(reader->zip_handle, number_entry);
|
||||
|
||||
err = mz_zip_reader_goto_first_entry(handle);
|
||||
}
|
||||
|
||||
reader->cd_verified = reader->entry_verified;
|
||||
|
||||
mz_stream_mem_delete(&new_cd_stream);
|
||||
return err;
|
||||
}
|
||||
@@ -372,18 +381,20 @@ int32_t mz_zip_reader_entry_open(void *handle)
|
||||
char password_buf[120];
|
||||
|
||||
|
||||
reader->entry_verified = 0;
|
||||
|
||||
if (mz_zip_reader_is_open(reader) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (reader->file_info == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
// If the entry isn't open for reading, open it
|
||||
/* If the entry isn't open for reading, open it */
|
||||
if (mz_zip_entry_is_open(reader->zip_handle) == MZ_OK)
|
||||
return MZ_OK;
|
||||
|
||||
password = reader->password;
|
||||
|
||||
// Check if we need a password and ask for it if we need to
|
||||
/* Check if we need a password and ask for it if we need to */
|
||||
if ((reader->file_info->flag & MZ_ZIP_FLAG_ENCRYPTED) && (password == NULL) &&
|
||||
(reader->password_cb != NULL))
|
||||
{
|
||||
@@ -414,13 +425,17 @@ int32_t mz_zip_reader_entry_open(void *handle)
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (mz_zip_reader_entry_has_sign(handle) == MZ_OK)
|
||||
{
|
||||
err = mz_zip_reader_entry_sign_verify(handle);
|
||||
else if (reader->sign_required)
|
||||
if (err == MZ_OK)
|
||||
reader->entry_verified = 1;
|
||||
}
|
||||
else if (reader->sign_required && !reader->cd_verified)
|
||||
err = MZ_SIGN_ERROR;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if (reader->sign_required)
|
||||
else if (reader->sign_required && !reader->cd_verified)
|
||||
err = MZ_SIGN_ERROR;
|
||||
#endif
|
||||
|
||||
@@ -447,7 +462,7 @@ int32_t mz_zip_reader_entry_close(void *handle)
|
||||
|
||||
if (err_hash == MZ_OK)
|
||||
{
|
||||
// Verify expected hash against computed hash
|
||||
/* Verify expected hash against computed hash */
|
||||
if (memcmp(computed_hash, expected_hash, reader->hash_digest_size) != 0)
|
||||
err = MZ_CRC_ERROR;
|
||||
}
|
||||
@@ -475,19 +490,12 @@ int32_t mz_zip_reader_entry_read(void *handle, void *buf, int32_t len)
|
||||
int32_t mz_zip_reader_entry_has_sign(void *handle)
|
||||
{
|
||||
mz_zip_reader *reader = (mz_zip_reader *)handle;
|
||||
void *file_extra_stream = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (reader == NULL || mz_zip_entry_is_open(reader->zip_handle) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
mz_stream_mem_create(&file_extra_stream);
|
||||
mz_stream_mem_set_buffer(file_extra_stream, (void *)reader->file_info->extrafield,
|
||||
reader->file_info->extrafield_size);
|
||||
|
||||
err = mz_zip_extrafield_find(file_extra_stream, MZ_ZIP_EXTENSION_SIGN, NULL);
|
||||
|
||||
mz_stream_mem_delete(&file_extra_stream);
|
||||
|
||||
return err;
|
||||
return mz_zip_extrafield_contains(reader->file_info->extrafield,
|
||||
reader->file_info->extrafield_size, MZ_ZIP_EXTENSION_SIGN, NULL);
|
||||
}
|
||||
|
||||
#if !defined(MZ_ZIP_NO_ENCRYPTION) && !defined(MZ_ZIP_NO_SIGNING)
|
||||
@@ -519,13 +527,13 @@ int32_t mz_zip_reader_entry_sign_verify(void *handle)
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Get most secure hash to verify signature against
|
||||
/* Get most secure hash to verify signature against */
|
||||
err = mz_zip_reader_entry_get_hash(handle, reader->hash_algorithm, hash, reader->hash_digest_size);
|
||||
}
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Verify the pkcs signature
|
||||
/* Verify the pkcs signature */
|
||||
err = mz_crypt_sign_verify(hash, reader->hash_digest_size, signature, signature_size);
|
||||
}
|
||||
|
||||
@@ -558,20 +566,17 @@ int32_t mz_zip_reader_entry_get_hash(void *handle, uint16_t algorithm, uint8_t *
|
||||
err = mz_stream_read_uint16(file_extra_stream, &cur_algorithm);
|
||||
if (err == MZ_OK)
|
||||
err = mz_stream_read_uint16(file_extra_stream, &cur_digest_size);
|
||||
if ((cur_algorithm == algorithm) && (cur_digest_size <= digest_size) &&
|
||||
if ((err == MZ_OK) && (cur_algorithm == algorithm) && (cur_digest_size <= digest_size) &&
|
||||
(cur_digest_size <= MZ_HASH_MAX_SIZE))
|
||||
{
|
||||
// Read hash digest
|
||||
if (mz_stream_read(file_extra_stream, digest, digest_size) != cur_digest_size)
|
||||
err = MZ_FORMAT_ERROR;
|
||||
else
|
||||
/* Read hash digest */
|
||||
if (mz_stream_read(file_extra_stream, digest, digest_size) == cur_digest_size)
|
||||
return_err = MZ_OK;
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = mz_stream_seek(file_extra_stream, cur_digest_size, SEEK_CUR);
|
||||
err = mz_stream_seek(file_extra_stream, cur_digest_size, MZ_SEEK_CUR);
|
||||
}
|
||||
}
|
||||
while (err == MZ_OK);
|
||||
@@ -647,19 +652,19 @@ int32_t mz_zip_reader_entry_save_process(void *handle, void *stream, mz_stream_w
|
||||
if (write_cb == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
// If the entry isn't open for reading, open it
|
||||
/* If the entry isn't open for reading, open it */
|
||||
if (mz_zip_entry_is_open(reader->zip_handle) != MZ_OK)
|
||||
err = mz_zip_reader_entry_open(handle);
|
||||
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
// Unzip entry in zip file
|
||||
/* Unzip entry in zip file */
|
||||
read = mz_zip_reader_entry_read(handle, reader->buffer, sizeof(reader->buffer));
|
||||
|
||||
if (read == 0)
|
||||
{
|
||||
// If we are done close the entry
|
||||
/* If we are done close the entry */
|
||||
err = mz_zip_reader_entry_close(handle);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
@@ -669,7 +674,7 @@ int32_t mz_zip_reader_entry_save_process(void *handle, void *stream, mz_stream_w
|
||||
|
||||
if (read > 0)
|
||||
{
|
||||
// Write the data to the specified stream
|
||||
/* Write the data to the specified stream */
|
||||
written = write_cb(stream, reader->buffer, read);
|
||||
if (written != read)
|
||||
return MZ_WRITE_ERROR;
|
||||
@@ -693,11 +698,11 @@ int32_t mz_zip_reader_entry_save(void *handle, void *stream, mz_stream_write_cb
|
||||
if (reader->file_info == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
// Update the progress at the beginning
|
||||
/* Update the progress at the beginning */
|
||||
if (reader->progress_cb != NULL)
|
||||
reader->progress_cb(handle, reader->progress_userdata, reader->file_info, current_pos);
|
||||
|
||||
// Write data to stream until done
|
||||
/* Write data to stream until done */
|
||||
while (err == MZ_OK)
|
||||
{
|
||||
written = mz_zip_reader_entry_save_process(handle, stream, write_cb);
|
||||
@@ -708,7 +713,7 @@ int32_t mz_zip_reader_entry_save(void *handle, void *stream, mz_stream_write_cb
|
||||
if (written < 0)
|
||||
err = written;
|
||||
|
||||
// Update progress if enough time have passed
|
||||
/* Update progress if enough time have passed */
|
||||
current_time = mz_os_ms_time();
|
||||
if ((current_time - update_time) > reader->progress_cb_interval_ms)
|
||||
{
|
||||
@@ -720,7 +725,7 @@ int32_t mz_zip_reader_entry_save(void *handle, void *stream, mz_stream_write_cb
|
||||
}
|
||||
}
|
||||
|
||||
// Update the progress at the end
|
||||
/* Update the progress at the end */
|
||||
if (reader->progress_cb != NULL && update_pos != current_pos)
|
||||
reader->progress_cb(handle, reader->progress_userdata, reader->file_info, current_pos);
|
||||
|
||||
@@ -735,6 +740,8 @@ int32_t mz_zip_reader_entry_save_file(void *handle, const char *path)
|
||||
int32_t err_attrib = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t err_cb = MZ_OK;
|
||||
int32_t i = 0;
|
||||
char pathwfs[512];
|
||||
char directory[512];
|
||||
|
||||
if (mz_zip_reader_is_open(reader) != MZ_OK)
|
||||
@@ -742,30 +749,39 @@ int32_t mz_zip_reader_entry_save_file(void *handle, const char *path)
|
||||
if (reader->file_info == NULL || path == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (reader->entry_cb != NULL)
|
||||
reader->entry_cb(handle, reader->entry_userdata, reader->file_info, path);
|
||||
/* Convert to forward slashes for unix which doesn't like backslashes */
|
||||
strncpy(pathwfs, path, sizeof(pathwfs) - 1);
|
||||
pathwfs[sizeof(pathwfs) - 1] = 0;
|
||||
for (i = 0; i < (int32_t)strlen(pathwfs); i += 1)
|
||||
{
|
||||
if (pathwfs[i] == '\\')
|
||||
pathwfs[i] = '/';
|
||||
}
|
||||
|
||||
strncpy(directory, path, sizeof(directory) - 1);
|
||||
if (reader->entry_cb != NULL)
|
||||
reader->entry_cb(handle, reader->entry_userdata, reader->file_info, pathwfs);
|
||||
|
||||
strncpy(directory, pathwfs, sizeof(directory) - 1);
|
||||
directory[sizeof(directory) - 1] = 0;
|
||||
mz_path_remove_filename(directory);
|
||||
|
||||
// If it is a directory entry then create a directory instead of writing file
|
||||
/* If it is a directory entry then create a directory instead of writing file */
|
||||
if (mz_zip_entry_is_dir(reader->zip_handle) == MZ_OK)
|
||||
{
|
||||
err = mz_dir_make(directory);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Check if file exists and ask if we want to overwrite
|
||||
if ((mz_os_file_exists(path) == MZ_OK) && (reader->overwrite_cb != NULL))
|
||||
/* Check if file exists and ask if we want to overwrite */
|
||||
if ((mz_os_file_exists(pathwfs) == MZ_OK) && (reader->overwrite_cb != NULL))
|
||||
{
|
||||
err_cb = reader->overwrite_cb(handle, reader->overwrite_userdata, reader->file_info, path);
|
||||
err_cb = reader->overwrite_cb(handle, reader->overwrite_userdata, reader->file_info, pathwfs);
|
||||
if (err_cb != MZ_OK)
|
||||
return err;
|
||||
mz_os_delete(path);
|
||||
mz_os_delete(pathwfs);
|
||||
}
|
||||
|
||||
// Create the output directory if it doesn't already exist
|
||||
/* Create the output directory if it doesn't already exist */
|
||||
if (mz_os_is_dir(directory) != MZ_OK)
|
||||
{
|
||||
err = mz_dir_make(directory);
|
||||
@@ -775,8 +791,8 @@ int32_t mz_zip_reader_entry_save_file(void *handle, const char *path)
|
||||
|
||||
mz_stream_os_create(&file_stream);
|
||||
|
||||
// Create the file on disk so we can save to it
|
||||
err = mz_stream_os_open(file_stream, path, MZ_OPEN_MODE_CREATE);
|
||||
/* Create the file on disk so we can save to it */
|
||||
err = mz_stream_os_open(file_stream, pathwfs, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
if (err == MZ_OK)
|
||||
err = mz_zip_reader_entry_save(handle, file_stream, mz_stream_os_write);
|
||||
@@ -786,19 +802,19 @@ int32_t mz_zip_reader_entry_save_file(void *handle, const char *path)
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Set the time of the file that has been created
|
||||
mz_os_set_file_date(path, reader->file_info->modified_date,
|
||||
/* Set the time of the file that has been created */
|
||||
mz_os_set_file_date(pathwfs, reader->file_info->modified_date,
|
||||
reader->file_info->accessed_date, reader->file_info->creation_date);
|
||||
}
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Set file attributes for the correct system
|
||||
/* Set file attributes for the correct system */
|
||||
err_attrib = mz_zip_attrib_convert(MZ_HOST_SYSTEM(reader->file_info->version_madeby),
|
||||
reader->file_info->external_fa, MZ_VERSION_MADEBY_HOST_SYSTEM, &target_attrib);
|
||||
|
||||
if (err_attrib == MZ_OK)
|
||||
mz_os_set_file_attribs(path, target_attrib);
|
||||
mz_os_set_file_attribs(pathwfs, target_attrib);
|
||||
}
|
||||
|
||||
return err;
|
||||
@@ -819,7 +835,7 @@ int32_t mz_zip_reader_entry_save_buffer(void *handle, void *buf, int32_t len)
|
||||
if (len != (int32_t)reader->file_info->uncompressed_size)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
// Create a memory stream backed by our buffer and save to it
|
||||
/* Create a memory stream backed by our buffer and save to it */
|
||||
mz_stream_mem_create(&mem_stream);
|
||||
mz_stream_mem_set_buffer(mem_stream, buf, len);
|
||||
|
||||
@@ -842,7 +858,7 @@ int32_t mz_zip_reader_entry_save_buffer_length(void *handle)
|
||||
if (reader->file_info->uncompressed_size > INT32_MAX)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
// Get the maximum size required for the save buffer
|
||||
/* Get the maximum size required for the save buffer */
|
||||
return (int32_t)reader->file_info->uncompressed_size;
|
||||
}
|
||||
|
||||
@@ -861,7 +877,7 @@ int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir)
|
||||
|
||||
while (err == MZ_OK)
|
||||
{
|
||||
// Construct output path
|
||||
/* Construct output path */
|
||||
path[0] = 0;
|
||||
|
||||
strncpy(utf8_name, reader->file_info->filename, sizeof(utf8_name) - 1);
|
||||
@@ -872,7 +888,8 @@ int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir)
|
||||
utf8_string = mz_os_utf8_string_create(reader->file_info->filename, reader->encoding);
|
||||
if (utf8_string)
|
||||
{
|
||||
strncpy(utf8_name, (char *)utf8_string, sizeof(utf8_name));
|
||||
strncpy(utf8_name, (char *)utf8_string, sizeof(utf8_name) - 1);
|
||||
utf8_name[sizeof(utf8_name) - 1] = 0;
|
||||
mz_os_utf8_string_delete(&utf8_string);
|
||||
}
|
||||
}
|
||||
@@ -886,7 +903,7 @@ int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir)
|
||||
|
||||
mz_path_combine(path, resolved_name, sizeof(path));
|
||||
|
||||
// Save file to disk
|
||||
/* Save file to disk */
|
||||
err = mz_zip_reader_entry_save_file(handle, path);
|
||||
|
||||
if (err == MZ_OK)
|
||||
@@ -929,6 +946,25 @@ int32_t mz_zip_reader_get_raw(void *handle, uint8_t *raw)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_zip_reader_get_zip_cd(void *handle, uint8_t *zip_cd)
|
||||
{
|
||||
mz_zip_reader *reader = (mz_zip_reader *)handle;
|
||||
if (zip_cd == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
*zip_cd = reader->cd_zipped;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_zip_reader_get_comment(void *handle, const char **comment)
|
||||
{
|
||||
mz_zip_reader *reader = (mz_zip_reader *)handle;
|
||||
if (mz_zip_reader_is_open(reader) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (comment == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_zip_get_comment(reader->zip_handle, comment);
|
||||
}
|
||||
|
||||
void mz_zip_reader_set_encoding(void *handle, int32_t encoding)
|
||||
{
|
||||
mz_zip_reader *reader = (mz_zip_reader *)handle;
|
||||
@@ -1042,7 +1078,9 @@ typedef struct mz_zip_writer_s {
|
||||
mz_zip_writer_entry_cb
|
||||
entry_cb;
|
||||
const char *password;
|
||||
const char *cert_path;
|
||||
const char *comment;
|
||||
uint8_t *cert_data;
|
||||
int32_t cert_data_size;
|
||||
const char *cert_pwd;
|
||||
uint16_t compress_method;
|
||||
int16_t compress_level;
|
||||
@@ -1092,14 +1130,23 @@ int32_t mz_zip_writer_open_file(void *handle, const char *path, int64_t disk_siz
|
||||
int32_t mode = MZ_OPEN_MODE_READWRITE;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t err_cb = 0;
|
||||
|
||||
char directory[320];
|
||||
|
||||
mz_zip_writer_close(handle);
|
||||
|
||||
if (mz_os_file_exists(path) != MZ_OK)
|
||||
{
|
||||
// If the file doesn't exist, we don't append file
|
||||
/* If the file doesn't exist, we don't append file */
|
||||
mode |= MZ_OPEN_MODE_CREATE;
|
||||
|
||||
/* Create destination directory if it doesn't already exist */
|
||||
if (strchr(path, '/') != NULL || strrchr(path, '\\') != NULL)
|
||||
{
|
||||
strncpy(directory, path, sizeof(directory));
|
||||
mz_path_remove_filename(directory);
|
||||
if (mz_os_file_exists(directory) != MZ_OK)
|
||||
mz_os_make_dir(directory);
|
||||
}
|
||||
}
|
||||
else if (append)
|
||||
{
|
||||
@@ -1156,13 +1203,13 @@ int32_t mz_zip_writer_open_file_in_memory(void *handle, const char *path)
|
||||
return err;
|
||||
}
|
||||
|
||||
mz_stream_os_seek(file_stream, 0, SEEK_END);
|
||||
mz_stream_os_seek(file_stream, 0, MZ_SEEK_END);
|
||||
file_size = mz_stream_os_tell(file_stream);
|
||||
mz_stream_os_seek(file_stream, 0, SEEK_SET);
|
||||
mz_stream_os_seek(file_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
if ((file_size <= 0) || (file_size > UINT32_MAX))
|
||||
{
|
||||
// Memory size is too large or too small
|
||||
/* Memory size is too large or too small */
|
||||
|
||||
mz_stream_os_close(file_stream);
|
||||
mz_stream_os_delete(&file_stream);
|
||||
@@ -1192,13 +1239,15 @@ int32_t mz_zip_writer_close(void *handle)
|
||||
mz_zip_writer *writer = (mz_zip_writer *)handle;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
|
||||
if (writer->zip_cd)
|
||||
mz_zip_writer_zip_cd(writer);
|
||||
|
||||
if (writer->zip_handle != NULL)
|
||||
{
|
||||
mz_zip_set_version_madeby(writer->zip_handle, MZ_VERSION_MADEBY);
|
||||
if (writer->comment)
|
||||
mz_zip_set_comment(writer->zip_handle, writer->comment);
|
||||
if (writer->zip_cd)
|
||||
mz_zip_writer_zip_cd(writer);
|
||||
|
||||
err = mz_zip_close(writer->zip_handle);
|
||||
mz_zip_delete(&writer->zip_handle);
|
||||
}
|
||||
@@ -1220,7 +1269,7 @@ int32_t mz_zip_writer_close(void *handle)
|
||||
mz_stream_mem_close(writer->mem_stream);
|
||||
mz_stream_mem_delete(&writer->mem_stream);
|
||||
}
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1270,11 +1319,13 @@ int32_t mz_zip_writer_zip_cd(void *handle)
|
||||
err = mz_zip_writer_entry_open(handle, &cd_file);
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
mz_stream_copy_stream(handle, mz_zip_writer_entry_write, cd_mem_stream, NULL, (int32_t)cd_mem_length);
|
||||
mz_stream_copy_stream(handle, mz_zip_writer_entry_write, cd_mem_stream,
|
||||
NULL, (int32_t)cd_mem_length);
|
||||
|
||||
mz_stream_seek(cd_mem_stream, 0, MZ_SEEK_SET);
|
||||
mz_stream_mem_set_buffer_limit(cd_mem_stream, 0);
|
||||
|
||||
err = mz_zip_entry_close(writer->zip_handle);
|
||||
err = mz_zip_writer_entry_close(writer);
|
||||
}
|
||||
|
||||
mz_stream_mem_delete(&file_extra_stream);
|
||||
@@ -1291,7 +1342,7 @@ int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info)
|
||||
const char *password = NULL;
|
||||
char password_buf[120];
|
||||
|
||||
// Copy file info to access data upon close
|
||||
/* Copy file info to access data upon close */
|
||||
memcpy(&writer->file_info, file_info, sizeof(mz_zip_file));
|
||||
|
||||
if (writer->entry_cb != NULL)
|
||||
@@ -1299,7 +1350,7 @@ int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info)
|
||||
|
||||
password = writer->password;
|
||||
|
||||
// Check if we need a password and ask for it if we need to
|
||||
/* Check if we need a password and ask for it if we need to */
|
||||
if ((writer->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (password == NULL) &&
|
||||
(writer->password_cb != NULL))
|
||||
{
|
||||
@@ -1311,14 +1362,14 @@ int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info)
|
||||
#ifndef MZ_ZIP_NO_ENCRYPTION
|
||||
if (mz_zip_attrib_is_dir(writer->file_info.external_fa, writer->file_info.version_madeby) != MZ_OK)
|
||||
{
|
||||
// Start calculating sha256
|
||||
/* Start calculating sha256 */
|
||||
mz_crypt_sha_create(&writer->sha256);
|
||||
mz_crypt_sha_set_algorithm(writer->sha256, MZ_HASH_SHA256);
|
||||
mz_crypt_sha_begin(writer->sha256);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Open entry in zip
|
||||
/* Open entry in zip */
|
||||
err = mz_zip_entry_write_open(writer->zip_handle, &writer->file_info, writer->compress_level,
|
||||
writer->raw, password);
|
||||
|
||||
@@ -1332,7 +1383,7 @@ int32_t mz_zip_writer_entry_close(void *handle)
|
||||
#ifndef MZ_ZIP_NO_ENCRYPTION
|
||||
const uint8_t *extrafield = NULL;
|
||||
int32_t extrafield_size = 0;
|
||||
int32_t field_length_hash = 0;
|
||||
int16_t field_length_hash = 0;
|
||||
uint8_t sha256[MZ_HASH_SHA256_SIZE];
|
||||
|
||||
|
||||
@@ -1341,11 +1392,11 @@ int32_t mz_zip_writer_entry_close(void *handle)
|
||||
mz_crypt_sha_end(writer->sha256, sha256, sizeof(sha256));
|
||||
mz_crypt_sha_delete(&writer->sha256);
|
||||
|
||||
// Copy extrafield so we can append our own fields before close
|
||||
/* Copy extrafield so we can append our own fields before close */
|
||||
mz_stream_mem_create(&writer->file_extra_stream);
|
||||
mz_stream_mem_open(writer->file_extra_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
// Write sha256 hash to extrafield
|
||||
/* Write sha256 hash to extrafield */
|
||||
field_length_hash = 4 + MZ_HASH_SHA256_SIZE;
|
||||
err = mz_zip_extrafield_write(writer->file_extra_stream, MZ_ZIP_EXTENSION_HASH, field_length_hash);
|
||||
if (err == MZ_OK)
|
||||
@@ -1359,16 +1410,22 @@ int32_t mz_zip_writer_entry_close(void *handle)
|
||||
}
|
||||
|
||||
#ifndef MZ_ZIP_NO_SIGNING
|
||||
if (writer->cert_path != NULL)
|
||||
err = mz_zip_writer_entry_sign(handle, sha256, sizeof(sha256),
|
||||
writer->cert_path, writer->cert_pwd);
|
||||
if ((err == MZ_OK) && (writer->cert_data != NULL) && (writer->cert_data_size > 0))
|
||||
{
|
||||
/* Sign entry if not zipping cd or if it is cd being zipped */
|
||||
if (!writer->zip_cd || strcmp(writer->file_info.filename, MZ_ZIP_CD_FILENAME) == 0)
|
||||
{
|
||||
err = mz_zip_writer_entry_sign(handle, sha256, sizeof(sha256),
|
||||
writer->cert_data, writer->cert_data_size, writer->cert_pwd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((writer->file_info.extrafield != NULL) && (writer->file_info.extrafield_size > 0))
|
||||
mz_stream_mem_write(writer->file_extra_stream, writer->file_info.extrafield,
|
||||
writer->file_info.extrafield_size);
|
||||
|
||||
// Update extra field for central directory after adding extra fields
|
||||
/* Update extra field for central directory after adding extra fields */
|
||||
mz_stream_mem_get_buffer(writer->file_extra_stream, (const void **)&extrafield);
|
||||
mz_stream_mem_get_buffer_length(writer->file_extra_stream, &extrafield_size);
|
||||
|
||||
@@ -1376,12 +1433,15 @@ int32_t mz_zip_writer_entry_close(void *handle)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (writer->raw)
|
||||
err = mz_zip_entry_close_raw(writer->zip_handle, writer->file_info.uncompressed_size,
|
||||
writer->file_info.crc);
|
||||
else
|
||||
err = mz_zip_entry_close(writer->zip_handle);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (writer->raw)
|
||||
err = mz_zip_entry_close_raw(writer->zip_handle, writer->file_info.uncompressed_size,
|
||||
writer->file_info.crc);
|
||||
else
|
||||
err = mz_zip_entry_close(writer->zip_handle);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1399,57 +1459,29 @@ int32_t mz_zip_writer_entry_write(void *handle, const void *buf, int32_t len)
|
||||
|
||||
#if !defined(MZ_ZIP_NO_ENCRYPTION) && !defined(MZ_ZIP_NO_SIGNING)
|
||||
int32_t mz_zip_writer_entry_sign(void *handle, uint8_t *message, int32_t message_size,
|
||||
const char *cert_path, const char *cert_pwd)
|
||||
uint8_t *cert_data, int32_t cert_data_size, const char *cert_pwd)
|
||||
{
|
||||
mz_zip_writer *writer = (mz_zip_writer *)handle;
|
||||
void *cert_stream = NULL;
|
||||
uint8_t *cert_data = NULL;
|
||||
int32_t cert_data_size = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t signature_size = 0;
|
||||
uint8_t *signature = NULL;
|
||||
|
||||
|
||||
if (writer == NULL || mz_zip_entry_is_open(writer->zip_handle) != MZ_OK)
|
||||
if (writer == NULL || cert_data == NULL || cert_data_size <= 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (cert_path == NULL)
|
||||
{
|
||||
cert_path = writer->cert_path;
|
||||
cert_pwd = writer->cert_pwd;
|
||||
}
|
||||
if (cert_path == NULL)
|
||||
if (mz_zip_entry_is_open(writer->zip_handle) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
cert_data_size = (int32_t)mz_os_get_file_size(cert_path);
|
||||
if (cert_data_size == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
cert_data = (uint8_t *)MZ_ALLOC(cert_data_size);
|
||||
|
||||
// Read pkcs12 certificate from disk
|
||||
mz_stream_os_create(&cert_stream);
|
||||
err = mz_stream_os_open(cert_stream, cert_path, MZ_OPEN_MODE_READ);
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (mz_stream_os_read(cert_stream, cert_data, cert_data_size) != cert_data_size)
|
||||
err = MZ_READ_ERROR;
|
||||
mz_stream_os_close(cert_stream);
|
||||
}
|
||||
mz_stream_os_delete(&cert_stream);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Sign message with certificate
|
||||
err = mz_crypt_sign(message, message_size, cert_data, cert_data_size, cert_pwd,
|
||||
&signature, &signature_size);
|
||||
}
|
||||
|
||||
MZ_FREE(cert_data);
|
||||
/* Sign message with certificate */
|
||||
err = mz_crypt_sign(message, message_size, cert_data, cert_data_size, cert_pwd,
|
||||
&signature, &signature_size);
|
||||
|
||||
if ((err == MZ_OK) && (signature != NULL))
|
||||
{
|
||||
// Write signature zip extra field
|
||||
err = mz_zip_extrafield_write(writer->file_extra_stream, MZ_ZIP_EXTENSION_SIGN, signature_size);
|
||||
/* Write signature zip extra field */
|
||||
err = mz_zip_extrafield_write(writer->file_extra_stream, MZ_ZIP_EXTENSION_SIGN,
|
||||
(uint16_t)signature_size);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (mz_stream_write(writer->file_extra_stream, signature, signature_size) != signature_size)
|
||||
@@ -1458,6 +1490,7 @@ int32_t mz_zip_writer_entry_sign(void *handle, uint8_t *message, int32_t message
|
||||
|
||||
MZ_FREE(signature);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
@@ -1473,7 +1506,7 @@ int32_t mz_zip_writer_add_process(void *handle, void *stream, mz_stream_read_cb
|
||||
|
||||
if (mz_zip_writer_is_open(writer) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
// If the entry isn't open for writing, open it
|
||||
/* If the entry isn't open for writing, open it */
|
||||
if (mz_zip_entry_is_open(writer->zip_handle) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (read_cb == NULL)
|
||||
@@ -1505,11 +1538,11 @@ int32_t mz_zip_writer_add(void *handle, void *stream, mz_stream_read_cb read_cb)
|
||||
int32_t err = MZ_OK;
|
||||
int32_t written = 0;
|
||||
|
||||
// Update the progress at the beginning
|
||||
/* Update the progress at the beginning */
|
||||
if (writer->progress_cb != NULL)
|
||||
writer->progress_cb(handle, writer->progress_userdata, &writer->file_info, current_pos);
|
||||
|
||||
// Write data to stream until done
|
||||
/* Write data to stream until done */
|
||||
while (err == MZ_OK)
|
||||
{
|
||||
written = mz_zip_writer_add_process(handle, stream, read_cb);
|
||||
@@ -1520,7 +1553,7 @@ int32_t mz_zip_writer_add(void *handle, void *stream, mz_stream_read_cb read_cb)
|
||||
if (written < 0)
|
||||
err = written;
|
||||
|
||||
// Update progress if enough time have passed
|
||||
/* Update progress if enough time have passed */
|
||||
current_time = mz_os_ms_time();
|
||||
if ((current_time - update_time) > writer->progress_cb_interval_ms)
|
||||
{
|
||||
@@ -1532,7 +1565,7 @@ int32_t mz_zip_writer_add(void *handle, void *stream, mz_stream_read_cb read_cb)
|
||||
}
|
||||
}
|
||||
|
||||
// Update the progress at the end
|
||||
/* Update the progress at the end */
|
||||
if (writer->progress_cb != NULL && update_pos != current_pos)
|
||||
writer->progress_cb(handle, writer->progress_userdata, &writer->file_info, current_pos);
|
||||
|
||||
@@ -1550,7 +1583,7 @@ int32_t mz_zip_writer_add_info(void *handle, void *stream, mz_stream_read_cb rea
|
||||
if (file_info == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
// Add to zip
|
||||
/* Add to zip */
|
||||
err = mz_zip_writer_entry_open(handle, file_info);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
@@ -1580,7 +1613,7 @@ int32_t mz_zip_writer_add_buffer(void *handle, void *buf, int32_t len, mz_zip_fi
|
||||
if (buf == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
// Create a memory stream backed by our buffer and add from it
|
||||
/* Create a memory stream backed by our buffer and add from it */
|
||||
mz_stream_mem_create(&mem_stream);
|
||||
mz_stream_mem_set_buffer(mem_stream, buf, len);
|
||||
|
||||
@@ -1618,13 +1651,13 @@ int32_t mz_zip_writer_add_file(void *handle, const char *path, const char *filen
|
||||
|
||||
memset(&file_info, 0, sizeof(file_info));
|
||||
|
||||
// The path name saved, should not include a leading slash.
|
||||
// If it did, windows/xp and dynazip couldn't read the zip file.
|
||||
/* The path name saved, should not include a leading slash. */
|
||||
/* If it did, windows/xp and dynazip couldn't read the zip file. */
|
||||
|
||||
while (filename[0] == '\\' || filename[0] == '/')
|
||||
filename += 1;
|
||||
|
||||
// Get information about the file on disk so we can store it in zip
|
||||
/* Get information about the file on disk so we can store it in zip */
|
||||
|
||||
file_info.version_madeby = MZ_VERSION_MADEBY;
|
||||
file_info.compression_method = writer->compress_method;
|
||||
@@ -1634,11 +1667,8 @@ int32_t mz_zip_writer_add_file(void *handle, const char *path, const char *filen
|
||||
|
||||
if (writer->zip_cd)
|
||||
file_info.flag |= MZ_ZIP_FLAG_MASK_LOCAL_INFO;
|
||||
|
||||
#ifdef HAVE_AES
|
||||
if (writer->aes)
|
||||
file_info.aes_version = MZ_AES_VERSION;
|
||||
#endif
|
||||
|
||||
mz_os_get_file_date(path, &file_info.modified_date, &file_info.accessed_date,
|
||||
&file_info.creation_date);
|
||||
@@ -1648,7 +1678,7 @@ int32_t mz_zip_writer_add_file(void *handle, const char *path, const char *filen
|
||||
|
||||
if ((src_sys != MZ_HOST_SYSTEM_MSDOS) && (src_sys != MZ_HOST_SYSTEM_WINDOWS_NTFS))
|
||||
{
|
||||
// High bytes are OS specific attributes, low byte is always DOS attributes
|
||||
/* High bytes are OS specific attributes, low byte is always DOS attributes */
|
||||
if (mz_zip_attrib_convert(src_sys, src_attrib, MZ_HOST_SYSTEM_MSDOS, &target_attrib) == MZ_OK)
|
||||
file_info.external_fa = target_attrib;
|
||||
file_info.external_fa |= (src_attrib << 16);
|
||||
@@ -1676,8 +1706,8 @@ int32_t mz_zip_writer_add_file(void *handle, const char *path, const char *filen
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_zip_writer_add_path(void *handle, const char *path, const char *root_path, uint8_t include_path,
|
||||
uint8_t recursive)
|
||||
int32_t mz_zip_writer_add_path(void *handle, const char *path, const char *root_path,
|
||||
uint8_t include_path, uint8_t recursive)
|
||||
{
|
||||
DIR *dir = NULL;
|
||||
struct dirent *entry = NULL;
|
||||
@@ -1703,11 +1733,11 @@ int32_t mz_zip_writer_add_path(void *handle, const char *path, const char *root_
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct the filename that our file will be stored in the zip as
|
||||
/* 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?
|
||||
/* Should the file be stored with any path info at all? */
|
||||
if (!include_path)
|
||||
{
|
||||
if (!is_dir && root_path == path)
|
||||
@@ -1760,9 +1790,13 @@ int32_t mz_zip_writer_copy_from_reader(void *handle, void *reader)
|
||||
{
|
||||
mz_zip_writer *writer = (mz_zip_writer *)handle;
|
||||
mz_zip_file *file_info = NULL;
|
||||
int64_t compressed_size = 0;
|
||||
int64_t uncompressed_size = 0;
|
||||
uint32_t crc32 = 0;
|
||||
int32_t err = MZ_OK;
|
||||
uint8_t original_raw = 0;
|
||||
void *reader_zip_handle = NULL;
|
||||
void *writer_zip_handle = NULL;
|
||||
|
||||
|
||||
if (mz_zip_reader_is_open(reader) != MZ_OK)
|
||||
@@ -1771,24 +1805,44 @@ int32_t mz_zip_writer_copy_from_reader(void *handle, void *reader)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
err = mz_zip_reader_entry_get_info(reader, &file_info);
|
||||
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
mz_zip_reader_get_zip_handle(reader, &reader_zip_handle);
|
||||
mz_zip_writer_get_zip_handle(writer, &writer_zip_handle);
|
||||
|
||||
// Open entry for raw reading
|
||||
/* Open entry for raw reading */
|
||||
err = mz_zip_entry_read_open(reader_zip_handle, 1, NULL);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Write entry raw, save original raw value
|
||||
/* Write entry raw, save original raw value */
|
||||
original_raw = writer->raw;
|
||||
writer->raw = 1;
|
||||
|
||||
err = mz_zip_writer_add_info(writer, reader_zip_handle, mz_zip_entry_read, file_info);
|
||||
err = mz_zip_writer_entry_open(writer, file_info);
|
||||
|
||||
if ((err == MZ_OK) &&
|
||||
(mz_zip_attrib_is_dir(writer->file_info.external_fa, writer->file_info.version_madeby) != MZ_OK))
|
||||
{
|
||||
err = mz_zip_writer_add(writer, reader_zip_handle, mz_zip_entry_read);
|
||||
}
|
||||
|
||||
if ((err == MZ_OK) && (file_info->flag & MZ_ZIP_FLAG_DATA_DESCRIPTOR))
|
||||
{
|
||||
err = mz_zip_entry_read_close(reader_zip_handle, &crc32, &compressed_size, &uncompressed_size);
|
||||
if (err == MZ_OK)
|
||||
err = mz_zip_entry_write_close(writer_zip_handle, crc32, compressed_size, uncompressed_size);
|
||||
}
|
||||
|
||||
if (mz_zip_entry_is_open(reader_zip_handle) == MZ_OK)
|
||||
mz_zip_entry_close(reader_zip_handle);
|
||||
|
||||
if (mz_zip_entry_is_open(writer_zip_handle) == MZ_OK)
|
||||
mz_zip_entry_close(writer_zip_handle);
|
||||
|
||||
writer->raw = original_raw;
|
||||
|
||||
mz_zip_entry_close(reader_zip_handle);
|
||||
}
|
||||
|
||||
return err;
|
||||
@@ -1802,6 +1856,12 @@ void mz_zip_writer_set_password(void *handle, const char *password)
|
||||
writer->password = password;
|
||||
}
|
||||
|
||||
void mz_zip_writer_set_comment(void *handle, const char *comment)
|
||||
{
|
||||
mz_zip_writer *writer = (mz_zip_writer *)handle;
|
||||
writer->comment = comment;
|
||||
}
|
||||
|
||||
void mz_zip_writer_set_raw(void *handle, uint8_t raw)
|
||||
{
|
||||
mz_zip_writer *writer = (mz_zip_writer *)handle;
|
||||
@@ -1841,11 +1901,53 @@ void mz_zip_writer_set_zip_cd(void *handle, uint8_t zip_cd)
|
||||
writer->zip_cd = zip_cd;
|
||||
}
|
||||
|
||||
void mz_zip_writer_set_certificate(void *handle, const char *cert_path, const char *cert_pwd)
|
||||
int32_t mz_zip_writer_set_certificate(void *handle, const char *cert_path, const char *cert_pwd)
|
||||
{
|
||||
mz_zip_writer *writer = (mz_zip_writer *)handle;
|
||||
writer->cert_path = cert_path;
|
||||
writer->cert_pwd = cert_pwd;
|
||||
void *cert_stream = NULL;
|
||||
uint8_t *cert_data = NULL;
|
||||
int32_t cert_data_size = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (cert_path == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
cert_data_size = (int32_t)mz_os_get_file_size(cert_path);
|
||||
|
||||
if (cert_data_size == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (writer->cert_data != NULL)
|
||||
{
|
||||
MZ_FREE(writer->cert_data);
|
||||
writer->cert_data = NULL;
|
||||
}
|
||||
|
||||
cert_data = (uint8_t *)MZ_ALLOC(cert_data_size);
|
||||
|
||||
/* Read pkcs12 certificate from disk */
|
||||
mz_stream_os_create(&cert_stream);
|
||||
err = mz_stream_os_open(cert_stream, cert_path, MZ_OPEN_MODE_READ);
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (mz_stream_os_read(cert_stream, cert_data, cert_data_size) != cert_data_size)
|
||||
err = MZ_READ_ERROR;
|
||||
mz_stream_os_close(cert_stream);
|
||||
}
|
||||
mz_stream_os_delete(&cert_stream);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
writer->cert_data = cert_data;
|
||||
writer->cert_data_size = cert_data_size;
|
||||
writer->cert_pwd = cert_pwd;
|
||||
}
|
||||
else
|
||||
{
|
||||
MZ_FREE(cert_data);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void mz_zip_writer_set_overwrite_cb(void *handle, void *userdata, mz_zip_writer_overwrite_cb cb)
|
||||
@@ -1903,9 +2005,18 @@ void *mz_zip_writer_create(void **handle)
|
||||
if (writer != NULL)
|
||||
{
|
||||
memset(writer, 0, sizeof(mz_zip_writer));
|
||||
|
||||
#if defined(HAVE_WZAES)
|
||||
writer->aes = 1;
|
||||
#endif
|
||||
#if defined(HAVE_ZLIB) || defined(HAVE_LIBCOMP)
|
||||
writer->compress_method = MZ_COMPRESS_METHOD_DEFLATE;
|
||||
#elif defined(HAVE_BZIP2)
|
||||
writer->compress_method = MZ_COMPRESS_METHOD_BZIP2;
|
||||
#elif defined(HAVE_LZMA)
|
||||
writer->compress_method = MZ_COMPRESS_METHOD_LZMA;
|
||||
#else
|
||||
writer->compress_method = MZ_COMPRESS_METHOD_STORE;
|
||||
#endif
|
||||
writer->compress_level = MZ_COMPRESS_LEVEL_BEST;
|
||||
writer->progress_cb_interval_ms = MZ_DEFAULT_PROGRESS_INTERVAL;
|
||||
|
||||
@@ -1924,6 +2035,13 @@ void mz_zip_writer_delete(void **handle)
|
||||
if (writer != NULL)
|
||||
{
|
||||
mz_zip_writer_close(writer);
|
||||
|
||||
if (writer->cert_data != NULL)
|
||||
MZ_FREE(writer->cert_data);
|
||||
|
||||
writer->cert_data = NULL;
|
||||
writer->cert_data_size = 0;
|
||||
|
||||
MZ_FREE(writer);
|
||||
}
|
||||
*handle = NULL;
|
||||
|
||||
+86
-81
@@ -1,8 +1,8 @@
|
||||
/* mz_zip_rw.h -- Zip reader/writer
|
||||
Version 2.7.2, November 2, 2018
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -12,14 +12,10 @@
|
||||
#ifndef MZ_ZIP_RW_H
|
||||
#define MZ_ZIP_RW_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "mz_zip.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef int32_t (*mz_zip_reader_overwrite_cb)(void *handle, void *userdata, mz_zip_file *file_info, const char *path);
|
||||
@@ -30,129 +26,135 @@ typedef int32_t (*mz_zip_reader_entry_cb)(void *handle, void *userdata, mz_zip_f
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_reader_is_open(void *handle);
|
||||
// Checks to see if the zip file is open
|
||||
/* Checks to see if the zip file is open */
|
||||
|
||||
int32_t mz_zip_reader_open(void *handle, void *stream);
|
||||
// Opens zip file from stream
|
||||
/* Opens zip file from stream */
|
||||
|
||||
int32_t mz_zip_reader_open_file(void *handle, const char *path);
|
||||
// Opens zip file from a file path
|
||||
/* Opens zip file from a file path */
|
||||
|
||||
int32_t mz_zip_reader_open_file_in_memory(void *handle, const char *path);
|
||||
// Opens zip file from a file path into memory for faster access
|
||||
/* Opens zip file from a file path into memory for faster access */
|
||||
|
||||
int32_t mz_zip_reader_open_buffer(void *handle, uint8_t *buf, int32_t len, uint8_t copy);
|
||||
// Opens zip file from memory buffer
|
||||
/* Opens zip file from memory buffer */
|
||||
|
||||
int32_t mz_zip_reader_close(void *handle);
|
||||
// Closes the zip file
|
||||
/* Closes the zip file */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_reader_unzip_cd(void *handle);
|
||||
// Unzip the central directory
|
||||
/* Unzip the central directory */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_reader_goto_first_entry(void *handle);
|
||||
// Goto the first entry in the zip file that matches the pattern
|
||||
/* Goto the first entry in the zip file that matches the pattern */
|
||||
|
||||
int32_t mz_zip_reader_goto_next_entry(void *handle);
|
||||
// Goto the next entry in the zip file that matches the pattern
|
||||
/* Goto the next entry in the zip file that matches the pattern */
|
||||
|
||||
int32_t mz_zip_reader_locate_entry(void *handle, const char *filename, uint8_t ignore_case);
|
||||
// Locates an entry by filename
|
||||
/* Locates an entry by filename */
|
||||
|
||||
int32_t mz_zip_reader_entry_open(void *handle);
|
||||
// Opens an entry for reading
|
||||
/* Opens an entry for reading */
|
||||
|
||||
int32_t mz_zip_reader_entry_close(void *handle);
|
||||
// Closes an entry
|
||||
/* Closes an entry */
|
||||
|
||||
int32_t mz_zip_reader_entry_read(void *handle, void *buf, int32_t len);
|
||||
// Reads and entry after being opened
|
||||
/* Reads and entry after being opened */
|
||||
|
||||
int32_t mz_zip_reader_entry_has_sign(void *handle);
|
||||
// Checks to see if the entry has a signature
|
||||
/* Checks to see if the entry has a signature */
|
||||
|
||||
int32_t mz_zip_reader_entry_sign_verify(void *handle);
|
||||
// Verifies a signature stored with the entry
|
||||
/* Verifies a signature stored with the entry */
|
||||
|
||||
int32_t mz_zip_reader_entry_get_hash(void *handle, uint16_t algorithm, uint8_t *digest, int32_t digest_size);
|
||||
// Gets a hash algorithm from the entry's extra field
|
||||
/* Gets a hash algorithm from the entry's extra field */
|
||||
|
||||
int32_t mz_zip_reader_entry_get_first_hash(void *handle, uint16_t *algorithm, uint16_t *digest_size);
|
||||
// Gets the most secure hash algorithm from the entry's extra field
|
||||
/* Gets the most secure hash algorithm from the entry's extra field */
|
||||
|
||||
int32_t mz_zip_reader_entry_get_info(void *handle, mz_zip_file **file_info);
|
||||
// Gets the current entry file info
|
||||
/* Gets the current entry file info */
|
||||
|
||||
int32_t mz_zip_reader_entry_is_dir(void *handle);
|
||||
// Gets the current entry is a directory
|
||||
/* Gets the current entry is a directory */
|
||||
|
||||
int32_t mz_zip_reader_entry_save(void *handle, void *stream, mz_stream_write_cb write_cb);
|
||||
// Save the current entry to a steam
|
||||
/* Save the current entry to a steam */
|
||||
|
||||
int32_t mz_zip_reader_entry_save_process(void *handle, void *stream, mz_stream_write_cb write_cb);
|
||||
// Saves a portion of the current entry to a stream callback
|
||||
/* Saves a portion of the current entry to a stream callback */
|
||||
|
||||
int32_t mz_zip_reader_entry_save_file(void *handle, const char *path);
|
||||
// Save the current entry to a file
|
||||
/* Save the current entry to a file */
|
||||
|
||||
int32_t mz_zip_reader_entry_save_buffer(void *handle, void *buf, int32_t len);
|
||||
// Save the current entry to a memory buffer
|
||||
/* Save the current entry to a memory buffer */
|
||||
|
||||
int32_t mz_zip_reader_entry_save_buffer_length(void *handle);
|
||||
// Gets the length of the buffer required to save
|
||||
/* Gets the length of the buffer required to save */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_reader_save_all(void *handle, const char *destination_dir);
|
||||
// Save all files into a directory
|
||||
/* Save all files into a directory */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void mz_zip_reader_set_pattern(void *handle, const char *pattern, uint8_t ignore_case);
|
||||
// Sets the match pattern for entries in the zip file, if null all entries are matched
|
||||
/* Sets the match pattern for entries in the zip file, if null all entries are matched */
|
||||
|
||||
void mz_zip_reader_set_password(void *handle, const char *password);
|
||||
// Sets the password required for extraction
|
||||
/* Sets the password required for extraction */
|
||||
|
||||
void mz_zip_reader_set_raw(void *handle, uint8_t raw);
|
||||
// Sets whether or not it should save the entry raw
|
||||
/* Sets whether or not it should save the entry raw */
|
||||
|
||||
int32_t mz_zip_reader_get_raw(void *handle, uint8_t *raw);
|
||||
// Gets whether or not it should save the entry raw
|
||||
/* Gets whether or not it should save the entry raw */
|
||||
|
||||
int32_t mz_zip_reader_get_zip_cd(void *handle, uint8_t *zip_cd);
|
||||
/* Gets whether or not the archive has zipped cd */
|
||||
|
||||
int32_t mz_zip_reader_get_comment(void *handle, const char **comment);
|
||||
/* Gets the comment for the central directory */
|
||||
|
||||
void mz_zip_reader_set_encoding(void *handle, int32_t encoding);
|
||||
// Sets whether or not it should support cp437 in zip file names
|
||||
/* Sets whether or not it should support cp437 in zip file names */
|
||||
|
||||
void mz_zip_reader_set_sign_required(void *handle, uint8_t sign_required);
|
||||
// Sets whether or not it a signature is required
|
||||
/* Sets whether or not it a signature is required */
|
||||
|
||||
void mz_zip_reader_set_overwrite_cb(void *handle, void *userdata, mz_zip_reader_overwrite_cb cb);
|
||||
// Callback for what to do when a file is being overwritten
|
||||
/* Callback for what to do when a file is being overwritten */
|
||||
|
||||
void mz_zip_reader_set_password_cb(void *handle, void *userdata, mz_zip_reader_password_cb cb);
|
||||
// Callback for when a password is required and hasn't been set
|
||||
/* Callback for when a password is required and hasn't been set */
|
||||
|
||||
void mz_zip_reader_set_progress_cb(void *handle, void *userdata, mz_zip_reader_progress_cb cb);
|
||||
// Callback for extraction progress
|
||||
/* Callback for extraction progress */
|
||||
|
||||
void mz_zip_reader_set_progress_interval(void *handle, uint32_t milliseconds);
|
||||
// Let at least milliseconds pass between calls to progress callback
|
||||
/* Let at least milliseconds pass between calls to progress callback */
|
||||
|
||||
void mz_zip_reader_set_entry_cb(void *handle, void *userdata, mz_zip_reader_entry_cb cb);
|
||||
// Callback for zip file entries
|
||||
/* Callback for zip file entries */
|
||||
|
||||
int32_t mz_zip_reader_get_zip_handle(void *handle, void **zip_handle);
|
||||
// Gets the underlying zip instance handle
|
||||
/* Gets the underlying zip instance handle */
|
||||
|
||||
void* mz_zip_reader_create(void **handle);
|
||||
// Create new instance of zip reader
|
||||
/* Create new instance of zip reader */
|
||||
|
||||
void mz_zip_reader_delete(void **handle);
|
||||
// Delete instance of zip reader
|
||||
/* Delete instance of zip reader */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -164,113 +166,116 @@ typedef int32_t (*mz_zip_writer_entry_cb)(void *handle, void *userdata, mz_zip_f
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_writer_is_open(void *handle);
|
||||
// Checks to see if the zip file is open
|
||||
/* Checks to see if the zip file is open */
|
||||
|
||||
int32_t mz_zip_writer_open(void *handle, void *stream);
|
||||
// Opens zip file from stream
|
||||
/* Opens zip file from stream */
|
||||
|
||||
int32_t mz_zip_writer_open_file(void *handle, const char *path, int64_t disk_size, uint8_t append);
|
||||
// Opens zip file from a file path
|
||||
/* Opens zip file from a file path */
|
||||
|
||||
int32_t mz_zip_writer_open_file_in_memory(void *handle, const char *path);
|
||||
// Opens zip file from a file path into memory for faster access
|
||||
/* Opens zip file from a file path into memory for faster access */
|
||||
|
||||
int32_t mz_zip_writer_close(void *handle);
|
||||
// Closes the zip file
|
||||
/* Closes the zip file */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_writer_zip_cd(void *handle);
|
||||
// Zip the central directory
|
||||
/* Zip the central directory */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info);
|
||||
// Opens an entry in the zip file for writing
|
||||
/* Opens an entry in the zip file for writing */
|
||||
|
||||
int32_t mz_zip_writer_entry_close(void *handle);
|
||||
// Closes entry in zip file
|
||||
/* Closes entry in zip file */
|
||||
|
||||
int32_t mz_zip_writer_entry_write(void *handle, const void *buf, int32_t len);
|
||||
// Writes data into entry for zip
|
||||
/* Writes data into entry for zip */
|
||||
|
||||
int32_t mz_zip_writer_entry_sign(void *handle, uint8_t *message, int32_t message_size,
|
||||
const char *cert_path, const char *cert_pwd);
|
||||
// Signs uncompressed content of entry, call before closing
|
||||
uint8_t *cert_data, int32_t cert_data_size, const char *cert_pwd);
|
||||
/* Signs uncompressed content of entry, call before closing */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_writer_add(void *handle, void *stream, mz_stream_read_cb read_cb);
|
||||
// Writes all data to the currently open entry in the zip
|
||||
/* Writes all data to the currently open entry in the zip */
|
||||
|
||||
int32_t mz_zip_writer_add_process(void *handle, void *stream, mz_stream_read_cb read_cb);
|
||||
// Writes a portion of data to the currently open entry in the zip
|
||||
/* Writes a portion of data to the currently open entry in the zip */
|
||||
|
||||
int32_t mz_zip_writer_add_info(void *handle, void *stream, mz_stream_read_cb read_cb, mz_zip_file *file_info);
|
||||
// Adds an entry to the zip based on the info
|
||||
/* Adds an entry to the zip based on the info */
|
||||
|
||||
int32_t mz_zip_writer_add_buffer(void *handle, void *buf, int32_t len, mz_zip_file *file_info);
|
||||
// Adds an entry to the zip with a memory buffer
|
||||
/* Adds an entry to the zip with a memory buffer */
|
||||
|
||||
int32_t mz_zip_writer_add_file(void *handle, const char *path, const char *filename_in_zip);
|
||||
// Adds an entry to the zip from a file
|
||||
/* Adds an entry to the zip from a file */
|
||||
|
||||
int32_t mz_zip_writer_add_path(void *handle, const char *path, const char *root_path, uint8_t include_path,
|
||||
uint8_t recursive);
|
||||
// Enumerates a directory or pattern and adds entries to the zip
|
||||
/* Enumerates a directory or pattern and adds entries to the zip */
|
||||
|
||||
int32_t mz_zip_writer_copy_from_reader(void *handle, void *reader);
|
||||
// Adds an entry from a zip reader instance
|
||||
/* Adds an entry from a zip reader instance */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void mz_zip_writer_set_password(void *handle, const char *password);
|
||||
// Password to use for encrypting files in the zip
|
||||
/* Password to use for encrypting files in the zip */
|
||||
|
||||
void mz_zip_writer_set_comment(void *handle, const char *comment);
|
||||
/* Comment to use for the archive */
|
||||
|
||||
void mz_zip_writer_set_raw(void *handle, uint8_t raw);
|
||||
// Sets whether or not we should write the entry raw
|
||||
/* Sets whether or not we should write the entry raw */
|
||||
|
||||
int32_t mz_zip_writer_get_raw(void *handle, uint8_t *raw);
|
||||
// Gets whether or not we should write the entry raw
|
||||
/* Gets whether or not we should write the entry raw */
|
||||
|
||||
void mz_zip_writer_set_aes(void *handle, uint8_t aes);
|
||||
// Use aes encryption when adding files in zip
|
||||
/* Use aes encryption when adding files in zip */
|
||||
|
||||
void mz_zip_writer_set_compress_method(void *handle, uint16_t compress_method);
|
||||
// Sets the compression method when adding files in zip
|
||||
/* Sets the compression method when adding files in zip */
|
||||
|
||||
void mz_zip_writer_set_compress_level(void *handle, int16_t compress_level);
|
||||
// Sets the compression level when adding files in zip
|
||||
/* Sets the compression level when adding files in zip */
|
||||
|
||||
void mz_zip_writer_set_zip_cd(void *handle, uint8_t flags);
|
||||
// Sets additional flags to be set when adding files in zip
|
||||
void mz_zip_writer_set_zip_cd(void *handle, uint8_t zip_cd);
|
||||
/* Sets additional flags to be set when adding files in zip */
|
||||
|
||||
void mz_zip_writer_set_certificate(void *handle, const char *cert_path, const char *cert_pwd);
|
||||
// Sets the certificate and timestamp url to use for signing when adding files in zip
|
||||
int32_t mz_zip_writer_set_certificate(void *handle, const char *cert_path, const char *cert_pwd);
|
||||
/* Sets the certificate and timestamp url to use for signing when adding files in zip */
|
||||
|
||||
void mz_zip_writer_set_overwrite_cb(void *handle, void *userdata, mz_zip_writer_overwrite_cb cb);
|
||||
// Callback for what to do when zip file already exists
|
||||
/* Callback for what to do when zip file already exists */
|
||||
|
||||
void mz_zip_writer_set_password_cb(void *handle, void *userdata, mz_zip_writer_password_cb cb);
|
||||
// Callback for ask if a password is required for adding
|
||||
/* Callback for ask if a password is required for adding */
|
||||
|
||||
void mz_zip_writer_set_progress_cb(void *handle, void *userdata, mz_zip_writer_progress_cb cb);
|
||||
// Callback for compression progress
|
||||
/* Callback for compression progress */
|
||||
|
||||
void mz_zip_writer_set_progress_interval(void *handle, uint32_t milliseconds);
|
||||
// Let at least milliseconds pass between calls to progress callback
|
||||
/* Let at least milliseconds pass between calls to progress callback */
|
||||
|
||||
void mz_zip_writer_set_entry_cb(void *handle, void *userdata, mz_zip_writer_entry_cb cb);
|
||||
// Callback for zip file entries
|
||||
/* Callback for zip file entries */
|
||||
|
||||
int32_t mz_zip_writer_get_zip_handle(void *handle, void **zip_handle);
|
||||
// Gets the underlying zip handle
|
||||
/* Gets the underlying zip handle */
|
||||
|
||||
void* mz_zip_writer_create(void **handle);
|
||||
// Create new instance of zip writer
|
||||
/* Create new instance of zip writer */
|
||||
|
||||
void mz_zip_writer_delete(void **handle);
|
||||
// Delete instance of zip writer
|
||||
/* Delete instance of zip writer */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/* standalone.c - Standalone fuzzer tester
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2018 sebpop
|
||||
https://github.com/sebpop
|
||||
Copyright (C) 2018-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
#include <stdio.h> /* printf */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
void *stream = NULL;
|
||||
int64_t file_size = 0;
|
||||
uint8_t *buf = NULL;
|
||||
int32_t buf_length = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t read = 0;
|
||||
int32_t i = 0;
|
||||
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
printf("Must specify an input file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Running %"PRId32" inputs\n", argc - 1);
|
||||
|
||||
for (i = 1; (i < argc) && (err == MZ_OK); i++)
|
||||
{
|
||||
read = 0;
|
||||
|
||||
mz_stream_os_create(&stream);
|
||||
err = mz_stream_os_open(stream, argv[i], MZ_OPEN_MODE_READ);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Skipping %s (%"PRId32")\n", argv[i], err);
|
||||
}
|
||||
else
|
||||
{
|
||||
mz_stream_os_seek(stream, 0, MZ_SEEK_END);
|
||||
file_size = mz_stream_os_tell(stream);
|
||||
if (file_size > INT32_MAX)
|
||||
printf("File size is too large (%"PRId64")\n", file_size);
|
||||
else
|
||||
buf_length = (int32_t)file_size;
|
||||
mz_stream_os_seek(stream, 0, MZ_SEEK_SET);
|
||||
|
||||
buf = NULL;
|
||||
if (buf_length > 0)
|
||||
buf = MZ_ALLOC(buf_length);
|
||||
|
||||
if (buf != NULL)
|
||||
{
|
||||
printf("Running %s %"PRId32"\n", argv[i], buf_length);
|
||||
read = mz_stream_os_read(stream, buf, buf_length);
|
||||
if (read == buf_length)
|
||||
LLVMFuzzerTestOneInput(buf, buf_length);
|
||||
else
|
||||
err = MZ_BUF_ERROR;
|
||||
|
||||
MZ_FREE(buf);
|
||||
}
|
||||
|
||||
mz_stream_os_close(stream);
|
||||
}
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
printf("Done %s (%"PRId32")\n", argv[i], err);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,120 @@
|
||||
/* unzip_fuzzer.c - Unzip fuzzer for libFuzzer
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2018 The Chromium Authors
|
||||
Copyright (C) 2018 Anand K. Mistry
|
||||
Copyright (C) 2018-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_mem.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_FUZZ_TEST_PWD "test123"
|
||||
#define MZ_FUZZ_TEST_FILENAME "foo"
|
||||
#define MZ_FUZZ_TEST_FILENAMEUC "FOO"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
mz_zip_file* file_info = NULL;
|
||||
void *stream = NULL;
|
||||
void *handle = NULL;
|
||||
const char* archive_comment = NULL;
|
||||
char buffer[1024];
|
||||
uint16_t version_madeby = 0;
|
||||
uint64_t num_entries = 0;
|
||||
int64_t entry_pos = 0;
|
||||
int32_t err = MZ_OK;
|
||||
uint8_t encrypted = 0;
|
||||
|
||||
|
||||
mz_stream_mem_create(&stream);
|
||||
mz_stream_mem_set_buffer(stream, (void *)data, size);
|
||||
|
||||
mz_zip_create(&handle);
|
||||
|
||||
err = mz_zip_open(handle, stream, MZ_OPEN_MODE_READ);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
/* Some archive properties that are non-fatal for reading the archive. */
|
||||
mz_zip_get_comment(handle, &archive_comment);
|
||||
mz_zip_get_version_madeby(handle, &version_madeby);
|
||||
mz_zip_get_number_entry(handle, &num_entries);
|
||||
|
||||
err = mz_zip_goto_first_entry(handle);
|
||||
while (err == MZ_OK)
|
||||
{
|
||||
err = mz_zip_entry_get_info(handle, &file_info);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
encrypted = (file_info->flag & MZ_ZIP_FLAG_ENCRYPTED);
|
||||
|
||||
err = mz_zip_entry_read_open(handle, 0,
|
||||
encrypted ? MZ_FUZZ_TEST_PWD : NULL);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
err = mz_zip_entry_is_open(handle);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
/* Return value isn't checked here because we can't predict
|
||||
what the value will be. */
|
||||
|
||||
mz_zip_entry_is_dir(handle);
|
||||
entry_pos = mz_zip_get_entry(handle);
|
||||
if (entry_pos < 0)
|
||||
break;
|
||||
|
||||
err = mz_zip_entry_read(handle, buffer, sizeof(buffer));
|
||||
if (err < 0)
|
||||
break;
|
||||
|
||||
err = mz_zip_entry_close(handle);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
err = mz_zip_goto_next_entry(handle);
|
||||
}
|
||||
|
||||
mz_zip_entry_close(handle);
|
||||
|
||||
/* Return value isn't checked here because we can't predict what the value
|
||||
will be. */
|
||||
|
||||
mz_zip_locate_entry(handle, MZ_FUZZ_TEST_FILENAME, 0);
|
||||
mz_zip_locate_entry(handle, MZ_FUZZ_TEST_FILENAMEUC, 0);
|
||||
mz_zip_locate_entry(handle, MZ_FUZZ_TEST_FILENAME, 1);
|
||||
mz_zip_locate_entry(handle, MZ_FUZZ_TEST_FILENAMEUC, 1);
|
||||
|
||||
mz_zip_close(handle);
|
||||
}
|
||||
|
||||
mz_zip_delete(&handle);
|
||||
mz_stream_mem_delete(&stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
# A dictionary for more efficient fuzzing of DoStuff().
|
||||
# If the inputs contain multi-byte tokens, list them here.
|
||||
# See http://libfuzzer.info#dictionaries
|
||||
"\x50\x4b\x03\x04"
|
||||
"\x50\x4b\x01\x02"
|
||||
"\x50\x4b\x05\x06"
|
||||
"\x50\x4b\x06\x06"
|
||||
"\x50\x4b\x06\x07"
|
||||
"\x50\x4b\x07\x08"
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,115 @@
|
||||
/* zip_fuzzer.c - Zip fuzzer for libFuzzer
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2018 The Chromium Authors
|
||||
Copyright (C) 2018 Anand K. Mistry
|
||||
Copyright (C) 2018-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_mem.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_FUZZ_TEST_FILENAME "foo"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
mz_zip_file file_info;
|
||||
void *fuzz_stream = NULL;
|
||||
void *stream = NULL;
|
||||
void *handle = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
uint16_t value16 = 0;
|
||||
uint8_t value8 = 0;
|
||||
int16_t compress_level = 0;
|
||||
int64_t fuzz_pos = 0;
|
||||
int32_t fuzz_length = 0;
|
||||
uint8_t *fuzz_buf = NULL;
|
||||
|
||||
mz_stream_mem_create(&fuzz_stream);
|
||||
mz_stream_mem_set_buffer(fuzz_stream, (void *)data, size);
|
||||
|
||||
memset(&file_info, 0, sizeof(file_info));
|
||||
|
||||
file_info.flag = MZ_ZIP_FLAG_UTF8;
|
||||
if ((mz_stream_read_uint8(fuzz_stream, &value8) == MZ_OK) && (value8 < 0x08))
|
||||
{
|
||||
if (mz_stream_read_uint16(fuzz_stream, &value16) == MZ_OK)
|
||||
file_info.flag = value16;
|
||||
}
|
||||
file_info.compression_method = MZ_COMPRESS_METHOD_DEFLATE;
|
||||
if ((mz_stream_read_uint8(fuzz_stream, &value8) == MZ_OK) && (value8 < 0x08))
|
||||
{
|
||||
file_info.compression_method = MZ_COMPRESS_METHOD_STORE;
|
||||
}
|
||||
else if ((mz_stream_read_uint8(fuzz_stream, &value8) == MZ_OK) && (value8 < 0x08))
|
||||
{
|
||||
if (mz_stream_read_uint16(fuzz_stream, &value16) == MZ_OK)
|
||||
file_info.compression_method = value16;
|
||||
}
|
||||
|
||||
if ((mz_stream_read_uint8(fuzz_stream, &value8) == MZ_OK) && (value8 < 0x08))
|
||||
{
|
||||
if (mz_stream_read_uint16(fuzz_stream, &value16) == MZ_OK)
|
||||
file_info.zip64 = value16;
|
||||
}
|
||||
|
||||
file_info.filename = MZ_FUZZ_TEST_FILENAME;
|
||||
file_info.filename_size = (uint16_t)strlen(MZ_FUZZ_TEST_FILENAME);
|
||||
|
||||
compress_level = MZ_COMPRESS_LEVEL_DEFAULT;
|
||||
if ((mz_stream_read_uint8(fuzz_stream, &value8) == MZ_OK) && (value8 < 0x08))
|
||||
{
|
||||
if (mz_stream_read_uint16(fuzz_stream, &value16) == MZ_OK)
|
||||
compress_level = value16;
|
||||
}
|
||||
|
||||
mz_stream_mem_create(&stream);
|
||||
mz_zip_create(&handle);
|
||||
|
||||
err = mz_zip_open(handle, stream, MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_WRITE);
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
err = mz_zip_entry_write_open(handle, &file_info, compress_level, 0, NULL);
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
mz_stream_mem_get_buffer_at_current(fuzz_stream, (const void **)&fuzz_buf);
|
||||
fuzz_pos = mz_stream_tell(fuzz_stream);
|
||||
mz_stream_mem_get_buffer_length(fuzz_stream, &fuzz_length);
|
||||
|
||||
err = mz_zip_entry_write(handle, fuzz_buf, (fuzz_length - (int32_t)fuzz_pos));
|
||||
|
||||
mz_zip_entry_close(handle);
|
||||
}
|
||||
|
||||
mz_zip_close(handle);
|
||||
}
|
||||
|
||||
mz_zip_delete(&handle);
|
||||
mz_stream_mem_delete(&stream);
|
||||
|
||||
mz_stream_mem_delete(&fuzz_stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
1
|
||||
+195
-90
@@ -1,16 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
/* test.c - Test bed area
|
||||
Version 2.8.2, January 8, 2019
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2018-2019 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_crypt.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_crc32.h"
|
||||
#ifdef HAVE_BZIP
|
||||
#ifdef HAVE_BZIP2
|
||||
#include "mz_strm_bzip.h"
|
||||
#endif
|
||||
#ifdef HAVE_PKCRYPT
|
||||
@@ -18,7 +21,7 @@
|
||||
#endif
|
||||
#include "mz_strm_mem.h"
|
||||
#include "mz_strm_os.h"
|
||||
#ifdef HAVE_AES
|
||||
#ifdef HAVE_WZAES
|
||||
#include "mz_strm_wzaes.h"
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
@@ -26,70 +29,55 @@
|
||||
#endif
|
||||
#include "mz_zip.h"
|
||||
|
||||
#include <stdio.h> /* printf, snprintf */
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void test_path_resolve(void)
|
||||
void test_path_resolve_int(char *path, char *expected_path)
|
||||
{
|
||||
char output[256];
|
||||
int32_t ok = 0;
|
||||
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve(path, output, sizeof(output));
|
||||
ok = (strcmp(output, expected_path) == 0);
|
||||
printf("path resolve - %s -> %s (%"PRId32")\n", path, expected_path, ok);
|
||||
}
|
||||
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\.", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\test\\") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\.\\", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\test\\") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\..", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\..\\", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\.\\..", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\.\\\\..", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve(".", output, sizeof(output));
|
||||
ok = (strcmp(output, ".") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve(".\\", output, sizeof(output));
|
||||
ok = (strcmp(output, "") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("..", output, sizeof(output));
|
||||
ok = (strcmp(output, "") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("..\\", output, sizeof(output));
|
||||
ok = (strcmp(output, "") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\123\\.\\abc.txt", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\test\\123\\abc.txt") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\123\\..\\abc.txt", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\test\\abc.txt") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\123\\..\\..\\abc.txt", output, sizeof(output));
|
||||
ok = (strcmp(output, "c:\\abc.txt") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
mz_path_resolve("c:\\test\\123\\..\\..\\..\\abc.txt", output, sizeof(output));
|
||||
ok = (strcmp(output, "abc.txt") == 0);
|
||||
memset(output, 'z', sizeof(output));
|
||||
printf("ok = %d", ok);
|
||||
void test_path_resolve(void)
|
||||
{
|
||||
test_path_resolve_int("c:\\test\\.", "c:\\test\\");
|
||||
test_path_resolve_int("c:\\test\\.\\", "c:\\test\\");
|
||||
test_path_resolve_int("c:\\test\\..", "c:\\");
|
||||
test_path_resolve_int("c:\\test\\..\\", "c:\\");
|
||||
test_path_resolve_int("c:\\test\\.\\..", "c:\\");
|
||||
test_path_resolve_int("c:\\test\\.\\\\..", "c:\\");
|
||||
test_path_resolve_int(".", ".");
|
||||
test_path_resolve_int(".\\", "");
|
||||
test_path_resolve_int("..", "");
|
||||
test_path_resolve_int("..\\", "");
|
||||
test_path_resolve_int("c:\\test\\123\\.\\abc.txt", "c:\\test\\123\\abc.txt");
|
||||
test_path_resolve_int("c:\\test\\123\\..\\abc.txt", "c:\\test\\abc.txt");
|
||||
test_path_resolve_int("c:\\test\\123\\..\\..\\abc.txt", "c:\\abc.txt");
|
||||
test_path_resolve_int("c:\\test\\123\\..\\..\\..\\abc.txt", "abc.txt");
|
||||
}
|
||||
|
||||
void test_encrypt(char *method, mz_stream_create_cb crypt_create, char *password)
|
||||
{
|
||||
char buf[UINT16_MAX];
|
||||
int16_t read = 0;
|
||||
int16_t written = 0;
|
||||
int32_t read = 0;
|
||||
int32_t written = 0;
|
||||
int64_t total_written = 0;
|
||||
void *out_stream = NULL;
|
||||
void *in_stream = NULL;
|
||||
void *crypt_out_stream = NULL;
|
||||
char encrypt_path[120];
|
||||
char decrypt_path[120];
|
||||
|
||||
|
||||
snprintf(encrypt_path, sizeof(encrypt_path), "LICENSE.encrypt.%s", method);
|
||||
snprintf(decrypt_path, sizeof(decrypt_path), "LICENSE.decrypt.%s", method);
|
||||
|
||||
@@ -114,13 +102,14 @@ void test_encrypt(char *method, mz_stream_create_cb crypt_create, char *password
|
||||
{
|
||||
written = mz_stream_write(crypt_out_stream, buf, read);
|
||||
mz_stream_close(crypt_out_stream);
|
||||
mz_stream_get_prop_int64(crypt_out_stream, MZ_STREAM_PROP_TOTAL_OUT, &total_written);
|
||||
}
|
||||
|
||||
mz_stream_delete(&crypt_out_stream);
|
||||
|
||||
mz_stream_os_close(out_stream);
|
||||
|
||||
printf("%s encrypted %d\n", encrypt_path, written);
|
||||
printf("%s encrypted %"PRId32"\n", encrypt_path, written);
|
||||
}
|
||||
|
||||
mz_stream_os_delete(&out_stream);
|
||||
@@ -131,6 +120,7 @@ void test_encrypt(char *method, mz_stream_create_cb crypt_create, char *password
|
||||
crypt_create(&crypt_out_stream);
|
||||
|
||||
mz_stream_set_base(crypt_out_stream, in_stream);
|
||||
mz_stream_set_prop_int64(crypt_out_stream, MZ_STREAM_PROP_TOTAL_IN_MAX, total_written);
|
||||
|
||||
if (mz_stream_open(crypt_out_stream, password, MZ_OPEN_MODE_READ) == MZ_OK)
|
||||
{
|
||||
@@ -143,7 +133,7 @@ void test_encrypt(char *method, mz_stream_create_cb crypt_create, char *password
|
||||
mz_stream_os_close(in_stream);
|
||||
|
||||
|
||||
printf("%s decrypted %d\n", decrypt_path, read);
|
||||
printf("%s decrypted %"PRId32"\n", decrypt_path, read);
|
||||
}
|
||||
|
||||
mz_stream_os_delete(&in_stream);
|
||||
@@ -160,11 +150,10 @@ void test_encrypt(char *method, mz_stream_create_cb crypt_create, char *password
|
||||
|
||||
void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
{
|
||||
char buf[UINT16_MAX];
|
||||
int16_t read = 0;
|
||||
uint8_t buf[UINT16_MAX];
|
||||
int32_t read = 0;
|
||||
int64_t total_in = 0;
|
||||
int64_t total_out = 0;
|
||||
void *crc_in_stream = NULL;
|
||||
void *in_stream = NULL;
|
||||
void *out_stream = NULL;
|
||||
void *deflate_stream = NULL;
|
||||
@@ -178,13 +167,9 @@ void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
|
||||
if (mz_stream_os_open(in_stream, "LICENSE", MZ_OPEN_MODE_READ) == MZ_OK)
|
||||
{
|
||||
mz_stream_crc32_create(&crc_in_stream);
|
||||
mz_stream_set_base(crc_in_stream, in_stream);
|
||||
mz_stream_crc32_open(crc_in_stream, NULL, MZ_OPEN_MODE_READ);
|
||||
read = mz_stream_read(crc_in_stream, buf, UINT16_MAX);
|
||||
crc32 = mz_stream_crc32_get_value(crc_in_stream);
|
||||
mz_stream_close(crc_in_stream);
|
||||
mz_stream_crc32_delete(&crc_in_stream);
|
||||
read = mz_stream_os_read(in_stream, buf, UINT16_MAX);
|
||||
if (read > 0)
|
||||
crc32 = mz_crypt_crc32_update(crc32, (const uint8_t *)buf, read);
|
||||
|
||||
mz_stream_os_close(in_stream);
|
||||
}
|
||||
@@ -246,20 +231,12 @@ void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
mz_stream_os_delete(&in_stream);
|
||||
mz_stream_os_create(&out_stream);
|
||||
|
||||
crc32 = 0;
|
||||
|
||||
snprintf(filename, sizeof(filename), "LICENSE.inflate.%s", method);
|
||||
if (mz_stream_os_open(out_stream, filename, MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_WRITE) == MZ_OK)
|
||||
{
|
||||
mz_stream_crc32_create(&crc_in_stream);
|
||||
mz_stream_crc32_open(crc_in_stream, NULL, MZ_OPEN_MODE_WRITE);
|
||||
|
||||
mz_stream_set_base(crc_in_stream, in_stream);
|
||||
if (mz_stream_write(crc_in_stream, buf, read) != read)
|
||||
printf("Failed to write %s\n", filename);
|
||||
|
||||
crc32 = mz_stream_crc32_get_value(crc_in_stream);
|
||||
|
||||
mz_stream_close(crc_in_stream);
|
||||
mz_stream_delete(&crc_in_stream);
|
||||
crc32 = mz_crypt_crc32_update(crc32, (const uint8_t *)buf, read);
|
||||
|
||||
mz_stream_os_close(out_stream);
|
||||
|
||||
@@ -271,7 +248,7 @@ void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef HAVE_BZIP
|
||||
#ifdef HAVE_BZIP2
|
||||
void test_stream_bzip(void)
|
||||
{
|
||||
test_compress("bzip", mz_stream_bzip_create);
|
||||
@@ -283,7 +260,7 @@ void test_stream_pkcrypt(void)
|
||||
test_encrypt("pkcrypt", mz_stream_pkcrypt_create, "hello");
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_AES
|
||||
#ifdef HAVE_WZAES
|
||||
void test_stream_wzaes(void)
|
||||
{
|
||||
int32_t iteration_count = 1000;
|
||||
@@ -297,7 +274,7 @@ void test_stream_wzaes(void)
|
||||
printf("Pbkdf2 password - %s\n", password);
|
||||
printf("Pbkdf2 salt - %s\n", salt);
|
||||
|
||||
err = mz_stream_wzaes_pbkdf2((uint8_t *)password, (int32_t)strlen(password),
|
||||
err = mz_crypt_pbkdf2((uint8_t *)password, (int32_t)strlen(password),
|
||||
(uint8_t *)salt, (int32_t)strlen(salt), iteration_count, key, sizeof(key));
|
||||
|
||||
if (err == MZ_OK)
|
||||
@@ -309,7 +286,7 @@ void test_stream_wzaes(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Pbkdf2 failed - %d", err);
|
||||
printf("Pbkdf2 failed - %"PRId32"", err);
|
||||
}
|
||||
|
||||
test_encrypt("aes", mz_stream_wzaes_create, "hello");
|
||||
@@ -326,7 +303,7 @@ void test_stream_zlib(void)
|
||||
|
||||
void test_stream_mem(void)
|
||||
{
|
||||
mz_zip_file file_info = { 0 };
|
||||
mz_zip_file file_info;
|
||||
void *read_mem_stream = NULL;
|
||||
void *write_mem_stream = NULL;
|
||||
void *os_stream = NULL;
|
||||
@@ -343,9 +320,11 @@ void test_stream_mem(void)
|
||||
char temp[120];
|
||||
|
||||
|
||||
memset(&file_info, 0, sizeof(file_info));
|
||||
|
||||
text_size = (int32_t)strlen(text_ptr);
|
||||
|
||||
// Write zip to memory stream
|
||||
/* Write zip to memory stream */
|
||||
mz_stream_mem_create(&write_mem_stream);
|
||||
mz_stream_mem_set_grow_size(write_mem_stream, 128 * 1024);
|
||||
mz_stream_open(write_mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
@@ -359,7 +338,7 @@ void test_stream_mem(void)
|
||||
file_info.compression_method = MZ_COMPRESS_METHOD_DEFLATE;
|
||||
file_info.filename = text_name;
|
||||
file_info.uncompressed_size = text_size;
|
||||
#ifdef HAVE_AES
|
||||
#ifdef HAVE_WZAES
|
||||
file_info.aes_version = MZ_AES_VERSION;
|
||||
#endif
|
||||
|
||||
@@ -387,7 +366,7 @@ void test_stream_mem(void)
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Create a zip file on disk for inspection
|
||||
/* Create a zip file on disk for inspection */
|
||||
mz_stream_os_create(&os_stream);
|
||||
mz_stream_os_open(os_stream, "mytest.zip", MZ_OPEN_MODE_WRITE | MZ_OPEN_MODE_CREATE);
|
||||
mz_stream_os_write(os_stream, buffer_ptr, buffer_size);
|
||||
@@ -397,7 +376,7 @@ void test_stream_mem(void)
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Read from a memory stream
|
||||
/* Read from a memory stream */
|
||||
mz_stream_mem_create(&read_mem_stream);
|
||||
mz_stream_mem_set_buffer(read_mem_stream, (void *)buffer_ptr, buffer_size);
|
||||
mz_stream_open(read_mem_stream, NULL, MZ_OPEN_MODE_READ);
|
||||
@@ -431,6 +410,132 @@ void test_stream_mem(void)
|
||||
write_mem_stream = NULL;
|
||||
}
|
||||
|
||||
int32_t test_stream_find_run(char *name, int32_t count, const uint8_t *find, int32_t find_size, mz_stream_find_cb find_cb)
|
||||
{
|
||||
void *mem_stream = NULL;
|
||||
int32_t i = 0;
|
||||
int32_t x = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int64_t last_pos = 0;
|
||||
int64_t position = 0;
|
||||
|
||||
if (find == NULL || find_size == 0 || find_cb == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
for (i = 0; i < count; i += 1)
|
||||
{
|
||||
#if 1
|
||||
mz_stream_mem_create(&mem_stream);
|
||||
mz_stream_mem_open(mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
for (x = 0; x < find_size; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, find[x]);
|
||||
for (x = 0; x < i; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, 0);
|
||||
|
||||
if (find_cb == mz_stream_find)
|
||||
mz_stream_seek(mem_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
err = find_cb(mem_stream, (const void *)find, find_size, (int64_t)i + find_size, &position);
|
||||
last_pos = mz_stream_tell(mem_stream);
|
||||
mz_stream_mem_delete(&mem_stream);
|
||||
|
||||
printf("Find postzero - %s (len %"PRId32" pos %"PRId64" ok %"PRId32")\n",
|
||||
name, find_size, position, (position == 0));
|
||||
|
||||
if (position != 0 || last_pos != position)
|
||||
break;
|
||||
#endif
|
||||
mz_stream_mem_create(&mem_stream);
|
||||
mz_stream_mem_open(mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
for (x = 0; x < i; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, 0);
|
||||
for (x = 0; x < find_size; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, find[x]);
|
||||
|
||||
if (find_cb == mz_stream_find)
|
||||
mz_stream_seek(mem_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
err = find_cb(mem_stream, (const void *)find, find_size, (int64_t)i + find_size, &position);
|
||||
last_pos = mz_stream_tell(mem_stream);
|
||||
mz_stream_mem_delete(&mem_stream);
|
||||
|
||||
printf("Find prezero - %s (len %"PRId32" pos %"PRId64" ok %"PRId32")\n",
|
||||
name, find_size, position, (position == i));
|
||||
|
||||
if (position != i || last_pos != position)
|
||||
break;
|
||||
|
||||
mz_stream_mem_create(&mem_stream);
|
||||
mz_stream_mem_open(mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
for (x = 0; x < i; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, 0);
|
||||
for (x = 0; x < find_size; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, find[x]);
|
||||
for (x = 0; x < i; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, 0);
|
||||
|
||||
if (find_cb == mz_stream_find)
|
||||
mz_stream_seek(mem_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
err = find_cb(mem_stream, (const void *)find, find_size, (int64_t)i + find_size + i, &position);
|
||||
last_pos = mz_stream_tell(mem_stream);
|
||||
mz_stream_mem_delete(&mem_stream);
|
||||
|
||||
printf("Find equalzero - %s (len %"PRId32" pos %"PRId64" ok %"PRId32")\n",
|
||||
name, find_size, position, (position == i));
|
||||
|
||||
if (position != i || last_pos != position)
|
||||
break;
|
||||
|
||||
mz_stream_mem_create(&mem_stream);
|
||||
mz_stream_mem_open(mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
|
||||
for (x = 0; x < i; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, 0);
|
||||
for (x = 0; x < find_size; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, find[x]);
|
||||
for (x = 0; x < i; x += 1)
|
||||
mz_stream_write_uint8(mem_stream, 0);
|
||||
mz_stream_write_uint8(mem_stream, 0);
|
||||
|
||||
if (find_cb == mz_stream_find)
|
||||
mz_stream_seek(mem_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
err = find_cb(mem_stream, (const void *)find, find_size, (int64_t)i + find_size + i + 1, &position);
|
||||
last_pos = mz_stream_tell(mem_stream);
|
||||
mz_stream_mem_delete(&mem_stream);
|
||||
|
||||
printf("Find unequalzero - %s (len %"PRId32" pos %"PRId64" ok %"PRId32")\n",
|
||||
name, find_size, position, (position == i));
|
||||
|
||||
if (position != i || last_pos != position)
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void test_stream_find(void)
|
||||
{
|
||||
int32_t c = 1;
|
||||
char *find = "0123456789";
|
||||
|
||||
for (c = 1; c < (int32_t)strlen(find); c += 1)
|
||||
test_stream_find_run("forward", 2096, (uint8_t *)find, c, mz_stream_find);
|
||||
}
|
||||
|
||||
void test_stream_find_reverse(void)
|
||||
{
|
||||
int32_t c = 1;
|
||||
char *find = "0123456789";
|
||||
|
||||
for (c = 1; c < (int32_t)strlen(find); c += 1)
|
||||
test_stream_find_run("backward", 2096, (uint8_t *)find, c, mz_stream_find_reverse);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifndef MZ_ZIP_NO_ENCRYPTION
|
||||
@@ -581,4 +686,4 @@ void test_crypt_hmac(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -12,6 +12,8 @@ void test_stream_pkcrypt(void);
|
||||
void test_stream_wzaes(void);
|
||||
void test_stream_zlib(void);
|
||||
void test_stream_mem(void);
|
||||
void test_stream_find(void);
|
||||
void test_stream_find_reverse(void);
|
||||
|
||||
void test_crypt_sha(void);
|
||||
void test_crypt_aes(void);
|
||||
|
||||
-220
@@ -1,220 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
import stat
|
||||
import argparse
|
||||
import glob
|
||||
import shutil
|
||||
import fnmatch
|
||||
import time
|
||||
import struct
|
||||
import random
|
||||
import pprint
|
||||
import hashlib
|
||||
from sys import platform
|
||||
|
||||
parser = argparse.ArgumentParser(description='Zip/unzip test script')
|
||||
parser.add_argument('--exe_dir', help='Minizip command line tool directory', default=None, action='store', required=False)
|
||||
parser.add_argument('--deflate', help='Runs zlib/deflate tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--raw', help='Runs raw tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--bzip2', help='Runs bzip2 tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--lzma', help='Runs lzma tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--pkcrypt', help='Runs pkware traditional encryption tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--wzaes', help='Runs winzip aes encryption tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--split', help='Runs disk span tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--zipcd', help='Runs zip/unzip central dir tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--sign', help='Runs signing tests', action='store_const', const=True, default=None, required=False)
|
||||
parser.add_argument('--rand', help='Runs tests against random generated files', action='store_const', const=True, default=None, required=False)
|
||||
args, unknown = parser.parse_known_args()
|
||||
|
||||
def hash_file_sha1(path):
|
||||
sha1 = hashlib.sha1()
|
||||
with open(path, 'rb') as f:
|
||||
while True:
|
||||
data = f.read(8192)
|
||||
if not data:
|
||||
break
|
||||
sha1.update(data)
|
||||
return sha1.hexdigest()
|
||||
|
||||
def find_files(directory, pattern, recursive = True):
|
||||
if directory == '':
|
||||
directory = os.getcwd()
|
||||
if recursive:
|
||||
items = os.walk(directory)
|
||||
else:
|
||||
items = [next(os.walk(directory))]
|
||||
for root, dirs, files in items:
|
||||
for basename in files:
|
||||
if fnmatch.fnmatch(basename, pattern):
|
||||
filename = os.path.join(root, basename)
|
||||
yield filename
|
||||
|
||||
def erase_file(path, retries = 10, sleep = 0.1):
|
||||
#print('Deleting {0}'.format(path))
|
||||
for i in range(retries):
|
||||
try:
|
||||
os.chmod(path, stat.S_IWUSR)
|
||||
os.remove(path)
|
||||
except WindowsError:
|
||||
time.sleep(sleep)
|
||||
else:
|
||||
break
|
||||
|
||||
def erase_files(search_pattern):
|
||||
search_dir, match = os.path.split(search_pattern)
|
||||
for path in find_files(search_dir, match):
|
||||
erase_file(path)
|
||||
|
||||
def erase_dir(path, retries = 10):
|
||||
if not os.path.exists(path):
|
||||
return
|
||||
#print('Erasing dir {0}'.format(path))
|
||||
# shutil.rmtree doesn't work well and sometimes can't delete
|
||||
for root, dirs, files in os.walk(path, topdown=False):
|
||||
for name in files:
|
||||
filename = os.path.join(root, name)
|
||||
erase_file(filename)
|
||||
for name in dirs:
|
||||
os.rmdir(os.path.join(root, name))
|
||||
os.rmdir(path)
|
||||
|
||||
def get_exec(name):
|
||||
global args
|
||||
if platform == 'win32':
|
||||
name += '.exe'
|
||||
if args.exe_dir is not None:
|
||||
return os.path.join(args.exe_dir, name)
|
||||
return name
|
||||
|
||||
def get_files_info(path):
|
||||
if os.path.isfile(path):
|
||||
return {
|
||||
path: {
|
||||
'hash': hash_file_sha1(path),
|
||||
'size': os.path.getsize(path)
|
||||
}
|
||||
}
|
||||
info = {}
|
||||
for root, dirs, files in os.walk(path):
|
||||
path = root.split(os.sep)
|
||||
for path in files:
|
||||
info.update(get_files_info(path))
|
||||
return info
|
||||
|
||||
def create_random_file(path, size):
|
||||
import numpy
|
||||
if os.path.exists(path):
|
||||
return
|
||||
with open(path, 'wb') as fout:
|
||||
i = 0
|
||||
while size > 0:
|
||||
if i == 0 or i % 400000 == 0:
|
||||
data = numpy.random.rand(100000)
|
||||
floatlist = numpy.squeeze(numpy.asarray(data))
|
||||
buf = struct.pack('%sf' % len(floatlist), *floatlist)
|
||||
fout.write(buf)
|
||||
size -= len(buf)
|
||||
i += 1
|
||||
|
||||
def zip(zip_file, zip_args, files):
|
||||
cmd = '{0} {1} {2} {3}'.format(get_exec('minizip'), zip_args, zip_file, ' '.join(files))
|
||||
print cmd
|
||||
err = os.system(cmd)
|
||||
if (err != 0):
|
||||
print('Zip returned error code {0}'.format(err))
|
||||
exit(err)
|
||||
|
||||
def list(zip_file):
|
||||
cmd = '{0} -l {1}'.format(get_exec('minizip'), zip_file)
|
||||
print cmd
|
||||
err = os.system(cmd)
|
||||
if (err != 0):
|
||||
print('List returned error code {0}'.format(err))
|
||||
exit(err)
|
||||
|
||||
def unzip(zip_file, dest_dir, unzip_args = ''):
|
||||
cmd = '{0} -x {1} -d {2} {3}'.format(get_exec('minizip'), unzip_args, dest_dir, zip_file)
|
||||
print cmd
|
||||
err = os.system(cmd)
|
||||
if (err != 0):
|
||||
print('Unzip returned error code {0}'.format(err))
|
||||
exit(err)
|
||||
|
||||
def zip_list_unzip(zip_file, dest_dir, zip_args, unzip_args, files):
|
||||
# Single test run
|
||||
original_infos = {}
|
||||
for (i, path) in enumerate(files):
|
||||
original_infos.update(get_files_info(path))
|
||||
|
||||
erase_files(zip_file[0:-2] + "*")
|
||||
erase_dir(dest_dir)
|
||||
|
||||
zip(zip_file, zip_args, files)
|
||||
list(zip_file)
|
||||
unzip(zip_file, dest_dir, unzip_args)
|
||||
|
||||
new_infos = {}
|
||||
for (i, path) in enumerate(files):
|
||||
new_infos.update(get_files_info(path))
|
||||
|
||||
if (' '.join(original_infos) != ' '.join(new_infos)):
|
||||
print('Infos do not match')
|
||||
print('Original: ')
|
||||
pprint(original_infos)
|
||||
print('New: ')
|
||||
print(new_infos)
|
||||
|
||||
def file_tests(method, zip_arg = '', unzip_arg = ''):
|
||||
global args
|
||||
print('Testing {0} on Single File'.format(method))
|
||||
zip_list_unzip('test.zip', 'out', zip_arg, unzip_arg, ['test.c'])
|
||||
print('Testing {0} on Two Files'.format(method))
|
||||
zip_list_unzip('test.zip', 'out', zip_arg, unzip_arg, ['test.c', 'test.h'])
|
||||
print('Testing {0} Directory'.format(method))
|
||||
zip_list_unzip('test.zip', 'out', zip_arg, unzip_arg, ['repo'])
|
||||
if args.rand:
|
||||
print('Testing {0} 1MB file'.format(method))
|
||||
create_random_file('1MB.dat', 1 * 1024 * 1024)
|
||||
zip_list_unzip('test.zip', 'out', zip_arg, unzip_arg, ['1MB.dat'])
|
||||
print('Testing {0} 25MB file'.format(method))
|
||||
create_random_file('25MB.dat', 25 * 1024 * 1024)
|
||||
zip_list_unzip('test.zip', 'out', zip_arg, unzip_arg, ['25MB.dat'])
|
||||
|
||||
def compression_method_tests(method = '', zip_arg = '', unzip_arg = ''):
|
||||
global args
|
||||
method = method + ' ' if method != '' else ''
|
||||
if args.deflate:
|
||||
file_tests(method + 'Deflate', zip_arg, unzip_arg)
|
||||
if args.raw:
|
||||
file_tests(method + 'Raw', '-0 ' + zip_arg, unzip_arg)
|
||||
if args.bzip2:
|
||||
file_tests(method + 'BZIP2', '-b ' + zip_arg, unzip_arg)
|
||||
if args.lzma:
|
||||
file_tests(method + 'LZMA', '-m ' + zip_arg, unzip_arg)
|
||||
|
||||
def empty_zip_test():
|
||||
unzip('empty.zip', 'out')
|
||||
|
||||
def sfx_zip_test():
|
||||
org_exe = get_exec('minizip')
|
||||
sfx_exe = org_exe.replace('.exe', '') + '_sfx.exe'
|
||||
shutil.copyfile(org_exe, sfx_exe)
|
||||
zip_list_unzip(sfx_exe, 'out', '-a', '', [ 'test.c', 'test.h' ])
|
||||
|
||||
if not os.path.exists('repo'):
|
||||
os.system('git clone https://github.com/nmoinvaz/minizip repo')
|
||||
|
||||
# Run tests
|
||||
#empty_zip_test()
|
||||
#sfx_zip_test()
|
||||
compression_method_tests()
|
||||
if args.pkcrypt:
|
||||
compression_method_tests('PKCrypt', '-p 1234567890', '-p 1234567890')
|
||||
if args.wzaes:
|
||||
compression_method_tests('WinZipAES', '-s -p 1234567890', '-p 1234567890')
|
||||
if args.split:
|
||||
compression_method_tests('Disk Span', '-k 1024', '')
|
||||
if args.zipcd:
|
||||
compression_method_tests('ZipCD', '-z', '')
|
||||
if args.sign:
|
||||
compression_method_tests('Signing', '-h ia.p12 -w test', '')
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user