2 Commits

Author SHA1 Message Date
Antoine Cœur
c15c6db4f5 converting isFilePasswordProtectedAtPath 2017-10-07 21:17:44 +08:00
Antoine Cœur
913c3127e0 new minizip files 2017-10-07 00:50:57 +08:00
51 changed files with 5872 additions and 6725 deletions

View File

@@ -15,22 +15,6 @@ matrix:
env: SDK="macosx"
DEVICE="OS X 10.11"
- osx_image: xcode9
env: SDK="appletvsimulator"
DEVICE="Apple TV 4K (11.0)" # oldest/newest for tvOS 11.x
- osx_image: xcode8.3
env: SDK="appletvsimulator"
DEVICE="Apple TV 1080p (10.2)" # latest for tvOS 10.x
- osx_image: xcode8.3
env: SDK="appletvsimulator"
DEVICE="Apple TV 1080p (9.2)" # latest for tvOS 9.x
- osx_image: xcode7.3
env: SDK="appletvsimulator"
DEVICE="Apple TV 1080p (9.0)" # oldest for tvOS 9.x
- osx_image: xcode9
env: SDK="iphonesimulator"
DEVICE="iPhone X (11.0)" # oldest/newest for iOS 11.x
@@ -62,14 +46,9 @@ matrix:
before_install:
- if [ ${SDK} = "macosx" ]; then
SCHEME="ObjectiveCExample_macOS";
elif [ ${SDK} = "appletvsimulator" ]; then
SCHEME="ObjectiveCExample_tvOS";
else
SCHEME="ObjectiveCExample_iOS";
fi
- if [ ${SDK} = "macosx" ]; then
DESTINATION="platform=macosx";
else
SCHEME="ObjectiveCExample_iOS";
DESTINATION_UDID=$(instruments -s devices | grep "$DEVICE \[" | sed -E 's/.*\[([0-9A-F-]+)\].*/\1/g');
`Prelaunching simulator to avoid timeout https://github.com/travis-ci/travis-ci/issues/6422`
open -a Simulator --args -CurrentDeviceUDID $DESTINATION_UDID;

View File

@@ -7,9 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
3754B1331F88961C00A58AA0 /* Empty.zip in Resources */ = {isa = PBXBuildFile; fileRef = 3754B1311F88961800A58AA0 /* Empty.zip */; };
3754B1341F88961D00A58AA0 /* Empty.zip in Resources */ = {isa = PBXBuildFile; fileRef = 3754B1311F88961800A58AA0 /* Empty.zip */; };
3754B1351F88961E00A58AA0 /* Empty.zip in Resources */ = {isa = PBXBuildFile; fileRef = 3754B1311F88961800A58AA0 /* Empty.zip */; };
3773ADB61F7F453E009A4B2D /* CollectingDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DFE1A131BDAA0A800709011 /* CollectingDelegate.m */; };
3773ADB71F7F4541009A4B2D /* SSZipArchiveTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DFE1A071BDA9FF300709011 /* SSZipArchiveTests.m */; };
3773ADB81F7F4D13009A4B2D /* hello.zip in Resources */ = {isa = PBXBuildFile; fileRef = 8DFE1A161BDAA10100709011 /* hello.zip */; };
@@ -86,7 +83,6 @@
/* Begin PBXFileReference section */
04CB37570807602F7E5C66D9 /* Pods-core-ObjectiveCExampleTests_macOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-core-ObjectiveCExampleTests_macOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-core-ObjectiveCExampleTests_macOS/Pods-core-ObjectiveCExampleTests_macOS.release.xcconfig"; sourceTree = "<group>"; };
254DE0B206EE66F57BBE7EEE /* Pods-core-ObjectiveCExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-core-ObjectiveCExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-core-ObjectiveCExample/Pods-core-ObjectiveCExample.release.xcconfig"; sourceTree = "<group>"; };
3754B1311F88961800A58AA0 /* Empty.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = Empty.zip; sourceTree = "<group>"; };
3773ADAE1F7F44D8009A4B2D /* ObjectiveCExampleTests_macOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ObjectiveCExampleTests_macOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3793E6D71F7F5F93000B1A19 /* ObjectiveCExampleTests_tvOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ObjectiveCExampleTests_tvOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
37FF0CB11F8533E0006E4361 /* CancelDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CancelDelegate.h; sourceTree = "<group>"; };
@@ -255,7 +251,6 @@
8DFE1A151BDAA10100709011 /* Fixtures */ = {
isa = PBXGroup;
children = (
3754B1311F88961800A58AA0 /* Empty.zip */,
8DFE1A161BDAA10100709011 /* hello.zip */,
8DFE1A171BDAA10100709011 /* IncorrectHeaders.zip */,
8DFE1A181BDAA10100709011 /* PermissionsTestApp.app */,
@@ -430,7 +425,6 @@
3773ADC31F7F4D1C009A4B2D /* 3.m4a in Resources */,
3773ADC21F7F4D1C009A4B2D /* 2.m4a in Resources */,
3773ADC41F7F4D1C009A4B2D /* 4.m4a in Resources */,
3754B1341F88961D00A58AA0 /* Empty.zip in Resources */,
3773ADC01F7F4D1C009A4B2D /* 0.m4a in Resources */,
3773ADC51F7F4D1C009A4B2D /* 5.m4a in Resources */,
3773ADB91F7F4D13009A4B2D /* IncorrectHeaders.zip in Resources */,
@@ -454,7 +448,6 @@
3793E6E71F7F6052000B1A19 /* 6.m4a in Resources */,
3793E6E91F7F6059000B1A19 /* hello.zip in Resources */,
3793E6F01F7F605C000B1A19 /* PermissionsTestApp.app in Resources */,
3754B1351F88961E00A58AA0 /* Empty.zip in Resources */,
3793E6ED1F7F6059000B1A19 /* TestArchive.zip in Resources */,
3793E6E61F7F6052000B1A19 /* 5.m4a in Resources */,
3793E6E41F7F6052000B1A19 /* 3.m4a in Resources */,
@@ -489,7 +482,6 @@
8DFE1A321BDAA10100709011 /* 3.m4a in Resources */,
8DFE1A311BDAA10100709011 /* 2.m4a in Resources */,
8DFE1A331BDAA10100709011 /* 4.m4a in Resources */,
3754B1331F88961C00A58AA0 /* Empty.zip in Resources */,
8DFE1A2F1BDAA10100709011 /* 0.m4a in Resources */,
8DFE1A341BDAA10100709011 /* 5.m4a in Resources */,
8DFE1A2D1BDAA10100709011 /* TestPasswordArchive.zip in Resources */,
@@ -843,6 +835,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 11.1;
};
name = Debug;
};
@@ -864,6 +857,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 11.1;
};
name = Release;
};
@@ -920,7 +914,6 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
};
@@ -969,7 +962,6 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 9.0;
VALIDATE_PRODUCT = YES;
};
name = Release;

View File

@@ -26,123 +26,115 @@
#pragma mark - Life Cycle
- (void)viewDidLoad {
[super viewDidLoad];
[super viewDidLoad];
_file1.text = @"";
_file2.text = @"";
_file3.text = @"";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - IBAction
- (IBAction)zipPressed:(id)sender {
NSString *sampleDataPath = [[NSBundle mainBundle].bundleURL
URLByAppendingPathComponent:@"Sample Data"
isDirectory:YES].path;
_zipPath = [self tempZipPath];
NSString *password = _passwordField.text;
BOOL success = [SSZipArchive createZipFileAtPath:_zipPath
withContentsOfDirectory:sampleDataPath
keepParentDirectory:NO
compressionLevel:-1
password:password.length > 0 ? password : nil
AES:YES
progressHandler:nil];
if (success) {
NSLog(@"Success zip");
_unzipButton.enabled = YES;
_zipButton.enabled = NO;
} else {
NSLog(@"No success zip");
}
_resetButton.enabled = YES;
NSString *sampleDataPath = [[NSBundle mainBundle].bundleURL
URLByAppendingPathComponent:@"Sample Data"
isDirectory:YES].path;
_zipPath = [self tempZipPath];
NSString *password = _passwordField.text;
BOOL success = [SSZipArchive createZipFileAtPath:_zipPath
withContentsOfDirectory:sampleDataPath
withPassword:password.length > 0 ? password : nil];
if (success) {
_unzipButton.enabled = YES;
_zipButton.enabled = NO;
} else {
NSLog(@"No success");
}
_resetButton.enabled = YES;
}
- (IBAction)unzipPressed:(id)sender {
if (!_zipPath) {
return;
if (!_zipPath) {
return;
}
NSString *unzipPath = [self tempUnzipPath];
if (!unzipPath) {
return;
}
NSString *password = _passwordField.text;
BOOL success = [SSZipArchive unzipFileAtPath:_zipPath
toDestination:unzipPath
overwrite:YES
password:password.length > 0 ? password : nil
error:nil];
if (!success) {
NSLog(@"No success");
return;
}
NSError *error = nil;
NSMutableArray<NSString *> *items = [[[NSFileManager defaultManager]
contentsOfDirectoryAtPath:unzipPath
error:&error] mutableCopy];
if (error) {
return;
}
[items enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
switch (idx) {
case 0: {
self.file1.text = obj;
break;
}
case 1: {
self.file2.text = obj;
break;
}
case 2: {
self.file3.text = obj;
break;
}
default: {
NSLog(@"Went beyond index of assumed files");
break;
}
}
NSString *unzipPath = [self tempUnzipPath];
if (!unzipPath) {
return;
}
NSString *password = _passwordField.text;
BOOL success = [SSZipArchive unzipFileAtPath:_zipPath
toDestination:unzipPath
preserveAttributes:YES
overwrite:YES
nestedZipLevel:0
password:password.length > 0 ? password : nil
error:nil
delegate:nil
progressHandler:nil
completionHandler:nil];
if (success) {
NSLog(@"Success unzip");
} else {
NSLog(@"No success unzip");
return;
}
NSError *error = nil;
NSMutableArray<NSString *> *items = [[[NSFileManager defaultManager]
contentsOfDirectoryAtPath:unzipPath
error:&error] mutableCopy];
if (error) {
return;
}
[items enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
switch (idx) {
case 0: {
self.file1.text = obj;
break;
}
case 1: {
self.file2.text = obj;
break;
}
case 2: {
self.file3.text = obj;
break;
}
default: {
NSLog(@"Went beyond index of assumed files");
break;
}
}
}];
_unzipButton.enabled = NO;
}];
_unzipButton.enabled = NO;
}
- (IBAction)resetPressed:(id)sender {
_file1.text = @"";
_file2.text = @"";
_file3.text = @"";
_zipButton.enabled = YES;
_unzipButton.enabled = NO;
_resetButton.enabled = NO;
_file1.text = @"";
_file2.text = @"";
_file3.text = @"";
_zipButton.enabled = YES;
_unzipButton.enabled = NO;
_resetButton.enabled = NO;
}
#pragma mark - Private
- (NSString *)tempZipPath {
NSString *path = [NSString stringWithFormat:@"%@/\%@.zip",
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
[NSUUID UUID].UUIDString];
return path;
NSString *path = [NSString stringWithFormat:@"%@/\%@.zip",
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
[NSUUID UUID].UUIDString];
return path;
}
- (NSString *)tempUnzipPath {
NSString *path = [NSString stringWithFormat:@"%@/\%@",
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
[NSUUID UUID].UUIDString];
NSURL *url = [NSURL fileURLWithPath:path];
NSError *error = nil;
[[NSFileManager defaultManager] createDirectoryAtURL:url
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
return nil;
}
return url.path;
NSString *path = [NSString stringWithFormat:@"%@/\%@",
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
[NSUUID UUID].UUIDString];
NSURL *url = [NSURL fileURLWithPath:path];
NSError *error = nil;
[[NSFileManager defaultManager] createDirectoryAtURL:url
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
return nil;
}
return url.path;
}
@end

View File

