#ifndef _HAD_ZIPINT_H #define _HAD_ZIPINT_H /* zipint.h -- internal declarations. Copyright (C) 1999-2017 Dieter Baron and Thomas Klausner This file is part of libzip, a library to manipulate ZIP archives. The authors can be contacted at Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "compat.h" #include #ifndef _ZIP_COMPILING_DEPRECATED #define ZIP_DISABLE_DEPRECATED #endif #include "zip.h" #define CENTRAL_MAGIC "PK\1\2" #define LOCAL_MAGIC "PK\3\4" #define EOCD_MAGIC "PK\5\6" #define DATADES_MAGIC "PK\7\10" #define EOCD64LOC_MAGIC "PK\6\7" #define EOCD64_MAGIC "PK\6\6" #define CDENTRYSIZE 46u #define LENTRYSIZE 30 #define MAXCOMLEN 65536 #define MAXEXTLEN 65536 #define EOCDLEN 22 #define EOCD64LOCLEN 20 #define EOCD64LEN 56 #define CDBUFSIZE (MAXCOMLEN + EOCDLEN + EOCD64LOCLEN) #define BUFSIZE 8192 #define EFZIP64SIZE 28 #define EF_WINZIP_AES_SIZE 7 #define ZIP_CM_REPLACED_DEFAULT (-2) #define ZIP_CM_WINZIP_AES 99 /* Winzip AES encrypted */ #define WINZIP_AES_PASSWORD_VERIFY_LENGTH 2 #define WINZIP_AES_MAX_HEADER_LENGTH (16 + WINZIP_AES_PASSWORD_VERIFY_LENGTH) #define AES_BLOCK_SIZE 16 #define HMAC_LENGTH 10 #define SHA1_LENGTH 20 #define SALT_LENGTH(method) ((method) == ZIP_EM_AES_128 ? 8 : ((method) == ZIP_EM_AES_192 ? 12 : 16)) #define ZIP_CM_IS_DEFAULT(x) ((x) == ZIP_CM_DEFAULT || (x) == ZIP_CM_REPLACED_DEFAULT) #define ZIP_CM_ACTUAL(x) ((zip_uint16_t)(ZIP_CM_IS_DEFAULT(x) ? ZIP_CM_DEFLATE : (x))) #define ZIP_EF_UTF_8_COMMENT 0x6375 #define ZIP_EF_UTF_8_NAME 0x7075 #define ZIP_EF_WINZIP_AES 0x9901 #define ZIP_EF_ZIP64 0x0001 #define ZIP_EF_IS_INTERNAL(id) ((id) == ZIP_EF_UTF_8_COMMENT || (id) == ZIP_EF_UTF_8_NAME || (id) == ZIP_EF_WINZIP_AES || (id) == ZIP_EF_ZIP64) /* according to unzip-6.0's zipinfo.c, this corresponds to a regular file with rw permissions for everyone */ #define ZIP_EXT_ATTRIB_DEFAULT (0100666u << 16) /* according to unzip-6.0's zipinfo.c, this corresponds to a directory with rwx permissions for everyone */ #define ZIP_EXT_ATTRIB_DEFAULT_DIR (0040777u << 16) #define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b)) #define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b)) /* This section contains API that won't materialize like this. It's placed in the internal section, pending cleanup. */ /* flags for compression and encryption sources */ #define ZIP_CODEC_DECODE 0 /* decompress/decrypt (encode flag not set) */ #define ZIP_CODEC_ENCODE 1 /* compress/encrypt */ typedef zip_source_t *(*zip_encryption_implementation)(zip_t *, zip_source_t *, zip_uint16_t, int, const char *); zip_encryption_implementation _zip_get_encryption_implementation(zip_uint16_t method, int operation); // clang-format off enum zip_compression_status { ZIP_COMPRESSION_OK, ZIP_COMPRESSION_END, ZIP_COMPRESSION_ERROR, ZIP_COMPRESSION_NEED_DATA }; // clang-format on typedef enum zip_compression_status zip_compression_status_t; struct zip_compression_algorithm { /* called once to create new context */ void *(*allocate)(zip_uint16_t method, int compression_flags, zip_error_t *error); /* called once to free context */ void (*deallocate)(void *ctx); /* get compression specific general purpose bitflags */ int (*compression_flags)(void *ctx); /* start processing */ bool (*start)(void *ctx); /*
/*
 Derived from source code of TrueCrypt 7.1a, which is
 Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
 by the TrueCrypt License 3.0.

 Modifications and additions to the original source code (contained in this file)
 and all other portions of this file are Copyright (c) 2013-2017 IDRIX
 and are governed by the Apache License 2.0 the full text of which is
 contained in the file License.txt included in VeraCrypt binary and source
 code distribution packages.
*/

