Compare commits
14 Commits
IncorrectH
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0c410516e | ||
|
|
0f638a9e94 | ||
|
|
334c7bb78d | ||
|
|
bfc6fb8d34 | ||
|
|
b6ba338a4c | ||
|
|
e46a23f76d | ||
|
|
150f9a276e | ||
|
|
82af68a7d5 | ||
|
|
924b9240d3 | ||
|
|
6b302a33b1 | ||
|
|
6128b6faf3 | ||
|
|
8e3a03d78b | ||
|
|
5b9e60e4ea | ||
|
|
91e8bff0a7 |
@@ -1,5 +1,5 @@
|
||||
PODS:
|
||||
- SSZipArchive (2.1.0)
|
||||
- SSZipArchive (2.1.1)
|
||||
|
||||
DEPENDENCIES:
|
||||
- SSZipArchive (from `..`)
|
||||
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
|
||||
:path: ..
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
SSZipArchive: 1e8e53dcb11bca3ded4738958dc49fc467320a14
|
||||
SSZipArchive: 14401ade5f8e82aba1ff03e9f88e9de60937ae60
|
||||
|
||||
PODFILE CHECKSUM: 5e250843c66c607960128ebfe02ab7d6569102be
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SSZipArchive'
|
||||
s.version = '2.1.0'
|
||||
s.version = '2.1.1'
|
||||
s.summary = 'Utility class for zipping and unzipping files on iOS, tvOS, watchOS, and Mac.'
|
||||
s.description = 'SSZipArchive is a simple utility class for zipping and unzipping files on iOS, tvOS, watchOS, and Mac.'
|
||||
s.homepage = 'https://github.com/ZipArchive/ZipArchive'
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE.txt' }
|
||||
s.authors = { 'Sam Soffes' => 'sam@soff.es', 'Joshua Hudson' => nil, 'Antoine Cœur' => nil }
|
||||
s.source = { :git => 'https://github.com/ZipArchive/ZipArchive.git', :tag => "v#{s.version}" }
|
||||
s.ios.deployment_target = '4.0'
|
||||
s.ios.deployment_target = '11.0'
|
||||
s.tvos.deployment_target = '9.0'
|
||||
s.osx.deployment_target = '10.8'
|
||||
s.watchos.deployment_target = '2.0'
|
||||
|
||||
@@ -91,6 +91,7 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
|
||||
|
||||
// with optional password, default encryption is AES
|
||||
// don't use AES if you need compatibility with native macOS unzip and Archive Utility
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths diskSize:(int)diskSize;
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths withPassword:(nullable NSString *)password;
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password;
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory withPassword:(nullable NSString *)password;
|
||||
@@ -106,10 +107,19 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
|
||||
password:(nullable NSString *)password
|
||||
AES:(BOOL)aes
|
||||
progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler;
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path
|
||||
withContentsOfDirectory:(NSString *)directoryPath
|
||||
keepParentDirectory:(BOOL)keepParentDirectory
|
||||
compressionLevel:(int)compressionLevel
|
||||
password:(nullable NSString *)password
|
||||
AES:(BOOL)aes
|
||||
diskSize:(int)diskSize
|
||||
progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
- (instancetype)initWithPath:(NSString *)path NS_DESIGNATED_INITIALIZER;
|
||||
- (BOOL)open;
|
||||
- (BOOL)openWithSplitSize:(int)disk_size;
|
||||
|
||||
/// write empty folder
|
||||
- (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password;
|
||||
|
||||
@@ -364,6 +364,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
|
||||
// ignoring resource forks: https://superuser.com/questions/104500/what-is-macosx-folder
|
||||
unzCloseCurrentFile(zip);
|
||||
ret = unzGoToNextFile(zip);
|
||||
free(filename);
|
||||
continue;
|
||||
}
|
||||
if (!strPath.length) {
|
||||
@@ -666,6 +667,19 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
|
||||
return success;
|
||||
}
|
||||
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths diskSize:(int)diskSize
|
||||
{
|
||||
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
|
||||
BOOL success = [zipArchive openWithSplitSize:diskSize];
|
||||
if (success) {
|
||||
for (NSString *filePath in paths) {
|
||||
success &= [zipArchive writeFile:filePath withPassword:nil];
|
||||
}
|
||||
success &= [zipArchive close];
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath withPassword:(nullable NSString *)password {
|
||||
return [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:NO withPassword:password];
|
||||
}
|
||||
@@ -685,7 +699,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
|
||||
keepParentDirectory:(BOOL)keepParentDirectory
|
||||
withPassword:(nullable NSString *)password
|
||||
andProgressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler {
|
||||
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:keepParentDirectory compressionLevel:Z_DEFAULT_COMPRESSION password:password AES:YES progressHandler:progressHandler];
|
||||
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:keepParentDirectory compressionLevel:Z_DEFAULT_COMPRESSION password:password AES:YES diskSize:0 progressHandler:progressHandler];
|
||||
}
|
||||
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path
|
||||
@@ -695,9 +709,20 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
|
||||
password:(nullable NSString *)password
|
||||
AES:(BOOL)aes
|
||||
progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler {
|
||||
return [self createZipFileAtPath:path withContentsOfDirectory:directoryPath keepParentDirectory:keepParentDirectory compressionLevel:compressionLevel password:password AES:aes diskSize:0 progressHandler:progressHandler];
|
||||
}
|
||||
|
||||
+ (BOOL)createZipFileAtPath:(NSString *)path
|
||||
withContentsOfDirectory:(NSString *)directoryPath
|
||||
keepParentDirectory:(BOOL)keepParentDirectory
|
||||
compressionLevel:(int)compressionLevel
|
||||
password:(nullable NSString *)password
|
||||
AES:(BOOL)aes
|
||||
diskSize:(int)diskSize
|
||||
progressHandler:(void(^ _Nullable)(NSUInteger entryNumber, NSUInteger total))progressHandler {
|
||||
|
||||
SSZipArchive *zipArchive = [[SSZipArchive alloc] initWithPath:path];
|
||||
BOOL success = [zipArchive open];
|
||||
BOOL success = [zipArchive openWithSplitSize:diskSize];
|
||||
if (success) {
|
||||
// use a local fileManager (queue/thread compatibility)
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
@@ -747,11 +772,18 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)open
|
||||
{
|
||||
return [self openWithSplitSize:0];
|
||||
}
|
||||
|
||||
- (BOOL)openWithSplitSize:(int)disk_size
|
||||
{
|
||||
NSAssert((_zip == NULL), @"Attempting to open an archive which is already open");
|
||||
_zip = zipOpen(_path.fileSystemRepresentation, APPEND_STATUS_CREATE);
|
||||
if (disk_size < 1024) //avoid creating split of size < 1 KB
|
||||
_zip = zipOpen(_path.fileSystemRepresentation, APPEND_STATUS_CREATE);
|
||||
else
|
||||
_zip = zipOpen3(_path.fileSystemRepresentation, APPEND_STATUS_CREATE, disk_size, NULL, NULL);
|
||||
return (NULL != _zip);
|
||||
}
|
||||
|
||||
@@ -857,10 +889,12 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
|
||||
|
||||
+ (NSString *)_filenameStringWithCString:(const char *)filename size:(uint16_t)size_filename
|
||||
{
|
||||
// attempting unicode encoding
|
||||
NSString * strPath = @(filename);
|
||||
if (strPath) {
|
||||
return strPath;
|
||||
}
|
||||
|
||||
// if filename is non-unicode, detect and transform Encoding
|
||||
NSData *data = [NSData dataWithBytes:(const void *)filename length:sizeof(unsigned char) * size_filename];
|
||||
#ifdef __MAC_10_13
|
||||
@@ -886,11 +920,13 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!strPath) {
|
||||
// if filename encoding is non-detected, we default to something based on data
|
||||
// _hexString is more readable than _base64RFC4648 for debugging unknown encodings
|
||||
strPath = [data _hexString];
|
||||
if (strPath) {
|
||||
return strPath;
|
||||
}
|
||||
|
||||
// if filename encoding is non-detected, we default to something based on data
|
||||
// _hexString is more readable than _base64RFC4648 for debugging unknown encodings
|
||||
strPath = [data _hexString];
|
||||
return strPath;
|
||||
}
|
||||
|
||||
@@ -1042,6 +1078,11 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo)
|
||||
NSUInteger length = self.length;
|
||||
const unsigned char *bytes = self.bytes;
|
||||
char *chars = malloc(length * 2);
|
||||
if (chars == NULL) {
|
||||
// we directly raise an exception instead of using NSAssert to make sure assertion is not disabled as this is irrecoverable
|
||||
[NSException raise:@"NSInternalInconsistencyException" format:@"failed malloc" arguments:nil];
|
||||
return nil;
|
||||
}
|
||||
char *s = chars;
|
||||
NSUInteger i = length;
|
||||
while (i--) {
|
||||
|
||||
@@ -46,10 +46,6 @@
|
||||
|
||||
#define CRC32(c, b) ((*(pcrc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
||||
|
||||
#ifndef ZCR_SEED2
|
||||
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint8_t decrypt_byte(uint32_t *pkeys)
|
||||
@@ -90,11 +86,10 @@ void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab)
|
||||
|
||||
int cryptrand(unsigned char *buf, unsigned int len)
|
||||
{
|
||||
static unsigned calls = 0;
|
||||
int rlen = 0;
|
||||
#ifdef _WIN32
|
||||
HCRYPTPROV provider;
|
||||
unsigned __int64 pentium_tsc[1];
|
||||
int rlen = 0;
|
||||
int result = 0;
|
||||
|
||||
|
||||
@@ -112,24 +107,12 @@ int cryptrand(unsigned char *buf, unsigned int len)
|
||||
QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc);
|
||||
buf[rlen] = ((unsigned char*)pentium_tsc)[rlen % 8];
|
||||
}
|
||||
#else
|
||||
int frand = open("/dev/urandom", O_RDONLY);
|
||||
if (frand != -1)
|
||||
{
|
||||
rlen = (int)read(frand, buf, len);
|
||||
close(frand);
|
||||
}
|
||||
#endif
|
||||
if (rlen < (int)len)
|
||||
{
|
||||
/* Ensure different random header each time */
|
||||
if (++calls == 1)
|
||||
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
|
||||
|
||||
while (rlen < (int)len)
|
||||
buf[rlen++] = (rand() >> 7) & 0xff;
|
||||
}
|
||||
return rlen;
|
||||
#else
|
||||
arc4random_buf(buf, len);
|
||||
return len;
|
||||
#endif
|
||||
}
|
||||
|
||||
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
|
||||
|
||||
@@ -350,6 +350,7 @@ static unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_f
|
||||
uint64_t value64 = 0;
|
||||
voidpf filestream = NULL;
|
||||
int err = UNZ_OK;
|
||||
int err64 = UNZ_OK;
|
||||
|
||||
us.filestream = NULL;
|
||||
us.filestream_with_CD = NULL;
|
||||
@@ -412,7 +413,7 @@ static unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_f
|
||||
if (err == UNZ_OK)
|
||||
{
|
||||
/* Search for Zip64 end of central directory header */
|
||||
int err64 = unzSearchCentralDir64(&us.z_filefunc, ¢ral_pos64, us.filestream, central_pos);
|
||||
err64 = unzSearchCentralDir64(&us.z_filefunc, ¢ral_pos64, us.filestream, central_pos);
|
||||
if (err64 == UNZ_OK)
|
||||
{
|
||||
central_pos = central_pos64;
|
||||
@@ -454,7 +455,7 @@ static unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_f
|
||||
if (unzReadUInt64(&us.z_filefunc, us.filestream, &us.offset_central_dir) != UNZ_OK)
|
||||
err = UNZ_ERRNO;
|
||||
}
|
||||
else if ((us.gi.number_entry == UINT16_MAX) || (us.size_central_dir == UINT16_MAX) || (us.offset_central_dir == UINT32_MAX))
|
||||
else if ((us.size_central_dir == UINT16_MAX) || (us.offset_central_dir == UINT32_MAX))
|
||||
err = UNZ_BADZIPFILE;
|
||||
}
|
||||
}
|
||||
@@ -491,6 +492,10 @@ static unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_f
|
||||
if (s != NULL)
|
||||
{
|
||||
*s = us;
|
||||
if (err64 != UNZ_OK)
|
||||
// workaround incorrect count #184
|
||||
s->gi.number_entry = unzCountEntries(s);
|
||||
|
||||
unzGoToFirstFile((unzFile)s);
|
||||
}
|
||||
return (unzFile)s;
|
||||
@@ -1026,6 +1031,29 @@ static int unzCheckCurrentFileCoherencyHeader(unz64_internal *s, uint32_t *psize
|
||||
return err;
|
||||
}
|
||||
|
||||
extern uint64_t ZEXPORT unzCountEntries(const unzFile file)
|
||||
{
|
||||
if (file == NULL)
|
||||
return 0;
|
||||
|
||||
unz64_internal s = *(unz64_internal*)file;
|
||||
|
||||
s.pos_in_central_dir = s.offset_central_dir;
|
||||
s.num_file = 0;
|
||||
while (UNZ_OK == unzGetCurrentFileInfoInternal(&s,
|
||||
&s.cur_file_info,
|
||||
&s.cur_file_info_internal,
|
||||
NULL, 0, NULL, 0, NULL, 0))
|
||||
{
|
||||
s.pos_in_central_dir += SIZECENTRALDIRITEM
|
||||
+ s.cur_file_info.size_filename
|
||||
+ s.cur_file_info.size_file_extra
|
||||
+ s.cur_file_info.size_file_comment;
|
||||
s.num_file += 1;
|
||||
}
|
||||
return s.num_file;
|
||||
}
|
||||
|
||||
/*
|
||||
Open for reading data the current file in the zipfile.
|
||||
If there is no error and the file is opened, the return value is UNZ_OK.
|
||||
|
||||
@@ -100,6 +100,8 @@ extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t com
|
||||
uSizeBuf is the size of the szComment buffer.
|
||||
return the number of byte copied or an error code <0 */
|
||||
|
||||
extern uint64_t ZEXPORT unzCountEntries(const unzFile file);
|
||||
|
||||
/***************************************************************************/
|
||||
/* Reading the content of the current zipfile, you can open it, read data from it, and close it
|
||||
(you can close it before reading all the file) */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
PODS:
|
||||
- SSZipArchive (2.1.0)
|
||||
- SSZipArchive (2.1.1)
|
||||
|
||||
DEPENDENCIES:
|
||||
- SSZipArchive (from `..`)
|
||||
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
|
||||
:path: ..
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
SSZipArchive: 1e8e53dcb11bca3ded4738958dc49fc467320a14
|
||||
SSZipArchive: 14401ade5f8e82aba1ff03e9f88e9de60937ae60
|
||||
|
||||
PODFILE CHECKSUM: 0dc500eb72745751ccba7677de4da5534fcef36d
|
||||
|
||||
|
||||
Reference in New Issue
Block a user