@@ -233,24 +233,25 @@
testPath = [outputPath stringByAppendingPathComponent:@"LICENSE"];
XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"LICENSE unzipped");
}
//Temp Disabled test, fix is not yet in the AES version of the unzip lib
- (void)testUnzippingTruncatedFileFix {
NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"IncorrectHeaders" ofType:@"zip"];
NSString *outputPath = [self _cachesPath:@"IncorrectHeaders"];
id<SSZipArchiveDelegate> delegate = [ProgressDelegate new];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate];
XCTAssertTrue(success);
NSString *intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5";
NSString *filePath = [outputPath stringByAppendingPathComponent:@"IncorrectHeaders/Readme.txt"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSString *actualReadmeTxtMD5 = [self _calculateMD5Digest:data];
XCTAssertTrue([actualReadmeTxtMD5 isEqualToString:intendedReadmeTxtMD5], @"Readme.txt MD5 digest should match original.");
}
//- (void)testUnzippingTruncatedFileFix {
// NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"IncorrectHeaders" ofType:@"zip"];
// NSString *outputPath = [self _cachesPath:@"IncorrectHeaders"];
//
// id<SSZipArchiveDelegate> delegate = [ProgressDelegate new];
// BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate];
// XCTAssertTrue(success);
//
// NSString *intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5";
//
// NSString *filePath = [outputPath stringByAppendingPathComponent:@"IncorrectHeaders/Readme.txt"];
// NSData *data = [NSData dataWithContentsOfFile:filePath];
//
// NSString *actualReadmeTxtMD5 = [self _calculateMD5Digest:data];
// XCTAssertTrue([actualReadmeTxtMD5 isEqualToString:intendedReadmeTxtMD5], @"Readme.txt MD5 digest should match original.");
//}
- (void)testUnzippingWithSymlinkedFileInside {
@@ -312,14 +313,6 @@
XCTAssertTrue(unicodeFolderWasExtracted, @"Folders with names in unicode should be extracted propertly.");
}
- (void)testUnzippingEmptyArchive {
NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"Empty" ofType:@"zip"];
NSString *outputPath = [self _cachesPath:@"Empty"];
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:nil];
XCTAssertTrue(success);
}
- (void)testZippingAndUnzippingForDate {

View File

@@ -1,5 +1,5 @@
PODS:
- SSZipArchive (2.1.1)
- SSZipArchive (2.1.0)
DEPENDENCIES:
- SSZipArchive (from `..`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ..
SPEC CHECKSUMS:
SSZipArchive: 14401ade5f8e82aba1ff03e9f88e9de60937ae60
SSZipArchive: faba11d882f0bcaf608c1dab320e2900a70537aa
PODFILE CHECKSUM: 5e250843c66c607960128ebfe02ab7d6569102be

View File

@@ -3,21 +3,18 @@
# SSZipArchive
ZipArchive is a simple utility class for zipping and unzipping files on iOS, macOS and tvOS.
ZipArchive is a simple utility class for zipping and unzipping files on iOS and Mac.
- Unzip zip files;
- Unzip password protected zip files;
- Unzip AES encrypted zip files;
- Create zip files;
- Create password protected zip files;
- Create AES encrypted zip files;
- Choose compression level;
- Create new zip files;
- Append to existing zip files;
- Zip files;
- Zip-up NSData instances. (with a filename)
## Installation and Setup
*The main release branch is configured to support Objective C and Swift 3+.*
*The main release branch is configured to support Objective C and Swift 3+. There is a 'swift23' branch which is a tied to a older 1.x release and will not be upgraded. Xcode 8.3+ removes support for Swift 2.3*
SSZipArchive works on Xcode 7-9 and above, iOS 8-11 and above.
@@ -42,10 +39,10 @@ SSZipArchive requires ARC.
```objective-c
// Create
[SSZipArchive createZipFileAtPath:zipPath withContentsOfDirectory:sampleDataPath];
[SSZipArchive createZipFileAtPath: zipPath withContentsOfDirectory: sampleDataPath];
// Unzip
[SSZipArchive unzipFileAtPath:zipPath toDestination:unzipPath];
[SSZipArchive unzipFileAtPath:zipPath toDestination: unzipPath];
```
### Swift
@@ -60,7 +57,7 @@ SSZipArchive.unzipFileAtPath(zipPath, toDestination: unzipPath)
## License
SSZipArchive is protected under the [MIT license](https://github.com/samsoffes/ssziparchive/raw/master/LICENSE) and our slightly modified version of [Minizip](https://github.com/nmoinvaz/minizip) 1.2 is licensed under the [Zlib license](http://www.zlib.net/zlib_license.html).
SSZipArchive is protected under the [MIT license](https://github.com/samsoffes/ssziparchive/raw/master/LICENSE) and our slightly modified version of [Minizip](https://github.com/nmoinvaz/minizip) 1.1 is licensed under the [Zlib license](http://www.zlib.net/zlib_license.html).
## Acknowledgments

View File

@@ -1,17 +1,17 @@
Pod::Spec.new do |s|
s.name = 'SSZipArchive'
s.version = '2.1.1'
s.version = '2.1.0'
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 = '11.0'
s.ios.deployment_target = '4.0'
s.tvos.deployment_target = '9.0'
s.osx.deployment_target = '10.8'
s.watchos.deployment_target = '2.0'
s.source_files = 'SSZipArchive/*.{m,h}', 'SSZipArchive/minizip/*.{c,h}', 'SSZipArchive/minizip/aes/*.{c,h}'
s.source_files = 'SSZipArchive/*.{m,h}', 'SSZipArchive/minizip/**/*.{c,h}'
s.public_header_files = 'SSZipArchive/*.h'
s.library = 'z'
end

View File

@@ -0,0 +1,25 @@
//
// SSZipArchive+Swift.swift
// ZipArchive
//
// Created by William Dunay on 7/6/16.
// Copyright © 2016 smumryak. All rights reserved.
//
import Foundation
extension SSZipArchive {
static func unzipFileAtPath(_ path: String, toDestination destination: String, overwrite: Bool, password: String?, delegate: SSZipArchiveDelegate?) throws -> Bool {
var success = false
var error: NSError?
success = __unzipFile(atPath: path, toDestination: destination, overwrite: overwrite, password: password, error: &error, delegate: delegate)
if let throwableError = error {
throw throwableError
}
return success
}
}

View File

@@ -59,29 +59,17 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
overwrite:(BOOL)overwrite
password:(nullable NSString *)password
progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
preserveAttributes:(BOOL)preserveAttributes
overwrite:(BOOL)overwrite
nestedZipLevel:(NSInteger)nestedZipLevel
password:(nullable NSString *)password
error:(NSError **)error
delegate:(nullable id<SSZipArchiveDelegate>)delegate
progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler;
// Zip
// default compression level is Z_DEFAULT_COMPRESSION (from "zlib.h")
// without password
+ (BOOL)createZipFileAtPath:(NSString *)path withFilesAtPaths:(NSArray<NSString *> *)paths;
@@ -89,9 +77,7 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
+ (BOOL)createZipFileAtPath:(NSString *)path withContentsOfDirectory:(NSString *)directoryPath keepParentDirectory:(BOOL)keepParentDirectory;
// 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;
// with password, password could be nil
+ (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;
@@ -100,37 +86,14 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
keepParentDirectory:(BOOL)keepParentDirectory
withPassword:(nullable NSString *)password
andProgressHandler:(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
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;
/// write file
- (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password;
- (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password;
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password;
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes;
/// write data
- (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password;
- (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes;
- (BOOL)close;
@end

View File

@@ -7,9 +7,10 @@
//
#import "SSZipArchive.h"
#include "unzip.h"
#include "zip.h"
#include "minishared.h"
#include "mz_error.h"
#include "mz_os.h"
#include "mz_unzip.h"
#include "mz_zip.h"
#include <sys/stat.h>
@@ -17,7 +18,6 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
#define CHUNK 16384
int _zipOpenEntry(zipFile entry, NSString *name, const zip_fileinfo *zipfi, int level, NSString *password, BOOL aes);
BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
#ifndef API_AVAILABLE
@@ -44,32 +44,42 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
#pragma mark - Password check
+ (BOOL)isFilePasswordProtectedAtPath:(NSString *)path {
// Begin opening
zipFile zip = unzOpen(path.fileSystemRepresentation);
if (zip == NULL) {
void *stream = NULL;
mz_stream_os_create(&stream);
if (mz_stream_open(stream, path.fileSystemRepresentation, MZ_STREAM_MODE_READ) != MZ_OK)
{
mz_stream_os_delete(&stream);
return NO;
}
int ret = unzGoToFirstFile(zip);
if (ret == UNZ_OK) {
// Begin opening
void *zip = mz_unzip_open(stream);
if (zip == NULL) {
mz_stream_os_delete(&stream);
return NO;
}
int ret = mz_unzip_goto_first_entry(zip);
if (ret == MZ_OK) {
do {
ret = unzOpenCurrentFile(zip);
if (ret != UNZ_OK) {
mz_unzip_file *fileInfo = NULL;
ret = mz_unzip_entry_get_info(zip, &fileInfo);
if (ret != MZ_OK) {
mz_unzip_close(stream);
mz_stream_os_delete(&stream);
return NO;
}
unz_file_info fileInfo = {};
ret = unzGetCurrentFileInfo(zip, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
if (ret != UNZ_OK) {
return NO;
} else if ((fileInfo.flag & 1) == 1) {
} else if ((fileInfo->flag & 1) == 1) {
mz_unzip_close(stream);
mz_stream_os_delete(&stream);
return YES;
}
unzCloseCurrentFile(zip);
ret = unzGoToNextFile(zip);
} while (ret == UNZ_OK);
ret = mz_unzip_goto_next_entry(zip);
} while (ret == MZ_OK);
}
mz_unzip_close(stream);
mz_stream_os_delete(&stream);
return NO;
}
@@ -89,14 +99,14 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
}
int ret = unzGoToFirstFile(zip);
if (ret == UNZ_OK) {
if (ret == MZ_OK) {
do {
if (pw.length == 0) {
ret = unzOpenCurrentFile(zip);
} else {
ret = unzOpenCurrentFilePassword(zip, [pw cStringUsingEncoding:NSUTF8StringEncoding]);
}
if (ret != UNZ_OK) {
if (ret != MZ_OK) {
if (ret != UNZ_BADPASSWORD) {
if (error) {
*error = [NSError errorWithDomain:SSZipArchiveErrorDomain
@@ -108,7 +118,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
}
unz_file_info fileInfo = {};
ret = unzGetCurrentFileInfo(zip, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
if (ret != UNZ_OK) {
if (ret != MZ_OK) {
if (error) {
*error = [NSError errorWithDomain:SSZipArchiveErrorDomain
code:SSZipArchiveErrorCodeFileInfoNotLoadable
@@ -135,7 +145,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
unzCloseCurrentFile(zip);
ret = unzGoToNextFile(zip);
} while (ret == UNZ_OK);
} while (ret == MZ_OK && MZ_OK != UNZ_END_OF_LIST_OF_FILE);
}
// No password required
@@ -181,8 +191,8 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler
{
return [self unzipFileAtPath:path toDestination:destination preserveAttributes:YES overwrite:YES password:nil error:nil delegate:nil progressHandler:progressHandler completionHandler:completionHandler];
}
@@ -204,23 +214,9 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
overwrite:(BOOL)overwrite
password:(nullable NSString *)password
error:(NSError **)error
delegate:(nullable id<SSZipArchiveDelegate>)delegate
progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler
{
return [self unzipFileAtPath:path toDestination:destination preserveAttributes:preserveAttributes overwrite:overwrite nestedZipLevel:0 password:password error:error delegate:delegate progressHandler:progressHandler completionHandler:completionHandler];
}
+ (BOOL)unzipFileAtPath:(NSString *)path
toDestination:(NSString *)destination
preserveAttributes:(BOOL)preserveAttributes
overwrite:(BOOL)overwrite
nestedZipLevel:(NSInteger)nestedZipLevel
password:(nullable NSString *)password
error:(NSError **)error
delegate:(nullable id<SSZipArchiveDelegate>)delegate
progressHandler:(void (^_Nullable)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^_Nullable)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler
delegate:(id<SSZipArchiveDelegate>)delegate
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * _Nullable error))completionHandler
{
// Guard against empty strings
if (path.length == 0 || destination.length == 0)
@@ -263,9 +259,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
unzGetGlobalInfo(zip, &globalInfo);
// Begin unzipping
int ret = 0;
ret = unzGoToFirstFile(zip);
if (ret != UNZ_OK && ret != UNZ_END_OF_LIST_OF_FILE)
if (unzGoToFirstFile(zip) != MZ_OK)
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: @"failed to open first file in zip file"};
NSError *err = [NSError errorWithDomain:SSZipArchiveErrorDomain code:SSZipArchiveErrorCodeFailedOpenFileInZip userInfo:userInfo];
@@ -282,6 +276,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
BOOL success = YES;
BOOL canceled = NO;
int ret = 0;
int crc_ret = 0;
unsigned char buffer[4096] = {0};
NSFileManager *fileManager = [NSFileManager defaultManager];
@@ -295,12 +290,9 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
[delegate zipArchiveProgressEvent:currentPosition total:fileSize];
}
NSInteger currentFileNumber = -1;
NSInteger currentFileNumber = 0;
NSError *unzippingError;
do {
currentFileNumber++;
if (ret == UNZ_END_OF_LIST_OF_FILE)
break;
@autoreleasepool {
if (password.length == 0) {
ret = unzOpenCurrentFile(zip);
@@ -308,7 +300,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
ret = unzOpenCurrentFilePassword(zip, [password cStringUsingEncoding:NSUTF8StringEncoding]);
}
if (ret != UNZ_OK) {
if (ret != MZ_OK) {
unzippingError = [NSError errorWithDomain:@"SSZipArchiveErrorDomain" code:SSZipArchiveErrorCodeFailedOpenFileInZip userInfo:@{NSLocalizedDescriptionKey: @"failed to open file in zip file"}];
success = NO;
break;
@@ -319,7 +311,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
memset(&fileInfo, 0, sizeof(unz_file_info));
ret = unzGetCurrentFileInfo(zip, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
if (ret != UNZ_OK) {
if (ret != MZ_OK) {
unzippingError = [NSError errorWithDomain:@"SSZipArchiveErrorDomain" code:SSZipArchiveErrorCodeFileInfoNotLoadable userInfo:@{NSLocalizedDescriptionKey: @"failed to retrieve info for file"}];
success = NO;
unzCloseCurrentFile(zip);
@@ -332,8 +324,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
if ([delegate respondsToSelector:@selector(zipArchiveShouldUnzipFileAtIndex:totalFiles:archivePath:fileInfo:)]) {
if (![delegate zipArchiveShouldUnzipFileAtIndex:currentFileNumber
totalFiles:(NSInteger)globalInfo.number_entry
archivePath:path
fileInfo:fileInfo]) {
archivePath:path fileInfo:fileInfo]) {
success = NO;
canceled = YES;
break;
@@ -360,13 +351,6 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
BOOL fileIsSymbolicLink = _fileIsSymbolicLink(&fileInfo);
NSString * strPath = [SSZipArchive _filenameStringWithCString:filename size:fileInfo.size_filename];
if ([strPath hasPrefix:@"__MACOSX/"]) {
// ignoring resource forks: https://superuser.com/questions/104500/what-is-macosx-folder
unzCloseCurrentFile(zip);
ret = unzGoToNextFile(zip);
free(filename);
continue;
}
if (!strPath.length) {
// if filename data is unsalvageable, we default to currentFileNumber
strPath = @(currentFileNumber).stringValue;
@@ -443,23 +427,16 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
}
if (fp) {
if ([fullPath.pathExtension.lowercaseString isEqualToString:@"zip"]) {
NSLog(@"Unzipping nested .zip file: %@", fullPath.lastPathComponent);
if ([self unzipFileAtPath:fullPath toDestination:fullPath.stringByDeletingLastPathComponent overwrite:overwrite password:password error:nil delegate:nil]) {
[[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
}
}
fclose(fp);
if (nestedZipLevel
&& [fullPath.pathExtension.lowercaseString isEqualToString:@"zip"]
&& [self unzipFileAtPath:fullPath
toDestination:fullPath.stringByDeletingLastPathComponent
preserveAttributes:preserveAttributes
overwrite:overwrite
nestedZipLevel:nestedZipLevel - 1
password:password
error:nil
delegate:nil
progressHandler:nil
completionHandler:nil]) {
[directoriesModificationDates removeLastObject];
[[NSFileManager defaultManager] removeItemAtPath:fullPath error:nil];
} else if (preserveAttributes) {
if (preserveAttributes) {
// Set the original datetime property
if (fileInfo.dos_date != 0) {
@@ -564,7 +541,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
crc_ret = unzCloseCurrentFile(zip);
if (crc_ret == UNZ_CRCERROR) {
// CRC ERROR
//CRC ERROR
success = NO;
break;
}
@@ -579,12 +556,13 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
archivePath:path unzippedFilePath: fullPath];
}
currentFileNumber++;
if (progressHandler)
{
progressHandler(strPath, fileInfo, currentFileNumber, globalInfo.number_entry);
}
}
} while (ret == UNZ_OK && success);
} while (ret == MZ_OK && success);
// Close
unzClose(zip);
@@ -667,19 +645,6 @@ 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];
}
@@ -699,30 +664,9 @@ 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 diskSize:0 progressHandler:progressHandler];
}
+ (BOOL)createZipFileAtPath:(NSString *)path
withContentsOfDirectory:(NSString *)directoryPath
keepParentDirectory:(BOOL)keepParentDirectory
compressionLevel:(int)compressionLevel
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 openWithSplitSize:diskSize];
BOOL success = [zipArchive open];
if (success) {
// use a local fileManager (queue/thread compatibility)
NSFileManager *fileManager = [[NSFileManager alloc] init];
@@ -741,13 +685,15 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
}
if (!isDir) {
success &= [zipArchive writeFileAtPath:fullFilePath withFileName:fileName compressionLevel:compressionLevel password:password AES:aes];
success &= [zipArchive writeFileAtPath:fullFilePath withFileName:fileName withPassword:password];
}
else
{
if ([[NSFileManager defaultManager] subpathsOfDirectoryAtPath:fullFilePath error:nil].count == 0)
{
success &= [zipArchive writeFolderAtPath:fullFilePath withFolderName:fileName withPassword:password];
NSString *tempFilePath = [self _temporaryPathForDiscardableFile];
NSString *tempFileFilename = [fileName stringByAppendingPathComponent:tempFilePath.lastPathComponent];
success &= [zipArchive writeFileAtPath:tempFilePath withFileName:tempFileFilename withPassword:password];
}
}
complete++;
@@ -772,19 +718,30 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
return self;
}
- (BOOL)open
{
return [self openWithSplitSize:0];
NSAssert((_zip == NULL), @"Attempting to open an archive which is already open");
_zip = zipOpen(_path.fileSystemRepresentation, APPEND_STATUS_CREATE);
return (NULL != _zip);
}
- (BOOL)openWithSplitSize:(int)disk_size
- (void)zipInfo:(zip_fileinfo *)zipInfo setDate:(NSDate *)date
{
NSAssert((_zip == NULL), @"Attempting to open an archive which is already open");
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);
NSCalendar *currentCalendar = SSZipArchive._gregorian;
NSCalendarUnit flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDateComponents *components = [currentCalendar components:flags fromDate:date];
struct tm tmz_date;
tmz_date.tm_sec = (unsigned int)components.second;
tmz_date.tm_min = (unsigned int)components.minute;
tmz_date.tm_hour = (unsigned int)components.hour;
tmz_date.tm_mday = (unsigned int)components.day;
// ISO/IEC 9899 struct tm is 0-indexed for January but NSDateComponents for gregorianCalendar is 1-indexed for January
tmz_date.tm_mon = (unsigned int)components.month - 1;
// ISO/IEC 9899 struct tm is 0-indexed for AD 1900 but NSDateComponents for gregorianCalendar is 1-indexed for AD 1
tmz_date.tm_year = (unsigned int)components.year - 1900;
zipInfo->dos_date = tm_to_dosdate(&tmz_date);
}
- (BOOL)writeFolderAtPath:(NSString *)path withFolderName:(NSString *)folderName withPassword:(nullable NSString *)password
@@ -793,29 +750,66 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
zip_fileinfo zipInfo = {};
[SSZipArchive zipInfo:&zipInfo setAttributesOfItemAtPath:path];
NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error: nil];
if (attr)
{
NSDate *fileDate = (NSDate *)attr[NSFileModificationDate];
if (fileDate)
{
[self zipInfo:&zipInfo setDate: fileDate];
}
// Write permissions into the external attributes, for details on this see here: http://unix.stackexchange.com/a/14727
// Get the permissions value from the files attributes
NSNumber *permissionsValue = (NSNumber *)attr[NSFilePosixPermissions];
if (permissionsValue != nil) {
// Get the short value for the permissions
short permissionsShort = permissionsValue.shortValue;
// Convert this into an octal by adding 010000, 010000 being the flag for a regular file
NSInteger permissionsOctal = 0100000 + permissionsShort;
// Convert this into a long value
uLong permissionsLong = @(permissionsOctal).unsignedLongValue;
// Store this into the external file attributes once it has been shifted 16 places left to form part of the second from last byte
// Casted back to an unsigned int to match type of external_fa in minizip
zipInfo.external_fa = (unsigned int)(permissionsLong << 16L);
}
}
int error = _zipOpenEntry(_zip, [folderName stringByAppendingString:@"/"], &zipInfo, Z_NO_COMPRESSION, password, 0);
const void *buffer = NULL;
zipWriteInFileInZip(_zip, buffer, 0);
int error = zipOpenNewFileInZip3(_zip,
[folderName stringByAppendingString:@"/"].fileSystemRepresentation,
&zipInfo,
NULL,
0,
NULL,
0,
NULL,
Z_DEFLATED,
Z_NO_COMPRESSION,
0,
-MAX_WBITS,
DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY,
password.UTF8String,
0);
unsigned int len = 0;
zipWriteInFileInZip(_zip, &len, 0);
zipCloseFileInZip(_zip);
return error == ZIP_OK;
}
- (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password
- (BOOL)writeFile:(NSString *)path withPassword:(nullable NSString *)password;
{
return [self writeFileAtPath:path withFileName:nil withPassword:password];
}
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password
{
return [self writeFileAtPath:path withFileName:fileName compressionLevel:Z_DEFAULT_COMPRESSION password:password AES:YES];
}
// supports writing files with logical folder/directory structure
// *path* is the absolute path of the file that will be compressed
// *fileName* is the relative name of the file how it is stored within the zip e.g. /folder/subfolder/text1.txt
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes
- (BOOL)writeFileAtPath:(NSString *)path withFileName:(nullable NSString *)fileName withPassword:(nullable NSString *)password
{
NSAssert((_zip != NULL), @"Attempting to write to an archive which was never opened");
@@ -824,13 +818,44 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
return NO;
}
const char *aFileName;
if (!fileName) {
fileName = path.lastPathComponent;
aFileName = path.lastPathComponent.fileSystemRepresentation;
}
else {
aFileName = fileName.fileSystemRepresentation;
}
zip_fileinfo zipInfo = {};
[SSZipArchive zipInfo:&zipInfo setAttributesOfItemAtPath:path];
NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error: nil];
if (attr)
{
NSDate *fileDate = (NSDate *)attr[NSFileModificationDate];
if (fileDate)
{
[self zipInfo:&zipInfo setDate: fileDate];
}
// Write permissions into the external attributes, for details on this see here: http://unix.stackexchange.com/a/14727
// Get the permissions value from the files attributes
NSNumber *permissionsValue = (NSNumber *)attr[NSFilePosixPermissions];
if (permissionsValue != nil) {
// Get the short value for the permissions
short permissionsShort = permissionsValue.shortValue;
// Convert this into an octal by adding 010000, 010000 being the flag for a regular file
NSInteger permissionsOctal = 0100000 + permissionsShort;
// Convert this into a long value
uLong permissionsLong = @(permissionsOctal).unsignedLongValue;
// Store this into the external file attributes once it has been shifted 16 places left to form part of the second from last byte
// Casted back to an unsigned int to match type of external_fa in minizip
zipInfo.external_fa = (unsigned int)(permissionsLong << 16L);
}
}
void *buffer = malloc(CHUNK);
if (buffer == NULL)
@@ -839,7 +864,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
return NO;
}
int error = _zipOpenEntry(_zip, fileName, &zipInfo, compressionLevel, password, aes);
int error = zipOpenNewFileInZip3(_zip, aFileName, &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password.UTF8String, 0);
while (!feof(input) && !ferror(input))
{
@@ -853,12 +878,7 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
return error == ZIP_OK;
}
- (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password
{
return [self writeData:data filename:filename compressionLevel:Z_DEFAULT_COMPRESSION password:password AES:YES];
}
- (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename compressionLevel:(int)compressionLevel password:(nullable NSString *)password AES:(BOOL)aes
- (BOOL)writeData:(NSData *)data filename:(nullable NSString *)filename withPassword:(nullable NSString *)password;
{
if (!_zip) {
return NO;
@@ -867,9 +887,9 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
return NO;
}
zip_fileinfo zipInfo = {};
[SSZipArchive zipInfo:&zipInfo setDate:[NSDate date]];
[self zipInfo:&zipInfo setDate:[NSDate date]];
int error = _zipOpenEntry(_zip, filename, &zipInfo, compressionLevel, password, aes);
int error = zipOpenNewFileInZip3(_zip, filename.fileSystemRepresentation, &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password.UTF8String, 0);
zipWriteInFileInZip(_zip, data.bytes, (unsigned int)data.length);
@@ -877,24 +897,23 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
return error == ZIP_OK;
}
- (BOOL)close
{
NSAssert((_zip != NULL), @"[SSZipArchive] Attempting to close an archive which was never opened");
int error = zipClose(_zip, NULL);
_zip = nil;
return error == UNZ_OK;
return error == MZ_OK;
}
#pragma mark - Private
+ (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
@@ -920,63 +939,29 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
}
}
}
if (strPath) {
return strPath;
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 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;
}
+ (void)zipInfo:(zip_fileinfo *)zipInfo setAttributesOfItemAtPath:(NSString *)path
+ (NSString *)_temporaryPathForDiscardableFile
{
NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:path error: nil];
if (attr)
{
NSDate *fileDate = (NSDate *)attr[NSFileModificationDate];
if (fileDate)
{
[self zipInfo:zipInfo setDate:fileDate];
static NSString *discardableFileName = @".DS_Store";
static NSString *discardableFilePath = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *temporaryDirectoryName = [NSUUID UUID].UUIDString;
NSString *temporaryDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:temporaryDirectoryName];
BOOL directoryCreated = [[NSFileManager defaultManager] createDirectoryAtPath:temporaryDirectory withIntermediateDirectories:YES attributes:nil error:nil];
if (directoryCreated) {
discardableFilePath = [temporaryDirectory stringByAppendingPathComponent:discardableFileName];
[@"" writeToFile:discardableFilePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
// Write permissions into the external attributes, for details on this see here: http://unix.stackexchange.com/a/14727
// Get the permissions value from the files attributes
NSNumber *permissionsValue = (NSNumber *)attr[NSFilePosixPermissions];
if (permissionsValue != nil) {
// Get the short value for the permissions
short permissionsShort = permissionsValue.shortValue;
// Convert this into an octal by adding 010000, 010000 being the flag for a regular file
NSInteger permissionsOctal = 0100000 + permissionsShort;
// Convert this into a long value
uLong permissionsLong = @(permissionsOctal).unsignedLongValue;
// Store this into the external file attributes once it has been shifted 16 places left to form part of the second from last byte
// Casted back to an unsigned int to match type of external_fa in minizip
zipInfo->external_fa = (unsigned int)(permissionsLong << 16L);
}
}
}
+ (void)zipInfo:(zip_fileinfo *)zipInfo setDate:(NSDate *)date
{
NSCalendar *currentCalendar = SSZipArchive._gregorian;
NSCalendarUnit flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
NSDateComponents *components = [currentCalendar components:flags fromDate:date];
struct tm tmz_date;
tmz_date.tm_sec = (unsigned int)components.second;
tmz_date.tm_min = (unsigned int)components.minute;
tmz_date.tm_hour = (unsigned int)components.hour;
tmz_date.tm_mday = (unsigned int)components.day;
// ISO/IEC 9899 struct tm is 0-indexed for January but NSDateComponents for gregorianCalendar is 1-indexed for January
tmz_date.tm_mon = (unsigned int)components.month - 1;
// ISO/IEC 9899 struct tm is 0-indexed for AD 1900 but NSDateComponents for gregorianCalendar is 1-indexed for AD 1
tmz_date.tm_year = (unsigned int)components.year - 1900;
zipInfo->dos_date = tm_to_dosdate(&tmz_date);
});
return discardableFilePath;
}
+ (NSCalendar *)_gregorian
@@ -1025,11 +1010,6 @@ BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo);
@end
int _zipOpenEntry(zipFile entry, NSString *name, const zip_fileinfo *zipfi, int level, NSString *password, BOOL aes)
{
return zipOpenNewFileInZip5(entry, name.fileSystemRepresentation, zipfi, NULL, 0, NULL, 0, NULL, 0, 0, Z_DEFLATED, level, 0, -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, password.UTF8String, aes);
}
#pragma mark - Private tools for file info
BOOL _fileIsSymbolicLink(const unz_file_info *fileInfo)
@@ -1078,11 +1058,6 @@ 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--) {

View File

@@ -1,144 +0,0 @@
/* crypt.c -- base code for traditional PKWARE encryption
Version 1.2.0, September 16th, 2017
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
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.
This encryption code is a direct transcription of the algorithm from
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
file (appnote.txt) is distributed with the PKZIP program (even in the
version without encryption capabilities).
If you don't need crypting in your application, just define symbols
NOCRYPT and NOUNCRYPT.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#ifdef _WIN32
# include <windows.h>
# include <wincrypt.h>
#else
# include <sys/stat.h>
# include <fcntl.h>
# include <unistd.h>
#endif
#include "zlib.h"
#include "crypt.h"
/***************************************************************************/
#define CRC32(c, b) ((*(pcrc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
/***************************************************************************/
uint8_t decrypt_byte(uint32_t *pkeys)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
temp = ((uint32_t)(*(pkeys+2)) & 0xffff) | 2;
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c)
{
(*(pkeys+0)) = (uint32_t)CRC32((*(pkeys+0)), c);
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
{
register int32_t keyshift = (int32_t)((*(pkeys + 1)) >> 24);
(*(pkeys+2)) = (uint32_t)CRC32((*(pkeys+2)), keyshift);
}
return c;
}
void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab)
{
*(pkeys+0) = 305419896L;
*(pkeys+1) = 591751049L;
*(pkeys+2) = 878082192L;
while (*passwd != 0)
{
update_keys(pkeys, pcrc_32_tab, *passwd);
passwd += 1;
}
}
/***************************************************************************/
int cryptrand(unsigned char *buf, unsigned int len)
{
#ifdef _WIN32
HCRYPTPROV provider;
unsigned __int64 pentium_tsc[1];
int rlen = 0;
int result = 0;
if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
{
result = CryptGenRandom(provider, len, buf);
CryptReleaseContext(provider, 0);
if (result)
return len;
}
for (rlen = 0; rlen < (int)len; ++rlen)
{
if (rlen % 8 == 0)
QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc);
buf[rlen] = ((unsigned char*)pentium_tsc)[rlen % 8];
}
return rlen;
#else
arc4random_buf(buf, len);
return len;
#endif
}
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2)
{
uint8_t n = 0; /* index in random header */
uint8_t header[RAND_HEAD_LEN-2]; /* random header */
uint16_t t = 0; /* temporary */
if (buf_size < RAND_HEAD_LEN)
return 0;
init_keys(passwd, pkeys, pcrc_32_tab);
/* First generate RAND_HEAD_LEN-2 random bytes. */
cryptrand(header, RAND_HEAD_LEN-2);
/* Encrypt random header (last two bytes is high word of crc) */
init_keys(passwd, pkeys, pcrc_32_tab);
for (n = 0; n < RAND_HEAD_LEN-2; n++)
buf[n] = (uint8_t)zencode(pkeys, pcrc_32_tab, header[n], t);
buf[n++] = (uint8_t)zencode(pkeys, pcrc_32_tab, verify1, t);
buf[n++] = (uint8_t)zencode(pkeys, pcrc_32_tab, verify2, t);
return n;
}
/***************************************************************************/

View File

@@ -1,64 +0,0 @@
/* crypt.h -- base code for traditional PKWARE encryption
Version 1.2.0, September 16th, 2017
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
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 _MINICRYPT_H
#define _MINICRYPT_H
#if ZLIB_VERNUM < 0x1270
typedef unsigned long z_crc_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define RAND_HEAD_LEN 12
/***************************************************************************/
#define zdecode(pkeys,pcrc_32_tab,c) \
(update_keys(pkeys,pcrc_32_tab, c ^= decrypt_byte(pkeys)))
#define zencode(pkeys,pcrc_32_tab,c,t) \
(t = decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c))
/***************************************************************************/
/* Return the next byte in the pseudo-random sequence */
uint8_t decrypt_byte(uint32_t *pkeys);
/* Update the encryption keys with the next byte of plain text */
uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c);
/* Initialize the encryption keys and the random header according to the given password. */
void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab);
/* Generate cryptographically secure random numbers */
int cryptrand(unsigned char *buf, unsigned int len);
/* Create encryption header */
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,353 +0,0 @@
/* ioapi.c -- IO base function header for compress/uncompress .zip
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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 <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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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(ZIP_UNUSED 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;
}

View File

@@ -1,154 +0,0 @@
/* ioapi.h -- IO base function header for compress/uncompress .zip
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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 _ZLIBIOAPI64_H
#define _ZLIBIOAPI64_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "zlib.h"
#ifdef __GNUC__
# define ZIP_UNUSED __attribute__((__unused__))
#else
# define ZIP_UNUSED
#endif
#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__) || defined(__ANDROID__)
# 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

View File

@@ -1,461 +0,0 @@
/* ioapi_buf.c -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
This version of ioapi is designed to buffer IO.
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "zlib.h"
#include "ioapi.h"
#include "ioapi_buf.h"
#ifndef IOBUF_BUFFERSIZE
# define IOBUF_BUFFERSIZE (UINT16_MAX)
#endif
#if defined(_WIN32)
# include <conio.h>
# define PRINTF _cprintf
# define VPRINTF _vcprintf
#else
# define PRINTF printf
# define VPRINTF vprintf
#endif
//#define IOBUF_VERBOSE
#ifdef __GNUC__
#ifndef max
#define max(x,y) ({ \
const __typeof__(x) _x = (x); \
const __typeof__(y) _y = (y); \
(void) (&_x == &_y); \
_x > _y ? _x : _y; })
#endif /* __GNUC__ */
#ifndef min
#define min(x,y) ({ \
const __typeof__(x) _x = (x); \
const __typeof__(y) _y = (y); \
(void) (&_x == &_y); \
_x < _y ? _x : _y; })
#endif
#endif
typedef struct ourstream_s {
char readbuf[IOBUF_BUFFERSIZE];
uint32_t readbuf_len;
uint32_t readbuf_pos;
uint32_t readbuf_hits;
uint32_t readbuf_misses;
char writebuf[IOBUF_BUFFERSIZE];
uint32_t writebuf_len;
uint32_t writebuf_pos;
uint32_t writebuf_hits;
uint32_t writebuf_misses;
uint64_t position;
voidpf stream;
} ourstream_t;
#if defined(IOBUF_VERBOSE)
# define print_buf(o,s,f,...) print_buf_internal(o,s,f,__VA_ARGS__);
#else
# define print_buf(o,s,f,...)
#endif
void print_buf_internal(ZIP_UNUSED voidpf opaque, voidpf stream, char *format, ...)
{
ourstream_t *streamio = (ourstream_t *)stream;
va_list arglist;
PRINTF("Buf stream %p - ", streamio);
va_start(arglist, format);
VPRINTF(format, arglist);
va_end(arglist);
}
voidpf fopen_buf_internal_func(ZIP_UNUSED voidpf opaque, voidpf stream, ZIP_UNUSED uint32_t number_disk, ZIP_UNUSED int mode)
{
ourstream_t *streamio = NULL;
if (stream == NULL)
return NULL;
streamio = (ourstream_t *)malloc(sizeof(ourstream_t));
if (streamio == NULL)
return NULL;
memset(streamio, 0, sizeof(ourstream_t));
streamio->stream = stream;
print_buf(opaque, streamio, "open [num %d mode %d]\n", number_disk, mode);
return streamio;
}
voidpf ZCALLBACK fopen_buf_func(voidpf opaque, const char *filename, int mode)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
voidpf stream = bufio->filefunc.zopen_file(bufio->filefunc.opaque, filename, mode);
return fopen_buf_internal_func(opaque, stream, 0, mode);
}
voidpf ZCALLBACK fopen64_buf_func(voidpf opaque, const void *filename, int mode)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
voidpf stream = bufio->filefunc64.zopen64_file(bufio->filefunc64.opaque, filename, mode);
return fopen_buf_internal_func(opaque, stream, 0, mode);
}
voidpf ZCALLBACK fopendisk_buf_func(voidpf opaque, voidpf stream_cd, uint32_t number_disk, int mode)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream_cd;
voidpf *stream = bufio->filefunc.zopendisk_file(bufio->filefunc.opaque, streamio->stream, number_disk, mode);
return fopen_buf_internal_func(opaque, stream, number_disk, mode);
}
voidpf ZCALLBACK fopendisk64_buf_func(voidpf opaque, voidpf stream_cd, uint32_t number_disk, int mode)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream_cd;
voidpf stream = bufio->filefunc64.zopendisk64_file(bufio->filefunc64.opaque, streamio->stream, number_disk, mode);
return fopen_buf_internal_func(opaque, stream, number_disk, mode);
}
long fflush_buf(voidpf opaque, voidpf stream)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
uint32_t total_bytes_to_write = 0;
uint32_t bytes_to_write = streamio->writebuf_len;
uint32_t bytes_left_to_write = streamio->writebuf_len;
long bytes_written = 0;
while (bytes_left_to_write > 0)
{
if (bufio->filefunc64.zwrite_file != NULL)
bytes_written = bufio->filefunc64.zwrite_file(bufio->filefunc64.opaque, streamio->stream, streamio->writebuf + (bytes_to_write - bytes_left_to_write), bytes_left_to_write);
else
bytes_written = bufio->filefunc.zwrite_file(bufio->filefunc.opaque, streamio->stream, streamio->writebuf + (bytes_to_write - bytes_left_to_write), bytes_left_to_write);
streamio->writebuf_misses += 1;
print_buf(opaque, stream, "write flush [%d:%d len %d]\n", bytes_to_write, bytes_left_to_write, streamio->writebuf_len);
if (bytes_written < 0)
return bytes_written;
total_bytes_to_write += bytes_written;
bytes_left_to_write -= bytes_written;
streamio->position += bytes_written;
}
streamio->writebuf_len = 0;
streamio->writebuf_pos = 0;
return total_bytes_to_write;
}
uint32_t ZCALLBACK fread_buf_func(voidpf opaque, voidpf stream, void *buf, uint32_t size)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
uint32_t buf_len = 0;
uint32_t bytes_to_read = 0;
uint32_t bytes_to_copy = 0;
uint32_t bytes_left_to_read = size;
uint32_t bytes_read = 0;
print_buf(opaque, stream, "read [size %ld pos %lld]\n", size, streamio->position);
if (streamio->writebuf_len > 0)
{
print_buf(opaque, stream, "switch from write to read, not yet supported [%lld]\n", streamio->position);
}
while (bytes_left_to_read > 0)
{
if ((streamio->readbuf_len == 0) || (streamio->readbuf_pos == streamio->readbuf_len))
{
if (streamio->readbuf_len == IOBUF_BUFFERSIZE)
{
streamio->readbuf_pos = 0;
streamio->readbuf_len = 0;
}
bytes_to_read = IOBUF_BUFFERSIZE - (streamio->readbuf_len - streamio->readbuf_pos);
if (bufio->filefunc64.zread_file != NULL)
bytes_read = bufio->filefunc64.zread_file(bufio->filefunc64.opaque, streamio->stream, streamio->readbuf + streamio->readbuf_pos, bytes_to_read);
else
bytes_read = bufio->filefunc.zread_file(bufio->filefunc.opaque, streamio->stream, streamio->readbuf + streamio->readbuf_pos, bytes_to_read);
streamio->readbuf_misses += 1;
streamio->readbuf_len += bytes_read;
streamio->position += bytes_read;
print_buf(opaque, stream, "filled [read %d/%d buf %d:%d pos %lld]\n", bytes_read, bytes_to_read, streamio->readbuf_pos, streamio->readbuf_len, streamio->position);
if (bytes_read == 0)
break;
}
if ((streamio->readbuf_len - streamio->readbuf_pos) > 0)
{
bytes_to_copy = min(bytes_left_to_read, (uint32_t)(streamio->readbuf_len - streamio->readbuf_pos));
memcpy((char *)buf + buf_len, streamio->readbuf + streamio->readbuf_pos, bytes_to_copy);
buf_len += bytes_to_copy;
bytes_left_to_read -= bytes_to_copy;
streamio->readbuf_hits += 1;
streamio->readbuf_pos += bytes_to_copy;
print_buf(opaque, stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n", bytes_to_copy, bytes_left_to_read, streamio->readbuf_pos, streamio->readbuf_len, streamio->position);
}
}
return size - bytes_left_to_read;
}
uint32_t ZCALLBACK fwrite_buf_func(voidpf opaque, voidpf stream, const void *buf, uint32_t size)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
uint32_t bytes_to_write = size;
uint32_t bytes_left_to_write = size;
uint32_t bytes_to_copy = 0;
int64_t ret = 0;
print_buf(opaque, stream, "write [size %ld len %d pos %lld]\n", size, streamio->writebuf_len, streamio->position);
if (streamio->readbuf_len > 0)
{
streamio->position -= streamio->readbuf_len;
streamio->position += streamio->readbuf_pos;
streamio->readbuf_len = 0;
streamio->readbuf_pos = 0;
print_buf(opaque, stream, "switch from read to write [%lld]\n", streamio->position);
if (bufio->filefunc64.zseek64_file != NULL)
ret = bufio->filefunc64.zseek64_file(bufio->filefunc64.opaque, streamio->stream, streamio->position, ZLIB_FILEFUNC_SEEK_SET);
else
ret = bufio->filefunc.zseek_file(bufio->filefunc.opaque, streamio->stream, (uint32_t)streamio->position, ZLIB_FILEFUNC_SEEK_SET);
if (ret != 0)
return (uint32_t)-1;
}
while (bytes_left_to_write > 0)
{
bytes_to_copy = min(bytes_left_to_write, (uint32_t)(IOBUF_BUFFERSIZE - min(streamio->writebuf_len, streamio->writebuf_pos)));
if (bytes_to_copy == 0)
{
if (fflush_buf(opaque, stream) <= 0)
return 0;
continue;
}
memcpy(streamio->writebuf + streamio->writebuf_pos, (char *)buf + (bytes_to_write - bytes_left_to_write), bytes_to_copy);
print_buf(opaque, stream, "write copy [remaining %d write %d:%d len %d]\n", bytes_to_copy, bytes_to_write, bytes_left_to_write, streamio->writebuf_len);
bytes_left_to_write -= bytes_to_copy;
streamio->writebuf_pos += bytes_to_copy;
streamio->writebuf_hits += 1;
if (streamio->writebuf_pos > streamio->writebuf_len)
streamio->writebuf_len += streamio->writebuf_pos - streamio->writebuf_len;
}
return size - bytes_left_to_write;
}
uint64_t ftell_buf_internal_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint64_t position)
{
ourstream_t *streamio = (ourstream_t *)stream;
streamio->position = position;
print_buf(opaque, stream, "tell [pos %llu readpos %d writepos %d err %d]\n", streamio->position, streamio->readbuf_pos, streamio->writebuf_pos, errno);
if (streamio->readbuf_len > 0)
position -= (streamio->readbuf_len - streamio->readbuf_pos);
if (streamio->writebuf_len > 0)
position += streamio->writebuf_pos;
return position;
}
long ZCALLBACK ftell_buf_func(voidpf opaque, voidpf stream)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
uint64_t position = bufio->filefunc.ztell_file(bufio->filefunc.opaque, streamio->stream);
return (long)ftell_buf_internal_func(opaque, stream, position);
}
uint64_t ZCALLBACK ftell64_buf_func(voidpf opaque, voidpf stream)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
uint64_t position = bufio->filefunc64.ztell64_file(bufio->filefunc64.opaque, streamio->stream);
return ftell_buf_internal_func(opaque, stream, position);
}
int fseek_buf_internal_func(voidpf opaque, voidpf stream, uint64_t offset, int origin)
{
ourstream_t *streamio = (ourstream_t *)stream;
print_buf(opaque, stream, "seek [origin %d offset %llu pos %lld]\n", origin, offset, streamio->position);
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_SET:
if (streamio->writebuf_len > 0)
{
if ((offset >= streamio->position) && (offset <= streamio->position + streamio->writebuf_len))
{
streamio->writebuf_pos = (uint32_t)(offset - streamio->position);
return 0;
}
}
if ((streamio->readbuf_len > 0) && (offset < streamio->position) && (offset >= streamio->position - streamio->readbuf_len))
{
streamio->readbuf_pos = (uint32_t)(offset - (streamio->position - streamio->readbuf_len));
return 0;
}
if (fflush_buf(opaque, stream) < 0)
return -1;
streamio->position = offset;
break;
case ZLIB_FILEFUNC_SEEK_CUR:
if (streamio->readbuf_len > 0)
{
if (offset <= (streamio->readbuf_len - streamio->readbuf_pos))
{
streamio->readbuf_pos += (uint32_t)offset;
return 0;
}
offset -= (streamio->readbuf_len - streamio->readbuf_pos);
streamio->position += offset;
}
if (streamio->writebuf_len > 0)
{
if (offset <= (streamio->writebuf_len - streamio->writebuf_pos))
{
streamio->writebuf_pos += (uint32_t)offset;
return 0;
}
//offset -= (streamio->writebuf_len - streamio->writebuf_pos);
}
if (fflush_buf(opaque, stream) < 0)
return -1;
break;
case ZLIB_FILEFUNC_SEEK_END:
if (streamio->writebuf_len > 0)
{
streamio->writebuf_pos = streamio->writebuf_len;
return 0;
}
break;
}
streamio->readbuf_len = 0;
streamio->readbuf_pos = 0;
streamio->writebuf_len = 0;
streamio->writebuf_pos = 0;
return 1;
}
long ZCALLBACK fseek_buf_func(voidpf opaque, voidpf stream, uint32_t offset, int origin)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
long ret = -1;
if (bufio->filefunc.zseek_file == NULL)
return ret;
ret = fseek_buf_internal_func(opaque, stream, offset, origin);
if (ret == 1)
ret = bufio->filefunc.zseek_file(bufio->filefunc.opaque, streamio->stream, offset, origin);
return ret;
}
long ZCALLBACK fseek64_buf_func(voidpf opaque, voidpf stream, uint64_t offset, int origin)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
long ret = -1;
if (bufio->filefunc64.zseek64_file == NULL)
return ret;
ret = fseek_buf_internal_func(opaque, stream, offset, origin);
if (ret == 1)
ret = bufio->filefunc64.zseek64_file(bufio->filefunc64.opaque, streamio->stream, offset, origin);
return ret;
}
int ZCALLBACK fclose_buf_func(voidpf opaque, voidpf stream)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
int ret = 0;
fflush_buf(opaque, stream);
print_buf(opaque, stream, "close\n");
if (streamio->readbuf_hits + streamio->readbuf_misses > 0)
print_buf(opaque, stream, "read efficency %.02f%%\n", (streamio->readbuf_hits / ((float)streamio->readbuf_hits + streamio->readbuf_misses)) * 100);
if (streamio->writebuf_hits + streamio->writebuf_misses > 0)
print_buf(opaque, stream, "write efficency %.02f%%\n", (streamio->writebuf_hits / ((float)streamio->writebuf_hits + streamio->writebuf_misses)) * 100);
if (bufio->filefunc64.zclose_file != NULL)
ret = bufio->filefunc64.zclose_file(bufio->filefunc64.opaque, streamio->stream);
else
ret = bufio->filefunc.zclose_file(bufio->filefunc.opaque, streamio->stream);
free(streamio);
return ret;
}
int ZCALLBACK ferror_buf_func(voidpf opaque, voidpf stream)
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
if (bufio->filefunc64.zerror_file != NULL)
return bufio->filefunc64.zerror_file(bufio->filefunc64.opaque, streamio->stream);
return bufio->filefunc.zerror_file(bufio->filefunc.opaque, streamio->stream);
}
void fill_buffer_filefunc(zlib_filefunc_def *pzlib_filefunc_def, ourbuffer_t *ourbuf)
{
pzlib_filefunc_def->zopen_file = fopen_buf_func;
pzlib_filefunc_def->zopendisk_file = fopendisk_buf_func;
pzlib_filefunc_def->zread_file = fread_buf_func;
pzlib_filefunc_def->zwrite_file = fwrite_buf_func;
pzlib_filefunc_def->ztell_file = ftell_buf_func;
pzlib_filefunc_def->zseek_file = fseek_buf_func;
pzlib_filefunc_def->zclose_file = fclose_buf_func;
pzlib_filefunc_def->zerror_file = ferror_buf_func;
pzlib_filefunc_def->opaque = ourbuf;
}
void fill_buffer_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def, ourbuffer_t *ourbuf)
{
pzlib_filefunc_def->zopen64_file = fopen64_buf_func;
pzlib_filefunc_def->zopendisk64_file = fopendisk64_buf_func;
pzlib_filefunc_def->zread_file = fread_buf_func;
pzlib_filefunc_def->zwrite_file = fwrite_buf_func;
pzlib_filefunc_def->ztell64_file = ftell64_buf_func;
pzlib_filefunc_def->zseek64_file = fseek64_buf_func;
pzlib_filefunc_def->zclose_file = fclose_buf_func;
pzlib_filefunc_def->zerror_file = ferror_buf_func;
pzlib_filefunc_def->opaque = ourbuf;
}