#include "Setup.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct
{
	// WARNING: file name is NOT null-terminated (use fileNameLength).
	wchar_t *fileName;
	int fileNameLength;
	uint32 crc;
	__int32 fileLength;
	unsigned char *fileContent;
} DECOMPRESSED_FILE;

extern DECOMPRESSED_FILE	Decompressed_Files [NBR_COMPRESSED_FILES];
extern int Decompressed_Files_Count;

void SelfExtractStartupInit (void);
BOOL SelfExtractInMemory (wchar_t *path, BOOL bSkipCountCheck);
void __cdecl ExtractAllFilesThread (void *hwndDlg);
BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir, BOOL bSkipX64);
BOOL VerifyPackageIntegrity (const wchar_t *path);
BOOL VerifySelfPackageIntegrity (void);
BOOL IsSelfExtractingPackage (void);
void FreeAllFileBuffers (void);
void DeobfuscateMagEndMarker (void);

extern wchar_t DestExtractPath [TC_MAX_PATH];

#ifdef __cplusplus
}
#endif
READING(src) ((src)->open_count > 0) #define ZIP_SOURCE_IS_OPEN_WRITING(src) ((src)->write_state == ZIP_SOURCE_WRITE_OPEN) #define ZIP_SOURCE_IS_LAYERED(src) ((src)->src != NULL) /* entry in zip archive directory */ struct zip_entry { zip_dirent_t *orig; zip_dirent_t *changes; zip_source_t *source; bool deleted; }; /* file or archive comment, or filename */ struct zip_string { zip_uint8_t *raw; /* raw string */ zip_uint16_t length; /* length of raw string */ enum zip_encoding_type encoding; /* autorecognized encoding */ zip_uint8_t *converted; /* autoconverted string */ zip_uint32_t converted_length; /* length of converted */ }; /* bounds checked access to memory buffer */ struct zip_buffer { bool ok; bool free_data; zip_uint8_t *data; zip_uint64_t size; zip_uint64_t offset; }; /* which files to write in which order */ struct zip_filelist { zip_uint64_t idx; /* TODO const char *name; */ }; typedef struct zip_filelist zip_filelist_t; struct _zip_winzip_aes; typedef struct _zip_winzip_aes zip_winzip_aes_t; extern const char *const _zip_err_str[]; extern const int _zip_nerr_str; extern const int _zip_err_type[]; #define ZIP_MAX(a, b) ((a) > (b) ? (a) : (b)) #define ZIP_MIN(a, b) ((a) < (b) ? (a) : (b)) #define ZIP_ENTRY_CHANGED(e, f) ((e)->changes && ((e)->changes->changed & (f))) #define ZIP_ENTRY_DATA_CHANGED(x) ((x)->source != NULL) #define ZIP_ENTRY_HAS_CHANGES(e) (ZIP_ENTRY_DATA_CHANGED(e) || (e)->deleted || ZIP_ENTRY_CHANGED((e), ZIP_DIRENT_ALL)) #define ZIP_IS_RDONLY(za) ((za)->ch_flags & ZIP_AFL_RDONLY) #ifdef HAVE_EXPLICIT_MEMSET #define _zip_crypto_clear(b, l) explicit_memset((b), 0, (l)) #else #ifdef HAVE_EXPLICIT_BZERO #define _zip_crypto_clear(b, l) explicit_bzero((b), (l)) #else #include #define _zip_crypto_clear(b, l) memset((b), 0, (l)) #endif #endif zip_int64_t _zip_add_entry(zip_t *); zip_uint8_t *_zip_buffer_data(zip_buffer_t *buffer); bool _zip_buffer_eof(zip_buffer_t *buffer); void _zip_buffer_free(zip_buffer_t *buffer); zip_uint8_t *_zip_buffer_get(zip_buffer_t *buffer, zip_uint64_t length); zip_uint16_t _zip_buffer_get_16(zip_buffer_t *buffer); zip_uint32_t _zip_buffer_get_32(zip_buffer_t *buffer); zip_uint64_t _zip_buffer_get_64(zip_buffer_t *buffer); zip_uint8_t _zip_buffer_get_8(zip_buffer_t *buffer); zip_uint64_t _zip_buffer_left(zip_buffer_t *buffer); zip_buffer_t *_zip_buffer_new(zip_uint8_t *data, zip_uint64_t size); zip_buffer_t *_zip_buffer_new_from_source(zip_source_t *src, zip_uint64_t size, zip_uint8_t *buf, zip_error_t *error); zip_uint64_t _zip_buffer_offset(zip_buffer_t *buffer); bool _zip_buffer_ok(zip_buffer_t *buffer); zip_uint8_t *_zip_buffer_peek(zip_buffer_t *buffer, zip_uint64_t length); int _zip_buffer_put(zip_buffer_t *buffer, const void *src, size_t length); int _zip_buffer_put_16(zip_buffer_t *buffer, zip_uint16_t i); int _zip_buffer_put_32(zip_buffer_t *buffer, zip_uint32_t i); int _zip_buffer_put_64(zip_buffer_t *buffer, zip_uint64_t i); int _zip_buffer_put_8(zip_buffer_t *buffer, zip_uint8_t i); zip_uint64_t _zip_buffer_read(zip_buffer_t *buffer, zip_uint8_t *data, zip_uint64_t length); int _zip_buffer_skip(zip_buffer_t *buffer, zip_uint64_t length); int _zip_buffer_set_offset(zip_buffer_t *buffer, zip_uint64_t offset); zip_uint64_t _zip_buffer_size(zip_buffer_t *buffer); int _zip_cdir_compute_crc(zip_t *, uLong *); void _zip_cdir_free(zip_cdir_t *); bool _zip_cdir_grow(zip_cdir_t *cd, zip_uint64_t additional_entries, zip_error_t *error); zip_cdir_t *_zip_cdir_new(zip_uint64_t, zip_error_t *); zip_int64_t _zip_cdir_write(zip_t *za, const zip_filelist_t *filelist, zip_uint64_t survivors); void _zip_deregister_source(zip_t *za, zip_source_t *src); zip_dirent_t *_zip_dirent_clone(const zip_dirent_t *); void _zip_dirent_free(zip_dirent_t *); void _zip_dirent_finalize(zip_dirent_t *); void _zip_dirent_init(zip_dirent_t *); bool _zip_dirent_needs_zip64(const zip_dirent_t *, zip_flags_t); zip_dirent_t *_zip_dirent_new(void); zip_int64_t _zip_dirent_read(zip_dirent_t *zde, zip_source_t *src, zip_buffer_t *buffer, bool local, zip_error_t *error); void _zip_dirent_set_version_needed(zip_dirent_t *de, bool force_zip64); zip_int32_t _zip_dirent_size(zip_source_t *src, zip_uint16_t, zip_error_t *); int _zip_dirent_write(zip_t *za, zip_dirent_t *dirent, zip_flags_t flags); zip_extra_field_t *_zip_ef_clone(const zip_extra_field_t *, zip_error_t *); zip_extra_field_t *_zip_ef_delete_by_id(zip_extra_field_t *, zip_uint16_t, zip_uint16_t, zip_flags_t); void _zip_ef_free(zip_extra_field_t *); const zip_uint8_t *_zip_ef_get_by_id(const zip_extra_field_t *, zip_uint16_t *, zip_uint16_t, zip_uint16_t, zip_flags_t, zip_error_t *); zip_extra_field_t *_zip_ef_merge(zip_extra_field_t *, zip_extra_field_t *); zip_extra_field_t *_zip_ef_new(zip_uint16_t, zip_uint16_t, const zip_uint8_t *, zip_flags_t); bool _zip_ef_parse(const zip_uint8_t *, zip_uint16_t, zip_flags_t, zip_extra_field_t **, zip_error_t *); zip_extra_field_t *_zip_ef_remove_internal(zip_extra_field_t *); zip_uint16_t _zip_ef_size(const zip_extra_field_t *, zip_flags_t); int _zip_ef_write(zip_t *za, const zip_extra_field_t *ef, zip_flags_t flags); void _zip_entry_finalize(zip_entry_t *); void _zip_entry_init(zip_entry_t *); void _zip_error_clear(zip_error_t *); void _zip_error_get(const zip_error_t *, int *, int *); void _zip_error_copy(zip_error_t *dst, const zip_error_t *src); void _zip_error_set_from_source(zip_error_t *, zip_source_t *); const zip_uint8_t *_zip_extract_extra_field_by_id(zip_error_t *, zip_uint16_t, int, const zip_uint8_t *, zip_uint16_t, zip_uint16_t *); int _zip_file_extra_field_prepare_for_change(zip_t *, zip_uint64_t); int _zip_file_fillbuf(void *, size_t, zip_file_t *); zip_uint64_t _zip_file_get_end(const zip_t *za, zip_uint64_t index, zip_error_t *error); zip_uint64_t _zip_file_get_offset(const zip_t *, zip_uint64_t, zip_error_t *); int _zip_filerange_crc(zip_source_t *src, zip_uint64_t offset, zip_uint64_t length, uLong *crcp, zip_error_t *error); zip_dirent_t *_zip_get_dirent(zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *); enum zip_encoding_type _zip_guess_encoding(zip_string_t *, enum zip_encoding_type); zip_uint8_t *_zip_cp437_to_utf8(const zip_uint8_t *const, zip_uint32_t, zip_uint32_t *, zip_error_t *); bool _zip_hash_add(zip_hash_t *hash, const zip_uint8_t *name, zip_uint64_t index, zip_flags_t flags, zip_error_t *error); bool _zip_hash_delete(zip_hash_t *hash, const zip_uint8_t *key, zip_error_t *error); void _zip_hash_free(zip_hash_t *hash); zip_int64_t _zip_hash_lookup(zip_hash_t *hash, const zip_uint8_t *name, zip_flags_t flags, zip_error_t *error); zip_hash_t *_zip_hash_new(zip_error_t *error); bool _zip_hash_reserve_capacity(zip_hash_t *hash, zip_uint64_t capacity, zip_error_t *error); bool _zip_hash_revert(zip_hash_t *hash, zip_error_t *error); zip_t *_zip_open(zip_source_t *, unsigned int, zip_error_t *); void _zip_progress_end(zip_progress_t *progress); void _zip_progress_free(zip_progress_t *progress); zip_progress_t *_zip_progress_new(zip_t *za, double precision, zip_progress_callback callback, void (*ud_free)(void *), void *ud); void _zip_progress_start(zip_progress_t *progress); void _zip_progress_subrange(zip_progress_t *progress, double start, double end); void _zip_progress_update(zip_progress_t *progress, double value); ZIP_EXTERN bool zip_random(zip_uint8_t *buffer, zip_uint16_t length); int _zip_read(zip_source_t *src, zip_uint8_t *data, zip_uint64_t length, zip_error_t *error); int _zip_read_at_offset(zip_source_t *src, zip_uint64_t offset, unsigned char *b, size_t length, zip_error_t *error); zip_uint8_t *_zip_read_data(zip_buffer_t *buffer, zip_source_t *src, size_t length, bool nulp, zip_error_t *error); int _zip_read_local_ef(zip_t *, zip_uint64_t); zip_string_t *_zip_read_string(zip_buffer_t *buffer, zip_source_t *src, zip_uint16_t lenght, bool nulp, zip_error_t *error); int _zip_register_source(zip_t *za, zip_source_t *src); void _zip_set_open_error(int *zep, const zip_error_t *err, int ze); zip_int64_t _zip_source_call(zip_source_t *src, void *data, zip_uint64_t length, zip_source_cmd_t command); bool _zip_source_eof(zip_source_t *); zip_source_t *_zip_source_file_or_p(const char *, FILE *, zip_uint64_t, zip_int64_t, const zip_stat_t *, zip_error_t *error); zip_int8_t zip_source_get_compression_flags(zip_source_t *); bool _zip_source_had_error(zip_source_t *); void _zip_source_invalidate(zip_source_t *src); zip_source_t *_zip_source_new(zip_error_t *error); int _zip_source_set_source_archive(zip_source_t *, zip_t *); zip_source_t *_zip_source_window_new(zip_source_t *src, zip_uint64_t start, zip_uint64_t length, zip_stat_t *st, zip_int8_t compression_flags, zip_t *source_archive, zip_uint64_t source_index, zip_error_t *error); zip_source_t *_zip_source_zip_new(zip_t *, zip_t *, zip_uint64_t, zip_flags_t, zip_uint64_t, zip_uint64_t, const char *); int _zip_stat_merge(zip_stat_t *dst, const zip_stat_t *src, zip_error_t *error); int _zip_string_equal(const zip_string_t *, const zip_string_t *); void _zip_string_free(zip_string_t *); zip_uint32_t _zip_string_crc32(const zip_string_t *); const zip_uint8_t *_zip_string_get(zip_string_t *, zip_uint32_t *, zip_flags_t, zip_error_t *); zip_uint16_t _zip_string_length(const zip_string_t *); zip_string_t *_zip_string_new(const zip_uint8_t *, zip_uint16_t, zip_flags_t, zip_error_t *); int _zip_string_write(zip_t *za, const zip_string_t *string); bool _zip_winzip_aes_decrypt(zip_winzip_aes_t *ctx, zip_uint8_t *data, zip_uint64_t length); bool _zip_winzip_aes_encrypt(zip_winzip_aes_t *ctx, zip_uint8_t *data, zip_uint64_t length); bool _zip_winzip_aes_finish(zip_winzip_aes_t *ctx, zip_uint8_t *hmac); void _zip_winzip_aes_free(zip_winzip_aes_t *ctx); zip_winzip_aes_t *_zip_winzip_aes_new(const zip_uint8_t *password, zip_uint64_t password_length, const zip_uint8_t *salt, zip_uint16_t key_size, zip_uint8_t *password_verify, zip_error_t *error); int _zip_changed(const zip_t *, zip_uint64_t *); const char *_zip_get_name(zip_t *, zip_uint64_t, zip_flags_t, zip_error_t *); int _zip_local_header_read(zip_t *, int); void *_zip_memdup(const void *, size_t, zip_error_t *); zip_int64_t _zip_name_locate(zip_t *, const char *, zip_flags_t, zip_error_t *); zip_t *_zip_new(zip_error_t *); zip_int64_t _zip_file_replace(zip_t *, zip_uint64_t, const char *, zip_source_t *, zip_flags_t); int _zip_set_name(zip_t *, zip_uint64_t, const char *, zip_flags_t); void _zip_u2d_time(time_t, zip_uint16_t *, zip_uint16_t *); int _zip_unchange(zip_t *, zip_uint64_t, int); void _zip_unchange_data(zip_entry_t *); int _zip_write(zip_t *za, const void *data, zip_uint64_t length); #endif /* zipint.h */