Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
351b14e512 | ||
|
|
7188209f03 | ||
|
|
95047d3c90 | ||
|
|
359e8e1017 | ||
|
|
e7df0f7341 | ||
|
|
da1ab3dab1 | ||
|
|
abc29e4429 | ||
|
|
b8300ce0ea | ||
|
|
638f31ff41 | ||
|
|
a0d1877d0e | ||
|
|
3eaa5560bf | ||
|
|
d4c4d4f5b1 | ||
|
|
d79fb39d4b | ||
|
|
a2e89bf85e | ||
|
|
e27af27b6e | ||
|
|
72cc7015a2 | ||
|
|
a2bd3c6d95 | ||
|
|
dcd9b72bf9 | ||
|
|
d2aa2277d9 | ||
|
|
da4b58f6e5 | ||
|
|
b994caeab9 | ||
|
|
0b6059fc53 | ||
|
|
4b8e4b372c | ||
|
|
bb3d26efb7 | ||
|
|
74a6a21e56 | ||
|
|
2b3cd16b6f | ||
|
|
79cfab094d | ||
|
|
0e2201a5e1 | ||
|
|
e04106b734 | ||
|
|
b9dbacae60 | ||
|
|
590e5909b3 | ||
|
|
960a6e113c | ||
|
|
01bc6016fb | ||
|
|
5f01092239 | ||
|
|
444596646e | ||
|
|
c98dec4291 | ||
|
|
ca014e6f37 | ||
|
|
f5cc4c0355 | ||
|
|
00520cd631 | ||
|
|
c56d53156e | ||
|
|
05aa0f2a07 | ||
|
|
829ffb5cce | ||
|
|
b635b7db5a | ||
|
|
9f863b35ca | ||
|
|
de09ac796f | ||
|
|
cfa2e604f6 | ||
|
|
a8644a1de8 | ||
|
|
9a170d4d60 | ||
|
|
77687f3a42 | ||
|
|
a64c919e0b | ||
|
|
9eb113dee7 | ||
|
|
d08e1561d9 | ||
|
|
26308b244e | ||
|
|
0e4fe82acb | ||
|
|
fa146ad6bd | ||
|
|
0f8d91101b | ||
|
|
a6d04a7baa | ||
|
|
00ad03daf0 | ||
|
|
2b43158414 | ||
|
|
0e1fd3ee8b | ||
|
|
c65c7a928f | ||
|
|
65a87024d4 | ||
|
|
c599dd60f4 | ||
|
|
c2d5c47b51 | ||
|
|
89d6967afc | ||
|
|
7c29c16575 | ||
|
|
7679d219a0 | ||
|
|
298126af7f | ||
|
|
7f6f08acfc | ||
|
|
c83e4da20d | ||
|
|
b5c2f01c31 | ||
|
|
54dc69af1c | ||
|
|
5f2bf575df | ||
|
|
c9addbe56d | ||
|
|
155b3f5e42 | ||
|
|
32a9d34295 | ||
|
|
a8f4a09de6 | ||
|
|
e824da8453 | ||
|
|
51bf61d04e | ||
|
|
f55a3c5a40 | ||
|
|
546607c8e4 | ||
|
|
4818d8efe8 | ||
|
|
a2a37040c7 | ||
|
|
0fac5e72ec | ||
|
|
d195fd3a59 | ||
|
|
f23af14199 | ||
|
|
1149bafee3 | ||
|
|
aa311f349b | ||
|
|
6f32e35278 | ||
|
|
44a14426dc | ||
|
|
eadf3eb181 | ||
|
|
a982abf876 | ||
|
|
3719965652 | ||
|
|
91c028d276 | ||
|
|
4042763729 | ||
|
|
a6d1f6692e | ||
|
|
4d34203968 | ||
|
|
93c13564b8 | ||
|
|
f9ee9d7f08 | ||
|
|
7332bd6002 | ||
|
|
9645f4638c | ||
|
|
8d128a7c63 | ||
|
|
627993ef07 | ||
|
|
4cfdd5dd83 | ||
|
|
697e995d89 | ||
|
|
16d9f47a4f | ||
|
|
6ac2ff4ec2 | ||
|
|
e099a2a8f7 | ||
|
|
163b317ad6 | ||
|
|
446d062b3c | ||
|
|
6781995724 | ||
|
|
b3bf29ab02 | ||
|
|
7a0a62dc9c | ||
|
|
d50e91aafe | ||
|
|
ae724eff61 | ||
|
|
4bdb436e8e | ||
|
|
2ecd8a0b2a | ||
|
|
f873eccdd2 | ||
|
|
9593ca4fc5 | ||
|
|
2e4a85e36f | ||
|
|
ee614ff3ce | ||
|
|
6b12c36538 | ||
|
|
a4a5cf66aa | ||
|
|
cfcbccf67e | ||
|
|
eb80cd9fa4 | ||
|
|
9e2b2456dc | ||
|
|
ffa830f684 | ||
|
|
f65b9fecae | ||
|
|
f76c04be40 | ||
|
|
ebb01ce07e | ||
|
|
b0a005644d | ||
|
|
d7814e9b8d | ||
|
|
50f3252d2c | ||
|
|
adbbc68fa4 | ||
|
|
34e2ab5065 | ||
|
|
b47b41b8df | ||
|
|
155f8b52b2 | ||
|
|
5d3b5c593d | ||
|
|
e3958d9b46 | ||
|
|
957e5f92e4 | ||
|
|
184f4cbde1 | ||
|
|
8871f6c0f1 | ||
|
|
fa8105b657 | ||
|
|
2cf91c09ce | ||
|
|
9eecff3140 | ||
|
|
77dcb77506 | ||
|
|
ef776a31e1 | ||
|
|
b70b824b19 | ||
|
|
0a9282d2f0 | ||
|
|
6be5ec8163 | ||
|
|
5d4c61fdd5 | ||
|
|
4bcaf521d7 | ||
|
|
957f2e9976 | ||
|
|
dd808239dd | ||
|
|
7bdfbf4699 | ||
|
|
4a7723357e | ||
|
|
4925f31e28 | ||
|
|
669f5a3086 | ||
|
|
30e859be0b | ||
|
|
5b204622cc | ||
|
|
b07ab3e9b9 | ||
|
|
3dc4334d38 | ||
|
|
ca30682447 | ||
|
|
0e5c9dcdf4 | ||
|
|
ea99a46b6d | ||
|
|
23bc9fd943 | ||
|
|
cfcb729f79 | ||
|
|
51521bddc8 | ||
|
|
41331dd3ec | ||
|
|
9c155991d7 | ||
|
|
43e787bd88 | ||
|
|
3909c23817 | ||
|
|
c0d3dbf537 | ||
|
|
0388124aad | ||
|
|
e1aad8c445 | ||
|
|
b5fb12503d | ||
|
|
bd2f162009 | ||
|
|
408940f16c | ||
|
|
a710bd714a | ||
|
|
7a3b698578 | ||
|
|
e275fcf017 | ||
|
|
0e2e1a0b05 | ||
|
|
3431a6635b | ||
|
|
521a42a4c3 | ||
|
|
a4b83e8e95 | ||
|
|
121e088a7d | ||
|
|
46f714348e | ||
|
|
a56a08cf79 | ||
|
|
8a50b4b5df | ||
|
|
37ceb026db | ||
|
|
586300a787 | ||
|
|
92c8d77cfb | ||
|
|
c546a57f90 | ||
|
|
5244fc00c4 | ||
|
|
4c76400cce | ||
|
|
240b3b6709 | ||
|
|
e54582384a | ||
|
|
3ad1a92279 | ||
|
|
447dd06750 | ||
|
|
4827f71a08 | ||
|
|
bb3b75bc09 | ||
|
|
b7bd0421c5 | ||
|
|
9a3ae75a48 | ||
|
|
120bea1a6f | ||
|
|
4a41245099 | ||
|
|
0f0535fcaa | ||
|
|
8d8deb4e5d | ||
|
|
83bce6e82a | ||
|
|
739f03f951 | ||
|
|
7583be518c | ||
|
|
0619c3e6c4 | ||
|
|
e33916b608 | ||
|
|
596f19f79e | ||
|
|
2884e67a1a | ||
|
|
ae5740b19c | ||
|
|
b14ded7d01 | ||
|
|
914049d19c | ||
|
|
915b82e95b | ||
|
|
0f09a00810 | ||
|
|
f5f23217b3 | ||
|
|
5d362f43eb | ||
|
|
ce26dba5ba | ||
|
|
ad8e3dd4b1 | ||
|
|
53e1d650e5 | ||
|
|
bcd64ca3b8 | ||
|
|
078f20290f | ||
|
|
9c98a6b180 | ||
|
|
a30ff41e9d | ||
|
|
a43eb98099 | ||
|
|
8d8a987eea | ||
|
|
c5f0063c75 | ||
|
|
d57eb5de40 | ||
|
|
672dc834f1 | ||
|
|
5e8f4d7d88 | ||
|
|
68a48aa20e | ||
|
|
b5ac94fd24 | ||
|
|
b4020169b7 | ||
|
|
b8f38540c2 | ||
|
|
d65cd2ea9d | ||
|
|
6cd3054608 | ||
|
|
f44494aad2 | ||
|
|
7c5ccae39c | ||
|
|
82df346497 | ||
|
|
225c627f7d | ||
|
|
db8158a5cc | ||
|
|
62090966b1 | ||
|
|
dec6a65a64 | ||
|
|
7d7b1c9554 | ||
|
|
a4a4a1c665 | ||
|
|
b8887e9179 | ||
|
|
c0cc7df743 | ||
|
|
c5e2d27028 | ||
|
|
bb7b62fcb4 | ||
|
|
e56962c624 | ||
|
|
d9e159a395 | ||
|
|
4578b9dd33 | ||
|
|
b44f9c07b8 | ||
|
|
55bcdaf3c4 | ||
|
|
8f6f2ad5fb | ||
|
|
7063b0e2e9 | ||
|
|
3679a3dcdc | ||
|
|
4ae7992c2e | ||
|
|
566b978768 | ||
|
|
7a3820c539 | ||
|
|
bca5f2761d | ||
|
|
f7d49e2d7c | ||
|
|
f8b3d67c67 | ||
|
|
2043f834b0 | ||
|
|
c65486db27 | ||
|
|
30589b5419 | ||
|
|
3f59ffc209 | ||
|
|
d487d78b30 | ||
|
|
1d5b57bd9b | ||
|
|
9e89bb1ee0 | ||
|
|
6c717b6558 | ||
|
|
5c3dd5c27e | ||
|
|
ceca477ed4 | ||
|
|
34eff624c4 | ||
|
|
930f9188a5 | ||
|
|
397d2d5ab3 | ||
|
|
3064a0e551 | ||
|
|
d22a27a9c3 | ||
|
|
98cd93d3a7 | ||
|
|
d52e453488 | ||
|
|
61a4b59216 | ||
|
|
7443318057 | ||
|
|
e474a61e86 | ||
|
|
5e67eb720a | ||
|
|
d18e09d5b0 | ||
|
|
7855c3efd0 | ||
|
|
c689d51f79 | ||
|
|
fee885a931 | ||
|
|
a1e78c5fc4 | ||
|
|
3c52d21ba9 | ||
|
|
a6e3b69a3b | ||
|
|
0fbdb2298e | ||
|
|
7df69ea96e | ||
|
|
fc746532d8 | ||
|
|
d60c6d20af | ||
|
|
55e4fe414e | ||
|
|
5bb372d495 | ||
|
|
a86a4355da | ||
|
|
c9fd8d4df0 | ||
|
|
02123b82d5 | ||
|
|
7140c588c6 | ||
|
|
f60a99bd90 | ||
|
|
50fd547660 | ||
|
|
2fa05a7264 | ||
|
|
1a20b75c46 | ||
|
|
dab094fc31 | ||
|
|
13a12e32ab | ||
|
|
73418b7e05 | ||
|
|
3f7de8e289 | ||
|
|
18a30653b1 | ||
|
|
b73887478a | ||
|
|
51fb0afc82 | ||
|
|
a45fa6b8a0 | ||
|
|
6c6700d2f4 | ||
|
|
0574424b05 | ||
|
|
919d837abf | ||
|
|
12db0fc415 | ||
|
|
e4bd6d3191 | ||
|
|
f9749af452 | ||
|
|
02a516944d | ||
|
|
0d4ae83bd2 | ||
|
|
d15b013734 | ||
|
|
a3dc63a17f | ||
|
|
be85b3b4cd | ||
|
|
3da621e118 | ||
|
|
211f14074a | ||
|
|
819d0d56f0 | ||
|
|
fa7fadebfa | ||
|
|
a6e7d468e3 | ||
|
|
b8f7cf0fa7 | ||
|
|
886df95632 | ||
|
|
80c2d56436 |
@@ -1,5 +0,0 @@
|
||||
# Xcode
|
||||
xcuserdata/
|
||||
|
||||
# JetBrains
|
||||
.idea/
|
||||
@@ -7,13 +7,8 @@ compiler:
|
||||
- clang
|
||||
- gcc
|
||||
|
||||
python:
|
||||
- "2.7"
|
||||
|
||||
before_install:
|
||||
- sudo apt-get install libbsd-dev
|
||||
- sudo pip install --upgrade pip
|
||||
- sudo pip install numpy
|
||||
|
||||
before_script:
|
||||
- mkdir build
|
||||
@@ -22,5 +17,3 @@ before_script:
|
||||
|
||||
script:
|
||||
- make
|
||||
- cd ../test
|
||||
- python test.py --exe_dir=../build
|
||||
|
||||
+195
-85
@@ -1,33 +1,39 @@
|
||||
#***************************************************************************
|
||||
# Copyright: Matthias Schmieder,
|
||||
# E-Mail: schmieder.matthias@gmail.com
|
||||
# Year: 2016
|
||||
# Copyright (C) 2017-2018 Nathan Moinvaziri
|
||||
# https://github.com/nmoinvaz/minizip
|
||||
# Copyright (C) 2016 Matthias Schmieder
|
||||
# schmieder.matthias@gmail.com
|
||||
#***************************************************************************
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
option(USE_ZLIB "Enables building with ZLIB library" ON)
|
||||
option(USE_BZIP2 "Enables building with BZIP2 library" ON)
|
||||
option(USE_LZMA "Enables building with LZMA library" ON)
|
||||
option(USE_CRYPT "Enables building with PKWARE traditional encryption" ON)
|
||||
option(USE_AES "Enables building with AES library" ON)
|
||||
option(BUILD_TEST "Enables building of minizip executable." OFF)
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
|
||||
# Set a consistent MACOSX_RPATH default across all CMake versions.
|
||||
# When CMake 2.8.12 is required, change this default to 1.
|
||||
# When CMake 3.0.0 is required, remove this block (see CMP0042).
|
||||
if(NOT DEFINED CMAKE_MACOSX_RPATH)
|
||||
set(CMAKE_MACOSX_RPATH 0)
|
||||
endif()
|
||||
|
||||
set(INSTALL_BIN_DIR "bin" CACHE PATH "Installation directory for executables")
|
||||
set(INSTALL_LIB_DIR "lib" CACHE PATH "Installation directory for libraries")
|
||||
set(INSTALL_INC_DIR "include" CACHE PATH "Installation directory for headers")
|
||||
set(INSTALL_MAN_DIR "share/man" CACHE PATH "Installation directory for manual pages")
|
||||
set(INSTALL_PKGCONFIG_DIR "share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
|
||||
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(COMPRESS_ONLY "Only support compression" OFF)
|
||||
option(DECOMPRESS_ONLY "Only support decompression" OFF)
|
||||
option(BUILD_TEST "Builds minizip test executable" OFF)
|
||||
|
||||
project("minizip")
|
||||
|
||||
set(VERSION "2.2.4")
|
||||
include(CheckLibraryExists)
|
||||
include(CheckSymbolExists)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
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.5.2")
|
||||
|
||||
# Minizip api version
|
||||
set(SOVERSION "2.5")
|
||||
|
||||
# Set cmake debug postfix to d
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
@@ -39,6 +45,17 @@ if(USE_ZLIB)
|
||||
if(ZLIB_FOUND)
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
endif()
|
||||
add_definitions(-DHAVE_ZLIB)
|
||||
endif()
|
||||
|
||||
# Check if bzip2 installation is present
|
||||
if(USE_BZIP2)
|
||||
set(BZIP2_ROOT ${DEF_BZIP2_ROOT} CACHE PATH "Parent directory of bzip2 installation")
|
||||
find_package(BZip2)
|
||||
if(BZIP2_FOUND)
|
||||
include_directories(${BZIP2_INCLUDE_DIRS})
|
||||
endif()
|
||||
add_definitions(-DHAVE_BZIP2)
|
||||
endif()
|
||||
|
||||
set(MINIZIP_PC ${CMAKE_CURRENT_BINARY_DIR}/minizip.pc)
|
||||
@@ -47,83 +64,129 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/minizip.pc.cmakein ${MINIZIP_PC} @ONL
|
||||
set(PROJECT_NAME libminizip)
|
||||
|
||||
set(MINIZIP_SRC
|
||||
src/mz_os.c
|
||||
src/mz_compat.c
|
||||
src/mz_strm.c
|
||||
src/mz_strm_buf.c
|
||||
src/mz_strm_mem.c
|
||||
src/mz_strm_posix.c
|
||||
src/mz_strm_split.c
|
||||
src/mz_strm_zlib.c
|
||||
src/mz_zip.c)
|
||||
mz_os.c
|
||||
mz_compat.c
|
||||
mz_strm.c
|
||||
mz_strm_buf.c
|
||||
mz_strm_crc32.c
|
||||
mz_strm_mem.c
|
||||
mz_strm_posix.c
|
||||
mz_strm_split.c
|
||||
mz_zip.c
|
||||
mz_zip_rw.c)
|
||||
|
||||
set(MINIZIP_PUBLIC_HEADERS
|
||||
src/mz.h
|
||||
src/mz_os.h
|
||||
src/mz_compat.h
|
||||
src/mz_strm.h
|
||||
src/mz_strm_buf.h
|
||||
src/mz_strm_mem.h
|
||||
src/mz_strm_posix.h
|
||||
src/mz_strm_split.h
|
||||
src/mz_strm_zlib.h
|
||||
src/mz_zip.h)
|
||||
mz.h
|
||||
mz_os.h
|
||||
mz_compat.h
|
||||
mz_strm.h
|
||||
mz_strm_buf.h
|
||||
mz_strm_crc32.h
|
||||
mz_strm_mem.h
|
||||
mz_strm_posix.h
|
||||
mz_strm_split.h
|
||||
mz_zip.h
|
||||
mz_zip_rw.h)
|
||||
|
||||
if(COMPRESS_ONLY)
|
||||
add_definitions(-DMZ_ZIP_NO_DECOMPRESSION)
|
||||
endif()
|
||||
if(DECOMPRESS_ONLY)
|
||||
add_definitions(-DMZ_ZIP_NO_COMPRESSION)
|
||||
endif()
|
||||
if(NOT USE_PKCRYPT AND NOT USE_AES)
|
||||
add_definitions(-DMZ_ZIP_NO_ENCRYPTION)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND MINIZIP_SRC "src/mz_os_win32.c" "src/mz_strm_win32.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "src/mz_os_win32.h" "src/mz_strm_win32.h")
|
||||
list(APPEND MINIZIP_SRC "mz_os_win32.c" "mz_strm_win32.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_os_win32.h" "mz_strm_win32.h")
|
||||
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
endif()
|
||||
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
|
||||
add_definitions(-DMZ_USE_WINRT_API)
|
||||
add_definitions(-DMZ_WINRT_API)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O3")
|
||||
add_compile_options(-O3)
|
||||
|
||||
list(APPEND MINIZIP_SRC "src/mz_os_posix.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "src/mz_os_posix.h")
|
||||
list(APPEND MINIZIP_SRC "mz_os_posix.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_os_posix.h")
|
||||
|
||||
add_definitions(-D__USE_FILE_OFFSET64)
|
||||
add_definitions(-D__USE_LARGEFILE64)
|
||||
add_definitions(-D_LARGEFILE64_SOURCE)
|
||||
add_definitions(-D_FILE_OFFSET_BIT=64)
|
||||
set(define_lfs_macros TRUE)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
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()
|
||||
|
||||
pkg_check_modules(LIBBSD libbsd)
|
||||
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()
|
||||
|
||||
include_directories(${LIBBSD_INCLUDE_DIRS})
|
||||
link_directories(${LIBBSD_LIBRARY_DIRS})
|
||||
check_symbol_exists("getrandom" "sys/random.h" HAVE_GETRANDOM)
|
||||
if (HAVE_GETRANDOM)
|
||||
add_definitions(-DHAVE_GETRANDOM)
|
||||
endif()
|
||||
check_symbol_exists("arc4random_buf" "stdlib.h" HAVE_ARC4RANDOM_BUF)
|
||||
if (HAVE_ARC4RANDOM_BUF)
|
||||
add_definitions(-DHAVE_ARC4RANDOM_BUF)
|
||||
else()
|
||||
check_symbol_exists("arc4random" "stdlib.h" HAVE_ARC4RANDOM)
|
||||
if (HAVE_ARC4RANDOM)
|
||||
add_definitions(-DHAVE_ARC4RANDOM)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_ARC4RANDOM_BUF)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
pkg_check_modules(LIBBSD libbsd)
|
||||
if (LIBBSD_FOUND)
|
||||
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)
|
||||
include_directories(${LIBBSD_INCLUDE_DIRS})
|
||||
link_directories(${LIBBSD_LIBRARY_DIRS})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_CRYPT)
|
||||
add_definitions(-DHAVE_CRYPT)
|
||||
if(USE_PKCRYPT)
|
||||
add_definitions(-DHAVE_PKCRYPT)
|
||||
|
||||
list(APPEND MINIZIP_SRC "src/mz_strm_crypt.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "src/mz_strm_crypt.h")
|
||||
list(APPEND MINIZIP_SRC "mz_strm_pkcrypt.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_pkcrypt.h")
|
||||
endif()
|
||||
|
||||
if(USE_AES)
|
||||
add_definitions(-DHAVE_AES)
|
||||
|
||||
list(APPEND MINIZIP_SRC "src/mz_strm_aes.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "src/mz_strm_aes.h")
|
||||
list(APPEND MINIZIP_SRC "mz_strm_aes.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_aes.h")
|
||||
|
||||
set(AES_SRC
|
||||
lib/aes/aescrypt.c
|
||||
lib/aes/aeskey.c
|
||||
lib/aes/aestab.c
|
||||
lib/aes/aes_ni.c
|
||||
lib/aes/hmac.c
|
||||
lib/aes/pwd2key.c
|
||||
lib/aes/sha1.c)
|
||||
|
||||
set(AES_PUBLIC_HEADERS
|
||||
lib/aes/aes.h
|
||||
lib/aes/aes_ni.h
|
||||
lib/aes/aesopt.h
|
||||
lib/aes/aestab.h
|
||||
lib/aes/brg_endian.h
|
||||
@@ -139,13 +202,33 @@ endif()
|
||||
|
||||
if(USE_ZLIB)
|
||||
add_definitions(-DHAVE_ZLIB)
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_strm_zlib.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_zlib.h")
|
||||
|
||||
include(CheckFunctionExists)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB)
|
||||
CHECK_FUNCTION_EXISTS(z_get_crc_table
|
||||
NEEDS_Z_PREFIX)
|
||||
|
||||
if(NEEDS_Z_PREFIX)
|
||||
add_definitions(-DZ_PREFIX)
|
||||
endif()
|
||||
endif()
|
||||
if(USE_BZIP2)
|
||||
|
||||
if(USE_BZIP2 AND BZIP2_FOUND)
|
||||
add_definitions(-DHAVE_BZIP2)
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_strm_bzip.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_bzip.h")
|
||||
|
||||
set(CMAKE_REQUIRED_LIBRARIES BZip2::BZip2)
|
||||
elseif(USE_BZIP2)
|
||||
add_definitions(-DHAVE_BZIP2)
|
||||
add_definitions(-DBZ_NO_STDIO)
|
||||
|
||||
list(APPEND MINIZIP_SRC "src/mz_strm_bzip.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "src/mz_strm_bzip.h")
|
||||
list(APPEND MINIZIP_SRC "mz_strm_bzip.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_bzip.h")
|
||||
|
||||
set(BZIP2_SRC
|
||||
lib/bzip2/blocksort.c
|
||||
@@ -170,8 +253,8 @@ if(USE_LZMA)
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
add_definitions(-DLZMA_API_STATIC)
|
||||
|
||||
list(APPEND MINIZIP_SRC "src/mz_strm_lzma.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "src/mz_strm_lzma.h")
|
||||
list(APPEND MINIZIP_SRC "mz_strm_lzma.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_lzma.h")
|
||||
|
||||
set(LZMA_CHECK_SRC
|
||||
lib/liblzma/check/check.c
|
||||
@@ -273,8 +356,19 @@ if(USE_LZMA)
|
||||
source_group("LZMA\\RangeCoder" FILES ${LZMA_RANGECODER_SRC} ${LZMA_RANGECODER_HEADERS})
|
||||
endif()
|
||||
|
||||
# Enable x86 optimizations if supported
|
||||
if(CMAKE_C_COMPILER MATCHES ".*clang")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3 -msse4.1 -maes")
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
# Create minizip library
|
||||
@@ -286,10 +380,20 @@ add_library(${PROJECT_NAME}
|
||||
${BZIP2_SRC} ${BZIP2_PUBLIC_HEADERS}
|
||||
${LZMA_SRC} ${LZMA_PUBLIC_HEADERS})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C PREFIX "")
|
||||
if (MINGW 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)
|
||||
if(USE_ZLIB)
|
||||
target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)
|
||||
endif()
|
||||
if(USE_BZIP2 AND BZIP2_FOUND)
|
||||
target_link_libraries(${PROJECT_NAME} BZip2::BZip2)
|
||||
endif()
|
||||
if(USE_LZMA)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99)
|
||||
endif()
|
||||
@@ -299,23 +403,29 @@ endif()
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC $<INSTALL_INTERFACE:${INSTALL_INC_DIR}>)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
|
||||
INCLUDES DESTINATION "${INSTALL_INC_DIR}"
|
||||
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
|
||||
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_LIB_DIR}")
|
||||
|
||||
install(EXPORT ${PROJECT_NAME}
|
||||
DESTINATION "cmake"
|
||||
NAMESPACE "MINIZIP::")
|
||||
|
||||
install(FILES ${MINIZIP_PUBLIC_HEADERS} DESTINATION "${INSTALL_INC_DIR}")
|
||||
install(FILES ${MINIZIP_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
|
||||
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
|
||||
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
|
||||
INCLUDES DESTINATION "${INSTALL_INC_DIR}"
|
||||
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
|
||||
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_LIB_DIR}")
|
||||
install(EXPORT ${PROJECT_NAME}
|
||||
DESTINATION "${INSTALL_CMAKE_DIR}"
|
||||
NAMESPACE "MINIZIP::")
|
||||
endif()
|
||||
if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
|
||||
install(FILES ${MINIZIP_PUBLIC_HEADERS} DESTINATION "${INSTALL_INC_DIR}")
|
||||
endif()
|
||||
if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
|
||||
install(FILES ${MINIZIP_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}")
|
||||
endif()
|
||||
|
||||
if(BUILD_TEST)
|
||||
add_executable(minizip "src/minizip.c")
|
||||
add_executable(minizip "minizip.c")
|
||||
target_link_libraries(minizip ${PROJECT_NAME})
|
||||
|
||||
install(TARGETS minizip
|
||||
if(NOT SKIP_INSTALL_BINARIES AND NOT SKIP_INSTALL_ALL)
|
||||
install(TARGETS minizip
|
||||
RUNTIME DESTINATION "bin")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'Minizip'
|
||||
s.version = '2.2.4'
|
||||
s.version = '2.5.2'
|
||||
s.license = 'zlib'
|
||||
s.summary = 'Minizip contrib in zlib with the latest bug fixes and advanced features'
|
||||
s.description = <<-DESC
|
||||
@@ -17,7 +17,7 @@ DESC
|
||||
s.libraries = 'z'
|
||||
|
||||
s.subspec 'Core' do |sp|
|
||||
sp.source_files = 'src/{mz_os,mz_compat,mz_strm,mz_strm_mem,mz_strm_buf,mz_zip,mz_strm_crypt,mz_strm_posix,mz_strm_zlib}.{c,h}'
|
||||
sp.source_files = '{mz_os,mz_compat,mz_strm,mz_strm_mem,mz_strm_buf,mz_zip,mz_strm_crypt,mz_strm_posix,mz_strm_zlib}.{c,h}'
|
||||
end
|
||||
|
||||
s.subspec 'AES' do |sp|
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Minizip 2.2.4
|
||||
# Minizip 2.5.2
|
||||
|
||||
This library is a refactoring of the minizip contribution found in the zlib distribution that is supported on Windows, macOS, and Linux. The motivation for this work has been the inclusion of advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. It is based on the original work of [Gilles Vollant](http://www.winimage.com/zLibDll/minizip.html) that has been contributed to by many people over the years.
|
||||
This library is a refactoring of the minizip contribution found in the zlib distribution and is supported on Windows, macOS, and Linux. The motivation for this work has been the inclusion of advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. It is based on the original work of [Gilles Vollant](http://www.winimage.com/zLibDll/minizip.html) that has been contributed to by many people over the years.
|
||||
|
||||
Dev: 
|
||||
Master: 
|
||||
@@ -10,11 +10,49 @@ For the original work maintained by Mark Adler checkout the zlib minizip [contr
|
||||
|
||||
## Build
|
||||
|
||||
To generate the project files for your platform and IDE download and run cmake in the project directory.
|
||||
To generate project files for your platform:
|
||||
|
||||
1. [Download and install](https://cmake.org/install/) cmake.
|
||||
2. [Download](https://zlib.net/) and install zlib if it is not installed on your system.
|
||||
3. Run cmake in the minizip directory.
|
||||
|
||||
```
|
||||
cmake . -DBUILD_TEST=ON
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
## Build Options
|
||||
|
||||
| Name | Description | Default Value |
|
||||
|:- |:-|:-:|
|
||||
| USE_ZLIB | Enables ZLIB compression | ON |
|
||||
| USE_BZIP2 | Enables BZIP2 compression | ON |
|
||||
| USE_LZMA | Enables LZMA compression | ON |
|
||||
| USE_PKCRYPT | Enables PKWARE traditional encryption | ON |
|
||||
| COMPRESS_ONLY | Only support compression | OFF |
|
||||
| DECOMPRESS_ONLY | Only support decompression | OFF |
|
||||
| BUILD_TEST | Builds minizip test executable | OFF |
|
||||
|
||||
## Zlib Installation (Windows)
|
||||
|
||||
Option 1. Install the zlib package to the Program Files directory with an Administrator command prompt.
|
||||
|
||||
```
|
||||
cmake . -DCMAKE_INSTALL_PREFIX=%PROGRAMFILES%\zlib
|
||||
cmake --build . --config Release --target INSTALL
|
||||
```
|
||||
|
||||
Option 2. Compile zlib in minizip's lib directory.
|
||||
|
||||
```
|
||||
cmake .
|
||||
cmake --build .
|
||||
cmake --build . --config Release
|
||||
```
|
||||
|
||||
Navigate back to the minizip directory and before building run:
|
||||
|
||||
```
|
||||
cmake . -DZLIB_LIBRARY=lib\zlib\release\zlibstatic.lib -DZLIB_INCLUDE_DIR=lib\zlib\
|
||||
```
|
||||
|
||||
## Contents
|
||||
@@ -29,14 +67,16 @@ cmake --build .
|
||||
| mz_strm_aes.\* | WinZIP AES stream | No |
|
||||
| mz_strm_buf.\* | Buffered stream | No |
|
||||
| mz_strm_bzip.\* | BZIP2 stream using libbzip2 | No |
|
||||
| mz_strm_crypt.\* | PKWARE traditional encryption stream | No |
|
||||
| mz_strm_lzma.\* | LZMA stream using liblzma | No |
|
||||
| mz_strm_crc32.\* | CRC32 stream | Yes |
|
||||
| mz_strm_lzma.\* | LZMA stream using liblzma | zlib or liblzma |
|
||||
| mz_strm_mem.\* | Memory stream | Yes |
|
||||
| mz_strm_split.\* | Disk splitting stream | No |
|
||||
| mz_strm_pkcrypt.\* | PKWARE traditional encryption stream | No |
|
||||
| mz_strm_posix.\* | File stream using Posix functions | Non-windows systems |
|
||||
| mz_strm_win32.\* | File stream using Win32 API functions | Windows systems |
|
||||
| mz_strm_zlib.\* | Deflate stream using zlib | Yes |
|
||||
| mz_zip.\* | Zip functionality | Yes |
|
||||
| mz_strm_zlib.\* | Deflate stream using zlib | zlib or liblzma |
|
||||
| mz_zip.\* | Zip format | Yes |
|
||||
| mz_zip_rw.\* | Zip reader/writer | No |
|
||||
|
||||
## Features
|
||||
|
||||
@@ -50,14 +90,14 @@ cmake --build .
|
||||
#### LZMA
|
||||
|
||||
+ Requires ``cmake . -DUSE_LZMA=ON`` or ``#define HAVE_LZMA``
|
||||
+ Requires [liblzma](https://tukaani.org/xz/) library
|
||||
+ Requires [liblzma](https://tukaani.org/xz/) library with modifications
|
||||
|
||||
### Encryption
|
||||
|
||||
#### [WinZIP AES Encryption](http://www.winzip.com/aes_info.htm)
|
||||
#### [WinZIP AES Encryption](https://www.winzip.com/aes_info.htm)
|
||||
|
||||
+ Requires ``cmake . -DUSE_AES=ON`` or ``#define HAVE_AES``
|
||||
+ Requires [Brian Gladman's](https://github.com/BrianGladman/aes) AES library
|
||||
+ Requires Brian Gladman's [AES](https://github.com/BrianGladman/aes) and [SHA](https://github.com/BrianGladman/sha) libraries
|
||||
|
||||
When zipping with a password it will always use AES 256-bit encryption.
|
||||
When unzipping it will use AES decryption only if necessary.
|
||||
@@ -68,7 +108,7 @@ To disable encryption use the following cmake commands:
|
||||
|
||||
```
|
||||
cmake . -DUSE_AES=OFF
|
||||
cmake . -DUSE_CRYPT=OFF
|
||||
cmake . -DUSE_PKCRYPT=OFF
|
||||
```
|
||||
|
||||
### NTFS Timestamps
|
||||
@@ -81,7 +121,7 @@ This library has been refactored around streams.
|
||||
|
||||
#### Memory Streaming
|
||||
|
||||
To unzip from a zip file in memory create a memory stream and pass it to the unzip open functions.
|
||||
To unzip from a zip file in memory pass the memory stream to the open function.
|
||||
```
|
||||
uint8_t *zip_buffer = NULL;
|
||||
int32_t zip_buffer_size = 0;
|
||||
@@ -98,7 +138,7 @@ void *zip_handle = mz_zip_open(mem_stream, MZ_OPEN_MODE_READ);
|
||||
mz_stream_mem_delete(&mem_stream);
|
||||
```
|
||||
|
||||
To create a zip file in memory first create a growable memory stream and pass it to the zip open functions.
|
||||
To create a zip file in memory first create a growable memory stream and pass it to the open function.
|
||||
|
||||
```
|
||||
void *mem_stream = NULL;
|
||||
@@ -135,7 +175,7 @@ void *zip_handle = mz_zip_open(buf_stream, MZ_OPEN_MODE_READ);
|
||||
|
||||
#### Disk Splitting Stream
|
||||
|
||||
To create an archive with multiple disks use the disk splitting stream and for zipping supply a disk size value in bytes.
|
||||
To create an archive with multiple disks use the disk splitting stream and supply a disk size value in bytes.
|
||||
|
||||
```
|
||||
void *stream = NULL;
|
||||
@@ -150,19 +190,16 @@ mz_stream_set_base(split_stream, stream);
|
||||
|
||||
mz_stream_open(split_stream, path..
|
||||
|
||||
handle = mz_zip_open(split_stream, MZ_OPEN_MODE_WRITE);
|
||||
void *zip_handle = mz_zip_open(split_stream, MZ_OPEN_MODE_WRITE);
|
||||
```
|
||||
|
||||
The central directory is the only data stored in the .zip and doesn't follow disk size restrictions.
|
||||
|
||||
When unzipping it will automatically determine when in needs to cross disk boundaries.
|
||||
|
||||
### Windows RT
|
||||
|
||||
+ Requires ``#define MZ_USE_WINRT_API``
|
||||
+ Requires ``#define MZ_WINRT_API``
|
||||
|
||||
## Limitations
|
||||
|
||||
+ Archives are required to have a central directory.
|
||||
+ Central directory header values should be correct and it is necessary for the compressed size to be accurate for AES encryption.
|
||||
+ Central directory encryption is not supported due to licensing restrictions mentioned by PKWARE in their zip appnote.
|
||||
+ Central directory is the only data stored on the last disk of a split-disk archive and doesn't follow disk size restrictions.
|
||||
|
||||
+3497
File diff suppressed because it is too large
Load Diff
+1243
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,261 @@
|
||||
|
||||
# AES Encryption Information:
|
||||
Encryption Specification AE-1 and AE-2
|
||||
|
||||
**Document version: 1.04
|
||||
Last modified: January 30, 2009**
|
||||
|
||||
**NOTE: WinZip® users do not need to read or understand the information contained on this page. It is intended for developers of Zip file utilities.**
|
||||
|
||||
Changes since the original version of this document are summarized in the [Change History](https://www.winzip.com/aes_info.htm#changes) section below.
|
||||
|
||||
This document describes the file format that WinZip uses to create [AES-encrypted Zip files](https://www.winzip.com/learn/aes-encryption.html). The AE-1 encryption specification was introduced in WinZip 9.0 Beta 1, released in May 2003. The AE-2 encryption specification, a minor variant of the original AE-1 specification differing only in how the CRC is handled, was introduced in WinZip 9.0 Beta 3, released in January, 2004. Note that as of WinZip 11, WinZip itself encrypts most files using the AE-1 format and encrypts others using the AE-2 format.
|
||||
|
||||
From time to time we may update the information provided here, for example to document any changes to the file formats, or to add additional notes or implementation tips. If you would like to receive e-mail announcements of any substantive changes we make to this document, you can [sign up below](https://www.winzip.com/aes_info.htm#mailing-list)for our Developer Information mailing list.
|
||||
|
||||
Without compromising the basic Zip file format, WinZip Computing has extended the format specification to support AES encryption, and this document fully describes the format extension. Additionally, we are providing information about a no-cost third-party source for the actual AES encryption code--the same code that is used by WinZip. We believe that use of the free encryption code and of this specification will make it easy for all developers to add compatible advanced encryption to their Zip file utilities.
|
||||
|
||||
This document is not a tutorial on encryption or Zip file structure. While we have attempted to provide the necessary details of the current WinZip AES encryption format, developers and other interested third parties will need to have or obtain an understanding of basic encryption concepts, Zip file format, etc.
|
||||
|
||||
Developers should also review [AES Coding Tips](https://www.winzip.com/aes_tips.html) page.
|
||||
|
||||
WinZip Computing makes no warranties regarding the information provided in this document. In particular, WinZip Computing does not represent or warrant that the information provided here is free from errors or is suitable for any particular use, or that the file formats described here will be supported in future versions of WinZip. You should test and validate all code and techniques in accordance with good programming practice.
|
||||
|
||||
----------
|
||||
|
||||
**I. Encryption services**
|
||||
|
||||
To perform AES encryption and decryption, WinZip uses AES functions written by Dr. Brian Gladman. The source code for these functions is available in C/C++ and Pentium family assembler for anyone to use under an open source BSD or GPL license from [the AES project page](https://www.winzip.com/gladman.cgi) on Dr. Gladman's web site. The [AES Coding Tips](https://www.winzip.com/aes_tips.html) page also has some information on the use of these functions. WinZip Computing thanks Dr. Gladman for making his AES functions available to anyone under liberal license terms.
|
||||
|
||||
Dr. Gladman's encryption functions are portable to a number of operating systems and can be static linked into your applications, so there are no operating system version or library dependencies. In particular, the functions do not require Microsoft's Cryptography API.
|
||||
|
||||
General information on the AES standard and the encryption algorithm (also known as _Rijndael_) is readily available on the Internet. A good place to start is [http://www.nist.gov/public_affairs/releases/g00-176.htm](http://www.nist.gov/public_affairs/releases/g00-176.htm).
|
||||
|
||||
**II. Zip file format**
|
||||
|
||||
1. Base format reference
|
||||
|
||||
AES-encrypted files are stored within the guidelines of the standard Zip file format using only a new "extra data" field, a new compression method code, and a value in the CRC field dependant on the encryption version, AE-1 or AE-2. The basic Zip file format is otherwise unchanged.
|
||||
|
||||
WinZip sets the version needed to extract and version made by fields in the local and central headers to the same values it would use if the file were not encrypted.
|
||||
|
||||
The basic Zip file format specification used by WinZip is available via FTP from the Info-ZIP group at [ftp://ftp.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip](ftp://ftp.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip).
|
||||
|
||||
2. Compression method and encryption flag
|
||||
|
||||
As for any encrypted file, bit 0 of the "general purpose bit flags" field must be set to 1 in each AES-encrypted file's local header and central directory entry.
|
||||
|
||||
Additionally, the presence of an AES-encrypted file in a Zip file is indicated by a new compression method code (decimal 99) in the file's local header and central directory entry, used along with the AES extra data field described below. There is no change in either the _version made by_ or _version needed to extract_ codes.
|
||||
|
||||
The code for the actual compression method is stored in the AES extra data field (see below).
|
||||
|
||||
3. CRC value
|
||||
|
||||
For files encrypted using the AE-2 method, the standard Zip CRC value is _not_ used, and a 0 must be stored in this field. Corruption of encrypted data within a Zip file is instead detected via the [authentication code](https://www.winzip.com/aes_info.htm#authentication-code) field.
|
||||
|
||||
Files encrypted using the AE-1 method _do_ include the standard Zip CRC value. This, along with the fact that the vendor version stored in the AES extra data field is 0x0001 for AE-1 and 0x0002 for AE-2, is the only difference between the AE-1 and AE-2 formats.
|
||||
|
||||
**NOTE:** Zip utilities that support the AE-2 format are required to be able to read files that were created in the AE-1 format, and during decryption/extraction of files in AE-1 format should verify that the file's CRC matches the value stored in the CRC field.
|
||||
|
||||
4. AES extra data field
|
||||
1. A file encrypted with AES encryption will have a special "extra data" field associated with it. This extra data field is stored in both the local header and central directory entry for the file.
|
||||
|
||||
Note: see the Zip file format document referenced above for general information on the format and use of extra data fields.
|
||||
|
||||
2. The extra data header ID for AES encryption is 0x9901. The fields are all stored in Intel low-byte/high-byte order. The extra data field currently has a length of 11: seven data bytes plus two bytes for the header ID and two bytes for the data size. Therefore, the extra data overhead for each file in the archive is 22 bytes (11 bytes in the central header plus 11 bytes in the local header).
|
||||
3. The format of the data in the AES extra data field is as follows. See the notes below for additional information.
|
||||
|
||||
|**Offset**|**Size(bytes)**|**Content**|
|
||||
|:-|:-|:-|
|
||||
|0|2|Extra field header ID (0x9901)|
|
||||
|2|2|Data size (currently 7, but subject to possible increase in the future)|
|
||||
|4|2|Integer version number specific to the zip vendor|
|
||||
|6|2|2-character vendor ID|
|
||||
|8|1|Integer mode value indicating AES encryption strength|
|
||||
|9|2|The actual compression method used to compress the file|
|
||||
|
||||
4. Notes
|
||||
- **Data size**: this value is currently 7, but because it is possible that this specification will be modified in the future to store additional data in this extra field, vendors should not assume that it will always remain 7.
|
||||
- **Vendor ID**: the vendor ID field should always be set to the two ASCII characters "AE".
|
||||
- **Vendor version**: the vendor version for AE-1 is 0x0001. The vendor version for AE-2 is 0x0002.
|
||||
|
||||
Zip utilities that support AE-2 must also be able to process files that are encrypted in AE-1 format. The handling of the [CRC value](https://www.winzip.com/aes_info.htm#CRC) is the only difference between the AE-1 and AE-2 formats.
|
||||
|
||||
- **Encryption strength**: the mode values (encryption strength) for AE-1 and AE-2 are:
|
||||
|
||||
|**Value**|**Strength**|
|
||||
|-|-|
|
||||
|0x01|128-bit encryption key|
|
||||
|0x02|192-bit encryption key|
|
||||
|0x03|256-bit encryption key|
|
||||
|
||||
The encryption specification supports _only_ 128-, 192-, and 256-bit encryption keys. No other key lengths are permitted.
|
||||
|
||||
(Note: the current version of WinZip does not support encrypting files using 192-bit keys. This specification, however, does provide for the use of 192-bit keys, and WinZip is able to decrypt such files.)
|
||||
|
||||
- **Compression method**: the compression method is the one that would otherwise have been stored in the local and central headers for the file. For example, if the file is imploded, this field will contain the compression code 6. This is needed because a compression method of 99 is used to indicate the presence of an AES-encrypted file (see [above](https://www.winzip.com/aes_info.htm#comp-method)).
|
||||
|
||||
**III. Encrypted file storage format**
|
||||
|
||||
1. File format
|
||||
|
||||
Additional overhead data required for decryption is stored with the encrypted file itself (i.e., not in the headers). The actual format of the stored file is as follows; additional information about these fields is below. All fields are byte-aligned.
|
||||
|
||||
|**Size (bytes)**|**Content**|
|
||||
|:-|:-|
|
||||
|Variable|Salt value|
|
||||
|2|Password verification value|
|
||||
|Variable|Encrypted file data|
|
||||
|10|Authentication code|
|
||||
|
||||
Note that the value in the "compressed size" fields of the local file header and the central directory entry is the total size of all the items listed above. In other words, it is the total size of the salt value, password verification value, encrypted data, and authentication code.
|
||||
|
||||
2. Salt value
|
||||
|
||||
The "salt" or "salt value" is a random or pseudo-random sequence of bytes that is combined with the encryption password to create encryption and authentication keys. The salt is generated by the encrypting application and is stored unencrypted with the file data. The addition of salt values to passwords provides a number of security benefits and makes dictionary attacks based on precomputed keys much more difficult.
|
||||
|
||||
Good cryptographic practice requires that a different salt value be used for each of multiple files encrypted with the same password. If two files are encrypted with the same password and salt, they can leak information about each other. For example, it is possible to determine whether two files encrypted with the same password and salt are identical, and an attacker who somehow already knows the contents of one of two files encrypted with the same password and salt can determine some or all of the contents of the other file. Therefore, you should make every effort to use a unique salt value for each file.
|
||||
|
||||
The size of the salt value depends on the length of the encryption key, as follows:
|
||||
|
||||
|**Key size**|**Salt size**|
|
||||
|:-|:-|
|
||||
|128 bits|8 bytes|
|
||||
|192 bits|12 bytes|
|
||||
|256 bits|16 bytes|
|
||||
|
||||
3. Password verification value
|
||||
|
||||
This two-byte value is produced as part of the process that derives the encryption and decryption keys from the password. When encrypting, a verification value is derived from the encryption password and stored with the encrypted file. Before decrypting, a verification value can be derived from the decryption password and compared to the value stored with the file, serving as a quick check that will detect _most_, but not all, incorrect passwords. There is a 1 in 65,536 chance that an incorrect password will yield a matching verification value; therefore, a matching verification value cannot be absolutely relied on to indicate a correct password.
|
||||
|
||||
Information on how to obtain the password verification value from Dr. Gladman's encryption library can be found on the [coding tips](https://www.winzip.com/aes_tips.html) page.
|
||||
|
||||
This value is stored unencrypted.
|
||||
|
||||
4. Encrypted file data
|
||||
|
||||
Encryption is applied only to the content of files. It is performed after compression, and not to any other associated data. The file data is encrypted byte-for-byte using the AES encryption algorithm operating in "CTR" mode, which means that the lengths of the compressed data and the compressed, encrypted data are the same.
|
||||
|
||||
It is important for implementors to note that, although the data is encrypted byte-for-byte, it is presented to the encryption and decryption functions in blocks. The block size used for encryption and decryption must be the same. To be compatible with the encryption specification, this block size must be 16 bytes (although the last block may be smaller).
|
||||
|
||||
5. Authentication code
|
||||
|
||||
Authentication provides a high quality check that the contents of an encrypted file have not been inadvertently changed or deliberately tampered with since they were first encrypted. In effect, this is a super-CRC check on the data in the file _after_ compression and encryption. (Additionally, authentication is essential when using CTR mode encryption because this mode is vulnerable to several trivial attacks in its absence.)
|
||||
|
||||
The authentication code is derived from the output of the encryption process. [Dr. Gladman's AES code](https://www.winzip.com/aes_info.htm#encryption) provides this service, and information about how to obtain it is in the [coding tips](https://www.winzip.com/aes_tips.html).
|
||||
|
||||
The authentication code is stored unencrypted. It is byte-aligned and immediately follows the last byte of encrypted data.
|
||||
|
||||
For more discussion about authentication, see the [authentication code FAQ](https://www.winzip.com/aes_info.htm#auth-faq) below.
|
||||
|
||||
|
||||
**IV. Changes in WinZip 11**
|
||||
|
||||
Beginning with WinZip 11, WinZip makes a change in its use of the AE-1 and AE-2 file formats. The file formats themselves have not changed, and AES-encrypted files created by WinZip 11 are completely compatible with version 1.02 the WinZip AES encryption specification, which was published in January 2004.
|
||||
|
||||
[WinZip 9.0](https://www.winzip.com/win/en/winzip-9.html) and [WinZip 10.0](https://www.winzip.com/win/en/winzip-10.html) stored all AES-encrypted files using the AE-2 file format, which does not store the encrypted file's CRC. WinZip 11 instead uses the AE-1 file format, which does store the CRC, for most files. This provides an extra integrity check against the possibility of hardware or software errors that occur during the actual process of [file compression/encryption](https://www.winzip.com/win/en/features/data-protection.html) or decryption/decompression. For more information on this point, see the discussion of the [CRC](https://www.winzip.com/aes_info.htm#crc-faq) below.
|
||||
|
||||
Because for some very small files the CRC can be used to determine the exact contents of a file, regardless of the encryption method used, WinZip 11 continues to use the AE-2 file format, with no CRC stored, for files with an uncompressed size of less than 20 bytes. WinZip 11 also uses the AE-2 file format for files compressed in BZIP2 format, because the BZIP2 format contains its own integrity checks equivalent to those provided by the Zip format's CRC.
|
||||
|
||||
Other vendors who support WinZip's AES encryption specification may want to consider making a similar change to their own implementations of the specification, to get the benefit of the extra integrity check that it provides.
|
||||
|
||||
Note that the January 2004 version of the WinZip AE-2 specification, version 1.0.2, already required that all utilities that implemented the AE-2 format also be able to process files in AE-1 format, and should check on decryption/extraction of those files that the CRC was correct.
|
||||
|
||||
**V. Notes**
|
||||
|
||||
1. Non-files and zero-length files
|
||||
|
||||
To reduce Zip file size, it is recommended that non-file entries such as folder/directory entries not be encrypted. This, however, is only a recommendation; it is permissible to encrypt or not encrypt these entries, as you prefer.
|
||||
|
||||
On the other hand, it is recommended that you _do_ encrypt zero-length files. The presence of both encrypted and unencrypted files in a Zip file may trigger user warnings in some Zip file utilities, so the user experience may be improved if all files (including zero-length files) are encrypted.
|
||||
|
||||
If zero-length files are encrypted, the encrypted data portion of the file storage (see [above](https://www.winzip.com/aes_info.htm#encrypted-data)) will be empty, but the remainder of the encryption overhead data must be present, both in the file storage area and in the local and central headers.
|
||||
|
||||
2. "Mixed" Zip files
|
||||
|
||||
There is no requirement that all files in a Zip file be encrypted or that all files that _are_ encrypted use the same encryption method or the same password.
|
||||
|
||||
A Zip file can contain any combination of unencrypted files and files encrypted with any of the four currently defined encryption methods (Zip 2.0, AES-128, AES-192, AES-256). Encrypted files may use the same password or different passwords.
|
||||
|
||||
3. Key Generation
|
||||
|
||||
Key derivation, as used by AE-1 and AE-2 and as implemented in Dr. Gladman's library, is done according to the PBKDF2 algorithm, which is described in the [RFC2898](http://www.faqs.org/rfcs/rfc2898.html) guidelines. An iteration count of 1000 is used. An appropriate number of bits from the resulting hash value are used to compose three output values: an encryption key, an authentication key, and a password verification value. The first _n_ bits become the encryption key, the next _m_ bits become the authentication key, and the last 16 bits (two bytes) become the password verification value.
|
||||
|
||||
As part of the process outlined in RFC 2898 a pseudo-random function must be called; AE-2 uses the HMAC-SHA1 function, since it is a well-respected algorithm that has been in wide use for this purpose for several years.
|
||||
|
||||
Note that, when used in connection with 192- or 256-bit AES encryption, the fact that HMAC-SHA1 produces a 160-bit result means that, regardless of the password that you specify, the search space for the encryption key is unlikely to reach the theoretical 192- or 256-bit maximum, and cannot be guaranteed to exceed 160 bits. This is discussed in section B.1.1 of the [RFC2898 specification](http://www.faqs.org/rfcs/rfc2898.html).
|
||||
|
||||
|
||||
**VI. FAQs**
|
||||
|
||||
- **Why is the compression method field used to indicate AES encryption?**
|
||||
|
||||
As opposed to using new _version made by_ and _version needed to extract_ values to signal AES encryption for a file, the new compression method is more likely to be handled gracefully by older versions of existing Zip file utilities. Zip file utilities typically do not attempt to extract files compressed with unknown methods, presumably notifying the user with an appropriate message.
|
||||
|
||||
- **How can I guarantee that the salt value is unique?**
|
||||
|
||||
In principle, the value of the salt should be different whenever the same password is used more than once, for the reasons described [above](https://www.winzip.com/aes_info.htm#salt), but this is difficult to guarantee.
|
||||
|
||||
In practice, the number of bytes in the salt (as specified by AE-1 and AE-2) is such that using a pseudo-random value will ensure that the probability of duplicated salt values is very low and can be safely ignored.
|
||||
|
||||
There is one exception to this: With the 8-byte salt values used with WinZip's 128-bit encryption it is likely that, if approximately 4 billion files are encrypted with the same password, two of the files will have the same salt, so it is advisable to stay well below this limit. Because of this, when using the same password to encrypt very large numbers of files in WinZip's AES encryption format (that is, files totalling in the millions, for example 2000 Zip files, each containing 1000 encrypted files), we recommend the use of 192-bit or 256-bit AES keys, with their 12- and 16-byte salt values, rather than 128-bit AES keys, with their 8-byte salt values.
|
||||
|
||||
Although salt values do not need to be truly random, it is important that they be generated in a way that the probability of duplicated salt values is not significantly higher than that which would be expected if truly random values were being used.
|
||||
|
||||
One technique for generating salt values is presented in the [coding tips](https://www.winzip.com/aes_tips.html#prng) page.
|
||||
|
||||
- **Why is there an authentication code?**
|
||||
|
||||
The purpose of the authentication code is to insure that, once a file's data has been compressed and encrypted, any accidental corruption of the encrypted data, and any deliberate attempts to modify the encrypted data by an attacker who does not know the password, can be detected.
|
||||
|
||||
The current consensus in the cryptographic community is that associating a message authentication code (or MAC) with encrypted data has strong security value because it makes a number of attacks more difficult to engineer. For AES CTR mode encryption in particular, a MAC is especially important because a number of trivial attacks are possible in its absence. The MAC used with WinZip's AES encryption is based on[HMAC-SHA1-80](http://www.faqs.org/rfcs/rfc2104.html), a mature and widely respected authentication algorithm.
|
||||
|
||||
The MAC is calculated after the file data has been compressed and encrypted. This order of calculation is referred to as Encrypt-then-MAC, and is preferred by many cryptographers to the alternative order of MAC-then-Encrypt because Encrypt-then-MAC is immune to some known attacks on MAC-then-Encrypt.
|
||||
|
||||
- **What is the role of the CRC in WinZip 11?**
|
||||
|
||||
Within the Zip format, the primary use of the CRC value is to detect accidental corruption of data that has been stored in the Zip file. With files encrypted according to the Zip 2.0 encryption specification, it also functions to some extent as a method of detecting deliberate attempts to modify the encrypted data, but not one that can be considered cryptographically strong. The CRC is not needed for these purposes with the WinZip AES encryption specification, where the HMAC-SHA1-based authentication code instead serves these roles.
|
||||
|
||||
The CRC has a drawback in that for very small files, such as files with four or fewer bytes, the CRC can be used, independent of the encryption algorithm, to determine the unencrypted contents of the file. And, in general, it is preferable to store as little information as possible about the encrypted file in the unencrypted Zip headers.
|
||||
|
||||
The CRC does serve one purpose that the authentication code does not. The CRC is computed based on the original uncompressed, unencrypted contents of the file, and it is checked after the file has been decrypted and decompressed. In contrast, the authentication code used with WinZip AES encryption is computed after compression/encryption and it is checked before decryption/decompression. In the very rare event of a hardware or software error that corrupts data during compression and encryption, or during decryption and decompression, the CRC will catch the error, but the authentication code will not.
|
||||
|
||||
WinZip 9.0 and WinZip 10.0 used AE-2 for all files that they created, and did not store the CRC. As of WinZip 11, WinZip instead uses AE-1 for most files, storing the CRC as an additional integrity check against hardware or software errors occurring during the actual compression/encryption or decryption/decompression processes. WinZip 11 will continue to use AE-2, with no CRC, for very small files of less than 20 bytes. It will also use AE-2 for files compressed in BZIP2 format, because this format has internal integrity checks equivalent to a CRC check built in.
|
||||
|
||||
Note that the AES-encrypted files created by WinZip 11 are fully compatible with January 2004's version 1.0.2 of the WinZip AES encryption specification, in which both the AE-1 and AE-2 variants of the file format were already defined.
|
||||
|
||||
|
||||
**VII. Change history**
|
||||
|
||||
**Changes made in document version 1.04, January, 2009:** Minor clarification regarding the algorithm used to generate the authentication code.
|
||||
|
||||
**Changes made in document version 1.03, November, 2006:** Minor editorial and clarifying changes have been made throughout the document. The following substantive technical changes have been made:
|
||||
|
||||
1. WinZip 11 Usage of AE-1 and AE-2
|
||||
|
||||
WinZip's AES encryption specification defines two formats, known as AE-1 and AE-2, which differ in whether the CRC of the encrypted file is stored in the Zip headers. While the file formats themselves remain unchanged, WinZip's usage of them is changing. Beginning with [WinZip 11](https://www.winzip.com/aes_info.htm#winzip11), WinZip uses the AE-1 format, which includes the CRC of the encrypted file, for many encrypted files, in order to provide an additional integrity check against hardware or software errors occurring during the compression/encryption or decryption/decompression processes. Note that AES-encrypted files created by WinZip 11 are completely compatible with the previous version of the WinZip encryption specification, January 2004's version 1.0.2.
|
||||
|
||||
2. The discussion of [salt values](https://www.winzip.com/aes_info.htm#salt) mentions a limitation that applies to the uniqueness of salt values when very large numbers of files are encrypted with 128-bit encryption.
|
||||
3. Older versions of this specification suggested that other vendors might want to use their own vendor IDs to create their own unique encryption formats. We no longer suggest that vendor-specific alternative encryption methods be created in this way.
|
||||
|
||||
**Changes made in document version 1.02, January, 2004:** The introductory text at the start of the document has been rewritten, and minor editorial and clarifying changes have been made throughout the document. Two substantive technical changes have been made:
|
||||
|
||||
1. AE-2 Specification
|
||||
|
||||
Standard Zip files store the CRC of each file's unencrypted data. This value is used to help detect damage or other alterations to Zip files. However, storing the CRC value has a drawback in that, for a very small file, such as a file of four or fewer bytes, the CRC value can be used, independent of the encryption algorithm, to help determine the unencrypted contents of the file.
|
||||
|
||||
Because of this, files encrypted with the new AE-2 method store a 0 in the CRC field of the Zip header, and use the [authentication code](https://www.winzip.com/aes_info.htm#authentication-code) instead of the CRC value to verify that encrypted data within the Zip file has not been corrupted.
|
||||
|
||||
The only differences between the AE-1 and AE-2 methods are the storage in AE-2 of 0 instead of the CRC in the Zip file header,and the use in the AES extra data field of 0x0002 for AE-2 instead of 0x0001 for AE-1 as the vendor version.
|
||||
|
||||
Zip utilities that support the AE-2 format are required to be able to read files that were created in the AE-1 format, and during decryption/extraction of files in AE-1 format should verify that the file's CRC matches the value stored in the CRC field.
|
||||
|
||||
2. Key Generation and HMAC-SHA1
|
||||
|
||||
The description of the [key generation](https://www.winzip.com/aes_info.htm#key-generation) mechanism has been updated to point out a limitation arising from its use of HMAC-SHA1 as the pseudo-random function: When used in connection with 192- or 256-bit AES encryption, the fact that HMAC-SHA1 produces a 160-bit result means that, regardless of the password that you specify, the search space for the encryption key is unlikely to reach the theoretical 192- or 256-bit maximum, and cannot be guaranteed to exceed 160 bits. This is discussed in section B.1.1 of the [RFC2898 specification](http://www.faqs.org/rfcs/rfc2898.html).
|
||||
|
||||
Document version: 1.04
|
||||
Last modified: January 30, 2009
|
||||
|
||||
Copyright© 2003-2018 Corel Corporation.
|
||||
All Rights Reserved
|
||||
@@ -1,687 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
The redistribution and use of this software (with or without changes)
|
||||
is allowed without the payment of fees or royalties provided that:
|
||||
|
||||
source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation.
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its operation, including, but not limited to, correctness
|
||||
and fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 09/09/2014
|
||||
*/
|
||||
|
||||
#include "aes_ni.h"
|
||||
|
||||
#if defined( USE_INTEL_AES_IF_PRESENT )
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#include <intrin.h>
|
||||
#pragma intrinsic(__cpuid)
|
||||
#define INLINE __inline
|
||||
|
||||
INLINE int has_aes_ni(void)
|
||||
{
|
||||
static int test = -1;
|
||||
if(test < 0)
|
||||
{
|
||||
int cpu_info[4];
|
||||
__cpuid(cpu_info, 1);
|
||||
test = cpu_info[2] & 0x02000000;
|
||||
}
|
||||
return test;
|
||||
}
|
||||
|
||||
#elif defined( __GNUC__ )
|
||||
|
||||
#include <cpuid.h>
|
||||
|
||||
#if !defined(__clang__)
|
||||
#pragma GCC target ("ssse3")
|
||||
#pragma GCC target ("sse4.1")
|
||||
#pragma GCC target ("aes")
|
||||
#endif
|
||||
|
||||
#include <x86intrin.h>
|
||||
#define INLINE static __inline
|
||||
|
||||
INLINE int has_aes_ni()
|
||||
{
|
||||
static int test = -1;
|
||||
if(test < 0)
|
||||
{
|
||||
unsigned int a, b, c, d;
|
||||
if(!__get_cpuid(1, &a, &b, &c, &d))
|
||||
test = 0;
|
||||
else
|
||||
test = (c & 0x2000000);
|
||||
}
|
||||
return test;
|
||||
}
|
||||
|
||||
#else
|
||||
#error AES New Instructions require Microsoft, Intel, GNU C, or CLANG
|
||||
#endif
|
||||
|
||||
INLINE __m128i aes_128_assist(__m128i t1, __m128i t2)
|
||||
{
|
||||
__m128i t3;
|
||||
t2 = _mm_shuffle_epi32(t2, 0xff);
|
||||
t3 = _mm_slli_si128(t1, 0x4);
|
||||
t1 = _mm_xor_si128(t1, t3);
|
||||
t3 = _mm_slli_si128(t3, 0x4);
|
||||
t1 = _mm_xor_si128(t1, t3);
|
||||
t3 = _mm_slli_si128(t3, 0x4);
|
||||
t1 = _mm_xor_si128(t1, t3);
|
||||
t1 = _mm_xor_si128(t1, t2);
|
||||
return t1;
|
||||
}
|
||||
|
||||
AES_RETURN aes_ni(encrypt_key128)(const unsigned char *key, aes_encrypt_ctx cx[1])
|
||||
{
|
||||
__m128i t1, t2;
|
||||
__m128i *ks = (__m128i*)cx->ks;
|
||||
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_xi(encrypt_key128)(key, cx);
|
||||
}
|
||||
|
||||
t1 = _mm_loadu_si128((__m128i*)key);
|
||||
|
||||
ks[0] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x1);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[1] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x2);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[2] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x4);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[3] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x8);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[4] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x10);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[5] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x20);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[6] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x40);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[7] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x80);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[8] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x1b);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[9] = t1;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t1, 0x36);
|
||||
t1 = aes_128_assist(t1, t2);
|
||||
ks[10] = t1;
|
||||
|
||||
cx->inf.l = 0;
|
||||
cx->inf.b[0] = 10 * 16;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
INLINE void aes_192_assist(__m128i* t1, __m128i * t2, __m128i * t3)
|
||||
{
|
||||
__m128i t4;
|
||||
*t2 = _mm_shuffle_epi32(*t2, 0x55);
|
||||
t4 = _mm_slli_si128(*t1, 0x4);
|
||||
*t1 = _mm_xor_si128(*t1, t4);
|
||||
t4 = _mm_slli_si128(t4, 0x4);
|
||||
*t1 = _mm_xor_si128(*t1, t4);
|
||||
t4 = _mm_slli_si128(t4, 0x4);
|
||||
*t1 = _mm_xor_si128(*t1, t4);
|
||||
*t1 = _mm_xor_si128(*t1, *t2);
|
||||
*t2 = _mm_shuffle_epi32(*t1, 0xff);
|
||||
t4 = _mm_slli_si128(*t3, 0x4);
|
||||
*t3 = _mm_xor_si128(*t3, t4);
|
||||
*t3 = _mm_xor_si128(*t3, *t2);
|
||||
}
|
||||
|
||||
AES_RETURN aes_ni(encrypt_key192)(const unsigned char *key, aes_encrypt_ctx cx[1])
|
||||
{
|
||||
__m128i t1, t2, t3;
|
||||
__m128i *ks = (__m128i*)cx->ks;
|
||||
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_xi(encrypt_key192)(key, cx);
|
||||
}
|
||||
|
||||
t1 = _mm_loadu_si128((__m128i*)key);
|
||||
t3 = _mm_loadu_si128((__m128i*)(key + 16));
|
||||
|
||||
ks[0] = t1;
|
||||
ks[1] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x1);
|
||||
aes_192_assist(&t1, &t2, &t3);
|
||||
|
||||
ks[1] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(ks[1]), _mm_castsi128_pd(t1), 0));
|
||||
ks[2] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(t1), _mm_castsi128_pd(t3), 1));
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x2);
|
||||
aes_192_assist(&t1, &t2, &t3);
|
||||
ks[3] = t1;
|
||||
ks[4] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x4);
|
||||
aes_192_assist(&t1, &t2, &t3);
|
||||
ks[4] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(ks[4]), _mm_castsi128_pd(t1), 0));
|
||||
ks[5] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(t1), _mm_castsi128_pd(t3), 1));
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x8);
|
||||
aes_192_assist(&t1, &t2, &t3);
|
||||
ks[6] = t1;
|
||||
ks[7] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x10);
|
||||
aes_192_assist(&t1, &t2, &t3);
|
||||
ks[7] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(ks[7]), _mm_castsi128_pd(t1), 0));
|
||||
ks[8] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(t1), _mm_castsi128_pd(t3), 1));
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x20);
|
||||
aes_192_assist(&t1, &t2, &t3);
|
||||
ks[9] = t1;
|
||||
ks[10] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x40);
|
||||
aes_192_assist(&t1, &t2, &t3);
|
||||
ks[10] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(ks[10]), _mm_castsi128_pd(t1), 0));
|
||||
ks[11] = _mm_castpd_si128(_mm_shuffle_pd(_mm_castsi128_pd(t1), _mm_castsi128_pd(t3), 1));
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x80);
|
||||
aes_192_assist(&t1, &t2, &t3);
|
||||
ks[12] = t1;
|
||||
|
||||
cx->inf.l = 0;
|
||||
cx->inf.b[0] = 12 * 16;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
INLINE void aes_256_assist1(__m128i* t1, __m128i * t2)
|
||||
{
|
||||
__m128i t4;
|
||||
*t2 = _mm_shuffle_epi32(*t2, 0xff);
|
||||
t4 = _mm_slli_si128(*t1, 0x4);
|
||||
*t1 = _mm_xor_si128(*t1, t4);
|
||||
t4 = _mm_slli_si128(t4, 0x4);
|
||||
*t1 = _mm_xor_si128(*t1, t4);
|
||||
t4 = _mm_slli_si128(t4, 0x4);
|
||||
*t1 = _mm_xor_si128(*t1, t4);
|
||||
*t1 = _mm_xor_si128(*t1, *t2);
|
||||
}
|
||||
|
||||
INLINE void aes_256_assist2(__m128i* t1, __m128i * t3)
|
||||
{
|
||||
__m128i t2, t4;
|
||||
t4 = _mm_aeskeygenassist_si128(*t1, 0x0);
|
||||
t2 = _mm_shuffle_epi32(t4, 0xaa);
|
||||
t4 = _mm_slli_si128(*t3, 0x4);
|
||||
*t3 = _mm_xor_si128(*t3, t4);
|
||||
t4 = _mm_slli_si128(t4, 0x4);
|
||||
*t3 = _mm_xor_si128(*t3, t4);
|
||||
t4 = _mm_slli_si128(t4, 0x4);
|
||||
*t3 = _mm_xor_si128(*t3, t4);
|
||||
*t3 = _mm_xor_si128(*t3, t2);
|
||||
}
|
||||
|
||||
AES_RETURN aes_ni(encrypt_key256)(const unsigned char *key, aes_encrypt_ctx cx[1])
|
||||
{
|
||||
__m128i t1, t2, t3;
|
||||
__m128i *ks = (__m128i*)cx->ks;
|
||||
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_xi(encrypt_key256)(key, cx);
|
||||
}
|
||||
|
||||
t1 = _mm_loadu_si128((__m128i*)key);
|
||||
t3 = _mm_loadu_si128((__m128i*)(key + 16));
|
||||
|
||||
ks[0] = t1;
|
||||
ks[1] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x01);
|
||||
aes_256_assist1(&t1, &t2);
|
||||
ks[2] = t1;
|
||||
aes_256_assist2(&t1, &t3);
|
||||
ks[3] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x02);
|
||||
aes_256_assist1(&t1, &t2);
|
||||
ks[4] = t1;
|
||||
aes_256_assist2(&t1, &t3);
|
||||
ks[5] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x04);
|
||||
aes_256_assist1(&t1, &t2);
|
||||
ks[6] = t1;
|
||||
aes_256_assist2(&t1, &t3);
|
||||
ks[7] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x08);
|
||||
aes_256_assist1(&t1, &t2);
|
||||
ks[8] = t1;
|
||||
aes_256_assist2(&t1, &t3);
|
||||
ks[9] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x10);
|
||||
aes_256_assist1(&t1, &t2);
|
||||
ks[10] = t1;
|
||||
aes_256_assist2(&t1, &t3);
|
||||
ks[11] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x20);
|
||||
aes_256_assist1(&t1, &t2);
|
||||
ks[12] = t1;
|
||||
aes_256_assist2(&t1, &t3);
|
||||
ks[13] = t3;
|
||||
|
||||
t2 = _mm_aeskeygenassist_si128(t3, 0x40);
|
||||
aes_256_assist1(&t1, &t2);
|
||||
ks[14] = t1;
|
||||
|
||||
cx->inf.l = 0;
|
||||
cx->inf.b[0] = 14 * 16;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
INLINE void enc_to_dec(aes_decrypt_ctx cx[1])
|
||||
{
|
||||
__m128i *ks = (__m128i*)cx->ks;
|
||||
int j;
|
||||
|
||||
for( j = 1 ; j < (cx->inf.b[0] >> 4) ; ++j )
|
||||
ks[j] = _mm_aesimc_si128(ks[j]);
|
||||
}
|
||||
|
||||
AES_RETURN aes_ni(decrypt_key128)(const unsigned char *key, aes_decrypt_ctx cx[1])
|
||||
{
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_xi(decrypt_key128)(key, cx);
|
||||
}
|
||||
|
||||
if(aes_ni(encrypt_key128)(key, (aes_encrypt_ctx*)cx) == EXIT_SUCCESS)
|
||||
{
|
||||
enc_to_dec(cx);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else
|
||||
return EXIT_FAILURE;
|
||||
|
||||
}
|
||||
|
||||
AES_RETURN aes_ni(decrypt_key192)(const unsigned char *key, aes_decrypt_ctx cx[1])
|
||||
{
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_xi(decrypt_key192)(key, cx);
|
||||
}
|
||||
|
||||
if(aes_ni(encrypt_key192)(key, (aes_encrypt_ctx*)cx) == EXIT_SUCCESS)
|
||||
{
|
||||
enc_to_dec(cx);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
AES_RETURN aes_ni(decrypt_key256)(const unsigned char *key, aes_decrypt_ctx cx[1])
|
||||
{
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_xi(decrypt_key256)(key, cx);
|
||||
}
|
||||
|
||||
if(aes_ni(encrypt_key256)(key, (aes_encrypt_ctx*)cx) == EXIT_SUCCESS)
|
||||
{
|
||||
enc_to_dec(cx);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
AES_RETURN aes_ni(encrypt)(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1])
|
||||
{
|
||||
__m128i *key = (__m128i*)cx->ks, t;
|
||||
|
||||
if(cx->inf.b[0] != 10 * 16 && cx->inf.b[0] != 12 * 16 && cx->inf.b[0] != 14 * 16)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_xi(encrypt)(in, out, cx);
|
||||
}
|
||||
|
||||
t = _mm_xor_si128(_mm_loadu_si128((__m128i*)in), *(__m128i*)key);
|
||||
|
||||
switch(cx->inf.b[0])
|
||||
{
|
||||
case 14 * 16:
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
case 12 * 16:
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
case 10 * 16:
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenc_si128(t, *(__m128i*)++key);
|
||||
t = _mm_aesenclast_si128(t, *(__m128i*)++key);
|
||||
}
|
||||
|
||||
_mm_storeu_si128(&((__m128i*)out)[0], t);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
AES_RETURN aes_ni(decrypt)(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1])
|
||||
{
|
||||
__m128i *key = (__m128i*)cx->ks + (cx->inf.b[0] >> 4), t;
|
||||
|
||||
if(cx->inf.b[0] != 10 * 16 && cx->inf.b[0] != 12 * 16 && cx->inf.b[0] != 14 * 16)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_xi(decrypt)(in, out, cx);
|
||||
}
|
||||
|
||||
t = _mm_xor_si128(_mm_loadu_si128((__m128i*)in), *(__m128i*)key);
|
||||
|
||||
switch(cx->inf.b[0])
|
||||
{
|
||||
case 14 * 16:
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
case 12 * 16:
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
case 10 * 16:
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdec_si128(t, *(__m128i*)--key);
|
||||
t = _mm_aesdeclast_si128(t, *(__m128i*)--key);
|
||||
}
|
||||
|
||||
_mm_storeu_si128((__m128i*)out, t);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef ADD_AESNI_MODE_CALLS
|
||||
#ifdef USE_AES_CONTEXT
|
||||
|
||||
AES_RETURN aes_CBC_encrypt(const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned char ivec[16],
|
||||
unsigned long length,
|
||||
const aes_encrypt_ctx cx[1])
|
||||
{
|
||||
__m128i feedback, data, *key = (__m128i*)cx->ks;
|
||||
int number_of_rounds = cx->inf.b[0] >> 4, j;
|
||||
unsigned long i;
|
||||
|
||||
if(number_of_rounds != 10 && number_of_rounds != 12 && number_of_rounds != 14)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_cbc_encrypt(in, out, length, ivec, cx);
|
||||
}
|
||||
|
||||
if(length % 16)
|
||||
length = length / 16 + 1;
|
||||
else length /= 16;
|
||||
feedback = _mm_loadu_si128((__m128i*)ivec);
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
data = _mm_loadu_si128(&((__m128i*)in)[i]);
|
||||
feedback = _mm_xor_si128(data, feedback);
|
||||
feedback = _mm_xor_si128(feedback, ((__m128i*)key)[0]);
|
||||
for(j = 1; j <number_of_rounds; j++)
|
||||
feedback = _mm_aesenc_si128(feedback, ((__m128i*)key)[j]);
|
||||
feedback = _mm_aesenclast_si128(feedback, ((__m128i*)key)[j]);
|
||||
_mm_storeu_si128(&((__m128i*)out)[i], feedback);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
AES_RETURN aes_CBC_decrypt(const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned char ivec[16],
|
||||
unsigned long length,
|
||||
const aes_decrypt_ctx cx[1])
|
||||
{
|
||||
__m128i data, feedback, last_in, *key = (__m128i*)cx->ks;
|
||||
int number_of_rounds = cx->inf.b[0] >> 4, j;
|
||||
unsigned long i;
|
||||
|
||||
if(number_of_rounds != 10 && number_of_rounds != 12 && number_of_rounds != 14)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
return aes_cbc_decrypt(in, out, length, ivec, cx);
|
||||
}
|
||||
|
||||
if(length % 16)
|
||||
length = length / 16 + 1;
|
||||
else length /= 16;
|
||||
feedback = _mm_loadu_si128((__m128i*)ivec);
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
last_in = _mm_loadu_si128(&((__m128i*)in)[i]);
|
||||
data = _mm_xor_si128(last_in, ((__m128i*)key)[number_of_rounds]);
|
||||
for(j = number_of_rounds - 1; j > 0; j--)
|
||||
{
|
||||
data = _mm_aesdec_si128(data, ((__m128i*)key)[j]);
|
||||
}
|
||||
data = _mm_aesdeclast_si128(data, ((__m128i*)key)[0]);
|
||||
data = _mm_xor_si128(data, feedback);
|
||||
_mm_storeu_si128(&((__m128i*)out)[i], data);
|
||||
feedback = last_in;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static void ctr_inc(unsigned char *ctr_blk)
|
||||
{
|
||||
uint32_t c;
|
||||
|
||||
c = *(uint32_t*)(ctr_blk + 8);
|
||||
c++;
|
||||
*(uint32_t*)(ctr_blk + 8) = c;
|
||||
|
||||
if(!c)
|
||||
*(uint32_t*)(ctr_blk + 12) = *(uint32_t*)(ctr_blk + 12) + 1;
|
||||
}
|
||||
|
||||
AES_RETURN AES_CTR_encrypt(const unsigned char *in,
|
||||
unsigned char *out,
|
||||
const unsigned char ivec[8],
|
||||
const unsigned char nonce[4],
|
||||
unsigned long length,
|
||||
const aes_encrypt_ctx cx[1])
|
||||
{
|
||||
__m128i ctr_block = { 0 }, *key = (__m128i*)cx->ks, tmp, ONE, BSWAP_EPI64;
|
||||
int number_of_rounds = cx->inf.b[0] >> 4, j;
|
||||
unsigned long i;
|
||||
|
||||
if(number_of_rounds != 10 && number_of_rounds != 12 && number_of_rounds != 14)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
if(!has_aes_ni())
|
||||
{
|
||||
unsigned char ctr_blk[16];
|
||||
*(uint64_t*)ctr_blk = *(uint64_t*)ivec;
|
||||
*(uint32_t*)(ctr_blk + 8) = *(uint32_t*)nonce;
|
||||
return aes_ctr_crypt(in, out, length, (unsigned char*)ctr_blk, ctr_inc, cx);
|
||||
}
|
||||
|
||||
if(length % 16)
|
||||
length = length / 16 + 1;
|
||||
else length /= 16;
|
||||
ONE = _mm_set_epi32(0, 1, 0, 0);
|
||||
BSWAP_EPI64 = _mm_setr_epi8(7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8);
|
||||
#ifdef _MSC_VER
|
||||
ctr_block = _mm_insert_epi64(ctr_block, *(long long*)ivec, 1);
|
||||
#else
|
||||
ctr_block = _mm_set_epi64(*(__m64*)ivec, *(__m64*)&ctr_block);
|
||||
#endif
|
||||
ctr_block = _mm_insert_epi32(ctr_block, *(long*)nonce, 1);
|
||||
ctr_block = _mm_srli_si128(ctr_block, 4);
|
||||
ctr_block = _mm_shuffle_epi8(ctr_block, BSWAP_EPI64);
|
||||
ctr_block = _mm_add_epi64(ctr_block, ONE);
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
tmp = _mm_shuffle_epi8(ctr_block, BSWAP_EPI64);
|
||||
ctr_block = _mm_add_epi64(ctr_block, ONE);
|
||||
tmp = _mm_xor_si128(tmp, ((__m128i*)key)[0]);
|
||||
for(j = 1; j <number_of_rounds; j++)
|
||||
{
|
||||
tmp = _mm_aesenc_si128(tmp, ((__m128i*)key)[j]);
|
||||
};
|
||||
tmp = _mm_aesenclast_si128(tmp, ((__m128i*)key)[j]);
|
||||
tmp = _mm_xor_si128(tmp, _mm_loadu_si128(&((__m128i*)in)[i]));
|
||||
_mm_storeu_si128(&((__m128i*)out)[i], tmp);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void aes_CBC_encrypt(const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned char ivec[16],
|
||||
unsigned long length,
|
||||
unsigned char *key,
|
||||
int number_of_rounds)
|
||||
{
|
||||
__m128i feedback, data;
|
||||
unsigned long i;
|
||||
int j;
|
||||
if(length % 16)
|
||||
length = length / 16 + 1;
|
||||
else length /= 16;
|
||||
feedback = _mm_loadu_si128((__m128i*)ivec);
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
data = _mm_loadu_si128(&((__m128i*)in)[i]);
|
||||
feedback = _mm_xor_si128(data, feedback);
|
||||
feedback = _mm_xor_si128(feedback, ((__m128i*)key)[0]);
|
||||
for(j = 1; j <number_of_rounds; j++)
|
||||
feedback = _mm_aesenc_si128(feedback, ((__m128i*)key)[j]);
|
||||
feedback = _mm_aesenclast_si128(feedback, ((__m128i*)key)[j]);
|
||||
_mm_storeu_si128(&((__m128i*)out)[i], feedback);
|
||||
}
|
||||
}
|
||||
|
||||
void aes_CBC_decrypt(const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned char ivec[16],
|
||||
unsigned long length,
|
||||
unsigned char *key,
|
||||
int number_of_rounds)
|
||||
{
|
||||
__m128i data, feedback, last_in;
|
||||
unsigned long i;
|
||||
int j;
|
||||
if(length % 16)
|
||||
length = length / 16 + 1;
|
||||
else length /= 16;
|
||||
feedback = _mm_loadu_si128((__m128i*)ivec);
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
last_in = _mm_loadu_si128(&((__m128i*)in)[i]);
|
||||
data = _mm_xor_si128(last_in, ((__m128i*)key)[0]);
|
||||
for(j = 1; j <number_of_rounds; j++)
|
||||
{
|
||||
data = _mm_aesdec_si128(data, ((__m128i*)key)[j]);
|
||||
}
|
||||
data = _mm_aesdeclast_si128(data, ((__m128i*)key)[j]);
|
||||
data = _mm_xor_si128(data, feedback);
|
||||
_mm_storeu_si128(&((__m128i*)out)[i], data);
|
||||
feedback = last_in;
|
||||
}
|
||||
}
|
||||
|
||||
void AES_CTR_encrypt(const unsigned char *in,
|
||||
unsigned char *out,
|
||||
const unsigned char ivec[8],
|
||||
const unsigned char nonce[4],
|
||||
unsigned long length,
|
||||
const unsigned char *key,
|
||||
int number_of_rounds)
|
||||
{
|
||||
__m128i ctr_block = { 0 }, tmp, ONE, BSWAP_EPI64;
|
||||
unsigned long i;
|
||||
int j;
|
||||
if(length % 16)
|
||||
length = length / 16 + 1;
|
||||
else length /= 16;
|
||||
ONE = _mm_set_epi32(0, 1, 0, 0);
|
||||
BSWAP_EPI64 = _mm_setr_epi8(7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8);
|
||||
#ifdef _MSC_VER
|
||||
ctr_block = _mm_insert_epi64(ctr_block, *(long long*)ivec, 1);
|
||||
#else
|
||||
ctr_block = _mm_set_epi64(*(__m64*)ivec, *(__m64*)&ctr_block);
|
||||
#endif
|
||||
ctr_block = _mm_insert_epi32(ctr_block, *(long*)nonce, 1);
|
||||
ctr_block = _mm_srli_si128(ctr_block, 4);
|
||||
ctr_block = _mm_shuffle_epi8(ctr_block, BSWAP_EPI64);
|
||||
ctr_block = _mm_add_epi64(ctr_block, ONE);
|
||||
for(i = 0; i < length; i++)
|
||||
{
|
||||
tmp = _mm_shuffle_epi8(ctr_block, BSWAP_EPI64);
|
||||
ctr_block = _mm_add_epi64(ctr_block, ONE);
|
||||
tmp = _mm_xor_si128(tmp, ((__m128i*)key)[0]);
|
||||
for(j = 1; j <number_of_rounds; j++)
|
||||
{
|
||||
tmp = _mm_aesenc_si128(tmp, ((__m128i*)key)[j]);
|
||||
};
|
||||
tmp = _mm_aesenclast_si128(tmp, ((__m128i*)key)[j]);
|
||||
tmp = _mm_xor_si128(tmp, _mm_loadu_si128(&((__m128i*)in)[i]));
|
||||
_mm_storeu_si128(&((__m128i*)out)[i], tmp);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved.
|
||||
|
||||
The redistribution and use of this software (with or without changes)
|
||||
is allowed without the payment of fees or royalties provided that:
|
||||
|
||||
source code distributions include the above copyright notice, this
|
||||
list of conditions and the following disclaimer;
|
||||
|
||||
binary distributions include the above copyright notice, this list
|
||||
of conditions and the following disclaimer in their documentation.
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its operation, including, but not limited to, correctness
|
||||
and fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 13/11/2013
|
||||
*/
|
||||
|
||||
#ifndef AES_NI_H
|
||||
#define AES_NI_H
|
||||
|
||||
#define USE_AES_CONTEXT
|
||||
|
||||
#include "aesopt.h"
|
||||
|
||||
#if defined( USE_INTEL_AES_IF_PRESENT )
|
||||
|
||||
/* map names in C code to make them internal ('name' -> 'aes_name_i') */
|
||||
#define aes_xi(x) aes_ ## x ## _i
|
||||
|
||||
/* map names here to provide the external API ('name' -> 'aes_name') */
|
||||
#define aes_ni(x) aes_ ## x
|
||||
|
||||
AES_RETURN aes_ni(encrypt_key128)(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
AES_RETURN aes_ni(encrypt_key192)(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
AES_RETURN aes_ni(encrypt_key256)(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_ni(decrypt_key128)(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
AES_RETURN aes_ni(decrypt_key192)(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
AES_RETURN aes_ni(decrypt_key256)(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_ni(encrypt)(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]);
|
||||
AES_RETURN aes_ni(decrypt)(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_xi(encrypt_key128)(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
AES_RETURN aes_xi(encrypt_key192)(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
AES_RETURN aes_xi(encrypt_key256)(const unsigned char *key, aes_encrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_xi(decrypt_key128)(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
AES_RETURN aes_xi(decrypt_key192)(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
AES_RETURN aes_xi(decrypt_key256)(const unsigned char *key, aes_decrypt_ctx cx[1]);
|
||||
|
||||
AES_RETURN aes_xi(encrypt)(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]);
|
||||
AES_RETURN aes_xi(decrypt)(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -188,7 +188,7 @@ Issue Date: 20/12/2007
|
||||
built
|
||||
*/
|
||||
|
||||
#if 1 && defined( INTEL_AES_POSSIBLE ) && !defined( USE_INTEL_AES_IF_PRESENT )
|
||||
#if 0 && defined( INTEL_AES_POSSIBLE ) && !defined( USE_INTEL_AES_IF_PRESENT )
|
||||
# define USE_INTEL_AES_IF_PRESENT
|
||||
#endif
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ a password and a salt value.
|
||||
|
||||
#include <string.h>
|
||||
#include "hmac.h"
|
||||
#include "pwd2key.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
|
||||
@@ -219,7 +219,11 @@
|
||||
*/
|
||||
#ifndef lzma_nothrow
|
||||
# if defined(__cplusplus)
|
||||
# define lzma_nothrow throw()
|
||||
# if __cplusplus >= 201103L
|
||||
# define lzma_nothrow noexcept
|
||||
# else
|
||||
# define lzma_nothrow throw()
|
||||
# endif
|
||||
# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
|
||||
# define lzma_nothrow __attribute__((__nothrow__))
|
||||
# else
|
||||
|
||||
@@ -644,11 +644,16 @@ extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm)
|
||||
* This function is supported only when *strm has been initialized with
|
||||
* a function that takes a memlimit argument.
|
||||
*
|
||||
* liblzma 5.2.3 and earlier has a bug where memlimit value of 0 causes
|
||||
* this function to do nothing (leaving the limit unchanged) and still
|
||||
* return LZMA_OK. Later versions treat 0 as if 1 had been specified (so
|
||||
* lzma_memlimit_get() will return 1 even if you specify 0 here).
|
||||
*
|
||||
* \return - LZMA_OK: New memory usage limit successfully set.
|
||||
* - LZMA_MEMLIMIT_ERROR: The new limit is too small.
|
||||
* The limit was not changed.
|
||||
* - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't
|
||||
* support memory usage limit or memlimit was zero.
|
||||
* support memory usage limit.
|
||||
*/
|
||||
extern LZMA_API(lzma_ret) lzma_memlimit_set(
|
||||
lzma_stream *strm, uint64_t memlimit) lzma_nothrow;
|
||||
|
||||
@@ -520,7 +520,10 @@ extern LZMA_API(lzma_ret) lzma_stream_buffer_encode(
|
||||
*
|
||||
* \param strm Pointer to properly prepared lzma_stream
|
||||
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
|
||||
* to effectively disable the limiter.
|
||||
* to effectively disable the limiter. liblzma
|
||||
* 5.2.3 and earlier don't allow 0 here and return
|
||||
* LZMA_PROG_ERROR; later versions treat 0 as if 1
|
||||
* had been specified.
|
||||
* \param flags Bitwise-or of zero or more of the decoder flags:
|
||||
* LZMA_TELL_NO_CHECK, LZMA_TELL_UNSUPPORTED_CHECK,
|
||||
* LZMA_TELL_ANY_CHECK, LZMA_CONCATENATED
|
||||
@@ -544,7 +547,10 @@ extern LZMA_API(lzma_ret) lzma_stream_decoder(
|
||||
*
|
||||
* \param strm Pointer to properly prepared lzma_stream
|
||||
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
|
||||
* to effectively disable the limiter.
|
||||
* to effectively disable the limiter. liblzma
|
||||
* 5.2.3 and earlier don't allow 0 here and return
|
||||
* LZMA_PROG_ERROR; later versions treat 0 as if 1
|
||||
* had been specified.
|
||||
* \param flags Bitwise-or of flags, or zero for no flags.
|
||||
*
|
||||
* \return - LZMA_OK: Initialization was successful.
|
||||
@@ -560,9 +566,16 @@ extern LZMA_API(lzma_ret) lzma_auto_decoder(
|
||||
/**
|
||||
* \brief Initialize .lzma decoder (legacy file format)
|
||||
*
|
||||
* \param strm Pointer to properly prepared lzma_stream
|
||||
* \param memlimit Memory usage limit as bytes. Use UINT64_MAX
|
||||
* to effectively disable the limiter. liblzma
|
||||
* 5.2.3 and earlier don't allow 0 here and return
|
||||
* LZMA_PROG_ERROR; later versions treat 0 as if 1
|
||||
* had been specified.
|
||||
*
|
||||
* Valid `action' arguments to lzma_code() are LZMA_RUN and LZMA_FINISH.
|
||||
* There is no need to use LZMA_FINISH, but allowing it may simplify
|
||||
* certain types of applications.
|
||||
* There is no need to use LZMA_FINISH, but it's allowed because it may
|
||||
* simplify certain types of applications.
|
||||
*
|
||||
* \return - LZMA_OK
|
||||
* - LZMA_MEM_ERROR
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
#define LZMA_VERSION_MAJOR 5
|
||||
#define LZMA_VERSION_MINOR 2
|
||||
#define LZMA_VERSION_PATCH 3
|
||||
#define LZMA_VERSION_PATCH 4
|
||||
#define LZMA_VERSION_STABILITY LZMA_VERSION_STABILITY_STABLE
|
||||
|
||||
#ifndef LZMA_VERSION_COMMIT
|
||||
|
||||
@@ -109,9 +109,9 @@ extern const uint64_t lzma_crc64_table[4][256];
|
||||
|
||||
/// \brief Initialize *check depending on type
|
||||
///
|
||||
/// \param check LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type
|
||||
/// is not supported by the current version or build of
|
||||
/// liblzma. LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
|
||||
/// \return LZMA_OK on success. LZMA_UNSUPPORTED_CHECK if the type is not
|
||||
/// supported by the current version or build of liblzma.
|
||||
/// LZMA_PROG_ERROR if type > LZMA_CHECK_ID_MAX.
|
||||
extern void lzma_check_init(lzma_check_state *check, lzma_check type);
|
||||
|
||||
/// Update the check state
|
||||
|
||||
@@ -184,9 +184,6 @@ lzma_alone_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||
{
|
||||
lzma_next_coder_init(&lzma_alone_decoder_init, next, allocator);
|
||||
|
||||
if (memlimit == 0)
|
||||
return LZMA_PROG_ERROR;
|
||||
|
||||
lzma_alone_coder *coder = next->coder;
|
||||
|
||||
if (coder == NULL) {
|
||||
@@ -208,7 +205,7 @@ lzma_alone_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||
coder->options.preset_dict = NULL;
|
||||
coder->options.preset_dict_size = 0;
|
||||
coder->uncompressed_size = 0;
|
||||
coder->memlimit = memlimit;
|
||||
coder->memlimit = my_max(1, memlimit);
|
||||
coder->memusage = LZMA_MEMUSAGE_BASE;
|
||||
|
||||
return LZMA_OK;
|
||||
|
||||
@@ -435,8 +435,10 @@ lzma_memlimit_set(lzma_stream *strm, uint64_t new_memlimit)
|
||||
|| strm->internal->next.memconfig == NULL)
|
||||
return LZMA_PROG_ERROR;
|
||||
|
||||
if (new_memlimit != 0 && new_memlimit < LZMA_MEMUSAGE_BASE)
|
||||
return LZMA_MEMLIMIT_ERROR;
|
||||
// Zero is a special value that cannot be used as an actual limit.
|
||||
// If 0 was specified, use 1 instead.
|
||||
if (new_memlimit == 0)
|
||||
new_memlimit = 1;
|
||||
|
||||
return strm->internal->next.memconfig(strm->internal->next.coder,
|
||||
&memusage, &old_memlimit, new_memlimit);
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
#include "common.h"
|
||||
|
||||
#ifdef HAVE_IMMINTRIN_H
|
||||
#if (defined(__GNUC__) && defined(__SSE2_MATH__)) || \
|
||||
(defined(__INTEL_COMPILER) && defined(__SSE2__)) || \
|
||||
(defined(_MSC_VER) && defined(_M_IX86_FP) && _M_IX86_FP >= 2)
|
||||
# include <immintrin.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/// Find out how many equal bytes the two buffers have.
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
#include "lzma_decoder.h"
|
||||
#include "range_decoder.h"
|
||||
|
||||
// The macros unroll loops with switch statements.
|
||||
// Silence warnings about missing fall-through comments.
|
||||
#if TUKLIB_GNUC_REQ(7, 0)
|
||||
# pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_SMALL
|
||||
|
||||
|
||||
@@ -0,0 +1,622 @@
|
||||
/* minizip.c
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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 <inttypes.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_buf.h"
|
||||
#include "mz_strm_split.h"
|
||||
#include "mz_zip.h"
|
||||
#include "mz_zip_rw.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void minizip_banner(void)
|
||||
{
|
||||
printf("Minizip %s - https://github.com/nmoinvaz/minizip\n", MZ_VERSION);
|
||||
printf("---------------------------------------------------\n");
|
||||
}
|
||||
|
||||
void minizip_help(void)
|
||||
{
|
||||
printf("Usage : minizip [-x -d dir|-l|-e] [-o] [-c] [-a] [-j] [-0 to -9] [-b|-m] [-k 512] [-p pwd] [-s] file.zip [files]\n\n" \
|
||||
" -x Extract files\n" \
|
||||
" -l List files\n" \
|
||||
" -d Destination directory\n" \
|
||||
" -o Overwrite existing files\n" \
|
||||
" -c File names use cp437 encoding\n" \
|
||||
" -a Append to existing zip file\n" \
|
||||
" -i Include full path of files\n" \
|
||||
" -0 Store only\n" \
|
||||
" -1 Compress faster\n" \
|
||||
" -9 Compress better\n" \
|
||||
" -k Disk size in KB\n" \
|
||||
" -p Encryption password\n");
|
||||
#ifdef HAVE_AES
|
||||
printf(" -s AES encryption\n");
|
||||
#endif
|
||||
#ifdef HAVE_BZIP2
|
||||
printf(" -b BZIP2 compression\n");
|
||||
#endif
|
||||
#ifdef HAVE_LZMA
|
||||
printf(" -m LZMA compression\n");
|
||||
#endif
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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;
|
||||
#ifdef HAVE_AES
|
||||
uint8_t aes;
|
||||
#endif
|
||||
uint8_t legacy_encoding;
|
||||
} minizip_opt;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_list(const char *path)
|
||||
{
|
||||
mz_zip_file *file_info = NULL;
|
||||
uint32_t ratio = 0;
|
||||
int16_t level = 0;
|
||||
int32_t err = MZ_OK;
|
||||
struct tm tmu_date;
|
||||
const char *string_method = NULL;
|
||||
char crypt = ' ';
|
||||
|
||||
void *reader = NULL;
|
||||
|
||||
|
||||
mz_zip_reader_create(&reader);
|
||||
err = mz_zip_reader_open_file(reader, path);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d opening zip file %s\n", err, path);
|
||||
mz_zip_reader_delete(&reader);
|
||||
return err;
|
||||
}
|
||||
|
||||
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);
|
||||
mz_zip_reader_delete(&reader);
|
||||
return err;
|
||||
}
|
||||
|
||||
printf(" Length Method Size Attribs Ratio Date Time CRC-32 Name\n");
|
||||
printf(" ------ ------ ---- ------- ----- ---- ---- ------ ----\n");
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
ratio = 0;
|
||||
if (file_info->uncompressed_size > 0)
|
||||
ratio = (uint32_t)((file_info->compressed_size * 100) / file_info->uncompressed_size);
|
||||
|
||||
// Display a '*' if the file is encrypted
|
||||
if (file_info->flag & MZ_ZIP_FLAG_ENCRYPTED)
|
||||
crypt = '*';
|
||||
|
||||
switch (file_info->compression_method)
|
||||
{
|
||||
case MZ_COMPRESS_METHOD_STORE:
|
||||
string_method = "Stored";
|
||||
break;
|
||||
case MZ_COMPRESS_METHOD_DEFLATE:
|
||||
level = (int16_t)((file_info->flag & 0x6) / 2);
|
||||
if (level == 0)
|
||||
string_method = "Defl:N";
|
||||
else if (level == 1)
|
||||
string_method = "Defl:X";
|
||||
else if ((level == 2) || (level == 3))
|
||||
string_method = "Defl:F"; // 2: fast , 3: extra fast
|
||||
else
|
||||
string_method = "Defl:?";
|
||||
break;
|
||||
case MZ_COMPRESS_METHOD_BZIP2:
|
||||
string_method = "BZip2";
|
||||
break;
|
||||
case MZ_COMPRESS_METHOD_LZMA:
|
||||
string_method = "LZMA";
|
||||
break;
|
||||
default:
|
||||
string_method = "Unknwn";
|
||||
}
|
||||
|
||||
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,
|
||||
(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,
|
||||
file_info->crc, file_info->filename);
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (err == MZ_OK);
|
||||
|
||||
mz_zip_reader_delete(&reader);
|
||||
|
||||
if (err == MZ_END_OF_LIST)
|
||||
return MZ_OK;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_add_entry_cb(void *handle, void *userdata, mz_zip_file *file_info)
|
||||
{
|
||||
printf("Adding %s\n", file_info->filename);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t minizip_add_progress_cb(void *handle, void *userdata, mz_zip_file *file_info, uint64_t position)
|
||||
{
|
||||
double progress = 0;
|
||||
uint8_t raw = 0;
|
||||
|
||||
mz_zip_writer_get_raw(handle, &raw);
|
||||
|
||||
if (raw && file_info->compressed_size > 0)
|
||||
progress = ((double)position / file_info->compressed_size) * 100;
|
||||
else if (!raw && file_info->uncompressed_size > 0)
|
||||
progress = ((double)position / file_info->uncompressed_size) * 100;
|
||||
|
||||
printf("%s - %lld / %lld (%.02f%%)\n", file_info->filename, position, file_info->uncompressed_size, progress);
|
||||
return MZ_OK;
|
||||
|
||||
}
|
||||
int32_t minizip_add_overwrite_cb(void *handle, void *userdata, const char *path)
|
||||
{
|
||||
minizip_opt *options = (minizip_opt *)userdata;
|
||||
|
||||
if (options->overwrite == 0)
|
||||
{
|
||||
// If ask the user what to do because append and overwrite args not set
|
||||
char rep = 0;
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ", path);
|
||||
if (scanf("%1s", answer) != 1)
|
||||
exit(EXIT_FAILURE);
|
||||
rep = answer[0];
|
||||
|
||||
if ((rep >= 'a') && (rep <= 'z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep != 'Y') && (rep != 'N') && (rep != 'A'));
|
||||
|
||||
if (rep == 'A')
|
||||
{
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
else if (rep == 'N')
|
||||
{
|
||||
return MZ_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t minizip_add(const char *path, const char *password, minizip_opt *options, int32_t arg_count, const char **args)
|
||||
{
|
||||
void *writer = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t err_close = MZ_OK;
|
||||
int32_t i = 0;
|
||||
const char *filename_in_zip = NULL;
|
||||
|
||||
|
||||
printf("Archive %s\n", path);
|
||||
|
||||
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_progress_cb(writer, options, minizip_add_progress_cb);
|
||||
|
||||
err = mz_zip_writer_open_file(writer, path, options->disk_size, options->append);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
for (i = 0; i < arg_count; i += 1)
|
||||
{
|
||||
filename_in_zip = args[i];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error %d 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);
|
||||
err = err_close;
|
||||
}
|
||||
|
||||
mz_zip_writer_delete(&writer);
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_extract_entry_cb(void *handle, void *userdata, mz_zip_file *file_info, const char *path)
|
||||
{
|
||||
printf("Extracting %s\n", file_info->filename);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t minizip_extract_progress_cb(void *handle, void *userdata, mz_zip_file *file_info, uint64_t position)
|
||||
{
|
||||
double progress = 0;
|
||||
uint8_t raw = 0;
|
||||
|
||||
mz_zip_reader_get_raw(handle, &raw);
|
||||
|
||||
if (raw && file_info->compressed_size > 0)
|
||||
progress = ((double)position / file_info->compressed_size) * 100;
|
||||
else if (!raw && file_info->uncompressed_size > 0)
|
||||
progress = ((double)position / file_info->uncompressed_size) * 100;
|
||||
|
||||
printf("%s - %lld / %lld (%.02f%%)\n", file_info->filename, position, file_info->uncompressed_size, progress);
|
||||
return MZ_OK;
|
||||
|
||||
}
|
||||
int32_t minizip_extract_overwrite_cb(void *handle, void *userdata, mz_zip_file *file_info, const char *path)
|
||||
{
|
||||
minizip_opt *options = (minizip_opt *)userdata;
|
||||
|
||||
if (options->overwrite == 0)
|
||||
{
|
||||
char rep = 0;
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ", path);
|
||||
if (scanf("%1s", answer) != 1)
|
||||
exit(EXIT_FAILURE);
|
||||
rep = answer[0];
|
||||
if ((rep >= 'a') && (rep <= 'z'))
|
||||
rep -= 0x20;
|
||||
} while ((rep != 'Y') && (rep != 'N') && (rep != 'A'));
|
||||
|
||||
if (rep == 'N')
|
||||
return MZ_EXIST_ERROR;
|
||||
if (rep == 'A')
|
||||
options->overwrite = 1;
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t minizip_extract(const char *path, const char *pattern, const char *destination, const char *password, minizip_opt *options)
|
||||
{
|
||||
void *reader = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t err_close = MZ_OK;
|
||||
|
||||
|
||||
printf("Archive %s\n", path);
|
||||
|
||||
mz_zip_reader_create(&reader);
|
||||
mz_zip_reader_set_pattern(reader, pattern, 1);
|
||||
mz_zip_reader_set_password(reader, password);
|
||||
mz_zip_reader_set_legacy_encoding(reader, options->legacy_encoding);
|
||||
mz_zip_reader_set_entry_cb(reader, options, minizip_extract_entry_cb);
|
||||
mz_zip_reader_set_progress_cb(reader, options, minizip_extract_progress_cb);
|
||||
mz_zip_reader_set_overwrite_cb(reader, options, minizip_extract_overwrite_cb);
|
||||
|
||||
err = mz_zip_reader_open_file(reader, path);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d opening zip file %s\n", err, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
err_close = mz_zip_reader_close(reader);
|
||||
if (err_close != MZ_OK)
|
||||
{
|
||||
printf("Error %d closing zip for reading\n", err_close);
|
||||
err = err_close;
|
||||
}
|
||||
|
||||
mz_zip_reader_delete(&reader);
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_erase(const char *src_path, const char *target_path, int32_t arg_count, const char **args)
|
||||
{
|
||||
mz_zip_file *file_info = NULL;
|
||||
const char *filename_in_zip = NULL;
|
||||
void *reader = NULL;
|
||||
void *writer = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t i = 0;
|
||||
|
||||
mz_zip_reader_create(&reader);
|
||||
mz_zip_writer_create(&writer);
|
||||
|
||||
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);
|
||||
mz_zip_reader_delete(&reader);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mz_zip_writer_open_file(writer, target_path, 0, 0);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d opening zip for writing %s\n", err, target_path);
|
||||
mz_zip_reader_delete(&reader);
|
||||
mz_zip_writer_delete(&writer);
|
||||
return err;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 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 (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d 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);
|
||||
}
|
||||
|
||||
mz_zip_reader_close(reader);
|
||||
mz_zip_reader_delete(&reader);
|
||||
|
||||
mz_zip_writer_close(writer);
|
||||
mz_zip_writer_delete(&writer);
|
||||
|
||||
if (err == MZ_END_OF_LIST)
|
||||
return MZ_OK;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(MZ_NO_MAIN)
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
minizip_opt options;
|
||||
void *handle = NULL;
|
||||
void *target_handle = NULL;
|
||||
void *file_stream = NULL;
|
||||
void *split_stream = NULL;
|
||||
void *buf_stream = NULL;
|
||||
void *tmp_file_stream = NULL;
|
||||
void *tmp_split_stream = NULL;
|
||||
void *tmp_buf_stream = NULL;
|
||||
int64_t disk_size = 0;
|
||||
int32_t path_arg = 0;
|
||||
int32_t err_close = 0;
|
||||
int32_t err = 0;
|
||||
int32_t i = 0;
|
||||
int16_t mode = 0;
|
||||
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;
|
||||
const char *filename_to_extract = NULL;
|
||||
|
||||
|
||||
minizip_banner();
|
||||
if (argc == 1)
|
||||
{
|
||||
minizip_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&options, 0, sizeof(options));
|
||||
|
||||
options.compress_method = MZ_COMPRESS_METHOD_DEFLATE;
|
||||
options.compress_level = MZ_COMPRESS_LEVEL_DEFAULT;
|
||||
|
||||
// Parse command line options
|
||||
for (i = 1; i < argc; i += 1)
|
||||
{
|
||||
if (argv[i][0] == '-')
|
||||
{
|
||||
char c = argv[i][1];
|
||||
if ((c == 'l') || (c == 'L'))
|
||||
do_list = 1;
|
||||
else if ((c == 'x') || (c == 'X'))
|
||||
do_extract = 1;
|
||||
else if ((c == 'e') || (c == 'E'))
|
||||
do_erase = 1;
|
||||
else if ((c == 'a') || (c == 'A'))
|
||||
options.append = 1;
|
||||
else if ((c == 'o') || (c == 'O'))
|
||||
options.overwrite = 1;
|
||||
else if ((c == 'i') || (c == 'I'))
|
||||
options.include_path = 1;
|
||||
else if ((c >= '0') && (c <= '9'))
|
||||
{
|
||||
options.compress_level = (c - '0');
|
||||
if (options.compress_level == 0)
|
||||
options.compress_method = MZ_COMPRESS_METHOD_STORE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
else if ((c == 'b') || (c == 'B'))
|
||||
options.compress_method = MZ_COMPRESS_METHOD_BZIP2;
|
||||
#endif
|
||||
#ifdef HAVE_LZMA
|
||||
else if ((c == 'm') || (c == 'M'))
|
||||
options.compress_method = MZ_COMPRESS_METHOD_LZMA;
|
||||
#endif
|
||||
#ifdef HAVE_AES
|
||||
else if ((c == 's') || (c == 'S'))
|
||||
options.aes = 1;
|
||||
#endif
|
||||
else if ((c == 'c') || (c == 'C'))
|
||||
options.legacy_encoding = 1;
|
||||
else if (((c == 'k') || (c == 'K')) && (i + 1 < argc))
|
||||
{
|
||||
options.disk_size = atoi(argv[i + 1]) * 1024;
|
||||
i += 1;
|
||||
}
|
||||
else if (((c == 'd') || (c == 'D')) && (i + 1 < argc))
|
||||
{
|
||||
destination = argv[i + 1];
|
||||
i += 1;
|
||||
}
|
||||
else if (((c == 'p') || (c == 'P')) && (i + 1 < argc))
|
||||
{
|
||||
password = argv[i + 1];
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
else if (path_arg == 0)
|
||||
path_arg = i;
|
||||
}
|
||||
|
||||
if (path_arg == 0)
|
||||
{
|
||||
minizip_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
path = argv[path_arg];
|
||||
|
||||
if (do_list)
|
||||
{
|
||||
err = minizip_list(path);
|
||||
}
|
||||
else if (do_extract)
|
||||
{
|
||||
if (argc > path_arg + 1)
|
||||
filename_to_extract = argv[path_arg + 1];
|
||||
|
||||
err = minizip_extract(path, filename_to_extract, destination, password, &options);
|
||||
}
|
||||
else if (do_erase)
|
||||
{
|
||||
strncpy(tmp_path, path, sizeof(tmp_path));
|
||||
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]);
|
||||
}
|
||||
else
|
||||
{
|
||||
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));
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
+2
-2
@@ -8,6 +8,6 @@ Name: minizip
|
||||
Description: Minizip zip file manipulation library
|
||||
Version: @VERSION@
|
||||
|
||||
Requires:
|
||||
Libs: -L${libdir} -L${sharedlibdir} -lz -lminizip
|
||||
Requires: zlib
|
||||
Libs: -L${libdir} -L${sharedlibdir} -lminizip
|
||||
Cflags: -I${includedir}
|
||||
|
||||
+42
-10
@@ -1,16 +1,16 @@
|
||||
/* mz.h -- Errors codes, zip flags and magic
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_H
|
||||
#define _MZ_H
|
||||
#ifndef MZ_H
|
||||
#define MZ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -19,13 +19,15 @@ extern "C" {
|
||||
/***************************************************************************/
|
||||
|
||||
// MZ_VERSION
|
||||
#define MZ_VERSION ("2.2.4")
|
||||
#define MZ_VERSION ("2.5.2")
|
||||
|
||||
// MZ_ERROR
|
||||
#define MZ_OK (0)
|
||||
#define MZ_STREAM_ERROR (-1)
|
||||
#define MZ_DATA_ERROR (-3)
|
||||
#define MZ_MEM_ERROR (-4)
|
||||
#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)
|
||||
#define MZ_PARAM_ERROR (-102)
|
||||
@@ -34,6 +36,8 @@ extern "C" {
|
||||
#define MZ_CRC_ERROR (-105)
|
||||
#define MZ_CRYPT_ERROR (-106)
|
||||
#define MZ_EXIST_ERROR (-107)
|
||||
#define MZ_PASSWORD_ERROR (-108)
|
||||
#define MZ_SUPPORT_ERROR (-109)
|
||||
|
||||
// MZ_OPEN
|
||||
#define MZ_OPEN_MODE_READ (0x01)
|
||||
@@ -49,7 +53,7 @@ extern "C" {
|
||||
#define MZ_SEEK_END (2)
|
||||
|
||||
// MZ_COMPRESS
|
||||
#define MZ_COMPRESS_METHOD_RAW (0)
|
||||
#define MZ_COMPRESS_METHOD_STORE (0)
|
||||
#define MZ_COMPRESS_METHOD_DEFLATE (8)
|
||||
#define MZ_COMPRESS_METHOD_BZIP2 (12)
|
||||
#define MZ_COMPRESS_METHOD_LZMA (14)
|
||||
@@ -69,12 +73,40 @@ extern "C" {
|
||||
#define MZ_ZIP_FLAG_DEFLATE_SUPER_FAST (MZ_ZIP_FLAG_DEFLATE_FAST | \
|
||||
MZ_ZIP_FLAG_DEFLATE_MAX)
|
||||
#define MZ_ZIP_FLAG_DATA_DESCRIPTOR (1 << 3)
|
||||
#define MZ_ZIP_FLAG_UTF8 (1 << 11)
|
||||
|
||||
// MZ_ZIP64
|
||||
#define MZ_ZIP64_AUTO (0)
|
||||
#define MZ_ZIP64_FORCE (1)
|
||||
#define MZ_ZIP64_DISABLE (2)
|
||||
|
||||
// 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
|
||||
#define MZ_PKCRYPT_HEADER_SIZE (12)
|
||||
|
||||
// MZ_AES
|
||||
#define MZ_AES_VERSION (1)
|
||||
#define MZ_AES_ENCRYPTION_MODE_128 (0x01)
|
||||
#define MZ_AES_ENCRYPTION_MODE_192 (0x02)
|
||||
#define MZ_AES_ENCRYPTION_MODE_256 (0x03)
|
||||
#define MZ_AES_HEADER_SIZE(MODE) ((4 * (MODE & 3) + 4) + 2)
|
||||
#define MZ_AES_FOOTER_SIZE (10)
|
||||
|
||||
// MZ_UTILITY
|
||||
#define MZ_UNUSED(SYMBOL) ((void)SYMBOL)
|
||||
|
||||
#ifndef MZ_CUSTOM_ALLOC
|
||||
#define MZ_ALLOC(SIZE) (malloc(SIZE))
|
||||
#endif
|
||||
#ifndef MZ_CUSTOM_FREE
|
||||
#define MZ_FREE(PTR) (free(PTR))
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
+839
@@ -0,0 +1,839 @@
|
||||
/* mz_compat.c -- Backwards compatible interface for older versions
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_mem.h"
|
||||
#include "mz_strm_zlib.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
#include "mz_compat.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_compat_s {
|
||||
void *stream;
|
||||
void *handle;
|
||||
} mz_compat;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static int32_t zipConvertAppendToStreamMode(int append)
|
||||
{
|
||||
int32_t mode = MZ_OPEN_MODE_WRITE;
|
||||
switch (append)
|
||||
{
|
||||
case APPEND_STATUS_CREATE:
|
||||
mode |= MZ_OPEN_MODE_CREATE;
|
||||
break;
|
||||
case APPEND_STATUS_CREATEAFTER:
|
||||
mode |= MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_APPEND;
|
||||
break;
|
||||
case APPEND_STATUS_ADDINZIP:
|
||||
mode |= MZ_OPEN_MODE_READ;
|
||||
break;
|
||||
}
|
||||
return mode;
|
||||
}
|
||||
|
||||
zipFile ZEXPORT zipOpen(const char *path, int append)
|
||||
{
|
||||
zlib_filefunc64_def pzlib = mz_stream_os_get_interface();
|
||||
return zipOpen2(path, append, NULL, &pzlib);
|
||||
}
|
||||
|
||||
zipFile ZEXPORT zipOpen64(const void *path, int append)
|
||||
{
|
||||
zlib_filefunc64_def pzlib = mz_stream_os_get_interface();
|
||||
return zipOpen2(path, append, NULL, &pzlib);
|
||||
}
|
||||
|
||||
zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
|
||||
zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
return zipOpen2_64(path, append, globalcomment, pzlib_filefunc_def);
|
||||
}
|
||||
|
||||
zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
|
||||
zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
zipFile zip = NULL;
|
||||
int32_t mode = zipConvertAppendToStreamMode(append);
|
||||
void *stream = NULL;
|
||||
|
||||
if (pzlib_filefunc_def)
|
||||
{
|
||||
if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mz_stream_os_create(&stream) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (mz_stream_open(stream, path, mode) != MZ_OK)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zip = zipOpen_MZ(stream, append, globalcomment);
|
||||
|
||||
if (zip == NULL)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return zip;
|
||||
}
|
||||
|
||||
zipFile ZEXPORT zipOpen_MZ(void *stream, int append, const char **globalcomment)
|
||||
{
|
||||
mz_compat *compat = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t mode = zipConvertAppendToStreamMode(append);
|
||||
void *handle = NULL;
|
||||
|
||||
mz_zip_create(&handle);
|
||||
err = mz_zip_open(handle, stream, mode);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
mz_zip_delete(&handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (globalcomment != NULL)
|
||||
mz_zip_get_comment(handle, globalcomment);
|
||||
|
||||
compat = (mz_compat *)MZ_ALLOC(sizeof(mz_compat));
|
||||
compat->handle = handle;
|
||||
compat->stream = stream;
|
||||
|
||||
return (zipFile)compat;
|
||||
}
|
||||
|
||||
int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
mz_zip_file file_info;
|
||||
uint64_t dos_date = 0;
|
||||
|
||||
|
||||
MZ_UNUSED(strategy);
|
||||
MZ_UNUSED(memLevel);
|
||||
MZ_UNUSED(windowBits);
|
||||
MZ_UNUSED(size_extrafield_local);
|
||||
MZ_UNUSED(extrafield_local);
|
||||
MZ_UNUSED(crc_for_crypting);
|
||||
|
||||
if (compat == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
|
||||
memset(&file_info, 0, sizeof(file_info));
|
||||
|
||||
if (zipfi != NULL)
|
||||
{
|
||||
if (zipfi->dosDate != 0)
|
||||
dos_date = zipfi->dosDate;
|
||||
else
|
||||
dos_date = mz_zip_tm_to_dosdate(&zipfi->tmz_date);
|
||||
|
||||
file_info.modified_date = mz_zip_dosdate_to_time_t(dos_date);
|
||||
file_info.external_fa = zipfi->external_fa;
|
||||
file_info.internal_fa = zipfi->internal_fa;
|
||||
}
|
||||
|
||||
if (filename == NULL)
|
||||
filename = "-";
|
||||
|
||||
file_info.compression_method = compression_method;
|
||||
file_info.filename = filename;
|
||||
//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;
|
||||
file_info.comment = comment;
|
||||
file_info.flag = flag_base;
|
||||
if (zip64)
|
||||
file_info.zip64 = MZ_ZIP64_FORCE;
|
||||
else
|
||||
file_info.zip64 = MZ_ZIP64_DISABLE;
|
||||
#ifdef HAVE_AES
|
||||
if ((password != NULL) || (raw && (file_info.flag & MZ_ZIP_FLAG_ENCRYPTED)))
|
||||
file_info.aes_version = MZ_AES_VERSION;
|
||||
#endif
|
||||
|
||||
return mz_zip_entry_write_open(compat->handle, &file_info, (int16_t)level, (uint8_t)raw, password);
|
||||
}
|
||||
|
||||
int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
|
||||
{
|
||||
return zipOpenNewFileInZip5(file, filename, zipfi, extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
|
||||
memLevel, strategy, password, crc_for_crypting, version_madeby, flag_base, zip64);
|
||||
}
|
||||
|
||||
int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base)
|
||||
{
|
||||
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
|
||||
memLevel, strategy, password, crc_for_crypting, version_madeby, flag_base, 0);
|
||||
}
|
||||
|
||||
int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
uint32_t crc_for_crypting)
|
||||
{
|
||||
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
|
||||
memLevel, strategy, password, crc_for_crypting, MZ_VERSION_MADEBY, 0, 0);
|
||||
}
|
||||
|
||||
int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
uint32_t crc_for_crypting, int zip64)
|
||||
{
|
||||
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
|
||||
memLevel, strategy, password, crc_for_crypting, MZ_VERSION_MADEBY, 0, zip64);
|
||||
}
|
||||
|
||||
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t written = 0;
|
||||
if (compat == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
written = mz_zip_entry_write(compat->handle, buf, len);
|
||||
if ((written < 0) || ((uint32_t)written != len))
|
||||
return ZIP_ERRNO;
|
||||
return ZIP_OK;
|
||||
}
|
||||
|
||||
int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32)
|
||||
{
|
||||
return zipCloseFileInZipRaw64(file, uncompressed_size, crc32);
|
||||
}
|
||||
|
||||
int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
return mz_zip_entry_close_raw(compat->handle, uncompressed_size, crc32);
|
||||
}
|
||||
|
||||
int ZEXPORT zipCloseFileInZip(zipFile file)
|
||||
{
|
||||
return zipCloseFileInZip64(file);
|
||||
}
|
||||
|
||||
int ZEXPORT zipCloseFileInZip64(zipFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
return mz_zip_entry_close(compat->handle);
|
||||
}
|
||||
|
||||
int ZEXPORT zipClose(zipFile file, const char *global_comment)
|
||||
{
|
||||
return zipClose_64(file, global_comment);
|
||||
}
|
||||
|
||||
int ZEXPORT zipClose_64(zipFile file, const char *global_comment)
|
||||
{
|
||||
return zipClose2_64(file, global_comment, MZ_VERSION_MADEBY);
|
||||
}
|
||||
|
||||
int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat->handle != NULL)
|
||||
err = zipClose2_MZ(file, global_comment, version_madeby);
|
||||
|
||||
if (compat->stream != NULL)
|
||||
{
|
||||
mz_stream_close(compat->stream);
|
||||
mz_stream_delete(&compat->stream);
|
||||
}
|
||||
|
||||
MZ_FREE(compat);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
// 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
|
||||
int ZEXPORT zipClose2_MZ(zipFile file, const char *global_comment, uint16_t version_madeby)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
if (compat->handle == NULL)
|
||||
return err;
|
||||
|
||||
if (global_comment != NULL)
|
||||
mz_zip_set_comment(compat->handle, global_comment);
|
||||
|
||||
mz_zip_set_version_madeby(compat->handle, version_madeby);
|
||||
err = mz_zip_close(compat->handle);
|
||||
mz_zip_delete(&compat->handle);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void* ZEXPORT zipGetStream(zipFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return NULL;
|
||||
return (void *)compat->stream;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
unzFile ZEXPORT unzOpen(const char *path)
|
||||
{
|
||||
return unzOpen64(path);
|
||||
}
|
||||
|
||||
unzFile ZEXPORT unzOpen64(const void *path)
|
||||
{
|
||||
zlib_filefunc64_def pzlib = mz_stream_os_get_interface();
|
||||
return unzOpen2(path, &pzlib);
|
||||
}
|
||||
|
||||
unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
return unzOpen2_64(path, pzlib_filefunc_def);
|
||||
}
|
||||
|
||||
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
unzFile unz = NULL;
|
||||
void *stream = NULL;
|
||||
|
||||
if (pzlib_filefunc_def)
|
||||
{
|
||||
if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mz_stream_os_create(&stream) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mz_stream_open(stream, path, MZ_OPEN_MODE_READ) != MZ_OK)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unz = unzOpen_MZ(stream);
|
||||
if (unz == NULL)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
return unz;
|
||||
}
|
||||
|
||||
unzFile ZEXPORT unzOpen_MZ(void *stream)
|
||||
{
|
||||
mz_compat *compat = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
void *handle = NULL;
|
||||
|
||||
mz_zip_create(&handle);
|
||||
err = mz_zip_open(handle, stream, MZ_OPEN_MODE_READ);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
mz_zip_delete(&handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
compat = (mz_compat *)MZ_ALLOC(sizeof(mz_compat));
|
||||
compat->handle = handle;
|
||||
compat->stream = stream;
|
||||
|
||||
mz_zip_goto_first_entry(compat->handle);
|
||||
return (unzFile)compat;
|
||||
}
|
||||
|
||||
int ZEXPORT unzClose(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
|
||||
if (compat->handle != NULL)
|
||||
err = unzClose_MZ(file);
|
||||
|
||||
if (compat->stream != NULL)
|
||||
{
|
||||
mz_stream_close(compat->stream);
|
||||
mz_stream_delete(&compat->stream);
|
||||
}
|
||||
|
||||
MZ_FREE(compat);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
// Only closes the zip handle, does not close the stream
|
||||
int ZEXPORT unzClose_MZ(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
|
||||
err = mz_zip_close(compat->handle);
|
||||
mz_zip_delete(&compat->handle);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
unz_global_info64 global_info64;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
memset(pglobal_info32, 0, sizeof(unz_global_info));
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
|
||||
err = unzGetGlobalInfo64(file, &global_info64);
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
pglobal_info32->number_entry = (uint32_t)global_info64.number_entry;
|
||||
pglobal_info32->size_comment = global_info64.size_comment;
|
||||
pglobal_info32->number_disk_with_CD = global_info64.number_disk_with_CD;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
const char *comment_ptr = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
memset(pglobal_info, 0, sizeof(unz_global_info64));
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
err = mz_zip_get_comment(compat->handle, &comment_ptr);
|
||||
if (err == MZ_OK)
|
||||
pglobal_info->size_comment = (uint16_t)strlen(comment_ptr);
|
||||
if ((err == MZ_OK) || (err == MZ_EXIST_ERROR))
|
||||
err = mz_zip_get_number_entry(compat->handle, (int64_t *)&pglobal_info->number_entry);
|
||||
if (err == MZ_OK)
|
||||
err = mz_zip_get_disk_number_with_cd(compat->handle, &pglobal_info->number_disk_with_CD);
|
||||
return err;
|
||||
}
|
||||
|
||||
int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
const char *comment_ptr = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (comment == NULL || comment_size == 0)
|
||||
return UNZ_PARAMERROR;
|
||||
err = mz_zip_get_comment(compat->handle, &comment_ptr);
|
||||
if (err == MZ_OK)
|
||||
strncpy(comment, comment_ptr, comment_size);
|
||||
return err;
|
||||
}
|
||||
|
||||
int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
mz_zip_file *file_info = NULL;
|
||||
int err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
if (method != NULL)
|
||||
*method = 0;
|
||||
if (level != NULL)
|
||||
*level = 0;
|
||||
|
||||
err = mz_zip_entry_read_open(compat->handle, (uint8_t)raw, password);
|
||||
if (err == MZ_OK)
|
||||
err = mz_zip_entry_get_info(compat->handle, &file_info);
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (method != NULL)
|
||||
{
|
||||
*method = file_info->compression_method;
|
||||
}
|
||||
|
||||
if (level != NULL)
|
||||
{
|
||||
*level = 6;
|
||||
switch (file_info->flag & 0x06)
|
||||
{
|
||||
case MZ_ZIP_FLAG_DEFLATE_SUPER_FAST:
|
||||
*level = 1;
|
||||
break;
|
||||
case MZ_ZIP_FLAG_DEFLATE_FAST:
|
||||
*level = 2;
|
||||
break;
|
||||
case MZ_ZIP_FLAG_DEFLATE_MAX:
|
||||
*level = 9;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int ZEXPORT unzOpenCurrentFile(unzFile file)
|
||||
{
|
||||
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
|
||||
{
|
||||
return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
|
||||
}
|
||||
|
||||
int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw)
|
||||
{
|
||||
return unzOpenCurrentFile3(file, method, level, raw, NULL);
|
||||
}
|
||||
|
||||
int ZEXPORT unzReadCurrentFile(unzFile file, void *buf, uint32_t len)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
return mz_zip_entry_read(compat->handle, buf, len);
|
||||
}
|
||||
|
||||
int ZEXPORT unzCloseCurrentFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
return mz_zip_entry_close(compat->handle);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
mz_zip_file *file_info = NULL;
|
||||
int16_t bytes_to_copy = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
|
||||
err = mz_zip_entry_get_info(compat->handle, &file_info);
|
||||
|
||||
if ((err == MZ_OK) && (pfile_info != NULL))
|
||||
{
|
||||
pfile_info->version = file_info->version_madeby;
|
||||
pfile_info->version_needed = file_info->version_needed;
|
||||
pfile_info->flag = file_info->flag;
|
||||
pfile_info->compression_method = file_info->compression_method;
|
||||
pfile_info->dosDate = mz_zip_time_t_to_dos_date(file_info->modified_date);
|
||||
mz_zip_time_t_to_tm(file_info->modified_date, &pfile_info->tmu_date);
|
||||
pfile_info->tmu_date.tm_year += 1900;
|
||||
pfile_info->crc = file_info->crc;
|
||||
|
||||
pfile_info->size_filename = file_info->filename_size;
|
||||
pfile_info->size_file_extra = file_info->extrafield_size;
|
||||
pfile_info->size_file_comment = file_info->comment_size;
|
||||
|
||||
pfile_info->disk_num_start = (uint16_t)file_info->disk_number;
|
||||
pfile_info->internal_fa = file_info->internal_fa;
|
||||
pfile_info->external_fa = file_info->external_fa;
|
||||
|
||||
pfile_info->compressed_size = (uint32_t)file_info->compressed_size;
|
||||
pfile_info->uncompressed_size = (uint32_t)file_info->uncompressed_size;
|
||||
|
||||
if (filename_size > 0 && filename != NULL && file_info->filename != NULL)
|
||||
{
|
||||
bytes_to_copy = filename_size;
|
||||
if (bytes_to_copy > file_info->filename_size)
|
||||
bytes_to_copy = file_info->filename_size;
|
||||
memcpy(filename, file_info->filename, bytes_to_copy);
|
||||
if (bytes_to_copy < filename_size)
|
||||
filename[bytes_to_copy] = 0;
|
||||
}
|
||||
if (extrafield_size > 0 && extrafield != NULL)
|
||||
{
|
||||
bytes_to_copy = extrafield_size;
|
||||
if (bytes_to_copy > file_info->extrafield_size)
|
||||
bytes_to_copy = file_info->extrafield_size;
|
||||
memcpy(extrafield, file_info->extrafield, bytes_to_copy);
|
||||
}
|
||||
if (comment_size > 0 && comment != NULL && file_info->comment != NULL)
|
||||
{
|
||||
bytes_to_copy = comment_size;
|
||||
if (bytes_to_copy > file_info->comment_size)
|
||||
bytes_to_copy = file_info->comment_size;
|
||||
memcpy(comment, file_info->comment, bytes_to_copy);
|
||||
if (bytes_to_copy < comment_size)
|
||||
comment[bytes_to_copy] = 0;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
mz_zip_file *file_info = NULL;
|
||||
int16_t bytes_to_copy = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
|
||||
err = mz_zip_entry_get_info(compat->handle, &file_info);
|
||||
|
||||
if ((err == MZ_OK) && (pfile_info != NULL))
|
||||
{
|
||||
pfile_info->version = file_info->version_madeby;
|
||||
pfile_info->version_needed = file_info->version_needed;
|
||||
pfile_info->flag = file_info->flag;
|
||||
pfile_info->compression_method = file_info->compression_method;
|
||||
pfile_info->dosDate = mz_zip_time_t_to_dos_date(file_info->modified_date);
|
||||
mz_zip_time_t_to_tm(file_info->modified_date, &pfile_info->tmu_date);
|
||||
pfile_info->tmu_date.tm_year += 1900;
|
||||
pfile_info->crc = file_info->crc;
|
||||
|
||||
pfile_info->size_filename = file_info->filename_size;
|
||||
pfile_info->size_file_extra = file_info->extrafield_size;
|
||||
pfile_info->size_file_comment = file_info->comment_size;
|
||||
|
||||
pfile_info->disk_num_start = file_info->disk_number;
|
||||
pfile_info->internal_fa = file_info->internal_fa;
|
||||
pfile_info->external_fa = file_info->external_fa;
|
||||
|
||||
pfile_info->compressed_size = file_info->compressed_size;
|
||||
pfile_info->uncompressed_size = file_info->uncompressed_size;
|
||||
|
||||
if (filename_size > 0 && filename != NULL && file_info->filename != NULL)
|
||||
{
|
||||
bytes_to_copy = filename_size;
|
||||
if (bytes_to_copy > file_info->filename_size)
|
||||
bytes_to_copy = file_info->filename_size;
|
||||
memcpy(filename, file_info->filename, bytes_to_copy);
|
||||
if (bytes_to_copy < filename_size)
|
||||
filename[bytes_to_copy] = 0;
|
||||
}
|
||||
|
||||
if (extrafield_size > 0 && extrafield != NULL)
|
||||
{
|
||||
bytes_to_copy = extrafield_size;
|
||||
if (bytes_to_copy > file_info->extrafield_size)
|
||||
bytes_to_copy = file_info->extrafield_size;
|
||||
memcpy(extrafield, file_info->extrafield, bytes_to_copy);
|
||||
}
|
||||
|
||||
if (comment_size > 0 && comment != NULL && file_info->comment != NULL)
|
||||
{
|
||||
bytes_to_copy = comment_size;
|
||||
if (bytes_to_copy > file_info->comment_size)
|
||||
bytes_to_copy = file_info->comment_size;
|
||||
memcpy(comment, file_info->comment, bytes_to_copy);
|
||||
if (bytes_to_copy < comment_size)
|
||||
comment[bytes_to_copy] = 0;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int ZEXPORT unzGoToFirstFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
return mz_zip_goto_first_entry(compat->handle);
|
||||
}
|
||||
|
||||
int ZEXPORT unzGoToNextFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
return mz_zip_goto_next_entry(compat->handle);
|
||||
}
|
||||
|
||||
int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
mz_zip_file *file_info = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t result = 0;
|
||||
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
|
||||
err = mz_zip_goto_first_entry(compat->handle);
|
||||
while (err == MZ_OK)
|
||||
{
|
||||
err = mz_zip_entry_get_info(compat->handle, &file_info);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
if (filename_compare_func != NULL)
|
||||
result = filename_compare_func(file, filename, file_info->filename);
|
||||
else
|
||||
result = strcmp(filename, file_info->filename);
|
||||
|
||||
if (result == 0)
|
||||
return MZ_OK;
|
||||
|
||||
err = mz_zip_goto_next_entry(compat->handle);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t ZEXPORT unzGetOffset(unzFile file)
|
||||
{
|
||||
return (int32_t)unzGetOffset64(file);
|
||||
}
|
||||
|
||||
int64_t ZEXPORT unzGetOffset64(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
return mz_zip_get_entry(compat->handle);
|
||||
}
|
||||
|
||||
int ZEXPORT unzSetOffset(unzFile file, uint32_t pos)
|
||||
{
|
||||
return unzSetOffset64(file, pos);
|
||||
}
|
||||
|
||||
int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
return (int)mz_zip_goto_entry(compat->handle, pos);
|
||||
}
|
||||
|
||||
int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned len) // TODO
|
||||
{
|
||||
MZ_UNUSED(file);
|
||||
MZ_UNUSED(buf);
|
||||
MZ_UNUSED(len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* ZEXPORT unzGetStream(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return NULL;
|
||||
return (void *)compat->stream;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
|
||||
void fill_memory_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
*pzlib_filefunc_def = mz_stream_mem_get_interface();
|
||||
}
|
||||
+120
-97
@@ -1,8 +1,8 @@
|
||||
/* mz_compat.h -- Backwards compatible interface for older versions
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
@@ -11,25 +11,16 @@
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef _MZ_COMPAT_H
|
||||
#define _MZ_COMPAT_H
|
||||
#ifndef MZ_COMPAT_H
|
||||
#define MZ_COMPAT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define ZIP_UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
# define ZIP_UNUSED
|
||||
"C" {
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
@@ -37,9 +28,18 @@ extern "C" {
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
# endif
|
||||
#endif
|
||||
#else
|
||||
#define MAX_WBITS (15)
|
||||
#define DEF_MEM_LEVEL (8)
|
||||
#endif
|
||||
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(USE_FILE32API)
|
||||
# define MZ_USE_FILE32API
|
||||
# define fopen64 fopen
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
@@ -70,7 +70,7 @@ extern "C" {
|
||||
typedef struct TagzipFile__ { int unused; } zip_file__;
|
||||
typedef zip_file__ *zipFile;
|
||||
#else
|
||||
typedef voidp zipFile;
|
||||
typedef void *zipFile;
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -79,11 +79,17 @@ typedef void *zlib_filefunc_def;
|
||||
typedef void *zlib_filefunc64_def;
|
||||
typedef const char *zipcharpc;
|
||||
|
||||
typedef struct tm tm_unz;
|
||||
typedef struct tm tm_zip;
|
||||
|
||||
typedef uint64_t ZPOS64_T;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t dos_date;
|
||||
uint32_t dosDate;
|
||||
struct tm tmz_date;
|
||||
uint16_t internal_fa; // internal file attributes 2 bytes
|
||||
uint32_t external_fa; // external file attributes 4 bytes
|
||||
} zip_fileinfo;
|
||||
@@ -92,61 +98,66 @@ typedef struct
|
||||
|
||||
#define ZIP_OK (0)
|
||||
#define ZIP_EOF (0)
|
||||
#define ZIP_ERRNO (Z_ERRNO)
|
||||
#define ZIP_ERRNO (-1)
|
||||
#define ZIP_PARAMERROR (-102)
|
||||
#define ZIP_BADZIPFILE (-103)
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
#define Z_BZIP2ED (12)
|
||||
|
||||
#define APPEND_STATUS_CREATE (1)
|
||||
#define APPEND_STATUS_CREATEAFTER (2)
|
||||
#define APPEND_STATUS_ADDINZIP (3)
|
||||
#define APPEND_STATUS_CREATE (0)
|
||||
#define APPEND_STATUS_CREATEAFTER (1)
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen(const char *path, int append);
|
||||
extern zipFile ZEXPORT zipOpen64(const void *path, int append);
|
||||
extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
|
||||
zipFile ZEXPORT zipOpen(const char *path, int append);
|
||||
zipFile ZEXPORT zipOpen64(const void *path, int append);
|
||||
zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
|
||||
zlib_filefunc_def *pzlib_filefunc_def);
|
||||
extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
|
||||
zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
|
||||
zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
zipFile ZEXPORT zipOpen_MZ(void *stream, int append, const char **globalcomment);
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting);
|
||||
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
uint32_t crc_for_crypting);
|
||||
int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting, int zip64);
|
||||
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
uint32_t crc_for_crypting, int zip64);
|
||||
int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
|
||||
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
|
||||
int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
|
||||
extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
|
||||
int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
|
||||
uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);
|
||||
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32);
|
||||
extern int ZEXPORT zipCloseFileInZip(zipFile file);
|
||||
extern int ZEXPORT zipCloseFileInZip64(zipFile file);
|
||||
int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32);
|
||||
int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32);
|
||||
int ZEXPORT zipCloseFileInZip(zipFile file);
|
||||
int ZEXPORT zipCloseFileInZip64(zipFile file);
|
||||
|
||||
extern int ZEXPORT zipClose(zipFile file, const char *global_comment);
|
||||
extern int ZEXPORT zipClose_64(zipFile file, const char *global_comment);
|
||||
extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby);
|
||||
int ZEXPORT zipClose(zipFile file, const char *global_comment);
|
||||
int ZEXPORT zipClose_64(zipFile file, const char *global_comment);
|
||||
int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby);
|
||||
int ZEXPORT zipClose_MZ(zipFile file, const char *global_comment);
|
||||
int ZEXPORT zipClose2_MZ(zipFile file, const char *global_comment, uint16_t version_madeby);
|
||||
void* ZEXPORT zipGetStream(zipFile file);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -156,14 +167,14 @@ extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16
|
||||
typedef struct TagunzFile__ { int unused; } unz_file__;
|
||||
typedef unz_file__ *unzFile;
|
||||
#else
|
||||
typedef voidp unzFile;
|
||||
typedef void *unzFile;
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (Z_ERRNO)
|
||||
#define UNZ_ERRNO (-1)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
@@ -175,35 +186,36 @@ typedef voidp unzFile;
|
||||
|
||||
typedef struct unz_global_info64_s
|
||||
{
|
||||
uint64_t number_entry; // total number of entries in the central dir on this disk
|
||||
uint64_t number_entry; // total number of entries in the central dir on this disk
|
||||
uint32_t number_disk_with_CD; // number the the disk with central dir, used for spanning ZIP
|
||||
uint16_t size_comment; // size of the global comment of the zipfile
|
||||
uint16_t size_comment; // size of the global comment of the zipfile
|
||||
} unz_global_info64;
|
||||
|
||||
typedef struct unz_global_info_s
|
||||
{
|
||||
uint32_t number_entry; // total number of entries in the central dir on this disk
|
||||
uint32_t number_entry; // total number of entries in the central dir on this disk
|
||||
uint32_t number_disk_with_CD; // number the the disk with central dir, used for spanning ZIP
|
||||
uint16_t size_comment; // size of the global comment of the zipfile
|
||||
uint16_t size_comment; // size of the global comment of the zipfile
|
||||
} unz_global_info;
|
||||
|
||||
typedef struct unz_file_info64_s
|
||||
{
|
||||
uint16_t version; // version made by 2 bytes
|
||||
uint16_t version_needed; // version needed to extract 2 bytes
|
||||
uint16_t flag; // general purpose bit flag 2 bytes
|
||||
uint16_t compression_method; // compression method 2 bytes
|
||||
uint32_t dos_date; // last mod file date in Dos fmt 4 bytes
|
||||
uint32_t crc; // crc-32 4 bytes
|
||||
uint64_t compressed_size; // compressed size 8 bytes
|
||||
uint64_t uncompressed_size; // uncompressed size 8 bytes
|
||||
uint16_t size_filename; // filename length 2 bytes
|
||||
uint16_t size_file_extra; // extra field length 2 bytes
|
||||
uint16_t size_file_comment; // file comment length 2 bytes
|
||||
uint16_t version; // version made by 2 bytes
|
||||
uint16_t version_needed; // version needed to extract 2 bytes
|
||||
uint16_t flag; // general purpose bit flag 2 bytes
|
||||
uint16_t compression_method; // compression method 2 bytes
|
||||
uint32_t dosDate; // last mod file date in Dos fmt 4 bytes
|
||||
struct tm tmu_date;
|
||||
uint32_t crc; // crc-32 4 bytes
|
||||
uint64_t compressed_size; // compressed size 8 bytes
|
||||
uint64_t uncompressed_size; // uncompressed size 8 bytes
|
||||
uint16_t size_filename; // filename length 2 bytes
|
||||
uint16_t size_file_extra; // extra field length 2 bytes
|
||||
uint16_t size_file_comment; // file comment length 2 bytes
|
||||
|
||||
uint32_t disk_num_start; // disk number start 4 bytes
|
||||
uint16_t internal_fa; // internal file attributes 2 bytes
|
||||
uint32_t external_fa; // external file attributes 4 bytes
|
||||
uint32_t disk_num_start; // disk number start 4 bytes
|
||||
uint16_t internal_fa; // internal file attributes 2 bytes
|
||||
uint32_t external_fa; // external file attributes 4 bytes
|
||||
|
||||
uint64_t disk_offset;
|
||||
|
||||
@@ -212,20 +224,21 @@ typedef struct unz_file_info64_s
|
||||
|
||||
typedef struct unz_file_info_s
|
||||
{
|
||||
uint16_t version; // version made by 2 bytes
|
||||
uint16_t version_needed; // version needed to extract 2 bytes
|
||||
uint16_t flag; // general purpose bit flag 2 bytes
|
||||
uint16_t compression_method; // compression method 2 bytes
|
||||
uint32_t dos_date; // last mod file date in Dos fmt 4 bytes
|
||||
uint32_t crc; // crc-32 4 bytes
|
||||
uint32_t compressed_size; // compressed size 4 bytes
|
||||
uint32_t uncompressed_size; // uncompressed size 4 bytes
|
||||
uint16_t size_filename; // filename length 2 bytes
|
||||
uint16_t size_file_extra; // extra field length 2 bytes
|
||||
uint16_t size_file_comment; // file comment length 2 bytes
|
||||
uint16_t version; // version made by 2 bytes
|
||||
uint16_t version_needed; // version needed to extract 2 bytes
|
||||
uint16_t flag; // general purpose bit flag 2 bytes
|
||||
uint16_t compression_method; // compression method 2 bytes
|
||||
uint32_t dosDate; // last mod file date in Dos fmt 4 bytes
|
||||
struct tm tmu_date;
|
||||
uint32_t crc; // crc-32 4 bytes
|
||||
uint32_t compressed_size; // compressed size 4 bytes
|
||||
uint32_t uncompressed_size; // uncompressed size 4 bytes
|
||||
uint16_t size_filename; // filename length 2 bytes
|
||||
uint16_t size_file_extra; // extra field length 2 bytes
|
||||
uint16_t size_file_comment; // file comment length 2 bytes
|
||||
|
||||
uint16_t disk_num_start; // disk number start 2 bytes
|
||||
uint16_t internal_fa; // internal file attributes 2 bytes
|
||||
uint16_t disk_num_start; // disk number start 2 bytes
|
||||
uint16_t internal_fa; // internal file attributes 2 bytes
|
||||
uint32_t external_fa; // external file attributes 4 bytes
|
||||
|
||||
uint64_t disk_offset;
|
||||
@@ -240,29 +253,38 @@ typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, c
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen(const char *path);
|
||||
extern unzFile ZEXPORT unzOpen64(const void *path);
|
||||
extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
|
||||
extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
unzFile ZEXPORT unzOpen(const char *path);
|
||||
unzFile ZEXPORT unzOpen64(const void *path);
|
||||
unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
|
||||
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
unzFile ZEXPORT unzOpen_MZ(void *stream);
|
||||
|
||||
extern int ZEXPORT unzClose(unzFile file);
|
||||
extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32);
|
||||
extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info);
|
||||
extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size);
|
||||
extern int ZEXPORT unzOpenCurrentFile(unzFile file);
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password);
|
||||
extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
|
||||
extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
|
||||
extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len);
|
||||
extern int ZEXPORT unzCloseCurrentFile(unzFile file);
|
||||
int ZEXPORT unzClose(unzFile file);
|
||||
int ZEXPORT unzClose_MZ(unzFile file);
|
||||
int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32);
|
||||
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info);
|
||||
int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size);
|
||||
int ZEXPORT unzOpenCurrentFile(unzFile file);
|
||||
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password);
|
||||
int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
|
||||
int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
|
||||
int ZEXPORT unzReadCurrentFile(unzFile file, void *buf, uint32_t len);
|
||||
int ZEXPORT unzCloseCurrentFile(unzFile file);
|
||||
|
||||
extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
|
||||
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);
|
||||
extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_info, char *filename,
|
||||
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);
|
||||
extern int ZEXPORT unzGoToFirstFile(unzFile file);
|
||||
extern int ZEXPORT unzGoToNextFile(unzFile file);
|
||||
extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
|
||||
int ZEXPORT unzGoToFirstFile(unzFile file);
|
||||
int ZEXPORT unzGoToNextFile(unzFile file);
|
||||
int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
|
||||
|
||||
int64_t ZEXPORT unzGetOffset64(unzFile file);
|
||||
int32_t ZEXPORT unzGetOffset(unzFile file);
|
||||
int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos);
|
||||
int ZEXPORT unzSetOffset(unzFile file, uint32_t pos);
|
||||
int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned len);
|
||||
void* ZEXPORT unzGetStream(unzFile file);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -272,6 +294,7 @@ void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
|
||||
void fill_win32_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
void fill_memory_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -280,8 +303,8 @@ void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
#define change_file_date mz_os_set_file_date
|
||||
#define get_file_date mz_os_get_file_date
|
||||
#define is_large_file(x) (mz_os_get_file_size(x) >= UINT32_MAX)
|
||||
#define makedir mz_make_dir
|
||||
#define get_file_crc(p,b,bs,rc) mz_get_file_crc(p,rc)
|
||||
#define makedir mz_dir_make
|
||||
#define get_file_crc(p,b,bs,rc) mz_file_get_crc(p,rc)
|
||||
|
||||
#define MKDIR mz_os_make_dir
|
||||
#define CHDIR chdir
|
||||
@@ -0,0 +1,406 @@
|
||||
/* mz_os.c -- System functions
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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 <ctype.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_crc32.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static uint32_t mz_encoding_codepage437_to_utf8[256] = {
|
||||
0x000000, 0xba98e2, 0xbb98e2, 0xa599e2, 0xa699e2, 0xa399e2, 0xa099e2, 0xa280e2,
|
||||
0x9897e2, 0x8b97e2, 0x9997e2, 0x8299e2, 0x8099e2, 0xaa99e2, 0xab99e2, 0xbc98e2,
|
||||
0xba96e2, 0x8497e2, 0x9586e2, 0xbc80e2, 0x00b6c2, 0x00a7c2, 0xac96e2, 0xa886e2,
|
||||
0x9186e2, 0x9386e2, 0x9286e2, 0x9086e2, 0x9f88e2, 0x9486e2, 0xb296e2, 0xbc96e2,
|
||||
0x000020, 0x000021, 0x000022, 0x000023, 0x000024, 0x000025, 0x000026, 0x000027,
|
||||
0x000028, 0x000029, 0x00002a, 0x00002b, 0x00002c, 0x00002d, 0x00002e, 0x00002f,
|
||||
0x000030, 0x000031, 0x000032, 0x000033, 0x000034, 0x000035, 0x000036, 0x000037,
|
||||
0x000038, 0x000039, 0x00003a, 0x00003b, 0x00003c, 0x00003d, 0x00003e, 0x00003f,
|
||||
0x000040, 0x000041, 0x000042, 0x000043, 0x000044, 0x000045, 0x000046, 0x000047,
|
||||
0x000048, 0x000049, 0x00004a, 0x00004b, 0x00004c, 0x00004d, 0x00004e, 0x00004f,
|
||||
0x000050, 0x000051, 0x000052, 0x000053, 0x000054, 0x000055, 0x000056, 0x000057,
|
||||
0x000058, 0x000059, 0x00005a, 0x00005b, 0x00005c, 0x00005d, 0x00005e, 0x00005f,
|
||||
0x000060, 0x000061, 0x000062, 0x000063, 0x000064, 0x000065, 0x000066, 0x000067,
|
||||
0x000068, 0x000069, 0x00006a, 0x00006b, 0x00006c, 0x00006d, 0x00006e, 0x00006f,
|
||||
0x000070, 0x000071, 0x000072, 0x000073, 0x000074, 0x000075, 0x000076, 0x000077,
|
||||
0x000078, 0x000079, 0x00007a, 0x00007b, 0x00007c, 0x00007d, 0x00007e, 0x828ce2,
|
||||
0x0087c3, 0x00bcc3, 0x00a9c3, 0x00a2c3, 0x00a4c3, 0x00a0c3, 0x00a5c3, 0x00a7c3,
|
||||
0x00aac3, 0x00abc3, 0x00a8c3, 0x00afc3, 0x00aec3, 0x00acc3, 0x0084c3, 0x0085c3,
|
||||
0x0089c3, 0x00a6c3, 0x0086c3, 0x00b4c3, 0x00b6c3, 0x00b2c3, 0x00bbc3, 0x00b9c3,
|
||||
0x00bfc3, 0x0096c3, 0x009cc3, 0x00a2c2, 0x00a3c2, 0x00a5c2, 0xa782e2, 0x0092c6,
|
||||
0x00a1c3, 0x00adc3, 0x00b3c3, 0x00bac3, 0x00b1c3, 0x0091c3, 0x00aac2, 0x00bac2,
|
||||
0x00bfc2, 0x908ce2, 0x00acc2, 0x00bdc2, 0x00bcc2, 0x00a1c2, 0x00abc2, 0x00bbc2,
|
||||
0x9196e2, 0x9296e2, 0x9396e2, 0x8294e2, 0xa494e2, 0xa195e2, 0xa295e2, 0x9695e2,
|
||||
0x9595e2, 0xa395e2, 0x9195e2, 0x9795e2, 0x9d95e2, 0x9c95e2, 0x9b95e2, 0x9094e2,
|
||||
0x9494e2, 0xb494e2, 0xac94e2, 0x9c94e2, 0x8094e2, 0xbc94e2, 0x9e95e2, 0x9f95e2,
|
||||
0x9a95e2, 0x9495e2, 0xa995e2, 0xa695e2, 0xa095e2, 0x9095e2, 0xac95e2, 0xa795e2,
|
||||
0xa895e2, 0xa495e2, 0xa595e2, 0x9995e2, 0x9895e2, 0x9295e2, 0x9395e2, 0xab95e2,
|
||||
0xaa95e2, 0x9894e2, 0x8c94e2, 0x8896e2, 0x8496e2, 0x8c96e2, 0x9096e2, 0x8096e2,
|
||||
0x00b1ce, 0x009fc3, 0x0093ce, 0x0080cf, 0x00a3ce, 0x0083cf, 0x00b5c2, 0x0084cf,
|
||||
0x00a6ce, 0x0098ce, 0x00a9ce, 0x00b4ce, 0x9e88e2, 0x0086cf, 0x00b5ce, 0xa988e2,
|
||||
0xa189e2, 0x00b1c2, 0xa589e2, 0xa489e2, 0xa08ce2, 0xa18ce2, 0x00b7c3, 0x8889e2,
|
||||
0x00b0c2, 0x9988e2, 0x00b7c2, 0x9a88e2, 0xbf81e2, 0x00b2c2, 0xa096e2, 0x00a0c2
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path)
|
||||
{
|
||||
int32_t path_len = 0;
|
||||
|
||||
if (path == NULL || join == NULL || max_path == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
path_len = strlen(path);
|
||||
|
||||
if (path_len == 0)
|
||||
{
|
||||
strncpy(path, join, max_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (path[path_len - 1] != '\\' && path[path_len - 1] != '/')
|
||||
strncat(path, "/", max_path - path_len - 1);
|
||||
strncat(path, join, max_path - path_len);
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case)
|
||||
{
|
||||
while (*path != 0)
|
||||
{
|
||||
switch (*wildcard)
|
||||
{
|
||||
case '*':
|
||||
|
||||
if (*(wildcard + 1) == 0)
|
||||
return MZ_OK;
|
||||
|
||||
while (*path != 0)
|
||||
{
|
||||
if (mz_path_compare_wc(path, (wildcard + 1), ignore_case) == MZ_OK)
|
||||
return MZ_OK;
|
||||
|
||||
path += 1;
|
||||
}
|
||||
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
default:
|
||||
// Ignore differences in path slashes on platforms
|
||||
if ((*path == '\\' && *wildcard == '/') || (*path == '/' && *wildcard == '\\'))
|
||||
break;
|
||||
|
||||
if (ignore_case)
|
||||
{
|
||||
if (tolower(*path) != tolower(*wildcard))
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*path != *wildcard)
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
path += 1;
|
||||
wildcard += 1;
|
||||
}
|
||||
|
||||
if ((*wildcard != 0) && (*wildcard != '*'))
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_resolve(const char *path, char *output, int32_t max_output)
|
||||
{
|
||||
const char *source = path;
|
||||
const char *check = output;
|
||||
char *target = output;
|
||||
|
||||
if (max_output <= 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
while (*source != 0 && max_output > 1)
|
||||
{
|
||||
check = source;
|
||||
if ((*check == '\\') || (*check == '/'))
|
||||
check += 1;
|
||||
|
||||
if ((source == path) || (check != source))
|
||||
{
|
||||
// Skip double paths
|
||||
if ((*check == '\\') || (*check == '/'))
|
||||
{
|
||||
source += 1;
|
||||
continue;
|
||||
}
|
||||
if ((*check != 0) && (*check == '.'))
|
||||
{
|
||||
check += 1;
|
||||
|
||||
// Remove current directory . if at end of stirng
|
||||
if ((*check == 0) && (source != path))
|
||||
{
|
||||
// Copy last slash
|
||||
*target = *source;
|
||||
target += 1;
|
||||
max_output -= 1;
|
||||
source += (check - source);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove current directory . if not at end of stirng
|
||||
if ((*check == 0) || (*check == '\\' || *check == '/'))
|
||||
{
|
||||
// Only proceed if .\ is not entire string
|
||||
if (check[1] != 0 || (path != source))
|
||||
{
|
||||
source += (check - source);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Go to parent directory ..
|
||||
if ((*check != 0) || (*check == '.'))
|
||||
{
|
||||
check += 1;
|
||||
if ((*check == 0) || (*check == '\\' || *check == '/'))
|
||||
{
|
||||
source += (check - source);
|
||||
|
||||
// Search backwards for previous slash
|
||||
if (target != output)
|
||||
{
|
||||
target -= 1;
|
||||
do
|
||||
{
|
||||
if ((*target == '\\') || (*target == '/'))
|
||||
break;
|
||||
|
||||
target -= 1;
|
||||
max_output += 1;
|
||||
}
|
||||
while (target > output);
|
||||
}
|
||||
|
||||
if ((target == output) && (*source != 0))
|
||||
source += 1;
|
||||
if ((*target == '\\' || *target == '/') && (*source == 0))
|
||||
target += 1;
|
||||
|
||||
*target = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*target = *source;
|
||||
|
||||
source += 1;
|
||||
target += 1;
|
||||
max_output -= 1;
|
||||
}
|
||||
|
||||
*target = 0;
|
||||
|
||||
if (*path == 0)
|
||||
return MZ_INTERNAL_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_remove_filename(const char *path)
|
||||
{
|
||||
char *path_ptr = NULL;
|
||||
|
||||
if (path == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
path_ptr = (char *)(path + strlen(path) - 1);
|
||||
|
||||
while (path_ptr > path)
|
||||
{
|
||||
if ((*path_ptr == '/') || (*path_ptr == '\\'))
|
||||
{
|
||||
*path_ptr = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
path_ptr -= 1;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_get_filename(const char *path, const char **filename)
|
||||
{
|
||||
const char *match = NULL;
|
||||
|
||||
if (path == NULL || filename == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
*filename = NULL;
|
||||
|
||||
for (match = path; *match != 0; match += 1)
|
||||
{
|
||||
if ((*match == '\\') || (*match == '/'))
|
||||
*filename = match + 1;
|
||||
}
|
||||
|
||||
if (*filename == NULL)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_dir_make(const char *path)
|
||||
{
|
||||
int32_t err = MZ_OK;
|
||||
int16_t len = 0;
|
||||
char *current_dir = NULL;
|
||||
char *match = NULL;
|
||||
char hold = 0;
|
||||
|
||||
|
||||
len = (int16_t)strlen(path);
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
current_dir = (char *)MZ_ALLOC(len + 1);
|
||||
if (current_dir == NULL)
|
||||
return MZ_MEM_ERROR;
|
||||
|
||||
strcpy(current_dir, path);
|
||||
|
||||
if (current_dir[len - 1] == '/')
|
||||
current_dir[len - 1] = 0;
|
||||
|
||||
err = mz_os_make_dir(current_dir);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
match = current_dir + 1;
|
||||
while (1)
|
||||
{
|
||||
while (*match != 0 && *match != '\\' && *match != '/')
|
||||
match += 1;
|
||||
hold = *match;
|
||||
*match = 0;
|
||||
|
||||
err = mz_os_make_dir(current_dir);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
if (hold == 0)
|
||||
break;
|
||||
|
||||
*match = hold;
|
||||
match += 1;
|
||||
}
|
||||
}
|
||||
|
||||
MZ_FREE(current_dir);
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc)
|
||||
{
|
||||
void *stream = NULL;
|
||||
void *crc32_stream = NULL;
|
||||
int32_t read = 0;
|
||||
int32_t err = MZ_OK;
|
||||
uint8_t buf[INT16_MAX];
|
||||
|
||||
mz_stream_os_create(&stream);
|
||||
|
||||
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));
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
err = read;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_encoding_cp437_to_utf8(const char *source, char *target, int32_t max_target)
|
||||
{
|
||||
uint32_t utf8_char = 0;
|
||||
uint8_t utf8_byte = 0;
|
||||
uint8_t cp437_char = 0;
|
||||
int32_t i = 0;
|
||||
int32_t x = 0;
|
||||
int32_t written = 0;
|
||||
|
||||
// Convert ibm codepage 437 encoding to utf-8
|
||||
while (*source != 0)
|
||||
{
|
||||
cp437_char = *source;
|
||||
source += 1;
|
||||
utf8_char = mz_encoding_codepage437_to_utf8[cp437_char];
|
||||
for (x = 0; x < 32; x += 8)
|
||||
{
|
||||
utf8_byte = (uint8_t)(utf8_char >> x);
|
||||
if (x > 0 && utf8_byte == 0)
|
||||
continue;
|
||||
if (max_target <= 1)
|
||||
break;
|
||||
target[written] = utf8_byte;
|
||||
written += 1;
|
||||
max_target -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (max_target > 0)
|
||||
{
|
||||
target[written] = 0;
|
||||
written += 1;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -0,0 +1,78 @@
|
||||
/* mz_os.h -- System functions
|
||||
Version 2.5.2, August 27, 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_OS_H
|
||||
#define MZ_OS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(MZ_WIN32_API)
|
||||
#include "mz_os_posix.h"
|
||||
#include "mz_strm_posix.h"
|
||||
#else
|
||||
#include "mz_os_win32.h"
|
||||
#include "mz_strm_win32.h"
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef HAVE_LZMA
|
||||
#define MZ_VERSION_MADEBY_ZIP_VERSION (63)
|
||||
#elif HAVE_AES
|
||||
#define MZ_VERSION_MADEBY_ZIP_VERSION (51)
|
||||
#elif HAVE_BZIP2
|
||||
#define MZ_VERSION_MADEBY_ZIP_VERSION (46)
|
||||
#else
|
||||
#define MZ_VERSION_MADEBY_ZIP_VERSION (45)
|
||||
#endif
|
||||
|
||||
#define MZ_VERSION_MADEBY ((MZ_VERSION_MADEBY_HOST_SYSTEM << 8) | \
|
||||
(MZ_VERSION_MADEBY_ZIP_VERSION))
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path);
|
||||
// Combines two paths
|
||||
|
||||
int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case);
|
||||
// Compare two paths with wildcard
|
||||
|
||||
int32_t mz_path_resolve(const char *path, char *target, int32_t max_target);
|
||||
// Resolves path
|
||||
|
||||
int32_t mz_path_remove_filename(const char *path);
|
||||
// Remove the filename from a path
|
||||
|
||||
int32_t mz_path_get_filename(const char *path, const char **filename);
|
||||
// Get the filename from a path
|
||||
|
||||
int32_t mz_dir_make(const char *path);
|
||||
// Creates a directory recursively
|
||||
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc);
|
||||
// Gets the crc32 hash of a file
|
||||
|
||||
int32_t mz_encoding_cp437_to_utf8(const char *source, char *target, int32_t max_target);
|
||||
// Converts ibm cp437 encoded string to utf8
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_os_posix.c -- System functions for posix
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -13,16 +13,24 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef HAVE_GETRANDOM
|
||||
# include <sys/random.h>
|
||||
#endif
|
||||
#if defined unix || defined __APPLE__
|
||||
# include <unistd.h>
|
||||
# include <utime.h>
|
||||
# define HAVE_ARC4RANDOM_BUF
|
||||
#endif
|
||||
#if defined unix
|
||||
# include <bsd/stdlib.h>
|
||||
#if defined(HAVE_LIBBSD) && \
|
||||
!defined(MZ_ZIP_NO_COMPRESSION) && \
|
||||
!defined(MZ_ZIP_NO_ENCRYPTION)
|
||||
# include <bsd/stdlib.h> // arc4random_buf
|
||||
#else
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "mz.h"
|
||||
@@ -32,11 +40,87 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(MZ_ZIP_NO_COMPRESSION) && !defined(MZ_ZIP_NO_ENCRYPTION)
|
||||
#if defined(HAVE_ARC4RANDOM_BUF)
|
||||
int32_t mz_posix_rand(uint8_t *buf, int32_t size)
|
||||
{
|
||||
arc4random_buf(buf, size);
|
||||
return size;
|
||||
}
|
||||
#elif defined(HAVE_ARC4RANDOM)
|
||||
int32_t mz_posix_rand(uint8_t *buf, int32_t size)
|
||||
{
|
||||
int32_t left = size;
|
||||
for (; left > 2; left -= 3, buf += 3)
|
||||
{
|
||||
uint32_t val = arc4random();
|
||||
|
||||
buf[0] = (val) & 0xFF;
|
||||
buf[1] = (val >> 8) & 0xFF;
|
||||
buf[2] = (val >> 16) & 0xFF;
|
||||
}
|
||||
for (; left > 0; left--, buf++)
|
||||
{
|
||||
*buf = arc4random() & 0xFF;
|
||||
}
|
||||
return size - left;
|
||||
}
|
||||
#elif defined(HAVE_GETRANDOM)
|
||||
int32_t mz_posix_rand(uint8_t *buf, int32_t size)
|
||||
{
|
||||
int32_t left = size;
|
||||
int32_t written = 0;
|
||||
|
||||
while (left > 0)
|
||||
{
|
||||
written = getrandom(buf, left, 0);
|
||||
if (written < 0)
|
||||
return MZ_INTERNAL_ERROR;
|
||||
|
||||
buf += written;
|
||||
left -= written;
|
||||
}
|
||||
return size - left;
|
||||
}
|
||||
#else
|
||||
#if !defined(FORCE_LOWQUALITY_ENTROPY)
|
||||
# error "Low quality entropy function used for encryption"
|
||||
#endif
|
||||
int32_t mz_posix_rand(uint8_t *buf, int32_t size)
|
||||
{
|
||||
static unsigned calls = 0;
|
||||
int32_t i = 0;
|
||||
|
||||
// Ensure different random header each time
|
||||
if (++calls == 1)
|
||||
{
|
||||
#define PI_SEED 3141592654UL
|
||||
srand((unsigned)(time(NULL) ^ PI_SEED));
|
||||
}
|
||||
|
||||
while (i < size)
|
||||
buf[i++] = (rand() >> 7) & 0xff;
|
||||
|
||||
return size;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int32_t mz_posix_rename(const char *source_path, const char *target_path)
|
||||
{
|
||||
if (rename(source_path, target_path) == -1)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_posix_delete(const char *path)
|
||||
{
|
||||
if (unlink(path) == -1)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_posix_file_exists(const char *path)
|
||||
{
|
||||
@@ -63,13 +147,10 @@ int64_t mz_posix_get_file_size(const char *path)
|
||||
int32_t mz_posix_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date)
|
||||
{
|
||||
struct stat stat_info;
|
||||
struct tm *filedate = NULL;
|
||||
char *name = NULL;
|
||||
size_t len = 0;
|
||||
time_t tm_t = 0;
|
||||
int32_t err = MZ_INTERNAL_ERROR;
|
||||
|
||||
|
||||
memset(&stat_info, 0, sizeof(stat_info));
|
||||
|
||||
if (strcmp(path, "-") != 0)
|
||||
@@ -108,6 +189,7 @@ int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t ac
|
||||
ut.actime = accessed_date;
|
||||
ut.modtime = modified_date;
|
||||
// Creation date not supported
|
||||
(void)creation_date;
|
||||
|
||||
if (utime(path, &ut) != 0)
|
||||
return MZ_INTERNAL_ERROR;
|
||||
@@ -115,6 +197,28 @@ int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t ac
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_posix_get_file_attribs(const char *path, uint32_t *attributes)
|
||||
{
|
||||
struct stat stat_info;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
memset(&stat_info, 0, sizeof(stat_info));
|
||||
if (stat(path, &stat_info) == -1)
|
||||
err = MZ_INTERNAL_ERROR;
|
||||
*attributes = stat_info.st_mode;
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_posix_set_file_attribs(const char *path, uint32_t attributes)
|
||||
{
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (chmod(path, (mode_t)attributes) == -1)
|
||||
err = MZ_INTERNAL_ERROR;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_posix_make_dir(const char *path)
|
||||
{
|
||||
int32_t err = 0;
|
||||
@@ -1,16 +1,16 @@
|
||||
/* mz_os_posix.h -- System functions for posix
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_OS_POSIX_H
|
||||
#define _MZ_OS_POSIX_H
|
||||
#ifndef MZ_OS_POSIX_H
|
||||
#define MZ_OS_POSIX_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
@@ -23,37 +23,45 @@ extern "C" {
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define MZ_VERSION_MADEBY (19)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_OSX_DARWIN)
|
||||
#elif defined(unix)
|
||||
#define MZ_VERSION_MADEBY (3)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_UNIX)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_posix_rand(uint8_t *buf, int32_t size);
|
||||
int32_t mz_posix_rename(const char *source_path, const char *target_path);
|
||||
int32_t mz_posix_delete(const char *path);
|
||||
int32_t mz_posix_file_exists(const char *path);
|
||||
int64_t mz_posix_get_file_size(const char *path);
|
||||
int32_t mz_posix_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
|
||||
int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
|
||||
int32_t mz_posix_get_file_attribs(const char *path, uint32_t *attributes);
|
||||
int32_t mz_posix_set_file_attribs(const char *path, uint32_t attributes);
|
||||
int32_t mz_posix_make_dir(const char *path);
|
||||
DIR* mz_posix_open_dir(const char *path);
|
||||
struct
|
||||
struct
|
||||
dirent* mz_posix_read_dir(DIR *dir);
|
||||
int32_t mz_posix_close_dir(DIR *dir);
|
||||
int32_t mz_posix_is_dir(const char *path);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define mz_os_rand mz_posix_rand
|
||||
#define mz_os_file_exists mz_posix_file_exists
|
||||
#define mz_os_get_file_size mz_posix_get_file_size
|
||||
#define mz_os_get_file_date mz_posix_get_file_date
|
||||
#define mz_os_set_file_date mz_posix_set_file_date
|
||||
#define mz_os_make_dir mz_posix_make_dir
|
||||
#define mz_os_open_dir mz_posix_open_dir
|
||||
#define mz_os_read_dir mz_posix_read_dir
|
||||
#define mz_os_close_dir mz_posix_close_dir
|
||||
#define mz_os_is_dir mz_posix_is_dir
|
||||
#define mz_os_rand mz_posix_rand
|
||||
#define mz_os_rename mz_posix_rename
|
||||
#define mz_os_delete mz_posix_delete
|
||||
#define mz_os_file_exists mz_posix_file_exists
|
||||
#define mz_os_get_file_size mz_posix_get_file_size
|
||||
#define mz_os_get_file_date mz_posix_get_file_date
|
||||
#define mz_os_set_file_date mz_posix_set_file_date
|
||||
#define mz_os_get_file_attribs mz_posix_get_file_attribs
|
||||
#define mz_os_set_file_attribs mz_posix_set_file_attribs
|
||||
#define mz_os_make_dir mz_posix_make_dir
|
||||
#define mz_os_open_dir mz_posix_open_dir
|
||||
#define mz_os_read_dir mz_posix_read_dir
|
||||
#define mz_os_close_dir mz_posix_close_dir
|
||||
#define mz_os_is_dir mz_posix_is_dir
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_os_win32.c -- System functions for Windows
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -17,7 +17,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#if !defined(MZ_ZIP_NO_COMPRESSION) && !defined(MZ_ZIP_NO_ENCRYPTION)
|
||||
# include <wincrypt.h>
|
||||
#endif
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
@@ -26,9 +28,9 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(MZ_USE_WINRT_API)))
|
||||
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(MZ_WINRT_API)))
|
||||
# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
# define MZ_USE_WINRT_API 1
|
||||
# define MZ_WINRT_API 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -43,6 +45,7 @@ typedef struct DIR_int_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(MZ_ZIP_NO_COMPRESSION) && !defined(MZ_ZIP_NO_ENCRYPTION)
|
||||
int32_t mz_win32_rand(uint8_t *buf, int32_t size)
|
||||
{
|
||||
HCRYPTPROV provider;
|
||||
@@ -68,6 +71,7 @@ int32_t mz_win32_rand(uint8_t *buf, int32_t size)
|
||||
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
|
||||
wchar_t *mz_win32_unicode_path_create(const char *path)
|
||||
{
|
||||
@@ -75,7 +79,7 @@ wchar_t *mz_win32_unicode_path_create(const char *path)
|
||||
uint32_t path_wide_size = 0;
|
||||
|
||||
path_wide_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
|
||||
path_wide = (wchar_t *)malloc((path_wide_size + 1) * sizeof(wchar_t));
|
||||
path_wide = (wchar_t *)MZ_ALLOC((path_wide_size + 1) * sizeof(wchar_t));
|
||||
memset(path_wide, 0, sizeof(wchar_t) * (path_wide_size + 1));
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, path_wide, path_wide_size);
|
||||
@@ -87,11 +91,46 @@ void mz_win32_unicode_path_delete(wchar_t **path)
|
||||
{
|
||||
if (path != NULL)
|
||||
{
|
||||
free(*path);
|
||||
MZ_FREE(*path);
|
||||
*path = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mz_win32_rename(const char *source_path, const char *target_path)
|
||||
{
|
||||
wchar_t *source_path_wide = NULL;
|
||||
wchar_t *target_path_wide = NULL;
|
||||
int32_t result = 0;
|
||||
|
||||
|
||||
source_path_wide = mz_win32_unicode_path_create(source_path);
|
||||
target_path_wide = mz_win32_unicode_path_create(target_path);
|
||||
result = MoveFileW(source_path_wide, target_path_wide);
|
||||
mz_win32_unicode_path_delete(&source_path_wide);
|
||||
mz_win32_unicode_path_delete(&target_path_wide);
|
||||
|
||||
if (result == 0)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_win32_delete(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t result = 0;
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_path_create(path);
|
||||
result = DeleteFileW(path_wide);
|
||||
mz_win32_unicode_path_delete(&path_wide);
|
||||
|
||||
if (result == 0)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_win32_file_exists(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
@@ -113,11 +152,10 @@ int64_t mz_win32_get_file_size(const char *path)
|
||||
HANDLE handle = NULL;
|
||||
LARGE_INTEGER large_size;
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_path_create(path);
|
||||
#ifdef MZ_USE_WINRT_API
|
||||
#ifdef MZ_WINRT_API
|
||||
handle = CreateFile2W(path_wide, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#else
|
||||
handle = CreateFileW(path_wide, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
@@ -160,7 +198,7 @@ int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *
|
||||
|
||||
path_wide = mz_win32_unicode_path_create(path);
|
||||
handle = FindFirstFileW(path_wide, &ff32);
|
||||
free(path_wide);
|
||||
MZ_FREE(path_wide);
|
||||
|
||||
if (handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@@ -187,7 +225,7 @@ int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t ac
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_path_create(path);
|
||||
#ifdef MZ_USE_WINRT_API
|
||||
#ifdef MZ_WINRT_API
|
||||
handle = CreateFile2W(path_wide, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
#else
|
||||
handle = CreateFileW(path_wide, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
@@ -214,6 +252,34 @@ int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t ac
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
path_wide = mz_win32_unicode_path_create(path);
|
||||
*attributes = GetFileAttributesW(path_wide);
|
||||
MZ_FREE(path_wide);
|
||||
|
||||
if (*attributes == INVALID_FILE_ATTRIBUTES)
|
||||
err = MZ_INTERNAL_ERROR;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
path_wide = mz_win32_unicode_path_create(path);
|
||||
if (SetFileAttributesW(path_wide, attributes) == 0)
|
||||
err = MZ_INTERNAL_ERROR;
|
||||
MZ_FREE(path_wide);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_make_dir(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
@@ -250,7 +316,7 @@ DIR *mz_win32_open_dir(const char *path)
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return NULL;
|
||||
|
||||
dir_int = (DIR_int *)malloc(sizeof(DIR_int));
|
||||
dir_int = (DIR_int *)MZ_ALLOC(sizeof(DIR_int));
|
||||
dir_int->find_handle = handle;
|
||||
dir_int->end = 0;
|
||||
|
||||
@@ -270,9 +336,9 @@ struct dirent* mz_win32_read_dir(DIR *dir)
|
||||
if (dir_int->end)
|
||||
return NULL;
|
||||
|
||||
WideCharToMultiByte(CP_UTF8, 0, dir_int->find_data.cFileName, -1,
|
||||
WideCharToMultiByte(CP_UTF8, 0, dir_int->find_data.cFileName, -1,
|
||||
dir_int->entry.d_name, sizeof(dir_int->entry.d_name), NULL, NULL);
|
||||
|
||||
|
||||
if (FindNextFileW(dir_int->find_handle, &dir_int->find_data) == 0)
|
||||
{
|
||||
if (GetLastError() != ERROR_NO_MORE_FILES)
|
||||
@@ -280,7 +346,7 @@ struct dirent* mz_win32_read_dir(DIR *dir)
|
||||
|
||||
dir_int->end = 1;
|
||||
}
|
||||
|
||||
|
||||
return &dir_int->entry;
|
||||
}
|
||||
|
||||
@@ -294,14 +360,14 @@ int32_t mz_win32_close_dir(DIR *dir)
|
||||
dir_int = (DIR_int *)dir;
|
||||
if (dir_int->find_handle != INVALID_HANDLE_VALUE)
|
||||
FindClose(dir_int->find_handle);
|
||||
free(dir_int);
|
||||
MZ_FREE(dir_int);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_win32_is_dir(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t attribs = 0;
|
||||
uint32_t attribs = 0;
|
||||
|
||||
path_wide = mz_win32_unicode_path_create(path);
|
||||
attribs = GetFileAttributesW(path_wide);
|
||||
@@ -314,4 +380,4 @@ int32_t mz_win32_is_dir(const char *path)
|
||||
}
|
||||
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
/* mz_os_win32.h -- System functions for Windows
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_OS_WIN32_H
|
||||
#define _MZ_OS_WIN32_H
|
||||
#ifndef MZ_OS_WIN32_H
|
||||
#define MZ_OS_WIN32_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -20,7 +20,7 @@ extern "C" {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_VERSION_MADEBY (10)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_WINDOWS_NTFS)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -32,29 +32,37 @@ typedef void* DIR;
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_win32_rand(uint8_t *buf, int32_t size);
|
||||
int32_t mz_win32_rename(const char *source_path, const char *target_path);
|
||||
int32_t mz_win32_delete(const char *path);
|
||||
int32_t mz_win32_file_exists(const char *path);
|
||||
int64_t mz_win32_get_file_size(const char *path);
|
||||
int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
|
||||
int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
|
||||
int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes);
|
||||
int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes);
|
||||
int32_t mz_win32_make_dir(const char *path);
|
||||
DIR* mz_win32_open_dir(const char *path);
|
||||
struct
|
||||
struct
|
||||
dirent* mz_win32_read_dir(DIR *dir);
|
||||
int32_t mz_win32_close_dir(DIR *dir);
|
||||
int32_t mz_win32_is_dir(const char *path);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define mz_os_rand mz_win32_rand
|
||||
#define mz_os_file_exists mz_win32_file_exists
|
||||
#define mz_os_get_file_size mz_win32_get_file_size
|
||||
#define mz_os_get_file_date mz_win32_get_file_date
|
||||
#define mz_os_set_file_date mz_win32_set_file_date
|
||||
#define mz_os_make_dir mz_win32_make_dir
|
||||
#define mz_os_open_dir mz_win32_open_dir
|
||||
#define mz_os_read_dir mz_win32_read_dir
|
||||
#define mz_os_close_dir mz_win32_close_dir
|
||||
#define mz_os_is_dir mz_win32_is_dir
|
||||
#define mz_os_rand mz_win32_rand
|
||||
#define mz_os_rename mz_win32_rename
|
||||
#define mz_os_delete mz_win32_delete
|
||||
#define mz_os_file_exists mz_win32_file_exists
|
||||
#define mz_os_get_file_size mz_win32_get_file_size
|
||||
#define mz_os_get_file_date mz_win32_get_file_date
|
||||
#define mz_os_set_file_date mz_win32_set_file_date
|
||||
#define mz_os_get_file_attribs mz_win32_get_file_attribs
|
||||
#define mz_os_set_file_attribs mz_win32_set_file_attribs
|
||||
#define mz_os_make_dir mz_win32_make_dir
|
||||
#define mz_os_open_dir mz_win32_open_dir
|
||||
#define mz_os_read_dir mz_win32_read_dir
|
||||
#define mz_os_close_dir mz_win32_close_dir
|
||||
#define mz_os_is_dir mz_win32_is_dir
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
Executable → Regular
+28
-161
@@ -1,8 +1,8 @@
|
||||
/* mz_strm.c -- Stream interface
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -13,8 +13,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
|
||||
@@ -163,6 +161,14 @@ 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)
|
||||
{
|
||||
uint8_t buf[INT16_MAX];
|
||||
@@ -173,7 +179,7 @@ int32_t mz_stream_copy(void *target, void *source, int32_t len)
|
||||
while (len > 0)
|
||||
{
|
||||
bytes_to_copy = len;
|
||||
if (bytes_to_copy > sizeof(buf))
|
||||
if (bytes_to_copy > (int32_t)sizeof(buf))
|
||||
bytes_to_copy = sizeof(buf);
|
||||
read = mz_stream_read(source, buf, bytes_to_copy);
|
||||
if (read < 0)
|
||||
@@ -232,6 +238,14 @@ int32_t mz_stream_set_base(void *stream, void *base)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void* mz_stream_get_interface(void *stream)
|
||||
{
|
||||
mz_stream *strm = (mz_stream *)stream;
|
||||
if (strm == NULL || strm->vtbl == NULL)
|
||||
return NULL;
|
||||
return (void *)strm->vtbl;
|
||||
}
|
||||
|
||||
int32_t mz_stream_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
{
|
||||
mz_stream *strm = (mz_stream *)stream;
|
||||
@@ -270,159 +284,6 @@ void mz_stream_delete(void **stream)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_crc32_s {
|
||||
mz_stream stream;
|
||||
int8_t initialized;
|
||||
int32_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;
|
||||
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_STREAM_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;
|
||||
crc32x->value = crc32x->update(crc32x->value, buf, size);
|
||||
written = mz_stream_write(crc32x->stream.base, buf, size);
|
||||
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);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_get_value(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return 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;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = crc32->total_out;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_set_update_func(void *stream, mz_stream_crc32_update update)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->update = update;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_crc32_create(void **stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = NULL;
|
||||
|
||||
crc32 = (mz_stream_crc32 *)malloc(sizeof(mz_stream_crc32));
|
||||
if (crc32 != NULL)
|
||||
{
|
||||
memset(crc32, 0, sizeof(mz_stream_crc32));
|
||||
crc32->stream.vtbl = &mz_stream_crc32_vtbl;
|
||||
}
|
||||
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)
|
||||
free(crc32);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_crc32_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_crc32_vtbl;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_raw_s {
|
||||
mz_stream stream;
|
||||
int64_t total_in;
|
||||
@@ -434,6 +295,10 @@ typedef struct mz_stream_raw_s {
|
||||
|
||||
int32_t mz_stream_raw_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
MZ_UNUSED(path);
|
||||
MZ_UNUSED(mode);
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@@ -486,6 +351,8 @@ int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin)
|
||||
|
||||
int32_t mz_stream_raw_close(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@@ -524,7 +391,7 @@ int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_raw_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_raw_vtbl = {
|
||||
mz_stream_raw_open,
|
||||
mz_stream_raw_is_open,
|
||||
mz_stream_raw_read,
|
||||
@@ -545,7 +412,7 @@ void *mz_stream_raw_create(void **stream)
|
||||
{
|
||||
mz_stream_raw *raw = NULL;
|
||||
|
||||
raw = (mz_stream_raw *)malloc(sizeof(mz_stream_raw));
|
||||
raw = (mz_stream_raw *)MZ_ALLOC(sizeof(mz_stream_raw));
|
||||
if (raw != NULL)
|
||||
{
|
||||
memset(raw, 0, sizeof(mz_stream_raw));
|
||||
@@ -564,6 +431,6 @@ void mz_stream_raw_delete(void **stream)
|
||||
return;
|
||||
raw = (mz_stream_raw *)*stream;
|
||||
if (raw != NULL)
|
||||
free(raw);
|
||||
MZ_FREE(raw);
|
||||
*stream = NULL;
|
||||
}
|
||||
Executable → Regular
+16
-25
@@ -1,16 +1,16 @@
|
||||
/* mz_strm.h -- Stream interface
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_H
|
||||
#define _MZ_STREAM_H
|
||||
#ifndef MZ_STREAM_H
|
||||
#define MZ_STREAM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -84,6 +84,7 @@ int32_t mz_stream_write_uint8(void *stream, uint8_t value);
|
||||
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_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);
|
||||
int64_t mz_stream_tell(void *stream);
|
||||
int32_t mz_stream_seek(void *stream, int64_t offset, int32_t origin);
|
||||
@@ -91,6 +92,7 @@ int32_t mz_stream_close(void *stream);
|
||||
int32_t mz_stream_error(void *stream);
|
||||
|
||||
int32_t mz_stream_set_base(void *stream, void *base);
|
||||
void* mz_stream_get_interface(void *stream);
|
||||
int32_t mz_stream_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
int32_t mz_stream_set_prop_int64(void *stream, int32_t prop, int64_t value);
|
||||
|
||||
@@ -99,28 +101,17 @@ void mz_stream_delete(void **stream);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef int32_t (*mz_stream_crc32_update)(int32_t value, const void *buf, int32_t size);
|
||||
int32_t mz_stream_raw_open(void *stream, const char *filename, int32_t mode);
|
||||
int32_t mz_stream_raw_is_open(void *stream);
|
||||
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);
|
||||
int64_t mz_stream_raw_tell(void *stream);
|
||||
int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_raw_close(void *stream);
|
||||
int32_t mz_stream_raw_error(void *stream);
|
||||
|
||||
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);
|
||||
|
||||
int32_t mz_stream_crc32_get_value(void *stream);
|
||||
|
||||
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
int32_t mz_stream_crc32_set_update_func(void *stream, mz_stream_crc32_update update);
|
||||
|
||||
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_raw_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value);
|
||||
|
||||
void* mz_stream_raw_create(void **stream);
|
||||
void mz_stream_raw_delete(void **stream);
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_aes.c -- Stream for WinZip AES encryption
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Brian Gladman, Worcester, UK
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_aes_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_aes_vtbl = {
|
||||
mz_stream_aes_open,
|
||||
mz_stream_aes_is_open,
|
||||
mz_stream_aes_read,
|
||||
@@ -49,7 +49,8 @@ mz_stream_vtbl mz_stream_aes_vtbl = {
|
||||
mz_stream_aes_error,
|
||||
mz_stream_aes_create,
|
||||
mz_stream_aes_delete,
|
||||
mz_stream_aes_get_prop_int64
|
||||
mz_stream_aes_get_prop_int64,
|
||||
mz_stream_aes_set_prop_int64
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -61,12 +62,13 @@ typedef struct mz_stream_aes_s {
|
||||
int16_t initialized;
|
||||
uint8_t buffer[INT16_MAX];
|
||||
int64_t total_in;
|
||||
int64_t max_total_in;
|
||||
int64_t total_out;
|
||||
int16_t encryption_mode;
|
||||
const char *password;
|
||||
aes_encrypt_ctx encr_ctx[1];
|
||||
hmac_ctx auth_ctx[1];
|
||||
uint8_t nonce[AES_BLOCK_SIZE];
|
||||
uint8_t nonce[AES_BLOCK_SIZE];
|
||||
uint8_t encr_bfr[AES_BLOCK_SIZE];
|
||||
uint32_t encr_pos;
|
||||
} mz_stream_aes;
|
||||
@@ -84,7 +86,6 @@ int32_t mz_stream_aes_open(void *stream, const char *path, int32_t mode)
|
||||
const char *password = path;
|
||||
int32_t password_length = 0;
|
||||
int32_t key_length = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
aes->total_in = 0;
|
||||
aes->total_out = 0;
|
||||
@@ -107,22 +108,30 @@ int32_t mz_stream_aes_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_os_rand(salt_value, salt_length);
|
||||
#endif
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
if (mz_stream_read(aes->stream.base, salt_value, salt_length) != salt_length)
|
||||
return MZ_STREAM_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
key_length = MZ_AES_KEY_LENGTH(aes->encryption_mode);
|
||||
// Derive the encryption and authentication keys and the password verifier
|
||||
derive_key(password, password_length, salt_value, salt_length,
|
||||
derive_key((const 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
|
||||
aes->encr_pos = AES_BLOCK_SIZE;
|
||||
memset(aes->nonce, 0, AES_BLOCK_SIZE * sizeof(unsigned char));
|
||||
memset(aes->nonce, 0, AES_BLOCK_SIZE * sizeof(uint8_t));
|
||||
|
||||
// Initialize for encryption using key 1
|
||||
aes_encrypt_key(kbuf, key_length, aes->encr_ctx);
|
||||
@@ -155,7 +164,7 @@ int32_t mz_stream_aes_open(void *stream, const char *path, int32_t mode)
|
||||
aes->total_in += MZ_AES_PW_VERIFY_SIZE;
|
||||
|
||||
if (memcmp(verify_expected, verify, MZ_AES_PW_VERIFY_SIZE) != 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_PASSWORD_ERROR;
|
||||
}
|
||||
|
||||
aes->mode = mode;
|
||||
@@ -172,7 +181,7 @@ int32_t mz_stream_aes_is_open(void *stream)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_aes_encrypt_data(void *stream, uint8_t *buf, int32_t size)
|
||||
static int32_t mz_stream_aes_encrypt_data(void *stream, uint8_t *buf, int32_t size)
|
||||
{
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
uint32_t pos = aes->encr_pos;
|
||||
@@ -220,7 +229,7 @@ int32_t mz_stream_aes_write(void *stream, const void *buf, int32_t size)
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
int32_t written = 0;
|
||||
|
||||
if (size > sizeof(aes->buffer))
|
||||
if (size > (int32_t)sizeof(aes->buffer))
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
memcpy(aes->buffer, buf, size);
|
||||
@@ -269,6 +278,7 @@ int32_t mz_stream_aes_close(void *stream)
|
||||
|
||||
aes->total_in += MZ_AES_AUTHCODE_SIZE;
|
||||
|
||||
// If entire entry was not read this will fail
|
||||
if (memcmp(authcode, verify_authcode, MZ_AES_AUTHCODE_SIZE) != 0)
|
||||
return MZ_CRC_ERROR;
|
||||
}
|
||||
@@ -300,27 +310,46 @@ int32_t mz_stream_aes_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = aes->total_in;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = aes->total_out;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
*value = aes->max_total_in;
|
||||
break;
|
||||
case MZ_STREAM_PROP_HEADER_SIZE:
|
||||
*value = MZ_AES_SALT_LENGTH(aes->encryption_mode) + MZ_AES_PW_VERIFY_SIZE;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_FOOTER_SIZE:
|
||||
*value = MZ_AES_AUTHCODE_SIZE;
|
||||
return MZ_OK;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_aes_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
{
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
aes->max_total_in = value;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_aes_create(void **stream)
|
||||
{
|
||||
mz_stream_aes *aes = NULL;
|
||||
|
||||
aes = (mz_stream_aes *)malloc(sizeof(mz_stream_aes));
|
||||
aes = (mz_stream_aes *)MZ_ALLOC(sizeof(mz_stream_aes));
|
||||
if (aes != NULL)
|
||||
{
|
||||
memset(aes, 0, sizeof(mz_stream_aes));
|
||||
@@ -340,7 +369,7 @@ void mz_stream_aes_delete(void **stream)
|
||||
return;
|
||||
aes = (mz_stream_aes *)*stream;
|
||||
if (aes != NULL)
|
||||
free(aes);
|
||||
MZ_FREE(aes);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
/* mz_strm_aes.h -- Stream for WinZIP AES encryption
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_AES_H
|
||||
#define _MZ_STREAM_AES_H
|
||||
#ifndef MZ_STREAM_AES_H
|
||||
#define MZ_STREAM_AES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -33,6 +33,7 @@ void mz_stream_aes_set_password(void *stream, const char *password);
|
||||
void mz_stream_aes_set_encryption_mode(void *stream, int16_t encryption_mode);
|
||||
|
||||
int32_t mz_stream_aes_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
int32_t mz_stream_aes_set_prop_int64(void *stream, int32_t prop, int64_t value);
|
||||
|
||||
void* mz_stream_aes_create(void **stream);
|
||||
void mz_stream_aes_delete(void **stream);
|
||||
Executable → Regular
+57
-50
@@ -1,10 +1,10 @@
|
||||
/* mz_strm_buf.c -- Stream for buffering reads/writes
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This version of ioapi is designed to buffer IO.
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -24,14 +24,14 @@
|
||||
/***************************************************************************/
|
||||
|
||||
#if 0
|
||||
# define mz_stream_buffered_print(o,s,f,...) printf(o,s,f,__VA_ARGS__);
|
||||
# define mz_stream_buffered_print(s,f,...) printf(f,__VA_ARGS__);
|
||||
#else
|
||||
# define mz_stream_buffered_print(o,s,f,...)
|
||||
# define mz_stream_buffered_print(s,f,...)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_buffered_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_buffered_vtbl = {
|
||||
mz_stream_buffered_open,
|
||||
mz_stream_buffered_is_open,
|
||||
mz_stream_buffered_read,
|
||||
@@ -41,7 +41,9 @@ mz_stream_vtbl mz_stream_buffered_vtbl = {
|
||||
mz_stream_buffered_close,
|
||||
mz_stream_buffered_error,
|
||||
mz_stream_buffered_create,
|
||||
mz_stream_buffered_delete
|
||||
mz_stream_buffered_delete,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -64,19 +66,34 @@ typedef struct mz_stream_buffered_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static int32_t mz_stream_buffered_reset(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
|
||||
buffered->readbuf_len = 0;
|
||||
buffered->readbuf_pos = 0;
|
||||
buffered->writebuf_len = 0;
|
||||
buffered->writebuf_pos = 0;
|
||||
buffered->position = 0;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
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(opaque, buffered, "open [mode %d]\n", mode);
|
||||
return mz_stream_open(stream, path, mode);
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
mz_stream_buffered_print(buffered, "open [mode %d]\n", mode);
|
||||
mz_stream_buffered_reset(buffered);
|
||||
return mz_stream_open(buffered->stream.base, path, mode);
|
||||
}
|
||||
|
||||
int32_t mz_stream_buffered_is_open(void *stream)
|
||||
{
|
||||
return mz_stream_is_open(stream);
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
return mz_stream_is_open(buffered->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
|
||||
static int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int32_t total_bytes_written = 0;
|
||||
@@ -88,7 +105,7 @@ int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
|
||||
|
||||
while (bytes_left_to_write > 0)
|
||||
{
|
||||
bytes_written = mz_stream_write(buffered->stream.base,
|
||||
bytes_written = mz_stream_write(buffered->stream.base,
|
||||
buffered->writebuf + (bytes_to_write - bytes_left_to_write), bytes_left_to_write);
|
||||
|
||||
if (bytes_written != bytes_left_to_write)
|
||||
@@ -96,7 +113,7 @@ int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
|
||||
|
||||
buffered->writebuf_misses += 1;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "write flush [%d:%d len %d]\n",
|
||||
mz_stream_buffered_print(stream, "write flush [%d:%d len %d]\n",
|
||||
bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
|
||||
|
||||
total_bytes_written += bytes_written;
|
||||
@@ -120,10 +137,10 @@ 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(opaque, stream, "read [size %ld pos %lld]\n", size, buffered->position);
|
||||
mz_stream_buffered_print(stream, "read [size %ld pos %lld]\n", size, buffered->position);
|
||||
|
||||
if (buffered->writebuf_len > 0)
|
||||
mz_stream_buffered_print(opaque, stream, "switch from write to read, not yet supported [%lld]\n",
|
||||
mz_stream_buffered_print(stream, "switch from write to read, not yet supported [%lld]\n",
|
||||
buffered->position);
|
||||
|
||||
while (bytes_left_to_read > 0)
|
||||
@@ -137,15 +154,15 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
|
||||
}
|
||||
|
||||
bytes_to_read = sizeof(buffered->readbuf) - (buffered->readbuf_len - buffered->readbuf_pos);
|
||||
|
||||
if (mz_stream_read(buffered->stream.base, buffered->readbuf + buffered->readbuf_pos, bytes_to_read) != bytes_to_read)
|
||||
return 0;
|
||||
bytes_read = mz_stream_read(buffered->stream.base, buffered->readbuf + buffered->readbuf_pos, bytes_to_read);
|
||||
if (bytes_read < 0)
|
||||
return bytes_read;
|
||||
|
||||
buffered->readbuf_misses += 1;
|
||||
buffered->readbuf_len += bytes_read;
|
||||
buffered->position += bytes_read;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "filled [read %d/%d buf %d:%d pos %lld]\n",
|
||||
mz_stream_buffered_print(stream, "filled [read %d/%d buf %d:%d pos %lld]\n",
|
||||
bytes_read, bytes_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
|
||||
|
||||
if (bytes_read == 0)
|
||||
@@ -166,7 +183,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(opaque, stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n",
|
||||
mz_stream_buffered_print(stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n",
|
||||
bytes_to_copy, bytes_left_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
|
||||
}
|
||||
}
|
||||
@@ -184,7 +201,7 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
int32_t bytes_flushed = 0;
|
||||
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "write [size %ld len %d pos %lld]\n",
|
||||
mz_stream_buffered_print(stream, "write [size %ld len %d pos %lld]\n",
|
||||
size, buffered->writebuf_len, buffered->position);
|
||||
|
||||
if (buffered->readbuf_len > 0)
|
||||
@@ -195,7 +212,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(opaque, stream, "switch from read to write [%lld]\n", buffered->position);
|
||||
mz_stream_buffered_print(stream, "switch from read to write [%lld]\n", buffered->position);
|
||||
|
||||
if (mz_stream_seek(buffered->stream.base, buffered->position, MZ_SEEK_SET) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
@@ -220,9 +237,9 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
continue;
|
||||
}
|
||||
|
||||
memcpy(buffered->writebuf + buffered->writebuf_pos, (char *)buf + (bytes_to_write - bytes_left_to_write), bytes_to_copy);
|
||||
memcpy(buffered->writebuf + buffered->writebuf_pos, (const char *)buf + (bytes_to_write - bytes_left_to_write), bytes_to_copy);
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "write copy [remaining %d write %d:%d len %d]\n",
|
||||
mz_stream_buffered_print(stream, "write copy [remaining %d write %d:%d len %d]\n",
|
||||
bytes_to_copy, bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
|
||||
|
||||
bytes_left_to_write -= bytes_to_copy;
|
||||
@@ -236,12 +253,14 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
return size - bytes_left_to_write;
|
||||
}
|
||||
|
||||
int64_t mz_stream_buffered_tellinternal(void *stream, uint64_t position)
|
||||
int64_t mz_stream_buffered_tell(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int64_t position = mz_stream_tell(buffered->stream.base);
|
||||
|
||||
buffered->position = position;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "tell [pos %llu readpos %d writepos %d err %d]\n",
|
||||
mz_stream_buffered_print(stream, "tell [pos %llu readpos %d writepos %d err %d]\n",
|
||||
buffered->position, buffered->readbuf_pos, buffered->writebuf_pos, errno);
|
||||
|
||||
if (buffered->readbuf_len > 0)
|
||||
@@ -251,19 +270,12 @@ int64_t mz_stream_buffered_tellinternal(void *stream, uint64_t position)
|
||||
return position;
|
||||
}
|
||||
|
||||
int64_t mz_stream_buffered_tell(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int64_t position = mz_stream_tell(buffered->stream.base);
|
||||
return mz_stream_buffered_tellinternal(stream, position);
|
||||
}
|
||||
|
||||
int mz_stream_buffered_seekinternal(void *stream, int64_t offset, int32_t origin)
|
||||
int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int32_t bytes_flushed = 0;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "seek [origin %d offset %llu pos %lld]\n", origin, offset, buffered->position);
|
||||
mz_stream_buffered_print(stream, "seek [origin %d offset %llu pos %lld]\n", origin, offset, buffered->position);
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
@@ -278,7 +290,7 @@ int mz_stream_buffered_seekinternal(void *stream, int64_t offset, int32_t origin
|
||||
}
|
||||
}
|
||||
|
||||
if ((buffered->readbuf_len > 0) && (offset < buffered->position) &&
|
||||
if ((buffered->readbuf_len > 0) && (offset < buffered->position) &&
|
||||
(offset >= buffered->position - buffered->readbuf_len))
|
||||
{
|
||||
buffered->readbuf_pos = (uint32_t)(offset - (buffered->position - buffered->readbuf_len));
|
||||
@@ -332,14 +344,7 @@ int mz_stream_buffered_seekinternal(void *stream, int64_t offset, int32_t origin
|
||||
buffered->readbuf_pos = 0;
|
||||
buffered->writebuf_len = 0;
|
||||
buffered->writebuf_pos = 0;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
if (mz_stream_buffered_seekinternal(stream, offset, origin) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return mz_stream_seek(buffered->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
@@ -349,30 +354,32 @@ int32_t mz_stream_buffered_close(void *stream)
|
||||
int32_t bytes_flushed = 0;
|
||||
|
||||
mz_stream_buffered_flush(stream, &bytes_flushed);
|
||||
mz_stream_buffered_print(opaque, stream, "close\n");
|
||||
mz_stream_buffered_print(stream, "close [flushed %d]\n", bytes_flushed);
|
||||
|
||||
if (buffered->readbuf_hits + buffered->readbuf_misses > 0)
|
||||
mz_stream_buffered_print(opaque, stream, "read efficency %.02f%%\n",
|
||||
mz_stream_buffered_print(stream, "read efficency %.02f%%\n",
|
||||
(buffered->readbuf_hits / ((float)buffered->readbuf_hits + buffered->readbuf_misses)) * 100);
|
||||
|
||||
if (buffered->writebuf_hits + buffered->writebuf_misses > 0)
|
||||
mz_stream_buffered_print(opaque, stream, "write efficency %.02f%%\n",
|
||||
mz_stream_buffered_print(stream, "write efficency %.02f%%\n",
|
||||
(buffered->writebuf_hits / ((float)buffered->writebuf_hits + buffered->writebuf_misses)) * 100);
|
||||
|
||||
return mz_stream_close(&buffered->stream.base);
|
||||
mz_stream_buffered_reset(buffered);
|
||||
|
||||
return mz_stream_close(buffered->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_buffered_error(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
return mz_stream_error(&buffered->stream.base);
|
||||
return mz_stream_error(buffered->stream.base);
|
||||
}
|
||||
|
||||
void *mz_stream_buffered_create(void **stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = NULL;
|
||||
|
||||
buffered = (mz_stream_buffered *)malloc(sizeof(mz_stream_buffered));
|
||||
buffered = (mz_stream_buffered *)MZ_ALLOC(sizeof(mz_stream_buffered));
|
||||
if (buffered != NULL)
|
||||
{
|
||||
memset(buffered, 0, sizeof(mz_stream_buffered));
|
||||
@@ -391,7 +398,7 @@ void mz_stream_buffered_delete(void **stream)
|
||||
return;
|
||||
buffered = (mz_stream_buffered *)*stream;
|
||||
if (buffered != NULL)
|
||||
free(buffered);
|
||||
MZ_FREE(buffered);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
/* mz_strm_buf.h -- Stream for buffering reads/writes
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This version of ioapi is designed to buffer IO.
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_BUFFERED_H
|
||||
#define _MZ_STREAM_BUFFERED_H
|
||||
#ifndef MZ_STREAM_BUFFERED_H
|
||||
#define MZ_STREAM_BUFFERED_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_bzip.c -- Stream for bzip inflate/deflate
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as bzip.
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_bzip_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_bzip_vtbl = {
|
||||
mz_stream_bzip_open,
|
||||
mz_stream_bzip_is_open,
|
||||
mz_stream_bzip_read,
|
||||
@@ -61,6 +61,7 @@ int32_t mz_stream_bzip_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
|
||||
MZ_UNUSED(path);
|
||||
|
||||
bzip->bzstream.bzalloc = 0;
|
||||
bzip->bzstream.bzfree = 0;
|
||||
@@ -75,17 +76,25 @@ int32_t mz_stream_bzip_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
bzip->bzstream.next_out = (char *)bzip->buffer;
|
||||
bzip->bzstream.avail_out = sizeof(bzip->buffer);
|
||||
|
||||
bzip->error = BZ2_bzCompressInit(&bzip->bzstream, bzip->level, 0, 0);
|
||||
#endif
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
bzip->bzstream.next_in = (char *)bzip->buffer;
|
||||
bzip->bzstream.avail_in = 0;
|
||||
|
||||
bzip->error = BZ2_bzDecompressInit(&bzip->bzstream, 0, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (bzip->error != BZ_OK)
|
||||
@@ -107,6 +116,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
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
uint64_t total_in_before = 0;
|
||||
uint64_t total_out_before = 0;
|
||||
@@ -125,7 +137,7 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
return 0;
|
||||
|
||||
bzip->bzstream.next_out = (char *)buf;
|
||||
bzip->bzstream.avail_out = (uint16_t)size;
|
||||
bzip->bzstream.avail_out = (unsigned int)size;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -134,9 +146,9 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
bytes_to_read = sizeof(bzip->buffer);
|
||||
if (bzip->max_total_in > 0)
|
||||
{
|
||||
if ((bzip->max_total_in - bzip->total_in) < sizeof(bzip->buffer))
|
||||
if ((bzip->max_total_in - bzip->total_in) < (int64_t)sizeof(bzip->buffer))
|
||||
bytes_to_read = (int32_t)(bzip->max_total_in - bzip->total_in);
|
||||
}
|
||||
}
|
||||
|
||||
read = mz_stream_read(bzip->stream.base, bzip->buffer, bytes_to_read);
|
||||
|
||||
@@ -153,13 +165,13 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
}
|
||||
|
||||
total_in_before = bzip->bzstream.avail_in;
|
||||
total_out_before = bzip->bzstream.total_out_lo32 +
|
||||
total_out_before = bzip->bzstream.total_out_lo32 +
|
||||
(((uint64_t)bzip->bzstream.total_out_hi32) << 32);
|
||||
|
||||
err = BZ2_bzDecompress(&bzip->bzstream);
|
||||
|
||||
total_in_after = bzip->bzstream.avail_in;
|
||||
total_out_after = bzip->bzstream.total_out_lo32 +
|
||||
total_out_after = bzip->bzstream.total_out_lo32 +
|
||||
(((uint64_t)bzip->bzstream.total_out_hi32) << 32);
|
||||
|
||||
in_bytes = (uint32_t)(total_in_before - total_in_after);
|
||||
@@ -188,9 +200,10 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
return bzip->error;
|
||||
|
||||
return total_out;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t mz_stream_bzip_flush(void *stream)
|
||||
static int32_t mz_stream_bzip_flush(void *stream)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
if (mz_stream_write(bzip->stream.base, bzip->buffer, bzip->buffer_len) != bzip->buffer_len)
|
||||
@@ -198,7 +211,7 @@ int32_t mz_stream_bzip_flush(void *stream)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
static int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
uint64_t total_out_before = 0;
|
||||
@@ -222,24 +235,26 @@ int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
bzip->buffer_len = 0;
|
||||
}
|
||||
|
||||
total_out_before = bzip->bzstream.total_out_lo32 +
|
||||
total_out_before = bzip->bzstream.total_out_lo32 +
|
||||
(((uint64_t)bzip->bzstream.total_out_hi32) << 32);
|
||||
|
||||
err = BZ2_bzCompress(&bzip->bzstream, flush);
|
||||
|
||||
total_out_after = bzip->bzstream.total_out_lo32 +
|
||||
total_out_after = bzip->bzstream.total_out_lo32 +
|
||||
(((uint64_t)bzip->bzstream.total_out_hi32) << 32);
|
||||
|
||||
out_bytes = (uint32_t)(total_out_after - total_out_before);
|
||||
|
||||
bzip->buffer_len += out_bytes;
|
||||
bzip->total_out += out_bytes;
|
||||
|
||||
if (err == BZ_STREAM_END)
|
||||
break;
|
||||
if (err < 0)
|
||||
{
|
||||
bzip->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
bzip->buffer_len += out_bytes;
|
||||
bzip->total_out += out_bytes;
|
||||
}
|
||||
while ((bzip->bzstream.avail_in > 0) || (flush == BZ_FINISH && err == BZ_FINISH_OK));
|
||||
|
||||
@@ -249,25 +264,35 @@ int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
int32_t mz_stream_bzip_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
int32_t err = size;
|
||||
|
||||
|
||||
bzip->bzstream.next_in = (char *)buf;
|
||||
bzip->bzstream.avail_in = size;
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(bzip);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
bzip->bzstream.next_in = (char *)(intptr_t)buf;
|
||||
bzip->bzstream.avail_in = (unsigned int)size;
|
||||
|
||||
mz_stream_bzip_compress(stream, BZ_RUN);
|
||||
|
||||
bzip->total_in += size;
|
||||
|
||||
return size;
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
int64_t mz_stream_bzip_tell(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_bzip_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
MZ_UNUSED(offset);
|
||||
MZ_UNUSED(origin);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
@@ -277,14 +302,22 @@ int32_t mz_stream_bzip_close(void *stream)
|
||||
|
||||
if (bzip->mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_bzip_compress(stream, BZ_FINISH);
|
||||
mz_stream_bzip_flush(stream);
|
||||
|
||||
BZ2_bzCompressEnd(&bzip->bzstream);
|
||||
#endif
|
||||
}
|
||||
else if (bzip->mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
BZ2_bzDecompressEnd(&bzip->bzstream);
|
||||
#endif
|
||||
}
|
||||
|
||||
bzip->initialized = 0;
|
||||
@@ -307,15 +340,20 @@ int32_t mz_stream_bzip_get_prop_int64(void *stream, int32_t prop, int64_t *value
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = bzip->total_in;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
*value = bzip->max_total_in;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = bzip->total_out;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_HEADER_SIZE:
|
||||
*value = 0;
|
||||
return MZ_OK;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_bzip_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
@@ -340,7 +378,7 @@ void *mz_stream_bzip_create(void **stream)
|
||||
{
|
||||
mz_stream_bzip *bzip = NULL;
|
||||
|
||||
bzip = (mz_stream_bzip *)malloc(sizeof(mz_stream_bzip));
|
||||
bzip = (mz_stream_bzip *)MZ_ALLOC(sizeof(mz_stream_bzip));
|
||||
if (bzip != NULL)
|
||||
{
|
||||
memset(bzip, 0, sizeof(mz_stream_bzip));
|
||||
@@ -360,7 +398,7 @@ void mz_stream_bzip_delete(void **stream)
|
||||
return;
|
||||
bzip = (mz_stream_bzip *)*stream;
|
||||
if (bzip != NULL)
|
||||
free(bzip);
|
||||
MZ_FREE(bzip);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
@@ -371,4 +409,5 @@ void *mz_stream_bzip_get_interface(void)
|
||||
|
||||
extern void bz_internal_error(int errcode)
|
||||
{
|
||||
MZ_UNUSED(errcode);
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
/* mz_strm_bzip.h -- Stream for bzip inflate/deflate
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_BZIP_H
|
||||
#define _MZ_STREAM_BZIP_H
|
||||
#ifndef MZ_STREAM_BZIP_H
|
||||
#define MZ_STREAM_BZIP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -37,6 +37,8 @@ void mz_stream_bzip_delete(void **stream);
|
||||
|
||||
void* mz_stream_bzip_get_interface(void);
|
||||
|
||||
void bz_internal_error(int errcode);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
/* mz_strm_crc32.c -- Stream for CRC32 hashing
|
||||
Version 2.5.2, August 27, 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_STREAM_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;
|
||||
crc32x->value = crc32x->update(crc32x->value, buf, size);
|
||||
written = mz_stream_write(crc32x->stream.base, buf, size);
|
||||
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);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_get_value(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return (int32_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;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/* mz_strm_crc32.h -- Stream for CRC32 hashing
|
||||
Version 2.5.2, August 27, 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);
|
||||
|
||||
int32_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
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_lzma.c -- Stream for lzma inflate/deflate
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as lzma.
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_lzma_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_lzma_vtbl = {
|
||||
mz_stream_lzma_open,
|
||||
mz_stream_lzma_is_open,
|
||||
mz_stream_lzma_read,
|
||||
@@ -55,6 +55,7 @@ typedef struct mz_stream_lzma_s {
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
int64_t max_total_in;
|
||||
int64_t max_total_out;
|
||||
int8_t initialized;
|
||||
uint32_t preset;
|
||||
} mz_stream_lzma;
|
||||
@@ -65,11 +66,15 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
lzma_filter filters[LZMA_FILTERS_MAX + 1];
|
||||
lzma_options_lzma opt_lzma = { 0 };
|
||||
lzma_options_lzma opt_lzma;
|
||||
uint32_t size = 0;
|
||||
uint8_t major = 0;
|
||||
uint8_t minor = 0;
|
||||
|
||||
MZ_UNUSED(path);
|
||||
|
||||
memset(&opt_lzma, 0, sizeof(opt_lzma));
|
||||
|
||||
lzma->lstream.total_in = 0;
|
||||
lzma->lstream.total_out = 0;
|
||||
|
||||
@@ -78,6 +83,10 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(filters);
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma->lstream.next_out = lzma->buffer;
|
||||
lzma->lstream.avail_out = sizeof(lzma->buffer);
|
||||
|
||||
@@ -91,7 +100,7 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
filters[1].id = LZMA_VLI_UNKNOWN;
|
||||
|
||||
lzma_properties_size(&size, (lzma_filter *)&filters);
|
||||
|
||||
|
||||
mz_stream_write_uint8(lzma->stream.base, LZMA_VERSION_MAJOR);
|
||||
mz_stream_write_uint8(lzma->stream.base, LZMA_VERSION_MINOR);
|
||||
mz_stream_write_uint16(lzma->stream.base, (uint16_t)size);
|
||||
@@ -99,9 +108,13 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
lzma->total_out += MZ_LZMA_HEADER_SIZE;
|
||||
|
||||
lzma->error = lzma_alone_encoder(&lzma->lstream, &opt_lzma);
|
||||
#endif
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma->lstream.next_in = lzma->buffer;
|
||||
lzma->lstream.avail_in = 0;
|
||||
|
||||
@@ -112,8 +125,9 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
lzma->total_in += MZ_LZMA_HEADER_SIZE;
|
||||
|
||||
lzma->error = lzma_alone_decoder(&lzma->lstream, UINT64_MAX);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (lzma->error != LZMA_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
@@ -132,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
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
uint64_t total_in_before = 0;
|
||||
uint64_t total_out_before = 0;
|
||||
@@ -147,7 +164,7 @@ int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
|
||||
|
||||
|
||||
lzma->lstream.next_out = (uint8_t*)buf;
|
||||
lzma->lstream.avail_out = (uint16_t)size;
|
||||
lzma->lstream.avail_out = (size_t)size;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -156,10 +173,10 @@ int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
|
||||
bytes_to_read = sizeof(lzma->buffer);
|
||||
if (lzma->max_total_in > 0)
|
||||
{
|
||||
if ((lzma->max_total_in - lzma->total_in) < sizeof(lzma->buffer))
|
||||
if ((lzma->max_total_in - lzma->total_in) < (int64_t)sizeof(lzma->buffer))
|
||||
bytes_to_read = (int32_t)(lzma->max_total_in - lzma->total_in);
|
||||
}
|
||||
|
||||
|
||||
read = mz_stream_read(lzma->stream.base, lzma->buffer, bytes_to_read);
|
||||
|
||||
if (read < 0)
|
||||
@@ -181,7 +198,9 @@ int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
|
||||
|
||||
total_in_after = lzma->lstream.avail_in;
|
||||
total_out_after = lzma->lstream.total_out;
|
||||
|
||||
if ((lzma->max_total_out != -1) && (int64_t)total_out_after > lzma->max_total_out)
|
||||
total_out_after = lzma->max_total_out;
|
||||
|
||||
in_bytes = (uint32_t)(total_in_before - total_in_after);
|
||||
out_bytes = (uint32_t)(total_out_after - total_out_before);
|
||||
|
||||
@@ -205,9 +224,10 @@ int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
|
||||
return lzma->error;
|
||||
|
||||
return total_out;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_flush(void *stream)
|
||||
static int32_t mz_stream_lzma_flush(void *stream)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
if (mz_stream_write(lzma->stream.base, lzma->buffer, lzma->buffer_len) != lzma->buffer_len)
|
||||
@@ -215,7 +235,7 @@ int32_t mz_stream_lzma_flush(void *stream)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
static int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
uint64_t total_out_before = 0;
|
||||
@@ -255,7 +275,7 @@ int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
lzma->buffer_len += out_bytes;
|
||||
lzma->total_out += out_bytes;
|
||||
}
|
||||
while (lzma->lstream.avail_in > 0);
|
||||
while ((lzma->lstream.avail_in > 0) || (flush == LZMA_FINISH && err == LZMA_OK));
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -263,25 +283,35 @@ int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
int32_t mz_stream_lzma_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
int32_t err = size;
|
||||
|
||||
|
||||
lzma->lstream.next_in = (uint8_t*)buf;
|
||||
lzma->lstream.avail_in = size;
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(lzma);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma->lstream.next_in = (uint8_t*)(intptr_t)buf;
|
||||
lzma->lstream.avail_in = (size_t)size;
|
||||
|
||||
mz_stream_lzma_code(stream, LZMA_RUN);
|
||||
|
||||
lzma->total_in += size;
|
||||
|
||||
return size;
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
int64_t mz_stream_lzma_tell(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
MZ_UNUSED(offset);
|
||||
MZ_UNUSED(origin);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
@@ -291,14 +321,22 @@ int32_t mz_stream_lzma_close(void *stream)
|
||||
|
||||
if (lzma->mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_lzma_code(stream, LZMA_FINISH);
|
||||
mz_stream_lzma_flush(stream);
|
||||
|
||||
lzma_end(&lzma->lstream);
|
||||
#endif
|
||||
}
|
||||
else if (lzma->mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma_end(&lzma->lstream);
|
||||
#endif
|
||||
}
|
||||
|
||||
lzma->initialized = 0;
|
||||
@@ -321,15 +359,23 @@ int32_t mz_stream_lzma_get_prop_int64(void *stream, int32_t prop, int64_t *value
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = lzma->total_in;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
*value = lzma->max_total_in;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = lzma->total_out;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT_MAX:
|
||||
*value = lzma->max_total_out;
|
||||
break;
|
||||
case MZ_STREAM_PROP_HEADER_SIZE:
|
||||
*value = MZ_LZMA_HEADER_SIZE;
|
||||
return MZ_OK;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
@@ -342,24 +388,32 @@ int32_t mz_stream_lzma_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
lzma->preset = LZMA_PRESET_EXTREME;
|
||||
else
|
||||
lzma->preset = LZMA_PRESET_DEFAULT;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
lzma->max_total_in = value;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT_MAX:
|
||||
if (value < -1)
|
||||
return MZ_PARAM_ERROR;
|
||||
lzma->max_total_out = value;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_lzma_create(void **stream)
|
||||
{
|
||||
mz_stream_lzma *lzma = NULL;
|
||||
|
||||
lzma = (mz_stream_lzma *)malloc(sizeof(mz_stream_lzma));
|
||||
lzma = (mz_stream_lzma *)MZ_ALLOC(sizeof(mz_stream_lzma));
|
||||
if (lzma != NULL)
|
||||
{
|
||||
memset(lzma, 0, sizeof(mz_stream_lzma));
|
||||
lzma->stream.vtbl = &mz_stream_lzma_vtbl;
|
||||
lzma->preset = LZMA_PRESET_DEFAULT;
|
||||
lzma->max_total_out = -1;
|
||||
}
|
||||
if (stream != NULL)
|
||||
*stream = lzma;
|
||||
@@ -374,7 +428,7 @@ void mz_stream_lzma_delete(void **stream)
|
||||
return;
|
||||
lzma = (mz_stream_lzma *)*stream;
|
||||
if (lzma != NULL)
|
||||
free(lzma);
|
||||
MZ_FREE(lzma);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
@@ -383,12 +437,12 @@ void *mz_stream_lzma_get_interface(void)
|
||||
return (void *)&mz_stream_lzma_vtbl;
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_crc32(int32_t value, const void *buf, int32_t size)
|
||||
static int64_t mz_stream_lzma_crc32(int64_t value, const void *buf, int32_t size)
|
||||
{
|
||||
return lzma_crc32(buf, size, value);
|
||||
return (int32_t)lzma_crc32(buf, size, (int32_t)value);
|
||||
}
|
||||
|
||||
void *mz_stream_lzma_get_crc32_update(void)
|
||||
{
|
||||
return (void *)mz_stream_lzma_crc32;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
/* mz_strm_lzma.h -- Stream for lzma inflate/deflate
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as lzma.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef _MZ_STREAM_LZMA_H
|
||||
#define _MZ_STREAM_LZMA_H
|
||||
#ifndef MZ_STREAM_LZMA_H
|
||||
#define MZ_STREAM_LZMA_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* mz_strm_mem.c -- Stream for memory access
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This interface is designed to access memory rather than files.
|
||||
We do use a region of memory to put data in to and take it out of.
|
||||
We do use a region of memory to put data in to and take it out of.
|
||||
|
||||
Based on Unzip ioapi.c version 0.22, May 19th, 2003
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2003 Justin Fletcher
|
||||
Copyright (C) 1998-2003 Gilles Vollant
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_mem_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_mem_vtbl = {
|
||||
mz_stream_mem_open,
|
||||
mz_stream_mem_is_open,
|
||||
mz_stream_mem_read,
|
||||
@@ -38,7 +38,9 @@ mz_stream_vtbl mz_stream_mem_vtbl = {
|
||||
mz_stream_mem_close,
|
||||
mz_stream_mem_error,
|
||||
mz_stream_mem_create,
|
||||
mz_stream_mem_delete
|
||||
mz_stream_mem_delete,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -46,7 +48,7 @@ mz_stream_vtbl mz_stream_mem_vtbl = {
|
||||
typedef struct mz_stream_mem_s {
|
||||
mz_stream stream;
|
||||
int32_t mode;
|
||||
char *buffer; // Memory buffer pointer
|
||||
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
|
||||
@@ -59,14 +61,14 @@ static void mz_stream_mem_set_size(void *stream, int32_t size)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
int32_t new_size = size;
|
||||
char *new_buf = NULL;
|
||||
uint8_t *new_buf = NULL;
|
||||
|
||||
|
||||
new_buf = (char *)malloc(new_size);
|
||||
new_buf = (uint8_t *)MZ_ALLOC(new_size);
|
||||
if (mem->buffer)
|
||||
{
|
||||
memcpy(new_buf, mem->buffer, mem->size);
|
||||
free(mem->buffer);
|
||||
MZ_FREE(mem->buffer);
|
||||
}
|
||||
|
||||
mem->buffer = new_buf;
|
||||
@@ -77,6 +79,7 @@ int32_t mz_stream_mem_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
|
||||
MZ_UNUSED(path);
|
||||
|
||||
mem->mode = mode;
|
||||
mem->limit = 0;
|
||||
@@ -189,12 +192,16 @@ int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin)
|
||||
|
||||
int32_t mz_stream_mem_close(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
// We never return errors
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_mem_error(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
// We never return errors
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -202,17 +209,17 @@ int32_t mz_stream_mem_error(void *stream)
|
||||
void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
mem->buffer = buf;
|
||||
mem->buffer = (uint8_t *)buf;
|
||||
mem->size = size;
|
||||
mem->limit = size;
|
||||
}
|
||||
|
||||
int32_t mz_stream_mem_get_buffer(void *stream, void **buf)
|
||||
int32_t mz_stream_mem_get_buffer(void *stream, const void **buf)
|
||||
{
|
||||
return mz_stream_mem_get_buffer_at(stream, 0, buf);
|
||||
}
|
||||
|
||||
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, void **buf)
|
||||
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, const void **buf)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
if (buf == NULL || position < 0 || mem->size < position || mem->buffer == NULL)
|
||||
@@ -221,6 +228,24 @@ int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, void **buf)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_mem_get_buffer_at_current(void *stream, const void **buf)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
return mz_stream_mem_get_buffer_at(stream, mem->position, buf);
|
||||
}
|
||||
|
||||
void mz_stream_mem_get_buffer_length(void *stream, int32_t *length)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
*length = mem->limit;
|
||||
}
|
||||
|
||||
void mz_stream_mem_set_buffer_limit(void *stream, int32_t limit)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
mem->limit = limit;
|
||||
}
|
||||
|
||||
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
@@ -231,7 +256,7 @@ void *mz_stream_mem_create(void **stream)
|
||||
{
|
||||
mz_stream_mem *mem = NULL;
|
||||
|
||||
mem = (mz_stream_mem *)malloc(sizeof(mz_stream_mem));
|
||||
mem = (mz_stream_mem *)MZ_ALLOC(sizeof(mz_stream_mem));
|
||||
if (mem != NULL)
|
||||
{
|
||||
memset(mem, 0, sizeof(mz_stream_mem));
|
||||
@@ -253,8 +278,8 @@ void mz_stream_mem_delete(void **stream)
|
||||
if (mem != NULL)
|
||||
{
|
||||
if ((mem->mode & MZ_OPEN_MODE_CREATE) && (mem->buffer != NULL))
|
||||
free(mem->buffer);
|
||||
free(mem);
|
||||
MZ_FREE(mem->buffer);
|
||||
MZ_FREE(mem);
|
||||
}
|
||||
*stream = NULL;
|
||||
}
|
||||
@@ -262,4 +287,4 @@ void mz_stream_mem_delete(void **stream)
|
||||
void *mz_stream_mem_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_mem_vtbl;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,16 @@
|
||||
/* mz_strm_mem.h -- Stream for memory access
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2003 Justin Fletcher
|
||||
Copyright (C) 1998-2003 Gilles Vollant
|
||||
|
||||
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_MEM_H
|
||||
#define _MZ_STREAM_MEM_H
|
||||
#ifndef MZ_STREAM_MEM_H
|
||||
#define MZ_STREAM_MEM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -32,8 +30,11 @@ int32_t mz_stream_mem_close(void *stream);
|
||||
int32_t mz_stream_mem_error(void *stream);
|
||||
|
||||
void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_mem_get_buffer(void *stream, void **buf);
|
||||
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, void **buf);
|
||||
int32_t mz_stream_mem_get_buffer(void *stream, const void **buf);
|
||||
int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, const void **buf);
|
||||
int32_t mz_stream_mem_get_buffer_at_current(void *stream, const void **buf);
|
||||
void mz_stream_mem_get_buffer_length(void *stream, int32_t *length);
|
||||
void mz_stream_mem_set_buffer_limit(void *stream, int32_t limit);
|
||||
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size);
|
||||
|
||||
void* mz_stream_mem_create(void **stream);
|
||||
@@ -0,0 +1,359 @@
|
||||
/* mz_strm_pkcrypt.c -- Code for traditional PKWARE encryption
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Modifications for Info-ZIP crypting
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
Copyright (C) 2003 Terry Thorsen
|
||||
|
||||
This code is a modified version of crypting code in Info-ZIP distribution
|
||||
|
||||
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.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,
|
||||
mz_stream_pkcrypt_read,
|
||||
mz_stream_pkcrypt_write,
|
||||
mz_stream_pkcrypt_tell,
|
||||
mz_stream_pkcrypt_seek,
|
||||
mz_stream_pkcrypt_close,
|
||||
mz_stream_pkcrypt_error,
|
||||
mz_stream_pkcrypt_create,
|
||||
mz_stream_pkcrypt_delete,
|
||||
mz_stream_pkcrypt_get_prop_int64,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_pkcrypt_s {
|
||||
mz_stream stream;
|
||||
int32_t error;
|
||||
int16_t initialized;
|
||||
uint8_t buffer[INT16_MAX];
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
uint32_t keys[3]; // keys defining the pseudo-random sequence
|
||||
uint8_t verify1;
|
||||
uint8_t verify2;
|
||||
const char *password;
|
||||
mz_stream_crc32_update
|
||||
crc32_update;
|
||||
} mz_stream_pkcrypt;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define mz_stream_pkcrypt_decode(strm, c) \
|
||||
(mz_stream_pkcrypt_update_keys(strm, \
|
||||
c ^= mz_stream_pkcrypt_decrypt_byte(strm)))
|
||||
|
||||
#define mz_stream_pkcrypt_encode(strm, c, t) \
|
||||
(t = mz_stream_pkcrypt_decrypt_byte(strm), \
|
||||
mz_stream_pkcrypt_update_keys(strm, c), t^(c))
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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.
|
||||
|
||||
temp = pkcrypt->keys[2] | 2;
|
||||
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
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[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);
|
||||
|
||||
return (uint8_t)c;
|
||||
}
|
||||
|
||||
static void mz_stream_pkcrypt_init_keys(void *stream, const char *password)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
|
||||
pkcrypt->keys[0] = 305419896L;
|
||||
pkcrypt->keys[1] = 591751049L;
|
||||
pkcrypt->keys[2] = 878082192L;
|
||||
|
||||
while (*password != 0)
|
||||
{
|
||||
mz_stream_pkcrypt_update_keys(stream, *password);
|
||||
password += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
uint16_t t = 0;
|
||||
int16_t i = 0;
|
||||
uint8_t verify1 = 0;
|
||||
uint8_t verify2 = 0;
|
||||
uint8_t header[RAND_HEAD_LEN];
|
||||
const char *password = path;
|
||||
|
||||
pkcrypt->total_in = 0;
|
||||
pkcrypt->total_out = 0;
|
||||
pkcrypt->initialized = 0;
|
||||
|
||||
if (mz_stream_is_open(pkcrypt->stream.base) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
if (password == NULL)
|
||||
password = pkcrypt->password;
|
||||
if (password == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
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)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(t);
|
||||
MZ_UNUSED(i);
|
||||
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
// First generate RAND_HEAD_LEN - 2 random bytes.
|
||||
mz_os_rand(header, RAND_HEAD_LEN - 2);
|
||||
|
||||
// Encrypt random header (last two bytes is high word of crc)
|
||||
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
|
||||
header[i] = 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)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
pkcrypt->total_out += RAND_HEAD_LEN;
|
||||
#endif
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
MZ_UNUSED(t);
|
||||
MZ_UNUSED(i);
|
||||
MZ_UNUSED(verify1);
|
||||
MZ_UNUSED(verify2);
|
||||
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
if (mz_stream_read(pkcrypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
|
||||
header[i] = 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.
|
||||
MZ_UNUSED(verify1);
|
||||
if ((verify2 != 0) && (verify2 != pkcrypt->verify2))
|
||||
return MZ_PASSWORD_ERROR;
|
||||
|
||||
pkcrypt->total_in += RAND_HEAD_LEN;
|
||||
#endif
|
||||
}
|
||||
|
||||
pkcrypt->initialized = 1;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_pkcrypt_is_open(void *stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
if (pkcrypt->initialized == 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_pkcrypt_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
uint8_t *buf_ptr = (uint8_t *)buf;
|
||||
int32_t read = 0;
|
||||
int32_t i = 0;
|
||||
|
||||
read = mz_stream_read(pkcrypt->stream.base, buf, size);
|
||||
|
||||
for (i = 0; i < read; i++)
|
||||
buf_ptr[i] = mz_stream_pkcrypt_decode(stream, buf_ptr[i]);
|
||||
|
||||
pkcrypt->total_in += read;
|
||||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_pkcrypt_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
const uint8_t *buf_ptr = (const uint8_t *)buf;
|
||||
int32_t written = 0;
|
||||
int32_t i = 0;
|
||||
uint16_t t = 0;
|
||||
|
||||
if (size > (int32_t)sizeof(pkcrypt->buffer))
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
pkcrypt->buffer[i] = mz_stream_pkcrypt_encode(stream, buf_ptr[i], t);
|
||||
|
||||
written = mz_stream_write(pkcrypt->stream.base, pkcrypt->buffer, size);
|
||||
|
||||
if (written > 0)
|
||||
pkcrypt->total_out += written;
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_pkcrypt_tell(void *stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
return mz_stream_tell(pkcrypt->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_pkcrypt_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
return mz_stream_seek(pkcrypt->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
int32_t mz_stream_pkcrypt_close(void *stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
pkcrypt->initialized = 0;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_pkcrypt_error(void *stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
return pkcrypt->error;
|
||||
}
|
||||
|
||||
void mz_stream_pkcrypt_set_password(void *stream, const char *password)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
pkcrypt->password = password;
|
||||
}
|
||||
|
||||
void mz_stream_pkcrypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
pkcrypt->verify1 = verify1;
|
||||
pkcrypt->verify2 = verify2;
|
||||
}
|
||||
|
||||
void mz_stream_pkcrypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
*verify1 = pkcrypt->verify1;
|
||||
*verify2 = pkcrypt->verify2;
|
||||
}
|
||||
|
||||
int32_t mz_stream_pkcrypt_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = pkcrypt->total_in;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = pkcrypt->total_out;
|
||||
break;
|
||||
case MZ_STREAM_PROP_HEADER_SIZE:
|
||||
*value = RAND_HEAD_LEN;
|
||||
break;
|
||||
case MZ_STREAM_PROP_FOOTER_SIZE:
|
||||
*value = 0;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_pkcrypt_create(void **stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = NULL;
|
||||
|
||||
pkcrypt = (mz_stream_pkcrypt *)MZ_ALLOC(sizeof(mz_stream_pkcrypt));
|
||||
if (pkcrypt != NULL)
|
||||
{
|
||||
memset(pkcrypt, 0, sizeof(mz_stream_pkcrypt));
|
||||
pkcrypt->stream.vtbl = &mz_stream_pkcrypt_vtbl;
|
||||
}
|
||||
|
||||
if (stream != NULL)
|
||||
*stream = pkcrypt;
|
||||
return pkcrypt;
|
||||
}
|
||||
|
||||
void mz_stream_pkcrypt_delete(void **stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = NULL;
|
||||
if (stream == NULL)
|
||||
return;
|
||||
pkcrypt = (mz_stream_pkcrypt *)*stream;
|
||||
if (pkcrypt != NULL)
|
||||
MZ_FREE(pkcrypt);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_pkcrypt_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_pkcrypt_vtbl;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/* mz_strm_pkcrypt.h -- Code for traditional PKWARE encryption
|
||||
Version 2.5.2, August 27, 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_PKCRYPT_H
|
||||
#define MZ_STREAM_PKCRYPT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_pkcrypt_open(void *stream, const char *filename, int32_t mode);
|
||||
int32_t mz_stream_pkcrypt_is_open(void *stream);
|
||||
int32_t mz_stream_pkcrypt_read(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_pkcrypt_write(void *stream, const void *buf, int32_t size);
|
||||
int64_t mz_stream_pkcrypt_tell(void *stream);
|
||||
int32_t mz_stream_pkcrypt_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_pkcrypt_close(void *stream);
|
||||
int32_t mz_stream_pkcrypt_error(void *stream);
|
||||
|
||||
void mz_stream_pkcrypt_set_password(void *stream, const char *password);
|
||||
void mz_stream_pkcrypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2);
|
||||
void mz_stream_pkcrypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2);
|
||||
int32_t mz_stream_pkcrypt_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
|
||||
void* mz_stream_pkcrypt_create(void **stream);
|
||||
void mz_stream_pkcrypt_delete(void **stream);
|
||||
|
||||
void* mz_stream_pkcrypt_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_posix.c -- Stream for filesystem access for posix/linux
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(MZ_USE_FILE32API)
|
||||
#if defined(MZ_FILE32_API)
|
||||
# define fopen64 fopen
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_posix_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_posix_vtbl = {
|
||||
mz_stream_posix_open,
|
||||
mz_stream_posix_is_open,
|
||||
mz_stream_posix_read,
|
||||
@@ -60,7 +60,9 @@ mz_stream_vtbl mz_stream_posix_vtbl = {
|
||||
mz_stream_posix_close,
|
||||
mz_stream_posix_error,
|
||||
mz_stream_posix_create,
|
||||
mz_stream_posix_delete
|
||||
mz_stream_posix_delete,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -85,7 +87,7 @@ int32_t mz_stream_posix_open(void *stream, const char *path, int32_t mode)
|
||||
if ((mode & MZ_OPEN_MODE_READWRITE) == MZ_OPEN_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else if (mode & MZ_OPEN_MODE_APPEND)
|
||||
mode_fopen = "ab";
|
||||
mode_fopen = "r+b";
|
||||
else if (mode & MZ_OPEN_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
else
|
||||
@@ -113,9 +115,9 @@ int32_t mz_stream_posix_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t read = (int32_t)fread(buf, 1, (size_t)size, posix->handle);
|
||||
if (read < 0)
|
||||
if (read < size && ferror(posix->handle))
|
||||
{
|
||||
posix->error = ferror(posix->handle);
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
return read;
|
||||
@@ -125,9 +127,9 @@ int32_t mz_stream_posix_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t written = (int32_t)fwrite(buf, 1, (size_t)size, posix->handle);
|
||||
if (written < 0)
|
||||
if (written < size && ferror(posix->handle))
|
||||
{
|
||||
posix->error = ferror(posix->handle);
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
return written;
|
||||
@@ -139,7 +141,7 @@ int64_t mz_stream_posix_tell(void *stream)
|
||||
int64_t position = ftello64(posix->handle);
|
||||
if (position == -1)
|
||||
{
|
||||
posix->error = ferror(posix->handle);
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
return position;
|
||||
@@ -167,7 +169,7 @@ int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin)
|
||||
|
||||
if (fseeko64(posix->handle, offset, fseek_origin) != 0)
|
||||
{
|
||||
posix->error = ferror(posix->handle);
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
@@ -177,8 +179,12 @@ int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin)
|
||||
int32_t mz_stream_posix_close(void *stream)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t closed = fclose(posix->handle);
|
||||
posix->handle = NULL;
|
||||
int32_t closed = 0;
|
||||
if (posix->handle != NULL)
|
||||
{
|
||||
closed = fclose(posix->handle);
|
||||
posix->handle = NULL;
|
||||
}
|
||||
if (closed != 0)
|
||||
{
|
||||
posix->error = errno;
|
||||
@@ -197,9 +203,12 @@ void *mz_stream_posix_create(void **stream)
|
||||
{
|
||||
mz_stream_posix *posix = NULL;
|
||||
|
||||
posix = (mz_stream_posix *)malloc(sizeof(mz_stream_posix));
|
||||
posix = (mz_stream_posix *)MZ_ALLOC(sizeof(mz_stream_posix));
|
||||
if (posix != NULL)
|
||||
{
|
||||
memset(posix, 0, sizeof(mz_stream_posix));
|
||||
posix->stream.vtbl = &mz_stream_posix_vtbl;
|
||||
}
|
||||
if (stream != NULL)
|
||||
*stream = posix;
|
||||
|
||||
@@ -213,7 +222,7 @@ void mz_stream_posix_delete(void **stream)
|
||||
return;
|
||||
posix = (mz_stream_posix *)*stream;
|
||||
if (posix != NULL)
|
||||
free(posix);
|
||||
MZ_FREE(posix);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
/* mz_strm_posix.h -- Stream for filesystem access for posix/linux
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
http://result42.com
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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_POSIX_H
|
||||
#define _MZ_STREAM_POSIX_H
|
||||
#ifndef MZ_STREAM_POSIX_H
|
||||
#define MZ_STREAM_POSIX_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -41,7 +36,7 @@ void* mz_stream_posix_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(MZ_USE_WIN32_API)
|
||||
#if !defined(_WIN32) && !defined(MZ_WIN32_API)
|
||||
#define mz_stream_os_open mz_stream_posix_open
|
||||
#define mz_stream_os_is_open mz_stream_posix_is_open
|
||||
#define mz_stream_os_read mz_stream_posix_read
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_split.c -- Stream for split files
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -23,9 +23,13 @@
|
||||
|
||||
#define MZ_ZIP_MAGIC_DISKHEADER (0x08074b50)
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_split_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_split_vtbl = {
|
||||
mz_stream_split_open,
|
||||
mz_stream_split_is_open,
|
||||
mz_stream_split_read,
|
||||
@@ -62,14 +66,13 @@ typedef struct mz_stream_split_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
static int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
uint32_t magic = 0;
|
||||
int32_t i = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int16_t disk_part = 0;
|
||||
int16_t read_disk_part = 0;
|
||||
|
||||
|
||||
// Check if we are reading or writing a disk part or the cd disk
|
||||
@@ -84,7 +87,7 @@ int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
// Construct disk path
|
||||
if (disk_part > 0)
|
||||
{
|
||||
for (i = strlen(split->path_disk) - 1; i >= 0; i -= 1)
|
||||
for (i = (int32_t)strlen(split->path_disk) - 1; i >= 0; i -= 1)
|
||||
{
|
||||
if (split->path_disk[i] != '.')
|
||||
continue;
|
||||
@@ -136,7 +139,7 @@ int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_stream_split_close_disk(void *stream)
|
||||
static int32_t mz_stream_split_close_disk(void *stream)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
|
||||
@@ -146,7 +149,7 @@ int32_t mz_stream_split_close_disk(void *stream)
|
||||
return mz_stream_close(split->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_split_goto_disk(void *stream, int32_t number_disk)
|
||||
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;
|
||||
@@ -177,12 +180,12 @@ int32_t mz_stream_split_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
split->mode = mode;
|
||||
|
||||
split->path_cd_size = strlen(path) + 1;
|
||||
split->path_cd = (char *)malloc(split->path_cd_size);
|
||||
split->path_cd_size = (int32_t)strlen(path) + 1;
|
||||
split->path_cd = (char *)MZ_ALLOC(split->path_cd_size);
|
||||
strncpy(split->path_cd, path, split->path_cd_size);
|
||||
|
||||
split->path_disk_size = strlen(path) + 10;
|
||||
split->path_disk = (char *)malloc(split->path_disk_size);
|
||||
split->path_disk_size = (int32_t)strlen(path) + 10;
|
||||
split->path_disk = (char *)MZ_ALLOC(split->path_disk_size);
|
||||
strncpy(split->path_disk, path, split->path_disk_size);
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
@@ -252,7 +255,7 @@ int32_t mz_stream_split_write(void *stream, const void *buf, int32_t size)
|
||||
int32_t bytes_avail = 0;
|
||||
int32_t number_disk = -1;
|
||||
int32_t err = MZ_OK;
|
||||
uint8_t *buf_ptr = (uint8_t *)buf;
|
||||
const uint8_t *buf_ptr = (const uint8_t *)buf;
|
||||
|
||||
while (bytes_left > 0)
|
||||
{
|
||||
@@ -278,11 +281,11 @@ int32_t mz_stream_split_write(void *stream, const void *buf, int32_t size)
|
||||
bytes_to_write = bytes_avail;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
written = mz_stream_write(split->stream.base, buf_ptr, bytes_to_write);
|
||||
if (written != bytes_to_write)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
|
||||
bytes_left -= written;
|
||||
buf_ptr += written;
|
||||
split->total_out += written;
|
||||
@@ -335,15 +338,17 @@ int32_t mz_stream_split_get_prop_int64(void *stream, int32_t prop, int64_t *valu
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = split->total_out;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_DISK_NUMBER:
|
||||
*value = split->number_disk;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_DISK_SIZE:
|
||||
*value = split->disk_size;
|
||||
return MZ_OK;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_split_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
@@ -353,19 +358,21 @@ int32_t mz_stream_split_set_prop_int64(void *stream, int32_t prop, int64_t value
|
||||
{
|
||||
case MZ_STREAM_PROP_DISK_NUMBER:
|
||||
split->number_disk = (int32_t)value;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_DISK_SIZE:
|
||||
split->disk_size = value;
|
||||
return MZ_OK;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_split_create(void **stream)
|
||||
{
|
||||
mz_stream_split *split = NULL;
|
||||
|
||||
split = (mz_stream_split *)malloc(sizeof(mz_stream_split));
|
||||
split = (mz_stream_split *)MZ_ALLOC(sizeof(mz_stream_split));
|
||||
if (split != NULL)
|
||||
{
|
||||
memset(split, 0, sizeof(mz_stream_split));
|
||||
@@ -386,11 +393,11 @@ void mz_stream_split_delete(void **stream)
|
||||
if (split != NULL)
|
||||
{
|
||||
if (split->path_cd)
|
||||
free(split->path_cd);
|
||||
MZ_FREE(split->path_cd);
|
||||
if (split->path_disk)
|
||||
free(split->path_disk);
|
||||
MZ_FREE(split->path_disk);
|
||||
|
||||
free(split);
|
||||
MZ_FREE(split);
|
||||
}
|
||||
*stream = NULL;
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
/* mz_strm_split.h -- Stream for split files
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_SPLIT_H
|
||||
#define _MZ_STREAM_SPLIT_H
|
||||
#ifndef MZ_STREAM_SPLIT_H
|
||||
#define MZ_STREAM_SPLIT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_win32.c -- Stream for filesystem access for windows
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
@@ -32,15 +32,15 @@
|
||||
# define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
||||
#endif
|
||||
|
||||
#if defined(WINAPI_FAMILY_ONE_PARTITION) && !defined(MZ_USE_WINRT_API)
|
||||
#if defined(WINAPI_FAMILY_ONE_PARTITION) && !defined(MZ_WINRT_API)
|
||||
# if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
|
||||
# define MZ_USE_WINRT_API 1
|
||||
# define MZ_WINRT_API 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_win32_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_win32_vtbl = {
|
||||
mz_stream_win32_open,
|
||||
mz_stream_win32_is_open,
|
||||
mz_stream_win32_read,
|
||||
@@ -50,7 +50,9 @@ mz_stream_vtbl mz_stream_win32_vtbl = {
|
||||
mz_stream_win32_close,
|
||||
mz_stream_win32_error,
|
||||
mz_stream_win32_create,
|
||||
mz_stream_win32_delete
|
||||
mz_stream_win32_delete,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -82,7 +84,6 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
desired_access = GENERIC_READ;
|
||||
creation_disposition = OPEN_EXISTING;
|
||||
share_mode &= FILE_SHARE_WRITE;
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_APPEND)
|
||||
{
|
||||
@@ -100,18 +101,18 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
|
||||
}
|
||||
|
||||
path_wide_size = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
|
||||
path_wide = (wchar_t *)malloc((path_wide_size + 1) * sizeof(wchar_t));
|
||||
path_wide = (wchar_t *)MZ_ALLOC((path_wide_size + 1) * sizeof(wchar_t));
|
||||
memset(path_wide, 0, sizeof(wchar_t) * (path_wide_size + 1));
|
||||
|
||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, path_wide, path_wide_size);
|
||||
|
||||
#ifdef MZ_USE_WINRT_API
|
||||
#ifdef MZ_WINRT_API
|
||||
win32->handle = CreateFile2W(path_wide, desired_access, share_mode, creation_disposition, NULL);
|
||||
#else
|
||||
win32->handle = CreateFileW(path_wide, desired_access, share_mode, NULL, creation_disposition, flags_attribs, NULL);
|
||||
#endif
|
||||
|
||||
free(path_wide);
|
||||
MZ_FREE(path_wide);
|
||||
|
||||
if (mz_stream_win32_is_open(stream) != MZ_OK)
|
||||
{
|
||||
@@ -122,7 +123,7 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
|
||||
if (mode & MZ_OPEN_MODE_APPEND)
|
||||
return mz_stream_win32_seek(stream, 0, MZ_SEEK_END);
|
||||
|
||||
return MZ_OK;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_win32_is_open(void *stream)
|
||||
@@ -171,7 +172,7 @@ int32_t mz_stream_win32_write(void *stream, const void *buf, int32_t size)
|
||||
|
||||
static int32_t mz_stream_win32_seekinternal(HANDLE handle, LARGE_INTEGER large_pos, LARGE_INTEGER *new_pos, uint32_t move_method)
|
||||
{
|
||||
#ifdef MZ_USE_WINRT_API
|
||||
#ifdef MZ_WINRT_API
|
||||
return SetFilePointerEx(handle, pos, newPos, dwMoveMethod);
|
||||
#else
|
||||
LONG high_part = large_pos.HighPart;
|
||||
@@ -262,7 +263,7 @@ void *mz_stream_win32_create(void **stream)
|
||||
{
|
||||
mz_stream_win32 *win32 = NULL;
|
||||
|
||||
win32 = (mz_stream_win32 *)malloc(sizeof(mz_stream_win32));
|
||||
win32 = (mz_stream_win32 *)MZ_ALLOC(sizeof(mz_stream_win32));
|
||||
if (win32 != NULL)
|
||||
{
|
||||
memset(win32, 0, sizeof(mz_stream_win32));
|
||||
@@ -281,11 +282,11 @@ void mz_stream_win32_delete(void **stream)
|
||||
return;
|
||||
win32 = (mz_stream_win32 *)*stream;
|
||||
if (win32 != NULL)
|
||||
free(win32);
|
||||
MZ_FREE(win32);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_win32_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_win32_vtbl;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,16 @@
|
||||
/* mz_sstrm_win32.h -- Stream for filesystem access for windows
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
http://result42.com
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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_WIN32_H
|
||||
#define _MZ_STREAM_WIN32_H
|
||||
#ifndef MZ_STREAM_WIN32_H
|
||||
#define MZ_STREAM_WIN32_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -41,7 +36,7 @@ void* mz_stream_win32_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(_WIN32) || defined(MZ_USE_WIN32_API)
|
||||
#if defined(_WIN32) || defined(MZ_WIN32_API)
|
||||
#define mz_stream_os_open mz_stream_win32_open
|
||||
#define mz_stream_os_is_open mz_stream_win32_is_open
|
||||
#define mz_stream_os_read mz_stream_win32_read
|
||||
@@ -1,8 +1,8 @@
|
||||
/* mz_strm_zlib.c -- Stream for zlib inflate/deflate
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
@@ -23,6 +23,15 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
// 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
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
@@ -33,7 +42,7 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_zlib_vtbl = {
|
||||
static mz_stream_vtbl mz_stream_zlib_vtbl = {
|
||||
mz_stream_zlib_open,
|
||||
mz_stream_zlib_is_open,
|
||||
mz_stream_zlib_read,
|
||||
@@ -70,6 +79,7 @@ int32_t mz_stream_zlib_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
|
||||
MZ_UNUSED(path);
|
||||
|
||||
zlib->zstream.data_type = Z_BINARY;
|
||||
zlib->zstream.zalloc = Z_NULL;
|
||||
@@ -83,17 +93,25 @@ int32_t mz_stream_zlib_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
zlib->zstream.next_out = zlib->buffer;
|
||||
zlib->zstream.avail_out = sizeof(zlib->buffer);
|
||||
|
||||
zlib->error = deflateInit2(&zlib->zstream, (int8_t)zlib->level, Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY);
|
||||
#endif
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
zlib->zstream.next_in = zlib->buffer;
|
||||
zlib->zstream.avail_in = 0;
|
||||
|
||||
zlib->error = inflateInit2(&zlib->zstream, -MAX_WBITS);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (zlib->error != Z_OK)
|
||||
@@ -114,6 +132,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
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
uint64_t total_in_before = 0;
|
||||
uint64_t total_in_after = 0;
|
||||
@@ -128,8 +149,8 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
int32_t err = Z_OK;
|
||||
|
||||
|
||||
zlib->zstream.next_out = (uint8_t*)buf;
|
||||
zlib->zstream.avail_out = (uint16_t)size;
|
||||
zlib->zstream.next_out = (Bytef*)buf;
|
||||
zlib->zstream.avail_out = (uInt)size;
|
||||
|
||||
do
|
||||
{
|
||||
@@ -138,7 +159,7 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
bytes_to_read = sizeof(zlib->buffer);
|
||||
if (zlib->max_total_in > 0)
|
||||
{
|
||||
if ((zlib->max_total_in - zlib->total_in) < sizeof(zlib->buffer))
|
||||
if ((zlib->max_total_in - zlib->total_in) < (int64_t)sizeof(zlib->buffer))
|
||||
bytes_to_read = (int32_t)(zlib->max_total_in - zlib->total_in);
|
||||
}
|
||||
|
||||
@@ -180,7 +201,7 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
|
||||
if (err == Z_STREAM_END)
|
||||
break;
|
||||
|
||||
|
||||
if (err != Z_OK)
|
||||
{
|
||||
zlib->error = err;
|
||||
@@ -193,9 +214,10 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
return zlib->error;
|
||||
|
||||
return total_out;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t mz_stream_zlib_flush(void *stream)
|
||||
static int32_t mz_stream_zlib_flush(void *stream)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
if (mz_stream_write(zlib->stream.base, zlib->buffer, zlib->buffer_len) != zlib->buffer_len)
|
||||
@@ -203,7 +225,7 @@ int32_t mz_stream_zlib_flush(void *stream)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
static int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
uint64_t total_out_before = 0;
|
||||
@@ -234,16 +256,18 @@ int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
|
||||
out_bytes = (uint32_t)(total_out_after - total_out_before);
|
||||
|
||||
if (err != Z_OK && err != Z_STREAM_END)
|
||||
zlib->buffer_len += out_bytes;
|
||||
zlib->total_out += out_bytes;
|
||||
|
||||
if (err == Z_STREAM_END)
|
||||
break;
|
||||
if (err != Z_OK)
|
||||
{
|
||||
zlib->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
zlib->buffer_len += out_bytes;
|
||||
zlib->total_out += out_bytes;
|
||||
}
|
||||
while (zlib->zstream.avail_in > 0);
|
||||
while ((zlib->zstream.avail_in > 0) || (flush == Z_FINISH && err == Z_OK));
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -251,25 +275,35 @@ int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
int32_t err = size;
|
||||
|
||||
|
||||
zlib->zstream.next_in = (uint8_t*)buf;
|
||||
zlib->zstream.avail_in = size;
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(zlib);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
zlib->zstream.next_in = (Bytef*)(intptr_t)buf;
|
||||
zlib->zstream.avail_in = (uInt)size;
|
||||
|
||||
mz_stream_zlib_deflate(stream, Z_NO_FLUSH);
|
||||
|
||||
zlib->total_in += size;
|
||||
|
||||
return size;
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
int64_t mz_stream_zlib_tell(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_zlib_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
MZ_UNUSED(offset);
|
||||
MZ_UNUSED(origin);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
@@ -280,14 +314,22 @@ int32_t mz_stream_zlib_close(void *stream)
|
||||
|
||||
if (zlib->mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_zlib_deflate(stream, Z_FINISH);
|
||||
mz_stream_zlib_flush(stream);
|
||||
|
||||
deflateEnd(&zlib->zstream);
|
||||
#endif
|
||||
}
|
||||
else if (zlib->mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
inflateEnd(&zlib->zstream);
|
||||
#endif
|
||||
}
|
||||
|
||||
zlib->initialized = 0;
|
||||
@@ -310,15 +352,20 @@ int32_t mz_stream_zlib_get_prop_int64(void *stream, int32_t prop, int64_t *value
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = zlib->total_in;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
*value = zlib->max_total_in;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = zlib->total_out;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_HEADER_SIZE:
|
||||
*value = 0;
|
||||
return MZ_OK;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_zlib_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
@@ -328,19 +375,21 @@ int32_t mz_stream_zlib_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
{
|
||||
case MZ_STREAM_PROP_COMPRESS_LEVEL:
|
||||
zlib->level = (int16_t)value;
|
||||
return MZ_OK;
|
||||
break;
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
zlib->max_total_in = value;
|
||||
return MZ_OK;
|
||||
break;
|
||||
default:
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_zlib_create(void **stream)
|
||||
{
|
||||
mz_stream_zlib *zlib = NULL;
|
||||
|
||||
zlib = (mz_stream_zlib *)malloc(sizeof(mz_stream_zlib));
|
||||
zlib = (mz_stream_zlib *)MZ_ALLOC(sizeof(mz_stream_zlib));
|
||||
if (zlib != NULL)
|
||||
{
|
||||
memset(zlib, 0, sizeof(mz_stream_zlib));
|
||||
@@ -360,7 +409,7 @@ void mz_stream_zlib_delete(void **stream)
|
||||
return;
|
||||
zlib = (mz_stream_zlib *)*stream;
|
||||
if (zlib != NULL)
|
||||
free(zlib);
|
||||
MZ_FREE(zlib);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
@@ -369,7 +418,12 @@ 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 *)crc32;
|
||||
}
|
||||
return (void *)mz_stream_zlib_crc32;
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
|
||||
Version 2.2.4, November 15th, 2017
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
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_ZLIB_H
|
||||
#define _MZ_STREAM_ZLIB_H
|
||||
#ifndef MZ_STREAM_ZLIB_H
|
||||
#define MZ_STREAM_ZLIB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
Executable → Regular
+714
-246
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,205 @@
|
||||
/* mz_zip.h -- Zip manipulation
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
http://result42.com
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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_ZIP_H
|
||||
#define MZ_ZIP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "mz_strm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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
|
||||
uint64_t compressed_size; // compressed size
|
||||
uint64_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
|
||||
uint64_t disk_offset; // relative offset of local header
|
||||
uint16_t internal_fa; // internal file attributes
|
||||
uint32_t external_fa; // external file attributes
|
||||
uint16_t zip64; // zip64 extension mode
|
||||
|
||||
const char *filename; // filename utf8 null-terminated string
|
||||
const uint8_t *extrafield; // extrafield data
|
||||
const char *comment; // comment utf8 null-terminated string
|
||||
|
||||
#ifdef HAVE_AES
|
||||
uint16_t aes_version; // winzip aes extension if not 0
|
||||
uint8_t aes_encryption_mode; // winzip aes encryption mode
|
||||
#endif
|
||||
} mz_zip_file, mz_zip_entry;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef int32_t (*mz_zip_locate_entry_cb)(void *handle, void *userdata, mz_zip_file *file_info);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void * mz_zip_create(void **handle);
|
||||
// Create zip instance for opening
|
||||
|
||||
void mz_zip_delete(void **handle);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_close(void *handle);
|
||||
// Close the zip file
|
||||
|
||||
int32_t mz_zip_get_comment(void *handle, const char **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
|
||||
|
||||
int32_t mz_zip_get_version_madeby(void *handle, uint16_t *version_madeby);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_get_stream(void *handle, void **stream);
|
||||
// Get a pointer to the stream used to open
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
int32_t mz_zip_entry_read(void *handle, void *buf, int32_t len);
|
||||
// Read bytes from the current file in the zip file
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
int32_t mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size, uint32_t crc32);
|
||||
// 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
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_get_number_entry(void *handle, int64_t *number_entry);
|
||||
// Get the total number of entries
|
||||
|
||||
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
|
||||
|
||||
int64_t mz_zip_get_entry(void *handle);
|
||||
// Return offset of the current entry in the zip file
|
||||
|
||||
int32_t mz_zip_goto_entry(void *handle, uint64_t cd_pos);
|
||||
// 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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_attrib_is_dir(int32_t attrib, int32_t version_madeby);
|
||||
// Checks to see if the attribute is a directory based on platform
|
||||
|
||||
int32_t mz_zip_attrib_convert(uint8_t src_sys, int32_t src_attrib, uint8_t target_sys, int32_t *target_attrib);
|
||||
// Converts file attributes from one host system to another
|
||||
|
||||
int32_t mz_zip_attrib_posix_to_win32(int32_t posix_attrib, int32_t *win32_attrib);
|
||||
// Converts posix file attributes to win32 file attributes
|
||||
|
||||
int32_t mz_zip_attrib_win32_to_posix(int32_t win32_attrib, int32_t *posix_attrib);
|
||||
// Converts win32 file attributes to posix file attributes
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_dosdate_to_tm(uint64_t dos_date, struct tm *ptm);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_time_t_to_tm(time_t unix_time, struct tm *ptm);
|
||||
// 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
|
||||
|
||||
uint32_t mz_zip_tm_to_dosdate(const struct tm *ptm);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_unix_to_ntfs_time(time_t unix_time, uint64_t *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
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ZIP_H */
|
||||
+1391
File diff suppressed because it is too large
Load Diff
+239
@@ -0,0 +1,239 @@
|
||||
/* mz_zip_rw.h -- Zip reader/writer
|
||||
Version 2.5.2, August 27, 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_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);
|
||||
typedef int32_t (*mz_zip_reader_password_cb)(void *handle, void *userdata, mz_zip_file *file_info, char *password, int32_t max_password);
|
||||
typedef int32_t (*mz_zip_reader_progress_cb)(void *handle, void *userdata, mz_zip_file *file_info, uint64_t position);
|
||||
typedef int32_t (*mz_zip_reader_entry_cb)(void *handle, void *userdata, mz_zip_file *file_info, const char *path);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_reader_is_open(void *handle);
|
||||
// Checks to see if the zip file is open
|
||||
|
||||
int32_t mz_zip_reader_open(void *handle, void *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
|
||||
|
||||
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
|
||||
|
||||
int32_t mz_zip_reader_open_buffer(void *handle, uint8_t *buf, int32_t len, uint8_t copy);
|
||||
// Opens zip file from memory buffer
|
||||
|
||||
int32_t mz_zip_reader_close(void *handle);
|
||||
// Closes the zip file
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_reader_goto_first_entry(void *handle);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_reader_locate_entry(void *handle, const char *filename, uint8_t ignore_case);
|
||||
// Locates an entry by filename
|
||||
|
||||
int32_t mz_zip_reader_entry_open(void *handle);
|
||||
// Opens an entry for reading
|
||||
|
||||
int32_t mz_zip_reader_entry_close(void *handle);
|
||||
// Closes an entry
|
||||
|
||||
int32_t mz_zip_reader_entry_read(void *handle, const void *buf, int32_t len);
|
||||
// Reads and entry after being opened
|
||||
|
||||
int32_t mz_zip_reader_entry_get_info(void *handle, mz_zip_file **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
|
||||
|
||||
int32_t mz_zip_reader_entry_save(void *handle, void *stream, mz_stream_write_cb write_cb);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_reader_entry_save_file(void *handle, const char *path);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_reader_entry_save_buffer_length(void *handle);
|
||||
// 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
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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
|
||||
|
||||
void mz_zip_reader_set_password(void *handle, const char *password);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_reader_get_raw(void *handle, uint8_t *raw);
|
||||
// Gets whether or not it should save the entry raw
|
||||
|
||||
void mz_zip_reader_set_legacy_encoding(void *handle, uint8_t legacy_encoding);
|
||||
// Sets whether or not it should support cp437 in zip file names
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
void mz_zip_reader_set_progress_cb(void *handle, void *userdata, mz_zip_reader_progress_cb cb);
|
||||
// Callback for extraction progress
|
||||
|
||||
void mz_zip_reader_set_entry_cb(void *handle, void *userdata, mz_zip_reader_entry_cb cb);
|
||||
// Callback for zip file entries
|
||||
|
||||
int32_t mz_zip_reader_get_zip_handle(void *handle, void **zip_handle);
|
||||
// Gets the underlying zip instance handle
|
||||
|
||||
void* mz_zip_reader_create(void **handle);
|
||||
// Create new instance of zip reader
|
||||
|
||||
void mz_zip_reader_delete(void **handle);
|
||||
// Delete instance of zip reader
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef int32_t (*mz_zip_writer_overwrite_cb)(void *handle, void *userdata, const char *path);
|
||||
typedef int32_t (*mz_zip_writer_password_cb)(void *handle, void *userdata, mz_zip_file *file_info, char *password, int32_t max_password);
|
||||
typedef int32_t (*mz_zip_writer_progress_cb)(void *handle, void *userdata, mz_zip_file *file_info, uint64_t position);
|
||||
typedef int32_t (*mz_zip_writer_entry_cb)(void *handle, void *userdata, mz_zip_file *file_info);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_writer_is_open(void *handle);
|
||||
// Checks to see if the zip file is open
|
||||
|
||||
int32_t mz_zip_writer_open(void *handle, void *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
|
||||
|
||||
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
|
||||
|
||||
int32_t mz_zip_writer_close(void *handle);
|
||||
// Closes the zip file
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info);
|
||||
// Opens an entry in the zip file for writing
|
||||
|
||||
int32_t mz_zip_writer_entry_close(void *handle);
|
||||
// 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
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
int32_t mz_zip_writer_copy_from_reader(void *handle, void *reader);
|
||||
// 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
|
||||
|
||||
void mz_zip_writer_set_raw(void *handle, uint8_t 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
|
||||
|
||||
void mz_zip_writer_set_aes(void *handle, uint8_t aes);
|
||||
// Use aes encryption when adding files in zip
|
||||
|
||||
void mz_zip_writer_set_compress_method(void *handle, int16_t compress_method);
|
||||
// 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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
void mz_zip_writer_set_progress_cb(void *handle, void *userdata, mz_zip_writer_progress_cb cb);
|
||||
// Callback for compression progress
|
||||
|
||||
void mz_zip_writer_set_entry_cb(void *handle, void *userdata, mz_zip_writer_entry_cb cb);
|
||||
// Callback for zip file entries
|
||||
|
||||
int32_t mz_zip_writer_get_zip_handle(void *handle, void **zip_handle);
|
||||
// Gets the underlying zip handle
|
||||
|
||||
void* mz_zip_writer_create(void **handle);
|
||||
// Create new instance of zip writer
|
||||
|
||||
void mz_zip_writer_delete(void **handle);
|
||||
// Delete instance of zip writer
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
-745
@@ -1,745 +0,0 @@
|
||||
/* minizip.c
|
||||
Version 2.2.4, November 15th, 2017
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
http://result42.com
|
||||
Copyright (C) 2007-2008 Even Rouault
|
||||
Modifications of Unzip for Zip64
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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 <inttypes.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_split.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void minizip_banner()
|
||||
{
|
||||
printf("Minizip %s - https://github.com/nmoinvaz/minizip\n", MZ_VERSION);
|
||||
printf("---------------------------------------------------\n");
|
||||
}
|
||||
|
||||
void minizip_help()
|
||||
{
|
||||
printf("Usage : minizip [-x -d dir|-l] [-o] [-a] [-j] [-0 to -9] [-b|-m] [-k 512] [-p pwd] [-s] file.zip [files]\n\n" \
|
||||
" -x Extract files\n" \
|
||||
" -l List files\n" \
|
||||
" -d Destination directory\n" \
|
||||
" -o Overwrite existing files\n" \
|
||||
" -a Append to existing zip file\n" \
|
||||
" -j Exclude path of files\n" \
|
||||
" -0 Store only\n" \
|
||||
" -1 Compress faster\n" \
|
||||
" -9 Compress better\n" \
|
||||
" -k Disk size in KB\n" \
|
||||
" -p Encryption password\n");
|
||||
#ifdef HAVE_AES
|
||||
printf(" -s AES encryption\n");
|
||||
#endif
|
||||
#ifdef HAVE_BZIP2
|
||||
printf(" -b BZIP2 compression\n");
|
||||
#endif
|
||||
#ifdef HAVE_LZMA
|
||||
printf(" -m LZMA compression\n");
|
||||
#endif
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct minizip_opt_s {
|
||||
uint8_t exclude_path;
|
||||
int16_t compress_level;
|
||||
int16_t compress_method;
|
||||
uint8_t overwrite;
|
||||
#ifdef HAVE_AES
|
||||
int16_t aes;
|
||||
#endif
|
||||
} minizip_opt;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_add_file(void *handle, const char *path, const char *password, minizip_opt *options)
|
||||
{
|
||||
mz_zip_file file_info = { 0 };
|
||||
int32_t read = 0;
|
||||
int32_t written = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t err_close = MZ_OK;
|
||||
void *stream = NULL;
|
||||
const char *filenameinzip = NULL;
|
||||
char buf[INT16_MAX];
|
||||
|
||||
|
||||
// Construct the filename that our file will be stored in the zip as.
|
||||
// The path name saved, should not include a leading slash.
|
||||
// If it did, windows/xp and dynazip couldn't read the zip file.
|
||||
|
||||
filenameinzip = path;
|
||||
while (filenameinzip[0] == '\\' || filenameinzip[0] == '/')
|
||||
filenameinzip += 1;
|
||||
|
||||
// Should the file be stored with any path info at all?
|
||||
if (options->exclude_path)
|
||||
{
|
||||
const char *match = NULL;
|
||||
const char *last_slash = NULL;
|
||||
|
||||
for (match = filenameinzip; *match; match += 1)
|
||||
{
|
||||
if (*match == '\\' || *match == '/')
|
||||
last_slash = match;
|
||||
}
|
||||
|
||||
if (last_slash != NULL)
|
||||
filenameinzip = last_slash + 1; // base filename follows last slash
|
||||
}
|
||||
|
||||
// Get information about the file on disk so we can store it in zip
|
||||
printf("Adding: %s\n", filenameinzip);
|
||||
|
||||
file_info.version_madeby = MZ_VERSION_MADEBY;
|
||||
file_info.compression_method = options->compress_method;
|
||||
file_info.filename = (char *)filenameinzip;
|
||||
file_info.uncompressed_size = mz_os_get_file_size(path);
|
||||
|
||||
#ifdef HAVE_AES
|
||||
if (options->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);
|
||||
|
||||
// Add to zip
|
||||
err = mz_zip_entry_write_open(handle, &file_info, options->compress_level, password);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error in opening %s in zip file (%d)\n", filenameinzip, err);
|
||||
return err;
|
||||
}
|
||||
|
||||
mz_stream_os_create(&stream);
|
||||
|
||||
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Read contents of file and write it to zip
|
||||
do
|
||||
{
|
||||
read = mz_stream_os_read(stream, buf, sizeof(buf));
|
||||
if (read < 0)
|
||||
{
|
||||
err = mz_stream_os_error(stream);
|
||||
printf("Error %d in reading %s\n", err, filenameinzip);
|
||||
break;
|
||||
}
|
||||
if (read == 0)
|
||||
break;
|
||||
|
||||
written = mz_zip_entry_write(handle, buf, read);
|
||||
if (written != read)
|
||||
{
|
||||
err = mz_stream_os_error(stream);
|
||||
printf("Error in writing %s in the zip file (%d)\n", filenameinzip, err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (err == MZ_OK);
|
||||
|
||||
mz_stream_os_close(stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error in opening %s for reading\n", path);
|
||||
}
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
|
||||
err_close = mz_zip_entry_close(handle);
|
||||
if (err_close != MZ_OK)
|
||||
{
|
||||
printf("Error in closing %s in the zip file (%d)\n", filenameinzip, err_close);
|
||||
err = err_close;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t minizip_add(void *handle, const char *path, const char *password, minizip_opt *options, uint8_t recursive)
|
||||
{
|
||||
DIR *dir = NULL;
|
||||
struct dirent *entry = NULL;
|
||||
int32_t err = 0;
|
||||
char full_path[320];
|
||||
|
||||
|
||||
if (mz_os_is_dir(path) != MZ_OK)
|
||||
return minizip_add_file(handle, path, password, options);
|
||||
|
||||
dir = mz_os_open_dir(path);
|
||||
|
||||
if (dir == NULL)
|
||||
{
|
||||
printf("Cannot enumerate directory %s\n", path);
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
while ((entry = mz_os_read_dir(dir)) != NULL)
|
||||
{
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
full_path[0] = 0;
|
||||
mz_path_combine(full_path, path, sizeof(full_path));
|
||||
mz_path_combine(full_path, entry->d_name, sizeof(full_path));
|
||||
|
||||
if (!recursive && mz_os_is_dir(full_path))
|
||||
continue;
|
||||
|
||||
err = minizip_add(handle, full_path, password, options, recursive);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
}
|
||||
|
||||
mz_os_close_dir(dir);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_list(void *handle)
|
||||
{
|
||||
mz_zip_file *file_info = NULL;
|
||||
uint32_t ratio = 0;
|
||||
int16_t level = 0;
|
||||
int32_t err = MZ_OK;
|
||||
struct tm tmu_date = { 0 };
|
||||
const char *string_method = NULL;
|
||||
char crypt = ' ';
|
||||
|
||||
|
||||
err = mz_zip_goto_first_entry(handle);
|
||||
|
||||
if (err != MZ_OK && err != MZ_END_OF_LIST)
|
||||
{
|
||||
printf("Error %d going to first entry in zip file\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
|
||||
printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
|
||||
|
||||
while (err == MZ_OK)
|
||||
{
|
||||
err = mz_zip_entry_get_info(handle, &file_info);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d getting entry info in zip file\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
if (file_info->uncompressed_size > 0)
|
||||
ratio = (uint32_t)((file_info->compressed_size * 100) / file_info->uncompressed_size);
|
||||
|
||||
// Display a '*' if the file is encrypted
|
||||
if (file_info->flag & MZ_ZIP_FLAG_ENCRYPTED)
|
||||
crypt = '*';
|
||||
|
||||
switch (file_info->compression_method)
|
||||
{
|
||||
case MZ_COMPRESS_METHOD_RAW:
|
||||
string_method = "Stored";
|
||||
break;
|
||||
case MZ_COMPRESS_METHOD_DEFLATE:
|
||||
level = (int16_t)((file_info->flag & 0x6) / 2);
|
||||
if (level == 0)
|
||||
string_method = "Defl:N";
|
||||
else if (level == 1)
|
||||
string_method = "Defl:X";
|
||||
else if ((level == 2) || (level == 3))
|
||||
string_method = "Defl:F"; // 2: fast , 3: extra fast
|
||||
else
|
||||
string_method = "Defl:?";
|
||||
break;
|
||||
case MZ_COMPRESS_METHOD_BZIP2:
|
||||
string_method = "BZip2";
|
||||
break;
|
||||
case MZ_COMPRESS_METHOD_LZMA:
|
||||
string_method = "LZMA";
|
||||
break;
|
||||
default:
|
||||
string_method = "Unknwn";
|
||||
}
|
||||
|
||||
mz_zip_time_t_to_tm(file_info->modified_date, &tmu_date);
|
||||
|
||||
printf(" %7"PRIu64" %6s%c %7"PRIu64" %3"PRIu32"%% %2.2"PRIu32"-%2.2"PRIu32\
|
||||
"-%2.2"PRIu32" %2.2"PRIu32":%2.2"PRIu32" %8.8"PRIx32" %s\n",
|
||||
file_info->uncompressed_size, string_method, crypt, file_info->compressed_size, ratio,
|
||||
(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,
|
||||
file_info->crc, file_info->filename);
|
||||
|
||||
err = mz_zip_goto_next_entry(handle);
|
||||
|
||||
if (err != MZ_OK && err != MZ_END_OF_LIST)
|
||||
{
|
||||
printf("Error %d going to next entry in zip file\n", err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
if (err == MZ_END_OF_LIST)
|
||||
return MZ_OK;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_extract_currentfile(void *handle, const char *destination, const char *password, minizip_opt *options)
|
||||
{
|
||||
mz_zip_file *file_info = NULL;
|
||||
uint8_t buf[INT16_MAX];
|
||||
int32_t read = 0;
|
||||
int32_t written = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t err_close = MZ_OK;
|
||||
uint8_t skip = 0;
|
||||
void *stream = NULL;
|
||||
char *match = NULL;
|
||||
char *filename = NULL;
|
||||
char out_path[512];
|
||||
char directory[512];
|
||||
|
||||
|
||||
err = mz_zip_entry_get_info(handle, &file_info);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d getting entry info in zip file\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
match = filename = file_info->filename;
|
||||
while (*match != 0)
|
||||
{
|
||||
if ((*match == '/') || (*match == '\\'))
|
||||
filename = match + 1;
|
||||
match += 1;
|
||||
}
|
||||
|
||||
// Construct output path
|
||||
out_path[0] = 0;
|
||||
if (destination != NULL)
|
||||
mz_path_combine(out_path, destination, sizeof(out_path));
|
||||
if (options->exclude_path)
|
||||
mz_path_combine(out_path, filename, sizeof(out_path));
|
||||
else
|
||||
mz_path_combine(out_path, file_info->filename, sizeof(out_path));
|
||||
|
||||
// If zip entry is a directory then create it on disk
|
||||
if (*filename == 0)
|
||||
{
|
||||
if (options->exclude_path == 0)
|
||||
{
|
||||
printf("Creating directory: %s\n", out_path);
|
||||
mz_make_dir(out_path);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mz_zip_entry_read_open(handle, 0, password);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d opening entry in zip file\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Determine if the file should be overwritten or not and ask the user if needed
|
||||
if ((err == MZ_OK) && (options->overwrite == 0) && (mz_os_file_exists(out_path) == MZ_OK))
|
||||
{
|
||||
char rep = 0;
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ", out_path);
|
||||
if (scanf("%1s", answer) != 1)
|
||||
exit(EXIT_FAILURE);
|
||||
rep = answer[0];
|
||||
if ((rep >= 'a') && (rep <= 'z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep != 'Y') && (rep != 'N') && (rep != 'A'));
|
||||
|
||||
if (rep == 'N')
|
||||
skip = 1;
|
||||
if (rep == 'A')
|
||||
options->overwrite = 1;
|
||||
}
|
||||
|
||||
mz_stream_os_create(&stream);
|
||||
|
||||
// Create the file on disk so we can unzip to it
|
||||
if ((skip == 0) && (err == MZ_OK))
|
||||
{
|
||||
// Some zips don't contain directory alone before file
|
||||
if ((mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE) != MZ_OK) &&
|
||||
(options->exclude_path == 0) && (filename != file_info->filename))
|
||||
{
|
||||
// Create the directory of the output path
|
||||
strncpy(directory, out_path, sizeof(directory));
|
||||
match = directory + strlen(directory) - 1;
|
||||
while (match > directory)
|
||||
{
|
||||
if ((*match == '/') || (*match == '\\'))
|
||||
{
|
||||
*match = 0;
|
||||
break;
|
||||
}
|
||||
match -= 1;
|
||||
}
|
||||
|
||||
mz_make_dir(directory);
|
||||
|
||||
mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE);
|
||||
}
|
||||
}
|
||||
|
||||
// Read from the zip, unzip to buffer, and write to disk
|
||||
if (mz_stream_os_is_open(stream) == MZ_OK)
|
||||
{
|
||||
printf(" Extracting: %s\n", out_path);
|
||||
while (1)
|
||||
{
|
||||
read = mz_zip_entry_read(handle, buf, sizeof(buf));
|
||||
if (read < 0)
|
||||
{
|
||||
err = read;
|
||||
printf("Error %d reading entry in zip file\n", err);
|
||||
break;
|
||||
}
|
||||
if (read == 0)
|
||||
break;
|
||||
written = mz_stream_os_write(stream, buf, read);
|
||||
if (written != read)
|
||||
{
|
||||
err = mz_stream_os_error(stream);
|
||||
printf("Error %d in writing extracted file\n", err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mz_stream_os_close(stream);
|
||||
|
||||
// Set the time of the file that has been unzipped
|
||||
if (err == MZ_OK)
|
||||
mz_os_set_file_date(out_path, file_info->modified_date, file_info->accessed_date,
|
||||
file_info->creation_date);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error opening %s\n", out_path);
|
||||
}
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
|
||||
err_close = mz_zip_entry_close(handle);
|
||||
if (err_close != MZ_OK)
|
||||
{
|
||||
printf("Error %d closing entry in zip file\n", err_close);
|
||||
err = err_close;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t minizip_extract_all(void *handle, const char *destination, const char *password, minizip_opt *options)
|
||||
{
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
|
||||
err = mz_zip_goto_first_entry(handle);
|
||||
|
||||
if (err == MZ_END_OF_LIST)
|
||||
return MZ_OK;
|
||||
if (err != MZ_OK)
|
||||
printf("Error %d going to first entry in zip file\n", err);
|
||||
|
||||
while (err == MZ_OK)
|
||||
{
|
||||
err = minizip_extract_currentfile(handle, destination, password, options);
|
||||
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
err = mz_zip_goto_next_entry(handle);
|
||||
|
||||
if (err == MZ_END_OF_LIST)
|
||||
return MZ_OK;
|
||||
if (err != MZ_OK)
|
||||
printf("Error %d going to next entry in zip file\n", err);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t minizip_extract_onefile(void *handle, const char *filename, const char *destination, const char *password, minizip_opt *options)
|
||||
{
|
||||
int32_t err = mz_zip_locate_entry(handle, filename, NULL);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("File %s not found in the zip file\n", filename);
|
||||
return err;
|
||||
}
|
||||
|
||||
return minizip_extract_currentfile(handle, destination, password, options);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifndef NOMAIN
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
void *handle = NULL;
|
||||
void *file_stream = NULL;
|
||||
void *split_stream = NULL;
|
||||
char *path = NULL;
|
||||
char *password = NULL;
|
||||
char *destination = NULL;
|
||||
char *filename_to_extract = NULL;
|
||||
minizip_opt options;
|
||||
int64_t disk_size = 0;
|
||||
int32_t path_arg = 0;
|
||||
uint8_t do_list = 0;
|
||||
uint8_t do_extract = 0;
|
||||
int16_t mode = 0;
|
||||
uint8_t append = 0;
|
||||
int32_t err_close = 0;
|
||||
int32_t err = 0;
|
||||
int32_t i = 0;
|
||||
|
||||
minizip_banner();
|
||||
if (argc == 1)
|
||||
{
|
||||
minizip_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(&options, 0, sizeof(options));
|
||||
|
||||
options.compress_method = MZ_COMPRESS_METHOD_DEFLATE;
|
||||
options.compress_level = MZ_COMPRESS_LEVEL_DEFAULT;
|
||||
|
||||
// Parse command line options
|
||||
for (i = 1; i < argc; i += 1)
|
||||
{
|
||||
if ((*argv[i]) == '-')
|
||||
{
|
||||
const char *p = argv[i] + 1;
|
||||
|
||||
while ((*p) != '\0')
|
||||
{
|
||||
char c = *(p++);
|
||||
if ((c == 'l') || (c == 'L'))
|
||||
do_list = 1;
|
||||
if ((c == 'x') || (c == 'X'))
|
||||
do_extract = 1;
|
||||
if ((c == 'a') || (c == 'A'))
|
||||
append = 1;
|
||||
if ((c == 'o') || (c == 'O'))
|
||||
options.overwrite = 1;
|
||||
if ((c == 'j') || (c == 'J'))
|
||||
options.exclude_path = 1;
|
||||
if ((c >= '0') && (c <= '9'))
|
||||
{
|
||||
options.compress_level = (c - '0');
|
||||
if (options.compress_level == 0)
|
||||
options.compress_method = MZ_COMPRESS_METHOD_RAW;
|
||||
}
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
if ((c == 'b') || (c == 'B'))
|
||||
options.compress_method = MZ_COMPRESS_METHOD_BZIP2;
|
||||
#endif
|
||||
#ifdef HAVE_LZMA
|
||||
if ((c == 'm') || (c == 'M'))
|
||||
options.compress_method = MZ_COMPRESS_METHOD_LZMA;
|
||||
#endif
|
||||
#ifdef HAVE_AES
|
||||
if ((c == 's') || (c == 'S'))
|
||||
options.aes = 1;
|
||||
#endif
|
||||
if (((c == 'k') || (c == 'k')) && (i + 1 < argc))
|
||||
{
|
||||
disk_size = atoi(argv[i + 1]) * 1024;
|
||||
i += 1;
|
||||
}
|
||||
if (((c == 'd') || (c == 'D')) && (i + 1 < argc))
|
||||
{
|
||||
destination = argv[i + 1];
|
||||
i += 1;
|
||||
}
|
||||
if (((c == 'p') || (c == 'P')) && (i + 1 < argc))
|
||||
{
|
||||
password = argv[i + 1];
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (path_arg == 0)
|
||||
path_arg = i;
|
||||
}
|
||||
|
||||
if (path_arg == 0)
|
||||
{
|
||||
minizip_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
path = argv[path_arg];
|
||||
|
||||
mode = MZ_OPEN_MODE_READ;
|
||||
|
||||
if ((do_list == 0) && (do_extract == 0))
|
||||
{
|
||||
mode |= MZ_OPEN_MODE_WRITE;
|
||||
|
||||
if (mz_os_file_exists(path) != MZ_OK)
|
||||
{
|
||||
// If the file doesn't exist, we don't append file
|
||||
mode |= MZ_OPEN_MODE_CREATE;
|
||||
}
|
||||
else if (append == 1)
|
||||
{
|
||||
mode |= MZ_OPEN_MODE_APPEND;
|
||||
}
|
||||
else if (options.overwrite == 0)
|
||||
{
|
||||
// If ask the user what to do because append and overwrite args not set
|
||||
char rep = 0;
|
||||
do
|
||||
{
|
||||
char answer[128];
|
||||
printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ", path);
|
||||
if (scanf("%1s", answer) != 1)
|
||||
exit(EXIT_FAILURE);
|
||||
rep = answer[0];
|
||||
|
||||
if ((rep >= 'a') && (rep <= 'z'))
|
||||
rep -= 0x20;
|
||||
}
|
||||
while ((rep != 'Y') && (rep != 'N') && (rep != 'A'));
|
||||
|
||||
if (rep == 'A')
|
||||
{
|
||||
mode |= MZ_OPEN_MODE_APPEND;
|
||||
}
|
||||
else if (rep == 'Y')
|
||||
{
|
||||
mode |= MZ_OPEN_MODE_CREATE;
|
||||
}
|
||||
else if (rep == 'N')
|
||||
{
|
||||
minizip_help();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mz_stream_os_create(&file_stream);
|
||||
|
||||
mz_stream_split_create(&split_stream);
|
||||
mz_stream_set_base(split_stream, file_stream);
|
||||
mz_stream_split_set_prop_int64(split_stream, MZ_STREAM_PROP_DISK_SIZE, disk_size);
|
||||
|
||||
err = mz_stream_open(split_stream, path, mode);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error opening file %s\n", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
handle = mz_zip_open(split_stream, mode);
|
||||
|
||||
if (handle == NULL)
|
||||
{
|
||||
printf("Error opening zip %s\n", path);
|
||||
err = MZ_FORMAT_ERROR;
|
||||
}
|
||||
|
||||
if (do_list)
|
||||
{
|
||||
err = minizip_list(handle);
|
||||
}
|
||||
else if (do_extract)
|
||||
{
|
||||
// Create target directory if it doesn't exist
|
||||
if (destination != NULL)
|
||||
mz_make_dir(destination);
|
||||
|
||||
if (argc > path_arg + 1)
|
||||
filename_to_extract = argv[path_arg + 1];
|
||||
|
||||
if (filename_to_extract == NULL)
|
||||
err = minizip_extract_all(handle, destination, password, &options);
|
||||
else
|
||||
err = minizip_extract_onefile(handle, filename_to_extract, destination, password, &options);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Creating %s\n", path);
|
||||
|
||||
// Go through command line args looking for files to add to zip
|
||||
for (i = path_arg + 1; (i < argc) && (err == MZ_OK); i += 1)
|
||||
err = minizip_add(handle, argv[i], password, &options, 1);
|
||||
|
||||
mz_zip_set_version_madeby(handle, MZ_VERSION_MADEBY);
|
||||
}
|
||||
|
||||
err_close = mz_zip_close(handle);
|
||||
|
||||
if (err_close != MZ_OK)
|
||||
{
|
||||
printf("Error in closing %s (%d)\n", path, err_close);
|
||||
err = err_close;
|
||||
}
|
||||
|
||||
mz_stream_os_close(file_stream);
|
||||
}
|
||||
|
||||
mz_stream_split_delete(&split_stream);
|
||||
mz_stream_os_delete(&file_stream);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
-574
@@ -1,574 +0,0 @@
|
||||
/* mz_compat.c -- Backwards compatible interface for older versions
|
||||
Version 2.2.4, November 15th, 2017
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_zlib.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
#include "mz_compat.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_compat_s {
|
||||
void *stream;
|
||||
void *handle;
|
||||
} mz_compat;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen(const char *path, int append)
|
||||
{
|
||||
return zipOpen2(path, append, NULL, mz_stream_os_get_interface());
|
||||
}
|
||||
|
||||
extern zipFile ZEXPORT zipOpen64(const void *path, int append)
|
||||
{
|
||||
return zipOpen2(path, append, NULL, mz_stream_os_get_interface());
|
||||
}
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
|
||||
zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
return zipOpen2_64(path, append, globalcomment, pzlib_filefunc_def);
|
||||
}
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
|
||||
zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
mz_compat *compat = NULL;
|
||||
int32_t mode = MZ_OPEN_MODE_READWRITE;
|
||||
int32_t open_existing = 0;
|
||||
void *handle = NULL;
|
||||
void *stream = NULL;
|
||||
|
||||
if (mz_stream_create(&stream, (mz_stream_vtbl *)pzlib_filefunc_def) == NULL)
|
||||
return NULL;
|
||||
|
||||
switch (append)
|
||||
{
|
||||
case APPEND_STATUS_CREATE:
|
||||
mode |= MZ_OPEN_MODE_CREATE;
|
||||
break;
|
||||
case APPEND_STATUS_CREATEAFTER:
|
||||
mode |= MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_APPEND;
|
||||
break;
|
||||
case APPEND_STATUS_ADDINZIP:
|
||||
open_existing = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (mz_stream_open(stream, path, mode) != MZ_OK)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle = mz_zip_open(stream, mode);
|
||||
|
||||
if (handle == NULL)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (globalcomment != NULL)
|
||||
mz_zip_get_comment(handle, globalcomment);
|
||||
|
||||
compat = (mz_compat *)malloc(sizeof(mz_compat));
|
||||
compat->handle = handle;
|
||||
compat->stream = stream;
|
||||
|
||||
return (zipFile)compat;
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
mz_zip_file file_info;
|
||||
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (zipfi != NULL)
|
||||
{
|
||||
file_info.modified_date = mz_zip_dosdate_to_time_t(zipfi->dos_date);
|
||||
file_info.external_fa = zipfi->external_fa;
|
||||
file_info.internal_fa = zipfi->internal_fa;
|
||||
}
|
||||
|
||||
file_info.compression_method = compression_method;
|
||||
file_info.filename = (char *)filename;
|
||||
//file_info.extrafield_local = extrafield_local;
|
||||
//file_info.extrafield_local_size = size_extrafield_local;
|
||||
file_info.extrafield = (uint8_t *)extrafield_global;
|
||||
file_info.extrafield_size = size_extrafield_global;
|
||||
file_info.version_madeby = version_madeby;
|
||||
file_info.comment = (char *)comment;
|
||||
file_info.flag = flag_base;
|
||||
#ifdef HAVE_AES
|
||||
file_info.aes_version = MZ_AES_VERSION;
|
||||
#endif
|
||||
|
||||
return mz_zip_entry_write_open(compat->handle, &file_info, (int16_t)level, password);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64)
|
||||
{
|
||||
return zipOpenNewFileInZip5(file, filename, zipfi, extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
|
||||
memLevel, strategy, password, crc_for_crypting, version_madeby, flag_base, zip64);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base)
|
||||
{
|
||||
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
|
||||
memLevel, strategy, password, crc_for_crypting, version_madeby, flag_base, 0);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting)
|
||||
{
|
||||
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
|
||||
memLevel, strategy, password, crc_for_crypting, MZ_VERSION_MADEBY, 0, 0);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
ZIP_UNUSED uint32_t crc_for_crypting, int zip64)
|
||||
{
|
||||
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
|
||||
extrafield_global, size_extrafield_global, comment, compression_method, level, raw, windowBits,
|
||||
memLevel, strategy, password, crc_for_crypting, MZ_VERSION_MADEBY, 0, zip64);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_zip_entry_write(compat->handle, buf, len);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_zip_entry_close_raw(compat->handle, uncompressed_size, crc32);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip(zipFile file)
|
||||
{
|
||||
return zipCloseFileInZipRaw(file, 0, 0);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip64(zipFile file)
|
||||
{
|
||||
return zipCloseFileInZipRaw(file, 0, 0);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
|
||||
{
|
||||
return zipClose_64(file, global_comment);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipClose_64(zipFile file, const char *global_comment)
|
||||
{
|
||||
return zipClose2_64(file, global_comment, MZ_VERSION_MADEBY);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (global_comment != NULL)
|
||||
mz_zip_set_comment(compat->handle, global_comment);
|
||||
|
||||
mz_zip_set_version_madeby(compat->handle, version_madeby);
|
||||
err = mz_zip_close(compat->handle);
|
||||
|
||||
if (compat->stream != NULL)
|
||||
{
|
||||
mz_stream_close(compat->stream);
|
||||
mz_stream_delete(&compat->stream);
|
||||
}
|
||||
|
||||
free(compat);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen(const char *path)
|
||||
{
|
||||
return unzOpen64(path);
|
||||
}
|
||||
|
||||
extern unzFile ZEXPORT unzOpen64(const void *path)
|
||||
{
|
||||
return unzOpen2(path, mz_stream_os_get_interface());
|
||||
}
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
return unzOpen2_64(path, pzlib_filefunc_def);
|
||||
}
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
mz_compat *compat = NULL;
|
||||
int32_t mode = MZ_OPEN_MODE_READ;
|
||||
void *handle = NULL;
|
||||
void *stream = NULL;
|
||||
|
||||
if (mz_stream_create(&stream, (mz_stream_vtbl *)pzlib_filefunc_def) == NULL)
|
||||
return NULL;
|
||||
|
||||
if (mz_stream_open(stream, path, mode) != MZ_OK)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle = mz_zip_open(stream, mode);
|
||||
|
||||
if (handle == NULL)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
compat = (mz_compat *)malloc(sizeof(mz_compat));
|
||||
compat->handle = handle;
|
||||
compat->stream = stream;
|
||||
|
||||
return (unzFile)compat;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzClose(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
err = mz_zip_close(compat->handle);
|
||||
|
||||
if (compat->stream != NULL)
|
||||
mz_stream_delete(&compat->stream);
|
||||
|
||||
free(compat);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
unz_global_info64 global_info64;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
err = unzGetGlobalInfo64(file, &global_info64);
|
||||
if (err != UNZ_OK)
|
||||
{
|
||||
pglobal_info32->number_entry = (uint32_t)global_info64.number_entry;
|
||||
pglobal_info32->size_comment = global_info64.size_comment;
|
||||
pglobal_info32->number_disk_with_CD = global_info64.number_disk_with_CD;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
const char *comment_ptr = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
err = mz_zip_get_comment(compat->handle, &comment_ptr);
|
||||
if (err == MZ_OK)
|
||||
pglobal_info->size_comment = (uint16_t)strlen(comment_ptr);
|
||||
mz_zip_get_number_entry(compat->handle, (int64_t *)&pglobal_info->number_entry);
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
const char *comment_ptr = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (comment == NULL || comment_size == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
err = mz_zip_get_comment(compat->handle, &comment_ptr);
|
||||
if (err == MZ_OK)
|
||||
strncpy(comment, comment_ptr, comment_size);
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (method != NULL)
|
||||
*method = 0;
|
||||
if (level != NULL)
|
||||
*level = 0;
|
||||
return mz_zip_entry_read_open(compat->handle, (int16_t)raw, password);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile(unzFile file)
|
||||
{
|
||||
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
|
||||
{
|
||||
return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw)
|
||||
{
|
||||
return unzOpenCurrentFile3(file, method, level, raw, NULL);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_zip_entry_read(compat->handle, buf, len);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_zip_entry_close(compat->handle);
|
||||
}
|
||||
|
||||
extern 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)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
mz_zip_file *file_info = NULL;
|
||||
int16_t bytes_to_copy = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
err = mz_zip_entry_get_info(compat->handle, &file_info);
|
||||
|
||||
if ((err == MZ_OK) && (pfile_info != NULL))
|
||||
{
|
||||
pfile_info->version = file_info->version_madeby;
|
||||
pfile_info->version_needed = file_info->version_needed;
|
||||
pfile_info->flag = file_info->flag;
|
||||
pfile_info->compression_method = file_info->compression_method;
|
||||
pfile_info->dos_date = mz_zip_time_t_to_dos_date(file_info->modified_date);
|
||||
pfile_info->crc = file_info->crc;
|
||||
|
||||
pfile_info->size_filename = file_info->filename_size;
|
||||
pfile_info->size_file_extra = file_info->extrafield_size;
|
||||
pfile_info->size_file_comment = file_info->comment_size;
|
||||
|
||||
pfile_info->disk_num_start = (uint16_t)file_info->disk_number;
|
||||
pfile_info->internal_fa = file_info->internal_fa;
|
||||
pfile_info->external_fa = file_info->external_fa;
|
||||
|
||||
pfile_info->compressed_size = (uint32_t)file_info->compressed_size;
|
||||
pfile_info->uncompressed_size = (uint32_t)file_info->uncompressed_size;
|
||||
|
||||
if (filename_size > 0 && filename != NULL)
|
||||
{
|
||||
bytes_to_copy = filename_size;
|
||||
if (bytes_to_copy > file_info->filename_size)
|
||||
bytes_to_copy = file_info->filename_size;
|
||||
memcpy(filename, file_info->filename, bytes_to_copy);
|
||||
}
|
||||
if (extrafield_size > 0 && extrafield != NULL)
|
||||
{
|
||||
bytes_to_copy = extrafield_size;
|
||||
if (bytes_to_copy > file_info->extrafield_size)
|
||||
bytes_to_copy = file_info->extrafield_size;
|
||||
memcpy(extrafield, file_info->extrafield, bytes_to_copy);
|
||||
}
|
||||
if (comment_size > 0 && comment != NULL)
|
||||
{
|
||||
bytes_to_copy = comment_size;
|
||||
if (bytes_to_copy > file_info->comment_size)
|
||||
bytes_to_copy = file_info->comment_size;
|
||||
memcpy(comment, file_info->comment, bytes_to_copy);
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
extern 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)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
mz_zip_file *file_info = NULL;
|
||||
int16_t bytes_to_copy = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
err = mz_zip_entry_get_info(compat->handle, &file_info);
|
||||
|
||||
if ((err == MZ_OK) && (pfile_info != NULL))
|
||||
{
|
||||
pfile_info->version = file_info->version_madeby;
|
||||
pfile_info->version_needed = file_info->version_needed;
|
||||
pfile_info->flag = file_info->flag;
|
||||
pfile_info->compression_method = file_info->compression_method;
|
||||
pfile_info->dos_date = mz_zip_time_t_to_dos_date(file_info->modified_date);
|
||||
pfile_info->crc = file_info->crc;
|
||||
|
||||
pfile_info->size_filename = file_info->filename_size;
|
||||
pfile_info->size_file_extra = file_info->extrafield_size;
|
||||
pfile_info->size_file_comment = file_info->comment_size;
|
||||
|
||||
pfile_info->disk_num_start = file_info->disk_number;
|
||||
pfile_info->internal_fa = file_info->internal_fa;
|
||||
pfile_info->external_fa = file_info->external_fa;
|
||||
|
||||
pfile_info->compressed_size = file_info->compressed_size;
|
||||
pfile_info->uncompressed_size = file_info->uncompressed_size;
|
||||
|
||||
if (filename_size > 0 && filename != NULL)
|
||||
{
|
||||
bytes_to_copy = filename_size;
|
||||
if (bytes_to_copy > file_info->filename_size)
|
||||
bytes_to_copy = file_info->filename_size;
|
||||
memcpy(filename, file_info->filename, bytes_to_copy);
|
||||
}
|
||||
if (extrafield_size > 0 && extrafield != NULL)
|
||||
{
|
||||
bytes_to_copy = extrafield_size;
|
||||
if (bytes_to_copy > file_info->extrafield_size)
|
||||
bytes_to_copy = file_info->extrafield_size;
|
||||
memcpy(extrafield, file_info->extrafield, bytes_to_copy);
|
||||
}
|
||||
if (comment_size > 0 && comment != NULL)
|
||||
{
|
||||
bytes_to_copy = comment_size;
|
||||
if (bytes_to_copy > file_info->comment_size)
|
||||
bytes_to_copy = file_info->comment_size;
|
||||
memcpy(comment, file_info->comment, bytes_to_copy);
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_zip_goto_first_entry(compat->handle);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_zip_goto_next_entry(compat->handle);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_zip_locate_entry(compat->handle, filename, filename_compare_func);
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
// 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();
|
||||
}
|
||||
|
||||
-152
@@ -1,152 +0,0 @@
|
||||
/* mz_os.c -- System functions
|
||||
Version 2.2.4, November 15th, 2017
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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_os.h"
|
||||
#include "mz_strm.h"
|
||||
#ifdef HAVE_LZMA
|
||||
# include "mz_strm_lzma.h"
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
# include "mz_strm_zlib.h"
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_make_dir(const char *path)
|
||||
{
|
||||
int32_t err = MZ_OK;
|
||||
int16_t len = 0;
|
||||
char *current_dir = NULL;
|
||||
char *match = NULL;
|
||||
char hold = 0;
|
||||
|
||||
|
||||
len = (int16_t)strlen(path);
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
current_dir = (char *)malloc(len + 1);
|
||||
if (current_dir == NULL)
|
||||
return MZ_MEM_ERROR;
|
||||
|
||||
strcpy(current_dir, path);
|
||||
|
||||
if (current_dir[len - 1] == '/')
|
||||
current_dir[len - 1] = 0;
|
||||
|
||||
err = mz_os_make_dir(current_dir);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
match = current_dir + 1;
|
||||
while (1)
|
||||
{
|
||||
while (*match != 0 && *match != '\\' && *match != '/')
|
||||
match += 1;
|
||||
hold = *match;
|
||||
*match = 0;
|
||||
|
||||
err = mz_os_make_dir(current_dir);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
if (hold == 0)
|
||||
break;
|
||||
|
||||
*match = hold;
|
||||
match += 1;
|
||||
}
|
||||
}
|
||||
|
||||
free(current_dir);
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path)
|
||||
{
|
||||
int32_t path_len = 0;
|
||||
|
||||
if (path == NULL || join == NULL || max_path == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
path_len = strlen(path);
|
||||
|
||||
if (path_len == 0)
|
||||
{
|
||||
strncpy(path, join, max_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (path[path_len - 1] != '\\' && path[path_len - 1] != '/')
|
||||
strncat(path, "/", max_path - path_len - 1);
|
||||
strncat(path, join, max_path - path_len);
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_get_file_crc(const char *path, uint32_t *result_crc)
|
||||
{
|
||||
void *stream = NULL;
|
||||
void *crc32_stream = NULL;
|
||||
int32_t read = 0;
|
||||
int32_t err = MZ_OK;
|
||||
uint8_t buf[INT16_MAX];
|
||||
|
||||
mz_stream_os_create(&stream);
|
||||
|
||||
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
|
||||
|
||||
mz_stream_crc32_create(&crc32_stream);
|
||||
#ifdef HAVE_ZLIB
|
||||
mz_stream_crc32_set_update_func(crc32_stream,
|
||||
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update());
|
||||
#elif defined(HAVE_LZMA)
|
||||
mz_stream_crc32_set_update_func(crc32_stream,
|
||||
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update());
|
||||
#else
|
||||
#error ZLIB or LZMA required for CRC32
|
||||
#endif
|
||||
|
||||
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));
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
err = read;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
|
||||
return err;
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/* mz_os.h -- System functions
|
||||
Version 2.2.4, November 15th, 2017
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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_OS_H
|
||||
#define _MZ_OS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(MZ_USE_WIN32_API)
|
||||
#include "mz_os_posix.h"
|
||||
#include "mz_strm_posix.h"
|
||||
#else
|
||||
#include "mz_os_win32.h"
|
||||
#include "mz_strm_win32.h"
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_make_dir(const char *path);
|
||||
// Creates a directory recursively
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path);
|
||||
// Combines two paths
|
||||
|
||||
int32_t mz_get_file_crc(const char *path, uint32_t *result_crc);
|
||||
// Gets the crc32 hash of a file
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,319 +0,0 @@
|
||||
/* mz_strm_crypt.c -- Code for traditional PKWARE encryption
|
||||
Version 2.2.4, November 15th, 2017
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Modifications for Info-ZIP crypting
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
Copyright (C) 2003 Terry Thorsen
|
||||
|
||||
This code is a modified version of crypting code in Info-ZIP distribution
|
||||
|
||||
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
|
||||
This encryption code is a direct transcription of the algorithm from
|
||||
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
||||
file (appnote.txt) is distributed with the PKZIP program (even in the
|
||||
version without encryption capabilities).
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_crypt.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define RAND_HEAD_LEN 12
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_crypt_vtbl = {
|
||||
mz_stream_crypt_open,
|
||||
mz_stream_crypt_is_open,
|
||||
mz_stream_crypt_read,
|
||||
mz_stream_crypt_write,
|
||||
mz_stream_crypt_tell,
|
||||
mz_stream_crypt_seek,
|
||||
mz_stream_crypt_close,
|
||||
mz_stream_crypt_error,
|
||||
mz_stream_crypt_create,
|
||||
mz_stream_crypt_delete,
|
||||
mz_stream_crypt_get_prop_int64
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_crypt_s {
|
||||
mz_stream stream;
|
||||
int32_t error;
|
||||
int16_t initialized;
|
||||
uint8_t buffer[INT16_MAX];
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
uint32_t keys[3]; // keys defining the pseudo-random sequence
|
||||
const z_crc_t *crc_32_tab;
|
||||
uint8_t verify1;
|
||||
uint8_t verify2;
|
||||
const char *password;
|
||||
} mz_stream_crypt;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define zdecode(keys,crc_32_tab,c) \
|
||||
(mz_stream_crypt_update_keys(keys,crc_32_tab, c ^= mz_stream_crypt_decrypt_byte(keys)))
|
||||
|
||||
#define zencode(keys,crc_32_tab,c,t) \
|
||||
(t = mz_stream_crypt_decrypt_byte(keys), mz_stream_crypt_update_keys(keys,crc_32_tab,c), t^(c))
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint8_t mz_stream_crypt_decrypt_byte(uint32_t *keys)
|
||||
{
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
* with any known compiler so far, though */
|
||||
|
||||
temp = ((uint32_t)(*(keys+2)) & 0xffff) | 2;
|
||||
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
uint8_t mz_stream_crypt_update_keys(uint32_t *keys, const z_crc_t *crc_32_tab, int32_t c)
|
||||
{
|
||||
#define CRC32(c, b) ((*(crc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
(*(keys+0)) = (uint32_t)CRC32((*(keys+0)), c);
|
||||
(*(keys+1)) += (*(keys+0)) & 0xff;
|
||||
(*(keys+1)) = (*(keys+1)) * 134775813L + 1;
|
||||
{
|
||||
register int32_t keyshift = (int32_t)((*(keys + 1)) >> 24);
|
||||
(*(keys+2)) = (uint32_t)CRC32((*(keys+2)), keyshift);
|
||||
}
|
||||
return (uint8_t)c;
|
||||
}
|
||||
|
||||
void mz_stream_crypt_init_keys(const char *password, uint32_t *keys, const z_crc_t *crc_32_tab)
|
||||
{
|
||||
*(keys+0) = 305419896L;
|
||||
*(keys+1) = 591751049L;
|
||||
*(keys+2) = 878082192L;
|
||||
|
||||
while (*password != 0)
|
||||
{
|
||||
mz_stream_crypt_update_keys(keys, crc_32_tab, *password);
|
||||
password += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_crypt_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
uint16_t t = 0;
|
||||
int16_t i = 0;
|
||||
uint8_t header[RAND_HEAD_LEN];
|
||||
const char *password = path;
|
||||
|
||||
crypt->total_in = 0;
|
||||
crypt->total_out = 0;
|
||||
crypt->initialized = 0;
|
||||
|
||||
if (mz_stream_is_open(crypt->stream.base) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
if (password == NULL)
|
||||
password = crypt->password;
|
||||
if (password == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
crypt->crc_32_tab = get_crc_table();
|
||||
if (crypt->crc_32_tab == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
mz_stream_crypt_init_keys(password, crypt->keys, crypt->crc_32_tab);
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
// First generate RAND_HEAD_LEN - 2 random bytes.
|
||||
mz_os_rand(header, RAND_HEAD_LEN - 2);
|
||||
|
||||
// Encrypt random header (last two bytes is high word of crc)
|
||||
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
|
||||
header[i] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, header[i], t);
|
||||
|
||||
header[i++] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, crypt->verify1, t);
|
||||
header[i++] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, crypt->verify2, t);
|
||||
|
||||
if (mz_stream_write(crypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
crypt->total_out += RAND_HEAD_LEN;
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
if (mz_stream_read(crypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
|
||||
header[i] = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i]);
|
||||
|
||||
crypt->verify1 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
|
||||
crypt->verify2 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
|
||||
|
||||
crypt->total_in += RAND_HEAD_LEN;
|
||||
}
|
||||
|
||||
crypt->initialized = 1;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crypt_is_open(void *stream)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
if (crypt->initialized == 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crypt_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
uint8_t *buf_ptr = (uint8_t *)buf;
|
||||
uint32_t read = 0;
|
||||
uint32_t i = 0;
|
||||
|
||||
read = mz_stream_read(crypt->stream.base, buf, size);
|
||||
|
||||
for (i = 0; i < read; i++)
|
||||
buf_ptr[i] = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, buf_ptr[i]);
|
||||
|
||||
crypt->total_in += read;
|
||||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crypt_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
uint8_t *buf_ptr = (uint8_t *)buf;
|
||||
uint32_t written = 0;
|
||||
uint16_t t = 0;
|
||||
int32_t i = 0;
|
||||
|
||||
if (size > sizeof(crypt->buffer))
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
crypt->buffer[i] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, buf_ptr[i], t);
|
||||
|
||||
written = mz_stream_write(crypt->stream.base, crypt->buffer, size);
|
||||
|
||||
if (written > 0)
|
||||
crypt->total_out += written;
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_crypt_tell(void *stream)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
return mz_stream_tell(crypt->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crypt_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
return mz_stream_seek(crypt->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crypt_close(void *stream)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
crypt->initialized = 0;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crypt_error(void *stream)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
return crypt->error;
|
||||
}
|
||||
|
||||
void mz_stream_crypt_set_password(void *stream, const char *password)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
crypt->password = password;
|
||||
}
|
||||
|
||||
void mz_stream_crypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
crypt->verify1 = verify1;
|
||||
crypt->verify2 = verify2;
|
||||
}
|
||||
|
||||
void mz_stream_crypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
*verify1 = crypt->verify1;
|
||||
*verify2 = crypt->verify2;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crypt_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
{
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = crypt->total_in;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = crypt->total_out;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
void *mz_stream_crypt_create(void **stream)
|
||||
{
|
||||
mz_stream_crypt *crypt = NULL;
|
||||
|
||||
crypt = (mz_stream_crypt *)malloc(sizeof(mz_stream_crypt));
|
||||
if (crypt != NULL)
|
||||
{
|
||||
memset(crypt, 0, sizeof(mz_stream_crypt));
|
||||
crypt->stream.vtbl = &mz_stream_crypt_vtbl;
|
||||
}
|
||||
|
||||
if (stream != NULL)
|
||||
*stream = crypt;
|
||||
return crypt;
|
||||
}
|
||||
|
||||
void mz_stream_crypt_delete(void **stream)
|
||||
{
|
||||
mz_stream_crypt *crypt = NULL;
|
||||
if (stream == NULL)
|
||||
return;
|
||||
crypt = (mz_stream_crypt *)*stream;
|
||||
if (crypt != NULL)
|
||||
free(crypt);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_crypt_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_crypt_vtbl;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/* mz_strm_crypt.h -- Code for traditional PKWARE encryption
|
||||
Version 2.2.4, November 15th, 2017
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
Modifications for Info-ZIP crypting
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
Copyright (C) 2003 Terry Thorsen
|
||||
|
||||
This code is a modified version of crypting code in Info-ZIP distribution
|
||||
|
||||
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef _MZ_STREAM_CRYPT_H
|
||||
#define _MZ_STREAM_CRYPT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_crypt_open(void *stream, const char *filename, int32_t mode);
|
||||
int32_t mz_stream_crypt_is_open(void *stream);
|
||||
int32_t mz_stream_crypt_read(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_crypt_write(void *stream, const void *buf, int32_t size);
|
||||
int64_t mz_stream_crypt_tell(void *stream);
|
||||
int32_t mz_stream_crypt_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_crypt_close(void *stream);
|
||||
int32_t mz_stream_crypt_error(void *stream);
|
||||
|
||||
void mz_stream_crypt_set_password(void *stream, const char *password);
|
||||
void mz_stream_crypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2);
|
||||
void mz_stream_crypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2);
|
||||
int32_t mz_stream_crypt_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
|
||||
void* mz_stream_crypt_create(void **stream);
|
||||
void mz_stream_crypt_delete(void **stream);
|
||||
|
||||
void* mz_stream_crypt_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
-151
@@ -1,151 +0,0 @@
|
||||
/* mz_zip.h -- Zip manipulation
|
||||
Version 2.2.4, November 15th, 2017
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
http://result42.com
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
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_ZIP_H
|
||||
#define _MZ_ZIP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "mz_strm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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
|
||||
uint64_t compressed_size; // compressed size
|
||||
uint64_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
|
||||
uint64_t disk_offset; // relative offset of local header
|
||||
uint16_t internal_fa; // internal file attributes
|
||||
uint32_t external_fa; // external file attributes
|
||||
|
||||
char *filename; // filename string
|
||||
uint8_t *extrafield; // extrafield data
|
||||
char *comment; // comment string
|
||||
|
||||
#ifdef HAVE_AES
|
||||
uint16_t aes_version; // winzip aes extension if not 0
|
||||
uint8_t aes_encryption_mode; // winzip aes encryption mode
|
||||
#endif
|
||||
} mz_zip_file;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern void * mz_zip_open(void *stream, int32_t mode);
|
||||
// Create a zip file, no delete file in zip functionality
|
||||
|
||||
extern int32_t mz_zip_close(void *handle);
|
||||
// Close the zip file
|
||||
|
||||
extern int32_t mz_zip_get_comment(void *handle, const char **comment);
|
||||
// Get a pointer to the global comment
|
||||
|
||||
extern int32_t mz_zip_set_comment(void *handle, const char *comment);
|
||||
// Set the global comment used for writing zip file
|
||||
|
||||
extern int32_t mz_zip_get_version_madeby(void *handle, uint16_t *version_madeby);
|
||||
// Get the version made by
|
||||
|
||||
extern int32_t mz_zip_set_version_madeby(void *handle, uint16_t version_madeby);
|
||||
// Set the version made by used for writing zip file
|
||||
|
||||
extern int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
|
||||
int16_t compress_level, const char *password);
|
||||
// Open for writing the current file in the zip file
|
||||
|
||||
extern int32_t mz_zip_entry_write(void *handle, const void *buf, uint32_t len);
|
||||
// Write bytes from the current file in the zip file
|
||||
|
||||
extern int32_t mz_zip_entry_read_open(void *handle, int16_t raw, const char *password);
|
||||
// Open for reading the current file in the zip file
|
||||
|
||||
extern int32_t mz_zip_entry_read(void *handle, void *buf, uint32_t len);
|
||||
// Read bytes from the current file in the zip file
|
||||
|
||||
extern 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
|
||||
|
||||
extern 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
|
||||
|
||||
extern int32_t mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size, uint32_t crc32);
|
||||
// Close the current file in the zip file where raw is compressed data
|
||||
|
||||
extern int32_t mz_zip_entry_close(void *handle);
|
||||
// Close the current file in the zip file
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern int32_t mz_zip_get_number_entry(void *handle, int64_t *number_entry);
|
||||
// Get the total number of entries
|
||||
|
||||
extern int32_t mz_zip_goto_first_entry(void *handle);
|
||||
// Go to the first entry in the zip file
|
||||
|
||||
extern int32_t mz_zip_goto_next_entry(void *handle);
|
||||
// Go to the next entry in the zip file or MZ_END_OF_LIST if reaching the end
|
||||
|
||||
typedef int32_t (*mz_filename_compare_cb)(void *handle, const char *filename1, const char *filename2);
|
||||
extern int32_t mz_zip_locate_entry(void *handle, const char *filename,
|
||||
mz_filename_compare_cb filename_compare_cb);
|
||||
// Locate the file with the specified name in the zip file or MZ_END_LIST if not found
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_zip_dosdate_to_tm(uint64_t dos_date, struct tm *ptm);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_time_t_to_tm(time_t unix_time, struct tm *ptm);
|
||||
// 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
|
||||
|
||||
uint32_t mz_zip_tm_to_dosdate(const struct tm *ptm);
|
||||
// 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
|
||||
|
||||
int32_t mz_zip_unix_to_ntfs_time(time_t unix_time, uint64_t *ntfs_time);
|
||||
// Convert unix time to ntfs time
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ZIP_H */
|
||||
+72
-7
@@ -9,14 +9,72 @@
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_mem.h"
|
||||
#ifdef HAVE_BZIP
|
||||
#include "mz_strm_bzip.h"
|
||||
#include "mz_strm_crypt.h"
|
||||
#endif
|
||||
#ifdef HAVE_PKCRYPT
|
||||
#include "mz_strm_pkcrypt.h"
|
||||
#endif
|
||||
#ifdef HAVE_AES
|
||||
#include "mz_strm_aes.h"
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
#include "mz_strm_zlib.h"
|
||||
#endif
|
||||
#include "mz_zip.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void test_path_resolve(void)
|
||||
{
|
||||
char output[256];
|
||||
int32_t ok = 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:\\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));
|
||||
}
|
||||
|
||||
void test_encrypt(char *method, mz_stream_create_cb crypt_create, char *password)
|
||||
{
|
||||
char buf[UINT16_MAX];
|
||||
@@ -151,7 +209,7 @@ void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
|
||||
mz_stream_delete(&deflate_stream);
|
||||
|
||||
printf("%s compressed from %d to %d\n", filename, (uint32_t)total_in, (uint32_t)total_out);
|
||||
printf("%s compressed from %u to %u\n", filename, (uint32_t)total_in, (uint32_t)total_out);
|
||||
|
||||
mz_stream_os_close(out_stream);
|
||||
}
|
||||
@@ -175,7 +233,7 @@ void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
|
||||
mz_stream_os_close(in_stream);
|
||||
|
||||
printf("%s uncompressed from %d to %d\n", filename, (uint32_t)total_in, (uint32_t)total_out);
|
||||
printf("%s uncompressed from %u to %u\n", filename, (uint32_t)total_in, (uint32_t)total_out);
|
||||
}
|
||||
|
||||
mz_stream_os_delete(&in_stream);
|
||||
@@ -206,25 +264,30 @@ void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef HAVE_AES
|
||||
void test_aes()
|
||||
{
|
||||
test_encrypt("aes", mz_stream_aes_create, "hello");
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef HAVE_PKCRYPT
|
||||
void test_crypt()
|
||||
{
|
||||
test_encrypt("crypt", mz_stream_crypt_create, "hello");
|
||||
test_encrypt("pkcrypt", mz_stream_pkcrypt_create, "hello");
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
void test_zlib()
|
||||
{
|
||||
test_compress("zlib", mz_stream_zlib_create);
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef HAVE_BZIP
|
||||
void test_bzip()
|
||||
{
|
||||
test_compress("bzip", mz_stream_bzip_create);
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -262,7 +325,9 @@ void test_zip_mem()
|
||||
file_info.compression_method = MZ_COMPRESS_METHOD_DEFLATE;
|
||||
file_info.filename = text_name;
|
||||
file_info.uncompressed_size = text_size;
|
||||
#ifdef HAVE_AES
|
||||
file_info.aes_version = MZ_AES_VERSION;
|
||||
#endif
|
||||
|
||||
err = mz_zip_entry_write_open(zip_handle, &file_info, MZ_COMPRESS_LEVEL_DEFAULT, password);
|
||||
if (err == MZ_OK)
|
||||
|
||||
Reference in New Issue
Block a user