View File

@@ -1,52 +0,0 @@
/* ioapi_buf.h -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
This version of ioapi is designed to buffer IO.
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _IOAPI_BUF_H
#define _IOAPI_BUF_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zlib.h"
#include "ioapi.h"
#ifdef __cplusplus
extern "C" {
#endif
voidpf ZCALLBACK fopen_buf_func(voidpf opaque, const char* filename, int mode);
voidpf ZCALLBACK fopen64_buf_func(voidpf opaque, const void* filename, int mode);
voidpf ZCALLBACK fopendisk_buf_func(voidpf opaque, voidpf stream_cd, uint32_t number_disk, int mode);
voidpf ZCALLBACK fopendisk64_buf_func(voidpf opaque, voidpf stream_cd, uint32_t number_disk, int mode);
uint32_t ZCALLBACK fread_buf_func(voidpf opaque, voidpf stream, void* buf, uint32_t size);
uint32_t ZCALLBACK fwrite_buf_func(voidpf opaque, voidpf stream, const void* buf, uint32_t size);
long ZCALLBACK ftell_buf_func(voidpf opaque, voidpf stream);
uint64_t ZCALLBACK ftell64_buf_func(voidpf opaque, voidpf stream);
long ZCALLBACK fseek_buf_func(voidpf opaque, voidpf stream, uint32_t offset, int origin);
long ZCALLBACK fseek64_buf_func(voidpf opaque, voidpf stream, uint64_t offset, int origin);
int ZCALLBACK fclose_buf_func(voidpf opaque,voidpf stream);
int ZCALLBACK ferror_buf_func(voidpf opaque,voidpf stream);
typedef struct ourbuffer_s {
zlib_filefunc_def filefunc;
zlib_filefunc64_def filefunc64;
} ourbuffer_t;
void fill_buffer_filefunc(zlib_filefunc_def* pzlib_filefunc_def, ourbuffer_t *ourbuf);
void fill_buffer_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def, ourbuffer_t *ourbuf);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,167 +0,0 @@
/* ioapi_mem.c -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
This version of ioapi is designed to access memory rather than files.
We do use a region of memory to put data in to and take it out of. We do
not have auto-extending buffers and do not inform anyone else that the
data has been written. It is really intended for accessing a zip archive
embedded in an application such that I can write an installer with no
external files. Creation of archives has not been attempted, although
parts of the framework are present.
Based on Unzip ioapi.c version 0.22, May 19th, 2003
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2003 Justin Fletcher
Copyright (C) 1998-2003 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
This file is under the same license as the Unzip tool it is distributed
with.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zlib.h"
#include "ioapi.h"
#include "ioapi_mem.h"
#ifndef IOMEM_BUFFERSIZE
# define IOMEM_BUFFERSIZE (UINT16_MAX)
#endif
voidpf ZCALLBACK fopen_mem_func(voidpf opaque, ZIP_UNUSED const char *filename, int mode)
{
ourmemory_t *mem = (ourmemory_t *)opaque;
if (mem == NULL)
return NULL; /* Mem structure passed in was null */
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
{
if (mem->grow)
{
mem->size = IOMEM_BUFFERSIZE;
mem->base = (char *)malloc(mem->size);
}
mem->limit = 0; /* When writing we start with 0 bytes written */
}
else
mem->limit = mem->size;
mem->cur_offset = 0;
return mem;
}
voidpf ZCALLBACK fopendisk_mem_func(ZIP_UNUSED voidpf opaque, ZIP_UNUSED voidpf stream, ZIP_UNUSED uint32_t number_disk, ZIP_UNUSED int mode)
{
/* Not used */
return NULL;
}
uint32_t ZCALLBACK fread_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream, void *buf, uint32_t size)
{
ourmemory_t *mem = (ourmemory_t *)stream;
if (size > mem->size - mem->cur_offset)
size = mem->size - mem->cur_offset;
memcpy(buf, mem->base + mem->cur_offset, size);
mem->cur_offset += size;
return size;
}
uint32_t ZCALLBACK fwrite_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream, const void *buf, uint32_t size)
{
ourmemory_t *mem = (ourmemory_t *)stream;
uint32_t newmemsize = 0;
char *newbase = NULL;
if (size > mem->size - mem->cur_offset)
{
if (mem->grow)
{
newmemsize = mem->size;
if (size < IOMEM_BUFFERSIZE)
newmemsize += IOMEM_BUFFERSIZE;
else
newmemsize += size;
newbase = (char *)malloc(newmemsize);
memcpy(newbase, mem->base, mem->size);
free(mem->base);
mem->base = newbase;
mem->size = newmemsize;
}
else
size = mem->size - mem->cur_offset;
}
memcpy(mem->base + mem->cur_offset, buf, size);
mem->cur_offset += size;
if (mem->cur_offset > mem->limit)
mem->limit = mem->cur_offset;
return size;
}
long ZCALLBACK ftell_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream)
{
ourmemory_t *mem = (ourmemory_t *)stream;
return mem->cur_offset;
}
long ZCALLBACK fseek_mem_func(ZIP_UNUSED voidpf opaque, voidpf stream, uint32_t offset, int origin)
{
ourmemory_t *mem = (ourmemory_t *)stream;
uint32_t new_pos = 0;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR:
new_pos = mem->cur_offset + offset;
break;
case ZLIB_FILEFUNC_SEEK_END:
new_pos = mem->limit + offset;
break;
case ZLIB_FILEFUNC_SEEK_SET:
new_pos = offset;
break;
default:
return -1;
}
if (new_pos > mem->size)
return 1; /* Failed to seek that far */
mem->cur_offset = new_pos;
return 0;
}
int ZCALLBACK fclose_mem_func(ZIP_UNUSED voidpf opaque, ZIP_UNUSED voidpf stream)
{
/* Even with grow = 1, caller must always free() memory */
return 0;
}
int ZCALLBACK ferror_mem_func(ZIP_UNUSED voidpf opaque, ZIP_UNUSED voidpf stream)
{
/* We never return errors */
return 0;
}
void fill_memory_filefunc(zlib_filefunc_def *pzlib_filefunc_def, ourmemory_t *ourmem)
{
pzlib_filefunc_def->zopen_file = fopen_mem_func;
pzlib_filefunc_def->zopendisk_file = fopendisk_mem_func;
pzlib_filefunc_def->zread_file = fread_mem_func;
pzlib_filefunc_def->zwrite_file = fwrite_mem_func;
pzlib_filefunc_def->ztell_file = ftell_mem_func;
pzlib_filefunc_def->zseek_file = fseek_mem_func;
pzlib_filefunc_def->zclose_file = fclose_mem_func;
pzlib_filefunc_def->zerror_file = ferror_mem_func;
pzlib_filefunc_def->opaque = ourmem;
}

View File

@@ -1,52 +0,0 @@
/* ioapi_mem.h -- IO base function header for compress/uncompress .zip
files using zlib + zip or unzip API
This version of ioapi is designed to access memory rather than files.
We do use a region of memory to put data in to and take it out of.
Copyright (C) 2012-2017 Nathan Moinvaziri (https://github.com/nmoinvaz/minizip)
(C) 2003 Justin Fletcher
(C) 1998-2003 Gilles Vollant
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 _IOAPI_MEM_H
#define _IOAPI_MEM_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zlib.h"
#include "ioapi.h"
#ifdef __cplusplus
extern "C" {
#endif
voidpf ZCALLBACK fopen_mem_func(voidpf opaque, const char* filename, int mode);
voidpf ZCALLBACK fopendisk_mem_func(voidpf opaque, voidpf stream, uint32_t number_disk, int mode);
uint32_t ZCALLBACK fread_mem_func(voidpf opaque, voidpf stream, void* buf, uint32_t size);
uint32_t ZCALLBACK fwrite_mem_func(voidpf opaque, voidpf stream, const void* buf, uint32_t size);
long ZCALLBACK ftell_mem_func(voidpf opaque, voidpf stream);
long ZCALLBACK fseek_mem_func(voidpf opaque, voidpf stream, uint32_t offset, int origin);
int ZCALLBACK fclose_mem_func(voidpf opaque, voidpf stream);
int ZCALLBACK ferror_mem_func(voidpf opaque, voidpf stream);
typedef struct ourmemory_s {
char *base; /* Base of the region of memory we're using */
uint32_t size; /* Size of the region of memory we're using */
uint32_t limit; /* Furthest we've written */
uint32_t cur_offset; /* Current offset in the area */
int grow; /* Growable memory buffer */
} ourmemory_t;
void fill_memory_filefunc(zlib_filefunc_def* pzlib_filefunc_def, ourmemory_t *ourmem);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,292 +0,0 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include "zlib.h"
#include "ioapi.h"
#ifdef _WIN32
# include <direct.h>
# include <io.h>
#else
# include <unistd.h>
# include <utime.h>
# include <sys/types.h>
# include <sys/stat.h>
#endif
#include "minishared.h"
#ifdef _WIN32
# define USEWIN32IOAPI
# include "iowin32.h"
#endif
uint32_t get_file_date(const char *path, uint32_t *dos_date)
{
int ret = 0;
#ifdef _WIN32
FILETIME ftm_local;
HANDLE find = NULL;
WIN32_FIND_DATAA ff32;
find = FindFirstFileA(path, &ff32);
if (find != INVALID_HANDLE_VALUE)
{
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime), &ftm_local);
FileTimeToDosDateTime(&ftm_local, ((LPWORD)dos_date) + 1, ((LPWORD)dos_date) + 0);
FindClose(find);
ret = 1;
}
#else
struct stat s;
struct tm *filedate = NULL;
time_t tm_t = 0;
memset(&s, 0, sizeof(s));
if (strcmp(path, "-") != 0)
{
size_t len = strlen(path);
char *name = (char *)malloc(len + 1);
strncpy(name, path, len + 1);
name[len] = 0;
if (name[len - 1] == '/')
name[len - 1] = 0;
/* Not all systems allow stat'ing a file with / appended */
if (stat(name, &s) == 0)
{
tm_t = s.st_mtime;
ret = 1;
}
free(name);
}
filedate = localtime(&tm_t);
*dos_date = tm_to_dosdate(filedate);
#endif
return ret;
}
void change_file_date(const char *path, uint32_t dos_date)
{
#ifdef _WIN32
HANDLE handle = NULL;
FILETIME ftm, ftm_local, ftm_create, ftm_access, ftm_modified;
handle = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (handle != INVALID_HANDLE_VALUE)
{
GetFileTime(handle, &ftm_create, &ftm_access, &ftm_modified);
DosDateTimeToFileTime((WORD)(dos_date >> 16), (WORD)dos_date, &ftm_local);
LocalFileTimeToFileTime(&ftm_local, &ftm);
SetFileTime(handle, &ftm, &ftm_access, &ftm);
CloseHandle(handle);
}
#else
struct utimbuf ut;
ut.actime = ut.modtime = dosdate_to_time_t(dos_date);
utime(path, &ut);
#endif
}
int invalid_date(const struct tm *ptm)
{
#define datevalue_in_range(min, max, value) ((min) <= (value) && (value) <= (max))
return (!datevalue_in_range(0, 207, ptm->tm_year) ||
!datevalue_in_range(0, 11, ptm->tm_mon) ||
!datevalue_in_range(1, 31, ptm->tm_mday) ||
!datevalue_in_range(0, 23, ptm->tm_hour) ||
!datevalue_in_range(0, 59, ptm->tm_min) ||
!datevalue_in_range(0, 59, ptm->tm_sec));
#undef datevalue_in_range
}
// Conversion without validation
void dosdate_to_raw_tm(uint64_t dos_date, struct tm *ptm)
{
uint64_t date = (uint64_t)(dos_date >> 16);
ptm->tm_mday = (uint16_t)(date & 0x1f);
ptm->tm_mon = (uint16_t)(((date & 0x1E0) / 0x20) - 1);
ptm->tm_year = (uint16_t)(((date & 0x0FE00) / 0x0200) + 80);
ptm->tm_hour = (uint16_t)((dos_date & 0xF800) / 0x800);
ptm->tm_min = (uint16_t)((dos_date & 0x7E0) / 0x20);
ptm->tm_sec = (uint16_t)(2 * (dos_date & 0x1f));
ptm->tm_isdst = -1;
}
int dosdate_to_tm(uint64_t dos_date, struct tm *ptm)
{
dosdate_to_raw_tm(dos_date, ptm);
if (invalid_date(ptm))
{
// Invalid date stored, so don't return it.
memset(ptm, 0, sizeof(struct tm));
return -1;
}
return 0;
}
time_t dosdate_to_time_t(uint64_t dos_date)
{
struct tm ptm;
dosdate_to_raw_tm(dos_date, &ptm);
return mktime(&ptm);
}
uint32_t tm_to_dosdate(const struct tm *ptm)
{
struct tm fixed_tm;
/* Years supported:
* [00, 79] (assumed to be between 2000 and 2079)
* [80, 207] (assumed to be between 1980 and 2107, typical output of old
software that does 'year-1900' to get a double digit year)
* [1980, 2107] (due to the date format limitations, only years between 1980 and 2107 can be stored.)
*/
memcpy(&fixed_tm, ptm, sizeof(struct tm));
if (fixed_tm.tm_year >= 1980) /* range [1980, 2107] */
fixed_tm.tm_year -= 1980;
else if (fixed_tm.tm_year >= 80) /* range [80, 99] */
fixed_tm.tm_year -= 80;
else /* range [00, 79] */
fixed_tm.tm_year += 20;
if (invalid_date(ptm))
return 0;
return (uint32_t)(((fixed_tm.tm_mday) + (32 * (fixed_tm.tm_mon + 1)) + (512 * fixed_tm.tm_year)) << 16) |
((fixed_tm.tm_sec / 2) + (32 * fixed_tm.tm_min) + (2048 * (uint32_t)fixed_tm.tm_hour));
}
int makedir(const char *newdir)
{
char *buffer = NULL;
char *p = NULL;
int len = (int)strlen(newdir);
if (len <= 0)
return 0;
buffer = (char*)malloc(len + 1);
if (buffer == NULL)
{
printf("Error allocating memory\n");
return -1;
}
strcpy(buffer, newdir);
if (buffer[len - 1] == '/')
buffer[len - 1] = 0;
if (MKDIR(buffer) == 0)
{
free(buffer);
return 1;
}
p = buffer + 1;
while (1)
{
char hold;
while (*p && *p != '\\' && *p != '/')
p++;
hold = *p;
*p = 0;
if ((MKDIR(buffer) == -1) && (errno == ENOENT))
{
printf("couldn't create directory %s (%d)\n", buffer, errno);
free(buffer);
return 0;
}
if (hold == 0)
break;
*p++ = hold;
}
free(buffer);
return 1;
}
FILE *get_file_handle(const char *path)
{
FILE *handle = NULL;
#if defined(WIN32)
wchar_t *pathWide = NULL;
int pathLength = 0;
pathLength = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0) + 1;
pathWide = (wchar_t*)calloc(pathLength, sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, path, -1, pathWide, pathLength);
handle = _wfopen((const wchar_t*)pathWide, L"rb");
free(pathWide);
#else
handle = fopen64(path, "rb");
#endif
return handle;
}
int check_file_exists(const char *path)
{
FILE *handle = get_file_handle(path);
if (handle == NULL)
return 0;
fclose(handle);
return 1;
}
int is_large_file(const char *path)
{
FILE* handle = NULL;
uint64_t pos = 0;
handle = get_file_handle(path);
if (handle == NULL)
return 0;
fseeko64(handle, 0, SEEK_END);
pos = ftello64(handle);
fclose(handle);
printf("file : %s is %lld bytes\n", path, pos);
return (pos >= UINT32_MAX);
}
void display_zpos64(uint64_t n, int size_char)
{
/* To avoid compatibility problem we do here the conversion */
char number[21] = { 0 };
int offset = 19;
int pos_string = 19;
int size_display_string = 19;
while (1)
{
number[offset] = (char)((n % 10) + '0');
if (number[offset] != '0')
pos_string = offset;
n /= 10;
if (offset == 0)
break;
offset--;
}
size_display_string -= pos_string;
while (size_char-- > size_display_string)
printf(" ");
printf("%s", &number[pos_string]);
}

View File

@@ -1,51 +0,0 @@
#ifndef _MINISHARED_H
#define _MINISHARED_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
# define MKDIR(d) _mkdir(d)
# define CHDIR(d) _chdir(d)
#else
# define MKDIR(d) mkdir(d, 0775)
# define CHDIR(d) chdir(d)
#endif
/***************************************************************************/
/* Get a file's date and time in dos format */
uint32_t get_file_date(const char *path, uint32_t *dos_date);
/* Sets a file's date and time in dos format */
void change_file_date(const char *path, uint32_t dos_date);
/* Convert dos date/time format to struct tm */
int dosdate_to_tm(uint64_t dos_date, struct tm *ptm);
/* Convert dos date/time format to time_t */
time_t dosdate_to_time_t(uint64_t dos_date);
/* Convert struct tm to dos date/time format */
uint32_t tm_to_dosdate(const struct tm *ptm);
/* Create a directory and all subdirectories */
int makedir(const char *newdir);
/* Check to see if a file exists */
int check_file_exists(const char *path);
/* Check to see if a file is over 4GB and needs ZIP64 extension */
int is_large_file(const char *path);
/* Print a 64-bit number for compatibility */
void display_zpos64(uint64_t n, int size_char);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* _MINISHARED_H */

View File

