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 |
+89
-35
@@ -1,9 +1,11 @@
|
||||
#***************************************************************************
|
||||
# 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)
|
||||
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
|
||||
option(USE_ZLIB "Enables ZLIB compression" ON)
|
||||
option(USE_BZIP2 "Enables BZIP2 compression" ON)
|
||||
@@ -14,15 +16,10 @@ option(COMPRESS_ONLY "Only support compression" OFF)
|
||||
option(DECOMPRESS_ONLY "Only support decompression" OFF)
|
||||
option(BUILD_TEST "Builds minizip test executable" OFF)
|
||||
|
||||
# Set a consistent MACOSX_RPATH default across all CMake versions.
|
||||
# When CMake 2.8.12 is required, change this default to 1.
|
||||
# When CMake 3.0.0 is required, remove this block (see CMP0042).
|
||||
if(NOT DEFINED CMAKE_MACOSX_RPATH)
|
||||
set(CMAKE_MACOSX_RPATH 0)
|
||||
endif()
|
||||
|
||||
project("minizip")
|
||||
|
||||
include(CheckLibraryExists)
|
||||
include(CheckSymbolExists)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Installation directory for executables")
|
||||
@@ -32,7 +29,11 @@ set(INSTALL_MAN_DIR ${CMAKE_INSTALL_MANDIR} CACHE PATH "Installation directory f
|
||||
set(INSTALL_PKGCONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE PATH "Installation directory for pkgconfig (.pc) files")
|
||||
set(INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/minizip CACHE PATH "Installation directory for cmake files.")
|
||||
|
||||
set(VERSION "2.3.7")
|
||||
# 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")
|
||||
@@ -47,6 +48,16 @@ if(USE_ZLIB)
|
||||
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)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/minizip.pc.cmakein ${MINIZIP_PC} @ONLY)
|
||||
|
||||
@@ -61,7 +72,8 @@ set(MINIZIP_SRC
|
||||
mz_strm_mem.c
|
||||
mz_strm_posix.c
|
||||
mz_strm_split.c
|
||||
mz_zip.c)
|
||||
mz_zip.c
|
||||
mz_zip_rw.c)
|
||||
|
||||
set(MINIZIP_PUBLIC_HEADERS
|
||||
mz.h
|
||||
@@ -73,13 +85,17 @@ set(MINIZIP_PUBLIC_HEADERS
|
||||
mz_strm_mem.h
|
||||
mz_strm_posix.h
|
||||
mz_strm_split.h
|
||||
mz_zip.h)
|
||||
mz_zip.h
|
||||
mz_zip_rw.h)
|
||||
|
||||
if(COMPRESS_ONLY)
|
||||
add_definitions(-DMZ_ZIP_COMPRESS_ONLY)
|
||||
add_definitions(-DMZ_ZIP_NO_DECOMPRESSION)
|
||||
endif()
|
||||
if(DECOMPRESS_ONLY)
|
||||
add_definitions(-DMZ_ZIP_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})
|
||||
@@ -118,13 +134,33 @@ if(UNIX)
|
||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
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 REQUIRED)
|
||||
|
||||
include_directories(${LIBBSD_INCLUDE_DIRS})
|
||||
link_directories(${LIBBSD_LIBRARY_DIRS})
|
||||
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()
|
||||
|
||||
@@ -180,7 +216,14 @@ if(USE_ZLIB)
|
||||
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)
|
||||
|
||||
@@ -341,11 +384,16 @@ 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()
|
||||
@@ -355,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 "${INSTALL_CMAKE_DIR}"
|
||||
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 "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()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'Minizip'
|
||||
s.version = '2.3.7'
|
||||
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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Minizip 2.3.7
|
||||
# Minizip 2.5.2
|
||||
|
||||
This library is a refactoring of the minizip contribution found in the zlib distribution and is supported on Windows, macOS, and Linux. The motivation for this work has been the inclusion of advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. It is based on the original work of [Gilles Vollant](http://www.winimage.com/zLibDll/minizip.html) that has been contributed to by many people over the years.
|
||||
|
||||
@@ -75,7 +75,8 @@ cmake . -DZLIB_LIBRARY=lib\zlib\release\zlibstatic.lib -DZLIB_INCLUDE_DIR=lib\zl
|
||||
| mz_strm_posix.\* | File stream using Posix functions | Non-windows systems |
|
||||
| mz_strm_win32.\* | File stream using Win32 API functions | Windows systems |
|
||||
| mz_strm_zlib.\* | Deflate stream using zlib | zlib or liblzma |
|
||||
| mz_zip.\* | Zip functionality | Yes |
|
||||
| mz_zip.\* | Zip format | Yes |
|
||||
| mz_zip_rw.\* | Zip reader/writer | No |
|
||||
|
||||
## Features
|
||||
|
||||
@@ -89,7 +90,7 @@ cmake . -DZLIB_LIBRARY=lib\zlib\release\zlibstatic.lib -DZLIB_INCLUDE_DIR=lib\zl
|
||||
#### 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
|
||||
|
||||
|
||||
+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
|
||||
@@ -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.
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
/* minizip.c
|
||||
Version 2.3.7, July 13, 2018
|
||||
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) 2007-2008 Even Rouault
|
||||
Modifications of Unzip for Zip64
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
@@ -29,6 +24,7 @@
|
||||
#include "mz_strm_buf.h"
|
||||
#include "mz_strm_split.h"
|
||||
#include "mz_zip.h"
|
||||
#include "mz_zip_rw.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -40,13 +36,13 @@ void minizip_banner(void)
|
||||
|
||||
void minizip_help(void)
|
||||
{
|
||||
printf("Usage : minizip [-x -d dir|-l] [-o] [-a] [-j] [-0 to -9] [-b|-m] [-k 512] [-p pwd] [-s] file.zip [files]\n\n" \
|
||||
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" \
|
||||
" -u Buffered reading and writing\n" \
|
||||
" -i Include full path of files\n" \
|
||||
" -0 Store only\n" \
|
||||
" -1 Compress faster\n" \
|
||||
@@ -68,184 +64,21 @@ void minizip_help(void)
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct minizip_opt_s {
|
||||
int16_t include_path;
|
||||
uint8_t include_path;
|
||||
int16_t compress_level;
|
||||
int16_t compress_method;
|
||||
int16_t overwrite;
|
||||
uint8_t compress_method;
|
||||
uint8_t overwrite;
|
||||
uint8_t append;
|
||||
int64_t disk_size;
|
||||
#ifdef HAVE_AES
|
||||
int16_t aes;
|
||||
uint8_t aes;
|
||||
#endif
|
||||
uint8_t legacy_encoding;
|
||||
} minizip_opt;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_add_path(void *handle, const char *path, const char *filenameinzip, const char *password, int16_t is_dir, minizip_opt *options)
|
||||
{
|
||||
mz_zip_file file_info;
|
||||
int32_t read = 0;
|
||||
int32_t written = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int32_t err_close = MZ_OK;
|
||||
void *stream = NULL;
|
||||
char buf[INT16_MAX];
|
||||
|
||||
|
||||
memset(&file_info, 0, sizeof(file_info));
|
||||
|
||||
// The path name saved, should not include a leading slash.
|
||||
// If it did, windows/xp and dynazip couldn't read the zip file.
|
||||
|
||||
if (filenameinzip == NULL)
|
||||
filenameinzip = path;
|
||||
while (filenameinzip[0] == '\\' || filenameinzip[0] == '/')
|
||||
filenameinzip += 1;
|
||||
|
||||
// Get information about the file on disk so we can store it in zip
|
||||
|
||||
file_info.version_madeby = MZ_VERSION_MADEBY;
|
||||
file_info.compression_method = options->compress_method;
|
||||
file_info.filename = 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);
|
||||
mz_os_get_file_attribs(path, &file_info.external_fa);
|
||||
|
||||
printf("Adding: %s\n", file_info.filename);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
if (!is_dir)
|
||||
{
|
||||
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 *root_path, const char *password, minizip_opt *options, uint8_t recursive)
|
||||
{
|
||||
DIR *dir = NULL;
|
||||
struct dirent *entry = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
int16_t is_dir = 0;
|
||||
char full_path[320];
|
||||
const char *filename = NULL;
|
||||
const char *filenameinzip = path;
|
||||
|
||||
|
||||
if (mz_os_is_dir(path) == MZ_OK)
|
||||
is_dir = 1;
|
||||
|
||||
// Construct the filename that our file will be stored in the zip as
|
||||
if (root_path == NULL)
|
||||
root_path = path;
|
||||
|
||||
// Should the file be stored with any path info at all?
|
||||
if (!options->include_path)
|
||||
{
|
||||
if (!is_dir && root_path == path)
|
||||
{
|
||||
if (mz_path_get_filename(filenameinzip, &filename) == MZ_OK)
|
||||
filenameinzip = filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
filenameinzip += strlen(root_path);
|
||||
}
|
||||
}
|
||||
|
||||
if (*filenameinzip != 0)
|
||||
err = minizip_add_path(handle, path, filenameinzip, password, is_dir, options);
|
||||
|
||||
if (!is_dir)
|
||||
return err;
|
||||
|
||||
dir = mz_os_open_dir(path);
|
||||
|
||||
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, root_path, password, options, recursive);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
}
|
||||
|
||||
mz_os_close_dir(dir);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_list(void *handle)
|
||||
int32_t minizip_list(const char *path)
|
||||
{
|
||||
mz_zip_file *file_info = NULL;
|
||||
uint32_t ratio = 0;
|
||||
@@ -255,21 +88,34 @@ int32_t minizip_list(void *handle)
|
||||
const char *string_method = NULL;
|
||||
char crypt = ' ';
|
||||
|
||||
void *reader = NULL;
|
||||
|
||||
err = mz_zip_goto_first_entry(handle);
|
||||
|
||||
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");
|
||||
|
||||
while (err == MZ_OK)
|
||||
do
|
||||
{
|
||||
err = mz_zip_entry_get_info(handle, &file_info);
|
||||
err = mz_zip_reader_entry_get_info(reader, &file_info);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
@@ -287,7 +133,7 @@ int32_t minizip_list(void *handle)
|
||||
|
||||
switch (file_info->compression_method)
|
||||
{
|
||||
case MZ_COMPRESS_METHOD_RAW:
|
||||
case MZ_COMPRESS_METHOD_STORE:
|
||||
string_method = "Stored";
|
||||
break;
|
||||
case MZ_COMPRESS_METHOD_DEFLATE:
|
||||
@@ -322,14 +168,17 @@ int32_t minizip_list(void *handle)
|
||||
(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);
|
||||
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);
|
||||
return err;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (err == MZ_OK);
|
||||
|
||||
mz_zip_reader_delete(&reader);
|
||||
|
||||
if (err == MZ_END_OF_LIST)
|
||||
return MZ_OK;
|
||||
@@ -339,222 +188,316 @@ int32_t minizip_list(void *handle)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minizip_extract_currentfile(void *handle, const char *destination, const char *password, minizip_opt *options)
|
||||
int32_t minizip_add_entry_cb(void *handle, void *userdata, mz_zip_file *file_info)
|
||||
{
|
||||
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;
|
||||
void *stream = NULL;
|
||||
const char *filename = NULL;
|
||||
char out_name[512];
|
||||
char out_path[512];
|
||||
char directory[512];
|
||||
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;
|
||||
|
||||
err = mz_zip_entry_get_info(handle, &file_info);
|
||||
mz_zip_writer_get_raw(handle, &raw);
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d getting entry info in zip file\n", err);
|
||||
return err;
|
||||
}
|
||||
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;
|
||||
|
||||
if (mz_path_get_filename(file_info->filename, &filename) != MZ_OK)
|
||||
filename = file_info->filename;
|
||||
printf("%s - %lld / %lld (%.02f%%)\n", file_info->filename, position, file_info->uncompressed_size, progress);
|
||||
return MZ_OK;
|
||||
|
||||
// Construct output path
|
||||
out_path[0] = 0;
|
||||
if ((*file_info->filename == '/') || (file_info->filename[1] == ':'))
|
||||
{
|
||||
strncpy(out_path, file_info->filename, sizeof(out_path));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (destination != NULL)
|
||||
mz_path_combine(out_path, destination, sizeof(out_path));
|
||||
err = mz_path_resolve(file_info->filename, out_name, sizeof(out_name));
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
printf("Error %d resolving output path\n", err);
|
||||
return err;
|
||||
}
|
||||
mz_path_combine(out_path, out_name, sizeof(out_path));
|
||||
}
|
||||
}
|
||||
int32_t minizip_add_overwrite_cb(void *handle, void *userdata, const char *path)
|
||||
{
|
||||
minizip_opt *options = (minizip_opt *)userdata;
|
||||
|
||||
// If zip entry is a directory then create it on disk
|
||||
if (mz_zip_attrib_is_dir(file_info->external_fa, file_info->version_madeby) == MZ_OK)
|
||||
{
|
||||
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))
|
||||
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]ll: ", out_path);
|
||||
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 == 'N')
|
||||
return err;
|
||||
if (rep == 'A')
|
||||
options->overwrite = 1;
|
||||
}
|
||||
|
||||
mz_stream_os_create(&stream);
|
||||
|
||||
// Create the file on disk so we can unzip to it
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
// Some zips don't contain directory alone before file
|
||||
err = mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE);
|
||||
if ((err != MZ_OK) && (filename != file_info->filename))
|
||||
{
|
||||
// Create the directory of the output path
|
||||
strncpy(directory, out_path, sizeof(directory));
|
||||
|
||||
mz_path_remove_filename(directory);
|
||||
mz_make_dir(directory);
|
||||
|
||||
err = mz_stream_os_open(stream, out_path, MZ_OPEN_MODE_CREATE);
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
else if (rep == 'N')
|
||||
{
|
||||
return MZ_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// Read from the zip, unzip to buffer, and write to disk
|
||||
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)
|
||||
{
|
||||
printf(" Extracting: %s\n", out_path);
|
||||
while (1)
|
||||
for (i = 0; i < arg_count; i += 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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
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 %d opening %s\n", err, out_path);
|
||||
printf("Error %d opening zip for writing\n", err);
|
||||
}
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
|
||||
err_close = mz_zip_entry_close(handle);
|
||||
|
||||
err_close = mz_zip_writer_close(writer);
|
||||
if (err_close != MZ_OK)
|
||||
{
|
||||
printf("Error %d closing entry in zip file\n", err_close);
|
||||
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_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[])
|
||||
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;
|
||||
char *path = NULL;
|
||||
char *password = NULL;
|
||||
char *destination = NULL;
|
||||
char *filename_to_extract = NULL;
|
||||
minizip_opt options;
|
||||
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;
|
||||
uint8_t do_list = 0;
|
||||
uint8_t do_extract = 0;
|
||||
uint8_t buffered = 0;
|
||||
int16_t mode = 0;
|
||||
uint8_t append = 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)
|
||||
@@ -576,46 +519,48 @@ int main(int argc, char *argv[])
|
||||
char c = argv[i][1];
|
||||
if ((c == 'l') || (c == 'L'))
|
||||
do_list = 1;
|
||||
if ((c == 'x') || (c == 'X'))
|
||||
else if ((c == 'x') || (c == 'X'))
|
||||
do_extract = 1;
|
||||
if ((c == 'a') || (c == 'A'))
|
||||
append = 1;
|
||||
if ((c == 'u') || (c == 'U'))
|
||||
buffered = 1;
|
||||
if ((c == 'o') || (c == 'O'))
|
||||
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;
|
||||
if ((c == 'i') || (c == 'I'))
|
||||
else if ((c == 'i') || (c == 'I'))
|
||||
options.include_path = 1;
|
||||
if ((c >= '0') && (c <= '9'))
|
||||
else if ((c >= '0') && (c <= '9'))
|
||||
{
|
||||
options.compress_level = (c - '0');
|
||||
if (options.compress_level == 0)
|
||||
options.compress_method = MZ_COMPRESS_METHOD_RAW;
|
||||
options.compress_method = MZ_COMPRESS_METHOD_STORE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_BZIP2
|
||||
if ((c == 'b') || (c == 'B'))
|
||||
else if ((c == 'b') || (c == 'B'))
|
||||
options.compress_method = MZ_COMPRESS_METHOD_BZIP2;
|
||||
#endif
|
||||
#ifdef HAVE_LZMA
|
||||
if ((c == 'm') || (c == 'M'))
|
||||
else if ((c == 'm') || (c == 'M'))
|
||||
options.compress_method = MZ_COMPRESS_METHOD_LZMA;
|
||||
#endif
|
||||
#ifdef HAVE_AES
|
||||
if ((c == 's') || (c == 'S'))
|
||||
else if ((c == 's') || (c == 'S'))
|
||||
options.aes = 1;
|
||||
#endif
|
||||
if (((c == 'k') || (c == 'K')) && (i + 1 < argc))
|
||||
else if ((c == 'c') || (c == 'C'))
|
||||
options.legacy_encoding = 1;
|
||||
else if (((c == 'k') || (c == 'K')) && (i + 1 < argc))
|
||||
{
|
||||
disk_size = atoi(argv[i + 1]) * 1024;
|
||||
options.disk_size = atoi(argv[i + 1]) * 1024;
|
||||
i += 1;
|
||||
}
|
||||
if (((c == 'd') || (c == 'D')) && (i + 1 < argc))
|
||||
else if (((c == 'd') || (c == 'D')) && (i + 1 < argc))
|
||||
{
|
||||
destination = argv[i + 1];
|
||||
i += 1;
|
||||
}
|
||||
if (((c == 'p') || (c == 'P')) && (i + 1 < argc))
|
||||
else if (((c == 'p') || (c == 'P')) && (i + 1 < argc))
|
||||
{
|
||||
password = argv[i + 1];
|
||||
i += 1;
|
||||
@@ -633,130 +578,45 @@ int main(int argc, char *argv[])
|
||||
|
||||
path = argv[path_arg];
|
||||
|
||||
mode = MZ_OPEN_MODE_READ;
|
||||
|
||||
if ((do_list == 0) && (do_extract == 0))
|
||||
if (do_list)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
err = minizip_list(path);
|
||||
}
|
||||
|
||||
mz_stream_os_create(&file_stream);
|
||||
mz_stream_buffered_create(&buf_stream);
|
||||
mz_stream_split_create(&split_stream);
|
||||
|
||||
if (buffered)
|
||||
else if (do_extract)
|
||||
{
|
||||
mz_stream_set_base(buf_stream, file_stream);
|
||||
mz_stream_set_base(split_stream, buf_stream);
|
||||
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
|
||||
{
|
||||
mz_stream_set_base(split_stream, file_stream);
|
||||
err = minizip_add(path, password, &options, argc - (path_arg + 1), &argv[path_arg + 1]);
|
||||
}
|
||||
|
||||
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)
|
||||
if (err == MZ_OK && do_erase)
|
||||
{
|
||||
printf("Error opening file %s\n", path);
|
||||
// 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);
|
||||
}
|
||||
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], NULL, 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_close(split_stream);
|
||||
}
|
||||
|
||||
mz_stream_split_delete(&split_stream);
|
||||
mz_stream_buffered_delete(&buf_stream);
|
||||
mz_stream_os_delete(&file_stream);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
/* mz.h -- Errors codes, zip flags and magic
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -19,13 +19,15 @@ extern "C" {
|
||||
/***************************************************************************/
|
||||
|
||||
// MZ_VERSION
|
||||
#define MZ_VERSION ("2.3.7")
|
||||
#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)
|
||||
@@ -51,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)
|
||||
@@ -71,6 +73,7 @@ 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)
|
||||
@@ -78,16 +81,22 @@ extern "C" {
|
||||
#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)
|
||||
|
||||
+252
-94
@@ -1,5 +1,5 @@
|
||||
/* mz_compat.c -- Backwards compatible interface for older versions
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -18,6 +18,7 @@
|
||||
#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"
|
||||
|
||||
@@ -26,36 +27,53 @@
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_compat_s {
|
||||
void *stream;
|
||||
void *handle;
|
||||
void *stream;
|
||||
void *handle;
|
||||
} mz_compat;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern zipFile ZEXPORT zipOpen(const char *path, int append)
|
||||
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);
|
||||
}
|
||||
|
||||
extern zipFile ZEXPORT zipOpen64(const void *path, int append)
|
||||
zipFile ZEXPORT zipOpen64(const void *path, int append)
|
||||
{
|
||||
zlib_filefunc64_def pzlib = mz_stream_os_get_interface();
|
||||
return zipOpen2(path, append, NULL, &pzlib);
|
||||
}
|
||||
|
||||
extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
|
||||
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,
|
||||
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;
|
||||
void *handle = NULL;
|
||||
zipFile zip = NULL;
|
||||
int32_t mode = zipConvertAppendToStreamMode(append);
|
||||
void *stream = NULL;
|
||||
|
||||
if (pzlib_filefunc_def)
|
||||
@@ -69,17 +87,6 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
||||
if (mz_stream_open(stream, path, mode) != MZ_OK)
|
||||
{
|
||||
@@ -87,14 +94,33 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle = mz_zip_open(stream, mode);
|
||||
zip = zipOpen_MZ(stream, append, globalcomment);
|
||||
|
||||
if (handle == NULL)
|
||||
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);
|
||||
|
||||
@@ -105,7 +131,7 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
|
||||
return (zipFile)compat;
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
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,
|
||||
@@ -157,17 +183,14 @@ extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, cons
|
||||
else
|
||||
file_info.zip64 = MZ_ZIP64_DISABLE;
|
||||
#ifdef HAVE_AES
|
||||
if (password)
|
||||
if ((password != NULL) || (raw && (file_info.flag & MZ_ZIP_FLAG_ENCRYPTED)))
|
||||
file_info.aes_version = MZ_AES_VERSION;
|
||||
#endif
|
||||
|
||||
if (raw)
|
||||
level = 0;
|
||||
|
||||
return mz_zip_entry_write_open(compat->handle, &file_info, (int16_t)level, password);
|
||||
return mz_zip_entry_write_open(compat->handle, &file_info, (int16_t)level, (uint8_t)raw, password);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
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,
|
||||
@@ -178,7 +201,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
|
||||
memLevel, strategy, password, crc_for_crypting, version_madeby, flag_base, zip64);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
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,
|
||||
@@ -189,7 +212,7 @@ extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, cons
|
||||
memLevel, strategy, password, crc_for_crypting, version_madeby, flag_base, 0);
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -200,7 +223,7 @@ extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, cons
|
||||
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,
|
||||
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,
|
||||
@@ -211,7 +234,7 @@ extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, c
|
||||
memLevel, strategy, password, crc_for_crypting, MZ_VERSION_MADEBY, 0, zip64);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len)
|
||||
int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t written = 0;
|
||||
@@ -223,12 +246,12 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t l
|
||||
return ZIP_OK;
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32)
|
||||
int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32)
|
||||
{
|
||||
return zipCloseFileInZipRaw64(file, uncompressed_size, crc32);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32)
|
||||
int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
@@ -236,39 +259,36 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_si
|
||||
return mz_zip_entry_close_raw(compat->handle, uncompressed_size, crc32);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip(zipFile file)
|
||||
int ZEXPORT zipCloseFileInZip(zipFile file)
|
||||
{
|
||||
return zipCloseFileInZipRaw(file, 0, 0);
|
||||
return zipCloseFileInZip64(file);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipCloseFileInZip64(zipFile file)
|
||||
int ZEXPORT zipCloseFileInZip64(zipFile file)
|
||||
{
|
||||
return zipCloseFileInZipRaw(file, 0, 0);
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
return ZIP_PARAMERROR;
|
||||
return mz_zip_entry_close(compat->handle);
|
||||
}
|
||||
|
||||
extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
|
||||
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)
|
||||
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)
|
||||
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 ZIP_PARAMERROR;
|
||||
|
||||
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->handle != NULL)
|
||||
err = zipClose2_MZ(file, global_comment, version_madeby);
|
||||
|
||||
if (compat->stream != NULL)
|
||||
{
|
||||
@@ -281,29 +301,62 @@ extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16
|
||||
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;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern unzFile ZEXPORT unzOpen(const char *path)
|
||||
unzFile ZEXPORT unzOpen(const char *path)
|
||||
{
|
||||
return unzOpen64(path);
|
||||
}
|
||||
|
||||
extern unzFile ZEXPORT unzOpen64(const void *path)
|
||||
unzFile ZEXPORT unzOpen64(const void *path)
|
||||
{
|
||||
zlib_filefunc64_def pzlib = mz_stream_os_get_interface();
|
||||
return unzOpen2(path, &pzlib);
|
||||
}
|
||||
|
||||
extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def)
|
||||
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)
|
||||
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;
|
||||
unzFile unz = NULL;
|
||||
void *stream = NULL;
|
||||
|
||||
if (pzlib_filefunc_def)
|
||||
@@ -316,20 +369,36 @@ extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_
|
||||
if (mz_stream_os_create(&stream) == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mz_stream_open(stream, path, mode) != MZ_OK)
|
||||
|
||||
if (mz_stream_open(stream, path, MZ_OPEN_MODE_READ) != MZ_OK)
|
||||
{
|
||||
mz_stream_delete(&stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handle = mz_zip_open(stream, mode);
|
||||
|
||||
if (handle == 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;
|
||||
@@ -339,7 +408,7 @@ extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_
|
||||
return (unzFile)compat;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzClose(unzFile file)
|
||||
int ZEXPORT unzClose(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
int32_t err = MZ_OK;
|
||||
@@ -347,7 +416,8 @@ extern int ZEXPORT unzClose(unzFile file)
|
||||
if (compat == NULL)
|
||||
return UNZ_PARAMERROR;
|
||||
|
||||
err = mz_zip_close(compat->handle);
|
||||
if (compat->handle != NULL)
|
||||
err = unzClose_MZ(file);
|
||||
|
||||
if (compat->stream != NULL)
|
||||
{
|
||||
@@ -360,7 +430,22 @@ extern int ZEXPORT unzClose(unzFile file)
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32)
|
||||
// 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;
|
||||
@@ -380,7 +465,7 @@ extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info3
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
|
||||
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
const char *comment_ptr = NULL;
|
||||
@@ -399,7 +484,7 @@ extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_i
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size)
|
||||
int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
const char *comment_ptr = NULL;
|
||||
@@ -413,34 +498,66 @@ extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t com
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
|
||||
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;
|
||||
return mz_zip_entry_read_open(compat->handle, (int16_t)raw, password);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFile(unzFile file)
|
||||
int ZEXPORT unzOpenCurrentFile(unzFile file)
|
||||
{
|
||||
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
|
||||
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)
|
||||
int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw)
|
||||
{
|
||||
return unzOpenCurrentFile3(file, method, level, raw, NULL);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzReadCurrentFile(unzFile file, void *buf, uint32_t len)
|
||||
int ZEXPORT unzReadCurrentFile(unzFile file, void *buf, uint32_t len)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
@@ -448,7 +565,7 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, void *buf, uint32_t len)
|
||||
return mz_zip_entry_read(compat->handle, buf, len);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzCloseCurrentFile(unzFile file)
|
||||
int ZEXPORT unzCloseCurrentFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
@@ -456,7 +573,7 @@ extern int ZEXPORT unzCloseCurrentFile(unzFile file)
|
||||
return mz_zip_entry_close(compat->handle);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
@@ -491,12 +608,14 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info
|
||||
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)
|
||||
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)
|
||||
{
|
||||
@@ -505,18 +624,20 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info
|
||||
bytes_to_copy = file_info->extrafield_size;
|
||||
memcpy(extrafield, file_info->extrafield, bytes_to_copy);
|
||||
}
|
||||
if (comment_size > 0 && comment != NULL)
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
@@ -551,14 +672,14 @@ extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile
|
||||
pfile_info->compressed_size = file_info->compressed_size;
|
||||
pfile_info->uncompressed_size = file_info->uncompressed_size;
|
||||
|
||||
if (filename_size > 0 && filename != NULL)
|
||||
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 (file_info->filename_size < filename_size)
|
||||
filename[file_info->filename_size] = 0;
|
||||
if (bytes_to_copy < filename_size)
|
||||
filename[bytes_to_copy] = 0;
|
||||
}
|
||||
|
||||
if (extrafield_size > 0 && extrafield != NULL)
|
||||
@@ -569,20 +690,20 @@ extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile
|
||||
memcpy(extrafield, file_info->extrafield, bytes_to_copy);
|
||||
}
|
||||
|
||||
if (comment_size > 0 && comment != NULL)
|
||||
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 (file_info->comment_size < comment_size)
|
||||
comment[file_info->comment_size] = 0;
|
||||
if (bytes_to_copy < comment_size)
|
||||
comment[bytes_to_copy] = 0;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGoToFirstFile(unzFile file)
|
||||
int ZEXPORT unzGoToFirstFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
@@ -590,7 +711,7 @@ extern int ZEXPORT unzGoToFirstFile(unzFile file)
|
||||
return mz_zip_goto_first_entry(compat->handle);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGoToNextFile(unzFile file)
|
||||
int ZEXPORT unzGoToNextFile(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
@@ -598,20 +719,43 @@ extern int ZEXPORT unzGoToNextFile(unzFile file)
|
||||
return mz_zip_goto_next_entry(compat->handle);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func)
|
||||
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;
|
||||
return mz_zip_locate_entry(compat->handle, filename, filename_compare_func);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT unzGetOffset(unzFile file)
|
||||
int32_t ZEXPORT unzGetOffset(unzFile file)
|
||||
{
|
||||
return (int32_t)unzGetOffset64(file);
|
||||
}
|
||||
|
||||
extern int64_t ZEXPORT unzGetOffset64(unzFile file)
|
||||
int64_t ZEXPORT unzGetOffset64(unzFile file)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
@@ -619,12 +763,12 @@ extern int64_t ZEXPORT unzGetOffset64(unzFile file)
|
||||
return mz_zip_get_entry(compat->handle);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos)
|
||||
int ZEXPORT unzSetOffset(unzFile file, uint32_t pos)
|
||||
{
|
||||
return unzSetOffset64(file, pos);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos)
|
||||
int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos)
|
||||
{
|
||||
mz_compat *compat = (mz_compat *)file;
|
||||
if (compat == NULL)
|
||||
@@ -632,7 +776,7 @@ extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos)
|
||||
return (int)mz_zip_goto_entry(compat->handle, pos);
|
||||
}
|
||||
|
||||
extern int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned len) // TODO
|
||||
int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned len) // TODO
|
||||
{
|
||||
MZ_UNUSED(file);
|
||||
MZ_UNUSED(buf);
|
||||
@@ -641,6 +785,14 @@ extern int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned 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)
|
||||
@@ -679,3 +831,9 @@ void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
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();
|
||||
}
|
||||
+67
-51
@@ -1,5 +1,5 @@
|
||||
/* mz_compat.h -- Backwards compatible interface for older versions
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -17,21 +17,29 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
"C" {
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
#include "zlib.h"
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
# else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
# endif
|
||||
#endif
|
||||
#else
|
||||
#define ZEXPORT
|
||||
#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
|
||||
@@ -97,55 +105,59 @@ typedef struct
|
||||
|
||||
#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,
|
||||
uint32_t crc_for_crypting);
|
||||
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
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);
|
||||
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
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);
|
||||
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
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);
|
||||
extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
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);
|
||||
|
||||
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 zipCloseFileInZipRaw64(zipFile file, uint64_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);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -241,35 +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, void *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);
|
||||
|
||||
extern int64_t ZEXPORT unzGetOffset64(unzFile file);
|
||||
extern int32_t ZEXPORT unzGetOffset(unzFile file);
|
||||
extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos);
|
||||
extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos);
|
||||
extern int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned len);
|
||||
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);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -279,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);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -287,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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* mz_os.c -- System functions
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
@@ -22,53 +23,42 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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;
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
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_path_combine(char *path, const char *join, int32_t max_path)
|
||||
{
|
||||
@@ -93,6 +83,56 @@ int32_t mz_path_combine(char *path, const char *join, int32_t max_path)
|
||||
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;
|
||||
@@ -108,7 +148,7 @@ int32_t mz_path_resolve(const char *path, char *output, int32_t max_output)
|
||||
if ((*check == '\\') || (*check == '/'))
|
||||
check += 1;
|
||||
|
||||
if ((source == path) || (check != source) || (*target == 0))
|
||||
if ((source == path) || (check != source))
|
||||
{
|
||||
// Skip double paths
|
||||
if ((*check == '\\') || (*check == '/'))
|
||||
@@ -235,7 +275,55 @@ int32_t mz_path_get_filename(const char *path, const char **filename)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_get_file_crc(const char *path, uint32_t *result_crc)
|
||||
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;
|
||||
@@ -277,3 +365,42 @@ int32_t mz_get_file_crc(const char *path, uint32_t *result_crc)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* mz_os.h -- System functions
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -20,7 +20,7 @@ extern "C" {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(MZ_USE_WIN32_API)
|
||||
#if !defined(_WIN32) && !defined(MZ_WIN32_API)
|
||||
#include "mz_os_posix.h"
|
||||
#include "mz_strm_posix.h"
|
||||
#else
|
||||
@@ -45,12 +45,12 @@ extern "C" {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
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_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
|
||||
|
||||
@@ -60,9 +60,15 @@ int32_t mz_path_remove_filename(const char *path);
|
||||
int32_t mz_path_get_filename(const char *path, const char **filename);
|
||||
// Get the filename from a path
|
||||
|
||||
int32_t mz_get_file_crc(const char *path, uint32_t *result_crc);
|
||||
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
|
||||
|
||||
+85
-5
@@ -1,5 +1,5 @@
|
||||
/* mz_os_posix.c -- System functions for posix
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -13,16 +13,22 @@
|
||||
#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 __linux__
|
||||
# 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
|
||||
@@ -34,13 +40,87 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(HAVE_PKCRYPT) || defined(HAVE_AES)
|
||||
#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)
|
||||
{
|
||||
|
||||
+5
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_os_posix.h -- System functions for posix
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -31,6 +31,8 @@ extern "C" {
|
||||
/***************************************************************************/
|
||||
|
||||
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);
|
||||
@@ -47,6 +49,8 @@ int32_t mz_posix_is_dir(const char *path);
|
||||
/***************************************************************************/
|
||||
|
||||
#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
|
||||
|
||||
+41
-3
@@ -1,5 +1,5 @@
|
||||
/* mz_os_win32.c -- System functions for Windows
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -14,9 +14,12 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <direct.h>
|
||||
#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"
|
||||
|
||||
@@ -42,7 +45,7 @@ typedef struct DIR_int_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(HAVE_PKCRYPT) || defined(HAVE_AES)
|
||||
#if !defined(MZ_ZIP_NO_COMPRESSION) && !defined(MZ_ZIP_NO_ENCRYPTION)
|
||||
int32_t mz_win32_rand(uint8_t *buf, int32_t size)
|
||||
{
|
||||
HCRYPTPROV provider;
|
||||
@@ -93,6 +96,41 @@ void mz_win32_unicode_path_delete(wchar_t **path)
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
+5
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_os_win32.h -- System functions for Windows
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -32,6 +32,8 @@ 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);
|
||||
@@ -48,6 +50,8 @@ int32_t mz_win32_is_dir(const char *path);
|
||||
/***************************************************************************/
|
||||
|
||||
#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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* mz_strm.c -- Stream interface
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -161,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];
|
||||
@@ -230,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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* mz_strm.h -- Stream interface
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -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);
|
||||
|
||||
|
||||
+9
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_aes.c -- Stream for WinZip AES encryption
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -108,12 +108,20 @@ 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);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_aes.h -- Stream for WinZIP AES encryption
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+16
-5
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_buf.c -- Stream for buffering reads/writes
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This version of ioapi is designed to buffer IO.
|
||||
@@ -66,10 +66,24 @@ 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(buffered, "open [mode %d]\n", mode);
|
||||
mz_stream_buffered_reset(buffered);
|
||||
return mz_stream_open(buffered->stream.base, path, mode);
|
||||
}
|
||||
|
||||
@@ -350,10 +364,7 @@ int32_t mz_stream_buffered_close(void *stream)
|
||||
mz_stream_buffered_print(stream, "write efficency %.02f%%\n",
|
||||
(buffered->writebuf_hits / ((float)buffered->writebuf_hits + buffered->writebuf_misses)) * 100);
|
||||
|
||||
buffered->readbuf_len = 0;
|
||||
buffered->readbuf_pos = 0;
|
||||
buffered->writebuf_len = 0;
|
||||
buffered->writebuf_pos = 0;
|
||||
mz_stream_buffered_reset(buffered);
|
||||
|
||||
return mz_stream_close(buffered->stream.base);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_buf.h -- Stream for buffering reads/writes
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This version of ioapi is designed to buffer IO.
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_bzip.c -- Stream for bzip inflate/deflate
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -76,7 +76,7 @@ int32_t mz_stream_bzip_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
bzip->bzstream.next_out = (char *)bzip->buffer;
|
||||
@@ -87,7 +87,7 @@ int32_t mz_stream_bzip_open(void *stream, const char *path, int32_t mode)
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
bzip->bzstream.next_in = (char *)bzip->buffer;
|
||||
@@ -116,7 +116,7 @@ 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_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
@@ -266,7 +266,7 @@ 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;
|
||||
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(bzip);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
@@ -302,7 +302,7 @@ int32_t mz_stream_bzip_close(void *stream)
|
||||
|
||||
if (bzip->mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_bzip_compress(stream, BZ_FINISH);
|
||||
@@ -313,7 +313,7 @@ int32_t mz_stream_bzip_close(void *stream)
|
||||
}
|
||||
else if (bzip->mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
BZ2_bzDecompressEnd(&bzip->bzstream);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_bzip.h -- Stream for bzip inflate/deflate
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_crc32.c -- Stream for CRC32 hashing
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_crc32.h -- Stream for CRC32 hashing
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_lzma.c -- Stream for lzma inflate/deflate
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -83,7 +83,7 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(filters);
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
@@ -112,7 +112,7 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma->lstream.next_in = lzma->buffer;
|
||||
@@ -146,7 +146,7 @@ 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_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
@@ -285,7 +285,7 @@ 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;
|
||||
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(lzma);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
@@ -321,7 +321,7 @@ int32_t mz_stream_lzma_close(void *stream)
|
||||
|
||||
if (lzma->mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_lzma_code(stream, LZMA_FINISH);
|
||||
@@ -332,7 +332,7 @@ int32_t mz_stream_lzma_close(void *stream)
|
||||
}
|
||||
else if (lzma->mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
lzma_end(&lzma->lstream);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_lzma.h -- Stream for lzma inflate/deflate
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+11
-5
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_mem.c -- Stream for memory access
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This interface is designed to access memory rather than files.
|
||||
@@ -48,7 +48,7 @@ static 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
|
||||
@@ -61,10 +61,10 @@ 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 *)MZ_ALLOC(new_size);
|
||||
new_buf = (uint8_t *)MZ_ALLOC(new_size);
|
||||
if (mem->buffer)
|
||||
{
|
||||
memcpy(new_buf, mem->buffer, mem->size);
|
||||
@@ -209,7 +209,7 @@ 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;
|
||||
}
|
||||
@@ -228,6 +228,12 @@ int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, const void *
|
||||
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;
|
||||
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_mem.h -- Stream for memory access
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -32,6 +32,7 @@ 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, 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);
|
||||
|
||||
+17
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_pkcrypt.c -- Code for traditional PKWARE encryption
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -158,6 +158,12 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
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);
|
||||
|
||||
@@ -172,9 +178,18 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
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;
|
||||
|
||||
@@ -190,6 +205,7 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
return MZ_PASSWORD_ERROR;
|
||||
|
||||
pkcrypt->total_in += RAND_HEAD_LEN;
|
||||
#endif
|
||||
}
|
||||
|
||||
pkcrypt->initialized = 1;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_pkcrypt.h -- Code for traditional PKWARE encryption
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_posix.c -- Stream for filesystem access for posix/linux
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(MZ_USE_FILE32API)
|
||||
#if defined(MZ_FILE32_API)
|
||||
# define fopen64 fopen
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_posix.h -- Stream for filesystem access for posix/linux
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -36,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
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_split.c -- Stream for split files
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_split.h -- Stream for split files
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_win32.c -- Stream for filesystem access for windows
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/* mz_sstrm_win32.h -- Stream for filesystem access for windows
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -36,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
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_zlib.c -- Stream for zlib inflate/deflate
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -93,7 +93,7 @@ int32_t mz_stream_zlib_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
zlib->zstream.next_out = zlib->buffer;
|
||||
@@ -104,7 +104,7 @@ int32_t mz_stream_zlib_open(void *stream, const char *path, int32_t mode)
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
zlib->zstream.next_in = zlib->buffer;
|
||||
@@ -132,7 +132,7 @@ 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_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
@@ -277,7 +277,7 @@ 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;
|
||||
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
MZ_UNUSED(zlib);
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
@@ -314,7 +314,7 @@ int32_t mz_stream_zlib_close(void *stream)
|
||||
|
||||
if (zlib->mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
#ifdef MZ_ZIP_DECOMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_COMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
mz_stream_zlib_deflate(stream, Z_FINISH);
|
||||
@@ -325,7 +325,7 @@ int32_t mz_stream_zlib_close(void *stream)
|
||||
}
|
||||
else if (zlib->mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
#ifdef MZ_ZIP_COMPRESS_ONLY
|
||||
#ifdef MZ_ZIP_NO_DECOMPRESSION
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
inflateEnd(&zlib->zstream);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* mz_zip.h -- Zip manipulation
|
||||
Version 2.3.7, July 13, 2018
|
||||
Version 2.5.2, August 27, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
@@ -49,91 +49,127 @@ typedef struct mz_zip_file_s
|
||||
uint32_t external_fa; // external file attributes
|
||||
uint16_t zip64; // zip64 extension mode
|
||||
|
||||
const char *filename; // filename string
|
||||
const char *filename; // filename utf8 null-terminated string
|
||||
const uint8_t *extrafield; // extrafield data
|
||||
const char *comment; // comment string
|
||||
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_file, mz_zip_entry;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern void * mz_zip_open(void *stream, int32_t mode);
|
||||
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
|
||||
|
||||
extern int32_t mz_zip_close(void *handle);
|
||||
int32_t mz_zip_close(void *handle);
|
||||
// Close the zip file
|
||||
|
||||
extern int32_t mz_zip_get_comment(void *handle, const char **comment);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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
|
||||
|
||||
extern int32_t mz_zip_entry_write(void *handle, const void *buf, uint32_t len);
|
||||
int32_t mz_zip_entry_write(void *handle, const void *buf, int32_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);
|
||||
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
|
||||
|
||||
extern int32_t mz_zip_entry_read(void *handle, void *buf, uint32_t len);
|
||||
int32_t mz_zip_entry_read(void *handle, void *buf, int32_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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
int32_t mz_zip_get_number_entry(void *handle, int64_t *number_entry);
|
||||
// Get the total number of entries
|
||||
|
||||
extern int32_t mz_zip_get_disk_number_with_cd(void *handle, uint32_t *disk_number_with_cd);
|
||||
int32_t mz_zip_get_disk_number_with_cd(void *handle, uint32_t *disk_number_with_cd);
|
||||
// Get the the disk number containing the central directory record
|
||||
|
||||
extern int64_t mz_zip_get_entry(void *handle);
|
||||
int64_t mz_zip_get_entry(void *handle);
|
||||
// Return offset of the current entry in the zip file
|
||||
|
||||
extern int32_t mz_zip_goto_entry(void *handle, uint64_t cd_pos);
|
||||
int32_t mz_zip_goto_entry(void *handle, uint64_t cd_pos);
|
||||
// Go to specified entry in the zip file
|
||||
|
||||
extern int32_t mz_zip_goto_first_entry(void *handle);
|
||||
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);
|
||||
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);
|
||||
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 attributes, int32_t version_madeby);
|
||||
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
|
||||
|
||||
@@ -157,6 +193,11 @@ int32_t mz_zip_unix_to_ntfs_time(time_t unix_time, uint64_t *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
|
||||
|
||||
+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
|
||||
@@ -199,4 +199,3 @@ sfx_zip_test()
|
||||
compression_method_tests()
|
||||
encryption_tests()
|
||||
compression_method_tests('Disk Span', '-k 1024', '')
|
||||
compression_method_tests('Buffered', '-u', '-u')
|
||||
|
||||
Reference in New Issue
Block a user