Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55e4fe414e | ||
|
|
5bb372d495 | ||
|
|
a86a4355da | ||
|
|
c9fd8d4df0 | ||
|
|
02123b82d5 | ||
|
|
7140c588c6 | ||
|
|
f60a99bd90 | ||
|
|
50fd547660 | ||
|
|
2fa05a7264 | ||
|
|
1a20b75c46 | ||
|
|
dab094fc31 | ||
|
|
13a12e32ab | ||
|
|
73418b7e05 | ||
|
|
3f7de8e289 | ||
|
|
18a30653b1 | ||
|
|
b73887478a | ||
|
|
51fb0afc82 | ||
|
|
a45fa6b8a0 | ||
|
|
6c6700d2f4 | ||
|
|
0574424b05 | ||
|
|
919d837abf | ||
|
|
12db0fc415 | ||
|
|
e4bd6d3191 | ||
|
|
f9749af452 | ||
|
|
02a516944d | ||
|
|
0d4ae83bd2 | ||
|
|
d15b013734 | ||
|
|
7e49256146 | ||
|
|
97a759a14b | ||
|
|
a3dc63a17f | ||
|
|
be85b3b4cd | ||
|
|
3da621e118 | ||
|
|
211f14074a | ||
|
|
819d0d56f0 | ||
|
|
fa7fadebfa | ||
|
|
a6e7d468e3 | ||
|
|
b8f7cf0fa7 | ||
|
|
886df95632 | ||
|
|
80c2d56436 | ||
|
|
4f6a0e3fc1 | ||
|
|
91a76f61c9 | ||
|
|
0cdc6af8cd | ||
|
|
6186dd6dc6 | ||
|
|
bf26d0e7f7 | ||
|
|
2aa8ed38a2 | ||
|
|
b1b25804fc | ||
|
|
053d00c451 | ||
|
|
b579191d9f |
No files matched your search
+1
-1
@@ -23,4 +23,4 @@ before_script:
|
||||
script:
|
||||
- make
|
||||
- cd ../test
|
||||
- python test.py --exe_dir=../build
|
||||
- travis_wait 30 python test.py --exe_dir=../build
|
||||
+28
-18
@@ -5,11 +5,12 @@
|
||||
#***************************************************************************
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
option(USE_CRYPT "Enables building with PKWARE traditional encryption" ON)
|
||||
option(USE_AES "Enables building with AES library" ON)
|
||||
option(USE_ZLIB "Enables building with ZLIB library" ON)
|
||||
option(USE_BZIP2 "Enables building with BZIP2 library" ON)
|
||||
option(USE_LZMA "Enables building with LZMA library" ON)
|
||||
option(BUILD_TEST "Enables building of executables. Requires ZLIB!" OFF)
|
||||
option(USE_CRYPT "Enables building with PKWARE traditional encryption" ON)
|
||||
option(USE_AES "Enables building with AES library" ON)
|
||||
option(BUILD_TEST "Enables building of minizip executable." OFF)
|
||||
|
||||
# Set a consistent MACOSX_RPATH default across all CMake versions.
|
||||
# When CMake 2.8.12 is required, change this default to 1.
|
||||
@@ -26,16 +27,18 @@ set(INSTALL_PKGCONFIG_DIR "share/pkgconfig" CACHE PATH "Installation directory f
|
||||
|
||||
project("minizip")
|
||||
|
||||
set(VERSION "2.2.3")
|
||||
set(VERSION "2.2.5")
|
||||
|
||||
# Set cmake debug postfix to d
|
||||
set(CMAKE_DEBUG_POSTFIX "d")
|
||||
|
||||
# Ensure correct version of zlib is referenced
|
||||
set(ZLIB_ROOT ${DEF_ZLIB_ROOT} CACHE PATH "Parent directory of zlib installation")
|
||||
find_package(ZLIB REQUIRED)
|
||||
if(ZLIB_FOUND)
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
if(USE_ZLIB)
|
||||
set(ZLIB_ROOT ${DEF_ZLIB_ROOT} CACHE PATH "Parent directory of zlib installation")
|
||||
find_package(ZLIB REQUIRED)
|
||||
if(ZLIB_FOUND)
|
||||
include_directories(${ZLIB_INCLUDE_DIRS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(MINIZIP_PC ${CMAKE_CURRENT_BINARY_DIR}/minizip.pc)
|
||||
@@ -78,7 +81,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O3")
|
||||
add_compile_options(-fPIC -O3)
|
||||
|
||||
list(APPEND MINIZIP_SRC "src/mz_os_posix.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "src/mz_os_posix.h")
|
||||
@@ -86,14 +89,16 @@ if(UNIX)
|
||||
add_definitions(-D__USE_FILE_OFFSET64)
|
||||
add_definitions(-D__USE_LARGEFILE64)
|
||||
add_definitions(-D_LARGEFILE64_SOURCE)
|
||||
add_definitions(-D_FILE_OFFSET_BIT=64)
|
||||
add_definitions(-D_FILE_OFFSET_BITS=64)
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
||||
pkg_check_modules(LIBBSD libbsd)
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
pkg_check_modules(LIBBSD libbsd REQUIRED)
|
||||
|
||||
include_directories(${LIBBSD_INCLUDE_DIRS})
|
||||
link_directories(${LIBBSD_LIBRARY_DIRS})
|
||||
include_directories(${LIBBSD_INCLUDE_DIRS})
|
||||
link_directories(${LIBBSD_LIBRARY_DIRS})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(USE_CRYPT)
|
||||
@@ -114,7 +119,6 @@ if(USE_AES)
|
||||
lib/aes/aeskey.c
|
||||
lib/aes/aestab.c
|
||||
lib/aes/aes_ni.c
|
||||
lib/aes/fileenc.c
|
||||
lib/aes/hmac.c
|
||||
lib/aes/pwd2key.c
|
||||
lib/aes/sha1.c)
|
||||
@@ -126,7 +130,6 @@ if(USE_AES)
|
||||
lib/aes/aestab.h
|
||||
lib/aes/brg_endian.h
|
||||
lib/aes/brg_types.h
|
||||
lib/aes/fileenc.h
|
||||
lib/aes/hmac.h
|
||||
lib/aes/pwd2key.h
|
||||
lib/aes/sha1.h)
|
||||
@@ -136,6 +139,9 @@ if(USE_AES)
|
||||
source_group("AES" FILES ${AES_SRC} ${AES_PUBLIC_HEADERS})
|
||||
endif()
|
||||
|
||||
if(USE_ZLIB)
|
||||
add_definitions(-DHAVE_ZLIB)
|
||||
endif()
|
||||
if(USE_BZIP2)
|
||||
add_definitions(-DHAVE_BZIP2)
|
||||
add_definitions(-DBZ_NO_STDIO)
|
||||
@@ -171,6 +177,7 @@ if(USE_LZMA)
|
||||
|
||||
set(LZMA_CHECK_SRC
|
||||
lib/liblzma/check/check.c
|
||||
lib/liblzma/check/crc32_fast.c
|
||||
lib/liblzma/check/crc32_table.c)
|
||||
set(LZMA_COMMON_SRC
|
||||
lib/liblzma/common/alone_decoder.c
|
||||
@@ -206,7 +213,8 @@ if(USE_LZMA)
|
||||
set(LZMA_CHECK_HEADERS
|
||||
lib/liblzma/check/check.h
|
||||
lib/liblzma/check/crc32_table_be.h
|
||||
lib/liblzma/check/crc32_table_le.h)
|
||||
lib/liblzma/check/crc32_table_le.h
|
||||
lib/liblzma/check/crc_macros.h)
|
||||
set(LZMA_COMMON_HEADERS
|
||||
lib/liblzma/common/alone_decoder.h
|
||||
lib/liblzma/common/common.h
|
||||
@@ -268,7 +276,7 @@ if(USE_LZMA)
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER MATCHES ".*clang")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3 -msse4.1 -maes")
|
||||
add_compile_options(-msse3 -msse4.1 -maes)
|
||||
endif()
|
||||
|
||||
# Create minizip library
|
||||
@@ -281,10 +289,12 @@ add_library(${PROJECT_NAME}
|
||||
${LZMA_SRC} ${LZMA_PUBLIC_HEADERS})
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C PREFIX "")
|
||||
if(USE_ZLIB)
|
||||
target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)
|
||||
endif()
|
||||
if(USE_LZMA)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 99)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)
|
||||
if(UNIX)
|
||||
target_link_libraries(${PROJECT_NAME} ${LIBBSD_LIBRARIES})
|
||||
endif()
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'Minizip'
|
||||
s.version = '2.2.3'
|
||||
s.version = '2.2.5'
|
||||
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.2.3
|
||||
# Minizip 2.2.5
|
||||
|
||||
This library is a refactoring of the minizip contribution found in the zlib distribution that is supported on Windows, macOS, and Linux. The motivation for this work has been the inclusion of advanced features, improvements in code maintainability and readability, and the reduction of duplicate code. It is based on the original work of [Gilles Vollant](http://www.winimage.com/zLibDll/minizip.html) that has been contributed to by many people over the years.
|
||||
|
||||
@@ -57,7 +57,7 @@ cmake --build .
|
||||
#### [WinZIP AES Encryption](http://www.winzip.com/aes_info.htm)
|
||||
|
||||
+ Requires ``cmake . -DUSE_AES=ON`` or ``#define HAVE_AES``
|
||||
+ Requires [Brian Gladman's](https://github.com/BrianGladman/aes) AES library
|
||||
+ Requires Brian Gladman's [AES](https://github.com/BrianGladman/aes) and [SHA](https://github.com/BrianGladman/sha) libraries
|
||||
|
||||
When zipping with a password it will always use AES 256-bit encryption.
|
||||
When unzipping it will use AES decryption only if necessary.
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
||||
All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software in both source and binary
|
||||
form is allowed (with or without changes) provided that:
|
||||
|
||||
1. distributions of this source code include the above copyright
|
||||
notice, this list of conditions and the following disclaimer;
|
||||
|
||||
2. distributions in binary form include the above copyright
|
||||
notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other associated materials;
|
||||
|
||||
3. the copyright holder's name is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
ALTERNATIVELY, provided that this notice is retained in full, this product
|
||||
may be distributed under the terms of the GNU General Public License (GPL),
|
||||
in which case the provisions of the GPL apply INSTEAD OF those given above.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
-------------------------------------------------------------------------
|
||||
Issue Date: 24/01/2003
|
||||
|
||||
This file implements password based file encryption and authentication
|
||||
using AES in CTR mode, HMAC-SHA1 authentication and RFC2898 password
|
||||
based key derivation.
|
||||
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "fileenc.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* subroutine for data encryption/decryption */
|
||||
/* this could be speeded up a lot by aligning */
|
||||
/* buffers and using 32 bit operations */
|
||||
|
||||
static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1])
|
||||
{
|
||||
unsigned int i = 0, pos = cx->encr_pos;
|
||||
|
||||
while (i < d_len)
|
||||
{
|
||||
if (pos == AES_BLOCK_SIZE)
|
||||
{
|
||||
unsigned int j = 0;
|
||||
/* increment encryption nonce */
|
||||
while (j < 8 && !++cx->nonce[j])
|
||||
++j;
|
||||
/* encrypt the nonce to form next xor buffer */
|
||||
aes_encrypt(cx->nonce, cx->encr_bfr, cx->encr_ctx);
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
data[i++] ^= cx->encr_bfr[pos++];
|
||||
}
|
||||
|
||||
cx->encr_pos = pos;
|
||||
}
|
||||
|
||||
int fcrypt_init(
|
||||
int mode, /* the mode to be used (input) */
|
||||
const unsigned char pwd[], /* the user specified password (input) */
|
||||
unsigned int pwd_len, /* the length of the password (input) */
|
||||
const unsigned char salt[], /* the salt (input) */
|
||||
#ifdef PASSWORD_VERIFIER
|
||||
unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */
|
||||
#endif
|
||||
fcrypt_ctx cx[1]) /* the file encryption context (output) */
|
||||
{ unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH];
|
||||
|
||||
if (pwd_len > MAX_PWD_LENGTH)
|
||||
return PASSWORD_TOO_LONG;
|
||||
|
||||
if (mode < 1 || mode > 3)
|
||||
return BAD_MODE;
|
||||
|
||||
cx->mode = mode;
|
||||
cx->pwd_len = pwd_len;
|
||||
|
||||
/* derive the encryption and authentication keys and the password verifier */
|
||||
derive_key(pwd, pwd_len, salt, SALT_LENGTH(mode), KEYING_ITERATIONS,
|
||||
kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH);
|
||||
|
||||
/* initialise the encryption nonce and buffer pos */
|
||||
cx->encr_pos = AES_BLOCK_SIZE;
|
||||
/* if we need a random component in the encryption */
|
||||
/* nonce, this is where it would have to be set */
|
||||
memset(cx->nonce, 0, AES_BLOCK_SIZE * sizeof(unsigned char));
|
||||
|
||||
/* initialise for encryption using key 1 */
|
||||
aes_encrypt_key(kbuf, KEY_LENGTH(mode), cx->encr_ctx);
|
||||
|
||||
/* initialise for authentication using key 2 */
|
||||
hmac_sha_begin(HMAC_SHA1, cx->auth_ctx);
|
||||
hmac_sha_key(kbuf + KEY_LENGTH(mode), KEY_LENGTH(mode), cx->auth_ctx);
|
||||
|
||||
#ifdef PASSWORD_VERIFIER
|
||||
memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH);
|
||||
#endif
|
||||
|
||||
return GOOD_RETURN;
|
||||
}
|
||||
|
||||
/* perform 'in place' encryption and authentication */
|
||||
|
||||
void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1])
|
||||
{
|
||||
encr_data(data, data_len, cx);
|
||||
hmac_sha_data(data, data_len, cx->auth_ctx);
|
||||
}
|
||||
|
||||
/* perform 'in place' authentication and decryption */
|
||||
|
||||
void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1])
|
||||
{
|
||||
hmac_sha_data(data, data_len, cx->auth_ctx);
|
||||
encr_data(data, data_len, cx);
|
||||
}
|
||||
|
||||
/* close encryption/decryption and return the MAC value */
|
||||
|
||||
int fcrypt_end(unsigned char mac[], fcrypt_ctx cx[1])
|
||||
{
|
||||
hmac_sha_end(mac, MAC_LENGTH(cx->mode), cx->auth_ctx);
|
||||
return MAC_LENGTH(cx->mode); /* return MAC length in bytes */
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK.
|
||||
All rights reserved.
|
||||
|
||||
LICENSE TERMS
|
||||
|
||||
The free distribution and use of this software in both source and binary
|
||||
form is allowed (with or without changes) provided that:
|
||||
|
||||
1. distributions of this source code include the above copyright
|
||||
notice, this list of conditions and the following disclaimer;
|
||||
|
||||
2. distributions in binary form include the above copyright
|
||||
notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other associated materials;
|
||||
|
||||
3. the copyright holder's name is not used to endorse products
|
||||
built using this software without specific written permission.
|
||||
|
||||
ALTERNATIVELY, provided that this notice is retained in full, this product
|
||||
may be distributed under the terms of the GNU General Public License (GPL),
|
||||
in which case the provisions of the GPL apply INSTEAD OF those given above.
|
||||
|
||||
DISCLAIMER
|
||||
|
||||
This software is provided 'as is' with no explicit or implied warranties
|
||||
in respect of its properties, including, but not limited to, correctness
|
||||
and/or fitness for purpose.
|
||||
---------------------------------------------------------------------------
|
||||
Issue Date: 24/01/2003
|
||||
|
||||
This file contains the header file for fileenc.c, which implements password
|
||||
based file encryption and authentication using AES in CTR mode, HMAC-SHA1
|
||||
authentication and RFC2898 password based key derivation.
|
||||
*/
|
||||
|
||||
#ifndef _FENC_H
|
||||
#define _FENC_H
|
||||
|
||||
#include "aes.h"
|
||||
#include "hmac.h"
|
||||
#include "pwd2key.h"
|
||||
|
||||
#define PASSWORD_VERIFIER
|
||||
|
||||
#define MAX_KEY_LENGTH 32
|
||||
#define MAX_PWD_LENGTH 128
|
||||
#define MAX_SALT_LENGTH 16
|
||||
#define KEYING_ITERATIONS 1000
|
||||
|
||||
#ifdef PASSWORD_VERIFIER
|
||||
#define PWD_VER_LENGTH 2
|
||||
#else
|
||||
#define PWD_VER_LENGTH 0
|
||||
#endif
|
||||
|
||||
#define GOOD_RETURN 0
|
||||
#define PASSWORD_TOO_LONG -100
|
||||
#define BAD_MODE -101
|
||||
|
||||
/*
|
||||
Field lengths (in bytes) versus File Encryption Mode (0 < mode < 4)
|
||||
|
||||
Mode Key Salt MAC Overhead
|
||||
1 16 8 10 18
|
||||
2 24 12 10 22
|
||||
3 32 16 10 26
|
||||
|
||||
The following macros assume that the mode value is correct.
|
||||
*/
|
||||
|
||||
#define KEY_LENGTH(mode) (8 * (mode & 3) + 8)
|
||||
#define SALT_LENGTH(mode) (4 * (mode & 3) + 4)
|
||||
#define MAC_LENGTH(mode) (10)
|
||||
|
||||
/* the context for file encryption */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{ unsigned char nonce[AES_BLOCK_SIZE]; /* the CTR nonce */
|
||||
unsigned char encr_bfr[AES_BLOCK_SIZE]; /* encrypt buffer */
|
||||
aes_encrypt_ctx encr_ctx[1]; /* encryption context */
|
||||
hmac_ctx auth_ctx[1]; /* authentication context */
|
||||
unsigned int encr_pos; /* block position (enc) */
|
||||
unsigned int pwd_len; /* password length */
|
||||
unsigned int mode; /* File encryption mode */
|
||||
} fcrypt_ctx;
|
||||
|
||||
/* initialise file encryption or decryption */
|
||||
|
||||
int fcrypt_init(
|
||||
int mode, /* the mode to be used (input) */
|
||||
const unsigned char pwd[], /* the user specified password (input) */
|
||||
unsigned int pwd_len, /* the length of the password (input) */
|
||||
const unsigned char salt[], /* the salt (input) */
|
||||
#ifdef PASSWORD_VERIFIER
|
||||
unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */
|
||||
#endif
|
||||
fcrypt_ctx cx[1]); /* the file encryption context (output) */
|
||||
|
||||
/* perform 'in place' encryption or decryption and authentication */
|
||||
|
||||
void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]);
|
||||
void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]);
|
||||
|
||||
/* close encryption/decryption and return the MAC value */
|
||||
/* the return value is the length of the MAC */
|
||||
|
||||
int fcrypt_end(unsigned char mac[], /* the MAC value (output) */
|
||||
fcrypt_ctx cx[1]); /* the context (input) */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -23,6 +23,7 @@ a password and a salt value.
|
||||
|
||||
#include <string.h>
|
||||
#include "hmac.h"
|
||||
#include "pwd2key.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc32.c
|
||||
/// \brief CRC32 calculation
|
||||
///
|
||||
/// Calculate the CRC32 using the slice-by-eight algorithm.
|
||||
/// It is explained in this document:
|
||||
/// http://www.intel.com/technology/comms/perfnet/download/CRC_generators.pdf
|
||||
/// The code in this file is not the same as in Intel's paper, but
|
||||
/// the basic principle is identical.
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "check.h"
|
||||
#include "crc_macros.h"
|
||||
|
||||
|
||||
// If you make any changes, do some bench marking! Seemingly unrelated
|
||||
// changes can very easily ruin the performance (and very probably is
|
||||
// very compiler dependent).
|
||||
extern LZMA_API(uint32_t)
|
||||
lzma_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
{
|
||||
crc = ~crc;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
crc = bswap32(crc);
|
||||
#endif
|
||||
|
||||
if (size > 8) {
|
||||
// Fix the alignment, if needed. The if statement above
|
||||
// ensures that this won't read past the end of buf[].
|
||||
while ((uintptr_t)(buf) & 7) {
|
||||
crc = lzma_crc32_table[0][*buf++ ^ A(crc)] ^ S8(crc);
|
||||
--size;
|
||||
}
|
||||
|
||||
// Calculate the position where to stop.
|
||||
const uint8_t *const limit = buf + (size & ~(size_t)(7));
|
||||
|
||||
// Calculate how many bytes must be calculated separately
|
||||
// before returning the result.
|
||||
size &= (size_t)(7);
|
||||
|
||||
// Calculate the CRC32 using the slice-by-eight algorithm.
|
||||
while (buf < limit) {
|
||||
crc ^= *(const uint32_t *)(buf);
|
||||
buf += 4;
|
||||
|
||||
crc = lzma_crc32_table[7][A(crc)]
|
||||
^ lzma_crc32_table[6][B(crc)]
|
||||
^ lzma_crc32_table[5][C(crc)]
|
||||
^ lzma_crc32_table[4][D(crc)];
|
||||
|
||||
const uint32_t tmp = *(const uint32_t *)(buf);
|
||||
buf += 4;
|
||||
|
||||
// At least with some compilers, it is critical for
|
||||
// performance, that the crc variable is XORed
|
||||
// between the two table-lookup pairs.
|
||||
crc = lzma_crc32_table[3][A(tmp)]
|
||||
^ lzma_crc32_table[2][B(tmp)]
|
||||
^ crc
|
||||
^ lzma_crc32_table[1][C(tmp)]
|
||||
^ lzma_crc32_table[0][D(tmp)];
|
||||
}
|
||||
}
|
||||
|
||||
while (size-- != 0)
|
||||
crc = lzma_crc32_table[0][*buf++ ^ A(crc)] ^ S8(crc);
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
crc = bswap32(crc);
|
||||
#endif
|
||||
|
||||
return ~crc;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
/// \file crc_macros.h
|
||||
/// \brief Some endian-dependent macros for CRC32 and CRC64
|
||||
//
|
||||
// Author: Lasse Collin
|
||||
//
|
||||
// This file has been put into the public domain.
|
||||
// You can do whatever you want with this file.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# define A(x) ((x) >> 24)
|
||||
# define B(x) (((x) >> 16) & 0xFF)
|
||||
# define C(x) (((x) >> 8) & 0xFF)
|
||||
# define D(x) ((x) & 0xFF)
|
||||
|
||||
# define S8(x) ((x) << 8)
|
||||
# define S32(x) ((x) << 32)
|
||||
|
||||
#else
|
||||
# define A(x) ((x) & 0xFF)
|
||||
# define B(x) (((x) >> 8) & 0xFF)
|
||||
# define C(x) (((x) >> 16) & 0xFF)
|
||||
# define D(x) ((x) >> 24)
|
||||
|
||||
# define S8(x) ((x) >> 8)
|
||||
# define S32(x) ((x) >> 32)
|
||||
#endif
|
||||
Executable → Regular
+22
-5
@@ -1,5 +1,5 @@
|
||||
/* minizip.c
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_buf.h"
|
||||
#include "mz_strm_split.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
@@ -45,6 +46,7 @@ void minizip_help()
|
||||
" -d Destination directory\n" \
|
||||
" -o Overwrite existing files\n" \
|
||||
" -a Append to existing zip file\n" \
|
||||
" -u Buffered reading and writing\n" \
|
||||
" -j Exclude path of files\n" \
|
||||
" -0 Store only\n" \
|
||||
" -1 Compress faster\n" \
|
||||
@@ -529,6 +531,7 @@ int main(int argc, char *argv[])
|
||||
void *handle = NULL;
|
||||
void *file_stream = NULL;
|
||||
void *split_stream = NULL;
|
||||
void *buf_stream = NULL;
|
||||
char *path = NULL;
|
||||
char *password = NULL;
|
||||
char *destination = NULL;
|
||||
@@ -538,6 +541,7 @@ int main(int argc, char *argv[])
|
||||
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;
|
||||
@@ -572,6 +576,8 @@ int main(int argc, char *argv[])
|
||||
do_extract = 1;
|
||||
if ((c == 'a') || (c == 'A'))
|
||||
append = 1;
|
||||
if ((c == 'u') || (c == 'U'))
|
||||
buffered = 1;
|
||||
if ((c == 'o') || (c == 'O'))
|
||||
options.overwrite = 1;
|
||||
if ((c == 'j') || (c == 'J'))
|
||||
@@ -595,7 +601,7 @@ int main(int argc, char *argv[])
|
||||
if ((c == 's') || (c == 'S'))
|
||||
options.aes = 1;
|
||||
#endif
|
||||
if (((c == 'k') || (c == 'k')) && (i + 1 < argc))
|
||||
if (((c == 'k') || (c == 'K')) && (i + 1 < argc))
|
||||
{
|
||||
disk_size = atoi(argv[i + 1]) * 1024;
|
||||
i += 1;
|
||||
@@ -676,9 +682,19 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
mz_stream_os_create(&file_stream);
|
||||
|
||||
mz_stream_buffered_create(&buf_stream);
|
||||
mz_stream_split_create(&split_stream);
|
||||
mz_stream_set_base(split_stream, file_stream);
|
||||
|
||||
if (buffered)
|
||||
{
|
||||
mz_stream_set_base(buf_stream, file_stream);
|
||||
mz_stream_set_base(split_stream, buf_stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
mz_stream_set_base(split_stream, file_stream);
|
||||
}
|
||||
|
||||
mz_stream_split_set_prop_int64(split_stream, MZ_STREAM_PROP_DISK_SIZE, disk_size);
|
||||
|
||||
err = mz_stream_open(split_stream, path, mode);
|
||||
@@ -734,10 +750,11 @@ int main(int argc, char *argv[])
|
||||
err = err_close;
|
||||
}
|
||||
|
||||
mz_stream_os_close(file_stream);
|
||||
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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* mz.h -- Errors codes, zip flags and magic
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -19,7 +19,7 @@ extern "C" {
|
||||
/***************************************************************************/
|
||||
|
||||
// MZ_VERSION
|
||||
#define MZ_VERSION ("2.2.3")
|
||||
#define MZ_VERSION ("2.2.5")
|
||||
|
||||
// MZ_ERROR
|
||||
#define MZ_OK (0)
|
||||
@@ -34,6 +34,7 @@ extern "C" {
|
||||
#define MZ_CRC_ERROR (-105)
|
||||
#define MZ_CRYPT_ERROR (-106)
|
||||
#define MZ_EXIST_ERROR (-107)
|
||||
#define MZ_PASSWORD_ERROR (-108)
|
||||
|
||||
// MZ_OPEN
|
||||
#define MZ_OPEN_MODE_READ (0x01)
|
||||
@@ -56,6 +57,7 @@ extern "C" {
|
||||
#define MZ_COMPRESS_METHOD_AES (99)
|
||||
|
||||
#define MZ_COMPRESS_LEVEL_DEFAULT (-1)
|
||||
#define MZ_COMPRESS_LEVEL_FAST (2)
|
||||
#define MZ_COMPRESS_LEVEL_NORMAL (6)
|
||||
#define MZ_COMPRESS_LEVEL_BEST (9)
|
||||
|
||||
|
||||
+31
-12
@@ -1,5 +1,5 @@
|
||||
/* mz_compat.c -- Backwards compatible interface for older versions
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -34,12 +34,14 @@ typedef struct mz_compat_s {
|
||||
|
||||
extern zipFile ZEXPORT zipOpen(const char *path, int append)
|
||||
{
|
||||
return zipOpen2(path, append, NULL, mz_stream_os_get_interface());
|
||||
zlib_filefunc64_def pzlib = mz_stream_os_get_interface();
|
||||
return zipOpen2(path, append, NULL, &pzlib);
|
||||
}
|
||||
|
||||
extern zipFile ZEXPORT zipOpen64(const void *path, int append)
|
||||
{
|
||||
return zipOpen2(path, append, NULL, mz_stream_os_get_interface());
|
||||
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,
|
||||
@@ -57,7 +59,7 @@ extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **gl
|
||||
void *handle = NULL;
|
||||
void *stream = NULL;
|
||||
|
||||
if (mz_stream_create(&stream, (mz_stream_vtbl *)pzlib_filefunc_def) == NULL)
|
||||
if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
|
||||
return NULL;
|
||||
|
||||
switch (append)
|
||||
@@ -129,6 +131,9 @@ extern int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, cons
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -227,7 +232,10 @@ extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16
|
||||
err = mz_zip_close(compat->handle);
|
||||
|
||||
if (compat->stream != NULL)
|
||||
{
|
||||
mz_stream_close(compat->stream);
|
||||
mz_stream_delete(&compat->stream);
|
||||
}
|
||||
|
||||
free(compat);
|
||||
|
||||
@@ -243,7 +251,8 @@ extern unzFile ZEXPORT unzOpen(const char *path)
|
||||
|
||||
extern unzFile ZEXPORT unzOpen64(const void *path)
|
||||
{
|
||||
return unzOpen2(path, mz_stream_os_get_interface());
|
||||
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)
|
||||
@@ -258,7 +267,7 @@ extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_
|
||||
void *handle = NULL;
|
||||
void *stream = NULL;
|
||||
|
||||
if (mz_stream_create(&stream, (mz_stream_vtbl *)pzlib_filefunc_def) == NULL)
|
||||
if (mz_stream_create(&stream, (mz_stream_vtbl *)*pzlib_filefunc_def) == NULL)
|
||||
return NULL;
|
||||
|
||||
if (mz_stream_open(stream, path, mode) != MZ_OK)
|
||||
@@ -279,6 +288,7 @@ extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_
|
||||
compat->handle = handle;
|
||||
compat->stream = stream;
|
||||
|
||||
mz_zip_goto_first_entry(compat->handle);
|
||||
return (unzFile)compat;
|
||||
}
|
||||
|
||||
@@ -293,7 +303,10 @@ extern int ZEXPORT unzClose(unzFile file)
|
||||
err = mz_zip_close(compat->handle);
|
||||
|
||||
if (compat->stream != NULL)
|
||||
{
|
||||
mz_stream_close(compat->stream);
|
||||
mz_stream_delete(&compat->stream);
|
||||
}
|
||||
|
||||
free(compat);
|
||||
|
||||
@@ -487,7 +500,10 @@ extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile
|
||||
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 (extrafield_size > 0 && extrafield != NULL)
|
||||
{
|
||||
bytes_to_copy = extrafield_size;
|
||||
@@ -495,12 +511,15 @@ extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile
|
||||
bytes_to_copy = file_info->extrafield_size;
|
||||
memcpy(extrafield, file_info->extrafield, bytes_to_copy);
|
||||
}
|
||||
|
||||
if (comment_size > 0 && comment != NULL)
|
||||
{
|
||||
bytes_to_copy = comment_size;
|
||||
if (bytes_to_copy > file_info->comment_size)
|
||||
bytes_to_copy = file_info->comment_size;
|
||||
memcpy(comment, file_info->comment, bytes_to_copy);
|
||||
if (file_info->comment_size < comment_size)
|
||||
comment[file_info->comment_size] = 0;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
@@ -535,37 +554,37 @@ extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileName
|
||||
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
// NOTE: You should no longer pass in widechar string to open function
|
||||
if (pzlib_filefunc_def != NULL)
|
||||
pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
*pzlib_filefunc_def = mz_stream_os_get_interface();
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_compat.h -- Backwards compatible interface for older versions
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+17
-2
@@ -1,5 +1,5 @@
|
||||
/* mz_os.c -- System functions
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -18,7 +18,12 @@
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_zlib.h"
|
||||
#ifdef HAVE_LZMA
|
||||
# include "mz_strm_lzma.h"
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
# include "mz_strm_zlib.h"
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -106,6 +111,16 @@ int32_t mz_get_file_crc(const char *path, uint32_t *result_crc)
|
||||
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
|
||||
|
||||
mz_stream_crc32_create(&crc32_stream);
|
||||
#ifdef HAVE_ZLIB
|
||||
mz_stream_crc32_set_update_func(crc32_stream,
|
||||
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update());
|
||||
#elif defined(HAVE_LZMA)
|
||||
mz_stream_crc32_set_update_func(crc32_stream,
|
||||
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update());
|
||||
#else
|
||||
#error ZLIB or LZMA required for CRC32
|
||||
#endif
|
||||
|
||||
mz_stream_crc32_open(crc32_stream, NULL, MZ_OPEN_MODE_READ);
|
||||
|
||||
mz_stream_set_base(crc32_stream, stream);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_os.h -- System functions
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/* mz_os_posix.c -- System functions for posix
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -21,8 +21,10 @@
|
||||
# include <unistd.h>
|
||||
# include <utime.h>
|
||||
#endif
|
||||
#if defined unix
|
||||
#if defined __linux__
|
||||
# include <bsd/stdlib.h>
|
||||
#else
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "mz.h"
|
||||
@@ -63,10 +65,8 @@ int64_t mz_posix_get_file_size(const char *path)
|
||||
int32_t mz_posix_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date)
|
||||
{
|
||||
struct stat stat_info;
|
||||
struct tm *filedate = NULL;
|
||||
char *name = NULL;
|
||||
size_t len = 0;
|
||||
time_t tm_t = 0;
|
||||
int32_t err = MZ_INTERNAL_ERROR;
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_os_posix.h -- System functions for posix
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+1
-2
@@ -1,5 +1,5 @@
|
||||
/* mz_os_win32.c -- System functions for Windows
|
||||
Version 2.2.0, October 22nd, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -113,7 +113,6 @@ int64_t mz_win32_get_file_size(const char *path)
|
||||
HANDLE handle = NULL;
|
||||
LARGE_INTEGER large_size;
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_path_create(path);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_os_win32.h -- System functions for Windows
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
Executable → Regular
+301
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm.c -- Stream interface
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -267,3 +267,303 @@ void mz_stream_delete(void **stream)
|
||||
strm->vtbl->destroy(stream);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_crc32_vtbl = {
|
||||
mz_stream_crc32_open,
|
||||
mz_stream_crc32_is_open,
|
||||
mz_stream_crc32_read,
|
||||
mz_stream_crc32_write,
|
||||
mz_stream_crc32_tell,
|
||||
mz_stream_crc32_seek,
|
||||
mz_stream_crc32_close,
|
||||
mz_stream_crc32_error,
|
||||
mz_stream_crc32_create,
|
||||
mz_stream_crc32_delete,
|
||||
mz_stream_crc32_get_prop_int64
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_crc32_s {
|
||||
mz_stream stream;
|
||||
int8_t initialized;
|
||||
int32_t value;
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
|
||||
mz_stream_crc32_update update;
|
||||
} mz_stream_crc32;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_crc32_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->initialized = 1;
|
||||
crc32->value = 0;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_is_open(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
if (crc32->initialized != 1)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
|
||||
int32_t read = 0;
|
||||
read = mz_stream_read(crc32x->stream.base, buf, size);
|
||||
if (read > 0)
|
||||
crc32x->value = crc32x->update(crc32x->value, buf, read);
|
||||
crc32x->total_in += read;
|
||||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
|
||||
int32_t written = 0;
|
||||
crc32x->value = crc32x->update(crc32x->value, buf, size);
|
||||
written = mz_stream_write(crc32x->stream.base, buf, size);
|
||||
crc32x->total_out += written;
|
||||
return written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_crc32_tell(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return mz_stream_tell(crc32->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->value = 0;
|
||||
return mz_stream_seek(crc32->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_close(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->initialized = 0;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_error(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return mz_stream_error(crc32->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_get_value(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return crc32->value;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = crc32->total_in;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = crc32->total_out;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_set_update_func(void *stream, mz_stream_crc32_update update)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->update = update;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_stream_crc32_create(void **stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = NULL;
|
||||
|
||||
crc32 = (mz_stream_crc32 *)malloc(sizeof(mz_stream_crc32));
|
||||
if (crc32 != NULL)
|
||||
{
|
||||
memset(crc32, 0, sizeof(mz_stream_crc32));
|
||||
crc32->stream.vtbl = &mz_stream_crc32_vtbl;
|
||||
}
|
||||
if (stream != NULL)
|
||||
*stream = crc32;
|
||||
|
||||
return crc32;
|
||||
}
|
||||
|
||||
void mz_stream_crc32_delete(void **stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = NULL;
|
||||
if (stream == NULL)
|
||||
return;
|
||||
crc32 = (mz_stream_crc32 *)*stream;
|
||||
if (crc32 != NULL)
|
||||
free(crc32);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_crc32_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_crc32_vtbl;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_raw_s {
|
||||
mz_stream stream;
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
int64_t max_total_in;
|
||||
} mz_stream_raw;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_raw_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_is_open(void *stream)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
return mz_stream_is_open(raw->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
int32_t bytes_to_read = size;
|
||||
int32_t read = 0;
|
||||
|
||||
if (raw->max_total_in > 0)
|
||||
{
|
||||
if ((raw->max_total_in - raw->total_in) < size)
|
||||
bytes_to_read = (int32_t)(raw->max_total_in - raw->total_in);
|
||||
}
|
||||
|
||||
read = mz_stream_read(raw->stream.base, buf, bytes_to_read);
|
||||
|
||||
if (read > 0)
|
||||
raw->total_in += read;
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
int32_t written = mz_stream_write(raw->stream.base, buf, size);
|
||||
if (written > 0)
|
||||
raw->total_out += written;
|
||||
return written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_raw_tell(void *stream)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
return mz_stream_tell(raw->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
return mz_stream_seek(raw->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_close(void *stream)
|
||||
{
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_error(void *stream)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
return mz_stream_error(raw->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = raw->total_in;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = raw->total_out;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
raw->max_total_in = value;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_raw_vtbl = {
|
||||
mz_stream_raw_open,
|
||||
mz_stream_raw_is_open,
|
||||
mz_stream_raw_read,
|
||||
mz_stream_raw_write,
|
||||
mz_stream_raw_tell,
|
||||
mz_stream_raw_seek,
|
||||
mz_stream_raw_close,
|
||||
mz_stream_raw_error,
|
||||
mz_stream_raw_create,
|
||||
mz_stream_raw_delete,
|
||||
mz_stream_raw_get_prop_int64,
|
||||
mz_stream_raw_set_prop_int64
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void *mz_stream_raw_create(void **stream)
|
||||
{
|
||||
mz_stream_raw *raw = NULL;
|
||||
|
||||
raw = (mz_stream_raw *)malloc(sizeof(mz_stream_raw));
|
||||
if (raw != NULL)
|
||||
{
|
||||
memset(raw, 0, sizeof(mz_stream_raw));
|
||||
raw->stream.vtbl = &mz_stream_raw_vtbl;
|
||||
}
|
||||
if (stream != NULL)
|
||||
*stream = raw;
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
void mz_stream_raw_delete(void **stream)
|
||||
{
|
||||
mz_stream_raw *raw = NULL;
|
||||
if (stream == NULL)
|
||||
return;
|
||||
raw = (mz_stream_raw *)*stream;
|
||||
if (raw != NULL)
|
||||
free(raw);
|
||||
*stream = NULL;
|
||||
}
|
||||
Executable → Regular
+41
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm.h -- Stream interface
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -99,6 +99,46 @@ void mz_stream_delete(void **stream);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef int32_t (*mz_stream_crc32_update)(int32_t value, const void *buf, int32_t size);
|
||||
|
||||
int32_t mz_stream_crc32_open(void *stream, const char *filename, int32_t mode);
|
||||
int32_t mz_stream_crc32_is_open(void *stream);
|
||||
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size);
|
||||
int64_t mz_stream_crc32_tell(void *stream);
|
||||
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_crc32_close(void *stream);
|
||||
int32_t mz_stream_crc32_error(void *stream);
|
||||
|
||||
int32_t mz_stream_crc32_get_value(void *stream);
|
||||
|
||||
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
int32_t mz_stream_crc32_set_update_func(void *stream, mz_stream_crc32_update update);
|
||||
|
||||
void* mz_stream_crc32_create(void **stream);
|
||||
void mz_stream_crc32_delete(void **stream);
|
||||
|
||||
void* mz_stream_crc32_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_raw_open(void *stream, const char *filename, int32_t mode);
|
||||
int32_t mz_stream_raw_is_open(void *stream);
|
||||
int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_raw_write(void *stream, const void *buf, int32_t size);
|
||||
int64_t mz_stream_raw_tell(void *stream);
|
||||
int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_raw_close(void *stream);
|
||||
int32_t mz_stream_raw_error(void *stream);
|
||||
|
||||
int32_t mz_stream_raw_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value);
|
||||
|
||||
void* mz_stream_raw_create(void **stream);
|
||||
void mz_stream_raw_delete(void **stream);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+130
-58
@@ -1,9 +1,10 @@
|
||||
/* mz_strm_aes.c -- Stream for WinZip AES encryption
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Brian Gladman, Worcester, UK
|
||||
|
||||
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.
|
||||
@@ -15,7 +16,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "aes.h"
|
||||
#include "fileenc.h"
|
||||
#include "hmac.h"
|
||||
#include "pwd2key.h"
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
@@ -24,9 +26,15 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_AES_PWVERIFYSIZE (2)
|
||||
#define MZ_AES_AUTHCODESIZE (10)
|
||||
#define MZ_AES_MAXSALTLENGTH (16)
|
||||
#define MZ_AES_KEY_LENGTH(mode) (8 * (mode & 3) + 8)
|
||||
#define MZ_AES_KEY_LENGTH_MAX (32)
|
||||
#define MZ_AES_KEYING_ITERATIONS (1000)
|
||||
#define MZ_AES_SALT_LENGTH(mode) (4 * (mode & 3) + 4)
|
||||
#define MZ_AES_SALT_LENGTH_MAX (16)
|
||||
#define MZ_AES_MAC_LENGTH(mode) (10)
|
||||
#define MZ_AES_PW_LENGTH_MAX (128)
|
||||
#define MZ_AES_PW_VERIFY_SIZE (2)
|
||||
#define MZ_AES_AUTHCODE_SIZE (10)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
@@ -47,16 +55,20 @@ mz_stream_vtbl mz_stream_aes_vtbl = {
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_aes_s {
|
||||
mz_stream stream;
|
||||
int32_t mode;
|
||||
int32_t error;
|
||||
int16_t initialized;
|
||||
uint8_t buffer[INT16_MAX];
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
fcrypt_ctx crypt_ctx;
|
||||
int16_t encryption_mode;
|
||||
const char *password;
|
||||
mz_stream stream;
|
||||
int32_t mode;
|
||||
int32_t error;
|
||||
int16_t initialized;
|
||||
uint8_t buffer[INT16_MAX];
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
int16_t encryption_mode;
|
||||
const char *password;
|
||||
aes_encrypt_ctx encr_ctx[1];
|
||||
hmac_ctx auth_ctx[1];
|
||||
uint8_t nonce[AES_BLOCK_SIZE];
|
||||
uint8_t encr_bfr[AES_BLOCK_SIZE];
|
||||
uint32_t encr_pos;
|
||||
} mz_stream_aes;
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -64,11 +76,14 @@ typedef struct mz_stream_aes_s {
|
||||
int32_t mz_stream_aes_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
uint16_t salt_length = 0;
|
||||
uint8_t verify[MZ_AES_PWVERIFYSIZE];
|
||||
uint8_t verify_expected[MZ_AES_PWVERIFYSIZE];
|
||||
uint8_t salt_value[MZ_AES_MAXSALTLENGTH];
|
||||
uint8_t kbuf[2 * MZ_AES_KEY_LENGTH_MAX + MZ_AES_PW_VERIFY_SIZE];
|
||||
uint8_t verify[MZ_AES_PW_VERIFY_SIZE];
|
||||
uint8_t verify_expected[MZ_AES_PW_VERIFY_SIZE];
|
||||
uint8_t salt_value[MZ_AES_SALT_LENGTH_MAX];
|
||||
int32_t salt_length = 0;
|
||||
const char *password = path;
|
||||
int32_t password_length = 0;
|
||||
int32_t key_length = 0;
|
||||
|
||||
aes->total_in = 0;
|
||||
aes->total_out = 0;
|
||||
@@ -76,49 +91,70 @@ int32_t mz_stream_aes_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
if (mz_stream_is_open(aes->stream.base) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
if (password == NULL)
|
||||
password = aes->password;
|
||||
if (password == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_PARAM_ERROR;
|
||||
password_length = (int32_t)strlen(password);
|
||||
if (password_length > MZ_AES_PW_LENGTH_MAX)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
salt_length = SALT_LENGTH(aes->encryption_mode);
|
||||
if (aes->encryption_mode < 1 || aes->encryption_mode > 3)
|
||||
return MZ_PARAM_ERROR;
|
||||
salt_length = MZ_AES_SALT_LENGTH(aes->encryption_mode);
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
mz_os_rand(salt_value, salt_length);
|
||||
|
||||
if (fcrypt_init(aes->encryption_mode, (uint8_t *)password,
|
||||
(uint32_t)strlen(password), salt_value, verify, &aes->crypt_ctx) != 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
if (mz_stream_write(aes->stream.base, salt_value, salt_length) != salt_length)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
aes->total_out += salt_length;
|
||||
|
||||
if (mz_stream_write(aes->stream.base, verify, MZ_AES_PWVERIFYSIZE) != MZ_AES_PWVERIFYSIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
aes->total_out += MZ_AES_PWVERIFYSIZE;
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
if (mz_stream_read(aes->stream.base, salt_value, salt_length) != salt_length)
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
key_length = MZ_AES_KEY_LENGTH(aes->encryption_mode);
|
||||
// Derive the encryption and authentication keys and the password verifier
|
||||
derive_key((const uint8_t *)password, password_length, salt_value, salt_length,
|
||||
MZ_AES_KEYING_ITERATIONS, kbuf, 2 * key_length + MZ_AES_PW_VERIFY_SIZE);
|
||||
|
||||
// Initialize the encryption nonce and buffer pos
|
||||
aes->encr_pos = AES_BLOCK_SIZE;
|
||||
memset(aes->nonce, 0, AES_BLOCK_SIZE * sizeof(uint8_t));
|
||||
|
||||
// Initialize for encryption using key 1
|
||||
aes_encrypt_key(kbuf, key_length, aes->encr_ctx);
|
||||
|
||||
// Initialize for authentication using key 2
|
||||
hmac_sha_begin(HMAC_SHA1, aes->auth_ctx);
|
||||
hmac_sha_key(kbuf + key_length, key_length, aes->auth_ctx);
|
||||
|
||||
memcpy(verify, kbuf + 2 * key_length, MZ_AES_PW_VERIFY_SIZE);
|
||||
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
if (mz_stream_write(aes->stream.base, salt_value, salt_length) != salt_length)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
aes->total_out += salt_length;
|
||||
|
||||
if (mz_stream_write(aes->stream.base, verify, MZ_AES_PW_VERIFY_SIZE) != MZ_AES_PW_VERIFY_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
aes->total_out += MZ_AES_PW_VERIFY_SIZE;
|
||||
}
|
||||
else if (mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
aes->total_in += salt_length;
|
||||
|
||||
if (mz_stream_read(aes->stream.base, verify_expected, MZ_AES_PWVERIFYSIZE) != MZ_AES_PWVERIFYSIZE)
|
||||
if (mz_stream_read(aes->stream.base, verify_expected, MZ_AES_PW_VERIFY_SIZE) != MZ_AES_PW_VERIFY_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
aes->total_in += MZ_AES_PWVERIFYSIZE;
|
||||
aes->total_in += MZ_AES_PW_VERIFY_SIZE;
|
||||
|
||||
if (fcrypt_init(aes->encryption_mode, (uint8_t *)password,
|
||||
(uint32_t)strlen(password), salt_value, verify, &aes->crypt_ctx) != 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
if (memcmp(verify_expected, verify, MZ_AES_PWVERIFYSIZE) != 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
if (memcmp(verify_expected, verify, MZ_AES_PW_VERIFY_SIZE) != 0)
|
||||
return MZ_PASSWORD_ERROR;
|
||||
}
|
||||
|
||||
aes->mode = mode;
|
||||
@@ -135,13 +171,45 @@ int32_t mz_stream_aes_is_open(void *stream)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
static int32_t mz_stream_aes_encrypt_data(void *stream, uint8_t *buf, int32_t size)
|
||||
{
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
uint32_t pos = aes->encr_pos;
|
||||
uint32_t i = 0;
|
||||
|
||||
while (i < (uint32_t)size)
|
||||
{
|
||||
if (pos == AES_BLOCK_SIZE)
|
||||
{
|
||||
uint32_t j = 0;
|
||||
|
||||
// Increment encryption nonce
|
||||
while (j < 8 && !++aes->nonce[j])
|
||||
j += 1;
|
||||
|
||||
// Encrypt the nonce to form next xor buffer
|
||||
aes_encrypt(aes->nonce, aes->encr_bfr, aes->encr_ctx);
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
buf[i++] ^= aes->encr_bfr[pos++];
|
||||
}
|
||||
|
||||
aes->encr_pos = pos;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_aes_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
int32_t read = 0;
|
||||
read = mz_stream_read(aes->stream.base, buf, size);
|
||||
if (read > 0)
|
||||
fcrypt_decrypt((uint8_t *)buf, read, &aes->crypt_ctx);
|
||||
{
|
||||
hmac_sha_data((uint8_t *)buf, read, aes->auth_ctx);
|
||||
mz_stream_aes_encrypt_data(stream, (uint8_t *)buf, read);
|
||||
}
|
||||
|
||||
aes->total_in += read;
|
||||
return read;
|
||||
}
|
||||
@@ -150,10 +218,14 @@ int32_t mz_stream_aes_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
int32_t written = 0;
|
||||
|
||||
if (size > sizeof(aes->buffer))
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
memcpy(aes->buffer, buf, size);
|
||||
fcrypt_encrypt((uint8_t *)aes->buffer, size, &aes->crypt_ctx);
|
||||
mz_stream_aes_encrypt_data(stream, (uint8_t *)aes->buffer, size);
|
||||
hmac_sha_data((uint8_t *)aes->buffer, size, aes->auth_ctx);
|
||||
|
||||
written = mz_stream_write(aes->stream.base, aes->buffer, size);
|
||||
if (written > 0)
|
||||
aes->total_out += written;
|
||||
@@ -175,28 +247,28 @@ int32_t mz_stream_aes_seek(void *stream, int64_t offset, int32_t origin)
|
||||
int32_t mz_stream_aes_close(void *stream)
|
||||
{
|
||||
mz_stream_aes *aes = (mz_stream_aes *)stream;
|
||||
unsigned char authcode[MZ_AES_AUTHCODESIZE];
|
||||
unsigned char rauthcode[MZ_AES_AUTHCODESIZE];
|
||||
uint8_t authcode[MZ_AES_AUTHCODE_SIZE];
|
||||
uint8_t verify_authcode[MZ_AES_AUTHCODE_SIZE];
|
||||
|
||||
if (MZ_AES_MAC_LENGTH(aes->encryption_mode) != MZ_AES_AUTHCODE_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
hmac_sha_end(authcode, MZ_AES_MAC_LENGTH(aes->encryption_mode), aes->auth_ctx);
|
||||
|
||||
if (aes->mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
fcrypt_end(authcode, &aes->crypt_ctx);
|
||||
|
||||
if (mz_stream_write(aes->stream.base, authcode, MZ_AES_AUTHCODESIZE) != MZ_AES_AUTHCODESIZE)
|
||||
if (mz_stream_write(aes->stream.base, authcode, MZ_AES_AUTHCODE_SIZE) != MZ_AES_AUTHCODE_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
aes->total_out += MZ_AES_AUTHCODESIZE;
|
||||
aes->total_out += MZ_AES_AUTHCODE_SIZE;
|
||||
}
|
||||
else if (aes->mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
if (mz_stream_read(aes->stream.base, authcode, MZ_AES_AUTHCODESIZE) != MZ_AES_AUTHCODESIZE)
|
||||
if (mz_stream_read(aes->stream.base, verify_authcode, MZ_AES_AUTHCODE_SIZE) != MZ_AES_AUTHCODE_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
aes->total_in += MZ_AES_AUTHCODESIZE;
|
||||
aes->total_in += MZ_AES_AUTHCODE_SIZE;
|
||||
|
||||
if (fcrypt_end(rauthcode, &aes->crypt_ctx) != MZ_AES_AUTHCODESIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
if (memcmp(authcode, rauthcode, MZ_AES_AUTHCODESIZE) != 0)
|
||||
if (memcmp(authcode, verify_authcode, MZ_AES_AUTHCODE_SIZE) != 0)
|
||||
return MZ_CRC_ERROR;
|
||||
}
|
||||
|
||||
@@ -234,10 +306,10 @@ int32_t mz_stream_aes_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
*value = aes->total_out;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_HEADER_SIZE:
|
||||
*value = SALT_LENGTH(aes->encryption_mode) + MZ_AES_PWVERIFYSIZE;
|
||||
*value = MZ_AES_SALT_LENGTH(aes->encryption_mode) + MZ_AES_PW_VERIFY_SIZE;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_FOOTER_SIZE:
|
||||
*value = MZ_AES_AUTHCODESIZE;
|
||||
*value = MZ_AES_AUTHCODE_SIZE;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_aes.h -- Stream for WinZIP AES encryption
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
Executable → Regular
+36
-42
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_buf.c -- Stream for buffering reads/writes
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This version of ioapi is designed to buffer IO.
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if 0
|
||||
# define mz_stream_buffered_print(o,s,f,...) printf(o,s,f,__VA_ARGS__);
|
||||
#if 1
|
||||
# define mz_stream_buffered_print(s,f,...) printf(f,__VA_ARGS__);
|
||||
#else
|
||||
# define mz_stream_buffered_print(o,s,f,...)
|
||||
# define mz_stream_buffered_print(s,f,...)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
@@ -66,12 +66,18 @@ typedef struct mz_stream_buffered_s {
|
||||
|
||||
int32_t mz_stream_buffered_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
//mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
//mz_stream_buffered_print(opaque, buffered, "open [mode %d]\n", mode);
|
||||
return mz_stream_open(stream, path, mode);
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
mz_stream_buffered_print(buffered, "open [mode %d]\n", mode);
|
||||
return mz_stream_open(buffered->stream.base, path, mode);
|
||||
}
|
||||
|
||||
int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
|
||||
int32_t mz_stream_buffered_is_open(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
return mz_stream_is_open(buffered->stream.base);
|
||||
}
|
||||
|
||||
static int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int32_t total_bytes_written = 0;
|
||||
@@ -91,7 +97,7 @@ int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
|
||||
|
||||
buffered->writebuf_misses += 1;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "write flush [%d:%d len %d]\n",
|
||||
mz_stream_buffered_print(stream, "write flush [%d:%d len %d]\n",
|
||||
bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
|
||||
|
||||
total_bytes_written += bytes_written;
|
||||
@@ -115,10 +121,10 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
|
||||
int32_t bytes_left_to_read = size;
|
||||
int32_t bytes_read = 0;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "read [size %ld pos %lld]\n", size, buffered->position);
|
||||
mz_stream_buffered_print(stream, "read [size %ld pos %lld]\n", size, buffered->position);
|
||||
|
||||
if (buffered->writebuf_len > 0)
|
||||
mz_stream_buffered_print(opaque, stream, "switch from write to read, not yet supported [%lld]\n",
|
||||
mz_stream_buffered_print(stream, "switch from write to read, not yet supported [%lld]\n",
|
||||
buffered->position);
|
||||
|
||||
while (bytes_left_to_read > 0)
|
||||
@@ -132,15 +138,15 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
|
||||
}
|
||||
|
||||
bytes_to_read = sizeof(buffered->readbuf) - (buffered->readbuf_len - buffered->readbuf_pos);
|
||||
|
||||
if (mz_stream_read(buffered->stream.base, buffered->readbuf + buffered->readbuf_pos, bytes_to_read) != bytes_to_read)
|
||||
return 0;
|
||||
bytes_read = mz_stream_read(buffered->stream.base, buffered->readbuf + buffered->readbuf_pos, bytes_to_read);
|
||||
if (bytes_read < 0)
|
||||
return bytes_read;
|
||||
|
||||
buffered->readbuf_misses += 1;
|
||||
buffered->readbuf_len += bytes_read;
|
||||
buffered->position += bytes_read;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "filled [read %d/%d buf %d:%d pos %lld]\n",
|
||||
mz_stream_buffered_print(stream, "filled [read %d/%d buf %d:%d pos %lld]\n",
|
||||
bytes_read, bytes_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
|
||||
|
||||
if (bytes_read == 0)
|
||||
@@ -161,7 +167,7 @@ int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
|
||||
buffered->readbuf_hits += 1;
|
||||
buffered->readbuf_pos += bytes_to_copy;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n",
|
||||
mz_stream_buffered_print(stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n",
|
||||
bytes_to_copy, bytes_left_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
|
||||
}
|
||||
}
|
||||
@@ -179,7 +185,7 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
int32_t bytes_flushed = 0;
|
||||
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "write [size %ld len %d pos %lld]\n",
|
||||
mz_stream_buffered_print(stream, "write [size %ld len %d pos %lld]\n",
|
||||
size, buffered->writebuf_len, buffered->position);
|
||||
|
||||
if (buffered->readbuf_len > 0)
|
||||
@@ -190,7 +196,7 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
buffered->readbuf_len = 0;
|
||||
buffered->readbuf_pos = 0;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "switch from read to write [%lld]\n", buffered->position);
|
||||
mz_stream_buffered_print(stream, "switch from read to write [%lld]\n", buffered->position);
|
||||
|
||||
if (mz_stream_seek(buffered->stream.base, buffered->position, MZ_SEEK_SET) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
@@ -217,7 +223,7 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
|
||||
memcpy(buffered->writebuf + buffered->writebuf_pos, (char *)buf + (bytes_to_write - bytes_left_to_write), bytes_to_copy);
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "write copy [remaining %d write %d:%d len %d]\n",
|
||||
mz_stream_buffered_print(stream, "write copy [remaining %d write %d:%d len %d]\n",
|
||||
bytes_to_copy, bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
|
||||
|
||||
bytes_left_to_write -= bytes_to_copy;
|
||||
@@ -231,12 +237,14 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
return size - bytes_left_to_write;
|
||||
}
|
||||
|
||||
int64_t mz_stream_buffered_tellinternal(void *stream, uint64_t position)
|
||||
int64_t mz_stream_buffered_tell(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int64_t position = mz_stream_tell(buffered->stream.base);
|
||||
|
||||
buffered->position = position;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "tell [pos %llu readpos %d writepos %d err %d]\n",
|
||||
mz_stream_buffered_print(stream, "tell [pos %llu readpos %d writepos %d err %d]\n",
|
||||
buffered->position, buffered->readbuf_pos, buffered->writebuf_pos, errno);
|
||||
|
||||
if (buffered->readbuf_len > 0)
|
||||
@@ -246,19 +254,12 @@ int64_t mz_stream_buffered_tellinternal(void *stream, uint64_t position)
|
||||
return position;
|
||||
}
|
||||
|
||||
int64_t mz_stream_buffered_tell(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int64_t position = mz_stream_tell(buffered->stream.base);
|
||||
return mz_stream_buffered_tellinternal(stream, position);
|
||||
}
|
||||
|
||||
int mz_stream_buffered_seekinternal(void *stream, int64_t offset, int32_t origin)
|
||||
int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int32_t bytes_flushed = 0;
|
||||
|
||||
mz_stream_buffered_print(opaque, stream, "seek [origin %d offset %llu pos %lld]\n", origin, offset, buffered->position);
|
||||
mz_stream_buffered_print(stream, "seek [origin %d offset %llu pos %lld]\n", origin, offset, buffered->position);
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
@@ -327,14 +328,7 @@ int mz_stream_buffered_seekinternal(void *stream, int64_t offset, int32_t origin
|
||||
buffered->readbuf_pos = 0;
|
||||
buffered->writebuf_len = 0;
|
||||
buffered->writebuf_pos = 0;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
if (mz_stream_buffered_seekinternal(stream, offset, origin) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return mz_stream_seek(buffered->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
@@ -344,23 +338,23 @@ int32_t mz_stream_buffered_close(void *stream)
|
||||
int32_t bytes_flushed = 0;
|
||||
|
||||
mz_stream_buffered_flush(stream, &bytes_flushed);
|
||||
mz_stream_buffered_print(opaque, stream, "close\n");
|
||||
mz_stream_buffered_print(stream, "close\n");
|
||||
|
||||
if (buffered->readbuf_hits + buffered->readbuf_misses > 0)
|
||||
mz_stream_buffered_print(opaque, stream, "read efficency %.02f%%\n",
|
||||
mz_stream_buffered_print(stream, "read efficency %.02f%%\n",
|
||||
(buffered->readbuf_hits / ((float)buffered->readbuf_hits + buffered->readbuf_misses)) * 100);
|
||||
|
||||
if (buffered->writebuf_hits + buffered->writebuf_misses > 0)
|
||||
mz_stream_buffered_print(opaque, stream, "write efficency %.02f%%\n",
|
||||
mz_stream_buffered_print(stream, "write efficency %.02f%%\n",
|
||||
(buffered->writebuf_hits / ((float)buffered->writebuf_hits + buffered->writebuf_misses)) * 100);
|
||||
|
||||
return mz_stream_close(&buffered->stream.base);
|
||||
return mz_stream_close(buffered->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_buffered_error(void *stream)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
return mz_stream_error(&buffered->stream.base);
|
||||
return mz_stream_error(buffered->stream.base);
|
||||
}
|
||||
|
||||
void *mz_stream_buffered_create(void **stream)
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_buf.h -- Stream for buffering reads/writes
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This version of ioapi is designed to buffer IO.
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_bzip.c -- Stream for bzip inflate/deflate
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -190,7 +190,7 @@ int32_t mz_stream_bzip_read(void *stream, void *buf, int32_t size)
|
||||
return total_out;
|
||||
}
|
||||
|
||||
int32_t mz_stream_bzip_flush(void *stream)
|
||||
static int32_t mz_stream_bzip_flush(void *stream)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
if (mz_stream_write(bzip->stream.base, bzip->buffer, bzip->buffer_len) != bzip->buffer_len)
|
||||
@@ -198,7 +198,7 @@ int32_t mz_stream_bzip_flush(void *stream)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
static int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
uint64_t total_out_before = 0;
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_bzip.h -- Stream for bzip inflate/deflate
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -37,6 +37,8 @@ void mz_stream_bzip_delete(void **stream);
|
||||
|
||||
void* mz_stream_bzip_get_interface(void);
|
||||
|
||||
void bz_internal_error(int errcode);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+12
-6
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_crypt.c -- Code for traditional PKWARE encryption
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -80,7 +80,7 @@ typedef struct mz_stream_crypt_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint8_t mz_stream_crypt_decrypt_byte(uint32_t *keys)
|
||||
static uint8_t mz_stream_crypt_decrypt_byte(uint32_t *keys)
|
||||
{
|
||||
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
||||
* unpredictable manner on 16-bit systems; not a problem
|
||||
@@ -90,7 +90,7 @@ uint8_t mz_stream_crypt_decrypt_byte(uint32_t *keys)
|
||||
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
uint8_t mz_stream_crypt_update_keys(uint32_t *keys, const z_crc_t *crc_32_tab, int32_t c)
|
||||
static uint8_t mz_stream_crypt_update_keys(uint32_t *keys, const z_crc_t *crc_32_tab, int32_t c)
|
||||
{
|
||||
#define CRC32(c, b) ((*(crc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
@@ -104,7 +104,7 @@ uint8_t mz_stream_crypt_update_keys(uint32_t *keys, const z_crc_t *crc_32_tab, i
|
||||
return (uint8_t)c;
|
||||
}
|
||||
|
||||
void mz_stream_crypt_init_keys(const char *password, uint32_t *keys, const z_crc_t *crc_32_tab)
|
||||
static void mz_stream_crypt_init_keys(const char *password, uint32_t *keys, const z_crc_t *crc_32_tab)
|
||||
{
|
||||
*(keys+0) = 305419896L;
|
||||
*(keys+1) = 591751049L;
|
||||
@@ -124,6 +124,8 @@ int32_t mz_stream_crypt_open(void *stream, const char *path, int32_t mode)
|
||||
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
|
||||
uint16_t t = 0;
|
||||
int16_t i = 0;
|
||||
uint8_t verify1 = 0;
|
||||
uint8_t verify2 = 0;
|
||||
uint8_t header[RAND_HEAD_LEN];
|
||||
const char *password = path;
|
||||
|
||||
@@ -170,8 +172,12 @@ int32_t mz_stream_crypt_open(void *stream, const char *path, int32_t mode)
|
||||
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
|
||||
header[i] = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i]);
|
||||
|
||||
crypt->verify1 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
|
||||
crypt->verify2 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
|
||||
verify1 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
|
||||
verify2 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
|
||||
|
||||
// Older versions used 2 byte check, newer versions use 1 byte check.
|
||||
if ((verify2 != 0) && (verify2 != crypt->verify2))
|
||||
return MZ_PASSWORD_ERROR;
|
||||
|
||||
crypt->total_in += RAND_HEAD_LEN;
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_crypt.h -- Code for traditional PKWARE encryption
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+13
-3
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_lzma.c -- Stream for lzma inflate/deflate
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -207,7 +207,7 @@ int32_t mz_stream_lzma_read(void *stream, void *buf, int32_t size)
|
||||
return total_out;
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_flush(void *stream)
|
||||
static int32_t mz_stream_lzma_flush(void *stream)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
if (mz_stream_write(lzma->stream.base, lzma->buffer, lzma->buffer_len) != lzma->buffer_len)
|
||||
@@ -215,7 +215,7 @@ int32_t mz_stream_lzma_flush(void *stream)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
static int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
uint64_t total_out_before = 0;
|
||||
@@ -382,3 +382,13 @@ void *mz_stream_lzma_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_lzma_vtbl;
|
||||
}
|
||||
|
||||
static int32_t mz_stream_lzma_crc32(int32_t value, const void *buf, int32_t size)
|
||||
{
|
||||
return lzma_crc32(buf, size, value);
|
||||
}
|
||||
|
||||
void *mz_stream_lzma_get_crc32_update(void)
|
||||
{
|
||||
return (void *)mz_stream_lzma_crc32;
|
||||
}
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_lzma.h -- Stream for lzma inflate/deflate
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -36,6 +36,7 @@ void* mz_stream_lzma_create(void **stream);
|
||||
void mz_stream_lzma_delete(void **stream);
|
||||
|
||||
void* mz_stream_lzma_get_interface(void);
|
||||
void* mz_stream_lzma_get_crc32_update(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_mem.c -- Stream for memory access
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
This interface is designed to access memory rather than files.
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_mem.h -- Stream for memory access
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_posix.c -- Stream for filesystem access for posix/linux
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -113,9 +113,9 @@ int32_t mz_stream_posix_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t read = (int32_t)fread(buf, 1, (size_t)size, posix->handle);
|
||||
if (read < 0)
|
||||
if (read < size && ferror(posix->handle))
|
||||
{
|
||||
posix->error = ferror(posix->handle);
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
return read;
|
||||
@@ -125,9 +125,9 @@ int32_t mz_stream_posix_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t written = (int32_t)fwrite(buf, 1, (size_t)size, posix->handle);
|
||||
if (written < 0)
|
||||
if (written < size && ferror(posix->handle))
|
||||
{
|
||||
posix->error = ferror(posix->handle);
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
return written;
|
||||
@@ -139,7 +139,7 @@ int64_t mz_stream_posix_tell(void *stream)
|
||||
int64_t position = ftello64(posix->handle);
|
||||
if (position == -1)
|
||||
{
|
||||
posix->error = ferror(posix->handle);
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
return position;
|
||||
@@ -167,7 +167,7 @@ int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin)
|
||||
|
||||
if (fseeko64(posix->handle, offset, fseek_origin) != 0)
|
||||
{
|
||||
posix->error = ferror(posix->handle);
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_posix.h -- Stream for filesystem access for posix/linux
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+8
-5
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_split.c -- Stream for split files
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -23,6 +23,10 @@
|
||||
|
||||
#define MZ_ZIP_MAGIC_DISKHEADER (0x08074b50)
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_split_vtbl = {
|
||||
@@ -62,14 +66,13 @@ typedef struct mz_stream_split_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
static int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
uint32_t magic = 0;
|
||||
int32_t i = 0;
|
||||
int32_t err = MZ_OK;
|
||||
int16_t disk_part = 0;
|
||||
int16_t read_disk_part = 0;
|
||||
|
||||
|
||||
// Check if we are reading or writing a disk part or the cd disk
|
||||
@@ -136,7 +139,7 @@ int32_t mz_stream_split_open_disk(void *stream, int32_t number_disk)
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_stream_split_close_disk(void *stream)
|
||||
static int32_t mz_stream_split_close_disk(void *stream)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
|
||||
@@ -146,7 +149,7 @@ int32_t mz_stream_split_close_disk(void *stream)
|
||||
return mz_stream_close(split->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_split_goto_disk(void *stream, int32_t number_disk)
|
||||
static int32_t mz_stream_split_goto_disk(void *stream, int32_t number_disk)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_split.h -- Stream for split files
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_win32.c -- Stream for filesystem access for windows
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/* mz_sstrm_win32.h -- Stream for filesystem access for windows
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
|
||||
+15
-293
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_zlib.c -- Stream for zlib inflate/deflate
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -195,7 +195,7 @@ int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
|
||||
return total_out;
|
||||
}
|
||||
|
||||
int32_t mz_stream_zlib_flush(void *stream)
|
||||
static int32_t mz_stream_zlib_flush(void *stream)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
if (mz_stream_write(zlib->stream.base, zlib->buffer, zlib->buffer_len) != zlib->buffer_len)
|
||||
@@ -203,7 +203,7 @@ int32_t mz_stream_zlib_flush(void *stream)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
static int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
uint64_t total_out_before = 0;
|
||||
@@ -234,16 +234,18 @@ int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
|
||||
out_bytes = (uint32_t)(total_out_after - total_out_before);
|
||||
|
||||
if (err != Z_OK && err != Z_STREAM_END)
|
||||
zlib->buffer_len += out_bytes;
|
||||
zlib->total_out += out_bytes;
|
||||
|
||||
if (err == Z_STREAM_END)
|
||||
break;
|
||||
if (err != Z_OK)
|
||||
{
|
||||
zlib->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
zlib->buffer_len += out_bytes;
|
||||
zlib->total_out += out_bytes;
|
||||
}
|
||||
while (zlib->zstream.avail_in > 0);
|
||||
while ((zlib->zstream.avail_in > 0) || (flush == Z_FINISH && err == Z_OK));
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
@@ -369,292 +371,12 @@ void *mz_stream_zlib_get_interface(void)
|
||||
return (void *)&mz_stream_zlib_vtbl;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_crc32_vtbl = {
|
||||
mz_stream_crc32_open,
|
||||
mz_stream_crc32_is_open,
|
||||
mz_stream_crc32_read,
|
||||
mz_stream_crc32_write,
|
||||
mz_stream_crc32_tell,
|
||||
mz_stream_crc32_seek,
|
||||
mz_stream_crc32_close,
|
||||
mz_stream_crc32_error,
|
||||
mz_stream_crc32_create,
|
||||
mz_stream_crc32_delete,
|
||||
mz_stream_crc32_get_prop_int64
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_crc32_s {
|
||||
mz_stream stream;
|
||||
int8_t initialized;
|
||||
int32_t value;
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
} mz_stream_crc32;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_crc32_open(void *stream, const char *path, int32_t mode)
|
||||
static int32_t mz_stream_zlib_crc32(int32_t value, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->initialized = 1;
|
||||
crc32->value = 0;
|
||||
return MZ_OK;
|
||||
return crc32(value, buf, size);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_is_open(void *stream)
|
||||
void *mz_stream_zlib_get_crc32_update(void)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
if (crc32->initialized != 1)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
|
||||
int32_t read = 0;
|
||||
read = mz_stream_read(crc32x->stream.base, buf, size);
|
||||
if (read > 0)
|
||||
crc32x->value = (int32_t)crc32(crc32x->value, buf, read);
|
||||
crc32x->total_in += read;
|
||||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
|
||||
int32_t written = 0;
|
||||
crc32x->value = (int32_t)crc32(crc32x->value, buf, size);
|
||||
written = mz_stream_write(crc32x->stream.base, buf, size);
|
||||
crc32x->total_out += written;
|
||||
return written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_crc32_tell(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return mz_stream_tell(crc32->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return mz_stream_seek(crc32->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_close(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
crc32->initialized = 0;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_error(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return mz_stream_error(crc32->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_get_value(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
return crc32->value;
|
||||
}
|
||||
|
||||
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = crc32->total_in;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = crc32->total_out;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
void *mz_stream_crc32_create(void **stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = NULL;
|
||||
|
||||
crc32 = (mz_stream_crc32 *)malloc(sizeof(mz_stream_crc32));
|
||||
if (crc32 != NULL)
|
||||
{
|
||||
memset(crc32, 0, sizeof(mz_stream_crc32));
|
||||
crc32->stream.vtbl = &mz_stream_crc32_vtbl;
|
||||
}
|
||||
if (stream != NULL)
|
||||
*stream = crc32;
|
||||
|
||||
return crc32;
|
||||
}
|
||||
|
||||
void mz_stream_crc32_delete(void **stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = NULL;
|
||||
if (stream == NULL)
|
||||
return;
|
||||
crc32 = (mz_stream_crc32 *)*stream;
|
||||
if (crc32 != NULL)
|
||||
free(crc32);
|
||||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_crc32_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_crc32_vtbl;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_stream_raw_s {
|
||||
mz_stream stream;
|
||||
int64_t total_in;
|
||||
int64_t total_out;
|
||||
int64_t max_total_in;
|
||||
} mz_stream_raw;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_raw_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_is_open(void *stream)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
return mz_stream_is_open(raw->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
int32_t bytes_to_read = size;
|
||||
int32_t read = 0;
|
||||
|
||||
if (raw->max_total_in > 0)
|
||||
{
|
||||
if ((raw->max_total_in - raw->total_in) < size)
|
||||
bytes_to_read = (int32_t)(raw->max_total_in - raw->total_in);
|
||||
}
|
||||
|
||||
read = mz_stream_read(raw->stream.base, buf, bytes_to_read);
|
||||
|
||||
if (read > 0)
|
||||
raw->total_in += read;
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
int32_t written = mz_stream_write(raw->stream.base, buf, size);
|
||||
if (written > 0)
|
||||
raw->total_out += written;
|
||||
return written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_raw_tell(void *stream)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
return mz_stream_tell(raw->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
return mz_stream_seek(raw->stream.base, offset, origin);
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_close(void *stream)
|
||||
{
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_error(void *stream)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
return mz_stream_error(raw->stream.base);
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_get_prop_int64(void *stream, int32_t prop, int64_t *value)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN:
|
||||
*value = raw->total_in;
|
||||
return MZ_OK;
|
||||
case MZ_STREAM_PROP_TOTAL_OUT:
|
||||
*value = raw->total_out;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_raw_set_prop_int64(void *stream, int32_t prop, int64_t value)
|
||||
{
|
||||
mz_stream_raw *raw = (mz_stream_raw *)stream;
|
||||
switch (prop)
|
||||
{
|
||||
case MZ_STREAM_PROP_TOTAL_IN_MAX:
|
||||
raw->max_total_in = value;
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
mz_stream_vtbl mz_stream_raw_vtbl = {
|
||||
mz_stream_raw_open,
|
||||
mz_stream_raw_is_open,
|
||||
mz_stream_raw_read,
|
||||
mz_stream_raw_write,
|
||||
mz_stream_raw_tell,
|
||||
mz_stream_raw_seek,
|
||||
mz_stream_raw_close,
|
||||
mz_stream_raw_error,
|
||||
mz_stream_raw_create,
|
||||
mz_stream_raw_delete,
|
||||
mz_stream_raw_get_prop_int64,
|
||||
mz_stream_raw_set_prop_int64
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void *mz_stream_raw_create(void **stream)
|
||||
{
|
||||
mz_stream_raw *raw = NULL;
|
||||
|
||||
raw = (mz_stream_raw *)malloc(sizeof(mz_stream_raw));
|
||||
if (raw != NULL)
|
||||
{
|
||||
memset(raw, 0, sizeof(mz_stream_raw));
|
||||
raw->stream.vtbl = &mz_stream_raw_vtbl;
|
||||
}
|
||||
if (stream != NULL)
|
||||
*stream = raw;
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
void mz_stream_raw_delete(void **stream)
|
||||
{
|
||||
mz_stream_raw *raw = NULL;
|
||||
if (stream == NULL)
|
||||
return;
|
||||
raw = (mz_stream_raw *)*stream;
|
||||
if (raw != NULL)
|
||||
free(raw);
|
||||
*stream = NULL;
|
||||
}
|
||||
return (void *)mz_stream_zlib_crc32;
|
||||
}
|
||||
+2
-26
@@ -1,5 +1,5 @@
|
||||
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -36,31 +36,7 @@ void* mz_stream_zlib_create(void **stream);
|
||||
void mz_stream_zlib_delete(void **stream);
|
||||
|
||||
void* mz_stream_zlib_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_crc32_open(void *stream, const char *filename, int32_t mode);
|
||||
int32_t mz_stream_crc32_is_open(void *stream);
|
||||
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size);
|
||||
int64_t mz_stream_crc32_tell(void *stream);
|
||||
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_crc32_close(void *stream);
|
||||
int32_t mz_stream_crc32_error(void *stream);
|
||||
|
||||
int32_t mz_stream_crc32_get_value(void *stream);
|
||||
|
||||
int32_t mz_stream_crc32_get_prop_int64(void *stream, int32_t prop, int64_t *value);
|
||||
|
||||
void* mz_stream_crc32_create(void **stream);
|
||||
void mz_stream_crc32_delete(void **stream);
|
||||
|
||||
void* mz_stream_crc32_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void* mz_stream_raw_create(void **stream);
|
||||
void mz_stream_raw_delete(void **stream);
|
||||
void* mz_stream_zlib_get_crc32_update(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
Executable → Regular
+81
-66
@@ -1,9 +1,8 @@
|
||||
/* zip.c -- Zip manipulation
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2017 Nathan Moinvaziri
|
||||
Modifications for AES, PKWARE disk spanning
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
Modifications for Zip64 support
|
||||
@@ -22,8 +21,6 @@
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#ifdef HAVE_AES
|
||||
@@ -38,8 +35,10 @@
|
||||
#ifdef HAVE_LZMA
|
||||
# include "mz_strm_lzma.h"
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
# include "mz_strm_zlib.h"
|
||||
#endif
|
||||
#include "mz_strm_mem.h"
|
||||
#include "mz_strm_zlib.h"
|
||||
|
||||
#include "mz_zip.h"
|
||||
|
||||
@@ -450,7 +449,7 @@ static int32_t mz_zip_write_cd(void *handle)
|
||||
return err;
|
||||
}
|
||||
|
||||
extern void* ZEXPORT mz_zip_open(void *stream, int32_t mode)
|
||||
extern void* mz_zip_open(void *stream, int32_t mode)
|
||||
{
|
||||
mz_zip *zip = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
@@ -463,9 +462,8 @@ extern void* ZEXPORT mz_zip_open(void *stream, int32_t mode)
|
||||
memset(zip, 0, sizeof(mz_zip));
|
||||
|
||||
zip->stream = stream;
|
||||
zip->open_mode = mode;
|
||||
|
||||
if (zip->open_mode & MZ_OPEN_MODE_WRITE)
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
mz_stream_mem_create(&zip->cd_mem_stream);
|
||||
mz_stream_mem_open(zip->cd_mem_stream, NULL, MZ_OPEN_MODE_CREATE);
|
||||
@@ -477,7 +475,7 @@ extern void* ZEXPORT mz_zip_open(void *stream, int32_t mode)
|
||||
zip->cd_stream = stream;
|
||||
}
|
||||
|
||||
if ((zip->open_mode & MZ_OPEN_MODE_READ) || (mode & MZ_OPEN_MODE_APPEND))
|
||||
if ((mode & MZ_OPEN_MODE_READ) || (mode & MZ_OPEN_MODE_APPEND))
|
||||
{
|
||||
err = mz_zip_read_cd(zip);
|
||||
|
||||
@@ -514,27 +512,16 @@ extern void* ZEXPORT mz_zip_open(void *stream, int32_t mode)
|
||||
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
if (zip->file_info_stream != NULL)
|
||||
mz_stream_mem_delete(&zip->file_info_stream);
|
||||
if (zip->local_file_info_stream != NULL)
|
||||
mz_stream_mem_delete(&zip->local_file_info_stream);
|
||||
if (zip->cd_mem_stream != NULL)
|
||||
{
|
||||
mz_stream_close(zip->cd_mem_stream);
|
||||
mz_stream_delete(&zip->cd_mem_stream);
|
||||
}
|
||||
|
||||
if (zip->comment)
|
||||
free(zip->comment);
|
||||
|
||||
free(zip);
|
||||
mz_zip_close(zip);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zip->open_mode = mode;
|
||||
|
||||
return zip;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_close(void *handle)
|
||||
extern int32_t mz_zip_close(void *handle)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
int32_t err = MZ_OK;
|
||||
@@ -558,10 +545,16 @@ extern int32_t ZEXPORT mz_zip_close(void *handle)
|
||||
mz_stream_delete(&zip->cd_mem_stream);
|
||||
}
|
||||
|
||||
mz_stream_mem_close(zip->file_info_stream);
|
||||
mz_stream_mem_delete(&zip->file_info_stream);
|
||||
mz_stream_mem_close(zip->local_file_info_stream);
|
||||
mz_stream_mem_delete(&zip->local_file_info_stream);
|
||||
if (zip->file_info_stream != NULL)
|
||||
{
|
||||
mz_stream_mem_close(zip->file_info_stream);
|
||||
mz_stream_mem_delete(&zip->file_info_stream);
|
||||
}
|
||||
if (zip->local_file_info_stream != NULL)
|
||||
{
|
||||
mz_stream_mem_close(zip->local_file_info_stream);
|
||||
mz_stream_mem_delete(&zip->local_file_info_stream);
|
||||
}
|
||||
|
||||
if (zip->comment)
|
||||
free(zip->comment);
|
||||
@@ -571,7 +564,7 @@ extern int32_t ZEXPORT mz_zip_close(void *handle)
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_get_comment(void *handle, const char **comment)
|
||||
extern int32_t mz_zip_get_comment(void *handle, const char **comment)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
if (zip == NULL || comment == NULL)
|
||||
@@ -582,7 +575,7 @@ extern int32_t ZEXPORT mz_zip_get_comment(void *handle, const char **comment)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_set_comment(void *handle, const char *comment)
|
||||
extern int32_t mz_zip_set_comment(void *handle, const char *comment)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
uint16_t comment_size = 0;
|
||||
@@ -596,7 +589,7 @@ extern int32_t ZEXPORT mz_zip_set_comment(void *handle, const char *comment)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_get_version_madeby(void *handle, uint16_t *version_madeby)
|
||||
extern int32_t mz_zip_get_version_madeby(void *handle, uint16_t *version_madeby)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
if (zip == NULL || version_madeby == NULL)
|
||||
@@ -605,7 +598,7 @@ extern int32_t ZEXPORT mz_zip_get_version_madeby(void *handle, uint16_t *version
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_set_version_madeby(void *handle, uint16_t version_madeby)
|
||||
extern int32_t mz_zip_set_version_madeby(void *handle, uint16_t version_madeby)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
if (zip == NULL)
|
||||
@@ -851,7 +844,6 @@ static int32_t mz_zip_entry_read_header(void *stream, uint8_t local, mz_zip_file
|
||||
|
||||
static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_file *file_info)
|
||||
{
|
||||
struct tm *local_time = NULL;
|
||||
uint64_t ntfs_time = 0;
|
||||
uint32_t reserved = 0;
|
||||
uint32_t dos_date = 0;
|
||||
@@ -1089,7 +1081,7 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
|
||||
if ((zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED) && (password == NULL))
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if ((err == Z_OK) && (zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED))
|
||||
if ((err == MZ_OK) && (zip->file_info.flag & MZ_ZIP_FLAG_ENCRYPTED))
|
||||
{
|
||||
#ifdef HAVE_AES
|
||||
if (zip->file_info.aes_version)
|
||||
@@ -1102,17 +1094,26 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
|
||||
#endif
|
||||
{
|
||||
#ifdef HAVE_CRYPT
|
||||
uint32_t dos_date = 0;
|
||||
uint8_t verify1 = 0;
|
||||
uint8_t verify2 = 0;
|
||||
|
||||
// Info-ZIP modification to ZipCrypto format:
|
||||
// If bit 3 of the general purpose bit flag is set, it uses high byte of 16-bit File Time.
|
||||
|
||||
dos_date = mz_zip_time_t_to_dos_date(zip->file_info.modified_date);
|
||||
if (zip->file_info.flag & MZ_ZIP_FLAG_DATA_DESCRIPTOR)
|
||||
{
|
||||
uint32_t dos_date = 0;
|
||||
|
||||
verify1 = (uint8_t)((dos_date >> 16) & 0xff);
|
||||
verify2 = (uint8_t)((dos_date >> 8) & 0xff);
|
||||
dos_date = mz_zip_time_t_to_dos_date(zip->file_info.modified_date);
|
||||
|
||||
verify1 = (uint8_t)((dos_date >> 16) & 0xff);
|
||||
verify2 = (uint8_t)((dos_date >> 8) & 0xff);
|
||||
}
|
||||
else
|
||||
{
|
||||
verify1 = (uint8_t)((zip->file_info.crc >> 16) & 0xff);
|
||||
verify2 = (uint8_t)((zip->file_info.crc >> 24) & 0xff);
|
||||
}
|
||||
|
||||
mz_stream_crypt_create(&zip->crypt_stream);
|
||||
mz_stream_crypt_set_password(zip->crypt_stream, password);
|
||||
@@ -1172,9 +1173,19 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
|
||||
|
||||
err = mz_stream_open(zip->compress_stream, NULL, zip->open_mode);
|
||||
}
|
||||
if (err == Z_OK)
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
mz_stream_crc32_create(&zip->crc32_stream);
|
||||
#ifdef HAVE_ZLIB
|
||||
mz_stream_crc32_set_update_func(zip->crc32_stream,
|
||||
(mz_stream_crc32_update)mz_stream_zlib_get_crc32_update());
|
||||
#elif defined(HAVE_LZMA)
|
||||
mz_stream_crc32_set_update_func(zip->crc32_stream,
|
||||
(mz_stream_crc32_update)mz_stream_lzma_get_crc32_update());
|
||||
#else
|
||||
#error ZLIB or LZMA required for CRC32
|
||||
#endif
|
||||
|
||||
mz_stream_set_base(zip->crc32_stream, zip->compress_stream);
|
||||
|
||||
err = mz_stream_open(zip->crc32_stream, NULL, zip->open_mode);
|
||||
@@ -1188,7 +1199,7 @@ static int32_t mz_zip_entry_open_int(void *handle, int16_t compression_method, i
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_read_open(void *handle, int16_t raw, const char *password)
|
||||
extern int32_t mz_zip_entry_read_open(void *handle, int16_t raw, const char *password)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
int16_t compression_method = 0;
|
||||
@@ -1226,7 +1237,7 @@ extern int32_t ZEXPORT mz_zip_entry_read_open(void *handle, int16_t raw, const c
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
|
||||
extern int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
|
||||
int16_t compress_level, const char *password)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
@@ -1236,7 +1247,7 @@ extern int32_t ZEXPORT mz_zip_entry_write_open(void *handle, const mz_zip_file *
|
||||
|
||||
|
||||
#if !defined(HAVE_CRYPT) && !defined(HAVE_AES)
|
||||
if (crypt_info != NULL)
|
||||
if (password != NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
#endif
|
||||
if (zip == NULL || file_info == NULL || file_info->filename == NULL)
|
||||
@@ -1251,16 +1262,25 @@ extern int32_t ZEXPORT mz_zip_entry_write_open(void *handle, const mz_zip_file *
|
||||
|
||||
memcpy(&zip->file_info, file_info, sizeof(mz_zip_file));
|
||||
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_DATA_DESCRIPTOR;
|
||||
compression_method = zip->file_info.compression_method;
|
||||
if (compress_level == 0)
|
||||
compression_method = MZ_COMPRESS_METHOD_RAW;
|
||||
|
||||
if (compression_method == MZ_COMPRESS_METHOD_DEFLATE)
|
||||
{
|
||||
if ((compress_level == 8) || (compress_level == 9))
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_DEFLATE_MAX;
|
||||
if (compress_level == 2)
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_DEFLATE_FAST;
|
||||
if (compress_level == 1)
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_DEFLATE_SUPER_FAST;
|
||||
}
|
||||
#ifdef HAVE_LZMA
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_LZMA_EOS_MARKER;
|
||||
else if (compression_method == MZ_COMPRESS_METHOD_LZMA)
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_LZMA_EOS_MARKER;
|
||||
#endif
|
||||
if ((compress_level == 8) || (compress_level == 9))
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_DEFLATE_MAX;
|
||||
if (compress_level == 2)
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_DEFLATE_FAST;
|
||||
if (compress_level == 1)
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_DEFLATE_SUPER_FAST;
|
||||
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_DATA_DESCRIPTOR;
|
||||
|
||||
if (password != NULL)
|
||||
zip->file_info.flag |= MZ_ZIP_FLAG_ENCRYPTED;
|
||||
@@ -1279,10 +1299,6 @@ extern int32_t ZEXPORT mz_zip_entry_write_open(void *handle, const mz_zip_file *
|
||||
zip->file_info.aes_encryption_mode = MZ_AES_ENCRYPTION_MODE_256;
|
||||
#endif
|
||||
|
||||
compression_method = zip->file_info.compression_method;
|
||||
if (compress_level == 0)
|
||||
compression_method = MZ_COMPRESS_METHOD_RAW;
|
||||
|
||||
if (err == MZ_OK)
|
||||
err = mz_zip_entry_write_header(zip->stream, 1, &zip->file_info);
|
||||
if (err == MZ_OK)
|
||||
@@ -1291,7 +1307,7 @@ extern int32_t ZEXPORT mz_zip_entry_write_open(void *handle, const mz_zip_file *
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_read(void *handle, void *buf, uint32_t len)
|
||||
extern int32_t mz_zip_entry_read(void *handle, void *buf, uint32_t len)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
int32_t read = 0;
|
||||
@@ -1300,7 +1316,7 @@ extern int32_t ZEXPORT mz_zip_entry_read(void *handle, void *buf, uint32_t len)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (len > UINT16_MAX) // Zlib limitation
|
||||
return MZ_PARAM_ERROR;
|
||||
if (len == 0)
|
||||
if (len == 0 || zip->file_info.uncompressed_size == 0)
|
||||
return 0;
|
||||
read = mz_stream_read(zip->crc32_stream, buf, len);
|
||||
if (read > 0)
|
||||
@@ -1308,7 +1324,7 @@ extern int32_t ZEXPORT mz_zip_entry_read(void *handle, void *buf, uint32_t len)
|
||||
return read;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_write(void *handle, const void *buf, uint32_t len)
|
||||
extern int32_t mz_zip_entry_write(void *handle, const void *buf, uint32_t len)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
if (zip == NULL || zip->entry_opened == 0)
|
||||
@@ -1316,7 +1332,7 @@ extern int32_t ZEXPORT mz_zip_entry_write(void *handle, const void *buf, uint32_
|
||||
return mz_stream_write(zip->crc32_stream, buf, len);
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_get_info(void *handle, mz_zip_file **file_info)
|
||||
extern int32_t mz_zip_entry_get_info(void *handle, mz_zip_file **file_info)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
if (zip == NULL || zip->entry_scanned == 0)
|
||||
@@ -1325,7 +1341,7 @@ extern int32_t ZEXPORT mz_zip_entry_get_info(void *handle, mz_zip_file **file_in
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_get_local_info(void *handle, mz_zip_file **local_file_info)
|
||||
extern int32_t mz_zip_entry_get_local_info(void *handle, mz_zip_file **local_file_info)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
if (zip == NULL || zip->entry_scanned == 0 || zip->entry_opened == 0)
|
||||
@@ -1334,7 +1350,7 @@ extern int32_t ZEXPORT mz_zip_entry_get_local_info(void *handle, mz_zip_file **l
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size, uint32_t crc32)
|
||||
extern int32_t mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size, uint32_t crc32)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
uint64_t compressed_size = 0;
|
||||
@@ -1417,7 +1433,7 @@ extern int32_t ZEXPORT mz_zip_entry_close_raw(void *handle, uint64_t uncompresse
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_close(void *handle)
|
||||
extern int32_t mz_zip_entry_close(void *handle)
|
||||
{
|
||||
return mz_zip_entry_close_raw(handle, 0, 0);
|
||||
}
|
||||
@@ -1442,7 +1458,7 @@ static int32_t mz_zip_goto_next_entry_int(void *handle)
|
||||
return err;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_get_number_entry(void *handle, int64_t *number_entry)
|
||||
extern int32_t mz_zip_get_number_entry(void *handle, int64_t *number_entry)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
if (zip == NULL || number_entry == NULL)
|
||||
@@ -1451,7 +1467,7 @@ extern int32_t ZEXPORT mz_zip_get_number_entry(void *handle, int64_t *number_ent
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_goto_first_entry(void *handle)
|
||||
extern int32_t mz_zip_goto_first_entry(void *handle)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
|
||||
@@ -1463,7 +1479,7 @@ extern int32_t ZEXPORT mz_zip_goto_first_entry(void *handle)
|
||||
return mz_zip_goto_next_entry_int(handle);
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_goto_next_entry(void *handle)
|
||||
extern int32_t mz_zip_goto_next_entry(void *handle)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
|
||||
@@ -1476,7 +1492,7 @@ extern int32_t ZEXPORT mz_zip_goto_next_entry(void *handle)
|
||||
return mz_zip_goto_next_entry_int(handle);
|
||||
}
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_locate_entry(void *handle, const char *filename, mz_filename_compare_cb filename_compare_cb)
|
||||
extern int32_t mz_zip_locate_entry(void *handle, const char *filename, mz_filename_compare_cb filename_compare_cb)
|
||||
{
|
||||
mz_zip *zip = (mz_zip *)handle;
|
||||
int32_t err = MZ_OK;
|
||||
@@ -1574,7 +1590,6 @@ uint32_t mz_zip_time_t_to_dos_date(time_t unix_time)
|
||||
uint32_t mz_zip_tm_to_dosdate(const struct tm *ptm)
|
||||
{
|
||||
struct tm fixed_tm = { 0 };
|
||||
uint32_t dos_date = 0;
|
||||
|
||||
// Years supported:
|
||||
|
||||
|
||||
+19
-23
@@ -1,5 +1,5 @@
|
||||
/* mz_zip.h -- Zip manipulation
|
||||
Version 2.2.3, October 27th, 2017
|
||||
Version 2.2.5, January 3rd, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2012-2017 Nathan Moinvaziri
|
||||
@@ -20,10 +20,6 @@
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
# include "zlib.h"
|
||||
#endif
|
||||
|
||||
#include "mz_strm.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -64,62 +60,62 @@ typedef struct mz_zip_file_s
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern void * ZEXPORT mz_zip_open(void *stream, int32_t mode);
|
||||
extern void * mz_zip_open(void *stream, int32_t mode);
|
||||
// Create a zip file, no delete file in zip functionality
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_close(void *handle);
|
||||
extern int32_t mz_zip_close(void *handle);
|
||||
// Close the zip file
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_get_comment(void *handle, const char **comment);
|
||||
extern int32_t mz_zip_get_comment(void *handle, const char **comment);
|
||||
// Get a pointer to the global comment
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_set_comment(void *handle, const char *comment);
|
||||
extern int32_t mz_zip_set_comment(void *handle, const char *comment);
|
||||
// Set the global comment used for writing zip file
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_get_version_madeby(void *handle, uint16_t *version_madeby);
|
||||
extern int32_t mz_zip_get_version_madeby(void *handle, uint16_t *version_madeby);
|
||||
// Get the version made by
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_set_version_madeby(void *handle, uint16_t version_madeby);
|
||||
extern int32_t mz_zip_set_version_madeby(void *handle, uint16_t version_madeby);
|
||||
// Set the version made by used for writing zip file
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
|
||||
extern int32_t mz_zip_entry_write_open(void *handle, const mz_zip_file *file_info,
|
||||
int16_t compress_level, const char *password);
|
||||
// Open for writing the current file in the zip file
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_write(void *handle, const void *buf, uint32_t len);
|
||||
extern int32_t mz_zip_entry_write(void *handle, const void *buf, uint32_t len);
|
||||
// Write bytes from the current file in the zip file
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_read_open(void *handle, int16_t raw, const char *password);
|
||||
extern int32_t mz_zip_entry_read_open(void *handle, int16_t raw, const char *password);
|
||||
// Open for reading the current file in the zip file
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_read(void *handle, void *buf, uint32_t len);
|
||||
extern int32_t mz_zip_entry_read(void *handle, void *buf, uint32_t len);
|
||||
// Read bytes from the current file in the zip file
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_get_info(void *handle, mz_zip_file **file_info);
|
||||
extern int32_t mz_zip_entry_get_info(void *handle, mz_zip_file **file_info);
|
||||
// Get info about the current file, only valid while current entry is open
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_get_local_info(void *handle, mz_zip_file **local_file_info);
|
||||
extern int32_t mz_zip_entry_get_local_info(void *handle, mz_zip_file **local_file_info);
|
||||
// Get local info about the current file, only valid while current entry is being read
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size, uint32_t crc32);
|
||||
extern int32_t mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size, uint32_t crc32);
|
||||
// Close the current file in the zip file where raw is compressed data
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_entry_close(void *handle);
|
||||
extern int32_t mz_zip_entry_close(void *handle);
|
||||
// Close the current file in the zip file
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_get_number_entry(void *handle, int64_t *number_entry);
|
||||
extern int32_t mz_zip_get_number_entry(void *handle, int64_t *number_entry);
|
||||
// Get the total number of entries
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_goto_first_entry(void *handle);
|
||||
extern int32_t mz_zip_goto_first_entry(void *handle);
|
||||
// Go to the first entry in the zip file
|
||||
|
||||
extern int32_t ZEXPORT mz_zip_goto_next_entry(void *handle);
|
||||
extern int32_t mz_zip_goto_next_entry(void *handle);
|
||||
// Go to the next entry in the zip file or MZ_END_OF_LIST if reaching the end
|
||||
|
||||
typedef int32_t (*mz_filename_compare_cb)(void *handle, const char *filename1, const char *filename2);
|
||||
extern int32_t ZEXPORT mz_zip_locate_entry(void *handle, const char *filename,
|
||||
extern int32_t mz_zip_locate_entry(void *handle, const char *filename,
|
||||
mz_filename_compare_cb filename_compare_cb);
|
||||
// Locate the file with the specified name in the zip file or MZ_END_LIST if not found
|
||||
|
||||
|
||||
+2
-2
@@ -151,7 +151,7 @@ void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
|
||||
mz_stream_delete(&deflate_stream);
|
||||
|
||||
printf("%s compressed from %d to %d\n", filename, (uint32_t)total_in, (uint32_t)total_out);
|
||||
printf("%s compressed from %u to %u\n", filename, (uint32_t)total_in, (uint32_t)total_out);
|
||||
|
||||
mz_stream_os_close(out_stream);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ void test_compress(char *method, mz_stream_create_cb create_compress)
|
||||
|
||||
mz_stream_os_close(in_stream);
|
||||
|
||||
printf("%s uncompressed from %d to %d\n", filename, (uint32_t)total_in, (uint32_t)total_out);
|
||||
printf("%s uncompressed from %u to %u\n", filename, (uint32_t)total_in, (uint32_t)total_out);
|
||||
}
|
||||
|
||||
mz_stream_os_delete(&in_stream);
|
||||
|
||||
@@ -199,3 +199,4 @@ 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