@@ -0,0 +1,40 @@
/* mz_error.h -- List of function return codes
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2010 Gilles Vollant
http://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_ERROR_H
#define _MZ_ERROR_H
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
#define MZ_OK (0)
#define MZ_EOF (MZ_OK)
#define MZ_STREAM_ERROR (-1)
#define MZ_END_OF_LIST (-100)
#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)
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,133 @@
/* mz_os.c -- System functions
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include "mz_error.h"
#include "mz_strm.h"
#include "mz_os.h"
/***************************************************************************/
int32_t mz_os_file_exists(const char *path)
{
void *stream = NULL;
int opened = 0;
mz_stream_os_create(&stream);
if (mz_stream_os_open(stream, path, MZ_STREAM_MODE_READ) == MZ_OK)
{
mz_stream_os_close(stream);
opened = 1;
}
mz_stream_os_delete(&stream);
return opened;
}
int64_t mz_os_file_get_size(const char *path)
{
void *stream = NULL;
int64_t size = 0;
mz_stream_os_create(&stream);
if (mz_stream_os_open(stream, path, MZ_STREAM_MODE_READ) == MZ_OK)
{
mz_stream_os_seek(stream, 0, MZ_STREAM_SEEK_END);
size = mz_stream_os_tell(stream);
mz_stream_os_close(stream);
}
mz_stream_os_delete(&stream);
return size;
}
/***************************************************************************/
int mz_invalid_date(const struct tm *ptm)
{
#define datevalue_in_range(min, max, value) ((min) <= (value) && (value) <= (max))
return (!datevalue_in_range(0, 207, ptm->tm_year) ||
!datevalue_in_range(0, 11, ptm->tm_mon) ||
!datevalue_in_range(1, 31, ptm->tm_mday) ||
!datevalue_in_range(0, 23, ptm->tm_hour) ||
!datevalue_in_range(0, 59, ptm->tm_min) ||
!datevalue_in_range(0, 59, ptm->tm_sec));
#undef datevalue_in_range
}
// Conversion without validation
void mz_dosdate_to_raw_tm(uint64_t dos_date, struct tm *ptm)
{
uint64_t date = (uint64_t)(dos_date >> 16);
ptm->tm_mday = (uint16_t)(date & 0x1f);
ptm->tm_mon = (uint16_t)(((date & 0x1E0) / 0x20) - 1);
ptm->tm_year = (uint16_t)(((date & 0x0FE00) / 0x0200) + 80);
ptm->tm_hour = (uint16_t)((dos_date & 0xF800) / 0x800);
ptm->tm_min = (uint16_t)((dos_date & 0x7E0) / 0x20);
ptm->tm_sec = (uint16_t)(2 * (dos_date & 0x1f));
ptm->tm_isdst = -1;
}
int32_t mz_dosdate_to_tm(uint64_t dos_date, struct tm *ptm)
{
mz_dosdate_to_raw_tm(dos_date, ptm);
if (mz_invalid_date(ptm))
{
// Invalid date stored, so don't return it.
memset(ptm, 0, sizeof(struct tm));
return -1;
}
return 0;
}
time_t mz_dosdate_to_time_t(uint64_t dos_date)
{
struct tm ptm;
mz_dosdate_to_raw_tm(dos_date, &ptm);
return mktime(&ptm);
}
uint32_t mz_tm_to_dosdate(const struct tm *ptm)
{
struct tm fixed_tm = { 0 };
// Years supported:
// [00, 79] (assumed to be between 2000 and 2079)
// [80, 207] (assumed to be between 1980 and 2107, typical output of old
// software that does 'year-1900' to get a double digit year)
// [1980, 2107] (due to the date format limitations, only years between 1980 and 2107 can be stored.)
memcpy(&fixed_tm, ptm, sizeof(struct tm));
if (fixed_tm.tm_year >= 1980) // range [1980, 2107]
fixed_tm.tm_year -= 1980;
else if (fixed_tm.tm_year >= 80) // range [80, 99]
fixed_tm.tm_year -= 80;
else // range [00, 79]
fixed_tm.tm_year += 20;
if (mz_invalid_date(ptm))
return 0;
return (uint32_t)(((fixed_tm.tm_mday) + (32 * (fixed_tm.tm_mon + 1)) + (512 * fixed_tm.tm_year)) << 16) |
((fixed_tm.tm_sec / 2) + (32 * fixed_tm.tm_min) + (2048 * (uint32_t)fixed_tm.tm_hour));
}

View File

@@ -0,0 +1,51 @@
/* mz_os.h -- System functions
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_OS_H
#define _MZ_OS_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
#if !defined(_WIN32) && !defined(USEWIN32IOAPI)
#include "mz_os_posix.h"
#include "mz_strm_posix.h"
#else
#include "mz_os_win32.h"
#include "mz_strm_win32.h"
#endif
/***************************************************************************/
int32_t mz_os_file_exists(const char *path);
int64_t mz_os_file_get_size(const char *path);
/***************************************************************************/
int32_t mz_dosdate_to_tm(uint64_t dos_date, struct tm *ptm);
// Convert dos date/time format to struct tm
time_t mz_dosdate_to_time_t(uint64_t dos_date);
// Convert dos date/time format to time_t
uint32_t mz_tm_to_dosdate(const struct tm *ptm);
// Convert struct tm to dos date/time format
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,164 @@
/* mz_os_posix.c -- System functions for posix
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#if defined unix || defined __APPLE__
# include <unistd.h>
# include <utime.h>
# include <fcntl.h>
#endif
#include "mz_error.h"
#include "mz_strm.h"
#include "mz_os.h"
#include "mz_os_posix.h"
/***************************************************************************/
#ifndef ZCR_SEED2
# define ZCR_SEED2 3141592654UL // use PI as default pattern
#endif
/***************************************************************************/
int32_t mz_posix_rand(uint8_t *buf, int32_t size)
{
static unsigned calls = 0;
void *rand_stream = NULL;
int32_t len = 0;
if (mz_stream_posix_create(&rand_stream) == NULL)
return 0;
if (mz_stream_posix_open(rand_stream, "/dev/urandom", MZ_STREAM_MODE_READ) == MZ_OK)
{
len = mz_stream_posix_read(rand_stream, buf, size);
mz_stream_posix_close(rand_stream);
}
mz_stream_posix_delete(&rand_stream);
if (len < (int)size)
{
// Ensure different random header each time
if (++calls == 1)
srand((unsigned)(time(NULL) ^ ZCR_SEED2));
while (len < (int)size)
buf[len++] = (rand() >> 7) & 0xff;
}
return len;
}
int16_t mz_posix_get_file_date(const char *path, uint32_t *dos_date)
{
struct stat stat_info;
struct tm *filedate = NULL;
time_t tm_t = 0;
int16_t err = MZ_INTERNAL_ERROR;
memset(&stat_info, 0, sizeof(stat_info));
if (strcmp(path, "-") != 0)
{
size_t len = strlen(path);
char *name = (char *)malloc(len + 1);
strncpy(name, path, len + 1);
name[len] = 0;
if (name[len - 1] == '/')
name[len - 1] = 0;
/* Not all systems allow stat'ing a file with / appended */
if (stat(name, &stat_info) == 0)
{
tm_t = stat_info.st_mtime;
err = MZ_OK;
}
free(name);
}
filedate = localtime(&tm_t);
*dos_date = mz_tm_to_dosdate(filedate);
return err;
}
int16_t mz_posix_set_file_date(const char *path, uint32_t dos_date)
{
struct utimbuf ut;
ut.actime = mz_dosdate_to_time_t(dos_date);
ut.modtime = mz_dosdate_to_time_t(dos_date);
if (utime(path, &ut) != 0)
return MZ_INTERNAL_ERROR;
return MZ_OK;
}
int16_t mz_posix_change_dir(const char *path)
{
if (chdir(path) != 0)
return MZ_INTERNAL_ERROR;
return MZ_OK;
}
int16_t mz_posix_make_dir(const char *path)
{
int16_t err = 0;
err = mkdir(path, 0755);
if (err != 0 && errno != EEXIST)
return MZ_INTERNAL_ERROR;
return MZ_OK;
}
DIR* mz_posix_open_dir(const char *path)
{
return opendir(path);
}
struct dirent* mz_posix_read_dir(DIR *dir)
{
if (dir == NULL)
return NULL;
return readdir(dir);
}
int32_t mz_posix_close_dir(DIR *dir)
{
if (dir == NULL)
return MZ_PARAM_ERROR;
if (closedir(dir) == -1)
return MZ_INTERNAL_ERROR;
return MZ_OK;
}
int32_t mz_posix_is_dir(const char *path)
{
struct stat path_stat;
stat(path, &path_stat);
if (S_ISREG(path_stat.st_mode))
return MZ_OK;
return MZ_EXIST_ERROR;
}

View File

@@ -0,0 +1,61 @@
/* mz_os_posix.h -- System functions for posix
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_OS_POSIX_H
#define _MZ_OS_POSIX_H
#include <stdint.h>
#include <dirent.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
#if defined(__APPLE__)
#define MZ_VERSION_MADEBY (19)
#elif defined(unix)
#define MZ_VERSION_MADEBY (3)
#endif
/***************************************************************************/
int32_t mz_posix_rand(uint8_t *buf, int32_t size);
int16_t mz_posix_get_file_date(const char *path, uint32_t *dos_date);
int16_t mz_posix_set_file_date(const char *path, uint32_t dos_date);
int16_t mz_posix_change_dir(const char *path);
int16_t mz_posix_make_dir(const char *path);
DIR* mz_posix_open_dir(const char *path);
struct
dirent* mz_posix_read_dir(DIR *dir);
int32_t mz_posix_close_dir(DIR *dir);
int32_t mz_posix_is_dir(const char *path);
/***************************************************************************/
#define mz_os_rand mz_posix_rand
#define mz_os_get_file_date mz_posix_get_file_date
#define mz_os_set_file_date mz_posix_set_file_date
#define mz_os_change_dir mz_posix_change_dir
#define mz_os_make_dir mz_posix_make_dir
#define mz_os_open_dir mz_posix_open_dir
#define mz_os_read_dir mz_posix_read_dir
#define mz_os_close_dir mz_posix_close_dir
#define mz_os_is_dir mz_posix_is_dir
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

403
SSZipArchive/minizip/mz_strm.c Executable file
View File

@@ -0,0 +1,403 @@
/* mz_strm.c -- Stream interface
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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 <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include "mz_error.h"
#include "mz_strm.h"
/***************************************************************************/
int32_t mz_stream_open(void *stream, const char *path, int32_t mode)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->open == NULL)
return MZ_STREAM_ERROR;
return strm->open(strm, path, mode);
}
int32_t mz_stream_is_open(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->is_open == NULL)
return MZ_STREAM_ERROR;
return strm->is_open(strm);
}
int32_t mz_stream_read(void *stream, void *buf, int32_t size)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->read == NULL)
return MZ_STREAM_ERROR;
if (strm->is_open != NULL && strm->is_open(strm) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->read(strm, buf, size);
}
int32_t mz_stream_read_uint8(void *stream, uint8_t *value)
{
uint8_t c = 0;
if (mz_stream_read(stream, &c, 1) == 1)
*value = (uint8_t)c;
else if (mz_stream_error(stream))
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_read_uint16(void *stream, uint16_t *value)
{
uint8_t c = 0;
*value = 0;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value = (uint16_t)c;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint16_t)c) << 8;
return MZ_OK;
}
int32_t mz_stream_read_uint32(void *stream, uint32_t *value)
{
uint8_t c = 0;
*value = 0;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value = (uint32_t)c;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint32_t)c) << 8;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint32_t)c) << 16;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint32_t)c) << 24;
return MZ_OK;
}
int32_t mz_stream_read_uint64(void *stream, uint64_t *value)
{
uint8_t c = 0;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value = (uint64_t)c;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint64_t)c) << 8;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint64_t)c) << 16;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint64_t)c) << 24;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint64_t)c) << 32;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint64_t)c) << 40;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint64_t)c) << 48;
if (mz_stream_read_uint8(stream, &c) != MZ_OK)
return MZ_STREAM_ERROR;
*value += ((uint64_t)c) << 56;
return MZ_OK;
}
int32_t mz_stream_write(void *stream, const void *buf, int32_t size)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->write == NULL)
return MZ_STREAM_ERROR;
if (size == 0)
return size;
if (strm->is_open != NULL && strm->is_open(strm) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->write(strm, buf, size);
}
static int32_t mz_stream_write_value(void *stream, uint64_t value, uint32_t len)
{
uint8_t buf[8];
uint32_t n = 0;
for (n = 0; n < len; n++)
{
buf[n] = (uint8_t)(value & 0xff);
value >>= 8;
}
if (value != 0)
{
// Data overflow - hack for ZIP64 (X Roche)
for (n = 0; n < len; n++)
buf[n] = 0xff;
}
if (mz_stream_write(stream, buf, len) != len)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_write_uint8(void *stream, uint8_t value)
{
return mz_stream_write_value(stream, value, sizeof(uint8_t));
}
int32_t mz_stream_write_uint16(void *stream, uint16_t value)
{
return mz_stream_write_value(stream, value, sizeof(uint16_t));
}
int32_t mz_stream_write_uint32(void *stream, uint32_t value)
{
return mz_stream_write_value(stream, value, sizeof(uint32_t));
}
int32_t mz_stream_write_uint64(void *stream, uint64_t value)
{
return mz_stream_write_value(stream, value, sizeof(uint64_t));
}
int32_t mz_stream_copy(void *target, void *source, int32_t len)
{
uint8_t buf[UINT16_MAX];
int32_t bytes_to_copy = 0;
int32_t read = 0;
int32_t written = 0;
while (len > 0)
{
bytes_to_copy = len;
if (bytes_to_copy > UINT16_MAX)
bytes_to_copy = UINT16_MAX;
read = mz_stream_read(source, buf, bytes_to_copy);
if (read < 0)
return MZ_STREAM_ERROR;
written = mz_stream_write(target, buf, read);
if (written != read)
return MZ_STREAM_ERROR;
len -= read;
}
return MZ_OK;
}
int64_t mz_stream_tell(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->tell == NULL)
return MZ_STREAM_ERROR;
if (strm->is_open != NULL && strm->is_open(strm) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->tell(strm);
}
int32_t mz_stream_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->seek == NULL)
return MZ_STREAM_ERROR;
if (strm->is_open != NULL && strm->is_open(strm) != MZ_OK)
return MZ_STREAM_ERROR;
return strm->seek(strm, offset, origin);
}
int32_t mz_stream_close(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->close == NULL)
return MZ_STREAM_ERROR;
return strm->close(strm);
}
int32_t mz_stream_error(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm == NULL || strm->error == NULL)
return MZ_STREAM_ERROR;
return strm->error(strm);
}
int32_t mz_stream_set_base(void *stream, void *base)
{
mz_stream *strm = (mz_stream *)stream;
strm->base = (mz_stream *)base;
return MZ_OK;
}
int64_t mz_stream_get_total_in(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm->get_total_in == NULL)
return MZ_STREAM_ERROR;
return strm->get_total_in(stream);
}
int64_t mz_stream_get_total_out(void *stream)
{
mz_stream *strm = (mz_stream *)stream;
if (strm->get_total_out == NULL)
return MZ_STREAM_ERROR;
return strm->get_total_out(stream);
}
void *mz_stream_create(void **stream)
{
mz_stream *strm = NULL;
if (stream == NULL)
return NULL;
strm = (mz_stream *)*stream;
return strm->create(stream);
}
void mz_stream_delete(void **stream)
{
mz_stream *strm = NULL;
if (stream == NULL)
return;
strm = (mz_stream *)*stream;
strm->delete(stream);
*stream = NULL;
}
/***************************************************************************/
typedef struct mz_stream_passthru_s {
mz_stream stream;
int64_t total_in;
int64_t total_out;
} mz_stream_passthru;
/***************************************************************************/
int32_t mz_stream_passthru_open(void *stream, const char *path, int32_t mode)
{
return MZ_OK;
}
int32_t mz_stream_passthru_is_open(void *stream)
{
mz_stream_passthru *passthru = (mz_stream_passthru *)stream;
return mz_stream_is_open(passthru->stream.base);
}
int32_t mz_stream_passthru_read(void *stream, void *buf, int32_t size)
{
mz_stream_passthru *passthru = (mz_stream_passthru *)stream;
int32_t read = mz_stream_read(passthru->stream.base, buf, size);
if (read > 0)
passthru->total_in += read;
return read;
}
int32_t mz_stream_passthru_write(void *stream, const void *buf, int32_t size)
{
mz_stream_passthru *passthru = (mz_stream_passthru *)stream;
int32_t written = mz_stream_write(passthru->stream.base, buf, size);
if (written > 0)
passthru->total_out += written;
return written;
}
int64_t mz_stream_passthru_tell(void *stream)
{
mz_stream_passthru *passthru = (mz_stream_passthru *)stream;
return mz_stream_tell(passthru->stream.base);
}
int32_t mz_stream_passthru_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_passthru *passthru = (mz_stream_passthru *)stream;
return mz_stream_seek(passthru->stream.base, offset, origin);
}
int32_t mz_stream_passthru_close(void *stream)
{
return MZ_OK;
}
int32_t mz_stream_passthru_error(void *stream)
{
mz_stream_passthru *passthru = (mz_stream_passthru *)stream;
return mz_stream_error(passthru->stream.base);
}
int64_t mz_stream_passthru_get_total_in(void *stream)
{
mz_stream_passthru *passthru = (mz_stream_passthru *)stream;
return passthru->total_in;
}
int64_t mz_stream_passthru_get_total_out(void *stream)
{
mz_stream_passthru *passthru = (mz_stream_passthru *)stream;
return passthru->total_out;
}
void *mz_stream_passthru_create(void **stream)
{
mz_stream_passthru *passthru = NULL;
passthru = (mz_stream_passthru *)malloc(sizeof(mz_stream_passthru));
if (passthru != NULL)
{
memset(passthru, 0, sizeof(mz_stream_passthru));
passthru->stream.open = mz_stream_passthru_open;
passthru->stream.is_open = mz_stream_passthru_is_open;
passthru->stream.read = mz_stream_passthru_read;
passthru->stream.write = mz_stream_passthru_write;
passthru->stream.tell = mz_stream_passthru_tell;
passthru->stream.seek = mz_stream_passthru_seek;
passthru->stream.close = mz_stream_passthru_close;
passthru->stream.error = mz_stream_passthru_error;
passthru->stream.create = mz_stream_passthru_create;
passthru->stream.delete = mz_stream_passthru_delete;
passthru->stream.get_total_in = mz_stream_passthru_get_total_in;
passthru->stream.get_total_out = mz_stream_passthru_get_total_out;
}
if (stream != NULL)
*stream = passthru;
return passthru;
}
void mz_stream_passthru_delete(void **stream)
{
mz_stream_passthru *passthru = NULL;
if (stream == NULL)
return;
passthru = (mz_stream_passthru *)*stream;
if (passthru != NULL)
free(passthru);
*stream = NULL;
}

109
SSZipArchive/minizip/mz_strm.h Executable file
View File

@@ -0,0 +1,109 @@
/* mz_strm.h -- Stream interface
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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_STREAM_H
#define _MZ_STREAM_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
#define MZ_STREAM_SEEK_CUR (1)
#define MZ_STREAM_SEEK_END (2)
#define MZ_STREAM_SEEK_SET (0)
#define MZ_STREAM_MODE_READ (0x01)
#define MZ_STREAM_MODE_WRITE (0x02)
#define MZ_STREAM_MODE_READWRITE (MZ_STREAM_MODE_READ | MZ_STREAM_MODE_WRITE)
#define MZ_STREAM_MODE_APPEND (0x04)
#define MZ_STREAM_MODE_CREATE (0x08)
#define MZ_STREAM_MODE_EXISTING (0x10)
/***************************************************************************/
typedef int32_t (*mz_stream_open_cb) (void *stream, const char *path, int32_t mode);
typedef int32_t (*mz_stream_is_open_cb) (void *stream);
typedef int32_t (*mz_stream_read_cb) (void *stream, void *buf, int32_t size);
typedef int32_t (*mz_stream_write_cb) (void *stream, const void *buf, int32_t size);
typedef int64_t (*mz_stream_tell_cb) (void *stream);
typedef int32_t (*mz_stream_seek_cb) (void *stream, int64_t offset, int32_t origin);
typedef int32_t (*mz_stream_close_cb) (void *stream);
typedef int32_t (*mz_stream_error_cb) (void *stream);
typedef void* (*mz_stream_create_cb) (void **stream);
typedef void (*mz_stream_delete_cb) (void **stream);
typedef int64_t (*mz_stream_get_total_in_cb) (void *stream);
typedef int64_t (*mz_stream_get_total_out_cb) (void *stream);
/***************************************************************************/
typedef struct mz_stream_s
{
struct mz_stream_s *base;
mz_stream_open_cb open;
mz_stream_is_open_cb is_open;
mz_stream_read_cb read;
mz_stream_write_cb write;
mz_stream_tell_cb tell;
mz_stream_seek_cb seek;
mz_stream_close_cb close;
mz_stream_error_cb error;
mz_stream_create_cb create;
mz_stream_delete_cb delete;
mz_stream_get_total_in_cb get_total_in;
mz_stream_get_total_out_cb get_total_out;
} mz_stream;
/***************************************************************************/
int32_t mz_stream_open(void *stream, const char *path, int32_t mode);
int32_t mz_stream_is_open(void *stream);
int32_t mz_stream_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_read_uint8(void *stream, uint8_t *value);
int32_t mz_stream_read_uint16(void *stream, uint16_t *value);
int32_t mz_stream_read_uint32(void *stream, uint32_t *value);
int32_t mz_stream_read_uint64(void *stream, uint64_t *value);
int32_t mz_stream_write(void *stream, const void *buf, int32_t size);
int32_t mz_stream_write_uint8(void *stream, uint8_t value);
int32_t mz_stream_write_uint16(void *stream, uint16_t value);
int32_t mz_stream_write_uint32(void *stream, uint32_t value);
int32_t mz_stream_write_uint64(void *stream, uint64_t value);
int32_t mz_stream_copy(void *target, void *source, int32_t len);
int64_t mz_stream_tell(void *stream);
int32_t mz_stream_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_close(void *stream);
int32_t mz_stream_error(void *stream);
int32_t mz_stream_set_base(void *stream, void *base);
int64_t mz_stream_get_total_in(void *stream);
int64_t mz_stream_get_total_out(void *stream);
void* mz_stream_create(void **stream);
void mz_stream_delete(void **stream);
void* mz_stream_passthru_create(void **stream);
void mz_stream_passthru_delete(void **stream);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,264 @@
/* mz_strm_aes.c -- Stream for WinZip AES encryption
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mz_error.h"
#include "mz_os.h"
#include "mz_strm.h"
#include "mz_strm_aes.h"
#include "aes/aes.h"
#include "aes/fileenc.h"
/***************************************************************************/
#define MZ_AES_PWVERIFYSIZE (2)
#define MZ_AES_AUTHCODESIZE (10)
#define MZ_AES_MAXSALTLENGTH (16)
/***************************************************************************/
typedef struct mz_stream_aes_s {
mz_stream stream;
fcrypt_ctx crypt_ctx;
int16_t mode;
int16_t initialized;
int16_t error;
int16_t encryption_mode;
const char *password;
int64_t total_in;
int64_t total_out;
uint8_t buffer[UINT16_MAX];
} mz_stream_aes;
/***************************************************************************/
int32_t mz_stream_aes_open(void *stream, const char *path, int32_t mode)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
uint16_t salt_length = 0;
uint8_t verify[MZ_AES_PWVERIFYSIZE];
uint8_t verify_expected[MZ_AES_PWVERIFYSIZE];
uint8_t salt_value[MZ_AES_MAXSALTLENGTH];
const char *password = path;
aes->total_in = 0;
aes->total_out = 0;
aes->initialized = 0;
if (mz_stream_is_open(aes->stream.base) != MZ_OK)
return MZ_STREAM_ERROR;
if (password == NULL)
password = aes->password;
if (password == NULL)
return MZ_STREAM_ERROR;
salt_length = SALT_LENGTH(aes->encryption_mode);
if (mode & MZ_STREAM_MODE_WRITE)
{
mz_os_rand(salt_value, salt_length);
if (fcrypt_init(aes->encryption_mode, (uint8_t *)password,
(uint32_t)strlen(password), salt_value, verify, &aes->crypt_ctx) != 0)
return MZ_STREAM_ERROR;
if (mz_stream_write(aes->stream.base, salt_value, salt_length) != salt_length)
return MZ_STREAM_ERROR;
aes->total_out += salt_length;
if (mz_stream_write(aes->stream.base, verify, MZ_AES_PWVERIFYSIZE) != MZ_AES_PWVERIFYSIZE)
return MZ_STREAM_ERROR;
aes->total_out += MZ_AES_PWVERIFYSIZE;
}
else if (mode & MZ_STREAM_MODE_READ)
{
if (mz_stream_read(aes->stream.base, salt_value, salt_length) != salt_length)
return MZ_STREAM_ERROR;
aes->total_in += salt_length;
if (mz_stream_read(aes->stream.base, verify_expected, MZ_AES_PWVERIFYSIZE) != MZ_AES_PWVERIFYSIZE)
return MZ_STREAM_ERROR;
aes->total_in += MZ_AES_PWVERIFYSIZE;
if (fcrypt_init(aes->encryption_mode, (uint8_t *)password,
(uint32_t)strlen(password), salt_value, verify, &aes->crypt_ctx) != 0)
return MZ_STREAM_ERROR;
if (memcmp(verify_expected, verify, MZ_AES_PWVERIFYSIZE) != 0)
return MZ_STREAM_ERROR;
}
aes->mode = mode;
aes->initialized = 1;
return MZ_OK;
}
int32_t mz_stream_aes_is_open(void *stream)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
if (aes->initialized == 0)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_aes_read(void *stream, void *buf, int32_t size)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
int32_t read = 0;
read = mz_stream_read(aes->stream.base, buf, size);
if (read > 0)
fcrypt_decrypt((uint8_t *)buf, read, &aes->crypt_ctx);
aes->total_in += read;
return read;
}
int32_t mz_stream_aes_write(void *stream, const void *buf, int32_t size)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
int32_t written = 0;
if (size > sizeof(aes->buffer))
return MZ_STREAM_ERROR;
memcpy(aes->buffer, buf, size);
fcrypt_encrypt((uint8_t *)aes->buffer, size, &aes->crypt_ctx);
written = mz_stream_write(aes->stream.base, aes->buffer, size);
if (written > 0)
aes->total_out += written;
return written;
}
int64_t mz_stream_aes_tell(void *stream)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
return mz_stream_tell(aes->stream.base);
}
int32_t mz_stream_aes_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
return mz_stream_seek(aes->stream.base, offset, origin);
}
int32_t mz_stream_aes_close(void *stream)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
unsigned char authcode[MZ_AES_AUTHCODESIZE];
unsigned char rauthcode[MZ_AES_AUTHCODESIZE];
if (aes->mode & MZ_STREAM_MODE_WRITE)
{
fcrypt_end(authcode, &aes->crypt_ctx);
if (mz_stream_write(aes->stream.base, authcode, MZ_AES_AUTHCODESIZE) != MZ_AES_AUTHCODESIZE)
return MZ_STREAM_ERROR;
aes->total_out += MZ_AES_AUTHCODESIZE;
}
else if (aes->mode & MZ_STREAM_MODE_READ)
{
if (mz_stream_read(aes->stream.base, authcode, MZ_AES_AUTHCODESIZE) != MZ_AES_AUTHCODESIZE)
return MZ_STREAM_ERROR;
aes->total_in += MZ_AES_AUTHCODESIZE;
if (fcrypt_end(rauthcode, &aes->crypt_ctx) != MZ_AES_AUTHCODESIZE)
return MZ_STREAM_ERROR;
if (memcmp(authcode, rauthcode, MZ_AES_AUTHCODESIZE) != 0)
return MZ_CRC_ERROR;
}
aes->initialized = 0;
return MZ_OK;
}
int32_t mz_stream_aes_error(void *stream)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
return aes->error;
}
void mz_stream_aes_set_password(void *stream, const char *password)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
aes->password = password;
}
void mz_stream_aes_set_encryption_mode(void *stream, int16_t encryption_mode)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
aes->encryption_mode = encryption_mode;
}
int64_t mz_stream_aes_get_total_in(void *stream)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
return aes->total_in;
}
int64_t mz_stream_aes_get_total_out(void *stream)
{
mz_stream_aes *aes = (mz_stream_aes *)stream;
return aes->total_out;
}
int32_t mz_stream_aes_get_footer_size(void *stream)
{
return MZ_AES_AUTHCODESIZE;
}
void *mz_stream_aes_create(void **stream)
{
mz_stream_aes *aes = NULL;
aes = (mz_stream_aes *)malloc(sizeof(mz_stream_aes));
if (aes != NULL)
{
memset(aes, 0, sizeof(mz_stream_aes));
aes->stream.open = mz_stream_aes_open;
aes->stream.is_open = mz_stream_aes_is_open;
aes->stream.read = mz_stream_aes_read;
aes->stream.write = mz_stream_aes_write;
aes->stream.tell = mz_stream_aes_tell;
aes->stream.seek = mz_stream_aes_seek;
aes->stream.close = mz_stream_aes_close;
aes->stream.error = mz_stream_aes_error;
aes->stream.create = mz_stream_aes_create;
aes->stream.delete = mz_stream_aes_delete;
aes->stream.get_total_in = mz_stream_aes_get_total_in;
aes->stream.get_total_out = mz_stream_aes_get_total_out;
aes->encryption_mode = MZ_AES_ENCRYPTIONMODE;
}
if (stream != NULL)
*stream = aes;
return aes;
}
void mz_stream_aes_delete(void **stream)
{
mz_stream_aes *aes = NULL;
if (stream == NULL)
return;
aes = (mz_stream_aes *)*stream;
if (aes != NULL)
free(aes);
*stream = NULL;
}

