mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Externals: Update minizip to minizip-ng version 3.0.4.
This commit is contained in:
Vendored
+59
-8
@@ -1,18 +1,69 @@
|
||||
project(minizip C)
|
||||
|
||||
set(SRCS ioapi.c unzip.c)
|
||||
add_library(minizip STATIC
|
||||
mz.h
|
||||
mz_compat.c
|
||||
mz_compat.h
|
||||
mz_crypt.c
|
||||
mz_crypt.h
|
||||
mz_os.c
|
||||
mz_os.h
|
||||
mz_strm.c
|
||||
mz_strm.h
|
||||
mz_strm_buf.c
|
||||
mz_strm_buf.h
|
||||
mz_strm_mem.c
|
||||
mz_strm_mem.h
|
||||
mz_strm_os.h
|
||||
mz_strm_split.c
|
||||
mz_strm_split.h
|
||||
mz_strm_zlib.c
|
||||
mz_strm_zlib.h
|
||||
mz_zip.c
|
||||
mz_zip.h
|
||||
mz_zip_rw.c
|
||||
mz_zip_rw.h
|
||||
unzip.h
|
||||
zip.h
|
||||
)
|
||||
|
||||
add_definitions(-DNOUNCRYPT)
|
||||
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)
|
||||
if (UNIX)
|
||||
target_sources(minizip PRIVATE
|
||||
mz_os_posix.c
|
||||
mz_strm_os_posix.c
|
||||
)
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
target_sources(minizip PRIVATE
|
||||
mz_os_win32.c
|
||||
mz_strm_os_win32.c
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(minizip STATIC ${SRCS})
|
||||
target_include_directories(minizip PUBLIC .)
|
||||
|
||||
target_compile_definitions(minizip PRIVATE HAVE_ZLIB ZLIB_COMPAT MZ_ZIP_NO_CRYPTO MZ_ZIP_NO_ENCRYPTION)
|
||||
if (UNIX)
|
||||
target_compile_definitions(minizip PRIVATE _POSIX_C_SOURCE=200112L)
|
||||
target_compile_definitions(minizip PRIVATE __USE_LARGEFILE64 _LARGEFILE64_SOURCE)
|
||||
endif()
|
||||
|
||||
check_include_file(stdint.h HAVE_STDINT_H)
|
||||
if (HAVE_STDINT_H)
|
||||
target_compile_definitions(minizip PRIVATE HAVE_STDINT_H)
|
||||
endif()
|
||||
|
||||
check_include_file(inttypes.h HAVE_INTTYPES_H)
|
||||
if (HAVE_INTTYPES_H)
|
||||
target_compile_definitions(minizip PRIVATE HAVE_INTTYPES_H)
|
||||
endif()
|
||||
|
||||
check_function_exists(fseeko HAVE_FSEEKO)
|
||||
if (NOT HAVE_FSEEKO)
|
||||
target_compile_definitions(minizip PRIVATE NO_FSEEKO)
|
||||
endif()
|
||||
|
||||
target_link_libraries(minizip PUBLIC ZLIB::ZLIB)
|
||||
|
||||
add_library(MiniZip::minizip ALIAS minizip)
|
||||
|
||||
+1015
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
@@ -14,4 +14,4 @@ freely, subject to the following restrictions:
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
Vendored
+3
-2
@@ -1,2 +1,3 @@
|
||||
Partial import from https://github.com/nmoinvaz/minizip
|
||||
Revision: b3713abe7722f1b779e7cdbd527c6208abbe1121
|
||||
minizip-ng, Version 3.0.4 (2021-11-29)
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
Revision: 95987e98b4862c055b8cf91d6e7ce5f9153ddc24
|
||||
|
||||
Vendored
-351
@@ -1,351 +0,0 @@
|
||||
/* ioapi.c -- IO base function header for compress/uncompress .zip
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
http://result42.com
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined unix || defined __APPLE__
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "ioapi.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc, const void *filename, int mode)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zopen64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque, filename, mode);
|
||||
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque, (const char*)filename, mode);
|
||||
}
|
||||
|
||||
voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode)
|
||||
{
|
||||
if (pfilefunc->zfile_func64.zopendisk64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.zopendisk64_file)) (pfilefunc->zfile_func64.opaque, filestream, number_disk, mode);
|
||||
return (*(pfilefunc->zopendisk32_file))(pfilefunc->zfile_func64.opaque, filestream, number_disk, mode);
|
||||
}
|
||||
|
||||
long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin)
|
||||
{
|
||||
uint32_t offset_truncated = 0;
|
||||
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
|
||||
offset_truncated = (uint32_t)offset;
|
||||
if (offset_truncated != offset)
|
||||
return -1;
|
||||
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream, offset_truncated, origin);
|
||||
}
|
||||
|
||||
uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream)
|
||||
{
|
||||
uint64_t position;
|
||||
if (pfilefunc->zfile_func64.zseek64_file != NULL)
|
||||
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque, filestream);
|
||||
position = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque, filestream);
|
||||
if ((position) == UINT32_MAX)
|
||||
return (uint64_t)-1;
|
||||
return position;
|
||||
}
|
||||
|
||||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
|
||||
{
|
||||
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
|
||||
p_filefunc64_32->zfile_func64.zopendisk64_file = NULL;
|
||||
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
|
||||
p_filefunc64_32->zopendisk32_file = p_filefunc32->zopendisk_file;
|
||||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
||||
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
|
||||
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
|
||||
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
|
||||
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
|
||||
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
|
||||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
|
||||
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
|
||||
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
|
||||
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char *filename, int mode);
|
||||
static uint32_t ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uint32_t size);
|
||||
static uint32_t ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uint32_t size);
|
||||
static uint64_t ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream);
|
||||
static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, uint64_t offset, int origin);
|
||||
static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream);
|
||||
static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE *file;
|
||||
int filenameLength;
|
||||
void *filename;
|
||||
} FILE_IOPOSIX;
|
||||
|
||||
static voidpf file_build_ioposix(FILE *file, const char *filename)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
if (file == NULL)
|
||||
return NULL;
|
||||
ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX));
|
||||
ioposix->file = file;
|
||||
ioposix->filenameLength = (int)strlen(filename) + 1;
|
||||
ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
||||
strncpy((char*)ioposix->filename, filename, ioposix->filenameLength);
|
||||
return (voidpf)ioposix;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopen_file_func(voidpf opaque, const char *filename, int mode)
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char *mode_fopen = NULL;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
if ((filename != NULL) && (mode_fopen != NULL))
|
||||
{
|
||||
file = fopen(filename, mode_fopen);
|
||||
return file_build_ioposix(file, filename);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopen64_file_func(voidpf opaque, const void *filename, int mode)
|
||||
{
|
||||
FILE* file = NULL;
|
||||
const char *mode_fopen = NULL;
|
||||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
||||
mode_fopen = "r+b";
|
||||
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
|
||||
if ((filename != NULL) && (mode_fopen != NULL))
|
||||
{
|
||||
file = fopen64((const char*)filename, mode_fopen);
|
||||
return file_build_ioposix(file, (const char*)filename);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopendisk64_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
char *diskFilename = NULL;
|
||||
voidpf ret = NULL;
|
||||
int i = 0;
|
||||
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
||||
strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength);
|
||||
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
||||
{
|
||||
if (diskFilename[i] != '.')
|
||||
continue;
|
||||
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1);
|
||||
break;
|
||||
}
|
||||
if (i >= 0)
|
||||
ret = fopen64_file_func(opaque, diskFilename, mode);
|
||||
free(diskFilename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static voidpf ZCALLBACK fopendisk_file_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
char *diskFilename = NULL;
|
||||
voidpf ret = NULL;
|
||||
int i = 0;
|
||||
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
diskFilename = (char*)malloc(ioposix->filenameLength * sizeof(char));
|
||||
strncpy(diskFilename, (const char*)ioposix->filename, ioposix->filenameLength);
|
||||
for (i = ioposix->filenameLength - 1; i >= 0; i -= 1)
|
||||
{
|
||||
if (diskFilename[i] != '.')
|
||||
continue;
|
||||
snprintf(&diskFilename[i], ioposix->filenameLength - i, ".z%02u", number_disk + 1);
|
||||
break;
|
||||
}
|
||||
if (i >= 0)
|
||||
ret = fopen_file_func(opaque, diskFilename, mode);
|
||||
free(diskFilename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint32_t ZCALLBACK fread_file_func(voidpf opaque, voidpf stream, void* buf, uint32_t size)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
uint32_t read = (uint32_t)-1;
|
||||
if (stream == NULL)
|
||||
return read;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
read = (uint32_t)fread(buf, 1, (size_t)size, ioposix->file);
|
||||
return read;
|
||||
}
|
||||
|
||||
static uint32_t ZCALLBACK fwrite_file_func(voidpf opaque, voidpf stream, const void *buf, uint32_t size)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
uint32_t written = (uint32_t)-1;
|
||||
if (stream == NULL)
|
||||
return written;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
written = (uint32_t)fwrite(buf, 1, (size_t)size, ioposix->file);
|
||||
return written;
|
||||
}
|
||||
|
||||
static long ZCALLBACK ftell_file_func(voidpf opaque, voidpf stream)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
long ret = -1;
|
||||
if (stream == NULL)
|
||||
return ret;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
ret = ftell(ioposix->file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static uint64_t ZCALLBACK ftell64_file_func(voidpf opaque, voidpf stream)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
uint64_t ret = (uint64_t)-1;
|
||||
if (stream == NULL)
|
||||
return ret;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
ret = ftello64(ioposix->file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long ZCALLBACK fseek_file_func(voidpf opaque, voidpf stream, uint32_t offset, int origin)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
int fseek_origin = 0;
|
||||
long ret = 0;
|
||||
|
||||
if (stream == NULL)
|
||||
return -1;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR:
|
||||
fseek_origin = SEEK_CUR;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END:
|
||||
fseek_origin = SEEK_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET:
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
if (fseek(ioposix->file, offset, fseek_origin) != 0)
|
||||
ret = -1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static long ZCALLBACK fseek64_file_func(voidpf opaque, voidpf stream, uint64_t offset, int origin)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
int fseek_origin = 0;
|
||||
long ret = 0;
|
||||
|
||||
if (stream == NULL)
|
||||
return -1;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
case ZLIB_FILEFUNC_SEEK_CUR:
|
||||
fseek_origin = SEEK_CUR;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_END:
|
||||
fseek_origin = SEEK_END;
|
||||
break;
|
||||
case ZLIB_FILEFUNC_SEEK_SET:
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fseeko64(ioposix->file, offset, fseek_origin) != 0)
|
||||
ret = -1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ZCALLBACK fclose_file_func(voidpf opaque, voidpf stream)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
int ret = -1;
|
||||
if (stream == NULL)
|
||||
return ret;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
if (ioposix->filename != NULL)
|
||||
free(ioposix->filename);
|
||||
ret = fclose(ioposix->file);
|
||||
free(ioposix);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ZCALLBACK ferror_file_func(voidpf opaque, voidpf stream)
|
||||
{
|
||||
FILE_IOPOSIX *ioposix = NULL;
|
||||
int ret = -1;
|
||||
if (stream == NULL)
|
||||
return ret;
|
||||
ioposix = (FILE_IOPOSIX*)stream;
|
||||
ret = ferror(ioposix->file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen_file = fopen_file_func;
|
||||
pzlib_filefunc_def->zopendisk_file = fopendisk_file_func;
|
||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||
pzlib_filefunc_def->ztell_file = ftell_file_func;
|
||||
pzlib_filefunc_def->zseek_file = fseek_file_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
|
||||
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
|
||||
{
|
||||
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
|
||||
pzlib_filefunc_def->zopendisk64_file = fopendisk64_file_func;
|
||||
pzlib_filefunc_def->zread_file = fread_file_func;
|
||||
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
|
||||
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
|
||||
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
|
||||
pzlib_filefunc_def->zclose_file = fclose_file_func;
|
||||
pzlib_filefunc_def->zerror_file = ferror_file_func;
|
||||
pzlib_filefunc_def->opaque = NULL;
|
||||
}
|
||||
Vendored
-146
@@ -1,146 +0,0 @@
|
||||
/* ioapi.h -- IO base function header for compress/uncompress .zip
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
http://www.winimage.com/zLibDll/minizip.html
|
||||
Modifications for Zip64 support
|
||||
Copyright (C) 2009-2010 Mathias Svensson
|
||||
http://result42.com
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef _ZLIBIOAPI64_H
|
||||
#define _ZLIBIOAPI64_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
#if defined(USE_FILE32API)
|
||||
# define fopen64 fopen
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
#else
|
||||
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__APPLE__)
|
||||
# define fopen64 fopen
|
||||
# define ftello64 ftello
|
||||
# define fseeko64 fseeko
|
||||
# endif
|
||||
# ifdef _MSC_VER
|
||||
# define fopen64 fopen
|
||||
# if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
|
||||
# define ftello64 _ftelli64
|
||||
# define fseeko64 _fseeki64
|
||||
# else /* old MSC */
|
||||
# define ftello64 ftell
|
||||
# define fseeko64 fseek
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
# if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \
|
||||
defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
|
||||
# define ZCALLBACK CALLBACK
|
||||
# else
|
||||
# define ZCALLBACK
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char *filename, int mode);
|
||||
typedef voidpf (ZCALLBACK *opendisk_file_func) (voidpf opaque, voidpf stream, uint32_t number_disk, int mode);
|
||||
typedef uint32_t (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uint32_t size);
|
||||
typedef uint32_t (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void *buf, uint32_t size);
|
||||
typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream);
|
||||
typedef int (ZCALLBACK *error_file_func) (voidpf opaque, voidpf stream);
|
||||
|
||||
typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream);
|
||||
typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uint32_t offset, int origin);
|
||||
|
||||
/* here is the "old" 32 bits structure structure */
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
opendisk_file_func zopendisk_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
error_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
typedef uint64_t (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream);
|
||||
typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, uint64_t offset, int origin);
|
||||
typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void *filename, int mode);
|
||||
typedef voidpf (ZCALLBACK *opendisk64_file_func)(voidpf opaque, voidpf stream, uint32_t number_disk, int mode);
|
||||
|
||||
typedef struct zlib_filefunc64_def_s
|
||||
{
|
||||
open64_file_func zopen64_file;
|
||||
opendisk64_file_func zopendisk64_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell64_file_func ztell64_file;
|
||||
seek64_file_func zseek64_file;
|
||||
close_file_func zclose_file;
|
||||
error_file_func zerror_file;
|
||||
voidpf opaque;
|
||||
} zlib_filefunc64_def;
|
||||
|
||||
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
|
||||
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
|
||||
/* now internal definition, only for zip.c and unzip.h */
|
||||
typedef struct zlib_filefunc64_32_def_s
|
||||
{
|
||||
zlib_filefunc64_def zfile_func64;
|
||||
open_file_func zopen32_file;
|
||||
opendisk_file_func zopendisk32_file;
|
||||
tell_file_func ztell32_file;
|
||||
seek_file_func zseek32_file;
|
||||
} zlib_filefunc64_32_def;
|
||||
|
||||
#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
||||
#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
|
||||
/*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/
|
||||
/*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/
|
||||
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
|
||||
|
||||
voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc,const void*filename, int mode);
|
||||
voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode);
|
||||
long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin);
|
||||
uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream);
|
||||
|
||||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32);
|
||||
|
||||
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
|
||||
#define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode)))
|
||||
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
|
||||
#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+182
@@ -0,0 +1,182 @@
|
||||
/* minigzip.c
|
||||
part of the minizip-ng project
|
||||
|
||||
Copyright (C) 2010-2021 Nathan Moinvaziri
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_os.h"
|
||||
#include "mz_strm_zlib.h"
|
||||
|
||||
#include <stdio.h> /* printf */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_GZIP_COMPRESS (1)
|
||||
#define MZ_GZIP_DECOMPRESS (2)
|
||||
|
||||
int32_t minigzip_banner(void);
|
||||
int32_t minigzip_help(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minigzip_banner(void) {
|
||||
printf("Minigzip %s - https://github.com/zlib-ng/minizip-ng\n", MZ_VERSION);
|
||||
printf("---------------------------------------------------\n");
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t minigzip_help(void) {
|
||||
printf("Usage: minigzip [-x] [-d] [-0 to -9] [files]\n\n" \
|
||||
" -x Extract file\n" \
|
||||
" -d Destination directory\n" \
|
||||
" -0 Store only\n" \
|
||||
" -1 Compress faster\n" \
|
||||
" -9 Compress better\n\n");
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t minigzip_copy(const char *path, const char *destination, int16_t operation, int16_t level) {
|
||||
void *target_stream = NULL;
|
||||
void *source_stream = NULL;
|
||||
void *zlib_stream = NULL;
|
||||
const char *filename = NULL;
|
||||
char target_path[1024];
|
||||
int32_t err = 0;
|
||||
|
||||
|
||||
memset(target_path, 0, sizeof(target_path));
|
||||
|
||||
if (destination != NULL) {
|
||||
if (mz_os_file_exists(destination) != MZ_OK)
|
||||
mz_dir_make(destination);
|
||||
}
|
||||
|
||||
if (operation == MZ_GZIP_COMPRESS) {
|
||||
mz_path_combine(target_path, path, sizeof(target_path));
|
||||
strncat(target_path, ".gz", sizeof(target_path) - strlen(target_path) - 1);
|
||||
printf("Compressing to %s\n", target_path);
|
||||
} else if (operation == MZ_GZIP_DECOMPRESS) {
|
||||
if (destination != NULL)
|
||||
mz_path_combine(target_path, destination, sizeof(target_path));
|
||||
|
||||
if (mz_path_get_filename(path, &filename) != MZ_OK)
|
||||
filename = path;
|
||||
|
||||
mz_path_combine(target_path, filename, sizeof(target_path));
|
||||
mz_path_remove_extension(target_path);
|
||||
printf("Decompressing to %s\n", target_path);
|
||||
}
|
||||
|
||||
mz_stream_zlib_create(&zlib_stream);
|
||||
mz_stream_zlib_set_prop_int64(zlib_stream, MZ_STREAM_PROP_COMPRESS_WINDOW, 15 + 16);
|
||||
|
||||
mz_stream_os_create(&source_stream);
|
||||
err = mz_stream_os_open(source_stream, path, MZ_OPEN_MODE_READ);
|
||||
|
||||
if (err == MZ_OK) {
|
||||
mz_stream_os_create(&target_stream);
|
||||
err = mz_stream_os_open(target_stream, target_path, MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_WRITE);
|
||||
|
||||
if (err == MZ_OK) {
|
||||
if (operation == MZ_GZIP_COMPRESS) {
|
||||
mz_stream_zlib_set_prop_int64(zlib_stream, MZ_STREAM_PROP_COMPRESS_LEVEL, level);
|
||||
mz_stream_zlib_open(zlib_stream, target_path, MZ_OPEN_MODE_WRITE);
|
||||
mz_stream_set_base(zlib_stream, target_stream);
|
||||
err = mz_stream_copy_to_end(zlib_stream, source_stream);
|
||||
} else if (operation == MZ_GZIP_DECOMPRESS) {
|
||||
mz_stream_zlib_open(zlib_stream, path, MZ_OPEN_MODE_READ);
|
||||
mz_stream_set_base(zlib_stream, source_stream);
|
||||
err = mz_stream_copy_to_end(target_stream, zlib_stream);
|
||||
}
|
||||
|
||||
if (err != MZ_OK)
|
||||
printf("Error %d in zlib stream (%d)\n", err, mz_stream_zlib_error(zlib_stream));
|
||||
else
|
||||
printf("Operation completed successfully\n");
|
||||
|
||||
mz_stream_zlib_close(zlib_stream);
|
||||
} else {
|
||||
printf("Error %d opening target path %s\n", err, target_path);
|
||||
}
|
||||
|
||||
mz_stream_os_close(target_stream);
|
||||
mz_stream_os_delete(&target_stream);
|
||||
} else {
|
||||
printf("Error %d opening source path %s\n", err, path);
|
||||
}
|
||||
|
||||
mz_stream_os_close(source_stream);
|
||||
mz_stream_os_delete(&source_stream);
|
||||
|
||||
mz_stream_zlib_delete(&zlib_stream);
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(MZ_ZIP_NO_MAIN)
|
||||
int main(int argc, const char *argv[]) {
|
||||
int16_t operation_level = MZ_COMPRESS_LEVEL_DEFAULT;
|
||||
int32_t path_arg = 0;
|
||||
int32_t err = 0;
|
||||
int32_t i = 0;
|
||||
uint8_t operation = MZ_GZIP_COMPRESS;
|
||||
const char *path = NULL;
|
||||
const char *destination = NULL;
|
||||
|
||||
|
||||
minigzip_banner();
|
||||
if (argc == 1) {
|
||||
minigzip_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse command line options */
|
||||
for (i = 1; i < argc; i += 1) {
|
||||
printf("%s ", argv[i]);
|
||||
if (argv[i][0] == '-') {
|
||||
char c = argv[i][1];
|
||||
if ((c == 'x') || (c == 'X'))
|
||||
operation = MZ_GZIP_DECOMPRESS;
|
||||
else if ((c >= '0') && (c <= '9'))
|
||||
operation_level = (c - '0');
|
||||
else if (((c == 'd') || (c == 'D')) && (i + 1 < argc)) {
|
||||
destination = argv[i + 1];
|
||||
printf("%s ", argv[i + 1]);
|
||||
i += 1;
|
||||
} else {
|
||||
err = MZ_SUPPORT_ERROR;
|
||||
}
|
||||
} else if (path_arg == 0) {
|
||||
path_arg = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (err == MZ_SUPPORT_ERROR) {
|
||||
printf("Feature not supported\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
if (path_arg == 0) {
|
||||
minigzip_help();
|
||||
return 0;
|
||||
}
|
||||
|
||||
path = argv[path_arg];
|
||||
err = minigzip_copy(path, destination, operation, operation_level);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
Vendored
+671
File diff suppressed because it is too large
Load Diff
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=@CMAKE_INSTALL_PREFIX@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
sharedlibdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: Minizip zip file manipulation library
|
||||
Version: @VERSION@
|
||||
|
||||
Requires: zlib
|
||||
Libs: -L${libdir} -L${sharedlibdir} -l@PROJECT_NAME@
|
||||
Libs.private:@PC_PRIVATE_LIBS@
|
||||
Cflags: -I${includedir}
|
||||
Vendored
+26
-4
@@ -17,19 +17,41 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>NOUNCRYPT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>HAVE_ZLIB;ZLIB_COMPAT;MZ_ZIP_NO_CRYPTO;MZ_ZIP_NO_ENCRYPTION;HAVE_STDINT_H;HAVE_INTTYPES_H;NO_FSEEKO;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ioapi.c" />
|
||||
<ClCompile Include="unzip.c" />
|
||||
<ClCompile Include="mz_compat.c" />
|
||||
<ClCompile Include="mz_crypt.c" />
|
||||
<ClCompile Include="mz_os.c" />
|
||||
<ClCompile Include="mz_os_win32.c" />
|
||||
<ClCompile Include="mz_strm.c" />
|
||||
<ClCompile Include="mz_strm_buf.c" />
|
||||
<ClCompile Include="mz_strm_mem.c" />
|
||||
<ClCompile Include="mz_strm_os_win32.c" />
|
||||
<ClCompile Include="mz_strm_split.c" />
|
||||
<ClCompile Include="mz_strm_zlib.c" />
|
||||
<ClCompile Include="mz_zip.c" />
|
||||
<ClCompile Include="mz_zip_rw.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ioapi.h" />
|
||||
<ClInclude Include="mz.h" />
|
||||
<ClInclude Include="mz_compat.h" />
|
||||
<ClInclude Include="mz_crypt.h" />
|
||||
<ClInclude Include="mz_os.h" />
|
||||
<ClInclude Include="mz_strm.h" />
|
||||
<ClInclude Include="mz_strm_buf.h" />
|
||||
<ClInclude Include="mz_strm_mem.h" />
|
||||
<ClInclude Include="mz_strm_os.h" />
|
||||
<ClInclude Include="mz_strm_split.h" />
|
||||
<ClInclude Include="mz_strm_zlib.h" />
|
||||
<ClInclude Include="mz_zip.h" />
|
||||
<ClInclude Include="mz_zip_rw.h" />
|
||||
<ClInclude Include="unzip.h" />
|
||||
<ClInclude Include="zip.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="LICENSE" />
|
||||
|
||||
Vendored
+274
@@ -0,0 +1,274 @@
|
||||
/* mz.h -- Errors codes, zip flags and magic
|
||||
part of the minizip-ng project
|
||||
|
||||
Copyright (C) 2010-2021 Nathan Moinvaziri
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_H
|
||||
#define MZ_H
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
/* MZ_VERSION */
|
||||
#define MZ_VERSION ("3.0.4")
|
||||
#define MZ_VERSION_BUILD (030004)
|
||||
|
||||
/* MZ_ERROR */
|
||||
#define MZ_OK (0) /* zlib */
|
||||
#define MZ_STREAM_ERROR (-1) /* zlib */
|
||||
#define MZ_DATA_ERROR (-3) /* zlib */
|
||||
#define MZ_MEM_ERROR (-4) /* zlib */
|
||||
#define MZ_BUF_ERROR (-5) /* zlib */
|
||||
#define MZ_VERSION_ERROR (-6) /* zlib */
|
||||
|
||||
#define MZ_END_OF_LIST (-100)
|
||||
#define MZ_END_OF_STREAM (-101)
|
||||
|
||||
#define MZ_PARAM_ERROR (-102)
|
||||
#define MZ_FORMAT_ERROR (-103)
|
||||
#define MZ_INTERNAL_ERROR (-104)
|
||||
#define MZ_CRC_ERROR (-105)
|
||||
#define MZ_CRYPT_ERROR (-106)
|
||||
#define MZ_EXIST_ERROR (-107)
|
||||
#define MZ_PASSWORD_ERROR (-108)
|
||||
#define MZ_SUPPORT_ERROR (-109)
|
||||
#define MZ_HASH_ERROR (-110)
|
||||
#define MZ_OPEN_ERROR (-111)
|
||||
#define MZ_CLOSE_ERROR (-112)
|
||||
#define MZ_SEEK_ERROR (-113)
|
||||
#define MZ_TELL_ERROR (-114)
|
||||
#define MZ_READ_ERROR (-115)
|
||||
#define MZ_WRITE_ERROR (-116)
|
||||
#define MZ_SIGN_ERROR (-117)
|
||||
#define MZ_SYMLINK_ERROR (-118)
|
||||
|
||||
/* MZ_OPEN */
|
||||
#define MZ_OPEN_MODE_READ (0x01)
|
||||
#define MZ_OPEN_MODE_WRITE (0x02)
|
||||
#define MZ_OPEN_MODE_READWRITE (MZ_OPEN_MODE_READ | MZ_OPEN_MODE_WRITE)
|
||||
#define MZ_OPEN_MODE_APPEND (0x04)
|
||||
#define MZ_OPEN_MODE_CREATE (0x08)
|
||||
#define MZ_OPEN_MODE_EXISTING (0x10)
|
||||
|
||||
/* MZ_SEEK */
|
||||
#define MZ_SEEK_SET (0)
|
||||
#define MZ_SEEK_CUR (1)
|
||||
#define MZ_SEEK_END (2)
|
||||
|
||||
/* MZ_COMPRESS */
|
||||
#define MZ_COMPRESS_METHOD_STORE (0)
|
||||
#define MZ_COMPRESS_METHOD_DEFLATE (8)
|
||||
#define MZ_COMPRESS_METHOD_BZIP2 (12)
|
||||
#define MZ_COMPRESS_METHOD_LZMA (14)
|
||||
#define MZ_COMPRESS_METHOD_ZSTD (93)
|
||||
#define MZ_COMPRESS_METHOD_XZ (95)
|
||||
#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)
|
||||
|
||||
/* MZ_ZIP_FLAG */
|
||||
#define MZ_ZIP_FLAG_ENCRYPTED (1 << 0)
|
||||
#define MZ_ZIP_FLAG_LZMA_EOS_MARKER (1 << 1)
|
||||
#define MZ_ZIP_FLAG_DEFLATE_MAX (1 << 1)
|
||||
#define MZ_ZIP_FLAG_DEFLATE_NORMAL (0)
|
||||
#define MZ_ZIP_FLAG_DEFLATE_FAST (1 << 2)
|
||||
#define MZ_ZIP_FLAG_DEFLATE_SUPER_FAST (MZ_ZIP_FLAG_DEFLATE_FAST | \
|
||||
MZ_ZIP_FLAG_DEFLATE_MAX)
|
||||
#define MZ_ZIP_FLAG_DATA_DESCRIPTOR (1 << 3)
|
||||
#define MZ_ZIP_FLAG_UTF8 (1 << 11)
|
||||
#define MZ_ZIP_FLAG_MASK_LOCAL_INFO (1 << 13)
|
||||
|
||||
/* MZ_ZIP_EXTENSION */
|
||||
#define MZ_ZIP_EXTENSION_ZIP64 (0x0001)
|
||||
#define MZ_ZIP_EXTENSION_NTFS (0x000a)
|
||||
#define MZ_ZIP_EXTENSION_AES (0x9901)
|
||||
#define MZ_ZIP_EXTENSION_UNIX1 (0x000d)
|
||||
#define MZ_ZIP_EXTENSION_SIGN (0x10c5)
|
||||
#define MZ_ZIP_EXTENSION_HASH (0x1a51)
|
||||
#define MZ_ZIP_EXTENSION_CDCD (0xcdcd)
|
||||
|
||||
/* MZ_ZIP64 */
|
||||
#define MZ_ZIP64_AUTO (0)
|
||||
#define MZ_ZIP64_FORCE (1)
|
||||
#define MZ_ZIP64_DISABLE (2)
|
||||
|
||||
/* MZ_HOST_SYSTEM */
|
||||
#define MZ_HOST_SYSTEM(VERSION_MADEBY) ((uint8_t)(VERSION_MADEBY >> 8))
|
||||
#define MZ_HOST_SYSTEM_MSDOS (0)
|
||||
#define MZ_HOST_SYSTEM_UNIX (3)
|
||||
#define MZ_HOST_SYSTEM_WINDOWS_NTFS (10)
|
||||
#define MZ_HOST_SYSTEM_RISCOS (13)
|
||||
#define MZ_HOST_SYSTEM_OSX_DARWIN (19)
|
||||
|
||||
/* MZ_PKCRYPT */
|
||||
#define MZ_PKCRYPT_HEADER_SIZE (12)
|
||||
|
||||
/* MZ_AES */
|
||||
#define MZ_AES_VERSION (1)
|
||||
#define MZ_AES_ENCRYPTION_MODE_128 (0x01)
|
||||
#define MZ_AES_ENCRYPTION_MODE_192 (0x02)
|
||||
#define MZ_AES_ENCRYPTION_MODE_256 (0x03)
|
||||
#define MZ_AES_KEY_LENGTH(MODE) (8 * (MODE & 3) + 8)
|
||||
#define MZ_AES_KEY_LENGTH_MAX (32)
|
||||
#define MZ_AES_BLOCK_SIZE (16)
|
||||
#define MZ_AES_HEADER_SIZE(MODE) ((4 * (MODE & 3) + 4) + 2)
|
||||
#define MZ_AES_FOOTER_SIZE (10)
|
||||
|
||||
/* MZ_HASH */
|
||||
#define MZ_HASH_MD5 (10)
|
||||
#define MZ_HASH_MD5_SIZE (16)
|
||||
#define MZ_HASH_SHA1 (20)
|
||||
#define MZ_HASH_SHA1_SIZE (20)
|
||||
#define MZ_HASH_SHA256 (23)
|
||||
#define MZ_HASH_SHA256_SIZE (32)
|
||||
#define MZ_HASH_MAX_SIZE (256)
|
||||
|
||||
/* MZ_ENCODING */
|
||||
#define MZ_ENCODING_CODEPAGE_437 (437)
|
||||
#define MZ_ENCODING_CODEPAGE_932 (932)
|
||||
#define MZ_ENCODING_CODEPAGE_936 (936)
|
||||
#define MZ_ENCODING_CODEPAGE_950 (950)
|
||||
#define MZ_ENCODING_UTF8 (65001)
|
||||
|
||||
/* MZ_UTILITY */
|
||||
#define MZ_UNUSED(SYMBOL) ((void)SYMBOL)
|
||||
|
||||
#ifndef MZ_CUSTOM_ALLOC
|
||||
#define MZ_ALLOC(SIZE) (malloc((SIZE)))
|
||||
#endif
|
||||
#ifndef MZ_CUSTOM_FREE
|
||||
#define MZ_FREE(PTR) (free(PTR))
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && defined(MZ_EXPORTS)
|
||||
#define MZ_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define MZ_EXPORT
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#include <stdlib.h> /* size_t, NULL, malloc */
|
||||
#include <time.h> /* time_t, time() */
|
||||
#include <string.h> /* memset, strncpy, strlen */
|
||||
#include <limits.h>
|
||||
|
||||
#if defined(HAVE_STDINT_H)
|
||||
# include <stdint.h>
|
||||
#elif defined(__has_include)
|
||||
# if __has_include(<stdint.h>)
|
||||
# include <stdint.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef INT8_MAX
|
||||
typedef signed char int8_t;
|
||||
#endif
|
||||
#ifndef INT16_MAX
|
||||
typedef short int16_t;
|
||||
#endif
|
||||
#ifndef INT32_MAX
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
#ifndef INT64_MAX
|
||||
typedef long long int64_t;
|
||||
#endif
|
||||
#ifndef UINT8_MAX
|
||||
typedef unsigned char uint8_t;
|
||||
#endif
|
||||
#ifndef UINT16_MAX
|
||||
typedef unsigned short uint16_t;
|
||||
#endif
|
||||
#ifndef UINT32_MAX
|
||||
typedef unsigned int uint32_t;
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
typedef unsigned long long uint64_t;
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_INTTYPES_H)
|
||||
# include <inttypes.h>
|
||||
#elif defined(__has_include)
|
||||
# if __has_include(<inttypes.h>)
|
||||
# include <inttypes.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef PRId8
|
||||
# define PRId8 "hhd"
|
||||
#endif
|
||||
#ifndef PRIu8
|
||||
# define PRIu8 "hhu"
|
||||
#endif
|
||||
#ifndef PRIx8
|
||||
# define PRIx8 "hhx"
|
||||
#endif
|
||||
#ifndef PRId16
|
||||
# define PRId16 "hd"
|
||||
#endif
|
||||
#ifndef PRIu16
|
||||
# define PRIu16 "hu"
|
||||
#endif
|
||||
#ifndef PRIx16
|
||||
# define PRIx16 "hx"
|
||||
#endif
|
||||
#ifndef PRId32
|
||||
# define PRId32 "d"
|
||||
#endif
|
||||
#ifndef PRIu32
|
||||
# define PRIu32 "u"
|
||||
#endif
|
||||
#ifndef PRIx32
|
||||
# define PRIx32 "x"
|
||||
#endif
|
||||
#if ULONG_MAX == 0xfffffffful
|
||||
# ifndef PRId64
|
||||
# define PRId64 "ld"
|
||||
# endif
|
||||
# ifndef PRIu64
|
||||
# define PRIu64 "lu"
|
||||
# endif
|
||||
# ifndef PRIx64
|
||||
# define PRIx64 "lx"
|
||||
# endif
|
||||
#else
|
||||
# ifndef PRId64
|
||||
# define PRId64 "lld"
|
||||
# endif
|
||||
# ifndef PRIu64
|
||||
# define PRIu64 "llu"
|
||||
# endif
|
||||
# ifndef PRIx64
|
||||
# define PRIx64 "llx"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef INT16_MAX
|
||||
# define INT16_MAX 32767
|
||||
#endif
|
||||
#ifndef INT32_MAX
|
||||
# define INT32_MAX 2147483647L
|
||||
#endif
|
||||
#ifndef INT64_MAX
|
||||
# define INT64_MAX 9223372036854775807LL
|
||||
#endif
|
||||
#ifndef UINT16_MAX
|
||||
# define UINT16_MAX 65535U
|
||||
#endif
|
||||
#ifndef UINT32_MAX
|
||||
# define UINT32_MAX 4294967295UL
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
# define UINT64_MAX 18446744073709551615ULL
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#endif
|
||||
Vendored
+1303
File diff suppressed because it is too large
Load Diff
Vendored
+396
@@ -0,0 +1,396 @@
|
||||
/* mz_compat.h -- Backwards compatible interface for older versions
|
||||
part of the minizip-ng project
|
||||
|
||||
Copyright (C) 2010-2021 Nathan Moinvaziri
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
https://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_COMPAT_H
|
||||
#define MZ_COMPAT_H
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(HAVE_ZLIB) && defined(MAX_MEM_LEVEL)
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
# define DEF_MEM_LEVEL 8
|
||||
# else
|
||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||
# endif
|
||||
#endif
|
||||
#endif
|
||||
#ifndef MAX_WBITS
|
||||
#define MAX_WBITS (15)
|
||||
#endif
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
#define DEF_MEM_LEVEL (8)
|
||||
#endif
|
||||
|
||||
#ifndef ZEXPORT
|
||||
# define ZEXPORT MZ_EXPORT
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagzipFile__ { int unused; } zip_file__;
|
||||
typedef zip_file__ *zipFile;
|
||||
#else
|
||||
typedef void *zipFile;
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef uint64_t ZPOS64_T;
|
||||
|
||||
#ifndef ZCALLBACK
|
||||
#define ZCALLBACK
|
||||
#endif
|
||||
|
||||
typedef void* (ZCALLBACK *open_file_func) (void *opaque, const char *filename, int mode);
|
||||
typedef void* (ZCALLBACK *open64_file_func) (void *opaque, const void *filename, int mode);
|
||||
typedef unsigned long (ZCALLBACK *read_file_func) (void *opaque, void *stream, void* buf, unsigned long size);
|
||||
typedef unsigned long (ZCALLBACK *write_file_func) (void *opaque, void *stream, const void* buf,
|
||||
unsigned long size);
|
||||
typedef int (ZCALLBACK *close_file_func) (void *opaque, void *stream);
|
||||
typedef int (ZCALLBACK *testerror_file_func)(void *opaque, void *stream);
|
||||
typedef long (ZCALLBACK *tell_file_func) (void *opaque, void *stream);
|
||||
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (void *opaque, void *stream);
|
||||
typedef long (ZCALLBACK *seek_file_func) (void *opaque, void *stream, unsigned long offset, int origin);
|
||||
typedef long (ZCALLBACK *seek64_file_func) (void *opaque, void *stream, ZPOS64_T offset, int origin);
|
||||
|
||||
typedef struct zlib_filefunc_def_s
|
||||
{
|
||||
open_file_func zopen_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell_file_func ztell_file;
|
||||
seek_file_func zseek_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
void* opaque;
|
||||
} zlib_filefunc_def;
|
||||
|
||||
typedef struct zlib_filefunc64_def_s
|
||||
{
|
||||
open64_file_func zopen64_file;
|
||||
read_file_func zread_file;
|
||||
write_file_func zwrite_file;
|
||||
tell64_file_func ztell64_file;
|
||||
seek64_file_func zseek64_file;
|
||||
close_file_func zclose_file;
|
||||
testerror_file_func zerror_file;
|
||||
void* opaque;
|
||||
} zlib_filefunc64_def;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define ZLIB_FILEFUNC_SEEK_SET (0)
|
||||
#define ZLIB_FILEFUNC_SEEK_CUR (1)
|
||||
#define ZLIB_FILEFUNC_SEEK_END (2)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_READ (1)
|
||||
#define ZLIB_FILEFUNC_MODE_WRITE (2)
|
||||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
|
||||
|
||||
#define ZLIB_FILEFUNC_MODE_EXISTING (4)
|
||||
#define ZLIB_FILEFUNC_MODE_CREATE (8)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
ZEXPORT void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
|
||||
ZEXPORT void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
ZEXPORT void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
|
||||
ZEXPORT void fill_win32_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
ZEXPORT void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
ZEXPORT void fill_memory_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if MZ_COMPAT_VERSION <= 110
|
||||
#define mz_dos_date dosDate
|
||||
#else
|
||||
#define mz_dos_date dos_date
|
||||
#endif
|
||||
|
||||
typedef struct tm tm_unz;
|
||||
typedef struct tm tm_zip;
|
||||
|
||||
typedef struct {
|
||||
uint32_t mz_dos_date;
|
||||
struct tm tmz_date;
|
||||
uint16_t internal_fa; /* internal file attributes 2 bytes */
|
||||
uint32_t external_fa; /* external file attributes 4 bytes */
|
||||
} zip_fileinfo;
|
||||
|
||||
typedef const char *zipcharpc;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define ZIP_OK (0)
|
||||
#define ZIP_EOF (0)
|
||||
#define ZIP_ERRNO (-1)
|
||||
#define ZIP_PARAMERROR (-102)
|
||||
#define ZIP_BADZIPFILE (-103)
|
||||
#define ZIP_INTERNALERROR (-104)
|
||||
|
||||
#ifndef Z_DEFLATED
|
||||
#define Z_DEFLATED (8)
|
||||
#endif
|
||||
#define Z_BZIP2ED (12)
|
||||
|
||||
#define APPEND_STATUS_CREATE (0)
|
||||
#define APPEND_STATUS_CREATEAFTER (1)
|
||||
#define APPEND_STATUS_ADDINZIP (2)
|
||||
|
||||
/***************************************************************************/
|
||||
/* Writing a zip file */
|
||||
|
||||
ZEXPORT zipFile zipOpen(const char *path, int append);
|
||||
ZEXPORT zipFile zipOpen64(const void *path, int append);
|
||||
ZEXPORT zipFile zipOpen2(const char *path, int append, const char **globalcomment,
|
||||
zlib_filefunc_def *pzlib_filefunc_def);
|
||||
|
||||
ZEXPORT zipFile zipOpen2_64(const void *path, int append, const char **globalcomment,
|
||||
zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
ZEXPORT zipFile zipOpen_MZ(void *stream, int append, const char **globalcomment);
|
||||
|
||||
ZEXPORT void* zipGetHandle_MZ(zipFile);
|
||||
ZEXPORT void* zipGetStream_MZ(zipFile file);
|
||||
|
||||
ZEXPORT int zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level);
|
||||
ZEXPORT int zipOpenNewFileInZip_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level,
|
||||
int zip64);
|
||||
ZEXPORT int zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level,
|
||||
int raw);
|
||||
ZEXPORT int zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level,
|
||||
int raw, int zip64);
|
||||
ZEXPORT int zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
unsigned long crc_for_crypting);
|
||||
ZEXPORT int zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
uint32_t crc_for_crypting, int zip64);
|
||||
ZEXPORT int zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
unsigned long crc_for_crypting, unsigned long version_madeby, unsigned long flag_base);
|
||||
ZEXPORT int zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
unsigned long crc_for_crypting, unsigned long version_madeby, unsigned long flag_base, int zip64);
|
||||
ZEXPORT int zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
|
||||
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
|
||||
uint16_t size_extrafield_global, const char *comment, int compression_method, int level,
|
||||
int raw, int windowBits, int memLevel, int strategy, const char *password,
|
||||
unsigned long crc_for_crypting, unsigned long version_madeby, unsigned long flag_base, int zip64);
|
||||
|
||||
ZEXPORT int zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);
|
||||
|
||||
ZEXPORT int zipCloseFileInZipRaw(zipFile file, unsigned long uncompressed_size, unsigned long crc32);
|
||||
ZEXPORT int zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, unsigned long crc32);
|
||||
ZEXPORT int zipCloseFileInZip(zipFile file);
|
||||
ZEXPORT int zipCloseFileInZip64(zipFile file);
|
||||
|
||||
ZEXPORT int zipClose(zipFile file, const char *global_comment);
|
||||
ZEXPORT int zipClose_64(zipFile file, const char *global_comment);
|
||||
ZEXPORT int zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby);
|
||||
int zipClose_MZ(zipFile file, const char *global_comment);
|
||||
int zipClose2_MZ(zipFile file, const char *global_comment, uint16_t version_madeby);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
|
||||
/* like the STRICT of WIN32, we define a pointer that cannot be converted
|
||||
from (void*) without cast */
|
||||
typedef struct TagunzFile__ { int unused; } unz_file__;
|
||||
typedef unz_file__ *unzFile;
|
||||
#else
|
||||
typedef void *unzFile;
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define UNZ_OK (0)
|
||||
#define UNZ_END_OF_LIST_OF_FILE (-100)
|
||||
#define UNZ_ERRNO (-1)
|
||||
#define UNZ_EOF (0)
|
||||
#define UNZ_PARAMERROR (-102)
|
||||
#define UNZ_BADZIPFILE (-103)
|
||||
#define UNZ_INTERNALERROR (-104)
|
||||
#define UNZ_CRCERROR (-105)
|
||||
#define UNZ_BADPASSWORD (-106)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct unz_global_info64_s {
|
||||
uint64_t number_entry; /* total number of entries in the central dir on this disk */
|
||||
uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP */
|
||||
uint16_t size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info64;
|
||||
|
||||
typedef struct unz_global_info_s {
|
||||
uint32_t number_entry; /* total number of entries in the central dir on this disk */
|
||||
uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP */
|
||||
uint16_t size_comment; /* size of the global comment of the zipfile */
|
||||
} unz_global_info;
|
||||
|
||||
typedef struct unz_file_info64_s {
|
||||
uint16_t version; /* version made by 2 bytes */
|
||||
uint16_t version_needed; /* version needed to extract 2 bytes */
|
||||
uint16_t flag; /* general purpose bit flag 2 bytes */
|
||||
uint16_t compression_method; /* compression method 2 bytes */
|
||||
uint32_t mz_dos_date; /* last mod file date in Dos fmt 4 bytes */
|
||||
struct tm tmu_date;
|
||||
uint32_t crc; /* crc-32 4 bytes */
|
||||
uint64_t compressed_size; /* compressed size 8 bytes */
|
||||
uint64_t uncompressed_size; /* uncompressed size 8 bytes */
|
||||
uint16_t size_filename; /* filename length 2 bytes */
|
||||
uint16_t size_file_extra; /* extra field length 2 bytes */
|
||||
uint16_t size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uint32_t disk_num_start; /* disk number start 4 bytes */
|
||||
uint16_t internal_fa; /* internal file attributes 2 bytes */
|
||||
uint32_t external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
uint64_t disk_offset;
|
||||
|
||||
uint16_t size_file_extra_internal;
|
||||
} unz_file_info64;
|
||||
|
||||
typedef struct unz_file_info_s {
|
||||
uint16_t version; /* version made by 2 bytes */
|
||||
uint16_t version_needed; /* version needed to extract 2 bytes */
|
||||
uint16_t flag; /* general purpose bit flag 2 bytes */
|
||||
uint16_t compression_method; /* compression method 2 bytes */
|
||||
uint32_t mz_dos_date; /* last mod file date in Dos fmt 4 bytes */
|
||||
struct tm tmu_date;
|
||||
uint32_t crc; /* crc-32 4 bytes */
|
||||
uint32_t compressed_size; /* compressed size 4 bytes */
|
||||
uint32_t uncompressed_size; /* uncompressed size 4 bytes */
|
||||
uint16_t size_filename; /* filename length 2 bytes */
|
||||
uint16_t size_file_extra; /* extra field length 2 bytes */
|
||||
uint16_t size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
uint16_t disk_num_start; /* disk number start 2 bytes */
|
||||
uint16_t internal_fa; /* internal file attributes 2 bytes */
|
||||
uint32_t external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
uint64_t disk_offset;
|
||||
} unz_file_info;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
|
||||
typedef int (*unzIteratorFunction)(unzFile file);
|
||||
typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
|
||||
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment,
|
||||
uint16_t comment_size);
|
||||
|
||||
/***************************************************************************/
|
||||
/* Reading a zip file */
|
||||
|
||||
ZEXPORT unzFile unzOpen(const char *path);
|
||||
ZEXPORT unzFile unzOpen64(const void *path);
|
||||
ZEXPORT unzFile unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
|
||||
ZEXPORT unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
|
||||
unzFile unzOpen_MZ(void *stream);
|
||||
|
||||
ZEXPORT int unzClose(unzFile file);
|
||||
ZEXPORT int unzClose_MZ(unzFile file);
|
||||
|
||||
ZEXPORT void* unzGetHandle_MZ(unzFile file);
|
||||
ZEXPORT void* unzGetStream_MZ(zipFile file);
|
||||
|
||||
ZEXPORT int unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32);
|
||||
ZEXPORT int unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info);
|
||||
ZEXPORT int unzGetGlobalComment(unzFile file, char *comment, unsigned long comment_size);
|
||||
|
||||
ZEXPORT int unzOpenCurrentFile(unzFile file);
|
||||
ZEXPORT int unzOpenCurrentFilePassword(unzFile file, const char *password);
|
||||
ZEXPORT int unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
|
||||
ZEXPORT int unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
|
||||
ZEXPORT int unzReadCurrentFile(unzFile file, void *buf, uint32_t len);
|
||||
ZEXPORT int unzCloseCurrentFile(unzFile file);
|
||||
|
||||
ZEXPORT int unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
|
||||
unsigned long filename_size, void *extrafield, unsigned long extrafield_size, char *comment,
|
||||
unsigned long comment_size);
|
||||
ZEXPORT int unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_info, char *filename,
|
||||
unsigned long filename_size, void *extrafield, unsigned long extrafield_size, char *comment,
|
||||
unsigned long comment_size);
|
||||
|
||||
ZEXPORT int unzGoToFirstFile(unzFile file);
|
||||
ZEXPORT int unzGoToNextFile(unzFile file);
|
||||
ZEXPORT int unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
|
||||
|
||||
ZEXPORT int unzGetLocalExtrafield(unzFile file, void *buf, unsigned int len);
|
||||
|
||||
/***************************************************************************/
|
||||
/* Raw access to zip file */
|
||||
|
||||
typedef struct unz_file_pos_s {
|
||||
uint32_t pos_in_zip_directory; /* offset in zip file directory */
|
||||
uint32_t num_of_file; /* # of file */
|
||||
} unz_file_pos;
|
||||
|
||||
ZEXPORT int unzGetFilePos(unzFile file, unz_file_pos *file_pos);
|
||||
ZEXPORT int unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
|
||||
|
||||
typedef struct unz64_file_pos_s {
|
||||
int64_t pos_in_zip_directory; /* offset in zip file directory */
|
||||
uint64_t num_of_file; /* # of file */
|
||||
} unz64_file_pos;
|
||||
|
||||
ZEXPORT int unzGetFilePos64(unzFile file, unz64_file_pos *file_pos);
|
||||
ZEXPORT int unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos);
|
||||
|
||||
ZEXPORT int64_t unzGetOffset64(unzFile file);
|
||||
ZEXPORT unsigned long
|
||||
unzGetOffset(unzFile file);
|
||||
ZEXPORT int unzSetOffset64(unzFile file, int64_t pos);
|
||||
ZEXPORT int unzSetOffset(unzFile file, unsigned long pos);
|
||||
ZEXPORT int32_t unztell(unzFile file);
|
||||
ZEXPORT int32_t unzTell(unzFile file);
|
||||
ZEXPORT uint64_t unztell64(unzFile file);
|
||||
ZEXPORT uint64_t unzTell64(unzFile file);
|
||||
ZEXPORT int unzSeek(unzFile file, int32_t offset, int origin);
|
||||
ZEXPORT int unzSeek64(unzFile file, int64_t offset, int origin);
|
||||
ZEXPORT int unzEndOfFile(unzFile file);
|
||||
ZEXPORT int unzeof(unzFile file);
|
||||
ZEXPORT void* unzGetStream(unzFile file);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+196
@@ -0,0 +1,196 @@
|
||||
/* mz_crypt.c -- Crypto/hash functions
|
||||
part of the minizip-ng project
|
||||
|
||||
Copyright (C) 2010-2021 Nathan Moinvaziri
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_crypt.h"
|
||||
|
||||
#if defined(HAVE_ZLIB)
|
||||
# include "zlib.h"
|
||||
# if defined(ZLIBNG_VERNUM) && !defined(ZLIB_COMPAT)
|
||||
# include "zlib-ng.h"
|
||||
# endif
|
||||
#elif defined(HAVE_LZMA)
|
||||
# include "lzma.h"
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
/* Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng */
|
||||
|
||||
#if defined(HAVE_ZLIB) && defined(ZLIBNG_VERNUM)
|
||||
# if defined(ZLIB_COMPAT)
|
||||
# define ZLIB_PREFIX(x) x
|
||||
# else
|
||||
# define ZLIB_PREFIX(x) zng_ ## x
|
||||
# endif
|
||||
typedef uint32_t z_crc_t;
|
||||
#elif defined(HAVE_ZLIB)
|
||||
# define ZLIB_PREFIX(x) x
|
||||
# if (ZLIB_VERNUM < 0x1270)
|
||||
typedef unsigned long z_crc_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(MZ_ZIP_NO_CRYPTO)
|
||||
int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
|
||||
return mz_os_rand(buf, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t mz_crypt_crc32_update(uint32_t value, const uint8_t *buf, int32_t size) {
|
||||
#if defined(HAVE_ZLIB)
|
||||
return (uint32_t)ZLIB_PREFIX(crc32)((z_crc_t)value, buf, (uInt)size);
|
||||
#elif defined(HAVE_LZMA)
|
||||
return (uint32_t)lzma_crc32(buf, (size_t)size, (uint32_t)value);
|
||||
#else
|
||||
static uint32_t crc32_table[256] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
|
||||
};
|
||||
value = ~value;
|
||||
|
||||
while (size > 0) {
|
||||
value = (value >> 8) ^ crc32_table[(value ^ *buf) & 0xFF];
|
||||
|
||||
buf += 1;
|
||||
size -= 1;
|
||||
}
|
||||
|
||||
return ~value;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(HAVE_WZAES)
|
||||
int32_t mz_crypt_pbkdf2(uint8_t *password, int32_t password_length, uint8_t *salt,
|
||||
int32_t salt_length, int32_t iteration_count, uint8_t *key, int32_t key_length) {
|
||||
void *hmac1 = NULL;
|
||||
void *hmac2 = NULL;
|
||||
void *hmac3 = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
uint16_t i = 0;
|
||||
uint16_t j = 0;
|
||||
uint16_t k = 0;
|
||||
uint16_t block_count = 0;
|
||||
uint8_t uu[MZ_HASH_SHA1_SIZE];
|
||||
uint8_t ux[MZ_HASH_SHA1_SIZE];
|
||||
|
||||
if (password == NULL || salt == NULL || key == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
memset(key, 0, key_length);
|
||||
|
||||
mz_crypt_hmac_create(&hmac1);
|
||||
mz_crypt_hmac_create(&hmac2);
|
||||
mz_crypt_hmac_create(&hmac3);
|
||||
|
||||
mz_crypt_hmac_set_algorithm(hmac1, MZ_HASH_SHA1);
|
||||
mz_crypt_hmac_set_algorithm(hmac2, MZ_HASH_SHA1);
|
||||
mz_crypt_hmac_set_algorithm(hmac3, MZ_HASH_SHA1);
|
||||
|
||||
err = mz_crypt_hmac_init(hmac1, password, password_length);
|
||||
if (err == MZ_OK)
|
||||
err = mz_crypt_hmac_init(hmac2, password, password_length);
|
||||
if (err == MZ_OK)
|
||||
err = mz_crypt_hmac_update(hmac2, salt, salt_length);
|
||||
|
||||
block_count = 1 + ((uint16_t)key_length - 1) / MZ_HASH_SHA1_SIZE;
|
||||
|
||||
for (i = 0; (err == MZ_OK) && (i < block_count); i += 1) {
|
||||
memset(ux, 0, sizeof(ux));
|
||||
|
||||
err = mz_crypt_hmac_copy(hmac2, hmac3);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
uu[0] = (uint8_t)((i + 1) >> 24);
|
||||
uu[1] = (uint8_t)((i + 1) >> 16);
|
||||
uu[2] = (uint8_t)((i + 1) >> 8);
|
||||
uu[3] = (uint8_t)(i + 1);
|
||||
|
||||
for (j = 0, k = 4; j < iteration_count; j += 1) {
|
||||
err = mz_crypt_hmac_update(hmac3, uu, k);
|
||||
if (err == MZ_OK)
|
||||
err = mz_crypt_hmac_end(hmac3, uu, sizeof(uu));
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
for(k = 0; k < MZ_HASH_SHA1_SIZE; k += 1)
|
||||
ux[k] ^= uu[k];
|
||||
|
||||
err = mz_crypt_hmac_copy(hmac1, hmac3);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
}
|
||||
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
|
||||
j = 0;
|
||||
k = i * MZ_HASH_SHA1_SIZE;
|
||||
|
||||
while (j < MZ_HASH_SHA1_SIZE && k < key_length)
|
||||
key[k++] = ux[j++];
|
||||
}
|
||||
|
||||
/* hmac3 uses the same provider as hmac2, so it must be deleted
|
||||
before the context is destroyed. */
|
||||
mz_crypt_hmac_delete(&hmac3);
|
||||
mz_crypt_hmac_delete(&hmac1);
|
||||
mz_crypt_hmac_delete(&hmac2);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
Vendored
+65
@@ -0,0 +1,65 @@
|
||||
/* mz_crypt.h -- Crypto/hash functions
|
||||
part of the minizip-ng project
|
||||
|
||||
Copyright (C) 2010-2021 Nathan Moinvaziri
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_CRYPT_H
|
||||
#define MZ_CRYPT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint32_t mz_crypt_crc32_update(uint32_t value, const uint8_t *buf, int32_t size);
|
||||
|
||||
int32_t mz_crypt_pbkdf2(uint8_t *password, int32_t password_length, uint8_t *salt,
|
||||
int32_t salt_length, int32_t iteration_count, uint8_t *key, int32_t key_length);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_crypt_rand(uint8_t *buf, int32_t size);
|
||||
|
||||
void mz_crypt_sha_reset(void *handle);
|
||||
int32_t mz_crypt_sha_begin(void *handle);
|
||||
int32_t mz_crypt_sha_update(void *handle, const void *buf, int32_t size);
|
||||
int32_t mz_crypt_sha_end(void *handle, uint8_t *digest, int32_t digest_size);
|
||||
void mz_crypt_sha_set_algorithm(void *handle, uint16_t algorithm);
|
||||
void* mz_crypt_sha_create(void **handle);
|
||||
void mz_crypt_sha_delete(void **handle);
|
||||
|
||||
void mz_crypt_aes_reset(void *handle);
|
||||
int32_t mz_crypt_aes_encrypt(void *handle, uint8_t *buf, int32_t size);
|
||||
int32_t mz_crypt_aes_decrypt(void *handle, uint8_t *buf, int32_t size);
|
||||
int32_t mz_crypt_aes_set_encrypt_key(void *handle, const void *key, int32_t key_length);
|
||||
int32_t mz_crypt_aes_set_decrypt_key(void *handle, const void *key, int32_t key_length);
|
||||
void mz_crypt_aes_set_mode(void *handle, int32_t mode);
|
||||
void* mz_crypt_aes_create(void **handle);
|
||||
void mz_crypt_aes_delete(void **handle);
|
||||
|
||||
void mz_crypt_hmac_reset(void *handle);
|
||||
int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length);
|
||||
int32_t mz_crypt_hmac_update(void *handle, const void *buf, int32_t size);
|
||||
int32_t mz_crypt_hmac_end(void *handle, uint8_t *digest, int32_t digest_size);
|
||||
int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle);
|
||||
void mz_crypt_hmac_set_algorithm(void *handle, uint16_t algorithm);
|
||||
void* mz_crypt_hmac_create(void **handle);
|
||||
void mz_crypt_hmac_delete(void **handle);
|
||||
|
||||
int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data, int32_t cert_data_size,
|
||||
const char *cert_pwd, uint8_t **signature, int32_t *signature_size);
|
||||
int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+487
@@ -0,0 +1,487 @@
|
||||
/* mz_crypt_apple.c -- Crypto/hash functions for Apple
|
||||
part of the minizip-ng project
|
||||
|
||||
Copyright (C) 2010-2021 Nathan Moinvaziri
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CommonCrypto/CommonCryptor.h>
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#include <CommonCrypto/CommonHMAC.h>
|
||||
#include <Security/Security.h>
|
||||
#include <Security/SecPolicy.h>
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
|
||||
if (SecRandomCopyBytes(kSecRandomDefault, size, buf) != errSecSuccess)
|
||||
return 0;
|
||||
return size;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_crypt_sha_s {
|
||||
CC_SHA1_CTX ctx1;
|
||||
CC_SHA256_CTX ctx256;
|
||||
int32_t error;
|
||||
int32_t initialized;
|
||||
uint16_t algorithm;
|
||||
} mz_crypt_sha;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void mz_crypt_sha_reset(void *handle) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
|
||||
sha->error = 0;
|
||||
sha->initialized = 0;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_sha_begin(void *handle) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
|
||||
if (sha == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
mz_crypt_sha_reset(handle);
|
||||
|
||||
if (sha->algorithm == MZ_HASH_SHA1)
|
||||
sha->error = CC_SHA1_Init(&sha->ctx1);
|
||||
else if (sha->algorithm == MZ_HASH_SHA256)
|
||||
sha->error = CC_SHA256_Init(&sha->ctx256);
|
||||
else
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (!sha->error)
|
||||
return MZ_HASH_ERROR;
|
||||
|
||||
sha->initialized = 1;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_sha_update(void *handle, const void *buf, int32_t size) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
|
||||
if (sha == NULL || buf == NULL || !sha->initialized)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (sha->algorithm == MZ_HASH_SHA1)
|
||||
sha->error = CC_SHA1_Update(&sha->ctx1, buf, size);
|
||||
else
|
||||
sha->error = CC_SHA256_Update(&sha->ctx256, buf, size);
|
||||
|
||||
if (!sha->error)
|
||||
return MZ_HASH_ERROR;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_sha_end(void *handle, uint8_t *digest, int32_t digest_size) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
|
||||
if (sha == NULL || digest == NULL || !sha->initialized)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (sha->algorithm == MZ_HASH_SHA1) {
|
||||
if (digest_size < MZ_HASH_SHA1_SIZE)
|
||||
return MZ_BUF_ERROR;
|
||||
sha->error = CC_SHA1_Final(digest, &sha->ctx1);
|
||||
} else {
|
||||
if (digest_size < MZ_HASH_SHA256_SIZE)
|
||||
return MZ_BUF_ERROR;
|
||||
sha->error = CC_SHA256_Final(digest, &sha->ctx256);
|
||||
}
|
||||
|
||||
if (!sha->error)
|
||||
return MZ_HASH_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void mz_crypt_sha_set_algorithm(void *handle, uint16_t algorithm) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
sha->algorithm = algorithm;
|
||||
}
|
||||
|
||||
void *mz_crypt_sha_create(void **handle) {
|
||||
mz_crypt_sha *sha = NULL;
|
||||
|
||||
sha = (mz_crypt_sha *)MZ_ALLOC(sizeof(mz_crypt_sha));
|
||||
if (sha != NULL) {
|
||||
memset(sha, 0, sizeof(mz_crypt_sha));
|
||||
sha->algorithm = MZ_HASH_SHA256;
|
||||
}
|
||||
if (handle != NULL)
|
||||
*handle = sha;
|
||||
|
||||
return sha;
|
||||
}
|
||||
|
||||
void mz_crypt_sha_delete(void **handle) {
|
||||
mz_crypt_sha *sha = NULL;
|
||||
if (handle == NULL)
|
||||
return;
|
||||
sha = (mz_crypt_sha *)*handle;
|
||||
if (sha != NULL) {
|
||||
mz_crypt_sha_reset(*handle);
|
||||
MZ_FREE(sha);
|
||||
}
|
||||
*handle = NULL;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_crypt_aes_s {
|
||||
CCCryptorRef crypt;
|
||||
int32_t mode;
|
||||
int32_t error;
|
||||
} mz_crypt_aes;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void mz_crypt_aes_reset(void *handle) {
|
||||
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
||||
|
||||
if (aes->crypt != NULL)
|
||||
CCCryptorRelease(aes->crypt);
|
||||
aes->crypt = NULL;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_aes_encrypt(void *handle, uint8_t *buf, int32_t size) {
|
||||
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
||||
size_t data_moved = 0;
|
||||
|
||||
if (aes == NULL || buf == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (size != MZ_AES_BLOCK_SIZE)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
aes->error = CCCryptorUpdate(aes->crypt, buf, size, buf, size, &data_moved);
|
||||
|
||||
if (aes->error != kCCSuccess)
|
||||
return MZ_HASH_ERROR;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_aes_decrypt(void *handle, uint8_t *buf, int32_t size) {
|
||||
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
||||
size_t data_moved = 0;
|
||||
|
||||
if (aes == NULL || buf == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (size != MZ_AES_BLOCK_SIZE)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
aes->error = CCCryptorUpdate(aes->crypt, buf, size, buf, size, &data_moved);
|
||||
|
||||
if (aes->error != kCCSuccess)
|
||||
return MZ_HASH_ERROR;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_aes_set_encrypt_key(void *handle, const void *key, int32_t key_length) {
|
||||
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
||||
|
||||
|
||||
if (aes == NULL || key == NULL || key_length == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
mz_crypt_aes_reset(handle);
|
||||
|
||||
aes->error = CCCryptorCreate(kCCEncrypt, kCCAlgorithmAES, kCCOptionECBMode,
|
||||
key, key_length, NULL, &aes->crypt);
|
||||
|
||||
if (aes->error != kCCSuccess)
|
||||
return MZ_HASH_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_aes_set_decrypt_key(void *handle, const void *key, int32_t key_length) {
|
||||
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
||||
|
||||
|
||||
if (aes == NULL || key == NULL || key_length == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
mz_crypt_aes_reset(handle);
|
||||
|
||||
aes->error = CCCryptorCreate(kCCDecrypt, kCCAlgorithmAES, kCCOptionECBMode,
|
||||
key, key_length, NULL, &aes->crypt);
|
||||
|
||||
if (aes->error != kCCSuccess)
|
||||
return MZ_HASH_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void mz_crypt_aes_set_mode(void *handle, int32_t mode) {
|
||||
mz_crypt_aes *aes = (mz_crypt_aes *)handle;
|
||||
aes->mode = mode;
|
||||
}
|
||||
|
||||
void *mz_crypt_aes_create(void **handle) {
|
||||
mz_crypt_aes *aes = NULL;
|
||||
|
||||
aes = (mz_crypt_aes *)MZ_ALLOC(sizeof(mz_crypt_aes));
|
||||
if (aes != NULL)
|
||||
memset(aes, 0, sizeof(mz_crypt_aes));
|
||||
if (handle != NULL)
|
||||
*handle = aes;
|
||||
|
||||
return aes;
|
||||
}
|
||||
|
||||
void mz_crypt_aes_delete(void **handle) {
|
||||
mz_crypt_aes *aes = NULL;
|
||||
if (handle == NULL)
|
||||
return;
|
||||
aes = (mz_crypt_aes *)*handle;
|
||||
if (aes != NULL) {
|
||||
mz_crypt_aes_reset(*handle);
|
||||
MZ_FREE(aes);
|
||||
}
|
||||
*handle = NULL;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_crypt_hmac_s {
|
||||
CCHmacContext ctx;
|
||||
int32_t initialized;
|
||||
int32_t error;
|
||||
uint16_t algorithm;
|
||||
} mz_crypt_hmac;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static void mz_crypt_hmac_free(void *handle) {
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
memset(&hmac->ctx, 0, sizeof(hmac->ctx));
|
||||
}
|
||||
|
||||
void mz_crypt_hmac_reset(void *handle) {
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
mz_crypt_hmac_free(handle);
|
||||
hmac->error = 0;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
CCHmacAlgorithm algorithm = 0;
|
||||
|
||||
if (hmac == NULL || key == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
mz_crypt_hmac_reset(handle);
|
||||
|
||||
if (hmac->algorithm == MZ_HASH_SHA1)
|
||||
algorithm = kCCHmacAlgSHA1;
|
||||
else if (hmac->algorithm == MZ_HASH_SHA256)
|
||||
algorithm = kCCHmacAlgSHA256;
|
||||
else
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
CCHmacInit(&hmac->ctx, algorithm, key, key_length);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_hmac_update(void *handle, const void *buf, int32_t size) {
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
|
||||
if (hmac == NULL || buf == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
CCHmacUpdate(&hmac->ctx, buf, size);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_hmac_end(void *handle, uint8_t *digest, int32_t digest_size) {
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
|
||||
if (hmac == NULL || digest == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (hmac->algorithm == MZ_HASH_SHA1) {
|
||||
if (digest_size < MZ_HASH_SHA1_SIZE)
|
||||
return MZ_BUF_ERROR;
|
||||
CCHmacFinal(&hmac->ctx, digest);
|
||||
} else {
|
||||
if (digest_size < MZ_HASH_SHA256_SIZE)
|
||||
return MZ_BUF_ERROR;
|
||||
CCHmacFinal(&hmac->ctx, digest);
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void mz_crypt_hmac_set_algorithm(void *handle, uint16_t algorithm) {
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
hmac->algorithm = algorithm;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle) {
|
||||
mz_crypt_hmac *source = (mz_crypt_hmac *)src_handle;
|
||||
mz_crypt_hmac *target = (mz_crypt_hmac *)target_handle;
|
||||
|
||||
if (source == NULL || target == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
memcpy(&target->ctx, &source->ctx, sizeof(CCHmacContext));
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
void *mz_crypt_hmac_create(void **handle) {
|
||||
mz_crypt_hmac *hmac = NULL;
|
||||
|
||||
hmac = (mz_crypt_hmac *)MZ_ALLOC(sizeof(mz_crypt_hmac));
|
||||
if (hmac != NULL) {
|
||||
memset(hmac, 0, sizeof(mz_crypt_hmac));
|
||||
hmac->algorithm = MZ_HASH_SHA256;
|
||||
}
|
||||
if (handle != NULL)
|
||||
*handle = hmac;
|
||||
|
||||
return hmac;
|
||||
}
|
||||
|
||||
void mz_crypt_hmac_delete(void **handle) {
|
||||
mz_crypt_hmac *hmac = NULL;
|
||||
if (handle == NULL)
|
||||
return;
|
||||
hmac = (mz_crypt_hmac *)*handle;
|
||||
if (hmac != NULL) {
|
||||
mz_crypt_hmac_free(*handle);
|
||||
MZ_FREE(hmac);
|
||||
}
|
||||
*handle = NULL;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(MZ_ZIP_SIGNING)
|
||||
int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data, int32_t cert_data_size,
|
||||
const char *cert_pwd, uint8_t **signature, int32_t *signature_size) {
|
||||
CFStringRef password_ref = NULL;
|
||||
CFDictionaryRef options_dict = NULL;
|
||||
CFDictionaryRef identity_trust = NULL;
|
||||
CFDataRef signature_out = NULL;
|
||||
CFDataRef pkcs12_data = NULL;
|
||||
CFArrayRef items = 0;
|
||||
SecIdentityRef identity = NULL;
|
||||
SecTrustRef trust = NULL;
|
||||
OSStatus status = noErr;
|
||||
const void *options_key[2] = { kSecImportExportPassphrase, kSecReturnRef };
|
||||
const void *options_values[2] = { 0, kCFBooleanTrue };
|
||||
int32_t err = MZ_SIGN_ERROR;
|
||||
|
||||
|
||||
if (message == NULL || cert_data == NULL || signature == NULL || signature_size == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
*signature = NULL;
|
||||
*signature_size = 0;
|
||||
|
||||
password_ref = CFStringCreateWithCString(0, cert_pwd, kCFStringEncodingUTF8);
|
||||
options_values[0] = password_ref;
|
||||
|
||||
options_dict = CFDictionaryCreate(0, options_key, options_values, 2, 0, 0);
|
||||
if (options_dict)
|
||||
pkcs12_data = CFDataCreate(0, cert_data, cert_data_size);
|
||||
if (pkcs12_data)
|
||||
status = SecPKCS12Import(pkcs12_data, options_dict, &items);
|
||||
if (status == noErr)
|
||||
identity_trust = CFArrayGetValueAtIndex(items, 0);
|
||||
if (identity_trust)
|
||||
identity = (SecIdentityRef)CFDictionaryGetValue(identity_trust, kSecImportItemIdentity);
|
||||
if (identity)
|
||||
trust = (SecTrustRef)CFDictionaryGetValue(identity_trust, kSecImportItemTrust);
|
||||
if (trust) {
|
||||
status = CMSEncodeContent(identity, NULL, NULL, FALSE, 0, message, message_size, &signature_out);
|
||||
|
||||
if (status == errSecSuccess) {
|
||||
*signature_size = CFDataGetLength(signature_out);
|
||||
*signature = (uint8_t *)MZ_ALLOC(*signature_size);
|
||||
|
||||
memcpy(*signature, CFDataGetBytePtr(signature_out), *signature_size);
|
||||
|
||||
err = MZ_OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (signature_out)
|
||||
CFRelease(signature_out);
|
||||
if (items)
|
||||
CFRelease(items);
|
||||
if (pkcs12_data)
|
||||
CFRelease(pkcs12_data);
|
||||
if (options_dict)
|
||||
CFRelease(options_dict);
|
||||
if (password_ref)
|
||||
CFRelease(password_ref);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size) {
|
||||
CMSDecoderRef decoder = NULL;
|
||||
CMSSignerStatus signer_status = 0;
|
||||
CFDataRef message_out = NULL;
|
||||
SecPolicyRef trust_policy = NULL;
|
||||
OSStatus status = noErr;
|
||||
OSStatus verify_status = noErr;
|
||||
size_t signer_count = 0;
|
||||
size_t i = 0;
|
||||
int32_t err = MZ_SIGN_ERROR;
|
||||
|
||||
if (message == NULL || signature == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
status = CMSDecoderCreate(&decoder);
|
||||
if (status == errSecSuccess)
|
||||
status = CMSDecoderUpdateMessage(decoder, signature, signature_size);
|
||||
if (status == errSecSuccess)
|
||||
status = CMSDecoderFinalizeMessage(decoder);
|
||||
if (status == errSecSuccess)
|
||||
trust_policy = SecPolicyCreateBasicX509();
|
||||
|
||||
if (status == errSecSuccess && trust_policy) {
|
||||
CMSDecoderGetNumSigners(decoder, &signer_count);
|
||||
if (signer_count > 0)
|
||||
err = MZ_OK;
|
||||
for (i = 0; i < signer_count; i += 1) {
|
||||
status = CMSDecoderCopySignerStatus(decoder, i, trust_policy, TRUE, &signer_status, NULL, &verify_status);
|
||||
if (status != errSecSuccess || verify_status != 0 || signer_status != kCMSSignerValid) {
|
||||
err = MZ_SIGN_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (err == MZ_OK) {
|
||||
status = CMSDecoderCopyContent(decoder, &message_out);
|
||||
if ((status != errSecSuccess) ||
|
||||
(CFDataGetLength(message_out) != message_size) ||
|
||||
(memcmp(message, CFDataGetBytePtr(message_out), message_size) != 0))
|
||||
err = MZ_SIGN_ERROR;
|
||||
}
|
||||
|
||||
if (trust_policy)
|
||||
CFRelease(trust_policy);
|
||||
if (decoder)
|
||||
CFRelease(decoder);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
Vendored
+638
File diff suppressed because it is too large
Load Diff
Vendored
+739
File diff suppressed because it is too large
Load Diff
Vendored
+354
@@ -0,0 +1,354 @@
|
||||
/* mz_os.c -- System functions
|
||||
part of the minizip-ng project
|
||||
|
||||
Copyright (C) 2010-2021 Nathan Moinvaziri
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
https://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_crypt.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
#include <ctype.h> /* tolower */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path) {
|
||||
int32_t path_len = 0;
|
||||
|
||||
if (path == NULL || join == NULL || max_path == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
path_len = (int32_t)strlen(path);
|
||||
|
||||
if (path_len == 0) {
|
||||
strncpy(path, join, max_path - 1);
|
||||
path[max_path - 1] = 0;
|
||||
} else {
|
||||
mz_path_append_slash(path, max_path, MZ_PATH_SLASH_PLATFORM);
|
||||
strncat(path, join, max_path - path_len);
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_append_slash(char *path, int32_t max_path, char slash) {
|
||||
int32_t path_len = (int32_t)strlen(path);
|
||||
if ((path_len + 2) >= max_path)
|
||||
return MZ_BUF_ERROR;
|
||||
if (path[path_len - 1] != '\\' && path[path_len - 1] != '/') {
|
||||
path[path_len] = slash;
|
||||
path[path_len + 1] = 0;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_remove_slash(char *path) {
|
||||
int32_t path_len = (int32_t)strlen(path);
|
||||
while (path_len > 0) {
|
||||
if (path[path_len - 1] == '\\' || path[path_len - 1] == '/')
|
||||
path[path_len - 1] = 0;
|
||||
else
|
||||
break;
|
||||
|
||||
path_len -= 1;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_has_slash(const char *path) {
|
||||
int32_t path_len = (int32_t)strlen(path);
|
||||
if (path[path_len - 1] != '\\' && path[path_len - 1] != '/')
|
||||
return MZ_EXIST_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_convert_slashes(char *path, char slash) {
|
||||
int32_t i = 0;
|
||||
|
||||
for (i = 0; i < (int32_t)strlen(path); i += 1) {
|
||||
if (path[i] == '\\' || path[i] == '/')
|
||||
path[i] = slash;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case) {
|
||||
while (*path != 0) {
|
||||
switch (*wildcard) {
|
||||
case '*':
|
||||
|
||||
if (*(wildcard + 1) == 0)
|
||||
return MZ_OK;
|
||||
|
||||
while (*path != 0) {
|
||||
if (mz_path_compare_wc(path, (wildcard + 1), ignore_case) == MZ_OK)
|
||||
return MZ_OK;
|
||||
|
||||
path += 1;
|
||||
}
|
||||
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
default:
|
||||
/* Ignore differences in path slashes on platforms */
|
||||
if ((*path == '\\' && *wildcard == '/') || (*path == '/' && *wildcard == '\\'))
|
||||
break;
|
||||
|
||||
if (ignore_case) {
|
||||
if (tolower(*path) != tolower(*wildcard))
|
||||
return MZ_EXIST_ERROR;
|
||||
} else {
|
||||
if (*path != *wildcard)
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
path += 1;
|
||||
wildcard += 1;
|
||||
}
|
||||
|
||||
if ((*wildcard != 0) && (*wildcard != '*'))
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_resolve(const char *path, char *output, int32_t max_output) {
|
||||
const char *source = path;
|
||||
const char *check = output;
|
||||
char *target = output;
|
||||
|
||||
|
||||
if (max_output <= 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
while (*source != 0 && max_output > 1) {
|
||||
check = source;
|
||||
if ((*check == '\\') || (*check == '/'))
|
||||
check += 1;
|
||||
|
||||
if ((source == path) || (target == output) || (check != source)) {
|
||||
/* Skip double paths */
|
||||
if ((*check == '\\') || (*check == '/')) {
|
||||
source += 1;
|
||||
continue;
|
||||
}
|
||||
if (*check == '.') {
|
||||
check += 1;
|
||||
|
||||
/* Remove . if at end of string and not at the beginning */
|
||||
if ((*check == 0) && (source != path && target != output)) {
|
||||
/* Copy last slash */
|
||||
*target = *source;
|
||||
target += 1;
|
||||
max_output -= 1;
|
||||
source += (check - source);
|
||||
continue;
|
||||
}
|
||||
/* Remove . if not at end of string */
|
||||
else if ((*check == '\\') || (*check == '/')) {
|
||||
source += (check - source);
|
||||
/* Skip slash if at beginning of string */
|
||||
if (target == output && *source != 0)
|
||||
source += 1;
|
||||
continue;
|
||||
}
|
||||
/* Go to parent directory .. */
|
||||
else if (*check == '.') {
|
||||
check += 1;
|
||||
if ((*check == 0) || (*check == '\\' || *check == '/')) {
|
||||
source += (check - source);
|
||||
|
||||
/* Search backwards for previous slash */
|
||||
if (target != output) {
|
||||
target -= 1;
|
||||
do {
|
||||
if ((*target == '\\') || (*target == '/'))
|
||||
break;
|
||||
|
||||
target -= 1;
|
||||
max_output += 1;
|
||||
} while (target > output);
|
||||
}
|
||||
|
||||
if ((target == output) && (*source != 0))
|
||||
source += 1;
|
||||
if ((*target == '\\' || *target == '/') && (*source == 0))
|
||||
target += 1;
|
||||
|
||||
*target = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*target = *source;
|
||||
|
||||
source += 1;
|
||||
target += 1;
|
||||
max_output -= 1;
|
||||
}
|
||||
|
||||
*target = 0;
|
||||
|
||||
if (*path == 0)
|
||||
return MZ_INTERNAL_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_remove_filename(char *path) {
|
||||
char *path_ptr = NULL;
|
||||
|
||||
if (path == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
path_ptr = path + strlen(path) - 1;
|
||||
|
||||
while (path_ptr > path) {
|
||||
if ((*path_ptr == '/') || (*path_ptr == '\\')) {
|
||||
*path_ptr = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
path_ptr -= 1;
|
||||
}
|
||||
|
||||
if (path_ptr == path)
|
||||
*path_ptr = 0;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_remove_extension(char *path) {
|
||||
char *path_ptr = NULL;
|
||||
|
||||
if (path == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
path_ptr = path + strlen(path) - 1;
|
||||
|
||||
while (path_ptr > path) {
|
||||
if ((*path_ptr == '/') || (*path_ptr == '\\'))
|
||||
break;
|
||||
if (*path_ptr == '.') {
|
||||
*path_ptr = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
path_ptr -= 1;
|
||||
}
|
||||
|
||||
if (path_ptr == path)
|
||||
*path_ptr = 0;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_get_filename(const char *path, const char **filename) {
|
||||
const char *match = NULL;
|
||||
|
||||
if (path == NULL || filename == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
*filename = NULL;
|
||||
|
||||
for (match = path; *match != 0; match += 1) {
|
||||
if ((*match == '\\') || (*match == '/'))
|
||||
*filename = match + 1;
|
||||
}
|
||||
|
||||
if (*filename == NULL)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_dir_make(const char *path) {
|
||||
int32_t err = MZ_OK;
|
||||
int16_t len = 0;
|
||||
char *current_dir = NULL;
|
||||
char *match = NULL;
|
||||
char hold = 0;
|
||||
|
||||
|
||||
len = (int16_t)strlen(path);
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
current_dir = (char *)MZ_ALLOC((uint16_t)len + 1);
|
||||
if (current_dir == NULL)
|
||||
return MZ_MEM_ERROR;
|
||||
|
||||
strcpy(current_dir, path);
|
||||
mz_path_remove_slash(current_dir);
|
||||
|
||||
err = mz_os_make_dir(current_dir);
|
||||
if (err != MZ_OK) {
|
||||
match = current_dir + 1;
|
||||
while (1) {
|
||||
while (*match != 0 && *match != '\\' && *match != '/')
|
||||
match += 1;
|
||||
hold = *match;
|
||||
*match = 0;
|
||||
|
||||
err = mz_os_make_dir(current_dir);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
if (hold == 0)
|
||||
break;
|
||||
|
||||
*match = hold;
|
||||
match += 1;
|
||||
}
|
||||
}
|
||||
|
||||
MZ_FREE(current_dir);
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc) {
|
||||
void *stream = NULL;
|
||||
uint32_t crc32 = 0;
|
||||
int32_t read = 0;
|
||||
int32_t err = MZ_OK;
|
||||
uint8_t buf[16384];
|
||||
|
||||
mz_stream_os_create(&stream);
|
||||
|
||||
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
|
||||
|
||||
if (err == MZ_OK) {
|
||||
do {
|
||||
read = mz_stream_os_read(stream, buf, sizeof(buf));
|
||||
|
||||
if (read < 0) {
|
||||
err = read;
|
||||
break;
|
||||
}
|
||||
|
||||
crc32 = mz_crypt_crc32_update(crc32, buf, read);
|
||||
} while ((err == MZ_OK) && (read > 0));
|
||||
|
||||
mz_stream_os_close(stream);
|
||||
}
|
||||
|
||||
*result_crc = crc32;
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
Vendored
+175
@@ -0,0 +1,175 @@
|
||||
/* mz_os.h -- System functions
|
||||
part of the minizip-ng project
|
||||
|
||||
Copyright (C) 2010-2021 Nathan Moinvaziri
|
||||
https://github.com/zlib-ng/minizip-ng
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_OS_H
|
||||
#define MZ_OS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(__APPLE__)
|
||||
# define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_OSX_DARWIN)
|
||||
#elif defined(__riscos__)
|
||||
# define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_RISCOS)
|
||||
#elif defined(_WIN32)
|
||||
# define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_WINDOWS_NTFS)
|
||||
#else
|
||||
# define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_UNIX)
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LZMA) || defined(HAVE_LIBCOMP)
|
||||
# define MZ_VERSION_MADEBY_ZIP_VERSION (63)
|
||||
#elif defined(HAVE_WZAES)
|
||||
# define MZ_VERSION_MADEBY_ZIP_VERSION (51)
|
||||
#elif defined(HAVE_BZIP2)
|
||||
# define MZ_VERSION_MADEBY_ZIP_VERSION (46)
|
||||
#else
|
||||
# define MZ_VERSION_MADEBY_ZIP_VERSION (45)
|
||||
#endif
|
||||
|
||||
#define MZ_VERSION_MADEBY ((MZ_VERSION_MADEBY_HOST_SYSTEM << 8) | \
|
||||
(MZ_VERSION_MADEBY_ZIP_VERSION))
|
||||
|
||||
#define MZ_PATH_SLASH_UNIX ('/')
|
||||
#if defined(_WIN32)
|
||||
# define MZ_PATH_SLASH_PLATFORM ('\\')
|
||||
#else
|
||||
# define MZ_PATH_SLASH_PLATFORM (MZ_PATH_SLASH_UNIX)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(_WIN32)
|
||||
struct dirent {
|
||||
char d_name[256];
|
||||
};
|
||||
typedef void* DIR;
|
||||
#else
|
||||
#include <dirent.h>
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
/* Shared functions */
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path);
|
||||
/* Combines two paths */
|
||||
|
||||
int32_t mz_path_append_slash(char *path, int32_t max_path, char slash);
|
||||
/* Appends a path slash on to the end of the path */
|
||||
|
||||
int32_t mz_path_remove_slash(char *path);
|
||||
/* Removes a path slash from the end of the path */
|
||||
|
||||
int32_t mz_path_has_slash(const char *path);
|
||||
/* Returns whether or not the path ends with slash */
|
||||
|
||||
int32_t mz_path_convert_slashes(char *path, char slash);
|
||||
/* Converts the slashes in a path */
|
||||
|
||||
int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case);
|
||||
/* Compare two paths with wildcard */
|
||||
|
||||
int32_t mz_path_resolve(const char *path, char *target, int32_t max_target);
|
||||
/* Resolves path */
|
||||
|
||||
int32_t mz_path_remove_filename(char *path);
|
||||
/* Remove the filename from a path */
|
||||
|
||||
int32_t mz_path_remove_extension(char *path);
|
||||
/* Remove the extension from a path */
|
||||
|
||||
int32_t mz_path_get_filename(const char *path, const char **filename);
|
||||
/* Get the filename from a path */
|
||||
|
||||
int32_t mz_dir_make(const char *path);
|
||||
/* Creates a directory recursively */
|
||||
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc);
|
||||
/* Gets the crc32 hash of a file */
|
||||
|
||||
/***************************************************************************/
|
||||
/* Platform specific functions */
|
||||
|
||||
wchar_t *mz_os_unicode_string_create(const char *string, int32_t encoding);
|
||||
/* Create unicode string from a utf8 string */
|
||||
|
||||
void mz_os_unicode_string_delete(wchar_t **string);
|
||||
/* Delete a unicode string that was created */
|
||||
|
||||
uint8_t *mz_os_utf8_string_create(const char *string, int32_t encoding);
|
||||
/* Create a utf8 string from a string with another encoding */
|
||||
|
||||
void mz_os_utf8_string_delete(uint8_t **string);
|
||||
/* Delete a utf8 string that was created */
|
||||
|
||||
int32_t mz_os_rand(uint8_t *buf, int32_t size);
|
||||
/* Random number generator (not cryptographically secure) */
|
||||
|
||||
int32_t mz_os_rename(const char *source_path, const char *target_path);
|
||||
/* Rename a file */
|
||||
|
||||
int32_t mz_os_unlink(const char *path);
|
||||
/* Delete an existing file */
|
||||
|
||||
int32_t mz_os_file_exists(const char *path);
|
||||
/* Check to see if a file exists */
|
||||
|
||||
int64_t mz_os_get_file_size(const char *path);
|
||||
/* Gets the length of a file */
|
||||
|
||||
int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
|
||||
/* Gets a file's modified, access, and creation dates if supported */
|
||||
|
||||
int32_t mz_os_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
|
||||
/* Sets a file's modified, access, and creation dates if supported */
|
||||
|
||||
int32_t mz_os_get_file_attribs(const char *path, uint32_t *attributes);
|
||||
/* Gets a file's attributes */
|
||||
|
||||
int32_t mz_os_set_file_attribs(const char *path, uint32_t attributes);
|
||||
/* Sets a file's attributes */
|
||||
|
||||
int32_t mz_os_make_dir(const char *path);
|
||||
/* Recursively creates a directory */
|
||||
|
||||
DIR* mz_os_open_dir(const char *path);
|
||||
/* Opens a directory for listing */
|
||||
struct
|
||||
dirent* mz_os_read_dir(DIR *dir);
|
||||
/* Reads a directory listing entry */
|
||||
|
||||
int32_t mz_os_close_dir(DIR *dir);
|
||||
/* Closes a directory that has been opened for listing */
|
||||
|
||||
int32_t mz_os_is_dir(const char *path);
|
||||
/* Checks to see if path is a directory */
|
||||
|
||||
int32_t mz_os_is_symlink(const char *path);
|
||||
/* Checks to see if path is a symbolic link */
|
||||
|
||||
int32_t mz_os_make_symlink(const char *path, const char *target_path);
|
||||
/* Creates a symbolic link pointing to a target */
|
||||
|
||||
int32_t mz_os_read_symlink(const char *path, char *target_path, int32_t max_target_path);
|
||||
/* Gets the target path for a symbolic link */
|
||||
|
||||
uint64_t mz_os_ms_time(void);
|
||||
/* Gets the time in milliseconds */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user