View File

@@ -0,0 +1,52 @@
/* mz_strm_aes.h -- Stream for WinZIP AES encryption
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_AES_H
#define _MZ_STREAM_AES_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
#define MZ_AES_METHOD (99)
#define MZ_AES_VERSION (0x0001)
#define MZ_AES_ENCRYPTIONMODE (0x03)
/***************************************************************************/
int32_t mz_stream_aes_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_aes_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_aes_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_aes_tell(void *stream);
int32_t mz_stream_aes_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_aes_close(void *stream);
int32_t mz_stream_aes_error(void *stream);
void mz_stream_aes_set_password(void *stream, const char *password);
void mz_stream_aes_set_encryption_mode(void *stream, int16_t encryption_mode);
int64_t mz_stream_aes_get_total_in(void *stream);
int64_t mz_stream_aes_get_total_out(void *stream);
int32_t mz_stream_aes_get_footer_size(void *stream);
void* mz_stream_aes_create(void **stream);
void mz_stream_aes_delete(void **stream);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,381 @@
/* mz_strm_buf.c -- Stream for buffering reads/writes
Version 2.0.0, October 4th, 2017
part of the MiniZip project
This version of ioapi is designed to buffer IO.
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "mz_error.h"
#include "mz_strm.h"
#include "mz_strm_buf.h"
/***************************************************************************/
#define MZ_BUF_BUFFERSIZE (UINT16_MAX)
#if 0
# define mz_stream_buffered_print(o,s,f,...) printf(o,s,f,__VA_ARGS__);
#else
# define mz_stream_buffered_print(o,s,f,...)
#endif
/***************************************************************************/
typedef struct mz_stream_buffered_s {
mz_stream stream;
char readbuf[MZ_BUF_BUFFERSIZE];
uint32_t readbuf_len;
uint32_t readbuf_pos;
uint32_t readbuf_hits;
uint32_t readbuf_misses;
char writebuf[MZ_BUF_BUFFERSIZE];
uint32_t writebuf_len;
uint32_t writebuf_pos;
uint32_t writebuf_hits;
uint32_t writebuf_misses;
uint64_t position;
int32_t error;
} mz_stream_buffered;
/***************************************************************************/
int32_t mz_stream_buffered_open(void *stream, const char *path, int32_t mode)
{
//mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
//mz_stream_buffered_print(opaque, buffered, "open [num %d mode %d]\n", number_disk, mode);
return mz_stream_open(stream, path, mode);
}
int32_t mz_stream_buffered_flush(void *stream, uint32_t *written)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
uint32_t total_bytes_written = 0;
uint32_t bytes_to_write = buffered->writebuf_len;
uint32_t bytes_left_to_write = buffered->writebuf_len;
uint32_t bytes_written = 0;
*written = 0;
while (bytes_left_to_write > 0)
{
bytes_written = mz_stream_write(buffered->stream.base, buffered->writebuf + (bytes_to_write - bytes_left_to_write), bytes_left_to_write);
if (bytes_written != bytes_left_to_write)
return MZ_STREAM_ERROR;
buffered->writebuf_misses += 1;
mz_stream_buffered_print(opaque, stream, "write flush [%d:%d len %d]\n",
bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
total_bytes_written += bytes_written;
bytes_left_to_write -= bytes_written;
buffered->position += bytes_written;
}
buffered->writebuf_len = 0;
buffered->writebuf_pos = 0;
*written = total_bytes_written;
return MZ_OK;
}
int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
uint32_t buf_len = 0;
uint32_t bytes_to_read = 0;
uint32_t bytes_to_copy = 0;
uint32_t bytes_left_to_read = size;
uint32_t bytes_read = 0;
mz_stream_buffered_print(opaque, stream, "read [size %ld pos %lld]\n", size, buffered->position);
if (buffered->writebuf_len > 0)
mz_stream_buffered_print(opaque, stream, "switch from write to read, not yet supported [%lld]\n", buffered->position);
while (bytes_left_to_read > 0)
{
if ((buffered->readbuf_len == 0) || (buffered->readbuf_pos == buffered->readbuf_len))
{
if (buffered->readbuf_len == MZ_BUF_BUFFERSIZE)
{
buffered->readbuf_pos = 0;
buffered->readbuf_len = 0;
}
bytes_to_read = MZ_BUF_BUFFERSIZE - (buffered->readbuf_len - buffered->readbuf_pos);
if (mz_stream_read(buffered->stream.base, buffered->readbuf + buffered->readbuf_pos, bytes_to_read) != bytes_to_read)
return 0;
buffered->readbuf_misses += 1;
buffered->readbuf_len += bytes_read;
buffered->position += bytes_read;
mz_stream_buffered_print(opaque, stream, "filled [read %d/%d buf %d:%d pos %lld]\n",
bytes_read, bytes_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
if (bytes_read == 0)
break;
}
if ((buffered->readbuf_len - buffered->readbuf_pos) > 0)
{
bytes_to_copy = (uint32_t)(buffered->readbuf_len - buffered->readbuf_pos);
if (bytes_to_copy > bytes_left_to_read)
bytes_to_copy = bytes_left_to_read;
memcpy((char *)buf + buf_len, buffered->readbuf + buffered->readbuf_pos, bytes_to_copy);
buf_len += bytes_to_copy;
bytes_left_to_read -= bytes_to_copy;
buffered->readbuf_hits += 1;
buffered->readbuf_pos += bytes_to_copy;
mz_stream_buffered_print(opaque, stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n",
bytes_to_copy, bytes_left_to_read, buffered->readbuf_pos, buffered->readbuf_len, buffered->position);
}
}
return size - bytes_left_to_read;
}
int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
uint32_t bytes_to_write = size;
uint32_t bytes_left_to_write = size;
uint32_t bytes_to_copy = 0;
uint32_t bytes_used = 0;
uint32_t bytes_flushed = 0;
mz_stream_buffered_print(opaque, stream, "write [size %ld len %d pos %lld]\n", size, buffered->writebuf_len, buffered->position);
if (buffered->readbuf_len > 0)
{
buffered->position -= buffered->readbuf_len;
buffered->position += buffered->readbuf_pos;
buffered->readbuf_len = 0;
buffered->readbuf_pos = 0;
mz_stream_buffered_print(opaque, stream, "switch from read to write [%lld]\n", buffered->position);
if (mz_stream_seek(buffered->stream.base, buffered->position, MZ_STREAM_SEEK_SET) != MZ_OK)
return MZ_STREAM_ERROR;
}
while (bytes_left_to_write > 0)
{
bytes_used = buffered->writebuf_len;
if (bytes_used > buffered->writebuf_pos)
bytes_used = buffered->writebuf_pos;
bytes_to_copy = (uint32_t)(MZ_BUF_BUFFERSIZE - bytes_used);
if (bytes_to_copy > bytes_left_to_write)
bytes_to_copy = bytes_left_to_write;
if (bytes_to_copy == 0)
{
if (mz_stream_buffered_flush(stream, &bytes_flushed) != MZ_OK)
return MZ_STREAM_ERROR;
if (bytes_flushed == 0)
return 0;
continue;
}
memcpy(buffered->writebuf + buffered->writebuf_pos, (char *)buf + (bytes_to_write - bytes_left_to_write), bytes_to_copy);
mz_stream_buffered_print(opaque, stream, "write copy [remaining %d write %d:%d len %d]\n",
bytes_to_copy, bytes_to_write, bytes_left_to_write, buffered->writebuf_len);
bytes_left_to_write -= bytes_to_copy;
buffered->writebuf_pos += bytes_to_copy;
buffered->writebuf_hits += 1;
if (buffered->writebuf_pos > buffered->writebuf_len)
buffered->writebuf_len += buffered->writebuf_pos - buffered->writebuf_len;
}
return size - bytes_left_to_write;
}
int64_t mz_stream_buffered_tellinternal(void *stream, uint64_t position)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
buffered->position = position;
mz_stream_buffered_print(opaque, stream, "tell [pos %llu readpos %d writepos %d err %d]\n",
buffered->position, buffered->readbuf_pos, buffered->writebuf_pos, errno);
if (buffered->readbuf_len > 0)
position -= (buffered->readbuf_len - buffered->readbuf_pos);
if (buffered->writebuf_len > 0)
position += buffered->writebuf_pos;
return position;
}
int64_t mz_stream_buffered_tell(void *stream)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
int64_t position = mz_stream_tell(buffered->stream.base);
return mz_stream_buffered_tellinternal(stream, position);
}
int mz_stream_buffered_seekinternal(void *stream, uint64_t offset, int32_t origin)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
uint32_t bytes_flushed = 0;
mz_stream_buffered_print(opaque, stream, "seek [origin %d offset %llu pos %lld]\n", origin, offset, buffered->position);
switch (origin)
{
case MZ_STREAM_SEEK_SET:
if (buffered->writebuf_len > 0)
{
if ((offset >= buffered->position) && (offset <= buffered->position + buffered->writebuf_len))
{
buffered->writebuf_pos = (uint32_t)(offset - buffered->position);
return MZ_OK;
}
}
if ((buffered->readbuf_len > 0) && (offset < buffered->position) && (offset >= buffered->position - buffered->readbuf_len))
{
buffered->readbuf_pos = (uint32_t)(offset - (buffered->position - buffered->readbuf_len));
return MZ_OK;
}
if (mz_stream_buffered_flush(stream, &bytes_flushed) != MZ_OK)
return MZ_STREAM_ERROR;
buffered->position = offset;
break;
case MZ_STREAM_SEEK_CUR:
if (buffered->readbuf_len > 0)
{
if (offset <= (buffered->readbuf_len - buffered->readbuf_pos))
{
buffered->readbuf_pos += (uint32_t)offset;
return MZ_OK;
}
offset -= (buffered->readbuf_len - buffered->readbuf_pos);
buffered->position += offset;
}
if (buffered->writebuf_len > 0)
{
if (offset <= (buffered->writebuf_len - buffered->writebuf_pos))
{
buffered->writebuf_pos += (uint32_t)offset;
return MZ_OK;
}
//offset -= (buffered->writebuf_len - buffered->writebuf_pos);
}
if (mz_stream_buffered_flush(stream, &bytes_flushed) != MZ_OK)
return MZ_STREAM_ERROR;
break;
case MZ_STREAM_SEEK_END:
if (buffered->writebuf_len > 0)
{
buffered->writebuf_pos = buffered->writebuf_len;
return MZ_OK;
}
break;
}
buffered->readbuf_len = 0;
buffered->readbuf_pos = 0;
buffered->writebuf_len = 0;
buffered->writebuf_pos = 0;
return MZ_STREAM_ERROR;
}
int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
if (mz_stream_buffered_seekinternal(stream, offset, origin) != MZ_OK)
return MZ_STREAM_ERROR;
return mz_stream_seek(buffered->stream.base, offset, origin);
}
int32_t mz_stream_buffered_close(void *stream)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
uint32_t bytes_flushed = 0;
mz_stream_buffered_flush(stream, &bytes_flushed);
mz_stream_buffered_print(opaque, stream, "close\n");
if (buffered->readbuf_hits + buffered->readbuf_misses > 0)
mz_stream_buffered_print(opaque, stream, "read efficency %.02f%%\n",
(buffered->readbuf_hits / ((float)buffered->readbuf_hits + buffered->readbuf_misses)) * 100);
if (buffered->writebuf_hits + buffered->writebuf_misses > 0)
mz_stream_buffered_print(opaque, stream, "write efficency %.02f%%\n",
(buffered->writebuf_hits / ((float)buffered->writebuf_hits + buffered->writebuf_misses)) * 100);
return mz_stream_close(&buffered->stream.base);
}
int32_t mz_stream_buffered_error(void *stream)
{
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
return mz_stream_error(&buffered->stream.base);
}
void *mz_stream_buffered_create(void **stream)
{
mz_stream_buffered *buffered = NULL;
buffered = (mz_stream_buffered *)malloc(sizeof(mz_stream_buffered));
if (buffered != NULL)
{
memset(buffered, 0, sizeof(mz_stream_buffered));
buffered->stream.open = mz_stream_buffered_open;
buffered->stream.read = mz_stream_buffered_read;
buffered->stream.write = mz_stream_buffered_write;
buffered->stream.tell = mz_stream_buffered_tell;
buffered->stream.seek = mz_stream_buffered_seek;
buffered->stream.close = mz_stream_buffered_close;
buffered->stream.error = mz_stream_buffered_error;
buffered->stream.create = mz_stream_buffered_create;
buffered->stream.delete = mz_stream_buffered_delete;
}
if (stream != NULL)
*stream = buffered;
return buffered;
}
void mz_stream_buffered_delete(void **stream)
{
mz_stream_buffered *buffered = NULL;
if (stream == NULL)
return;
buffered = (mz_stream_buffered *)*stream;
if (buffered != NULL)
free(buffered);
*stream = NULL;
}

View File

@@ -0,0 +1,42 @@
/* mz_strm_buf.h -- Stream for buffering reads/writes
Version 2.0.0, October 4th, 2017
part of the MiniZip project
This version of ioapi is designed to buffer IO.
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_BUFFERED_H
#define _MZ_STREAM_BUFFERED_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
int32_t mz_stream_buffered_open(void *stream, const char *path, int32_t mode);
int32_t mz_stream_buffered_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_buffered_tell(void *stream);
int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_buffered_close(void *stream);
int32_t mz_stream_buffered_error(void *stream);
void* mz_stream_buffered_create(void **stream);
void mz_stream_buffered_delete(void **stream);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,310 @@
/* mz_strm_crypt.c -- Code for traditional PKWARE encryption
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
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.
This encryption code is a direct transcription of the algorithm from
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
file (appnote.txt) is distributed with the PKZIP program (even in the
version without encryption capabilities).
If you don't need crypting in your application, just define symbols
NOCRYPT and NOUNCRYPT.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zlib.h"
#include "mz_error.h"
#include "mz_os.h"
#include "mz_strm.h"
#include "mz_strm_crypt.h"
/***************************************************************************/
#define RAND_HEAD_LEN 12
/***************************************************************************/
typedef struct mz_stream_crypt_s {
mz_stream stream;
uint32_t keys[3]; // keys defining the pseudo-random sequence
const z_crc_t *crc_32_tab;
int16_t initialized;
int16_t error;
uint8_t verify1;
uint8_t verify2;
const char *password;
uint8_t buffer[UINT16_MAX];
int64_t total_in;
int64_t total_out;
} mz_stream_crypt;
/***************************************************************************/
#define zdecode(keys,crc_32_tab,c) \
(mz_stream_crypt_update_keys(keys,crc_32_tab, c ^= mz_stream_crypt_decrypt_byte(keys)))
#define zencode(keys,crc_32_tab,c,t) \
(t = mz_stream_crypt_decrypt_byte(keys), mz_stream_crypt_update_keys(keys,crc_32_tab,c), t^(c))
/***************************************************************************/
uint8_t mz_stream_crypt_decrypt_byte(uint32_t *keys)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */
temp = ((uint32_t)(*(keys+2)) & 0xffff) | 2;
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
uint8_t mz_stream_crypt_update_keys(uint32_t *keys, const z_crc_t *crc_32_tab, int32_t c)
{
#define CRC32(c, b) ((*(crc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
(*(keys+0)) = (uint32_t)CRC32((*(keys+0)), c);
(*(keys+1)) += (*(keys+0)) & 0xff;
(*(keys+1)) = (*(keys+1)) * 134775813L + 1;
{
register int32_t keyshift = (int32_t)((*(keys + 1)) >> 24);
(*(keys+2)) = (uint32_t)CRC32((*(keys+2)), keyshift);
}
return c;
}
void mz_stream_crypt_init_keys(const char *password, uint32_t *keys, const z_crc_t *crc_32_tab)
{
*(keys+0) = 305419896L;
*(keys+1) = 591751049L;
*(keys+2) = 878082192L;
while (*password != 0)
{
mz_stream_crypt_update_keys(keys, crc_32_tab, *password);
password += 1;
}
}
/***************************************************************************/
int32_t mz_stream_crypt_open(void *stream, const char *path, int32_t mode)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
uint16_t t = 0;
int16_t i = 0;
uint8_t header[RAND_HEAD_LEN];
const char *password = path;
crypt->total_in = 0;
crypt->total_out = 0;
crypt->initialized = 0;
if (mz_stream_is_open(crypt->stream.base) != MZ_OK)
return MZ_STREAM_ERROR;
if (password == NULL)
password = crypt->password;
if (password == NULL)
return MZ_STREAM_ERROR;
crypt->crc_32_tab = get_crc_table();
if (crypt->crc_32_tab == NULL)
return MZ_STREAM_ERROR;
mz_stream_crypt_init_keys(password, crypt->keys, crypt->crc_32_tab);
if (mode & MZ_STREAM_MODE_WRITE)
{
// First generate RAND_HEAD_LEN - 2 random bytes.
mz_os_rand(header, RAND_HEAD_LEN - 2);
// Encrypt random header (last two bytes is high word of crc)
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
header[i] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, header[i], t);
header[i++] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, crypt->verify1, t);
header[i++] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, crypt->verify2, t);
if (mz_stream_write(crypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
return MZ_STREAM_ERROR;
crypt->total_out += RAND_HEAD_LEN;
}
else if (mode & MZ_STREAM_MODE_READ)
{
if (mz_stream_read(crypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
return MZ_STREAM_ERROR;
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
header[i] = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i]);
crypt->verify1 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
crypt->verify2 = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, header[i++]);
crypt->total_in += RAND_HEAD_LEN;
}
crypt->initialized = 1;
return MZ_OK;
}
int32_t mz_stream_crypt_is_open(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
if (crypt->initialized == 0)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_crypt_read(void *stream, void *buf, int32_t size)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
uint8_t *buf_ptr = (uint8_t *)buf;
uint32_t read = 0;
uint32_t i = 0;
read = mz_stream_read(crypt->stream.base, buf, size);
for (i = 0; i < read; i++)
buf_ptr[i] = (uint8_t)zdecode(crypt->keys, crypt->crc_32_tab, buf_ptr[i]);
crypt->total_in += read;
return read;
}
int32_t mz_stream_crypt_write(void *stream, const void *buf, int32_t size)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
uint8_t *buf_ptr = (uint8_t *)buf;
uint32_t written = 0;
uint16_t t = 0;
int32_t i = 0;
if (size > sizeof(crypt->buffer))
return MZ_STREAM_ERROR;
for (i = 0; i < size; i++)
crypt->buffer[i] = (uint8_t)zencode(crypt->keys, crypt->crc_32_tab, buf_ptr[i], t);
written = mz_stream_write(crypt->stream.base, crypt->buffer, size);
if (written > 0)
crypt->total_out += written;
return written;
}
int64_t mz_stream_crypt_tell(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
return mz_stream_tell(crypt->stream.base);
}
int32_t mz_stream_crypt_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
return mz_stream_seek(crypt->stream.base, offset, origin);
}
int32_t mz_stream_crypt_close(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
crypt->initialized = 0;
return MZ_OK;
}
int32_t mz_stream_crypt_error(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
return crypt->error;
}
void mz_stream_crypt_set_password(void *stream, const char *password)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
crypt->password = password;
}
void mz_stream_crypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
crypt->verify1 = verify1;
crypt->verify2 = verify2;
}
void mz_stream_crypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
*verify1 = crypt->verify1;
*verify2 = crypt->verify2;
}
int64_t mz_stream_crypt_get_total_in(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
return crypt->total_in;
}
int64_t mz_stream_crypt_get_total_out(void *stream)
{
mz_stream_crypt *crypt = (mz_stream_crypt *)stream;
return crypt->total_out;
}
void *mz_stream_crypt_create(void **stream)
{
mz_stream_crypt *crypt = NULL;
crypt = (mz_stream_crypt *)malloc(sizeof(mz_stream_crypt));
if (crypt != NULL)
{
memset(crypt, 0, sizeof(mz_stream_crypt));
crypt->stream.open = mz_stream_crypt_open;
crypt->stream.is_open = mz_stream_crypt_is_open;
crypt->stream.read = mz_stream_crypt_read;
crypt->stream.write = mz_stream_crypt_write;
crypt->stream.tell = mz_stream_crypt_tell;
crypt->stream.seek = mz_stream_crypt_seek;
crypt->stream.close = mz_stream_crypt_close;
crypt->stream.error = mz_stream_crypt_error;
crypt->stream.create = mz_stream_crypt_create;
crypt->stream.delete = mz_stream_crypt_delete;
crypt->stream.get_total_in = mz_stream_crypt_get_total_in;
crypt->stream.get_total_out = mz_stream_crypt_get_total_out;
}
if (stream != NULL)
*stream = crypt;
return crypt;
}
void mz_stream_crypt_delete(void **stream)
{
mz_stream_crypt *crypt = NULL;
if (stream == NULL)
return;
crypt = (mz_stream_crypt *)*stream;
if (crypt != NULL)
free(crypt);
*stream = NULL;
}

View File

@@ -0,0 +1,54 @@
/* mz_strm_crypt.h -- Code for traditional PKWARE encryption
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 1998-2005 Gilles Vollant
Modifications for Info-ZIP crypting
http://www.winimage.com/zLibDll/minizip.html
Copyright (C) 2003 Terry Thorsen
This code is a modified version of crypting code in Info-ZIP distribution
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
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_STREAM_CRYPT_H
#define _MZ_STREAM_CRYPT_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
int32_t mz_stream_crypt_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_crypt_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_crypt_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_crypt_tell(void *stream);
int32_t mz_stream_crypt_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_crypt_close(void *stream);
int32_t mz_stream_crypt_error(void *stream);
void mz_stream_crypt_set_password(void *stream, const char *password);
void mz_stream_crypt_set_verify(void *stream, uint8_t verify1, uint8_t verify2);
void mz_stream_crypt_get_verify(void *stream, uint8_t *verify1, uint8_t *verify2);
int64_t mz_stream_crypt_get_total_in(void *stream);
int64_t mz_stream_crypt_get_total_out(void *stream);
void* mz_stream_crypt_create(void **stream);
void mz_stream_crypt_delete(void **stream);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,249 @@
/* mz_strm_mem.c -- Stream for memory access
Version 2.0.0, October 4th, 2017
part of the MiniZip project
This interface is designed to access memory rather than files.
We do use a region of memory to put data in to and take it out of.
Based on Unzip ioapi.c version 0.22, May 19th, 2003
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2003 Justin Fletcher
Copyright (C) 1998-2003 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
This file is under the same license as the Unzip tool it is distributed
with.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mz_error.h"
#include "mz_strm.h"
#include "mz_strm_mem.h"
/***************************************************************************/
typedef struct mz_stream_mem_s {
mz_stream stream;
char *buffer; // Memory buffer pointer
int32_t size; // Size of the memory buffer
int32_t limit; // Furthest we've written
int32_t position; // Current position in the memory
int8_t grow; // Memory buffer can grow
int32_t grow_size; // Size to grow when full
} mz_stream_mem;
/***************************************************************************/
int32_t mz_stream_mem_open(void *stream, const char *path, int32_t mode)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
if (mode & MZ_STREAM_MODE_CREATE)
{
if (mem->grow)
{
mem->size = mem->grow_size;
mem->buffer = (char *)malloc(mem->size);
}
// When writing we start with 0 bytes written
mem->limit = 0;
}
else
{
mem->limit = mem->size;
}
mem->position = 0;
return MZ_OK;
}
int32_t mz_stream_mem_is_open(void *stream)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
if (mem->buffer == NULL)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_mem_read(void *stream, void *buf, int32_t size)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
if (size > mem->size - mem->position)
size = mem->size - mem->position;
memcpy(buf, mem->buffer + mem->position, size);
mem->position += size;
return size;
}
int32_t mz_stream_mem_write(void *stream, const void *buf, int32_t size)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
int32_t new_size = 0;
char *new_buf = NULL;
if (size == 0)
return size;
if (size > mem->size - mem->position)
{
if (mem->grow)
{
new_size = mem->size;
if (size < mem->grow_size)
new_size += mem->grow_size;
else
new_size += size;
new_buf = (char *)malloc(new_size);
memcpy(new_buf, mem->buffer, mem->size);
free(mem->buffer);
mem->buffer = new_buf;
mem->size = new_size;
}
else
{
size = mem->size - mem->position;
}
}
memcpy(mem->buffer + mem->position, buf, size);
mem->position += size;
if (mem->position > mem->limit)
mem->limit = mem->position;
return size;
}
int64_t mz_stream_mem_tell(void *stream)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
return mem->position;
}
int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
uint64_t new_pos = 0;
switch (origin)
{
case MZ_STREAM_SEEK_CUR:
new_pos = mem->position + offset;
break;
case MZ_STREAM_SEEK_END:
new_pos = mem->limit + offset;
break;
case MZ_STREAM_SEEK_SET:
new_pos = offset;
break;
default:
return MZ_STREAM_ERROR;
}
if (new_pos > mem->size)
return MZ_STREAM_ERROR;
mem->position = (uint32_t)new_pos;
return MZ_OK;
}
int32_t mz_stream_mem_close(void *stream)
{
// We never return errors
return MZ_OK;
}
int32_t mz_stream_mem_error(void *stream)
{
// We never return errors
return MZ_OK;
}
void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
mem->buffer = buf;
mem->size = size;
}
int8_t mz_stream_mem_get_buffer(void *stream, void **buf)
{
return mz_stream_mem_get_buffer_at(stream, 0, buf);
}
int8_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, void **buf)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
if (buf == NULL || position < 0 || mem->size < position || mem->buffer == NULL)
return MZ_STREAM_ERROR;
*buf = mem->buffer + position;
return MZ_OK;
}
void mz_stream_mem_set_grow(void *stream, int8_t grow)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
mem->grow = grow;
}
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size)
{
mz_stream_mem *mem = (mz_stream_mem *)stream;
mem->grow_size = grow_size;
}
void *mz_stream_mem_create(void **stream)
{
mz_stream_mem *mem = NULL;
mem = (mz_stream_mem *)malloc(sizeof(mz_stream_mem));
if (mem != NULL)
{
memset(mem, 0, sizeof(mz_stream_mem));
mem->stream.open = mz_stream_mem_open;
mem->stream.is_open = mz_stream_mem_is_open;
mem->stream.read = mz_stream_mem_read;
mem->stream.write = mz_stream_mem_write;
mem->stream.tell = mz_stream_mem_tell;
mem->stream.seek = mz_stream_mem_seek;
mem->stream.close = mz_stream_mem_close;
mem->stream.error = mz_stream_mem_error;
mem->stream.create = mz_stream_mem_create;
mem->stream.delete = mz_stream_mem_delete;
mem->grow_size = 16384;
}
if (stream != NULL)
*stream = mem;
return mem;
}
void mz_stream_mem_delete(void **stream)
{
mz_stream_mem *mem = NULL;
if (stream == NULL)
return;
mem = (mz_stream_mem *)*stream;
if (mem != NULL)
{
if (mem->grow && mem->buffer != NULL)
free(mem->buffer);
free(mem);
}
*stream = NULL;
}

View File

@@ -0,0 +1,47 @@
/* mz_strm_mem.h -- Stream for memory access
part of MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2003 Justin Fletcher
Copyright (C) 1998-2003 Gilles Vollant
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_STREAM_MEM_H
#define _MZ_STREAM_MEM_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
int32_t mz_stream_mem_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_mem_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_mem_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_mem_tell(void *stream);
int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_mem_close(void *stream);
int32_t mz_stream_mem_error(void *stream);
void mz_stream_mem_set_buffer(void *stream, void *buf, int32_t size);
int8_t mz_stream_mem_get_buffer(void *stream, void **buf);
int8_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, void **buf);
void mz_stream_mem_set_grow(void *stream, int8_t grow);
void mz_stream_mem_set_grow_size(void *stream, int32_t grow_size);
void* mz_stream_mem_create(void **stream);
void mz_stream_mem_delete(void **stream);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,225 @@
/* mz_strm_posix.c -- Stream for filesystem access for posix/linux
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#if defined unix || defined __APPLE__
# include <unistd.h>
# include <utime.h>
# include <fcntl.h>
#endif
#include "mz_error.h"
#include "mz_strm.h"
#include "mz_strm_posix.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__) || defined(__ANDROID__)
# 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
/***************************************************************************/
typedef struct mz_stream_posix_s
{
mz_stream stream;
FILE *handle;
int16_t error;
} mz_stream_posix;
/***************************************************************************/
int32_t mz_stream_posix_open(void *stream, const char *path, int32_t mode)
{
mz_stream_posix *posix = (mz_stream_posix *)stream;
const char *mode_fopen = NULL;
if (path == NULL)
return MZ_STREAM_ERROR;
if ((mode & MZ_STREAM_MODE_READWRITE) == MZ_STREAM_MODE_READ)
mode_fopen = "rb";
else if (mode & MZ_STREAM_MODE_APPEND)
mode_fopen = "ab";
else if (mode & MZ_STREAM_MODE_CREATE)
mode_fopen = "wb";
else
return MZ_STREAM_ERROR;
posix->handle = fopen64(path, mode_fopen);
if (posix->handle == NULL)
{
posix->error = errno;
return MZ_STREAM_ERROR;
}
return MZ_OK;
}
int32_t mz_stream_posix_is_open(void *stream)
{
mz_stream_posix *posix = (mz_stream_posix*)stream;
if (posix->handle == NULL)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_posix_read(void *stream, void *buf, int32_t size)
{
mz_stream_posix *posix = (mz_stream_posix*)stream;
int32_t read = (int32_t)fread(buf, 1, (size_t)size, posix->handle);
if (read < 0)
{
posix->error = ferror(posix->handle);
return MZ_STREAM_ERROR;
}
return read;
}
int32_t mz_stream_posix_write(void *stream, const void *buf, int32_t size)
{
mz_stream_posix *posix = (mz_stream_posix*)stream;
int32_t written = (int32_t)fwrite(buf, 1, (size_t)size, posix->handle);
if (written < 0)
{
posix->error = ferror(posix->handle);
return MZ_STREAM_ERROR;
}
return written;
}
int64_t mz_stream_posix_tell(void *stream)
{
mz_stream_posix *posix = (mz_stream_posix*)stream;
int64_t position = ftello64(posix->handle);
if (position == -1)
{
posix->error = ferror(posix->handle);
return MZ_STREAM_ERROR;
}
return position;
}
int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_posix *posix = (mz_stream_posix*)stream;
int32_t fseek_origin = 0;
switch (origin)
{
case MZ_STREAM_SEEK_CUR:
fseek_origin = SEEK_CUR;
break;
case MZ_STREAM_SEEK_END:
fseek_origin = SEEK_END;
break;
case MZ_STREAM_SEEK_SET:
fseek_origin = SEEK_SET;
break;
default:
return MZ_STREAM_ERROR;
}
if (fseeko64(posix->handle, offset, fseek_origin) != 0)
{
posix->error = ferror(posix->handle);
return MZ_STREAM_ERROR;
}
return MZ_OK;
}
int32_t mz_stream_posix_close(void *stream)
{
mz_stream_posix *posix = (mz_stream_posix*)stream;
int32_t closed = fclose(posix->handle);
posix->handle = NULL;
if (closed != 0)
{
posix->error = errno;
return MZ_STREAM_ERROR;
}
return MZ_OK;
}
int32_t mz_stream_posix_error(void *stream)
{
mz_stream_posix *posix = (mz_stream_posix*)stream;
return posix->error;
}
void *mz_stream_posix_create(void **stream)
{
mz_stream_posix *posix = NULL;
posix = (mz_stream_posix *)malloc(sizeof(mz_stream_posix));
if (posix != NULL)
{
posix->stream.open = mz_stream_posix_open;
posix->stream.is_open = mz_stream_posix_is_open;
posix->stream.read = mz_stream_posix_read;
posix->stream.write = mz_stream_posix_write;
posix->stream.tell = mz_stream_posix_tell;
posix->stream.seek = mz_stream_posix_seek;
posix->stream.close = mz_stream_posix_close;
posix->stream.error = mz_stream_posix_error;
posix->stream.create = mz_stream_posix_create;
posix->stream.delete = mz_stream_posix_delete;
}
if (stream != NULL)
*stream = posix;
return posix;
}
void mz_stream_posix_delete(void **stream)
{
mz_stream_posix *posix = NULL;
if (stream == NULL)
return;
posix = (mz_stream_posix *)*stream;
if (posix != NULL)
free(posix);
*stream = NULL;
}

View File

@@ -0,0 +1,62 @@
/* mz_strm_posix.h -- Stream for filesystem access for posix/linux
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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_STREAM_POSIX_H
#define _MZ_STREAM_POSIX_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
int32_t mz_stream_posix_open(void *stream, const char *path, int32_t mode);
int32_t mz_stream_posix_is_open(void *stream);
int32_t mz_stream_posix_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_posix_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_posix_tell(void *stream);
int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_posix_close(void *stream);
int32_t mz_stream_posix_error(void *stream);
void* mz_stream_posix_create(void **stream);
void mz_stream_posix_delete(void **stream);
/***************************************************************************/
#if !defined(_WIN32) && !defined(USEWIN32IOAPI)
#define mz_stream_os_open mz_stream_posix_open
#define mz_stream_os_is_open mz_stream_posix_is_open
#define mz_stream_os_read mz_stream_posix_read
#define mz_stream_os_write mz_stream_posix_write
#define mz_stream_os_tell mz_stream_posix_tell
#define mz_stream_os_seek mz_stream_posix_seek
#define mz_stream_os_close mz_stream_posix_close
#define mz_stream_os_error mz_stream_posix_error
#define mz_stream_os_create mz_stream_posix_create
#define mz_stream_os_delete mz_stream_posix_delete
#endif
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,509 @@
/* mz_strm_zlib.c -- Stream for zlib inflate/deflate
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "zlib.h"
#include "mz_error.h"
#include "mz_strm.h"
#include "mz_strm_zlib.h"
/***************************************************************************/
#ifndef DEF_MEM_LEVEL
# if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
# else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
# endif
#endif
/***************************************************************************/
typedef struct mz_stream_zlib_s {
mz_stream stream;
z_stream zstream;
uint8_t buffer[UINT16_MAX];
int32_t buffer_len;
int64_t total_in;
int64_t total_out;
int64_t max_total_in;
int8_t initialized;
int16_t level;
int16_t window_bits;
int16_t mem_level;
int16_t strategy;
int16_t mode;
int16_t error;
} mz_stream_zlib;
/***************************************************************************/
int32_t mz_stream_zlib_open(void *stream, const char *path, int32_t mode)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
int16_t window_bits = 0;
zlib->zstream.data_type = Z_BINARY;
zlib->zstream.zalloc = Z_NULL;
zlib->zstream.zfree = Z_NULL;
zlib->zstream.opaque = Z_NULL;
zlib->zstream.total_in = 0;
zlib->zstream.total_out = 0;
zlib->total_in = 0;
zlib->total_out = 0;
window_bits = zlib->window_bits;
if (window_bits > 0)
window_bits = -window_bits;
if (mode & MZ_STREAM_MODE_READ)
{
zlib->zstream.next_in = zlib->buffer;
zlib->zstream.avail_in = 0;
zlib->error = inflateInit2(&zlib->zstream, window_bits);
}
else if (mode & MZ_STREAM_MODE_WRITE)
{
zlib->zstream.next_out = zlib->buffer;
zlib->zstream.avail_out = sizeof(zlib->buffer);
zlib->error = deflateInit2(&zlib->zstream, (int8_t)zlib->level, Z_DEFLATED, window_bits, zlib->mem_level, zlib->strategy);
}
if (zlib->error != Z_OK)
return MZ_STREAM_ERROR;
zlib->initialized = 1;
zlib->mode = mode;
return MZ_OK;
}
int32_t mz_stream_zlib_is_open(void *stream)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
if (zlib->initialized != 1)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
uint64_t total_out_before = 0;
uint64_t total_out_after = 0;
uint32_t out_bytes = 0;
uint32_t total_out = 0;
int32_t bytes_to_read = 0;
int32_t read = 0;
int16_t err = Z_OK;
zlib->zstream.next_out = (uint8_t*)buf;
zlib->zstream.avail_out = (uint16_t)size;
do
{
if (zlib->zstream.avail_in == 0)
{
bytes_to_read = sizeof(zlib->buffer);
if (zlib->max_total_in > 0)
{
if ((zlib->max_total_in - zlib->total_in) < sizeof(zlib->buffer))
bytes_to_read = (int32_t)(zlib->max_total_in - zlib->total_in);
}
read = mz_stream_read(zlib->stream.base, zlib->buffer, bytes_to_read);
if (read < 0)
{
zlib->error = Z_STREAM_ERROR;
break;
}
if (read == 0)
break;
zlib->total_in += read;
zlib->zstream.next_in = zlib->buffer;
zlib->zstream.avail_in = read;
}
total_out_before = zlib->zstream.total_out;
err = inflate(&zlib->zstream, Z_SYNC_FLUSH);
if ((err >= Z_OK) && (zlib->zstream.msg != NULL))
{
zlib->error = Z_DATA_ERROR;
break;
}
total_out_after = zlib->zstream.total_out;
out_bytes = (uint32_t)(total_out_after - total_out_before);
total_out += out_bytes;
if (err == Z_STREAM_END)
{
break;
}
if (err != Z_OK)
{
zlib->error = err;
break;
}
}
while (zlib->zstream.avail_out > 0);
zlib->total_out += total_out;
return total_out;
}
int32_t mz_stream_zlib_flush(void *stream)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
if (mz_stream_write(zlib->stream.base, zlib->buffer, zlib->buffer_len) != zlib->buffer_len)
return MZ_STREAM_ERROR;
return MZ_OK;
}
uint32_t mz_stream_zlib_deflate(void *stream, int flush)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
uint64_t total_out_before = 0;
uint64_t total_out_after = 0;
uint32_t out_bytes = 0;
int16_t err = Z_OK;
total_out_before = zlib->zstream.total_out;
err = deflate(&zlib->zstream, flush);
total_out_after = zlib->zstream.total_out;
out_bytes = (uint32_t)(total_out_after - total_out_before);
if (err != Z_OK && err != Z_STREAM_END)
{
zlib->error = err;
return MZ_STREAM_ERROR;
}
return out_bytes;
}
int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
uint32_t out_bytes = 0;
uint32_t total_out = 0;
zlib->zstream.next_in = (uint8_t*)buf;
zlib->zstream.avail_in = size;
while ((zlib->error == Z_OK) && (zlib->zstream.avail_in > 0))
{
if (zlib->zstream.avail_out == 0)
{
if (mz_stream_zlib_flush(zlib) != MZ_OK)
{
zlib->error = Z_STREAM_ERROR;
return 0;
}
zlib->zstream.avail_out = sizeof(zlib->buffer);
zlib->zstream.next_out = zlib->buffer;
zlib->buffer_len = 0;
}
out_bytes = mz_stream_zlib_deflate(stream, Z_NO_FLUSH);
total_out += out_bytes;
zlib->buffer_len += out_bytes;
}
zlib->total_in += size;
zlib->total_out += total_out;
return size;
}
int64_t mz_stream_zlib_tell(void *stream)
{
return MZ_STREAM_ERROR;
}
int32_t mz_stream_zlib_seek(void *stream, int64_t offset, int32_t origin)
{
return MZ_STREAM_ERROR;
}
int32_t mz_stream_zlib_close(void *stream)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
uint32_t out_bytes = 0;
if (zlib->mode & MZ_STREAM_MODE_READ)
{
inflateEnd(&zlib->zstream);
}
else if (zlib->mode & MZ_STREAM_MODE_WRITE)
{
out_bytes = mz_stream_zlib_deflate(stream, Z_FINISH);
zlib->buffer_len += out_bytes;
zlib->total_out += out_bytes;
mz_stream_zlib_flush(stream);
zlib->error = deflateEnd(&zlib->zstream);
}
zlib->initialized = 0;
if (zlib->error != Z_OK)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_zlib_error(void *stream)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
return zlib->error;
}
void mz_stream_zlib_set_level(void *stream, int16_t level)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
zlib->level = level;
}
void mz_stream_zlib_set_window_bits(void *stream, int16_t window_bits)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
if (window_bits == 0)
window_bits = -MAX_WBITS;
zlib->window_bits = window_bits;
}
void mz_stream_zlib_set_mem_level(void *stream, int16_t mem_level)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
if (mem_level == 0)
mem_level = DEF_MEM_LEVEL;
zlib->mem_level = mem_level;
}
void mz_stream_zlib_set_strategy(void *stream, int16_t strategy)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
zlib->strategy = strategy;
}
int64_t mz_stream_zlib_get_total_in(void *stream)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
return zlib->total_in;
}
int64_t mz_stream_zlib_get_total_out(void *stream)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
return zlib->total_out;
}
void mz_stream_zlib_set_max_total_in(void *stream, int64_t max_total_in)
{
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
zlib->max_total_in = max_total_in;
}
void *mz_stream_zlib_create(void **stream)
{
mz_stream_zlib *zlib = NULL;
zlib = (mz_stream_zlib *)malloc(sizeof(mz_stream_zlib));
if (zlib != NULL)
{
memset(zlib, 0, sizeof(mz_stream_zlib));
zlib->stream.open = mz_stream_zlib_open;
zlib->stream.is_open = mz_stream_zlib_is_open;
zlib->stream.read = mz_stream_zlib_read;
zlib->stream.write = mz_stream_zlib_write;
zlib->stream.tell = mz_stream_zlib_tell;
zlib->stream.seek = mz_stream_zlib_seek;
zlib->stream.close = mz_stream_zlib_close;
zlib->stream.error = mz_stream_zlib_error;
zlib->stream.create = mz_stream_zlib_create;
zlib->stream.delete = mz_stream_zlib_delete;
zlib->stream.get_total_in = mz_stream_zlib_get_total_in;
zlib->stream.get_total_out = mz_stream_zlib_get_total_out;
zlib->level = Z_DEFAULT_COMPRESSION;
zlib->window_bits = -MAX_WBITS;
zlib->mem_level = DEF_MEM_LEVEL;
zlib->strategy = Z_DEFAULT_STRATEGY;
}
if (stream != NULL)
*stream = zlib;
return zlib;
}
void mz_stream_zlib_delete(void **stream)
{
mz_stream_zlib *zlib = NULL;
if (stream == NULL)
return;
zlib = (mz_stream_zlib *)*stream;
if (zlib != NULL)
free(zlib);
*stream = NULL;
}
/***************************************************************************/
typedef struct mz_stream_crc32_s {
mz_stream stream;
int8_t initialized;
int32_t value;
int64_t total_in;
int64_t total_out;
} mz_stream_crc32;
/***************************************************************************/
int32_t mz_stream_crc32_open(void *stream, const char *path, int32_t mode)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
crc32->initialized = 1;
crc32->value = 0;
return MZ_OK;
}
int32_t mz_stream_crc32_is_open(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
if (crc32->initialized != 1)
return MZ_STREAM_ERROR;
return MZ_OK;
}
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size)
{
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
int32_t read = mz_stream_read(crc32x->stream.base, buf, size);
if (read > 0)
crc32x->value = (int32_t)crc32(crc32x->value, buf, read);
crc32x->total_in += read;
return read;
}
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size)
{
mz_stream_crc32 *crc32x = (mz_stream_crc32 *)stream;
int32_t written = 0;
crc32x->value = (int32_t)crc32(crc32x->value, buf, size);
written = mz_stream_write(crc32x->stream.base, buf, size);
crc32x->total_out += written;
return written;
}
int64_t mz_stream_crc32_tell(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return mz_stream_tell(crc32->stream.base);
}
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return mz_stream_seek(crc32->stream.base, offset, origin);
}
int32_t mz_stream_crc32_close(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
crc32->initialized = 0;
return MZ_OK;
}
int32_t mz_stream_crc32_error(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return mz_stream_error(crc32->stream.base);
}
int32_t mz_stream_crc32_get_value(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return crc32->value;
}
int64_t mz_stream_crc32_get_total_in(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return crc32->total_in;
}
int64_t mz_stream_crc32_get_total_out(void *stream)
{
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
return crc32->total_out;
}
void *mz_stream_crc32_create(void **stream)
{
mz_stream_crc32 *crc32 = NULL;
crc32 = (mz_stream_crc32 *)malloc(sizeof(mz_stream_crc32));
if (crc32 != NULL)
{
memset(crc32, 0, sizeof(mz_stream_crc32));
crc32->stream.open = mz_stream_crc32_open;
crc32->stream.is_open = mz_stream_crc32_is_open;
crc32->stream.read = mz_stream_crc32_read;
crc32->stream.write = mz_stream_crc32_write;
crc32->stream.tell = mz_stream_crc32_tell;
crc32->stream.seek = mz_stream_crc32_seek;
crc32->stream.close = mz_stream_crc32_close;
crc32->stream.error = mz_stream_crc32_error;
crc32->stream.create = mz_stream_crc32_create;
crc32->stream.delete = mz_stream_crc32_delete;
crc32->stream.get_total_in = mz_stream_crc32_get_total_in;
crc32->stream.get_total_out = mz_stream_crc32_get_total_out;
}
if (stream != NULL)
*stream = crc32;
return crc32;
}
void mz_stream_crc32_delete(void **stream)
{
mz_stream_crc32 *crc32 = NULL;
if (stream == NULL)
return;
crc32 = (mz_stream_crc32 *)*stream;
if (crc32 != NULL)
free(crc32);
*stream = NULL;
}

View File

@@ -0,0 +1,65 @@
/* mz_strm_zlib.h -- Stream for zlib inflate/deflate
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _MZ_STREAM_ZLIB_H
#define _MZ_STREAM_ZLIB_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
int32_t mz_stream_zlib_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_zlib_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_zlib_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_zlib_tell(void *stream);
int32_t mz_stream_zlib_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_zlib_close(void *stream);
int32_t mz_stream_zlib_error(void *stream);
void mz_stream_zlib_set_level(void *stream, int16_t level);
void mz_stream_zlib_set_window_bits(void *stream, int16_t window_bits);
void mz_stream_zlib_set_mem_level(void *stream, int16_t mem_level);
void mz_stream_zlib_set_strategy(void *stream, int16_t strategy);
int64_t mz_stream_zlib_get_total_in(void *stream);
int64_t mz_stream_zlib_get_total_out(void *stream);
void mz_stream_zlib_set_max_total_in(void *stream, int64_t max_total_in);
void* mz_stream_zlib_create(void **stream);
void mz_stream_zlib_delete(void **stream);
/***************************************************************************/
int32_t mz_stream_crc32_open(void *stream, const char *filename, int32_t mode);
int32_t mz_stream_crc32_read(void *stream, void *buf, int32_t size);
int32_t mz_stream_crc32_write(void *stream, const void *buf, int32_t size);
int64_t mz_stream_crc32_tell(void *stream);
int32_t mz_stream_crc32_seek(void *stream, int64_t offset, int32_t origin);
int32_t mz_stream_crc32_close(void *stream);
int32_t mz_stream_crc32_error(void *stream);
int32_t mz_stream_crc32_get_value(void *stream);
int64_t mz_stream_crc32_get_total_in(void *stream);
int64_t mz_stream_crc32_get_total_out(void *stream);
void* mz_stream_crc32_create(void **stream);
void mz_stream_crc32_delete(void **stream);
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,143 @@
/* mz_unzip.h -- Zip manipulation
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support on both zip and unzip
http://result42.com
Copyright (C) 2007-2008 Even Rouault
Modifications of Unzip for Zip64
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
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_UNZIP_H
#define _MZ_UNZIP_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#include "mz_strm.h"
/***************************************************************************/
#ifndef MZ_METHOD
# define MZ_METHOD_RAW (0)
# define MZ_METHOD_DEFLATE (8)
# define MZ_METHOD_BZIP2 (12)
# define MZ_METHOD_LZMA (14)
#endif
/***************************************************************************/
// Global data about the zip file that come from the end of central dir
typedef struct mz_unzip_global_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 comment_size; // size of the global comment of the zip file
} mz_unzip_global;
// Info about a file in the zip file at the central directory
typedef struct mz_unzip_file_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 dos_date; // last mod file date in Dos fmt 4 bytes
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 filename_size; // filename length 2 bytes
uint16_t extrafield_size; // extra field length 2 bytes
uint16_t comment_size; // 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; // relative offset of local header 8 bytes
char *filename; // filename string
uint8_t *extrafield; // extrafield data
char *comment; // comment string
} mz_unzip_file;
/***************************************************************************/
// Opening and close a zip file
// Open a zip file
extern void* ZEXPORT mz_unzip_open(void *stream);
// Close a zip file
extern int ZEXPORT mz_unzip_close(void *handle);
// Get global info about the zip file
extern int ZEXPORT mz_unzip_get_global_info(void *handle, mz_unzip_global *global_info);
// Get the global comment string of the zip file, in the comment buffer
extern int ZEXPORT mz_unzip_get_global_comment(void *handle, char *comment, uint16_t comment_size);
/***************************************************************************/
// Reading the content of the current zip file, you can open it, read it, and close it
extern int ZEXPORT mz_unzip_entry_open(void *handle, int raw, const char *password);
// Open for reading data the current file in the zip file
extern int ZEXPORT mz_unzip_entry_read(void *handle, void *buf, uint32_t len);
// Read bytes from the current file
extern int ZEXPORT mz_unzip_entry_get_info(void *handle, mz_unzip_file **file_info);
// Get info about the current file
extern int ZEXPORT mz_unzip_entry_get_extrafield_local(void *handle, void *buf, uint32_t len);
// Read extra field from the current file
//
// This is the local-header version of the extra field (sometimes, there is
// more info in the local-header version than in the central-header)
//
// if buf == NULL, it return the size of the local extra field
// if buf != NULL, len is the size of the buffer, the extra header is copied in buf.
//
// return number of bytes copied in buf, or (if <0) the error code
extern int ZEXPORT mz_unzip_entry_close(void *handle);
// Close the file in zip
/***************************************************************************/
// Navigate the directory of the zip file
typedef int (*mz_filename_compare_cb)(void *handle, const char *filename1, const char *filename2);
extern int ZEXPORT mz_unzip_locate_entry(void *file, const char *filename, mz_filename_compare_cb filename_compare_cb);
// Locate the file with the specified name in the zip file
//
// if filename_compare_cb == NULL, it uses strcmp
//
// return MZ_OK if the file is found (it becomes the current file)
// return MZ_END_OF_LIST if the file is not found
extern int ZEXPORT mz_unzip_goto_first_entry(void *handle);
// Go to the first entry in the zip file
extern int ZEXPORT mz_unzip_goto_next_entry(void *handle);
// Go to the next entry in the zip file or MZ_END_OF_LIST if reaching the end
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* _UNZ_H */

988
SSZipArchive/minizip/mz_zip.c Executable file
View File

@@ -0,0 +1,988 @@
/* zip.c -- Zip manipulation
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2010-2017 Nathan Moinvaziri
Modifications for AES, PKWARE disk spanning
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include "zlib.h"
#include "mz_error.h"
#include "mz_strm.h"
#ifdef HAVE_AES
# include "mz_strm_aes.h"
#endif
#ifdef HAVE_BZIP2
# include "mz_strm_bzip.h"
#endif
#ifndef NOCRYPT
# include "mz_strm_crypt.h"
#endif
#ifdef HAVE_LZMA
# include "mz_strm_lzma.h"
#endif
#include "mz_strm_mem.h"
#include "mz_strm_zlib.h"
#include "mz_zip.h"
/***************************************************************************/
#define DISKHEADERMAGIC (0x08074b50)
#define LOCALHEADERMAGIC (0x04034b50)
#define CENTRALHEADERMAGIC (0x02014b50)
#define ENDHEADERMAGIC (0x06054b50)
#define ZIP64ENDHEADERMAGIC (0x06064b50)
#define ZIP64ENDLOCHEADERMAGIC (0x07064b50)
#define DATADESCRIPTORMAGIC (0x08074b50)
#define SIZECENTRALHEADER (0x2e) // 46
#define SIZECENTRALHEADERLOCATOR (0x14) // 20
#define SIZECENTRALDIRITEM (0x2e)
#define SIZEZIPLOCALHEADER (0x1e)
#ifndef BUFREADCOMMENT
# define BUFREADCOMMENT (0x400)
#endif
/***************************************************************************/
typedef struct mz_zip_s
{
mz_zip_file file_info;
mz_zip_crypt crypt_info;
mz_zip_compress compress_info;
void *stream; // main stream
void *cd_stream; // memory stream for central directory
void *compress_stream; // compression stream
void *crc32_stream; // crc32 stream
void *crypt_stream; // encryption stream
uint64_t pos_local_header; // offset of the local header of the file currently writing
uint64_t add_position_when_writting_offset;
uint64_t number_entry;
uint16_t entry_opened; // 1 if a file in the zip is currently writ.
uint64_t disk_size; // size of each disk
uint32_t number_disk; // number of the current disk, used for spanning ZIP
uint32_t number_disk_with_CD; // number the the disk with central dir, used for spanning ZIP
#ifndef NO_ADDFILEINEXISTINGZIP
char *comment;
#endif
} mz_zip;
/***************************************************************************/
// Locate the central directory of a zip file (at the end, just before the global comment)
static uint64_t mz_zip_search_cd(void *stream)
{
uint8_t buf[BUFREADCOMMENT + 4];
uint64_t file_size = 0;
uint64_t back_read = 4;
uint64_t max_back = UINT16_MAX; // maximum size of global comment
uint64_t pos_found = 0;
uint32_t read_size = 0;
uint64_t read_pos = 0;
uint32_t i = 0;
if (mz_stream_seek(stream, 0, MZ_STREAM_SEEK_END) != MZ_OK)
return 0;
file_size = mz_stream_tell(stream);
if (max_back > file_size)
max_back = file_size;
while (back_read < max_back)
{
if (back_read + BUFREADCOMMENT > max_back)
back_read = max_back;
else
back_read += BUFREADCOMMENT;
read_pos = file_size-back_read;
read_size = ((BUFREADCOMMENT + 4) < (file_size - read_pos)) ?
(BUFREADCOMMENT + 4) : (uint32_t)(file_size - read_pos);
if (mz_stream_seek(stream, read_pos, MZ_STREAM_SEEK_SET) != MZ_OK)
break;
if (mz_stream_read(stream, buf, read_size) != read_size)
break;
for (i = read_size - 3; (i--) > 0;)
{
if ((*(buf + i)) == (ENDHEADERMAGIC & 0xff) &&
(*(buf + i + 1)) == (ENDHEADERMAGIC >> 8 & 0xff) &&
(*(buf + i + 2)) == (ENDHEADERMAGIC >> 16 & 0xff) &&
(*(buf + i + 3)) == (ENDHEADERMAGIC >> 24 & 0xff))
{
pos_found = read_pos + i;
break;
}
}
if (pos_found != 0)
break;
}
return pos_found;
}
// Locate the central directory 64 of a zip file (at the end, just before the global comment)
static uint64_t mz_zip_search_zip64_cd(void *stream, const uint64_t endcentraloffset)
{
uint64_t offset = 0;
uint32_t value32 = 0;
// Zip64 end of central directory locator
if (mz_stream_seek(stream, endcentraloffset - SIZECENTRALHEADERLOCATOR, MZ_STREAM_SEEK_SET) != MZ_OK)
return 0;
// Read locator signature
if (mz_stream_read_uint32(stream, &value32) != MZ_OK)
return 0;
if (value32 != ZIP64ENDLOCHEADERMAGIC)
return 0;
// Number of the disk with the start of the zip64 end of central directory
if (mz_stream_read_uint32(stream, &value32) != MZ_OK)
return 0;
// Relative offset of the zip64 end of central directory record
if (mz_stream_read_uint64(stream, &offset) != MZ_OK)
return 0;
// Total number of disks
if (mz_stream_read_uint32(stream, &value32) != MZ_OK)
return 0;
// Goto end of central directory record
if (mz_stream_seek(stream, offset, MZ_STREAM_SEEK_SET) != 0)
return 0;
// The signature
if (mz_stream_read_uint32(stream, &value32) != MZ_OK)
return 0;
if (value32 != ZIP64ENDHEADERMAGIC)
return 0;
return offset;
}
extern void* ZEXPORT mz_zip_open(uint8_t open_existing, uint64_t disk_size, void *stream)
{
mz_zip *zip = NULL;
#ifndef NO_ADDFILEINEXISTINGZIP
uint64_t byte_before_the_zipfile = 0; // byte before the zip file, (>0 for sfx)
uint64_t size_central_dir = 0; // size of the central directory
uint64_t offset_central_dir = 0; // offset of start of central directory
uint64_t number_entry_CD = 0; // total number of entries in the central dir
uint64_t number_entry = 0;
uint64_t central_pos = 0;
uint16_t value16 = 0;
uint32_t value32 = 0;
uint64_t value64 = 0;
uint16_t comment_size = 0;
#endif
int16_t err = MZ_OK;
zip = (mz_zip*)malloc(sizeof(mz_zip));
if (zip == NULL)
return NULL;
memset(zip, 0, sizeof(mz_zip));
zip->stream = stream;
zip->disk_size = disk_size;
mz_stream_mem_create(&zip->cd_stream);
mz_stream_mem_set_grow(zip->cd_stream, 1);
mz_stream_mem_open(zip->cd_stream, NULL, MZ_STREAM_MODE_CREATE);
#ifndef NO_ADDFILEINEXISTINGZIP
// Add file in a zip file
if (open_existing)
{
// Read and cache central directory records
central_pos = mz_zip_search_cd(zip->stream);
// Disable to allow appending to empty ZIP archive (must be standard zip, not zip64)
// if (central_pos == 0)
// err = MZ_FORMAT_ERROR;
if (err == MZ_OK)
{
// Read end of central directory info
if (mz_stream_seek(zip->stream, central_pos, MZ_STREAM_SEEK_SET) != MZ_OK)
err = MZ_STREAM_ERROR;
// The signature, already checked
if (mz_stream_read_uint32(zip->stream, &value32) != MZ_OK)
err = MZ_STREAM_ERROR;
// Number of this disk
if (mz_stream_read_uint16(zip->stream, &value16) != MZ_OK)
err = MZ_STREAM_ERROR;
zip->number_disk = value16;
// Number of the disk with the start of the central directory
if (mz_stream_read_uint16(zip->stream, &value16) != MZ_OK)
err = MZ_STREAM_ERROR;
zip->number_disk_with_CD = value16;
// Total number of entries in the central dir on this disk
number_entry = 0;
if (mz_stream_read_uint16(zip->stream, &value16) != MZ_OK)
err = MZ_STREAM_ERROR;
else
number_entry = value16;
// Total number of entries in the central dir
number_entry_CD = 0;
if (mz_stream_read_uint16(zip->stream, &value16) != MZ_OK)
err = MZ_STREAM_ERROR;
else
number_entry_CD = value16;
if (number_entry_CD != number_entry)
err = MZ_FORMAT_ERROR;
// Size of the central directory
size_central_dir = 0;
if (mz_stream_read_uint32(zip->stream, &value32) != MZ_OK)
err = MZ_STREAM_ERROR;
else
size_central_dir = value32;
// Offset of start of central directory with respect to the starting disk number
offset_central_dir = 0;
if (mz_stream_read_uint32(zip->stream, &value32) != MZ_OK)
err = MZ_STREAM_ERROR;
else
offset_central_dir = value32;
// Zipfile global comment length
if (mz_stream_read_uint16(zip->stream, &comment_size) != MZ_OK)
err = MZ_STREAM_ERROR;
if ((err == MZ_OK) && ((number_entry_CD == UINT16_MAX) || (offset_central_dir == UINT32_MAX)))
{
// Format should be Zip64, as the central directory or file size is too large
central_pos = mz_zip_search_zip64_cd(zip->stream, central_pos);
if (central_pos)
{
if (mz_stream_seek(zip->stream, central_pos, MZ_STREAM_SEEK_SET) != 0)
err = MZ_STREAM_ERROR;
// The signature, already checked
if (mz_stream_read_uint32(zip->stream, &value32) != MZ_OK)
err = MZ_STREAM_ERROR;
// Size of zip64 end of central directory record
if (mz_stream_read_uint64(zip->stream, &value64) != MZ_OK)
err = MZ_STREAM_ERROR;
// Version made by
if (mz_stream_read_uint16(zip->stream, &value16) != MZ_OK)
err = MZ_STREAM_ERROR;
// Version needed to extract
if (mz_stream_read_uint16(zip->stream, &value16) != MZ_OK)
err = MZ_STREAM_ERROR;
// Number of this disk
if (mz_stream_read_uint32(zip->stream, &zip->number_disk) != MZ_OK)
err = MZ_STREAM_ERROR;
// Number of the disk with the start of the central directory
if (mz_stream_read_uint32(zip->stream, &zip->number_disk_with_CD) != MZ_OK)
err = MZ_STREAM_ERROR;
// Total number of entries in the central directory on this disk
if (mz_stream_read_uint64(zip->stream, &number_entry) != MZ_OK)
err = MZ_STREAM_ERROR;
// Total number of entries in the central directory
if (mz_stream_read_uint64(zip->stream, &number_entry_CD) != MZ_OK)
err = MZ_STREAM_ERROR;
if (number_entry_CD != number_entry)
err = MZ_FORMAT_ERROR;
// Size of the central directory
if (mz_stream_read_uint64(zip->stream, &size_central_dir) != MZ_OK)
err = MZ_STREAM_ERROR;
// Offset of start of central directory with respect to the starting disk number
if (mz_stream_read_uint64(zip->stream, &offset_central_dir) != MZ_OK)
err = MZ_STREAM_ERROR;
}
else
{
err = MZ_FORMAT_ERROR;
}
}
}
if (err == MZ_OK)
{
if (central_pos < offset_central_dir + size_central_dir)
err = MZ_FORMAT_ERROR;
}
if ((err == MZ_OK) && (comment_size > 0))
{
zip->comment = (char *)malloc(comment_size + 1);
if (zip->comment)
{
if (mz_stream_read(zip->stream, zip->comment, comment_size) != comment_size)
err = MZ_STREAM_ERROR;
zip->comment[comment_size] = 0;
}
}
if (err == MZ_OK)
{
byte_before_the_zipfile = central_pos - (offset_central_dir + size_central_dir);
zip->add_position_when_writting_offset = byte_before_the_zipfile;
// Store central directory in memory
if (mz_stream_seek(zip->stream, offset_central_dir + byte_before_the_zipfile, MZ_STREAM_SEEK_SET) != MZ_OK)
err = MZ_STREAM_ERROR;
if (mz_stream_copy(zip->cd_stream, zip->stream, (uint32_t)size_central_dir) != MZ_OK)
err = MZ_STREAM_ERROR;
zip->number_entry = number_entry_CD;
if (mz_stream_seek(zip->stream, offset_central_dir + byte_before_the_zipfile, MZ_STREAM_SEEK_SET) != MZ_OK)
err = MZ_STREAM_ERROR;
}
}
#endif
if (err != MZ_OK)
{
mz_stream_close(zip->cd_stream);
mz_stream_delete(&zip->cd_stream);
#ifndef NO_ADDFILEINEXISTINGZIP
if (zip->comment)
free(zip->comment);
#endif
free(zip);
return NULL;
}
return zip;
}
extern int ZEXPORT mz_zip_get_global_comment(void *handle, const char **global_comment)
{
mz_zip *zip = NULL;
if (handle == NULL || global_comment == NULL)
return MZ_PARAM_ERROR;
zip = (mz_zip*)handle;
*global_comment = zip->comment;
return MZ_OK;
}
extern int ZEXPORT mz_zip_entry_open(void *handle, const mz_zip_file *file_info,
const mz_zip_compress *compress_info, const mz_zip_crypt *crypt_info)
{
mz_zip *zip = NULL;
uint16_t filename_size = 0;
uint16_t version_needed = 0;
int16_t err = MZ_OK;
#ifdef NOCRYPT
if (password != NULL)
return MZ_PARAM_ERROR;
#endif
if (handle == NULL)
return MZ_PARAM_ERROR;
if (file_info == NULL || file_info->filename == NULL)
return MZ_PARAM_ERROR;
if (compress_info == NULL)
return MZ_PARAM_ERROR;
if (crypt_info == NULL)
return MZ_PARAM_ERROR;
switch (compress_info->method)
{
case MZ_METHOD_RAW:
case MZ_METHOD_DEFLATE:
#ifdef HAVE_BZIP2
case MZ_METHOD_BZIP2:
#endif
#if HAVE_LZMA
case MZ_METHOD_LZMA:
#endif
err = MZ_OK;
break;
default:
return MZ_PARAM_ERROR;
}
zip = (mz_zip*)handle;
if (zip->entry_opened == 1)
{
err = mz_zip_entry_close(handle);
if (err != MZ_OK)
return err;
}
memcpy(&zip->file_info, file_info, sizeof(mz_zip_file));
memcpy(&zip->crypt_info, crypt_info, sizeof(mz_zip_crypt));
memcpy(&zip->compress_info, compress_info, sizeof(mz_zip_compress));
zip->file_info.flag |= 8; // data descriptor
#ifdef HAVE_LZMA
zip->file_info.flag |= 2; // end of stream marker
#endif
if ((zip->compress_info.level == 8) || (zip->compress_info.level == 9))
zip->file_info.flag |= 2;
if (zip->compress_info.level == 2)
zip->file_info.flag |= 4;
if (zip->compress_info.level == 1)
zip->file_info.flag |= 6;
if (zip->crypt_info.password != NULL)
zip->file_info.flag |= 1;
else
zip->file_info.flag &= ~1;
filename_size = (uint16_t)strlen(zip->file_info.filename);
zip->pos_local_header = mz_stream_tell(zip->stream);
if (zip->pos_local_header >= UINT32_MAX)
zip->file_info.zip64 = 1;
// Write the local header
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, (uint32_t)LOCALHEADERMAGIC);
version_needed = 20;
if (zip->file_info.zip64)
version_needed = 45;
#ifdef HAVE_AES
if ((zip->file_info.flag & 1) && (zip->crypt_info.aes))
version_needed = 51;
#endif
#ifdef HAVE_LZMA
if (zip->compress_info.method == MZ_METHOD_LZMA)
version_needed = 63;
#endif
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, version_needed);
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, zip->file_info.flag);
if (err == MZ_OK)
{
#ifdef HAVE_AES
if ((zip->file_info.flag & 1) && (zip->crypt_info.aes))
err = mz_stream_write_uint16(zip->stream, MZ_AES_METHOD);
else
#endif
err = mz_stream_write_uint16(zip->stream, zip->compress_info.method);
}
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, zip->file_info.dos_date);
// CRC & compressed size & uncompressed size is in data descriptor
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, 0); // crc 32
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, 0); // compressed size
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, 0); // uncompressed size
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, filename_size);
if (err == MZ_OK)
{
uint16_t extrafield_size = zip->file_info.extrafield_local_size;
#ifdef HAVE_AES
if ((zip->file_info.flag & 1) && (zip->crypt_info.aes))
extrafield_size += 4 + 7;
#endif
err = mz_stream_write_uint16(zip->stream, extrafield_size);
}
if (err == MZ_OK)
{
if (mz_stream_write(zip->stream, zip->file_info.filename, filename_size) != filename_size)
err = MZ_STREAM_ERROR;
}
if (err == MZ_OK)
{
if (mz_stream_write(zip->stream, zip->file_info.extrafield_local,
zip->file_info.extrafield_local_size) != zip->file_info.extrafield_local_size)
err = MZ_STREAM_ERROR;
}
#ifdef HAVE_AES
// Write the AES extended info
if ((err == MZ_OK) && (zip->file_info.flag & 1) && (zip->crypt_info.aes))
{
err = mz_stream_write_uint16(zip->stream, 0x9901);
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, 7);
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, MZ_AES_VERSION);
if (err == MZ_OK)
err = mz_stream_write_uint8(zip->stream, 'A');
if (err == MZ_OK)
err = mz_stream_write_uint8(zip->stream, 'E');
if (err == MZ_OK)
err = mz_stream_write_uint8(zip->stream, MZ_AES_ENCRYPTIONMODE);
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, zip->compress_info.method);
}
#endif
#ifndef NOCRYPT
if (err == Z_OK)
{
if (zip->crypt_info.password == NULL)
{
mz_stream_passthru_create(&zip->crypt_stream);
mz_stream_set_base(zip->crypt_stream, zip->stream);
}
#ifdef HAVE_AES
else if (zip->crypt_info.aes)
{
mz_stream_aes_create(&zip->crypt_stream);
mz_stream_aes_set_password(zip->crypt_stream, zip->crypt_info.password);
mz_stream_set_base(zip->crypt_stream, zip->stream);
if (mz_stream_open(zip->crypt_stream, NULL, MZ_STREAM_MODE_WRITE) != MZ_OK)
err = MZ_INTERNAL_ERROR;
}
else
#endif
{
uint8_t verify1 = 0;
uint8_t verify2 = 0;
// Info-ZIP modification to ZipCrypto format:
// If bit 3 of the general purpose bit flag is set, it uses high byte of 16-bit File Time.
verify1 = (uint8_t)((zip->file_info.dos_date >> 16) & 0xff);
verify2 = (uint8_t)((zip->file_info.dos_date >> 8) & 0xff);
mz_stream_crypt_create(&zip->crypt_stream);
mz_stream_crypt_set_password(zip->crypt_stream, zip->crypt_info.password);
mz_stream_crypt_set_verify(zip->crypt_stream, verify1, verify2);
mz_stream_set_base(zip->crypt_stream, zip->stream);
if (mz_stream_open(zip->crypt_stream, NULL, MZ_STREAM_MODE_WRITE) != MZ_OK)
err = MZ_INTERNAL_ERROR;
}
}
#endif
if (err == MZ_OK)
{
if (zip->compress_info.method == 0) // raw
{
mz_stream_passthru_create(&zip->compress_stream);
mz_stream_set_base(zip->compress_stream, zip->crypt_stream);
}
else if (zip->compress_info.method == MZ_METHOD_DEFLATE)
{
mz_stream_zlib_create(&zip->compress_stream);
mz_stream_zlib_set_level(zip->compress_stream, zip->compress_info.level);
mz_stream_zlib_set_window_bits(zip->compress_stream, zip->compress_info.window_bits);
mz_stream_zlib_set_mem_level(zip->compress_stream, zip->compress_info.mem_level);
mz_stream_zlib_set_strategy(zip->compress_stream, zip->compress_info.strategy);
mz_stream_set_base(zip->compress_stream, zip->crypt_stream);
if (mz_stream_open(zip->compress_stream, NULL, MZ_STREAM_MODE_WRITE) != MZ_OK)
err = MZ_INTERNAL_ERROR;
}
#ifdef HAVE_BZIP2
else if (zip->compress_info.method == MZ_METHOD_BZIP2)
{
mz_stream_bzip_create(&zip->compress_stream);
mz_stream_bzip_set_level(zip->compress_stream, zip->compress_info.level);
mz_stream_set_base(zip->compress_stream, zip->crypt_stream);
if (mz_stream_open(zip->compress_stream, NULL, MZ_STREAM_MODE_WRITE) != MZ_OK)
err = MZ_INTERNAL_ERROR;
}
#endif
#ifdef HAVE_LZMA
else if (zip->compress_info.method == MZ_METHOD_LZMA)
{
mz_stream_lzma_create(&zip->compress_stream);
mz_stream_lzma_set_level(zip->compress_stream, zip->compress_info.level);
mz_stream_set_base(zip->compress_stream, zip->crypt_stream);
if (mz_stream_open(zip->compress_stream, NULL, MZ_STREAM_MODE_WRITE) != MZ_OK)
err = MZ_INTERNAL_ERROR;
}
#endif
}
if (err == Z_OK)
{
mz_stream_crc32_create(&zip->crc32_stream);
mz_stream_set_base(zip->crc32_stream, zip->compress_stream);
if (mz_stream_open(zip->crc32_stream, NULL, MZ_STREAM_MODE_WRITE) != MZ_OK)
err = MZ_INTERNAL_ERROR;
}
if (err == Z_OK)
zip->entry_opened = 1;
return err;
}
extern int ZEXPORT mz_zip_entry_write(void *handle, const void *buf, uint32_t len)
{
mz_zip *zip = NULL;
if (handle == NULL)
return MZ_PARAM_ERROR;
zip = (mz_zip*)handle;
if (zip->entry_opened == 0)
return MZ_PARAM_ERROR;
if (mz_stream_write(zip->crc32_stream, buf, len) == MZ_STREAM_ERROR)
return MZ_STREAM_ERROR;
return MZ_OK;
}
extern int ZEXPORT mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size, uint32_t crc32)
{
mz_zip *zip = NULL;
uint64_t compressed_size = 0;
uint16_t extrafield_size = 0;
uint16_t extrafield_zip64_size = 0;
uint16_t filename_size = 0;
uint16_t comment_size = 0;
uint16_t version_needed = 0;
int16_t err = MZ_OK;
if (handle == NULL)
return MZ_PARAM_ERROR;
zip = (mz_zip*)handle;
if (zip->entry_opened == 0)
return MZ_PARAM_ERROR;
mz_stream_close(zip->compress_stream);
if ((zip->compress_info.method != 0) || (uncompressed_size == 0))
{
crc32 = mz_stream_crc32_get_value(zip->crc32_stream);
uncompressed_size = mz_stream_get_total_out(zip->crc32_stream);
compressed_size = mz_stream_get_total_out(zip->compress_stream);
}
if (zip->file_info.flag & 1)
{
mz_stream_set_base(zip->crypt_stream, zip->stream);
err = mz_stream_close(zip->crypt_stream);
if ((zip->compress_info.method != 0) || (uncompressed_size == 0))
compressed_size = mz_stream_get_total_out(zip->crypt_stream);
mz_stream_delete(&zip->crypt_stream);
}
mz_stream_delete(&zip->compress_stream);
mz_stream_crc32_delete(&zip->crc32_stream);
// Write data descriptor
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, (uint32_t)DATADESCRIPTORMAGIC);
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, crc32);
if (err == MZ_OK)
{
if (zip->file_info.zip64)
err = mz_stream_write_uint64(zip->stream, compressed_size);
else
err = mz_stream_write_uint32(zip->stream, (uint32_t)compressed_size);
}
if (err == MZ_OK)
{
if (zip->file_info.zip64)
err = mz_stream_write_uint64(zip->stream, uncompressed_size);
else
err = mz_stream_write_uint32(zip->stream, (uint32_t)uncompressed_size);
}
// Write central directory header
// Calculate extra field size
version_needed = 20;
extrafield_size = zip->file_info.extrafield_global_size;
if (zip->file_info.zip64)
{
version_needed = 45;
extrafield_zip64_size += 4;
if (uncompressed_size >= UINT32_MAX)
extrafield_zip64_size += 8;
if (compressed_size >= UINT32_MAX)
extrafield_zip64_size += 8;
if (zip->pos_local_header >= UINT32_MAX)
extrafield_zip64_size += 8;
extrafield_size += extrafield_zip64_size;
}
#ifdef HAVE_AES
if ((zip->file_info.flag & 1) && (zip->crypt_info.aes))
{
version_needed = 51;
extrafield_size += 4 + 7;
}
#endif
#ifdef HAVE_LZMA
if (zip->compress_info.method == MZ_METHOD_LZMA)
version_needed = 63;
#endif
filename_size = (uint16_t)strlen(zip->file_info.filename);
if (zip->file_info.comment != NULL)
comment_size = (uint16_t)strlen(zip->file_info.comment);
mz_stream_write_uint32(zip->cd_stream, (uint32_t)CENTRALHEADERMAGIC);
mz_stream_write_uint16(zip->cd_stream, zip->file_info.version_madeby);
mz_stream_write_uint16(zip->cd_stream, version_needed);
mz_stream_write_uint16(zip->cd_stream, zip->file_info.flag);
mz_stream_write_uint16(zip->cd_stream, zip->compress_info.method);
mz_stream_write_uint32(zip->cd_stream, zip->file_info.dos_date);
mz_stream_write_uint32(zip->cd_stream, crc32); // crc
if (compressed_size >= UINT32_MAX) // compr size
mz_stream_write_uint32(zip->cd_stream, UINT32_MAX);
else
mz_stream_write_uint32(zip->cd_stream, (uint32_t)compressed_size);
if (uncompressed_size >= UINT32_MAX) // uncompr size
mz_stream_write_uint32(zip->cd_stream, UINT32_MAX);
else
mz_stream_write_uint32(zip->cd_stream, (uint32_t)uncompressed_size);
mz_stream_write_uint16(zip->cd_stream, filename_size);
mz_stream_write_uint16(zip->cd_stream, extrafield_size);
mz_stream_write_uint16(zip->cd_stream, comment_size);
mz_stream_write_uint16(zip->cd_stream, (uint16_t)zip->number_disk); // disk nm start
mz_stream_write_uint16(zip->cd_stream, zip->file_info.internal_fa);
mz_stream_write_uint32(zip->cd_stream, zip->file_info.external_fa);
if (zip->pos_local_header >= UINT32_MAX)
mz_stream_write_uint32(zip->cd_stream, UINT32_MAX);
else
mz_stream_write_uint32(zip->cd_stream,
(uint32_t)(zip->pos_local_header - zip->add_position_when_writting_offset));
mz_stream_write(zip->cd_stream, zip->file_info.filename, filename_size);
mz_stream_write(zip->cd_stream, zip->file_info.extrafield_global, zip->file_info.extrafield_global_size);
// Add ZIP64 extra info header to central directory
if (zip->file_info.zip64)
{
mz_stream_write_uint16(zip->cd_stream, 0x0001);
mz_stream_write_uint16(zip->cd_stream, extrafield_zip64_size);
if (uncompressed_size >= UINT32_MAX)
mz_stream_write_uint64(zip->cd_stream, uncompressed_size);
if (compressed_size >= UINT32_MAX)
mz_stream_write_uint64(zip->cd_stream, compressed_size);
if (zip->pos_local_header >= UINT32_MAX)
mz_stream_write_uint64(zip->cd_stream, zip->pos_local_header);
}
#ifdef HAVE_AES
// Write AES extra info header to central directory
if ((zip->file_info.flag & 1) && (zip->crypt_info.aes))
{
mz_stream_write_uint16(zip->cd_stream, 0x9901);
mz_stream_write_uint16(zip->cd_stream, 7);
mz_stream_write_uint16(zip->cd_stream, MZ_AES_VERSION);
mz_stream_write_uint8(zip->cd_stream, 'A');
mz_stream_write_uint8(zip->cd_stream, 'E');
mz_stream_write_uint8(zip->cd_stream, MZ_AES_ENCRYPTIONMODE);
mz_stream_write_uint16(zip->cd_stream, zip->compress_info.method);
}
#endif
// Write comment
if (zip->file_info.comment != NULL)
{
mz_stream_write(zip->cd_stream, zip->file_info.comment, comment_size);
free(zip->comment);
}
zip->number_entry += 1;
zip->entry_opened = 0;
return err;
}
extern int ZEXPORT mz_zip_entry_close(void *handle)
{
return mz_zip_entry_close_raw(handle, 0, 0);
}
extern int ZEXPORT mz_zip_close(void *handle, const char *global_comment, uint16_t version_madeby)
{
mz_zip *zip = NULL;
uint32_t size_centraldir = 0;
uint16_t comment_size = 0;
uint64_t centraldir_pos_inzip = 0;
uint64_t pos = 0;
uint64_t cd_pos = 0;
int16_t err = MZ_OK;
if (handle == NULL)
return MZ_PARAM_ERROR;
zip = (mz_zip*)handle;
if (zip->entry_opened == 1)
{
err = mz_zip_entry_close(handle);
if (err != MZ_OK)
return err;
}
#ifndef NO_ADDFILEINEXISTINGZIP
if (global_comment == NULL)
global_comment = zip->comment;
#endif
centraldir_pos_inzip = mz_stream_tell(zip->stream);
mz_stream_seek(zip->cd_stream, 0, MZ_STREAM_SEEK_END);
size_centraldir = (uint32_t)mz_stream_tell(zip->cd_stream);
mz_stream_seek(zip->cd_stream, 0, MZ_STREAM_SEEK_SET);
err = mz_stream_copy(zip->stream, zip->cd_stream, size_centraldir);
mz_stream_close(zip->cd_stream);
mz_stream_delete(&zip->cd_stream);
pos = centraldir_pos_inzip - zip->add_position_when_writting_offset;
// Write the ZIP64 central directory header
if (pos >= UINT32_MAX || zip->number_entry > UINT32_MAX)
{
uint64_t zip64_eocd_pos_inzip = mz_stream_tell(zip->stream);
err = mz_stream_write_uint32(zip->stream, (uint32_t)ZIP64ENDHEADERMAGIC);
// Size of this 'zip64 end of central directory'
if (err == MZ_OK)
err = mz_stream_write_uint64(zip->stream, (uint64_t)44);
// Version made by
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, version_madeby);
// Version needed
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, (uint16_t)45);
// Number of this disk
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, zip->number_disk_with_CD);
// Number of the disk with the start of the central directory
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, zip->number_disk_with_CD);
// Total number of entries in the central dir on this disk
if (err == MZ_OK)
err = mz_stream_write_uint64(zip->stream, zip->number_entry);
// Total number of entries in the central dir
if (err == MZ_OK)
err = mz_stream_write_uint64(zip->stream, zip->number_entry);
// Size of the central directory
if (err == MZ_OK)
err = mz_stream_write_uint64(zip->stream, (uint64_t)size_centraldir);
if (err == MZ_OK)
{
// Offset of start of central directory with respect to the starting disk number
cd_pos = centraldir_pos_inzip - zip->add_position_when_writting_offset;
err = mz_stream_write_uint64(zip->stream, cd_pos);
}
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, (uint32_t)ZIP64ENDLOCHEADERMAGIC);
// Number of the disk with the start of the central directory
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, zip->number_disk_with_CD);
// Relative offset to the end of zip64 central directory
if (err == MZ_OK)
{
cd_pos = zip64_eocd_pos_inzip - zip->add_position_when_writting_offset;
err = mz_stream_write_uint64(zip->stream, cd_pos);
}
// Number of the disk with the start of the central directory
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, zip->number_disk_with_CD + 1);
}
// Write the central directory header
// Signature
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, (uint32_t)ENDHEADERMAGIC);
// Number of this disk
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, (uint16_t)zip->number_disk_with_CD);
// Number of the disk with the start of the central directory
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, (uint16_t)zip->number_disk_with_CD);
// Total number of entries in the central dir on this disk
if (err == MZ_OK)
{
if (zip->number_entry >= UINT16_MAX)
err = mz_stream_write_uint16(zip->stream, UINT16_MAX);
else
err = mz_stream_write_uint16(zip->stream, (uint16_t)zip->number_entry);
}
// Total number of entries in the central dir
if (err == MZ_OK)
{
if (zip->number_entry >= UINT16_MAX)
err = mz_stream_write_uint16(zip->stream, UINT16_MAX);
else
err = mz_stream_write_uint16(zip->stream, (uint16_t)zip->number_entry);
}
// Size of the central directory
if (err == MZ_OK)
err = mz_stream_write_uint32(zip->stream, size_centraldir);
// Offset of start of central directory with respect to the starting disk number
if (err == MZ_OK)
{
cd_pos = centraldir_pos_inzip - zip->add_position_when_writting_offset;
if (pos >= UINT32_MAX)
err = mz_stream_write_uint32(zip->stream, UINT32_MAX);
else
err = mz_stream_write_uint32(zip->stream, (uint32_t)cd_pos);
}
// Write global comment
if (global_comment != NULL)
comment_size = (uint16_t)strlen(global_comment);
if (err == MZ_OK)
err = mz_stream_write_uint16(zip->stream, comment_size);
if (err == MZ_OK)
{
if (mz_stream_write(zip->stream, global_comment, comment_size) != comment_size)
err = MZ_STREAM_ERROR;
}
#ifndef NO_ADDFILEINEXISTINGZIP
if (zip->comment)
free(zip->comment);
#endif
free(zip);
return err;
}

View File

@@ -0,0 +1,113 @@
/* mz_zip.h -- Zip manipulation
Version 2.0.0, October 4th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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_ZIP_H
#define _MZ_ZIP_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
# include "zlib.h"
#endif
#include "mz_strm.h"
/***************************************************************************/
#ifndef MZ_METHOD
# define MZ_METHOD_RAW (0)
# define MZ_METHOD_DEFLATE (8)
# define MZ_METHOD_BZIP2 (12)
# define MZ_METHOD_LZMA (14)
#endif
#define MZ_COMPRESS_LEVEL_DEFAULT (-1)
#define MZ_COMPRESS_WINDOW_BITS_DEFAULT (0)
#define MZ_COMPRESS_MEM_LEVEL_DEFAULT (0)
#define MZ_COMPRESS_STRATEGY_DEFAULT (-1)
/***************************************************************************/
typedef struct mz_zip_file_s
{
uint32_t dos_date; // ms-dos date and time
uint16_t internal_fa; // internal file attributes
uint32_t external_fa; // external file attributes
const uint8_t *extrafield_local; // extra fields in local header
uint16_t extrafield_local_size; // size of additional extra fields in local header
const uint8_t *extrafield_global; // extra fields in global header
uint16_t extrafield_global_size; // size of extra fields in global header
uint16_t version_madeby; // version made by
const char *comment; // file comment
const char *filename; // filename
uint8_t zip64; // enable zip64 extensions if 1
uint16_t flag; // base flag value
} mz_zip_file;
typedef struct mz_zip_compress_s
{
uint16_t method; // compression method
int level; // compression level
int window_bits; // deflate window bits
int mem_level; // deflate memory level
int strategy; // deflate strategy
} mz_zip_compress;
typedef struct mz_zip_crypt_s
{
const char *password; // encryption password
#if defined(HAVE_AES)
uint8_t aes; // enable winzip aes encryption if 1
#endif
} mz_zip_crypt;
/***************************************************************************/
extern void* ZEXPORT mz_zip_open(uint8_t open_existing, uint64_t disk_size, void *stream);
// Create a zip file
//
// NOTE: There is no delete function into a zip file. If you want delete file in a zip file,
// you must open a zip file, and create another. You can use RAW reading and writing to copy
// the file you did not want delete.
extern int ZEXPORT mz_zip_get_global_comment(void *handle, const char **global_comment);
// Gets the global comments if opening an existing zip
extern int ZEXPORT mz_zip_entry_open(void *handle, const mz_zip_file *file_info,
const mz_zip_compress *compress_info, const mz_zip_crypt *crypt_info);
// Open a file in the ZIP for writing
extern int ZEXPORT mz_zip_entry_write(void *handle, const void *buf, uint32_t len);
// Write data in the zip file
extern int ZEXPORT mz_zip_entry_close(void *handle);
// Close the current file in the zip file
extern int ZEXPORT mz_zip_entry_close_raw(void *handle, uint64_t uncompressed_size, uint32_t crc32);
// Close the current file in the zip file where raw is compressed data
extern int ZEXPORT mz_zip_close(void *handle, const char *global_comment, uint16_t version_madeby);
// Close the zip file
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* _ZIP_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,254 +0,0 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 1.2.0, September 16th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support on both zip and unzip
http://result42.com
Copyright (C) 2007-2008 Even Rouault
Modifications of Unzip for Zip64
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
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 _UNZ_H
#define _UNZ_H
#include "SSZipCommon.h"
#define HAVE_AES
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
#include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
#include "ioapi.h"
#endif
#ifdef HAVE_BZIP2
#include "bzlib.h"
#endif
#define Z_BZIP2ED 12
#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 voidp unzFile;
#endif
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
#define UNZ_BADPASSWORD (-106)
/***************************************************************************/
/* Opening and close a zip file */
extern unzFile ZEXPORT unzOpen(const char *path);
extern unzFile ZEXPORT unzOpen64(const void *path);
/* Open a Zip file.
path should contain the full path (by example, on a Windows XP computer
"c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
return NULL if zipfile cannot be opened or doesn't exist
return unzFile handle if no error
NOTE: The "64" function take a const void *pointer, because the path is just the value passed to the
open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char *does not describe the reality */
extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
/* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */
extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
/* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */
extern int ZEXPORT unzClose(unzFile file);
/* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile,
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no error */
extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info);
extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info);
/* Write info about the ZipFile in the *pglobal_info structure.
return UNZ_OK if no error */
extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size);
/* Get the global comment string of the ZipFile, in the comment buffer.
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) */
extern int ZEXPORT unzOpenCurrentFile(unzFile file);
/* Open for reading data the current file in the zipfile.
return UNZ_OK if no error */
extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password);
/* Open for reading data the current file in the zipfile.
password is a crypting password
return UNZ_OK if no error */
extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
/* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress)
if raw==1 *method will receive method of compression, *level will receive level of compression
NOTE: you can set level parameter as NULL (if you did not want known level,
but you CANNOT set method parameter as NULL */
extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
/* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */
extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len);
/* Read bytes from the current file (opened by unzOpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */
extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename,
uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
/* Get Info about the current file
pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file
filename if != NULL, the file name string will be copied in filename
filename_size is the size of the filename buffer
extrafield if != NULL, the extra field information from the central header will be copied in to
extrafield_size is the size of the extraField buffer
comment if != NULL, the comment string of the file will be copied in to
comment_size is the size of the comment buffer */
extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, uint32_t len);
/* Read extra field from the current file (opened by unzOpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf == NULL, it return the size of the local extra field
if buf != NULL, len is the size of the buffer, the extra header is copied in buf.
return number of bytes copied in buf, or (if <0) the error code */
extern int ZEXPORT unzCloseCurrentFile(unzFile file);
/* Close the file in zip opened with unzOpenCurrentFile
return UNZ_CRCERROR if all the file was read but the CRC is not good */
/***************************************************************************/
/* Browse the directory of the zipfile */
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);
extern int ZEXPORT unzGoToFirstFile(unzFile file);
/* Set the current file of the zipfile to the first file.
return UNZ_OK if no error */
extern int ZEXPORT unzGoToFirstFile2(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);
/* Set the current file of the zipfile to the first file and retrieves the current info on success.
Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo.
return UNZ_OK if no error */
extern int ZEXPORT unzGoToNextFile(unzFile file);
/* Set the current file of the zipfile to the next file.
return UNZ_OK if no error
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
extern int ZEXPORT unzGoToNextFile2(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);
/* Set the current file of the zipfile to the next file and retrieves the current
info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo.
return UNZ_OK if no error
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
/* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function.
return UNZ_OK if the file is found (it becomes the current file)
return UNZ_END_OF_LIST_OF_FILE if the file is not found */
/***************************************************************************/
/* 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;
extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos);
extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
typedef struct unz64_file_pos_s
{
uint64_t pos_in_zip_directory; /* offset in zip file directory */
uint64_t num_of_file; /* # of file */
} unz64_file_pos;
extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos);
extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos);
extern int32_t ZEXPORT unzGetOffset(unzFile file);
extern int64_t ZEXPORT unzGetOffset64(unzFile file);
/* Get the current file offset */
extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos);
extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos);
/* Set the current file offset */
extern int32_t ZEXPORT unzTell(unzFile file);
extern int64_t ZEXPORT unzTell64(unzFile file);
/* return current position in uncompressed data */
extern int ZEXPORT unzSeek(unzFile file, uint32_t offset, int origin);
extern int ZEXPORT unzSeek64(unzFile file, uint64_t offset, int origin);
/* Seek within the uncompressed data if compression method is storage */
extern int ZEXPORT unzEndOfFile(unzFile file);
/* return 1 if the end of file was reached, 0 elsewhere */
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* _UNZ_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,214 +0,0 @@
/* zip.h -- IO on .zip files using zlib
Version 1.2.0, September 16th, 2017
part of the MiniZip project
Copyright (C) 2012-2017 Nathan Moinvaziri
https://github.com/nmoinvaz/minizip
Copyright (C) 2009-2010 Mathias Svensson
Modifications for Zip64 support
http://result42.com
Copyright (C) 1998-2010 Gilles Vollant
http://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 _ZIP_H
#define _ZIP_H
#define HAVE_AES
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _ZLIB_H
# include "zlib.h"
#endif
#ifndef _ZLIBIOAPI_H
# include "ioapi.h"
#endif
#ifdef HAVE_BZIP2
# include "bzlib.h"
#endif
#define Z_BZIP2ED 12
#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 voidp zipFile;
#endif
#define ZIP_OK (0)
#define ZIP_EOF (0)
#define ZIP_ERRNO (Z_ERRNO)
#define ZIP_PARAMERROR (-102)
#define ZIP_BADZIPFILE (-103)
#define ZIP_INTERNALERROR (-104)
#ifndef DEF_MEM_LEVEL
# if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
# else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
# endif
#endif
typedef struct
{
uint32_t dos_date;
uint16_t internal_fa; /* internal file attributes 2 bytes */
uint32_t external_fa; /* external file attributes 4 bytes */
} zip_fileinfo;
#define APPEND_STATUS_CREATE (0)
#define APPEND_STATUS_CREATEAFTER (1)
#define APPEND_STATUS_ADDINZIP (2)
/***************************************************************************/
/* Writing a zip file */
extern zipFile ZEXPORT zipOpen(const char *path, int append);
extern zipFile ZEXPORT zipOpen64(const void *path, int append);
/* Create a zipfile.
path should contain the full path (by example, on a Windows XP computer
"c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
return NULL if zipfile cannot be opened
return zipFile handle if no error
If the file path exist and append == APPEND_STATUS_CREATEAFTER, the zip
will be created at the end of the file. (useful if the file contain a self extractor code)
If the file path exist and append == APPEND_STATUS_ADDINZIP, we will add files in existing
zip (be sure you don't add file that doesn't exist)
NOTE: There is no delete function into a zipfile. If you want delete file into a zipfile,
you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy
the file you did not want delete. */
extern zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment,
zlib_filefunc_def *pzlib_filefunc_def);
extern zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment,
zlib_filefunc64_def *pzlib_filefunc_def);
extern zipFile ZEXPORT zipOpen3(const char *path, int append, uint64_t disk_size,
const char **globalcomment, zlib_filefunc_def *pzlib_filefunc_def);
/* Same as zipOpen2 but allows specification of spanned zip size */
extern zipFile ZEXPORT zipOpen3_64(const void *path, int append, uint64_t disk_size,
const char **globalcomment, zlib_filefunc64_def *pzlib_filefunc_def);
extern int ZEXPORT 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, uint16_t method, int level);
/* Open a file in the ZIP for writing.
filename : the filename in zip (if NULL, '-' without quote will be used
*zipfi contain supplemental information
extrafield_local buffer to store the local header extra field data, can be NULL
size_extrafield_local size of extrafield_local buffer
extrafield_global buffer to store the global header extra field data, can be NULL
size_extrafield_global size of extrafield_local buffer
comment buffer for comment string
method contain the compression method (0 for store, Z_DEFLATED for deflate)
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
this MUST be '1' if the uncompressed size is >= 0xffffffff. */
extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int zip64);
/* Same as zipOpenNewFileInZip with zip64 support */
extern int ZEXPORT 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, uint16_t method, int level, int raw);
/* Same as zipOpenNewFileInZip, except if raw=1, we write raw file */
extern int ZEXPORT 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, uint16_t method, int level, int raw, int zip64);
/* Same as zipOpenNewFileInZip3 with zip64 support */
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting);
/* Same as zipOpenNewFileInZip2, except
windowBits, memLevel, strategy : see parameter strategy in deflateInit2
password : crypting password (NULL for no crypting)
crc_for_crypting : crc of file to compress (needed for crypting) */
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, int zip64);
/* Same as zipOpenNewFileInZip3 with zip64 support */
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base);
/* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
uint16_t size_extrafield_global, const char *comment, uint16_t method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, ZIP_UNUSED uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64);
/* Same as zipOpenNewFileInZip4 with zip64 support */
extern int ZEXPORT zipOpenNewFileInZip5(zipFile file,
const char *filename,
const zip_fileinfo *zipfi,
const void *extrafield_local,
uint16_t size_extrafield_local,
const void *extrafield_global,
uint16_t size_extrafield_global,
const char *comment,
uint16_t flag_base,
int zip64,
uint16_t method,
int level,
int raw,
int windowBits,
int memLevel,
int strategy,
const char *password,
int aes);
/* Allowing optional aes */
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);
/* Write data in the zipfile */
extern int ZEXPORT zipCloseFileInZip(zipFile file);
/* Close the current file in the zipfile */
extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32);
extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, uint64_t uncompressed_size, uint32_t crc32);
/* Close the current file in the zipfile, for file opened with parameter raw=1 in zipOpenNewFileInZip2
where raw is compressed data. Parameters uncompressed_size and crc32 are value for the uncompressed data. */
extern int ZEXPORT zipClose(zipFile file, const char *global_comment);
/* Close the zipfile */
extern int ZEXPORT zipClose_64(zipFile file, const char *global_comment);
extern int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby);
/* Same as zipClose_64 except version_madeby field */
/***************************************************************************/
#ifdef __cplusplus
}
#endif
#endif /* _ZIP_H */

View File

@@ -1,5 +1,5 @@
PODS:
- SSZipArchive (2.1.1)
- SSZipArchive (2.0.8)
DEPENDENCIES:
- SSZipArchive (from `..`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ..
SPEC CHECKSUMS:
SSZipArchive: 14401ade5f8e82aba1ff03e9f88e9de60937ae60
SSZipArchive: e6ab66e1936fac7e3b5073e9f5eb364d91dfbfc7
PODFILE CHECKSUM: 0dc500eb72745751ccba7677de4da5534fcef36d

View File

@@ -36,6 +36,11 @@ class ViewController: UIViewController {
file3.text = ""
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: IBAction
@IBAction func zipPressed(_: UIButton) {
@@ -43,19 +48,12 @@ class ViewController: UIViewController {
zipPath = tempZipPath()
let password = passwordField.text
let success = SSZipArchive.createZipFile(atPath: zipPath!,
withContentsOfDirectory: sampleDataPath,
keepParentDirectory: false,
compressionLevel: -1,
password: password?.isEmpty == false ? password : nil,
aes: true,
progressHandler: nil)
let success = SSZipArchive.createZipFile(atPath: zipPath!, withContentsOfDirectory: sampleDataPath, withPassword: password?.isEmpty == false ? password : nil)
if success {
print("Success zip")
unzipButton.isEnabled = true
zipButton.isEnabled = false
} else {
print("No success zip")
print("No success")
}
resetButton.isEnabled = true
}
@@ -70,20 +68,12 @@ class ViewController: UIViewController {
}
let password = passwordField.text
let success: Bool = SSZipArchive.unzipFile(atPath: zipPath,
toDestination: unzipPath,
preserveAttributes: true,
overwrite: true,
nestedZipLevel: 1,
password: password?.isEmpty == false ? password : nil,
error: nil,
delegate: nil,
progressHandler: nil,
completionHandler: nil)
if success != false {
print("Success unzip")
} else {
print("No success unzip")
let success: Void? = try? SSZipArchive.unzipFile(atPath: zipPath,
toDestination: unzipPath,
overwrite: true,
password: password?.isEmpty == false ? password : nil)
if success == nil {
print("No success")
return
}
@@ -137,6 +127,7 @@ class ViewController: UIViewController {
} catch {
return nil
}
return url.path
}

View File

@@ -101,6 +101,7 @@
37952C551F63B7A000DD6677 /* pwd2key.h in Headers */ = {isa = PBXBuildFile; fileRef = 373913F81F0009310094DB3B /* pwd2key.h */; };
37952C561F63B7A000DD6677 /* sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = 373913F91F0009310094DB3B /* sha1.c */; };
37952C571F63B7A000DD6677 /* sha1.h in Headers */ = {isa = PBXBuildFile; fileRef = 373913FA1F0009310094DB3B /* sha1.h */; };
37952C581F63B8C400DD6677 /* SSZipArchive+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87ACF3E91D2DAFAD00ED2F7E /* SSZipArchive+Swift.swift */; };
37952C661F63BBBB00DD6677 /* crypt.c in Sources */ = {isa = PBXBuildFile; fileRef = 373913FC1F0009320094DB3B /* crypt.c */; };
37952C671F63BBBB00DD6677 /* ioapi_buf.c in Sources */ = {isa = PBXBuildFile; fileRef = 373913E41F0009310094DB3B /* ioapi_buf.c */; };
37952C681F63BBBB00DD6677 /* ioapi_buf.h in Headers */ = {isa = PBXBuildFile; fileRef = 373913E51F0009310094DB3B /* ioapi_buf.h */; };
@@ -137,10 +138,12 @@
37952C871F63BBC000DD6677 /* sha1.h in Headers */ = {isa = PBXBuildFile; fileRef = 373913FA1F0009310094DB3B /* sha1.h */; };
37952C881F63BBD500DD6677 /* SSZipArchive.h in Headers */ = {isa = PBXBuildFile; fileRef = B423AE481C0DF7950004A2F1 /* SSZipArchive.h */; settings = {ATTRIBUTES = (Public, ); }; };
37952C891F63BBDA00DD6677 /* SSZipArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = B423AE491C0DF7950004A2F1 /* SSZipArchive.m */; };
37952C8A1F63BBE100DD6677 /* SSZipArchive+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87ACF3E91D2DAFAD00ED2F7E /* SSZipArchive+Swift.swift */; };
37952C8B1F63BBE400DD6677 /* ZipArchive.h in Headers */ = {isa = PBXBuildFile; fileRef = B423AE4A1C0DF7950004A2F1 /* ZipArchive.h */; settings = {ATTRIBUTES = (Public, ); }; };
37952C8C1F63BBED00DD6677 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = B423AE6E1C0DF83F0004A2F1 /* libz.tbd */; };
37952C8D1F63BBF300DD6677 /* SSZipCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 389869341D5BC30100F18782 /* SSZipCommon.h */; settings = {ATTRIBUTES = (Public, ); }; };
389869351D5BC30100F18782 /* SSZipCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 389869341D5BC30100F18782 /* SSZipCommon.h */; settings = {ATTRIBUTES = (Public, ); }; };
87ACF3EA1D2DAFAD00ED2F7E /* SSZipArchive+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87ACF3E91D2DAFAD00ED2F7E /* SSZipArchive+Swift.swift */; };
AFF75A2D1C3727F000F450AC /* ZipArchive.h in Headers */ = {isa = PBXBuildFile; fileRef = B423AE4A1C0DF7950004A2F1 /* ZipArchive.h */; settings = {ATTRIBUTES = (Public, ); }; };
AFF75A2E1C37280200F450AC /* SSZipArchive.h in Headers */ = {isa = PBXBuildFile; fileRef = B423AE481C0DF7950004A2F1 /* SSZipArchive.h */; settings = {ATTRIBUTES = (Public, ); }; };
AFF75A2F1C37280200F450AC /* SSZipArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = B423AE491C0DF7950004A2F1 /* SSZipArchive.m */; };
@@ -196,6 +199,7 @@
37952C261F63B50D00DD6677 /* ZipArchive.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ZipArchive.framework; sourceTree = BUILT_PRODUCTS_DIR; };
37952C5E1F63BB7100DD6677 /* ZipArchive.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ZipArchive.framework; sourceTree = BUILT_PRODUCTS_DIR; };
389869341D5BC30100F18782 /* SSZipCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SSZipCommon.h; sourceTree = "<group>"; };
87ACF3E91D2DAFAD00ED2F7E /* SSZipArchive+Swift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SSZipArchive+Swift.swift"; sourceTree = "<group>"; };
AFF75A241C37279600F450AC /* ZipArchive.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ZipArchive.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B423AE1A1C0DF76A0004A2F1 /* ZipArchive.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ZipArchive.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B423AE3D1C0DF7950004A2F1 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -303,6 +307,7 @@
B423AE3E1C0DF7950004A2F1 /* minizip */,
B423AE481C0DF7950004A2F1 /* SSZipArchive.h */,
B423AE491C0DF7950004A2F1 /* SSZipArchive.m */,
87ACF3E91D2DAFAD00ED2F7E /* SSZipArchive+Swift.swift */,
B423AE4A1C0DF7950004A2F1 /* ZipArchive.h */,
);
path = SSZipArchive;
@@ -603,6 +608,7 @@
files = (
37952C541F63B7A000DD6677 /* pwd2key.c in Sources */,
37952C521F63B7A000DD6677 /* prng.c in Sources */,
37952C581F63B8C400DD6677 /* SSZipArchive+Swift.swift in Sources */,
37952C401F63B78A00DD6677 /* ioapi_mem.c in Sources */,
37952C561F63B7A000DD6677 /* sha1.c in Sources */,
37952C4A1F63B7A000DD6677 /* aestab.c in Sources */,
@@ -627,6 +633,7 @@
files = (
37952C801F63BBC000DD6677 /* hmac.c in Sources */,
37952C841F63BBC000DD6677 /* pwd2key.c in Sources */,
37952C8A1F63BBE100DD6677 /* SSZipArchive+Swift.swift in Sources */,
37952C7E1F63BBC000DD6677 /* fileenc.c in Sources */,
37952C891F63BBDA00DD6677 /* SSZipArchive.m in Sources */,
37952C7A1F63BBC000DD6677 /* aestab.c in Sources */,
@@ -675,6 +682,7 @@
files = (
3739141D1F0009FF0094DB3B /* hmac.c in Sources */,
3739140E1F0009E50094DB3B /* aes_ni.c in Sources */,
87ACF3EA1D2DAFAD00ED2F7E /* SSZipArchive+Swift.swift in Sources */,
373914211F0009FF0094DB3B /* pwd2key.c in Sources */,
373914171F0009FF0094DB3B /* aestab.c in Sources */,
373914021F0009C80094DB3B /* minishared.c in Sources */,