Commit a4ce93c6 authored by Roy Marmelstein's avatar Roy Marmelstein

Updating minizip

parent fe792d1d
......@@ -7,6 +7,28 @@
objects = {
/* Begin PBXBuildFile section */
3430BB261C484A65001143B5 /* aes.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB101C484A65001143B5 /* aes.h */; };
3430BB271C484A65001143B5 /* aes_via_ace.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB111C484A65001143B5 /* aes_via_ace.h */; };
3430BB281C484A65001143B5 /* aescrypt.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB121C484A65001143B5 /* aescrypt.c */; };
3430BB291C484A65001143B5 /* aeskey.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB131C484A65001143B5 /* aeskey.c */; };
3430BB2A1C484A65001143B5 /* aesopt.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB141C484A65001143B5 /* aesopt.h */; };
3430BB2B1C484A65001143B5 /* aestab.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB151C484A65001143B5 /* aestab.c */; };
3430BB2C1C484A65001143B5 /* aestab.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB161C484A65001143B5 /* aestab.h */; };
3430BB2D1C484A65001143B5 /* brg_endian.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB171C484A65001143B5 /* brg_endian.h */; };
3430BB2E1C484A65001143B5 /* brg_types.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB181C484A65001143B5 /* brg_types.h */; };
3430BB2F1C484A65001143B5 /* entropy.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB191C484A65001143B5 /* entropy.c */; };
3430BB301C484A65001143B5 /* entropy.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB1A1C484A65001143B5 /* entropy.h */; };
3430BB311C484A65001143B5 /* fileenc.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB1B1C484A65001143B5 /* fileenc.c */; };
3430BB321C484A65001143B5 /* fileenc.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB1C1C484A65001143B5 /* fileenc.h */; };
3430BB331C484A65001143B5 /* hmac.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB1D1C484A65001143B5 /* hmac.c */; };
3430BB341C484A65001143B5 /* hmac.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB1E1C484A65001143B5 /* hmac.h */; };
3430BB351C484A65001143B5 /* Makefile in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB1F1C484A65001143B5 /* Makefile */; };
3430BB361C484A65001143B5 /* prng.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB201C484A65001143B5 /* prng.c */; };
3430BB371C484A65001143B5 /* prng.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB211C484A65001143B5 /* prng.h */; };
3430BB381C484A65001143B5 /* pwd2key.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB221C484A65001143B5 /* pwd2key.c */; };
3430BB391C484A65001143B5 /* pwd2key.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB231C484A65001143B5 /* pwd2key.h */; };
3430BB3A1C484A65001143B5 /* sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430BB241C484A65001143B5 /* sha1.c */; };
3430BB3B1C484A65001143B5 /* sha1.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430BB251C484A65001143B5 /* sha1.h */; };
3430F6201C45C805007473A6 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 3430F61F1C45C805007473A6 /* libz.tbd */; };
3430F62D1C45C851007473A6 /* crypt.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6221C45C851007473A6 /* crypt.h */; };
3430F62E1C45C851007473A6 /* include.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6231C45C851007473A6 /* include.h */; };
......@@ -19,27 +41,6 @@
3430F6351C45C851007473A6 /* zip.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F62B1C45C851007473A6 /* zip.c */; };
3430F6361C45C851007473A6 /* zip.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F62C1C45C851007473A6 /* zip.h */; };
3430F6381C45C89A007473A6 /* Common.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6371C45C89A007473A6 /* Common.h */; };
3430F64F1C45C8AD007473A6 /* aes.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F63A1C45C8AD007473A6 /* aes.h */; };
3430F6501C45C8AD007473A6 /* aes_via_ace.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F63B1C45C8AD007473A6 /* aes_via_ace.h */; };
3430F6511C45C8AD007473A6 /* aescrypt.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F63C1C45C8AD007473A6 /* aescrypt.c */; };
3430F6521C45C8AD007473A6 /* aeskey.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F63D1C45C8AD007473A6 /* aeskey.c */; };
3430F6531C45C8AD007473A6 /* aesopt.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F63E1C45C8AD007473A6 /* aesopt.h */; };
3430F6541C45C8AD007473A6 /* aestab.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F63F1C45C8AD007473A6 /* aestab.c */; };
3430F6551C45C8AD007473A6 /* aestab.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6401C45C8AD007473A6 /* aestab.h */; };
3430F6561C45C8AD007473A6 /* brg_endian.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6411C45C8AD007473A6 /* brg_endian.h */; };
3430F6571C45C8AD007473A6 /* brg_types.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6421C45C8AD007473A6 /* brg_types.h */; };
3430F6581C45C8AD007473A6 /* entropy.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6431C45C8AD007473A6 /* entropy.c */; };
3430F6591C45C8AD007473A6 /* entropy.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6441C45C8AD007473A6 /* entropy.h */; };
3430F65A1C45C8AD007473A6 /* fileenc.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6451C45C8AD007473A6 /* fileenc.c */; };
3430F65B1C45C8AD007473A6 /* fileenc.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6461C45C8AD007473A6 /* fileenc.h */; };
3430F65C1C45C8AD007473A6 /* hmac.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6471C45C8AD007473A6 /* hmac.c */; };
3430F65D1C45C8AD007473A6 /* hmac.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F6481C45C8AD007473A6 /* hmac.h */; };
3430F65E1C45C8AD007473A6 /* prng.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F6491C45C8AD007473A6 /* prng.c */; };
3430F65F1C45C8AD007473A6 /* prng.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F64A1C45C8AD007473A6 /* prng.h */; };
3430F6601C45C8AD007473A6 /* pwd2key.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F64B1C45C8AD007473A6 /* pwd2key.c */; };
3430F6611C45C8AD007473A6 /* pwd2key.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F64C1C45C8AD007473A6 /* pwd2key.h */; };
3430F6621C45C8AD007473A6 /* sha1.c in Sources */ = {isa = PBXBuildFile; fileRef = 3430F64D1C45C8AD007473A6 /* sha1.c */; };
3430F6631C45C8AD007473A6 /* sha1.h in Headers */ = {isa = PBXBuildFile; fileRef = 3430F64E1C45C8AD007473A6 /* sha1.h */; };
347E3A781C1DFFB500A11FD3 /* Zip.h in Headers */ = {isa = PBXBuildFile; fileRef = 347E3A771C1DFFB500A11FD3 /* Zip.h */; settings = {ATTRIBUTES = (Public, ); }; };
347E3A7F1C1DFFB500A11FD3 /* Zip.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 347E3A741C1DFFB500A11FD3 /* Zip.framework */; };
347E3A841C1DFFB500A11FD3 /* ZipTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E3A831C1DFFB500A11FD3 /* ZipTests.swift */; };
......@@ -57,6 +58,28 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
3430BB101C484A65001143B5 /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = "<group>"; };
3430BB111C484A65001143B5 /* aes_via_ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes_via_ace.h; sourceTree = "<group>"; };
3430BB121C484A65001143B5 /* aescrypt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aescrypt.c; sourceTree = "<group>"; };
3430BB131C484A65001143B5 /* aeskey.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aeskey.c; sourceTree = "<group>"; };
3430BB141C484A65001143B5 /* aesopt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aesopt.h; sourceTree = "<group>"; };
3430BB151C484A65001143B5 /* aestab.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aestab.c; sourceTree = "<group>"; };
3430BB161C484A65001143B5 /* aestab.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aestab.h; sourceTree = "<group>"; };
3430BB171C484A65001143B5 /* brg_endian.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = brg_endian.h; sourceTree = "<group>"; };
3430BB181C484A65001143B5 /* brg_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = brg_types.h; sourceTree = "<group>"; };
3430BB191C484A65001143B5 /* entropy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = entropy.c; sourceTree = "<group>"; };
3430BB1A1C484A65001143B5 /* entropy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = entropy.h; sourceTree = "<group>"; };
3430BB1B1C484A65001143B5 /* fileenc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fileenc.c; sourceTree = "<group>"; };
3430BB1C1C484A65001143B5 /* fileenc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fileenc.h; sourceTree = "<group>"; };
3430BB1D1C484A65001143B5 /* hmac.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hmac.c; sourceTree = "<group>"; };
3430BB1E1C484A65001143B5 /* hmac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hmac.h; sourceTree = "<group>"; };
3430BB1F1C484A65001143B5 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
3430BB201C484A65001143B5 /* prng.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = prng.c; sourceTree = "<group>"; };
3430BB211C484A65001143B5 /* prng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = prng.h; sourceTree = "<group>"; };
3430BB221C484A65001143B5 /* pwd2key.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pwd2key.c; sourceTree = "<group>"; };
3430BB231C484A65001143B5 /* pwd2key.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pwd2key.h; sourceTree = "<group>"; };
3430BB241C484A65001143B5 /* sha1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha1.c; sourceTree = "<group>"; };
3430BB251C484A65001143B5 /* sha1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha1.h; sourceTree = "<group>"; };
3430F61F1C45C805007473A6 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
3430F6221C45C851007473A6 /* crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypt.h; sourceTree = "<group>"; };
3430F6231C45C851007473A6 /* include.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = include.h; sourceTree = "<group>"; };
......@@ -70,27 +93,6 @@
3430F62B1C45C851007473A6 /* zip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = zip.c; sourceTree = "<group>"; };
3430F62C1C45C851007473A6 /* zip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = zip.h; sourceTree = "<group>"; };
3430F6371C45C89A007473A6 /* Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Common.h; sourceTree = "<group>"; };
3430F63A1C45C8AD007473A6 /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = "<group>"; };
3430F63B1C45C8AD007473A6 /* aes_via_ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes_via_ace.h; sourceTree = "<group>"; };
3430F63C1C45C8AD007473A6 /* aescrypt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aescrypt.c; sourceTree = "<group>"; };
3430F63D1C45C8AD007473A6 /* aeskey.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aeskey.c; sourceTree = "<group>"; };
3430F63E1C45C8AD007473A6 /* aesopt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aesopt.h; sourceTree = "<group>"; };
3430F63F1C45C8AD007473A6 /* aestab.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = aestab.c; sourceTree = "<group>"; };
3430F6401C45C8AD007473A6 /* aestab.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aestab.h; sourceTree = "<group>"; };
3430F6411C45C8AD007473A6 /* brg_endian.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = brg_endian.h; sourceTree = "<group>"; };
3430F6421C45C8AD007473A6 /* brg_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = brg_types.h; sourceTree = "<group>"; };
3430F6431C45C8AD007473A6 /* entropy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = entropy.c; sourceTree = "<group>"; };
3430F6441C45C8AD007473A6 /* entropy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = entropy.h; sourceTree = "<group>"; };
3430F6451C45C8AD007473A6 /* fileenc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fileenc.c; sourceTree = "<group>"; };
3430F6461C45C8AD007473A6 /* fileenc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = fileenc.h; sourceTree = "<group>"; };
3430F6471C45C8AD007473A6 /* hmac.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hmac.c; sourceTree = "<group>"; };
3430F6481C45C8AD007473A6 /* hmac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = hmac.h; sourceTree = "<group>"; };
3430F6491C45C8AD007473A6 /* prng.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = prng.c; sourceTree = "<group>"; };
3430F64A1C45C8AD007473A6 /* prng.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = prng.h; sourceTree = "<group>"; };
3430F64B1C45C8AD007473A6 /* pwd2key.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pwd2key.c; sourceTree = "<group>"; };
3430F64C1C45C8AD007473A6 /* pwd2key.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pwd2key.h; sourceTree = "<group>"; };
3430F64D1C45C8AD007473A6 /* sha1.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sha1.c; sourceTree = "<group>"; };
3430F64E1C45C8AD007473A6 /* sha1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sha1.h; sourceTree = "<group>"; };
347E3A741C1DFFB500A11FD3 /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; };
347E3A771C1DFFB500A11FD3 /* Zip.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Zip.h; sourceTree = "<group>"; };
347E3A791C1DFFB500A11FD3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
......@@ -120,9 +122,39 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
3430BB0F1C484A65001143B5 /* aes */ = {
isa = PBXGroup;
children = (
3430BB101C484A65001143B5 /* aes.h */,
3430BB111C484A65001143B5 /* aes_via_ace.h */,
3430BB121C484A65001143B5 /* aescrypt.c */,
3430BB131C484A65001143B5 /* aeskey.c */,
3430BB141C484A65001143B5 /* aesopt.h */,
3430BB151C484A65001143B5 /* aestab.c */,
3430BB161C484A65001143B5 /* aestab.h */,
3430BB171C484A65001143B5 /* brg_endian.h */,
3430BB181C484A65001143B5 /* brg_types.h */,
3430BB191C484A65001143B5 /* entropy.c */,
3430BB1A1C484A65001143B5 /* entropy.h */,
3430BB1B1C484A65001143B5 /* fileenc.c */,
3430BB1C1C484A65001143B5 /* fileenc.h */,
3430BB1D1C484A65001143B5 /* hmac.c */,
3430BB1E1C484A65001143B5 /* hmac.h */,
3430BB1F1C484A65001143B5 /* Makefile */,
3430BB201C484A65001143B5 /* prng.c */,
3430BB211C484A65001143B5 /* prng.h */,
3430BB221C484A65001143B5 /* pwd2key.c */,
3430BB231C484A65001143B5 /* pwd2key.h */,
3430BB241C484A65001143B5 /* sha1.c */,
3430BB251C484A65001143B5 /* sha1.h */,
);
path = aes;
sourceTree = "<group>";
};
3430F6211C45C83F007473A6 /* minizip */ = {
isa = PBXGroup;
children = (
3430BB0F1C484A65001143B5 /* aes */,
3430F6371C45C89A007473A6 /* Common.h */,
3430F6221C45C851007473A6 /* crypt.h */,
3430F6231C45C851007473A6 /* include.h */,
......@@ -139,34 +171,6 @@
path = minizip;
sourceTree = "<group>";
};
3430F6391C45C8AD007473A6 /* aes */ = {
isa = PBXGroup;
children = (
3430F63A1C45C8AD007473A6 /* aes.h */,
3430F63B1C45C8AD007473A6 /* aes_via_ace.h */,
3430F63C1C45C8AD007473A6 /* aescrypt.c */,
3430F63D1C45C8AD007473A6 /* aeskey.c */,
3430F63E1C45C8AD007473A6 /* aesopt.h */,
3430F63F1C45C8AD007473A6 /* aestab.c */,
3430F6401C45C8AD007473A6 /* aestab.h */,
3430F6411C45C8AD007473A6 /* brg_endian.h */,
3430F6421C45C8AD007473A6 /* brg_types.h */,
3430F6431C45C8AD007473A6 /* entropy.c */,
3430F6441C45C8AD007473A6 /* entropy.h */,
3430F6451C45C8AD007473A6 /* fileenc.c */,
3430F6461C45C8AD007473A6 /* fileenc.h */,
3430F6471C45C8AD007473A6 /* hmac.c */,
3430F6481C45C8AD007473A6 /* hmac.h */,
3430F6491C45C8AD007473A6 /* prng.c */,
3430F64A1C45C8AD007473A6 /* prng.h */,
3430F64B1C45C8AD007473A6 /* pwd2key.c */,
3430F64C1C45C8AD007473A6 /* pwd2key.h */,
3430F64D1C45C8AD007473A6 /* sha1.c */,
3430F64E1C45C8AD007473A6 /* sha1.h */,
);
path = aes;
sourceTree = "<group>";
};
347E3A6A1C1DFFB500A11FD3 = {
isa = PBXGroup;
children = (
......@@ -189,7 +193,6 @@
347E3A761C1DFFB500A11FD3 /* Zip */ = {
isa = PBXGroup;
children = (
3430F6391C45C8AD007473A6 /* aes */,
3430F6211C45C83F007473A6 /* minizip */,
347E3A771C1DFFB500A11FD3 /* Zip.h */,
347E3A791C1DFFB500A11FD3 /* Info.plist */,
......@@ -214,25 +217,25 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
3430F65D1C45C8AD007473A6 /* hmac.h in Headers */,
3430F65F1C45C8AD007473A6 /* prng.h in Headers */,
3430F6561C45C8AD007473A6 /* brg_endian.h in Headers */,
3430BB341C484A65001143B5 /* hmac.h in Headers */,
3430BB371C484A65001143B5 /* prng.h in Headers */,
3430BB2D1C484A65001143B5 /* brg_endian.h in Headers */,
347E3A781C1DFFB500A11FD3 /* Zip.h in Headers */,
3430F6361C45C851007473A6 /* zip.h in Headers */,
3430F6631C45C8AD007473A6 /* sha1.h in Headers */,
3430F6551C45C8AD007473A6 /* aestab.h in Headers */,
3430BB3B1C484A65001143B5 /* sha1.h in Headers */,
3430BB2C1C484A65001143B5 /* aestab.h in Headers */,
3430F62D1C45C851007473A6 /* crypt.h in Headers */,
3430F65B1C45C8AD007473A6 /* fileenc.h in Headers */,
3430BB321C484A65001143B5 /* fileenc.h in Headers */,
3430F62E1C45C851007473A6 /* include.h in Headers */,
3430F6341C45C851007473A6 /* unzip.h in Headers */,
3430F6531C45C8AD007473A6 /* aesopt.h in Headers */,
3430F6591C45C8AD007473A6 /* entropy.h in Headers */,
3430BB2A1C484A65001143B5 /* aesopt.h in Headers */,
3430BB301C484A65001143B5 /* entropy.h in Headers */,
3430F6301C45C851007473A6 /* ioapi.h in Headers */,
3430F64F1C45C8AD007473A6 /* aes.h in Headers */,
3430F6501C45C8AD007473A6 /* aes_via_ace.h in Headers */,
3430F6611C45C8AD007473A6 /* pwd2key.h in Headers */,
3430BB261C484A65001143B5 /* aes.h in Headers */,
3430BB271C484A65001143B5 /* aes_via_ace.h in Headers */,
3430BB391C484A65001143B5 /* pwd2key.h in Headers */,
3430F6321C45C851007473A6 /* mztools.h in Headers */,
3430F6571C45C8AD007473A6 /* brg_types.h in Headers */,
3430BB2E1C484A65001143B5 /* brg_types.h in Headers */,
3430F6381C45C89A007473A6 /* Common.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -334,20 +337,21 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3430F6621C45C8AD007473A6 /* sha1.c in Sources */,
3430F65E1C45C8AD007473A6 /* prng.c in Sources */,
3430F65C1C45C8AD007473A6 /* hmac.c in Sources */,
3430BB3A1C484A65001143B5 /* sha1.c in Sources */,
3430BB361C484A65001143B5 /* prng.c in Sources */,
3430BB291C484A65001143B5 /* aeskey.c in Sources */,
3430BB2B1C484A65001143B5 /* aestab.c in Sources */,
3430F62F1C45C851007473A6 /* ioapi.c in Sources */,
3430F6331C45C851007473A6 /* unzip.c in Sources */,
347E3AD81C1E04C900A11FD3 /* Zip.swift in Sources */,
3430F6581C45C8AD007473A6 /* entropy.c in Sources */,
3430F6521C45C8AD007473A6 /* aeskey.c in Sources */,
3430F6541C45C8AD007473A6 /* aestab.c in Sources */,
3430BB331C484A65001143B5 /* hmac.c in Sources */,
3430BB351C484A65001143B5 /* Makefile in Sources */,
3430BB2F1C484A65001143B5 /* entropy.c in Sources */,
3430F6351C45C851007473A6 /* zip.c in Sources */,
3430BB281C484A65001143B5 /* aescrypt.c in Sources */,
3430BB311C484A65001143B5 /* fileenc.c in Sources */,
3430BB381C484A65001143B5 /* pwd2key.c in Sources */,
3430F6311C45C851007473A6 /* mztools.c in Sources */,
3430F6511C45C8AD007473A6 /* aescrypt.c in Sources */,
3430F6601C45C8AD007473A6 /* pwd2key.c in Sources */,
3430F65A1C45C8AD007473A6 /* fileenc.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
More changes since 1.1
- Added support for AE-2 zip files
- Fixed error in AE-1 not testing CRC32
Credits
Steven Christy
Changes since 1.1
- Added PKZIP spanning support
- Added AES encryption support
- Added I/O buffering
- Clean up & changed unzLocateFile to support custom comparison function
- Clean up, removed zipRemoveExtraInfoBlock
Credits
Nathan Moinvaziri
Change in 1.1
- Added ZIP64 support for unzip ( by Even Rouault )
- Added ZIP64 support for zip ( by Mathias Svensson )
- Reverted some changed that Even Rouault did.
- Bunch of patches received from Gulles Vollant that he received for MiniZip from various users.
- Added unzip patch for BZIP Compression method (patch create by Daniel Borca)
- Added BZIP Compress method for zip
- Did some refactoring and code cleanup
Credits
Gilles Vollant - Original MiniZip author
Even Rouault - ZIP64 unzip Support
2007-2008
- Addition of cpl_unzGetCurrentFileZStreamPos
- Decoration of symbol names unz* -> cpl_unz*
- Remove old C style function prototypes
- Add unzip support for ZIP64
Daniel Borca - BZip Compression method support in unzip
Mathias Svensson - ZIP64 zip support ( http://result42.com )
Oct-2009 unzip.c
- Removed cpl_* from symbol names
- Fixed problem if uncompressed size was > 4G and compressed size was <4G
should only read the compressed/uncompressed size from the Zip64 format if
the size from normal header was 0xffffffff
- Applied some bug fixes from patches received from Gilles Vollant
- Applied support to unzip files with compression method BZIP2 (bzip2 lib is required)
Patch created by Daniel Borca
Oct-2009 zip.c
- Remove old C style function prototypes
- Added Zip64 Support when creating new file archives
- Did some code cleanup and refactoring to get better overview of some functions.
- Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
It is used when recreting zip archive with RAW when deleting items from a zip.
ZIP64 data is automaticly added to items that needs it, and existing ZIP64
data need to be removed.
- Added support for BZIP2 as compression mode (bzip2 lib is required)
Oct-2009 ioapi.x
- Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux.
- Change to fseeko64, ftello64 and fopen64 so large files would work on linux.
More if/def section may be needed to support other platforms
- Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows.
(but you should use iowin32.c for windows instead)
Change in 1.01e (12 feb 05)
- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
- Fix possible memory leak in unzip.c (Zoran Stevanovic)
Change in 1.01b (20 may 04)
- Integrate patch from Debian package (Mark Brown)
- Add tools mztools from Xavier Roche
Change in 1.01 (8 may 04)
- Fix buffer overrun risk in unzip.c (Xavier Roche)
- Fix a minor buffer insecurity in minizip.c (Mike Whittaker)
Change in 1.00: (10 sept 03)
- Rename to 1.00
- Cosmetic code change
Change in 0.22: (19 May 03)
- Crypting support (unless you define NOCRYPT)
- Append file in existing zipfile
Change in 0.21: (10 Mar 03)
- Bug fixes
Change in 0.17: (27 Jan 02)
- Bug fixes
Change in 0.16: (19 Jan 02)
- Support of ioapi for virtualize zip file access
Change in 0.15: (19 Mar 98)
- Fix memory leak in minizip.c
Change in 0.14: (10 Mar 98)
- Fix bugs in minizip.c sample for zipping big file
- Fix problem in month in date handling
- Fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for comment handling
Change in 0.13: (6 Mar 98)
- Fix bugs in zip.c
- Add real minizip sample
Change in 0.12: (4 Mar 98)
- Add zip.c and zip.h for creates .zip file
- Fix change_file_date in miniunz.c for Unix (Jean-loup Gailly)
- Fix miniunz.c for file without specific record for directory
Change in 0.11: (3 Mar 98)
- Fix bug in unzGetCurrentFileInfo for get extra field and comment
- Enhance miniunz sample, remove the bad unztst.c sample
Change in 0.10: (2 Mar 98)
- Fix bug in unzReadCurrentFile
- Rename unzip* to unz* function and structure
- Remove Windows-like hungary notation variable name
- Modify some structure in unzip.h
- Add somes comment in source
- Remove unzipGetcCurrentFile function
- Replace ZUNZEXPORT by ZEXPORT
- Add unzGetLocalExtrafield for get the local extrafield info
- Add a new sample, miniunz.c
Change in 0.4: (25 Feb 98)
- Suppress the type unzipFileInZip.
Only on file in the zipfile can be open at the same time
- Fix somes typo in code
- Added tm_unz structure in unzip_file_info (date/time in readable format)
Change unknown?
- Added unzGetOffset (RX '2004)
- Added unzGetFilePos & unzGoToFilePos (Ryan Haksi)
- Added unzGetCurrentFileZStreamPos64 (GDAL)
Condition of use and distribution are the same as zlib:
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgement in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
\ No newline at end of file
CC=cc
CFLAGS=-O -I../.. -DHAVE_AES
UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a libaes.a
ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a libaes.a
TEST_FILES = test.zip readme.old readme.txt
.c.o:
$(CC) -c $(CFLAGS) $*.c
all: miniunz minizip
libaes.a:
cd aes; $(MAKE) $(MFLAGS)
miniunz: $(UNZ_OBJS) libaes.a
$(CC) $(CFLAGS) -o $@ $(UNZ_OBJS)
minizip: $(ZIP_OBJS) libaes.a
$(CC) $(CFLAGS) -o $@ $(ZIP_OBJS)
.PHONY: test clean
test: miniunz minizip
@rm -f $(TEST_FILES)
@cp README.md readme.txt
@touch -t 200712301223.44 readme.txt
./minizip test.zip readme.txt
./miniunz -l test.zip
mv readme.txt readme.old
./miniunz test.zip
@diff -q README.md readme.txt || echo "Test failed: files differ"
@[[ "$$(stat -c %Y readme.txt)" = "$$(stat -c %Y readme.old)" ]] || echo "Test failed: timestamp not preserved"
@rm -f $(TEST_FILES)
clean:
/bin/rm -f *.o *~ minizip miniunz $(TEST_FILES)
lib_LTLIBRARIES = libminizip.la
if COND_DEMOS
bin_PROGRAMS = miniunzip minizip
endif
zlib_top_srcdir = $(top_srcdir)/../..
zlib_top_builddir = $(top_builddir)/../..
AM_CPPFLAGS = -I$(zlib_top_srcdir)
AM_LDFLAGS = -L$(zlib_top_builddir)
if WIN32
iowin32_src = iowin32.c
iowin32_h = iowin32.h
endif
libminizip_la_SOURCES = \
ioapi.c \
unzip.c \
zip.c \
${iowin32_src}
libminizip_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:0:0 -lz
minizip_includedir = $(includedir)/minizip
minizip_include_HEADERS = \
crypt.h \
ioapi.h \
unzip.h \
zip.h \
${iowin32_h}
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = minizip.pc
EXTRA_PROGRAMS = miniunzip minizip
miniunzip_SOURCES = miniunz.c
miniunzip_LDADD = libminizip.la
minizip_SOURCES = minizip.c
minizip_LDADD = libminizip.la -lz
Minizip zlib contribution that includes:
- AES encryption
- I/O buffering
- PKWARE disk spanning
- Visual Studio 2008 project files
It also has the latest bug fixes that having been found all over the internet including the minizip forum and zlib developer's mailing list.
*AES Encryption*
+ Requires #define HAVE_AES
+ Requires AES library files
When zipping with a password it will always use AES 256-bit encryption.
When unzipping it will use AES decryption only if necessary.
*I/O Buffering*
Improves I/O performance by buffering read and write operations.
```
zlib_filefunc64_def filefunc64 = {0};
ourbuffer_t buffered = {0};
fill_win32_filefunc64(&buffered->filefunc64);
fill_buffer_filefunc64(&filefunc64, buffered);
unzOpen2_64(filename, &filefunc64)
```
*PKWARE disk spanning*
To create an archive with multiple disks use zipOpen3_64 supplying a disk_size value in bytes.
```
extern zipFile ZEXPORT zipOpen3_64 OF((const void *pathname, int append,
ZPOS64_T disk_size, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def));
```
The central directory is the only data stored in the .zip and doesn't follow disk_size restrictions.
When unzipping it will automatically determine when in needs to span disks.
*I/O Memory*
To unzip from a zip file in memory use fill_memory_filefunc and supply a proper ourmemory_t structure.
```
zlib_filefunc_def filefunc32 = {0};
ourmemory_t unzmem = {0};
unzmem.size = bufsize;
unzmem.base = (char *)malloc(unzmem.size);
memcpy(unzmem.base, buffer, unzmem.size);
fill_memory_filefunc(&filefunc32, &unzmem);
unzOpen2("__notused__", &filefunc32);
```
To create a zip file in memory use fill_memory_filefunc and supply a proper ourmemory_t structure. It is important
not to forget to free zipmem->base when finished. If grow is set, zipmem->base will expand to fit the size of the zip.
If grow is not set be sure to fill out zipmem.base and zipmem.size.
```
zlib_filefunc_def filefunc32 = {0};
ourmemory_t zipmem = {0};
zipmem.grow = 1;
fill_memory_filefunc(&filefunc32, &zipmem);
zipOpen3("__notused__", APPEND_STATUS_CREATE, 0, 0, &filefunc32);
```
*BZIP2*
+ Requires #define HAVE_BZIP2
+ Requires BZIP2 library
*Windows RT*
+ Requires #define IOWIN32_USING_WINRT_API
CC=cc
CFLAGS=-O -DHAVE_AES
OBJS=aescrypt.o aeskey.o aestab.o entropy.o fileenc.o hmac.o prng.o pwd2key.o sha1.o
ARFLAGS=rv
.c.o:
$(CC) -c $(CFLAGS) $*.c
libaes.a: $(OBJS)
$(ECHO) $(AR) $(ARFLAGS) ../libaes.a $?
$(AR) $(ARFLAGS) ../libaes.a $?
$(RANLIB) ../libaes.a
all: libaes.a
.PHONY: clean
clean:
rm *.o *.a
\ No newline at end of file
......@@ -42,7 +42,7 @@ int entropy_fun(unsigned char buf[], unsigned int len)
int rlen = 0;
if (frand != -1)
{
rlen = (int)read(frand, buf, len);
rlen = read(frand, buf, len);
close(frand);
}
return rlen;
......
......@@ -34,7 +34,7 @@
using AES in CTR mode, HMAC-SHA1 authentication and RFC2898 password
based key derivation.
*/
*/
#include <memory.h>
......@@ -50,14 +50,14 @@ extern "C"
/* buffers and using 32 bit operations */
static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1])
{
unsigned long i = 0, pos = cx->encr_pos;
{ unsigned long i = 0, pos = cx->encr_pos;
while (i < d_len) {
if (pos == AES_BLOCK_SIZE) {
unsigned int j = 0;
while(i < d_len)
{
if(pos == AES_BLOCK_SIZE)
{ unsigned int j = 0;
/* increment encryption nonce */
while (j < 8 && !++cx->nonce[j])
while(j < 8 && !++cx->nonce[j])
++j;
/* encrypt the nonce to form next xor buffer */
aes_encrypt(cx->nonce, cx->encr_bfr, cx->encr_ctx);
......@@ -67,7 +67,7 @@ static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1
data[i++] ^= cx->encr_bfr[pos++];
}
cx->encr_pos = (unsigned int)pos;
cx->encr_pos = pos;
}
int fcrypt_init(
......@@ -79,13 +79,12 @@ int fcrypt_init(
unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */
#endif
fcrypt_ctx cx[1]) /* the file encryption context (output) */
{
unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH];
{ unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH];
if (pwd_len > MAX_PWD_LENGTH)
if(pwd_len > MAX_PWD_LENGTH)
return PASSWORD_TOO_LONG;
if (mode < 1 || mode > 3)
if(mode < 1 || mode > 3)
return BAD_MODE;
cx->mode = mode;
......
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_INIT([minizip], [1.2.8], [bugzilla.redhat.com])
AC_CONFIG_SRCDIR([minizip.c])
AM_INIT_AUTOMAKE([foreign])
LT_INIT
AC_MSG_CHECKING([whether to build example programs])
AC_ARG_ENABLE([demos], AC_HELP_STRING([--enable-demos], [build example programs]))
AM_CONDITIONAL([COND_DEMOS], [test "$enable_demos" = yes])
if test "$enable_demos" = yes
then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
case "${host}" in
*-mingw* | mingw*)
WIN32="yes"
;;
*)
;;
esac
AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"])
AC_SUBST([HAVE_UNISTD_H], [0])
AC_CHECK_HEADER([unistd.h], [HAVE_UNISTD_H=1], [])
AC_CONFIG_FILES([Makefile minizip.pc])
AC_OUTPUT
......@@ -31,7 +31,7 @@
/***********************************************************************
* Return the next byte in the pseudo-random sequence
*/
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
static int decrypt_byte(unsigned long* pkeys)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
......@@ -44,7 +44,7 @@ static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
/***********************************************************************
* Update the encryption keys with the next byte of plain text
*/
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
static int update_keys(unsigned long* pkeys, const unsigned long* pcrc_32_tab, int c)
{
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
......@@ -61,22 +61,23 @@ static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int
* Initialize the encryption keys and the random header according to
* the given password.
*/
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
static void init_keys(const char* passwd, unsigned long* pkeys, const unsigned long* pcrc_32_tab)
{
*(pkeys+0) = 305419896L;
*(pkeys+1) = 591751049L;
*(pkeys+2) = 878082192L;
while (*passwd != 0) {
while (*passwd != 0)
{
update_keys(pkeys,pcrc_32_tab,(int)*passwd);
passwd++;
}
}
#define zdecode(pkeys,pcrc_32_tab,c) \
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys)))
#define zencode(pkeys,pcrc_32_tab,c,t) \
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
(t=decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c))
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
......@@ -99,7 +100,7 @@ static int crypthead(const char* passwd, /* password string */
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
static unsigned calls = 0; /* ensure different random header each time */
if (bufSize<RAND_HEAD_LEN)
if (bufSize < RAND_HEAD_LEN)
return 0;
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
......
......@@ -118,7 +118,7 @@ static voidpf file_build_ioposix(FILE *file, const char *filename)
return NULL;
ioposix = (FILE_IOPOSIX*)malloc(sizeof(FILE_IOPOSIX));
ioposix->file = file;
ioposix->filenameLength = (int)strlen(filename) + 1;
ioposix->filenameLength = strlen(filename) + 1;
ioposix->filename = (char*)malloc(ioposix->filenameLength * sizeof(char));
strncpy(ioposix->filename, filename, ioposix->filenameLength);
return (voidpf)ioposix;
......
......@@ -59,7 +59,7 @@
#ifdef HAVE_64BIT_INT_CUSTOM
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
#else
# ifdef HAS_STDINT_H
# ifdef HAVE_STDINT_H
# include "stdint.h"
typedef uint64_t ZPOS64_T;
# else
......
/* 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) 1998-2003 Gilles Vollant
(C) 2012-2014 Nathan Moinvaziri
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"
#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 readBuffer[IOBUF_BUFFERSIZE];
uInt readBufferLength;
uInt readBufferPos;
uInt readBufferHits;
uInt readBufferMisses;
char writeBuffer[IOBUF_BUFFERSIZE];
uInt writeBufferLength;
uInt writeBufferPos;
uInt writeBufferHits;
uInt writeBufferMisses;
ZPOS64_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(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 (opaque, stream, number_disk, mode)
voidpf opaque;
voidpf stream;
int number_disk;
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 (opaque, filename, mode)
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 (opaque, filename, mode)
voidpf opaque;
const char* 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 (opaque, stream_cd, number_disk, mode)
voidpf opaque;
voidpf stream_cd;
int 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 (opaque, stream_cd, number_disk, mode)
voidpf opaque;
voidpf stream_cd;
int 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 OF((voidpf opaque, voidpf stream));
long fflush_buf (opaque, stream)
voidpf opaque;
voidpf stream;
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
uInt totalBytesWritten = 0;
uInt bytesToWrite = streamio->writeBufferLength;
uInt bytesLeftToWrite = streamio->writeBufferLength;
int bytesWritten = 0;
while (bytesLeftToWrite > 0)
{
if (bufio->filefunc64.zwrite_file != NULL)
bytesWritten = bufio->filefunc64.zwrite_file(bufio->filefunc64.opaque, streamio->stream, streamio->writeBuffer + (bytesToWrite - bytesLeftToWrite), bytesLeftToWrite);
else
bytesWritten = bufio->filefunc.zwrite_file(bufio->filefunc.opaque, streamio->stream, streamio->writeBuffer + (bytesToWrite - bytesLeftToWrite), bytesLeftToWrite);
streamio->writeBufferMisses += 1;
print_buf(opaque, stream, "write flush [%d:%d len %d]\n", bytesToWrite, bytesLeftToWrite, streamio->writeBufferLength);
if (bytesWritten < 0)
return bytesWritten;
totalBytesWritten += bytesWritten;
bytesLeftToWrite -= bytesWritten;
streamio->position += bytesWritten;
}
streamio->writeBufferLength = 0;
streamio->writeBufferPos = 0;
return totalBytesWritten;
}
uLong ZCALLBACK fread_buf_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
void* buf;
uLong size;
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
uInt bytesToRead = 0;
uInt bufLength = 0;
uInt bytesToCopy = 0;
uInt bytesLeftToRead = size;
uInt bytesRead = -1;
print_buf(opaque, stream, "read [size %ld pos %lld]\n", size, streamio->position);
if (streamio->writeBufferLength > 0)
{
print_buf(opaque, stream, "switch from write to read, not yet supported [%lld]\n", streamio->position);
}
while (bytesLeftToRead > 0)
{
if ((streamio->readBufferLength == 0) || (streamio->readBufferPos == streamio->readBufferLength))
{
if (streamio->readBufferLength == IOBUF_BUFFERSIZE)
{
streamio->readBufferPos = 0;
streamio->readBufferLength = 0;
}
bytesToRead = IOBUF_BUFFERSIZE -(streamio->readBufferLength - streamio->readBufferPos);
if (bufio->filefunc64.zread_file != NULL)
bytesRead = bufio->filefunc64.zread_file(bufio->filefunc64.opaque, streamio->stream, streamio->readBuffer + streamio->readBufferPos, bytesToRead);
else
bytesRead = bufio->filefunc.zread_file(bufio->filefunc.opaque, streamio->stream, streamio->readBuffer + streamio->readBufferPos, bytesToRead);
streamio->readBufferMisses += 1;
streamio->readBufferLength += bytesRead;
streamio->position += bytesRead;
print_buf(opaque, stream, "filled [read %d/%d buf %d:%d pos %lld]\n", bytesRead, bytesToRead, streamio->readBufferPos, streamio->readBufferLength, streamio->position);
if (bytesRead == 0)
break;
}
if ((streamio->readBufferLength - streamio->readBufferPos) > 0)
{
bytesToCopy = min(bytesLeftToRead, (streamio->readBufferLength - streamio->readBufferPos));
memcpy((char *)buf + bufLength, streamio->readBuffer + streamio->readBufferPos, bytesToCopy);
bufLength += bytesToCopy;
bytesLeftToRead -= bytesToCopy;
streamio->readBufferHits += 1;
streamio->readBufferPos += bytesToCopy;
print_buf(opaque, stream, "emptied [copied %d remaining %d buf %d:%d pos %lld]\n", bytesToCopy, bytesLeftToRead, streamio->readBufferPos, streamio->readBufferLength, streamio->position);
}
}
return size - bytesLeftToRead;
}
uLong ZCALLBACK fwrite_buf_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
const void* buf;
uLong size;
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
uInt bytesToWrite = size;
uInt bytesLeftToWrite = size;
uInt bytesToCopy = 0;
int retVal = 0;
print_buf(opaque, stream, "write [size %ld len %d pos %lld]\n", size, streamio->writeBufferLength, streamio->position);
if (streamio->readBufferLength > 0)
{
streamio->position -= streamio->readBufferLength;
streamio->position += streamio->readBufferPos;
streamio->readBufferLength = 0;
streamio->readBufferPos = 0;
print_buf(opaque, stream, "switch from read to write [%lld]\n", streamio->position);
if (bufio->filefunc64.zseek64_file != NULL)
retVal = bufio->filefunc64.zseek64_file(bufio->filefunc64.opaque, streamio->stream, streamio->position, ZLIB_FILEFUNC_SEEK_SET);
else
retVal = bufio->filefunc.zseek_file(bufio->filefunc.opaque, streamio->stream, (uLong)streamio->position, ZLIB_FILEFUNC_SEEK_SET);
if (retVal != 0)
return -1;
}
while (bytesLeftToWrite > 0)
{
bytesToCopy = min(bytesLeftToWrite, (IOBUF_BUFFERSIZE - min(streamio->writeBufferLength, streamio->writeBufferPos)));
if (bytesToCopy == 0)
{
if (fflush_buf(opaque, stream) <= 0)
return 0;
continue;
}
memcpy(streamio->writeBuffer + streamio->writeBufferPos, (char *)buf + (bytesToWrite - bytesLeftToWrite), bytesToCopy);
print_buf(opaque, stream, "write copy [remaining %d write %d:%d len %d]\n", bytesToCopy, bytesToWrite, bytesLeftToWrite, streamio->writeBufferLength);
bytesLeftToWrite -= bytesToCopy;
streamio->writeBufferPos += bytesToCopy;
streamio->writeBufferHits += 1;
if (streamio->writeBufferPos > streamio->writeBufferLength)
streamio->writeBufferLength += streamio->writeBufferPos - streamio->writeBufferLength;
}
return size - bytesLeftToWrite;
}
ZPOS64_T ftell_buf_internal_func (opaque, stream, position)
voidpf opaque;
voidpf stream;
ZPOS64_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->readBufferPos, streamio->writeBufferPos, errno);
if (streamio->readBufferLength > 0)
position -= (streamio->readBufferLength - streamio->readBufferPos);
if (streamio->writeBufferLength > 0)
position += streamio->writeBufferPos;
return position;
}
long ZCALLBACK ftell_buf_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
ZPOS64_T position = bufio->filefunc.ztell_file(bufio->filefunc.opaque, streamio->stream);
return (long)ftell_buf_internal_func(opaque, stream, position);
}
ZPOS64_T ZCALLBACK ftell64_buf_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
ZPOS64_T position = bufio->filefunc64.ztell64_file(bufio->filefunc64.opaque, streamio->stream);
return ftell_buf_internal_func(opaque, stream, position);
}
int fseek_buf_internal_func (opaque, stream, offset, origin)
voidpf opaque;
voidpf stream;
ZPOS64_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->writeBufferLength > 0)
{
if ((offset >= streamio->position) && (offset <= streamio->position + streamio->writeBufferLength))
{
streamio->writeBufferPos = (uLong)(offset - streamio->position);
return 0;
}
}
if ((streamio->readBufferLength > 0) && (offset < streamio->position) && (offset >= streamio->position - streamio->readBufferLength))
{
streamio->readBufferPos = (uLong)(offset - (streamio->position - streamio->readBufferLength));
return 0;
}
if (fflush_buf(opaque, stream) < 0)
return -1;
streamio->position = offset;
break;
case ZLIB_FILEFUNC_SEEK_CUR:
if (streamio->readBufferLength > 0)
{
if (offset <= (streamio->readBufferLength - streamio->readBufferPos))
{
streamio->readBufferPos += (uLong)offset;
return 0;
}
offset -= (streamio->readBufferLength - streamio->readBufferPos);
streamio->position += offset;
}
if (streamio->writeBufferLength > 0)
{
if (offset <= (streamio->writeBufferLength - streamio->writeBufferPos))
{
streamio->writeBufferPos += (uLong)offset;
return 0;
}
offset -= (streamio->writeBufferLength - streamio->writeBufferPos);
}
if (fflush_buf(opaque, stream) < 0)
return -1;
break;
case ZLIB_FILEFUNC_SEEK_END:
if (streamio->writeBufferLength > 0)
{
streamio->writeBufferPos = streamio->writeBufferLength;
return 0;
}
break;
}
streamio->readBufferLength = 0;
streamio->readBufferPos = 0;
streamio->writeBufferLength = 0;
streamio->writeBufferPos = 0;
return 1;
}
long ZCALLBACK fseek_buf_func (opaque, stream, offset, origin)
voidpf opaque;
voidpf stream;
uLong offset;
int origin;
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
int retVal = -1;
if (bufio->filefunc.zseek_file == NULL)
return retVal;
retVal = fseek_buf_internal_func(opaque, stream, offset, origin);
if (retVal == 1)
retVal = bufio->filefunc.zseek_file(bufio->filefunc.opaque, streamio->stream, offset, origin);
return retVal;
}
long ZCALLBACK fseek64_buf_func (opaque, stream, offset, origin)
voidpf opaque;
voidpf stream;
ZPOS64_T offset;
int origin;
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
int retVal = -1;
if (bufio->filefunc64.zseek64_file == NULL)
return retVal;
retVal = fseek_buf_internal_func(opaque, stream, offset, origin);
if (retVal == 1)
retVal = bufio->filefunc64.zseek64_file(bufio->filefunc64.opaque, streamio->stream, offset, origin);
return retVal;
}
int ZCALLBACK fclose_buf_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
ourbuffer_t *bufio = (ourbuffer_t *)opaque;
ourstream_t *streamio = (ourstream_t *)stream;
int retVal = 0;
fflush_buf(opaque, stream);
print_buf(opaque, stream, "close\n");
if (streamio->readBufferHits + streamio->readBufferMisses > 0)
print_buf(opaque, stream, "read efficency %.02f%%\n", (streamio->readBufferHits / ((float)streamio->readBufferHits + streamio->readBufferMisses)) * 100);
if (streamio->writeBufferHits + streamio->writeBufferMisses > 0)
print_buf(opaque, stream, "write efficency %.02f%%\n", (streamio->writeBufferHits / ((float)streamio->writeBufferHits + streamio->writeBufferMisses)) * 100);
if (bufio->filefunc64.zclose_file != NULL)
retVal = bufio->filefunc64.zclose_file(bufio->filefunc64.opaque, streamio->stream);
else
retVal = bufio->filefunc.zclose_file(bufio->filefunc.opaque, streamio->stream);
free(streamio);
return retVal;
}
int ZCALLBACK ferror_buf_func (opaque, stream)
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 (pzlib_filefunc_def, ourbuf)
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 (pzlib_filefunc_def, ourbuf)
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;
}
/* 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) 1998-2003 Gilles Vollant
(C) 2012-2014 Nathan Moinvaziri
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"
#define IOBUF_BUFFERSIZE (64 * 1024)
#ifdef __cplusplus
extern "C" {
#endif
voidpf ZCALLBACK fopen_buf_func OF((voidpf opaque,const char* filename,int mode));
voidpf ZCALLBACK fopen64_buf_func OF((voidpf opaque,const char* filename,int mode));
voidpf ZCALLBACK fopendisk_buf_func OF((voidpf opaque, voidpf stream_cd, int number_disk, int mode));
voidpf ZCALLBACK fopendisk64_buf_func OF((voidpf opaque, voidpf stream_cd, int number_disk, int mode));
uLong ZCALLBACK fread_buf_func OF((voidpf opaque,voidpf stream,void* buf,uLong size));
uLong ZCALLBACK fwrite_buf_func OF((voidpf opaque,voidpf stream,const void* buf,uLong size));
long ZCALLBACK ftell_buf_func OF((voidpf opaque,voidpf stream));
ZPOS64_T ZCALLBACK ftell64_buf_func OF((voidpf opaque, voidpf stream));
long ZCALLBACK fseek_buf_func OF((voidpf opaque,voidpf stream,uLong offset,int origin));
long ZCALLBACK fseek64_buf_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
int ZCALLBACK fclose_buf_func OF((voidpf opaque,voidpf stream));
int ZCALLBACK ferror_buf_func OF((voidpf opaque,voidpf stream));
typedef struct ourbuffer_s {
zlib_filefunc_def filefunc;
zlib_filefunc64_def filefunc64;
} ourbuffer_t;
void fill_buffer_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def, ourbuffer_t *ourbuf));
void fill_buffer_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def, ourbuffer_t *ourbuf));
#ifdef __cplusplus
}
#endif
#endif
/* 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. 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) 1998-2003 Gilles Vollant
(C) 2003 Justin Fletcher
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 (64 * 1024)
#endif
voidpf ZCALLBACK fopen_mem_func (opaque, filename, mode)
voidpf opaque;
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 (opaque, stream, number_disk, mode)
voidpf opaque;
voidpf stream;
int number_disk;
int mode;
{
/* Not used */
return NULL;
}
uLong ZCALLBACK fread_mem_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
void* buf;
uLong 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;
}
uLong ZCALLBACK fwrite_mem_func (opaque, stream, buf, size)
voidpf opaque;
voidpf stream;
const void* buf;
uLong size;
{
ourmemory_t *mem = (ourmemory_t *)stream;
char *newbase = NULL;
uLong newmemsize = 0;
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 (opaque, stream)
voidpf opaque;
voidpf stream;
{
ourmemory_t *mem = (ourmemory_t *)stream;
return mem->cur_offset;
}
long ZCALLBACK fseek_mem_func (opaque, stream, offset, origin)
voidpf opaque;
voidpf stream;
uLong offset;
int origin;
{
ourmemory_t *mem = (ourmemory_t *)stream;
uLong new_pos;
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 (opaque, stream)
voidpf opaque;
voidpf stream;
{
/* Even with grow = 1, caller must always free() memory */
return 0;
}
int ZCALLBACK ferror_mem_func (opaque, stream)
voidpf opaque;
voidpf stream;
{
/* We never return errors */
return 0;
}
void fill_memory_filefunc (pzlib_filefunc_def, ourmem)
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;
}
/* 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) 1998-2003 Gilles Vollant
(C) 2003 Justin Fletcher
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 OF((voidpf opaque,const char* filename,int mode));
voidpf ZCALLBACK fopendisk_mem_func OF((voidpf opaque, voidpf stream, int number_disk, int mode));
uLong ZCALLBACK fread_mem_func OF((voidpf opaque,voidpf stream,void* buf,uLong size));
uLong ZCALLBACK fwrite_mem_func OF((voidpf opaque,voidpf stream,const void* buf,uLong size));
long ZCALLBACK ftell_mem_func OF((voidpf opaque,voidpf stream));
long ZCALLBACK fseek_mem_func OF((voidpf opaque,voidpf stream,uLong offset,int origin));
int ZCALLBACK fclose_mem_func OF((voidpf opaque,voidpf stream));
int ZCALLBACK ferror_mem_func OF((voidpf opaque,voidpf stream));
typedef struct ourmemory_s {
char *base; /* Base of the region of memory we're using */
uLong size; /* Size of the region of memory we're using */
uLong limit; /* Furthest we've written */
uLong cur_offset; /* Current offset in the area */
int grow; /* Growable memory buffer */
} ourmemory_t;
void fill_memory_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def, ourmemory_t *ourmem));
#ifdef __cplusplus
}
#endif
#endif
/* iowin32.c -- IO base function header for compress/uncompress .zip
Version 1.1, February 14h, 2010
part of the MiniZip project
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include <stdlib.h>
#include <tchar.h>
#include "zlib.h"
#include "ioapi.h"
#include "iowin32.h"
#ifndef INVALID_HANDLE_VALUE
# define INVALID_HANDLE_VALUE (0xFFFFFFFF)
#endif
#ifndef INVALID_SET_FILE_POINTER
# define INVALID_SET_FILE_POINTER ((DWORD)-1)
#endif
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define IOWIN32_USING_WINRT_API 1
# endif
#endif
voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
typedef struct
{
HANDLE hf;
int error;
void *filename;
int filenameLength;
} WIN32FILE_IOWIN;
static void win32_translate_open_mode(int mode,
DWORD* lpdwDesiredAccess,
DWORD* lpdwCreationDisposition,
DWORD* lpdwShareMode,
DWORD* lpdwFlagsAndAttributes)
{
*lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
{
*lpdwDesiredAccess = GENERIC_READ;
*lpdwCreationDisposition = OPEN_EXISTING;
*lpdwShareMode = FILE_SHARE_READ;
}
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
{
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
*lpdwCreationDisposition = OPEN_EXISTING;
}
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
{
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
*lpdwCreationDisposition = CREATE_ALWAYS;
}
}
static voidpf win32_build_iowin(HANDLE hFile)
{
WIN32FILE_IOWIN *iowin = NULL;
if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
{
iowin = (WIN32FILE_IOWIN *)malloc(sizeof(WIN32FILE_IOWIN));
if (iowin == NULL)
{
CloseHandle(hFile);
return NULL;
}
memset(iowin, 0, sizeof(WIN32FILE_IOWIN));
iowin->hf = hFile;
}
return (voidpf)iowin;
}
voidpf ZCALLBACK win32_open64_file_func (voidpf opaque, const void* filename, int mode)
{
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
HANDLE hFile = NULL;
WIN32FILE_IOWIN *iowin = NULL;
win32_translate_open_mode(mode, &dwDesiredAccess, &dwCreationDisposition, &dwShareMode, &dwFlagsAndAttributes);
if ((filename != NULL) && (dwDesiredAccess != 0))
{
#ifdef IOWIN32_USING_WINRT_API
#ifdef UNICODE
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
#else
WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
MultiByteToWideChar(CP_ACP, 0, (const char*)filename, -1, filenameW, FILENAME_MAX + 0x200);
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
#endif
#else
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
#endif
}
iowin = win32_build_iowin(hFile);
if (iowin == NULL)
return NULL;
iowin->filenameLength = _tcslen(filename) + 1;
iowin->filename = (void*)malloc(iowin->filenameLength * sizeof(TCHAR));
_tcsncpy(iowin->filename, filename, iowin->filenameLength);
return iowin;
}
voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque, const void* filename, int mode)
{
DWORD dwDesiredAccess, dwCreationDisposition, dwShareMode, dwFlagsAndAttributes ;
HANDLE hFile = NULL;
WIN32FILE_IOWIN *iowin = NULL;
win32_translate_open_mode(mode, &dwDesiredAccess, &dwCreationDisposition, &dwShareMode, &dwFlagsAndAttributes);
if ((filename != NULL) && (dwDesiredAccess != 0))
{
#ifdef IOWIN32_USING_WINRT_API
WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
MultiByteToWideChar(CP_ACP, 0, (const char*)filename, -1, filenameW, FILENAME_MAX + 0x200);
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
#else
hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
#endif
}
iowin = win32_build_iowin(hFile);
if (iowin == NULL)
return NULL;
iowin->filenameLength = strlen(filename) + 1;
iowin->filename = (void*)malloc(iowin->filenameLength * sizeof(char));
strncpy(iowin->filename, filename, iowin->filenameLength);
return iowin;
}
voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
{
DWORD dwDesiredAccess, dwCreationDisposition, dwShareMode, dwFlagsAndAttributes;
HANDLE hFile = NULL;
WIN32FILE_IOWIN *iowin = NULL;
win32_translate_open_mode(mode, &dwDesiredAccess, &dwCreationDisposition, &dwShareMode, &dwFlagsAndAttributes);
if ((filename != NULL) && (dwDesiredAccess != 0))
{
#ifdef IOWIN32_USING_WINRT_API
hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
#else
hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
#endif
}
iowin = win32_build_iowin(hFile);
if (iowin == NULL)
return NULL;
if (iowin->filename == NULL)
{
iowin->filenameLength = wcslen(filename) + 1;
iowin->filename = (void*)malloc(iowin->filenameLength * sizeof(WCHAR));
wcsncpy(iowin->filename, filename, iowin->filenameLength);
}
return iowin;
}
voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
{
DWORD dwDesiredAccess, dwCreationDisposition, dwShareMode, dwFlagsAndAttributes ;
HANDLE hFile = NULL;
WIN32FILE_IOWIN *iowin = NULL;
win32_translate_open_mode(mode, &dwDesiredAccess, &dwCreationDisposition, &dwShareMode, &dwFlagsAndAttributes);
if ((filename != NULL) && (dwDesiredAccess != 0))
{
#ifdef IOWIN32_USING_WINRT_API
#ifdef UNICODE
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
#else
WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
MultiByteToWideChar(CP_ACP, 0, (const char*)filename, -1, filenameW, FILENAME_MAX + 0x200);
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
#endif
#else
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
#endif
}
iowin = win32_build_iowin(hFile);
if (iowin == NULL)
return NULL;
iowin->filenameLength = _tcslen((TCHAR*)filename) + 1;
iowin->filename = (void*)malloc(iowin->filenameLength * sizeof(TCHAR));
_tcsncpy(iowin->filename, (TCHAR*)filename, iowin->filenameLength);
return iowin;
}
voidpf ZCALLBACK win32_opendisk64_file_func (voidpf opaque, voidpf stream, int number_disk, int mode)
{
WIN32FILE_IOWIN *iowin = NULL;
TCHAR *diskFilename = NULL;
voidpf ret = NULL;
int i = 0;
if (stream == NULL)
return NULL;
iowin = (WIN32FILE_IOWIN*)stream;
diskFilename = (TCHAR*)malloc(iowin->filenameLength * sizeof(TCHAR));
_tcsncpy(diskFilename, iowin->filename, iowin->filenameLength);
for (i = iowin->filenameLength - 1; i >= 0; i -= 1)
{
if (diskFilename[i] != _T('.'))
continue;
_sntprintf(&diskFilename[i], iowin->filenameLength - i, _T(".z%02d"), number_disk + 1);
break;
}
if (i >= 0)
ret = win32_open64_file_func(opaque, (char*)diskFilename, mode);
free(diskFilename);
return ret;
}
voidpf ZCALLBACK win32_opendisk64_file_funcW (voidpf opaque, voidpf stream, int number_disk, int mode)
{
WIN32FILE_IOWIN *iowin = NULL;
WCHAR *diskFilename = NULL;
voidpf ret = NULL;
int i = 0;
if (stream == NULL)
return NULL;
iowin = (WIN32FILE_IOWIN*)stream;
diskFilename = (WCHAR*)malloc((iowin->filenameLength + 10) * sizeof(WCHAR));
wcsncpy(diskFilename, iowin->filename, iowin->filenameLength);
for (i = iowin->filenameLength - 1; i >= 0; i -= 1)
{
if (diskFilename[i] != L'.')
continue;
_snwprintf(&diskFilename[i], (iowin->filenameLength + 10) - i, L".z%02d", number_disk + 1);
break;
}
if (i >= 0)
ret = win32_open64_file_funcW(opaque, diskFilename, mode);
free(diskFilename);
return ret;
}
voidpf ZCALLBACK win32_opendisk64_file_funcA (voidpf opaque, voidpf stream, int number_disk, int mode)
{
WIN32FILE_IOWIN *iowin = NULL;
char *diskFilename = NULL;
voidpf ret = NULL;
int i = 0;
if (stream == NULL)
return NULL;
iowin = (WIN32FILE_IOWIN*)stream;
diskFilename = (char*)malloc(iowin->filenameLength * sizeof(char));
strncpy(diskFilename, iowin->filename, iowin->filenameLength);
for (i = iowin->filenameLength - 1; i >= 0; i -= 1)
{
if (diskFilename[i] != '.')
continue;
_snprintf(&diskFilename[i], iowin->filenameLength - i, ".z%02d", number_disk + 1);
break;
}
if (i >= 0)
ret = win32_open64_file_funcA(opaque, diskFilename, mode);
free(diskFilename);
return ret;
}
voidpf ZCALLBACK win32_opendisk_file_func (voidpf opaque, voidpf stream, int number_disk, int mode)
{
WIN32FILE_IOWIN *iowin = NULL;
TCHAR *diskFilename = NULL;
voidpf ret = NULL;
int i = 0;
if (stream == NULL)
return NULL;
iowin = (WIN32FILE_IOWIN*)stream;
diskFilename = (TCHAR*)malloc(iowin->filenameLength * sizeof(TCHAR));
_tcsncpy(diskFilename, iowin->filename, iowin->filenameLength);
for (i = iowin->filenameLength - 1; i >= 0; i -= 1)
{
if (diskFilename[i] != _T('.'))
continue;
_sntprintf(&diskFilename[i], iowin->filenameLength - i, _T(".z%02d"), number_disk + 1);
break;
}
if (i >= 0)
ret = win32_open_file_func(opaque, (char*)diskFilename, mode);
free(diskFilename);
return ret;
}
uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
{
uLong ret = 0;
HANDLE hFile = NULL;
if (stream != NULL)
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
if (hFile != NULL)
{
if (!ReadFile(hFile, buf, size, &ret, NULL))
{
DWORD dwErr = GetLastError();
if (dwErr == ERROR_HANDLE_EOF)
dwErr = 0;
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
}
}
return ret;
}
uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
{
uLong ret = 0;
HANDLE hFile = NULL;
if (stream != NULL)
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
if (hFile != NULL)
{
if (!WriteFile(hFile, buf, size, &ret, NULL))
{
DWORD dwErr = GetLastError();
if (dwErr == ERROR_HANDLE_EOF)
dwErr = 0;
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
}
}
return ret;
}
static BOOL win32_setfilepointer_internal(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod)
{
#ifdef IOWIN32_USING_WINRT_API
return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
#else
LONG lHigh = pos.HighPart;
BOOL ret = TRUE;
DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
if ((dwNewPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
ret = FALSE;
if ((newPos != NULL) && (ret))
{
newPos->LowPart = dwNewPos;
newPos->HighPart = lHigh;
}
return ret;
#endif
}
long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
{
long ret = -1;
HANDLE hFile = NULL;
if (stream != NULL)
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
if (hFile != NULL)
{
LARGE_INTEGER pos;
pos.QuadPart = 0;
if (!win32_setfilepointer_internal(hFile, pos, &pos, FILE_CURRENT))
{
DWORD dwErr = GetLastError();
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
ret = -1;
}
else
ret = (long)pos.LowPart;
}
return ret;
}
ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
{
ZPOS64_T ret = (ZPOS64_T)-1;
HANDLE hFile = NULL;
if (stream != NULL)
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
if (hFile)
{
LARGE_INTEGER pos;
pos.QuadPart = 0;
if (!win32_setfilepointer_internal(hFile, pos, &pos, FILE_CURRENT))
{
DWORD dwErr = GetLastError();
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
ret = (ZPOS64_T)-1;
}
else
ret = pos.QuadPart;
}
return ret;
}
long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
{
DWORD dwMoveMethod = 0xFFFFFFFF;
HANDLE hFile = NULL;
long ret = -1;
if (stream != NULL)
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR:
dwMoveMethod = FILE_CURRENT;
break;
case ZLIB_FILEFUNC_SEEK_END:
dwMoveMethod = FILE_END;
break;
case ZLIB_FILEFUNC_SEEK_SET:
dwMoveMethod = FILE_BEGIN;
break;
default:
return -1;
}
if (hFile != NULL)
{
LARGE_INTEGER pos;
pos.QuadPart = offset;
if (!win32_setfilepointer_internal(hFile, pos, NULL, dwMoveMethod))
{
DWORD dwErr = GetLastError();
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
ret = -1;
}
else
ret = 0;
}
return ret;
}
long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
{
DWORD dwMoveMethod = 0xFFFFFFFF;
HANDLE hFile = NULL;
long ret = -1;
if (stream != NULL)
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR:
dwMoveMethod = FILE_CURRENT;
break;
case ZLIB_FILEFUNC_SEEK_END:
dwMoveMethod = FILE_END;
break;
case ZLIB_FILEFUNC_SEEK_SET:
dwMoveMethod = FILE_BEGIN;
break;
default:
return -1;
}
if (hFile)
{
LARGE_INTEGER pos;
pos.QuadPart = offset;
if (!win32_setfilepointer_internal(hFile, pos, NULL, dwMoveMethod))
{
DWORD dwErr = GetLastError();
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
ret = -1;
}
else
ret = 0;
}
return ret;
}
int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
{
WIN32FILE_IOWIN* iowin = NULL;
int ret = -1;
if (stream == NULL)
return ret;
iowin = ((WIN32FILE_IOWIN*)stream);
if (iowin->filename != NULL)
free(iowin->filename);
if (iowin->hf != NULL)
{
CloseHandle(iowin->hf);
ret=0;
}
free(stream);
return ret;
}
int ZCALLBACK win32_error_file_func (voidpf opaque, voidpf stream)
{
int ret = -1;
if (stream == NULL)
return ret;
ret = ((WIN32FILE_IOWIN*)stream)->error;
return ret;
}
void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
{
pzlib_filefunc_def->zopen_file = win32_open_file_func;
pzlib_filefunc_def->zopendisk_file = win32_opendisk_file_func;
pzlib_filefunc_def->zread_file = win32_read_file_func;
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
pzlib_filefunc_def->ztell_file = win32_tell_file_func;
pzlib_filefunc_def->zseek_file = win32_seek_file_func;
pzlib_filefunc_def->zclose_file = win32_close_file_func;
pzlib_filefunc_def->zerror_file = win32_error_file_func;
pzlib_filefunc_def->opaque = NULL;
}
void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
{
pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
pzlib_filefunc_def->zopendisk64_file = win32_opendisk64_file_func;
pzlib_filefunc_def->zread_file = win32_read_file_func;
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
pzlib_filefunc_def->zclose_file = win32_close_file_func;
pzlib_filefunc_def->zerror_file = win32_error_file_func;
pzlib_filefunc_def->opaque = NULL;
}
void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
{
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
pzlib_filefunc_def->zopendisk64_file = win32_opendisk64_file_funcA;
pzlib_filefunc_def->zread_file = win32_read_file_func;
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
pzlib_filefunc_def->zclose_file = win32_close_file_func;
pzlib_filefunc_def->zerror_file = win32_error_file_func;
pzlib_filefunc_def->opaque = NULL;
}
void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
{
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
pzlib_filefunc_def->zopendisk64_file = win32_opendisk64_file_funcW;
pzlib_filefunc_def->zread_file = win32_read_file_func;
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
pzlib_filefunc_def->zclose_file = win32_close_file_func;
pzlib_filefunc_def->zerror_file = win32_error_file_func;
pzlib_filefunc_def->opaque = NULL;
}
/* iowin32.h -- IO base function header for compress/uncompress .zip
Version 1.1, February 14h, 2010
part of the MiniZip project
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#ifndef _IOWIN32_H
#define _IOWIN32_H
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def));
void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def));
void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def));
#ifdef __cplusplus
}
#endif
#endif
/* miniunz.c
Version 1.1, February 14h, 2010
sample part of the MiniZip project
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
# ifndef __USE_FILE_OFFSET64
# define __USE_FILE_OFFSET64
# endif
# ifndef __USE_LARGEFILE64
# define __USE_LARGEFILE64
# endif
# ifndef _LARGEFILE64_SOURCE
# define _LARGEFILE64_SOURCE
# endif
# ifndef _FILE_OFFSET_BIT
# define _FILE_OFFSET_BIT 64
# endif
#endif
#ifdef __APPLE__
/* In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions */
# define FOPEN_FUNC(filename, mode) fopen(filename, mode)
# define FTELLO_FUNC(stream) ftello(stream)
# define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
#else
# define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
# define FTELLO_FUNC(stream) ftello64(stream)
# define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#ifdef _WIN32
# include <direct.h>
# include <io.h>
#else
# include <sys/stat.h>
# include <unistd.h>
# include <utime.h>
#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
#include "unzip.h"
#define WRITEBUFFERSIZE (8192)
#define MAXFILENAME (256)
#ifdef _WIN32
# define USEWIN32IOAPI
# include "iowin32.h"
#endif
void change_file_date(const char *filename, uLong dosdate, tm_unz tmu_date)
{
#ifdef _WIN32
HANDLE hFile;
FILETIME ftm, ftLocal, ftCreate, ftLastAcc, ftLastWrite;
hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite);
DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate, &ftLocal);
LocalFileTimeToFileTime(&ftLocal, &ftm);
SetFileTime(hFile, &ftm, &ftLastAcc, &ftm);
CloseHandle(hFile);
}
#else
#if defined unix || defined __APPLE__
struct utimbuf ut;
struct tm newdate;
newdate.tm_sec = tmu_date.tm_sec;
newdate.tm_min = tmu_date.tm_min;
newdate.tm_hour = tmu_date.tm_hour;
newdate.tm_mday = tmu_date.tm_mday;
newdate.tm_mon = tmu_date.tm_mon;
if (tmu_date.tm_year > 1900)
newdate.tm_year = tmu_date.tm_year - 1900;
else
newdate.tm_year = tmu_date.tm_year ;
newdate.tm_isdst = -1;
ut.actime = ut.modtime = mktime(&newdate);
utime(filename,&ut);
#endif
#endif
}
int check_file_exists(const char* filename)
{
FILE* ftestexist = FOPEN_FUNC(filename,"rb");
if (ftestexist == NULL)
return 0;
fclose(ftestexist);
return 1;
}
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 UNZ_INTERNALERROR;
}
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;
}
void display_zpos64(ZPOS64_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]);
}
void do_banner()
{
printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
printf("more info at http://www.winimage.com/zLibDll/minizip.html\n\n");
}
void do_help()
{
printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
" -e Extract without pathname (junk paths)\n" \
" -x Extract with pathname\n" \
" -v list files\n" \
" -l list files\n" \
" -d directory to extract into\n" \
" -o overwrite files without prompting\n" \
" -p extract crypted file using password\n\n");
}
int do_list(unzFile uf)
{
int err = unzGoToFirstFile(uf);
if (err != UNZ_OK)
{
printf("error %d with zipfile in unzGoToFirstFile\n", err);
return 1;
}
printf(" Length Method Size Ratio Date Time CRC-32 Name\n");
printf(" ------ ------ ---- ----- ---- ---- ------ ----\n");
do
{
char filename_inzip[256] = {0};
unz_file_info64 file_info = {0};
uLong ratio = 0;
const char *string_method = NULL;
char charCrypt = ' ';
err = unzGetCurrentFileInfo64(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0);
if (err != UNZ_OK)
{
printf("error %d with zipfile in unzGetCurrentFileInfo\n", err);
break;
}
if (file_info.uncompressed_size > 0)
ratio = (uLong)((file_info.compressed_size*100) / file_info.uncompressed_size);
/* Display a '*' if the file is encrypted */
if ((file_info.flag & 1) != 0)
charCrypt = '*';
if (file_info.compression_method == 0)
string_method = "Stored";
else if (file_info.compression_method == Z_DEFLATED)
{
uInt iLevel = (uInt)((file_info.flag & 0x6) / 2);
if (iLevel == 0)
string_method = "Defl:N";
else if (iLevel == 1)
string_method = "Defl:X";
else if ((iLevel == 2) || (iLevel == 3))
string_method = "Defl:F"; /* 2:fast , 3 : extra fast*/
}
else if (file_info.compression_method == Z_BZIP2ED)
{
string_method = "BZip2 ";
}
else
string_method = "Unkn. ";
display_zpos64(file_info.uncompressed_size, 7);
printf(" %6s%c", string_method, charCrypt);
display_zpos64(file_info.compressed_size, 7);
printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", ratio,
(uLong)file_info.tmu_date.tm_mon + 1, (uLong)file_info.tmu_date.tm_mday,
(uLong)file_info.tmu_date.tm_year % 100,
(uLong)file_info.tmu_date.tm_hour, (uLong)file_info.tmu_date.tm_min,
(uLong)file_info.crc, filename_inzip);
err = unzGoToNextFile(uf);
}
while (err == UNZ_OK);
if (err != UNZ_END_OF_LIST_OF_FILE && err != UNZ_OK) {
printf("error %d with zipfile in unzGoToNextFile\n", err);
return err;
}
return 0;
}
int do_extract_currentfile(unzFile uf, int opt_extract_without_path, int* popt_overwrite, const char *password)
{
unz_file_info64 file_info = {0};
FILE* fout = NULL;
void* buf = NULL;
uInt size_buf = WRITEBUFFERSIZE;
int err = UNZ_OK;
int errclose = UNZ_OK;
int skip = 0;
char filename_inzip[256] = {0};
char* filename_withoutpath = NULL;
const char* write_filename = NULL;
char* p = NULL;
err = unzGetCurrentFileInfo64(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, NULL, 0);
if (err != UNZ_OK)
{
printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
return err;
}
p = filename_withoutpath = filename_inzip;
while (*p != 0)
{
if ((*p == '/') || (*p == '\\'))
filename_withoutpath = p+1;
p++;
}
/* If zip entry is a directory then create it on disk */
if (*filename_withoutpath == 0)
{
if (opt_extract_without_path == 0)
{
printf("creating directory: %s\n", filename_inzip);
MKDIR(filename_inzip);
}
return err;
}
buf = (void*)malloc(size_buf);
if (buf == NULL)
{
printf("Error allocating memory\n");
return UNZ_INTERNALERROR;
}
err = unzOpenCurrentFilePassword(uf, password);
if (err != UNZ_OK)
printf("error %d with zipfile in unzOpenCurrentFilePassword\n", err);
if (opt_extract_without_path)
write_filename = filename_withoutpath;
else
write_filename = filename_inzip;
/* Determine if the file should be overwritten or not and ask the user if needed */
if ((err == UNZ_OK) && (*popt_overwrite == 0) && (check_file_exists(write_filename)))
{
char rep = 0;
do
{
char answer[128];
printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ", write_filename);
if (scanf("%1s", answer) != 1)
exit(EXIT_FAILURE);
rep = answer[0];
if ((rep >= 'a') && (rep <= 'z'))
rep -= 0x20;
}
while ((rep != 'Y') && (rep != 'N') && (rep != 'A'));
if (rep == 'N')
skip = 1;
if (rep == 'A')
*popt_overwrite = 1;
}
/* Create the file on disk so we can unzip to it */
if ((skip == 0) && (err == UNZ_OK))
{
fout = FOPEN_FUNC(write_filename, "wb");
/* Some zips don't contain directory alone before file */
if ((fout == NULL) && (opt_extract_without_path == 0) &&
(filename_withoutpath != (char*)filename_inzip))
{
char c = *(filename_withoutpath-1);
*(filename_withoutpath-1) = 0;
makedir(write_filename);
*(filename_withoutpath-1) = c;
fout = FOPEN_FUNC(write_filename, "wb");
}
if (fout == NULL)
printf("error opening %s\n", write_filename);
}
/* Read from the zip, unzip to buffer, and write to disk */
if (fout != NULL)
{
printf(" extracting: %s\n", write_filename);
do
{
err = unzReadCurrentFile(uf, buf, size_buf);
if (err < 0)
{
printf("error %d with zipfile in unzReadCurrentFile\n", err);
break;
}
if (err == 0)
break;
if (fwrite(buf, err, 1, fout) != 1)
{
printf("error %d in writing extracted file\n", errno);
err = UNZ_ERRNO;
break;
}
}
while (err > 0);
if (fout)
fclose(fout);
/* Set the time of the file that has been unzipped */
if (err == 0)
change_file_date(write_filename,file_info.dosDate, file_info.tmu_date);
}
errclose = unzCloseCurrentFile(uf);
if (errclose != UNZ_OK)
printf("error %d with zipfile in unzCloseCurrentFile\n", errclose);
free(buf);
return err;
}
int do_extract_all(unzFile uf, int opt_extract_without_path, int opt_overwrite, const char *password)
{
int err = unzGoToFirstFile(uf);
if (err != UNZ_OK)
{
printf("error %d with zipfile in unzGoToFirstFile\n", err);
return 1;
}
do
{
err = do_extract_currentfile(uf, opt_extract_without_path, &opt_overwrite, password);
if (err != UNZ_OK)
break;
err = unzGoToNextFile(uf);
}
while (err == UNZ_OK);
if (err != UNZ_END_OF_LIST_OF_FILE)
{
printf("error %d with zipfile in unzGoToNextFile\n", err);
return 1;
}
return 0;
}
int do_extract_onefile(unzFile uf, const char* filename, int opt_extract_without_path, int opt_overwrite,
const char* password)
{
if (unzLocateFile(uf, filename, NULL) != UNZ_OK)
{
printf("file %s not found in the zipfile\n", filename);
return 2;
}
if (do_extract_currentfile(uf, opt_extract_without_path, &opt_overwrite, password) == UNZ_OK)
return 0;
return 1;
}
int main(int argc, const char *argv[])
{
const char *zipfilename = NULL;
const char *filename_to_extract = NULL;
const char *password = NULL;
int i = 0;
int ret = 0;
int opt_do_list = 0;
int opt_do_extract = 1;
int opt_do_extract_withoutpath = 0;
int opt_overwrite = 0;
int opt_extractdir = 0;
const char *dirname = NULL;
unzFile uf = NULL;
do_banner();
if (argc == 1)
{
do_help();
return 0;
}
/* Parse command line options */
for (i = 1; i < argc; i++)
{
if ((*argv[i]) == '-')
{
const char *p = argv[i]+1;
while (*p != 0)
{
char c = *(p++);
if ((c == 'l') || (c == 'L'))
opt_do_list = 1;
if ((c == 'v') || (c == 'V'))
opt_do_list = 1;
if ((c == 'x') || (c == 'X'))
opt_do_extract = 1;
if ((c == 'e') || (c == 'E'))
opt_do_extract = opt_do_extract_withoutpath = 1;
if ((c == 'o') || (c == 'O'))
opt_overwrite=1;
if ((c == 'd') || (c == 'D'))
{
opt_extractdir = 1;
dirname = argv[i+1];
}
if (((c == 'p') || (c == 'P')) && (i+1 < argc))
{
password = argv[i+1];
i++;
}
}
}
else
{
if (zipfilename == NULL)
zipfilename = argv[i];
else if ((filename_to_extract == NULL) && (!opt_extractdir))
filename_to_extract = argv[i];
}
}
/* Open zip file */
if (zipfilename != NULL)
{
#ifdef USEWIN32IOAPI
zlib_filefunc64_def ffunc;
fill_win32_filefunc64A(&ffunc);
uf = unzOpen2_64(zipfilename, &ffunc);
#else
uf = unzOpen64(zipfilename);
#endif
}
if (uf == NULL)
{
printf("Cannot open %s\n", zipfilename);
return 1;
}
printf("%s opened\n", zipfilename);
/* Process command line options */
if (opt_do_list == 1)
{
ret = do_list(uf);
}
else if (opt_do_extract == 1)
{
if (opt_extractdir && CHDIR(dirname))
{
printf("Error changing into %s, aborting\n", dirname);
exit(-1);
}
if (filename_to_extract == NULL)
ret = do_extract_all(uf, opt_do_extract_withoutpath, opt_overwrite, password);
else
ret = do_extract_onefile(uf, filename_to_extract, opt_do_extract_withoutpath, opt_overwrite, password);
}
unzClose(uf);
return ret;
}
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="miniunz"
ProjectGUID="{8D770B0A-A853-4FB7-8E71-5BDDC16A8C11}"
RootNamespace="miniunz"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="..\..\"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\ioapi.c"
>
</File>
<File
RelativePath=".\iowin32.c"
>
</File>
<File
RelativePath=".\miniunz.c"
>
</File>
<File
RelativePath=".\unzip.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\crypt.h"
>
</File>
<File
RelativePath=".\ioapi.h"
>
</File>
<File
RelativePath=".\iowin32.h"
>
</File>
<File
RelativePath=".\unzip.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<Filter
Name="Zlib"
>
<File
RelativePath="..\..\adler32.c"
>
</File>
<File
RelativePath="..\..\compress.c"
>
</File>
<File
RelativePath="..\..\crc32.c"
>
</File>
<File
RelativePath="..\..\crc32.h"
>
</File>
<File
RelativePath="..\..\deflate.c"
>
</File>
<File
RelativePath="..\..\deflate.h"
>
</File>
<File
RelativePath="..\..\infback.c"
>
</File>
<File
RelativePath="..\..\inffast.c"
>
</File>
<File
RelativePath="..\..\inffast.h"
>
</File>
<File
RelativePath="..\..\inffixed.h"
>
</File>
<File
RelativePath="..\..\inflate.c"
>
</File>
<File
RelativePath="..\..\inflate.h"
>
</File>
<File
RelativePath="..\..\inftrees.c"
>
</File>
<File
RelativePath="..\..\inftrees.h"
>
</File>
<File
RelativePath="..\..\trees.c"
>
</File>
<File
RelativePath="..\..\trees.h"
>
</File>
<File
RelativePath="..\..\uncompr.c"
>
</File>
<File
RelativePath="..\..\zconf.h"
>
</File>
<File
RelativePath="..\..\zlib.h"
>
</File>
<File
RelativePath="..\..\zutil.c"
>
</File>
<File
RelativePath="..\..\zutil.h"
>
</File>
</Filter>
<Filter
Name="AES"
>
<File
RelativePath=".\aes\aes.h"
>
</File>
<File
RelativePath=".\aes\aes_via_ace.h"
>
</File>
<File
RelativePath=".\aes\aescrypt.c"
>
</File>
<File
RelativePath=".\aes\aeskey.c"
>
</File>
<File
RelativePath=".\aes\aesopt.h"
>
</File>
<File
RelativePath=".\aes\aestab.c"
>
</File>
<File
RelativePath=".\aes\aestab.h"
>
</File>
<File
RelativePath=".\aes\brg_endian.h"
>
</File>
<File
RelativePath=".\aes\brg_types.h"
>
</File>
<File
RelativePath=".\aes\entropy.c"
>
</File>
<File
RelativePath=".\aes\entropy.h"
>
</File>
<File
RelativePath=".\aes\fileenc.c"
>
</File>
<File
RelativePath=".\aes\fileenc.h"
>
</File>
<File
RelativePath=".\aes\hmac.c"
>
</File>
<File
RelativePath=".\aes\hmac.h"
>
</File>
<File
RelativePath=".\aes\prng.c"
>
</File>
<File
RelativePath=".\aes\prng.h"
>
</File>
<File
RelativePath=".\aes\pwd2key.c"
>
</File>
<File
RelativePath=".\aes\pwd2key.h"
>
</File>
<File
RelativePath=".\aes\sha1.c"
>
</File>
<File
RelativePath=".\aes\sha1.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
/* minizip.c
Version 1.1, February 14h, 2010
sample part of the MiniZip project
Copyright (C) 1998-2010 Gilles Vollant
http://www.winimage.com/zLibDll/minizip.html
Modifications of Unzip for Zip64
Copyright (C) 2007-2008 Even Rouault
Modifications for Zip64 support
Copyright (C) 2009-2010 Mathias Svensson
http://result42.com
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
# ifndef __USE_FILE_OFFSET64
# define __USE_FILE_OFFSET64
# endif
# ifndef __USE_LARGEFILE64
# define __USE_LARGEFILE64
# endif
# ifndef _LARGEFILE64_SOURCE
# define _LARGEFILE64_SOURCE
# endif
# ifndef _FILE_OFFSET_BIT
# define _FILE_OFFSET_BIT 64
# endif
#endif
#ifdef __APPLE__
/* In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions */
# define FOPEN_FUNC(filename, mode) fopen(filename, mode)
# define FTELLO_FUNC(stream) ftello(stream)
# define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
#else
# define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
# define FTELLO_FUNC(stream) ftello64(stream)
# define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <fcntl.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 "zip.h"
#ifdef _WIN32
# define USEWIN32IOAPI
# include "iowin32.h"
#endif
#define WRITEBUFFERSIZE (16384)
#define MAXFILENAME (256)
uLong filetime(const char *filename, tm_zip *tmzip, uLong *dostime)
{
int ret = 0;
#ifdef _WIN32
FILETIME ftLocal;
HANDLE hFind;
WIN32_FIND_DATAA ff32;
hFind = FindFirstFileA(filename, &ff32);
if (hFind != INVALID_HANDLE_VALUE)
{
FileTimeToLocalFileTime(&(ff32.ftLastWriteTime), &ftLocal);
FileTimeToDosDateTime(&ftLocal,((LPWORD)dostime)+1,((LPWORD)dostime)+0);
FindClose(hFind);
ret = 1;
}
#else
#if defined unix || defined __APPLE__
struct stat s = {0};
struct tm* filedate;
time_t tm_t = 0;
if (strcmp(filename,"-") != 0)
{
char name[MAXFILENAME+1];
int len = strlen(filename);
if (len > MAXFILENAME)
len = MAXFILENAME;
strncpy(name, filename, MAXFILENAME - 1);
name[MAXFILENAME] = 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;
}
}
filedate = localtime(&tm_t);
tmzip->tm_sec = filedate->tm_sec;
tmzip->tm_min = filedate->tm_min;
tmzip->tm_hour = filedate->tm_hour;
tmzip->tm_mday = filedate->tm_mday;
tmzip->tm_mon = filedate->tm_mon ;
tmzip->tm_year = filedate->tm_year;
#endif
#endif
return ret;
}
int check_file_exists(const char* filename)
{
FILE* ftestexist = FOPEN_FUNC(filename, "rb");
if (ftestexist == NULL)
return 0;
fclose(ftestexist);
return 1;
}
int is_large_file(const char* filename)
{
ZPOS64_T pos = 0;
FILE* pFile = FOPEN_FUNC(filename, "rb");
if (pFile == NULL)
return 0;
FSEEKO_FUNC(pFile, 0, SEEK_END);
pos = FTELLO_FUNC(pFile);
fclose(pFile);
printf("File : %s is %lld bytes\n", filename, pos);
return (pos >= 0xffffffff);
}
/* Calculate the CRC32 of a file, because to encrypt a file, we need known the CRC32 of the file before */
int get_file_crc(const char* filenameinzip, void *buf, unsigned long size_buf, unsigned long* result_crc)
{
FILE *fin = NULL;
unsigned long calculate_crc = 0;
unsigned long size_read = 0;
int err = ZIP_OK;
fin = FOPEN_FUNC(filenameinzip,"rb");
if (fin == NULL)
err = ZIP_ERRNO;
else
{
do
{
size_read = (int)fread(buf,1,size_buf,fin);
if ((size_read < size_buf) && (feof(fin) == 0))
{
printf("error in reading %s\n",filenameinzip);
err = ZIP_ERRNO;
}
if (size_read > 0)
calculate_crc = crc32(calculate_crc,buf,size_read);
}
while ((err == ZIP_OK) && (size_read > 0));
}
if (fin)
fclose(fin);
printf("file %s crc %lx\n", filenameinzip, calculate_crc);
*result_crc = calculate_crc;
return err;
}
void do_banner()
{
printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
}
void do_help()
{
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
" -o Overwrite existing file.zip\n" \
" -a Append to existing file.zip\n" \
" -0 Store only\n" \
" -1 Compress faster\n" \
" -9 Compress better\n\n" \
" -j exclude path. store only the file name.\n\n");
}
int main(int argc, char *argv[])
{
zipFile zf = NULL;
#ifdef USEWIN32IOAPI
zlib_filefunc64_def ffunc = {0};
#endif
char *zipfilename = NULL;
const char* password = NULL;
void* buf = NULL;
int size_buf = WRITEBUFFERSIZE;
int zipfilenamearg = 0;
int errclose = 0;
int err = 0;
int i = 0;
int opt_overwrite = APPEND_STATUS_CREATE;
int opt_compress_level = Z_DEFAULT_COMPRESSION;
int opt_exclude_path = 0;
do_banner();
if (argc == 1)
{
do_help();
return 0;
}
/* Parse command line options */
for (i = 1; i < argc; i++)
{
if ((*argv[i]) == '-')
{
const char *p = argv[i]+1;
while ((*p) != '\0')
{
char c = *(p++);;
if ((c == 'o') || (c == 'O'))
opt_overwrite = APPEND_STATUS_CREATEAFTER;
if ((c == 'a') || (c == 'A'))
opt_overwrite = APPEND_STATUS_ADDINZIP;
if ((c >= '0') && (c <= '9'))
opt_compress_level = (c - '0');
if ((c == 'j') || (c == 'J'))
opt_exclude_path = 1;
if (((c == 'p') || (c == 'P')) && (i+1 < argc))
{
password=argv[i+1];
i++;
}
}
}
else
{
if (zipfilenamearg == 0)
zipfilenamearg = i;
}
}
if (zipfilenamearg == 0)
{
do_help();
return 0;
}
zipfilename = argv[zipfilenamearg];
buf = (void*)malloc(size_buf);
if (buf == NULL)
{
printf("Error allocating memory\n");
return ZIP_INTERNALERROR;
}
if (opt_overwrite == 2)
{
/* If the file don't exist, we not append file */
if (check_file_exists(zipfilename) == 0)
opt_overwrite = 1;
}
else if (opt_overwrite == 0)
{
/* If ask the user what to do because append and overwrite args not set */
if (check_file_exists(zipfilename) != 0)
{
char rep = 0;
do
{
char answer[128];
printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ", zipfilename);
if (scanf("%1s", answer) != 1)
exit(EXIT_FAILURE);
rep = answer[0];
if ((rep >= 'a') && (rep <= 'z'))
rep -= 0x20;
}
while ((rep != 'Y') && (rep != 'N') && (rep != 'A'));
if (rep == 'A')
opt_overwrite = 2;
else if (rep == 'N')
{
do_help();
free(buf);
return 0;
}
}
}
#ifdef USEWIN32IOAPI
fill_win32_filefunc64A(&ffunc);
zf = zipOpen2_64(zipfilename, opt_overwrite, NULL, &ffunc);
#else
zf = zipOpen64(zipfilename, opt_overwrite);
#endif
if (zf == NULL)
{
printf("error opening %s\n", zipfilename);
err = ZIP_ERRNO;
}
else
printf("creating %s\n", zipfilename);
/* Go through command line args looking for files to add to zip */
for (i = zipfilenamearg + 1; (i < argc) && (err == ZIP_OK); i++)
{
FILE *fin = NULL;
int size_read = 0;
const char* filenameinzip = argv[i];
const char *savefilenameinzip;
zip_fileinfo zi = {0};
unsigned long crcFile = 0;
int zip64 = 0;
/* Skip command line options */
if ((((*(argv[i])) == '-') || ((*(argv[i])) == '/')) && (strlen(argv[i]) == 2) &&
((argv[i][1] == 'o') || (argv[i][1] == 'O') || (argv[i][1] == 'a') || (argv[i][1] == 'A') ||
(argv[i][1] == 'p') || (argv[i][1] == 'P') || ((argv[i][1] >= '0') && (argv[i][1] <= '9'))))
continue;
/* Get information about the file on disk so we can store it in zip */
filetime(filenameinzip, &zi.tmz_date, &zi.dosDate);
if ((password != NULL) && (err == ZIP_OK))
err = get_file_crc(filenameinzip, buf, size_buf, &crcFile);
zip64 = is_large_file(filenameinzip);
/* Construct the filename that our file will be stored in the zip as.
The path name saved, should not include a leading slash.
If it did, windows/xp and dynazip couldn't read the zip file. */
savefilenameinzip = filenameinzip;
while (savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/')
savefilenameinzip++;
/* Should the file be stored with any path info at all? */
if (opt_exclude_path)
{
const char *tmpptr = NULL;
const char *lastslash = 0;
for (tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
{
if (*tmpptr == '\\' || *tmpptr == '/')
lastslash = tmpptr;
}
if (lastslash != NULL)
savefilenameinzip = lastslash + 1; /* base filename follows last slash. */
}
/* Add to zip file */
err = zipOpenNewFileInZip3_64(zf, savefilenameinzip, &zi,
NULL, 0, NULL, 0, NULL /* comment*/,
(opt_compress_level != 0) ? Z_DEFLATED : 0,
opt_compress_level,0,
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
password, crcFile, zip64);
if (err != ZIP_OK)
printf("error in opening %s in zipfile (%d)\n", filenameinzip, err);
else
{
fin = FOPEN_FUNC(filenameinzip, "rb");
if (fin == NULL)
{
err = ZIP_ERRNO;
printf("error in opening %s for reading\n", filenameinzip);
}
}
if (err == ZIP_OK)
{
/* Read contents of file and write it to zip */
do
{
size_read = (int)fread(buf, 1, size_buf, fin);
if ((size_read < size_buf) && (feof(fin) == 0))
{
printf("error in reading %s\n",filenameinzip);
err = ZIP_ERRNO;
}
if (size_read > 0)
{
err = zipWriteInFileInZip(zf, buf, size_read);
if (err < 0)
printf("error in writing %s in the zipfile (%d)\n", filenameinzip, err);
}
}
while ((err == ZIP_OK) && (size_read > 0));
}
if (fin)
fclose(fin);
if (err < 0)
err = ZIP_ERRNO;
else
{
err = zipCloseFileInZip(zf);
if (err != ZIP_OK)
printf("error in closing %s in the zipfile (%d)\n", filenameinzip, err);
}
}
errclose = zipClose(zf, NULL);
if (errclose != ZIP_OK)
printf("error in closing %s (%d)\n", zipfilename, errclose);
free(buf);
return err;
}
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@/minizip
Name: minizip
Description: Minizip zip file manipulation library
Requires:
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lminizip
Libs.private: -lz
Cflags: -I${includedir}

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{8D770B0A-A853-4FB7-8E71-5BDDC16A8C11}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{9C3AFF9E-022F-4A42-BCDC-C705AEE00DEB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8D770B0A-A853-4FB7-8E71-5BDDC16A8C11}.Debug|Win32.ActiveCfg = Debug|Win32
{8D770B0A-A853-4FB7-8E71-5BDDC16A8C11}.Debug|Win32.Build.0 = Debug|Win32
{8D770B0A-A853-4FB7-8E71-5BDDC16A8C11}.Release|Win32.ActiveCfg = Release|Win32
{8D770B0A-A853-4FB7-8E71-5BDDC16A8C11}.Release|Win32.Build.0 = Release|Win32
{9C3AFF9E-022F-4A42-BCDC-C705AEE00DEB}.Debug|Win32.ActiveCfg = Debug|Win32
{9C3AFF9E-022F-4A42-BCDC-C705AEE00DEB}.Debug|Win32.Build.0 = Debug|Win32
{9C3AFF9E-022F-4A42-BCDC-C705AEE00DEB}.Release|Win32.ActiveCfg = Release|Win32
{9C3AFF9E-022F-4A42-BCDC-C705AEE00DEB}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="minizip"
ProjectGUID="{9C3AFF9E-022F-4A42-BCDC-C705AEE00DEB}"
RootNamespace="minizip"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
StringPooling="true"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="..\..\"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS"
StringPooling="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\iowin32.c"
>
</File>
<File
RelativePath=".\minizip.c"
>
</File>
<File
RelativePath=".\zip.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\crypt.h"
>
</File>
<File
RelativePath=".\ioapi.c"
>
</File>
<File
RelativePath=".\ioapi.h"
>
</File>
<File
RelativePath=".\iowin32.h"
>
</File>
<File
RelativePath=".\zip.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<Filter
Name="Zlib"
>
<File
RelativePath="..\..\adler32.c"
>
</File>
<File
RelativePath="..\..\compress.c"
>
</File>
<File
RelativePath="..\..\crc32.c"
>
</File>
<File
RelativePath="..\..\crc32.h"
>
</File>
<File
RelativePath="..\..\deflate.c"
>
</File>
<File
RelativePath="..\..\deflate.h"
>
</File>
<File
RelativePath="..\..\infback.c"
>
</File>
<File
RelativePath="..\..\inffast.c"
>
</File>
<File
RelativePath="..\..\inffast.h"
>
</File>
<File
RelativePath="..\..\inffixed.h"
>
</File>
<File
RelativePath="..\..\inflate.c"
>
</File>
<File
RelativePath="..\..\inflate.h"
>
</File>
<File
RelativePath="..\..\inftrees.c"
>
</File>
<File
RelativePath="..\..\inftrees.h"
>
</File>
<File
RelativePath="..\..\trees.c"
>
</File>
<File
RelativePath="..\..\trees.h"
>
</File>
<File
RelativePath="..\..\uncompr.c"
>
</File>
<File
RelativePath="..\..\zconf.h"
>
</File>
<File
RelativePath="..\..\zlib.h"
>
</File>
<File
RelativePath="..\..\zutil.c"
>
</File>
<File
RelativePath="..\..\zutil.h"
>
</File>
</Filter>
<Filter
Name="AES"
>
<File
RelativePath=".\aes\aes.h"
>
</File>
<File
RelativePath=".\aes\aes_via_ace.h"
>
</File>
<File
RelativePath=".\aes\aescrypt.c"
>
</File>
<File
RelativePath=".\aes\aeskey.c"
>
</File>
<File
RelativePath=".\aes\aesopt.h"
>
</File>
<File
RelativePath=".\aes\aestab.c"
>
</File>
<File
RelativePath=".\aes\aestab.h"
>
</File>
<File
RelativePath=".\aes\brg_endian.h"
>
</File>
<File
RelativePath=".\aes\brg_types.h"
>
</File>
<File
RelativePath=".\aes\entropy.c"
>
</File>
<File
RelativePath=".\aes\entropy.h"
>
</File>
<File
RelativePath=".\aes\fileenc.c"
>
</File>
<File
RelativePath=".\aes\fileenc.h"
>
</File>
<File
RelativePath=".\aes\hmac.c"
>
</File>
<File
RelativePath=".\aes\hmac.h"
>
</File>
<File
RelativePath=".\aes\prng.c"
>
</File>
<File
RelativePath=".\aes\prng.h"
>
</File>
<File
RelativePath=".\aes\pwd2key.c"
>
</File>
<File
RelativePath=".\aes\pwd2key.h"
>
</File>
<File
RelativePath=".\aes\sha1.c"
>
</File>
<File
RelativePath=".\aes\sha1.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
......@@ -14,29 +14,26 @@
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>
/*#ifndef NOUNCRYPT
# define NOUNCRYPT
#endif*/
# define NOUNCRYPT
#endif*/
#include "zlib.h"
#include "unzip.h"
#include "Common.h"
#ifdef STDC
# include <stddef.h>
# include <string.h>
# include <stdlib.h>
#endif
#ifdef NO_ERRNO_H
extern int errno;
extern int errno;
#else
# include <errno.h>
#endif
......@@ -49,8 +46,8 @@ extern int errno;
# define AES_HEADERSIZE (11)
# define AES_KEYSIZE(mode) (64 + (mode * 64))
# include "aes.h"
# include "fileenc.h"
# include "aes/aes.h"
# include "aes/fileenc.h"
#endif
#ifndef NOUNCRYPT
# include "crypt.h"
......@@ -87,14 +84,15 @@ extern int errno;
# define ALLOC(size) (malloc(size))
#endif
#ifndef TRYFREE
# define TRYFREE(p) {if (p) free(p); }
# define TRYFREE(p) {if (p) free(p);}
#endif
const char unz_copyright[] =
" unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
/* unz_file_info_interntal contain internal info about a file in zipfile*/
typedef struct unz_file_info64_internal_s {
typedef struct unz_file_info64_internal_s
{
ZPOS64_T offset_curfile; /* relative offset of local header 8 bytes */
ZPOS64_T byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx) */
#ifdef HAVE_AES
......@@ -105,7 +103,8 @@ typedef struct unz_file_info64_internal_s {
} unz_file_info64_internal;
/* file_in_zip_read_info_s contain internal information about a file in zipfile */
typedef struct {
typedef struct
{
Bytef *read_buffer; /* internal buffer for compressed data */
z_stream stream; /* zLib stream structure for inflate */
......@@ -138,7 +137,8 @@ typedef struct {
} file_in_zip64_read_info_s;
/* unz64_s contain internal information about the zipfile */
typedef struct {
typedef struct
{
zlib_filefunc64_32_def z_filefunc;
voidpf filestream; /* io structure of the current zipfile */
voidpf filestream_with_CD; /* io structure of the disk with the central directory */
......@@ -156,26 +156,26 @@ typedef struct {
unz_file_info64 cur_file_info; /* public info about the current file in zip*/
unz_file_info64_internal cur_file_info_internal;
/* private info about it*/
file_in_zip64_read_info_s *pfile_in_zip_read;
file_in_zip64_read_info_s* pfile_in_zip_read;
/* structure about the current file if we are decompressing it */
int isZip64; /* is the current file zip64 */
#ifndef NOUNCRYPT
unsigned long keys[3]; /* keys defining the pseudo-random sequence */
const unsigned long *pcrc_32_tab;
const unsigned long* pcrc_32_tab;
#endif
} unz64_s;
/* Translate date/time from Dos format to tm_unz (readable more easily) */
local void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz *ptm)
local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
{
ZPOS64_T uDate = (ZPOS64_T)(ulDosDate >> 16);
ZPOS64_T uDate = (ZPOS64_T)(ulDosDate>>16);
ptm->tm_mday = (uInt)(uDate & 0x1f);
ptm->tm_mon = (uInt)((((uDate) & 0x1E0) / 0x20) - 1);
ptm->tm_year = (uInt)(((uDate & 0x0FE00) / 0x0200) + 1980);
ptm->tm_hour = (uInt)((ulDosDate & 0xF800) / 0x800);
ptm->tm_min = (uInt)((ulDosDate & 0x7E0) / 0x20);
ptm->tm_sec = (uInt)(2 * (ulDosDate & 0x1f));
ptm->tm_mday = (uInt)(uDate&0x1f);
ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1);
ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980);
ptm->tm_hour = (uInt)((ulDosDate &0xF800)/0x800);
ptm->tm_min = (uInt)((ulDosDate&0x7E0)/0x20);
ptm->tm_sec = (uInt)(2*(ulDosDate&0x1f));
#define unz64local_in_range(min, max, value) ((min) <= (value) && (value) <= (max))
if (!unz64local_in_range(0, 11, ptm->tm_mon) ||
......@@ -189,21 +189,24 @@ local void unz64local_DosDateToTmuDate(ZPOS64_T ulDosDate, tm_unz *ptm)
}
/* Read a byte from a gz_stream; Return EOF for end of file. */
local int unz64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
local int unz64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
{
unsigned char c;
int err = (int)ZREAD64(*pzlib_filefunc_def, filestream, &c, 1);
if (err == 1) {
if (err == 1)
{
*pi = (int)c;
return UNZ_OK;
}
*pi = 0;
if (ZERROR64(*pzlib_filefunc_def, filestream))
return UNZ_ERRNO;
return UNZ_EOF;
}
local int unz64local_getShort OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, uLong * pX));
local int unz64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
local int unz64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)
{
uLong x;
int i = 0;
......@@ -213,7 +216,7 @@ local int unz64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def,
x = (uLong)i;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((uLong)i) << 8;
x |= ((uLong)i)<<8;
if (err == UNZ_OK)
*pX = x;
......@@ -222,8 +225,8 @@ local int unz64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def,
return err;
}
local int unz64local_getLong OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, uLong * pX));
local int unz64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
local int unz64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)
{
uLong x;
int i = 0;
......@@ -233,13 +236,13 @@ local int unz64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, v
x = (uLong)i;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((uLong)i) << 8;
x |= ((uLong)i)<<8;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((uLong)i) << 16;
x |= ((uLong)i)<<16;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x += ((uLong)i) << 24;
x += ((uLong)i)<<24;
if (err == UNZ_OK)
*pX = x;
......@@ -248,8 +251,8 @@ local int unz64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, v
return err;
}
local int unz64local_getLong64 OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, ZPOS64_T * pX));
local int unz64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
local int unz64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
{
ZPOS64_T x;
int i = 0;
......@@ -259,25 +262,25 @@ local int unz64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def,
x = (ZPOS64_T)i;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((ZPOS64_T)i) << 8;
x |= ((ZPOS64_T)i)<<8;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((ZPOS64_T)i) << 16;
x |= ((ZPOS64_T)i)<<16;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((ZPOS64_T)i) << 24;
x |= ((ZPOS64_T)i)<<24;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((ZPOS64_T)i) << 32;
x |= ((ZPOS64_T)i)<<32;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((ZPOS64_T)i) << 40;
x |= ((ZPOS64_T)i)<<40;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((ZPOS64_T)i) << 48;
x |= ((ZPOS64_T)i)<<48;
if (err == UNZ_OK)
err = unz64local_getByte(pzlib_filefunc_def, filestream, &i);
x |= ((ZPOS64_T)i) << 56;
x |= ((ZPOS64_T)i)<<56;
if (err == UNZ_OK)
*pX = x;
......@@ -287,10 +290,10 @@ local int unz64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def,
}
/* Locate the Central directory of a zip file (at the end, just before the global comment) */
local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream));
local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
{
unsigned char *buf;
unsigned char* buf;
ZPOS64_T file_size;
ZPOS64_T back_read = 4;
ZPOS64_T max_back = 0xffff; /* maximum size of global comment */
......@@ -299,11 +302,12 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_f
ZPOS64_T read_pos;
int i;
buf = (unsigned char *)ALLOC(BUFREADCOMMENT + 4);
buf = (unsigned char*)ALLOC(BUFREADCOMMENT + 4);
if (buf == NULL)
return 0;
if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0) {
if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0)
{
TRYFREE(buf);
return 0;
}
......@@ -313,7 +317,8 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_f
if (max_back > file_size)
max_back = file_size;
while (back_read < max_back) {
while (back_read < max_back)
{
if (back_read + BUFREADCOMMENT > max_back)
back_read = max_back;
else
......@@ -328,12 +333,13 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_f
if (ZREAD64(*pzlib_filefunc_def, filestream, buf, read_size) != read_size)
break;
for (i = (int)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;
for (i = (int)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;
}
......@@ -345,9 +351,9 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_f
}
/* Locate the Central directory 64 of a zipfile (at the end, just before the global comment) */
local ZPOS64_T unz64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream,
local ZPOS64_T unz64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream,
const ZPOS64_T endcentraloffset));
local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream,
local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream,
const ZPOS64_T endcentraloffset)
{
ZPOS64_T offset;
......@@ -383,7 +389,7 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib
return offset;
}
local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_filefunc64_32_def)
local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
{
unz64_s us;
unz64_s *s;
......@@ -393,7 +399,7 @@ local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_fi
ZPOS64_T number_entry_CD;
int err = UNZ_OK;
if (unz_copyright[0] != ' ')
if (unz_copyright[0]!=' ')
return NULL;
us.filestream = NULL;
......@@ -416,7 +422,8 @@ local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_fi
/* Use unz64local_SearchCentralDir first. Only based on the result
is it necessary to locate the unz64local_SearchCentralDir64 */
central_pos = unz64local_SearchCentralDir(&us.z_filefunc, us.filestream);
if (central_pos) {
if (central_pos)
{
if (ZSEEK64(us.z_filefunc, us.filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = UNZ_ERRNO;
......@@ -428,7 +435,7 @@ local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_fi
err = UNZ_ERRNO;
us.number_disk = uL;
/* number of the disk with the start of the central directory */
if (unz64local_getShort(&us.z_filefunc, us.filestream, &uL) != UNZ_OK)
if (unz64local_getShort(&us.z_filefunc, us.filestream,& uL) != UNZ_OK)
err = UNZ_ERRNO;
us.gi.number_disk_with_CD = uL;
/* total number of entries in the central directory on this disk */
......@@ -454,10 +461,12 @@ local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_fi
err = UNZ_ERRNO;
if ((err == UNZ_OK) &&
((us.gi.number_entry == 0xffff) || (us.size_central_dir == 0xffff) || (us.offset_central_dir == 0xffffffff))) {
((us.gi.number_entry == 0xffff) || (us.size_central_dir == 0xffff) || (us.offset_central_dir == 0xffffffff)))
{
/* Format should be Zip64, as the central directory or file size is too large */
central_pos = unz64local_SearchCentralDir64(&us.z_filefunc, us.filestream, central_pos);
if (central_pos) {
if (central_pos)
{
ZPOS64_T uL64;
us.isZip64 = 1;
......@@ -497,21 +506,25 @@ local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_fi
/* offset of start of central directory with respect to the starting disk number */
if (unz64local_getLong64(&us.z_filefunc, us.filestream, &us.offset_central_dir) != UNZ_OK)
err = UNZ_ERRNO;
} else
}
else
err = UNZ_BADZIPFILE;
}
} else
}
else
err = UNZ_ERRNO;
if ((err == UNZ_OK) && (central_pos < us.offset_central_dir + us.size_central_dir))
err = UNZ_BADZIPFILE;
if (err != UNZ_OK) {
if (err != UNZ_OK)
{
ZCLOSE64(us.z_filefunc, us.filestream);
return NULL;
}
if (us.gi.number_disk_with_CD == 0) {
if (us.gi.number_disk_with_CD == 0)
{
/* If there is only one disk open another stream so we don't have to seek between the CD
and the file headers constantly */
filestream = ZOPEN64(us.z_filefunc, path, ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_EXISTING);
......@@ -527,17 +540,19 @@ local unzFile unzOpenInternal(const void *path, zlib_filefunc64_32_def *pzlib_fi
us.central_pos = central_pos;
us.pfile_in_zip_read = NULL;
s = (unz64_s *)ALLOC(sizeof(unz64_s));
if (s != NULL) {
s = (unz64_s*)ALLOC(sizeof(unz64_s));
if (s != NULL)
{
*s = us;
unzGoToFirstFile((unzFile)s);
}
return (unzFile)s;
}
extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc32_def)
extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def* pzlib_filefunc32_def)
{
if (pzlib_filefunc32_def != NULL) {
if (pzlib_filefunc32_def != NULL)
{
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill, pzlib_filefunc32_def);
return unzOpenInternal(path, &zlib_filefunc64_32_def_fill);
......@@ -545,9 +560,10 @@ extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filef
return unzOpenInternal(path, NULL);
}
extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def* pzlib_filefunc_def)
{
if (pzlib_filefunc_def != NULL) {
if (pzlib_filefunc_def != NULL)
{
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
zlib_filefunc64_32_def_fill.ztell32_file = NULL;
......@@ -569,10 +585,10 @@ extern unzFile ZEXPORT unzOpen64(const void *path)
extern int ZEXPORT unzClose(unzFile file)
{
unz64_s *s;
unz64_s* s;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
if (s->pfile_in_zip_read != NULL)
unzCloseCurrentFile(file);
......@@ -592,32 +608,34 @@ extern int ZEXPORT unzClose(unzFile file)
local int unzGoToNextDisk OF((unzFile file));
local int unzGoToNextDisk(unzFile file)
{
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
unz64_s* s;
uLong number_disk_next = 0;
s = (unz64_s *)file;
s = (unz64_s*)file;
if (s == NULL)
return UNZ_PARAMERROR;
pfile_in_zip_read_info = s->pfile_in_zip_read;
number_disk_next = s->number_disk;
if ((pfile_in_zip_read_info != NULL) && (pfile_in_zip_read_info->rest_read_uncompressed > 0))
if ((s->pfile_in_zip_read != NULL) && (s->pfile_in_zip_read->rest_read_uncompressed > 0))
/* We are currently reading a file and we need the next sequential disk */
number_disk_next += 1;
else
/* Goto the disk for the current file */
number_disk_next = s->cur_file_info.disk_num_start;
if (number_disk_next != s->number_disk) {
if (number_disk_next != s->number_disk)
{
/* Switch disks */
if ((s->filestream != NULL) && (s->filestream != s->filestream_with_CD))
ZCLOSE64(s->z_filefunc, s->filestream);
if (number_disk_next == s->gi.number_disk_with_CD) {
if (number_disk_next == s->gi.number_disk_with_CD)
{
s->filestream = s->filestream_with_CD;
} else {
s->filestream = ZOPENDISK64(s->z_filefunc, s->filestream_with_CD, (unsigned int)number_disk_next,
}
else
{
s->filestream = ZOPENDISK64(s->z_filefunc, s->filestream_with_CD, number_disk_next,
ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_EXISTING);
}
......@@ -630,12 +648,12 @@ local int unzGoToNextDisk(unzFile file)
return UNZ_OK;
}
extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info32)
extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32)
{
unz64_s *s;
unz64_s* s;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
/* to do : check if number_entry is not truncated */
pglobal_info32->number_entry = (uLong)s->gi.number_entry;
pglobal_info32->size_comment = s->gi.size_comment;
......@@ -643,23 +661,23 @@ extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info3
return UNZ_OK;
}
extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64* pglobal_info)
{
unz64_s *s;
unz64_s* s;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
*pglobal_info = s->gi;
return UNZ_OK;
}
extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uLong comment_size)
{
unz64_s *s;
unz64_s* s;
uLong bytes_to_read = comment_size;
if (file == NULL)
return (int)UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
if (bytes_to_read > s->gi.size_comment)
bytes_to_read = s->gi.size_comment;
......@@ -667,14 +685,15 @@ extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uLong commen
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD, s->central_pos + 22, ZLIB_FILEFUNC_SEEK_SET) != 0)
return UNZ_ERRNO;
if (bytes_to_read > 0) {
if (bytes_to_read>0)
{
*comment = 0;
if (ZREAD64(s->z_filefunc, s->filestream_with_CD, comment, bytes_to_read) != bytes_to_read)
return UNZ_ERRNO;
}
if ((comment != NULL) && (comment_size > s->gi.size_comment))
*(comment + s->gi.size_comment) = 0;
*(comment+s->gi.size_comment) = 0;
return (int)bytes_to_read;
}
......@@ -683,7 +702,7 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
unz_file_info64_internal *pfile_info_internal, char *filename, uLong filename_size, void *extrafield,
uLong extrafield_size, char *comment, uLong comment_size)
{
unz64_s *s;
unz64_s* s;
unz_file_info64 file_info;
unz_file_info64_internal file_info_internal;
ZPOS64_T bytes_to_read;
......@@ -697,14 +716,15 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD,
s->pos_in_central_dir + s->byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = UNZ_ERRNO;
/* Check the magic */
if (err == UNZ_OK) {
if (err == UNZ_OK)
{
if (unz64local_getLong(&s->z_filefunc, s->filestream_with_CD, &uMagic) != UNZ_OK)
err = UNZ_ERRNO;
else if (uMagic != CENTRALHEADERMAGIC)
......@@ -758,29 +778,34 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
lSeek += file_info.size_filename;
if ((err == UNZ_OK) && (filename != NULL)) {
if (file_info.size_filename < filename_size) {
*(filename + file_info.size_filename) = 0;
if ((err == UNZ_OK) && (filename != NULL))
{
if (file_info.size_filename < filename_size)
{
*(filename+file_info.size_filename) = 0;
bytes_to_read = file_info.size_filename;
} else
}
else
bytes_to_read = filename_size;
if ((file_info.size_filename > 0) && (filename_size > 0))
if (ZREAD64(s->z_filefunc, s->filestream_with_CD, filename, (uLong)bytes_to_read) != bytes_to_read)
if (ZREAD64(s->z_filefunc, s->filestream_with_CD,filename, (uLong)bytes_to_read) != bytes_to_read)
err = UNZ_ERRNO;
lSeek -= (uLong)bytes_to_read;
}
/* Read extrafield */
if ((err == UNZ_OK) && (extrafield != NULL)) {
if ((err == UNZ_OK) && (extrafield != NULL))
{
if (file_info.size_file_extra < extrafield_size)
bytes_to_read = file_info.size_file_extra;
else
bytes_to_read = extrafield_size;
if (lSeek != 0) {
if (lSeek != 0)
{
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD, lSeek, ZLIB_FILEFUNC_SEEK_CUR) == 0)
lSeek = 0;
lSeek=0;
else
err = UNZ_ERRNO;
}
......@@ -789,13 +814,16 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
if (ZREAD64(s->z_filefunc, s->filestream_with_CD, extrafield, (uLong)bytes_to_read) != bytes_to_read)
err = UNZ_ERRNO;
lSeek += file_info.size_file_extra - (uLong)bytes_to_read;
} else
}
else
lSeek += file_info.size_file_extra;
if ((err == UNZ_OK) && (file_info.size_file_extra != 0)) {
if (lSeek != 0) {
if ((err == UNZ_OK) && (file_info.size_file_extra != 0))
{
if (lSeek != 0)
{
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD, lSeek, ZLIB_FILEFUNC_SEEK_CUR) == 0)
lSeek = 0;
lSeek=0;
else
err = UNZ_ERRNO;
}
......@@ -808,7 +836,8 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD, current_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = UNZ_ERRNO;
while ((err != UNZ_ERRNO) && (acc < file_info.size_file_extra)) {
while((err != UNZ_ERRNO) && (acc < file_info.size_file_extra))
{
uLong headerid;
uLong datasize;
......@@ -818,26 +847,31 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
err = UNZ_ERRNO;
/* ZIP64 extra fields */
if (headerid == 0x0001) {
if (headerid == 0x0001)
{
/* Subtract size of ZIP64 field, since ZIP64 is handled internally */
file_info.size_file_extra_internal += 2 + 2 + datasize;
if (file_info.uncompressed_size == 0xffffffff) {
if (file_info.uncompressed_size == 0xffffffff)
{
if (unz64local_getLong64(&s->z_filefunc, s->filestream_with_CD, &file_info.uncompressed_size) != UNZ_OK)
err = UNZ_ERRNO;
}
if (file_info.compressed_size == 0xffffffff) {
if (file_info.compressed_size == 0xffffffff)
{
if (unz64local_getLong64(&s->z_filefunc, s->filestream_with_CD, &file_info.compressed_size) != UNZ_OK)
err = UNZ_ERRNO;
}
if (file_info_internal.offset_curfile == 0xffffffff) {
if (file_info_internal.offset_curfile == 0xffffffff)
{
/* Relative Header offset */
if (unz64local_getLong64(&s->z_filefunc, s->filestream_with_CD, &uL64) != UNZ_OK)
err = UNZ_ERRNO;
file_info_internal.offset_curfile = uL64;
file_info.disk_offset = uL64;
}
if (file_info.disk_num_start == 0xffffffff) {
if (file_info.disk_num_start == 0xffffffff)
{
/* Disk Start Number */
if (unz64local_getLong(&s->z_filefunc, s->filestream_with_CD, &file_info.disk_num_start) != UNZ_OK)
err = UNZ_ERRNO;
......@@ -845,7 +879,8 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
}
#ifdef HAVE_AES
/* AES header */
else if (headerid == 0x9901) {
else if (headerid == 0x9901)
{
/* Subtract size of AES field, since AES is handled internally */
file_info.size_file_extra_internal += 2 + 2 + datasize;
......@@ -856,16 +891,16 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
if (uL != 1 && uL != 2)
err = UNZ_ERRNO;
file_info_internal.aes_version = uL;
if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, (int *)&uL) != UNZ_OK)
if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, &uL) != UNZ_OK)
err = UNZ_ERRNO;
if ((char)uL != 'A')
err = UNZ_ERRNO;
if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, (int *)&uL) != UNZ_OK)
if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, &uL) != UNZ_OK)
err = UNZ_ERRNO;
if ((char)uL != 'E')
err = UNZ_ERRNO;
/* Get AES encryption strength and actual compression method */
if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, (int *)&uL) != UNZ_OK)
if (unz64local_getByte(&s->z_filefunc, s->filestream_with_CD, &uL) != UNZ_OK)
err = UNZ_ERRNO;
file_info_internal.aes_encryption_mode = uL;
if (unz64local_getShort(&s->z_filefunc, s->filestream_with_CD, &uL) != UNZ_OK)
......@@ -873,8 +908,9 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
file_info_internal.aes_compression_method = uL;
}
#endif
else {
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD, datasize, ZLIB_FILEFUNC_SEEK_CUR) != 0)
else
{
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD,datasize, ZLIB_FILEFUNC_SEEK_CUR) != 0)
err = UNZ_ERRNO;
}
......@@ -887,14 +923,18 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
else
file_info_internal.byte_before_the_zipfile = 0;
if ((err == UNZ_OK) && (comment != NULL)) {
if (file_info.size_file_comment < comment_size) {
*(comment + file_info.size_file_comment) = 0;
if ((err == UNZ_OK) && (comment != NULL))
{
if (file_info.size_file_comment < comment_size)
{
*(comment+file_info.size_file_comment) = 0;
bytes_to_read = file_info.size_file_comment;
} else
}
else
bytes_to_read = comment_size;
if (lSeek != 0) {
if (lSeek != 0)
{
if (ZSEEK64(s->z_filefunc, s->filestream_with_CD, lSeek, ZLIB_FILEFUNC_SEEK_CUR) != 0)
err = UNZ_ERRNO;
}
......@@ -903,7 +943,8 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
if (ZREAD64(s->z_filefunc, s->filestream_with_CD, comment, (uLong)bytes_to_read) != bytes_to_read)
err = UNZ_ERRNO;
lSeek += file_info.size_file_comment - (uLong)bytes_to_read;
} else
}
else
lSeek += file_info.size_file_comment;
if ((err == UNZ_OK) && (pfile_info != NULL))
......@@ -915,8 +956,8 @@ local int unz64local_GetCurrentFileInfoInternal(unzFile file, unz_file_info64 *p
return err;
}
extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size)
extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info * pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char* comment, uLong comment_size)
{
unz_file_info64 file_info64;
int err;
......@@ -924,7 +965,8 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info
err = unz64local_GetCurrentFileInfoInternal(file, &file_info64, NULL, filename, filename_size,
extrafield, extrafield_size, comment, comment_size);
if ((err == UNZ_OK) && (pfile_info != NULL)) {
if ((err == UNZ_OK) && (pfile_info != NULL))
{
pfile_info->version = file_info64.version;
pfile_info->version_needed = file_info64.version_needed;
pfile_info->flag = file_info64.flag;
......@@ -949,17 +991,17 @@ extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info
return err;
}
extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size)
extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char* comment, uLong comment_size)
{
return unz64local_GetCurrentFileInfoInternal(file, pfile_info, NULL, filename, filename_size,
extrafield, extrafield_size, comment, comment_size);
extrafield, extrafield_size, comment,comment_size);
}
/* Read the local header of the current zipfile. Check the coherency of the local header and info in the
end of central directory about this file store in *piSizeVar the size of extra info in local header
(filename and size of extra field data) */
local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s *s, uInt *piSizeVar, ZPOS64_T *poffset_local_extrafield,
local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s* s, uInt* piSizeVar, ZPOS64_T *poffset_local_extrafield,
uInt *psize_local_extrafield)
{
uLong uMagic, uL, uFlags;
......@@ -980,7 +1022,8 @@ local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s *s, uInt *piSizeVar
s->cur_file_info_internal.byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
return UNZ_ERRNO;
if (err == UNZ_OK) {
if (err == UNZ_OK)
{
if (unz64local_getLong(&s->z_filefunc, s->filestream, &uMagic) != UNZ_OK)
err = UNZ_ERRNO;
else if (uMagic != LOCALHEADERMAGIC)
......@@ -1043,14 +1086,14 @@ local int unz64local_CheckCurrentFileCoherencyHeader(unz64_s *s, uInt *piSizeVar
/*
Open for reading data the current file in the zipfile.
If there is no error and the file is opened, the return value is UNZ_OK.
*/
extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
*/
extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int* method, int* level, int raw, const char* password)
{
int err = UNZ_OK;
int compression_method;
uInt iSizeVar;
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
unz64_s* s;
file_in_zip64_read_info_s* pfile_in_zip_read_info;
ZPOS64_T offset_local_extrafield;
uInt size_local_extrafield;
#ifndef NOUNCRYPT
......@@ -1061,7 +1104,7 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
#endif
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
if (!s->current_file_ok)
return UNZ_PARAMERROR;
......@@ -1071,17 +1114,18 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
if (unz64local_CheckCurrentFileCoherencyHeader(s, &iSizeVar, &offset_local_extrafield, &size_local_extrafield) != UNZ_OK)
return UNZ_BADZIPFILE;
pfile_in_zip_read_info = (file_in_zip64_read_info_s *)ALLOC(sizeof(file_in_zip64_read_info_s));
pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
if (pfile_in_zip_read_info == NULL)
return UNZ_INTERNALERROR;
pfile_in_zip_read_info->read_buffer = (Bytef *)ALLOC(UNZ_BUFSIZE);
pfile_in_zip_read_info->read_buffer = (Bytef*)ALLOC(UNZ_BUFSIZE);
pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
pfile_in_zip_read_info->pos_local_extrafield = 0;
pfile_in_zip_read_info->raw = raw;
if (pfile_in_zip_read_info->read_buffer == NULL) {
if (pfile_in_zip_read_info->read_buffer == NULL)
{
TRYFREE(pfile_in_zip_read_info);
return UNZ_INTERNALERROR;
}
......@@ -1097,12 +1141,14 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
if (method != NULL)
*method = compression_method;
if (level != NULL) {
if (level != NULL)
{
*level = 6;
switch (s->cur_file_info.flag & 0x06) {
case 6: *level = 1; break;
case 4: *level = 2; break;
case 2: *level = 9; break;
switch (s->cur_file_info.flag & 0x06)
{
case 6 : *level = 1; break;
case 4 : *level = 2; break;
case 2 : *level = 9; break;
}
}
......@@ -1127,10 +1173,12 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
pfile_in_zip_read_info->stream.total_in = 0;
pfile_in_zip_read_info->stream.next_in = NULL;
if (!raw) {
if (compression_method == Z_BZIP2ED) {
if (!raw)
{
if (compression_method == Z_BZIP2ED)
{
#ifdef HAVE_BZIP2
pfile_in_zip_read_info->bstream.bzalloc = (void *(*)(void *, int, int)) 0;
pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
pfile_in_zip_read_info->bstream.state = (voidpf)0;
......@@ -1143,15 +1191,18 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
err = BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
if (err == Z_OK)
pfile_in_zip_read_info->stream_initialised = Z_BZIP2ED;
else {
pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
else
{
TRYFREE(pfile_in_zip_read_info);
return err;
}
#else
pfile_in_zip_read_info->raw = 1;
#endif
} else if (compression_method == Z_DEFLATED) {
}
else if (compression_method == Z_DEFLATED)
{
pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
pfile_in_zip_read_info->stream.zfree = (free_func)0;
pfile_in_zip_read_info->stream.opaque = (voidpf)s;
......@@ -1161,7 +1212,8 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
err = inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
if (err == Z_OK)
pfile_in_zip_read_info->stream_initialised = Z_DEFLATED;
else {
else
{
TRYFREE(pfile_in_zip_read_info);
return err;
}
......@@ -1181,15 +1233,18 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
pfile_in_zip_read_info->stream.avail_in = (uInt)0;
s->pfile_in_zip_read = pfile_in_zip_read_info;
s->pcrc_32_tab = NULL;
#ifndef NOUNCRYPT
if ((password != NULL) && ((s->cur_file_info.flag & 1) != 0)) {
if ((password != NULL) && ((s->cur_file_info.flag & 1) != 0))
{
if (ZSEEK64(s->z_filefunc, s->filestream,
s->pfile_in_zip_read->pos_in_zipfile + s->pfile_in_zip_read->byte_before_the_zipfile,
ZLIB_FILEFUNC_SEEK_SET) != 0)
return UNZ_INTERNALERROR;
#ifdef HAVE_AES
if (s->cur_file_info.compression_method == AES_METHOD) {
if (s->cur_file_info.compression_method == AES_METHOD)
{
unsigned char passverify[AES_PWVERIFYSIZE];
unsigned char saltvalue[AES_MAXSALTLENGTH];
uInt saltlength;
......@@ -1205,18 +1260,19 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
if (ZREAD64(s->z_filefunc, s->filestream, passverify, AES_PWVERIFYSIZE) != AES_PWVERIFYSIZE)
return UNZ_INTERNALERROR;
fcrypt_init((int)s->cur_file_info_internal.aes_encryption_mode, (unsigned char *)password, (unsigned int)strlen(password), saltvalue,
fcrypt_init(s->cur_file_info_internal.aes_encryption_mode, password, strlen(password), saltvalue,
passverify, &s->pfile_in_zip_read->aes_ctx);
pfile_in_zip_read_info->rest_read_compressed -= saltlength + AES_PWVERIFYSIZE;
pfile_in_zip_read_info->rest_read_compressed -= AES_AUTHCODESIZE;
s->pfile_in_zip_read->rest_read_compressed -= saltlength + AES_PWVERIFYSIZE;
s->pfile_in_zip_read->rest_read_compressed -= AES_AUTHCODESIZE;
s->pfile_in_zip_read->pos_in_zipfile += saltlength + AES_PWVERIFYSIZE;
} else
}
else
#endif
{
int i;
s->pcrc_32_tab = (const unsigned long *)get_crc_table();
s->pcrc_32_tab = (const unsigned long*)get_crc_table();
init_keys(password, s->keys, s->pcrc_32_tab);
if (ZREAD64(s->z_filefunc, s->filestream, source, 12) < 12)
......@@ -1225,7 +1281,7 @@ extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, in
for (i = 0; i < 12; i++)
zdecode(s->keys, s->pcrc_32_tab, source[i]);
pfile_in_zip_read_info->rest_read_compressed -= 12;
s->pfile_in_zip_read->rest_read_compressed -= 12;
s->pfile_in_zip_read->pos_in_zipfile += 12;
}
......@@ -1240,12 +1296,12 @@ extern int ZEXPORT unzOpenCurrentFile(unzFile file)
return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
}
extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char* password)
{
return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
}
extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw)
extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int* method, int* level, int raw)
{
return unzOpenCurrentFile3(file, method, level, raw, NULL);
}
......@@ -1261,193 +1317,189 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
{
int err = UNZ_OK;
uInt read = 0;
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
unz64_s* s;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
pfile_in_zip_read_info = s->pfile_in_zip_read;
s = (unz64_s*)file;
if (pfile_in_zip_read_info == NULL)
if (s->pfile_in_zip_read == NULL)
return UNZ_PARAMERROR;
if (pfile_in_zip_read_info->read_buffer == NULL)
if (s->pfile_in_zip_read->read_buffer == NULL)
return UNZ_END_OF_LIST_OF_FILE;
if (len == 0)
return 0;
pfile_in_zip_read_info->stream.next_out = (Bytef *)buf;
pfile_in_zip_read_info->stream.avail_out = (uInt)len;
if (pfile_in_zip_read_info->raw) {
if (len > pfile_in_zip_read_info->rest_read_compressed + pfile_in_zip_read_info->stream.avail_in)
pfile_in_zip_read_info->stream.avail_out = (uInt)pfile_in_zip_read_info->rest_read_compressed +
pfile_in_zip_read_info->stream.avail_in;
} else {
// NOTE:
// This bit of code seems to try to set the amount of space in the output buffer based on the
// value stored in the headers stored in the .zip file. However, if those values are incorrect
// it may result in a loss of data when uncompresssing that file. The compressed data is still
// legit and will deflate without knowing the uncompressed code so this tidbit is unnecessary and
// may cause issues for some .zip files.
//
// It's removed in here to fix those issues.
//
// See: https://github.com/ZipArchive/ziparchive/issues/16
//
/*
FIXME: Upgrading to minizip 1.1 caused issues here, Uncommented the code that was commented before. 11/24/2015
*/
if (len > pfile_in_zip_read_info->rest_read_uncompressed)
pfile_in_zip_read_info->stream.avail_out = (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
s->pfile_in_zip_read->stream.next_out = (Bytef*)buf;
s->pfile_in_zip_read->stream.avail_out = (uInt)len;
if (s->pfile_in_zip_read->raw)
{
if (len > s->pfile_in_zip_read->rest_read_compressed + s->pfile_in_zip_read->stream.avail_in)
s->pfile_in_zip_read->stream.avail_out = (uInt)s->pfile_in_zip_read->rest_read_compressed +
s->pfile_in_zip_read->stream.avail_in;
}
else
{
if (len > s->pfile_in_zip_read->rest_read_uncompressed)
s->pfile_in_zip_read->stream.avail_out = (uInt)s->pfile_in_zip_read->rest_read_uncompressed;
}
while (pfile_in_zip_read_info->stream.avail_out > 0) {
if (pfile_in_zip_read_info->stream.avail_in == 0) {
uInt bytes_to_read = UNZ_BUFSIZE;
uInt bytes_not_read = 0;
uInt bytes_read = 0;
uInt total_bytes_read = 0;
if (pfile_in_zip_read_info->stream.next_in != NULL)
bytes_not_read = (uInt)(pfile_in_zip_read_info->read_buffer + UNZ_BUFSIZE -
pfile_in_zip_read_info->stream.next_in);
while (s->pfile_in_zip_read->stream.avail_out > 0)
{
if (s->pfile_in_zip_read->stream.avail_in == 0)
{
uLong bytes_to_read = UNZ_BUFSIZE;
uLong bytes_not_read = 0;
uLong bytes_read = 0;
uLong total_bytes_read = 0;
if (s->pfile_in_zip_read->stream.next_in != NULL)
bytes_not_read = s->pfile_in_zip_read->read_buffer + UNZ_BUFSIZE -
s->pfile_in_zip_read->stream.next_in;
bytes_to_read -= bytes_not_read;
if (bytes_not_read > 0)
memcpy(pfile_in_zip_read_info->read_buffer, pfile_in_zip_read_info->stream.next_in, bytes_not_read);
if (pfile_in_zip_read_info->rest_read_compressed < bytes_to_read)
bytes_to_read = (uInt)pfile_in_zip_read_info->rest_read_compressed;
memcpy(s->pfile_in_zip_read->read_buffer, s->pfile_in_zip_read->stream.next_in, bytes_not_read);
if (s->pfile_in_zip_read->rest_read_compressed < bytes_to_read)
bytes_to_read = (uInt)s->pfile_in_zip_read->rest_read_compressed;
while (total_bytes_read != bytes_to_read) {
if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, pfile_in_zip_read_info->filestream,
pfile_in_zip_read_info->pos_in_zipfile + pfile_in_zip_read_info->byte_before_the_zipfile,
while (total_bytes_read != bytes_to_read)
{
if (ZSEEK64(s->pfile_in_zip_read->z_filefunc, s->pfile_in_zip_read->filestream,
s->pfile_in_zip_read->pos_in_zipfile + s->pfile_in_zip_read->byte_before_the_zipfile,
ZLIB_FILEFUNC_SEEK_SET) != 0)
return UNZ_ERRNO;
bytes_read = (int)ZREAD64(pfile_in_zip_read_info->z_filefunc, pfile_in_zip_read_info->filestream,
pfile_in_zip_read_info->read_buffer + bytes_not_read + total_bytes_read,
bytes_read = ZREAD64(s->pfile_in_zip_read->z_filefunc, s->pfile_in_zip_read->filestream,
s->pfile_in_zip_read->read_buffer + bytes_not_read + total_bytes_read,
bytes_to_read - total_bytes_read);
total_bytes_read += bytes_read;
pfile_in_zip_read_info->pos_in_zipfile += bytes_read;
s->pfile_in_zip_read->pos_in_zipfile += bytes_read;
if (bytes_read == 0) {
if (ZERROR64(pfile_in_zip_read_info->z_filefunc, pfile_in_zip_read_info->filestream))
if (bytes_read == 0)
{
if (ZERROR64(s->pfile_in_zip_read->z_filefunc, s->pfile_in_zip_read->filestream))
return UNZ_ERRNO;
err = unzGoToNextDisk(file);
if (err != UNZ_OK)
return err;
pfile_in_zip_read_info->pos_in_zipfile = 0;
pfile_in_zip_read_info->filestream = s->filestream;
s->pfile_in_zip_read->pos_in_zipfile = 0;
s->pfile_in_zip_read->filestream = s->filestream;
}
}
#ifndef NOUNCRYPT
if ((s->cur_file_info.flag & 1) != 0) {
if ((s->cur_file_info.flag & 1) != 0)
{
#ifdef HAVE_AES
if (s->cur_file_info.compression_method == AES_METHOD) {
fcrypt_decrypt(pfile_in_zip_read_info->read_buffer, bytes_to_read, &s->pfile_in_zip_read->aes_ctx);
} else
if (s->cur_file_info.compression_method == AES_METHOD)
{
fcrypt_decrypt(s->pfile_in_zip_read->read_buffer, bytes_to_read, &s->pfile_in_zip_read->aes_ctx);
}
else
#endif
if (s->pcrc_32_tab != NULL)
{
uInt i;
for (i = 0; i < total_bytes_read; i++)
pfile_in_zip_read_info->read_buffer[i] =
zdecode(s->keys, s->pcrc_32_tab, pfile_in_zip_read_info->read_buffer[i]);
for(i = 0; i < total_bytes_read; i++)
s->pfile_in_zip_read->read_buffer[i] =
zdecode(s->keys, s->pcrc_32_tab, s->pfile_in_zip_read->read_buffer[i]);
}
}
#endif
pfile_in_zip_read_info->rest_read_compressed -= total_bytes_read;
pfile_in_zip_read_info->stream.next_in = (Bytef *)pfile_in_zip_read_info->read_buffer;
pfile_in_zip_read_info->stream.avail_in = (uInt)bytes_not_read + total_bytes_read;
s->pfile_in_zip_read->rest_read_compressed -= total_bytes_read;
s->pfile_in_zip_read->stream.next_in = (Bytef*)s->pfile_in_zip_read->read_buffer;
s->pfile_in_zip_read->stream.avail_in = (uInt)(bytes_not_read + total_bytes_read);
}
if ((pfile_in_zip_read_info->compression_method == 0) || (pfile_in_zip_read_info->raw)) {
if ((s->pfile_in_zip_read->compression_method == 0) || (s->pfile_in_zip_read->raw))
{
uInt copy, i;
if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
(pfile_in_zip_read_info->rest_read_compressed == 0))
if ((s->pfile_in_zip_read->stream.avail_in == 0) &&
(s->pfile_in_zip_read->rest_read_compressed == 0))
return (read == 0) ? UNZ_EOF : read;
if (pfile_in_zip_read_info->stream.avail_out < pfile_in_zip_read_info->stream.avail_in)
copy = pfile_in_zip_read_info->stream.avail_out;
if (s->pfile_in_zip_read->stream.avail_out < s->pfile_in_zip_read->stream.avail_in)
copy = s->pfile_in_zip_read->stream.avail_out;
else
copy = pfile_in_zip_read_info->stream.avail_in;
copy = s->pfile_in_zip_read->stream.avail_in;
for (i = 0; i < copy; i++)
*(pfile_in_zip_read_info->stream.next_out + i) =
*(pfile_in_zip_read_info->stream.next_in + i);
pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + copy;
pfile_in_zip_read_info->rest_read_uncompressed -= copy;
pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
pfile_in_zip_read_info->stream.next_out, copy);
pfile_in_zip_read_info->stream.avail_in -= copy;
pfile_in_zip_read_info->stream.avail_out -= copy;
pfile_in_zip_read_info->stream.next_out += copy;
pfile_in_zip_read_info->stream.next_in += copy;
pfile_in_zip_read_info->stream.total_out += copy;
*(s->pfile_in_zip_read->stream.next_out+i) =
*(s->pfile_in_zip_read->stream.next_in+i);
s->pfile_in_zip_read->total_out_64 = s->pfile_in_zip_read->total_out_64 + copy;
s->pfile_in_zip_read->rest_read_uncompressed -= copy;
s->pfile_in_zip_read->crc32 = crc32(s->pfile_in_zip_read->crc32,
s->pfile_in_zip_read->stream.next_out, copy);
s->pfile_in_zip_read->stream.avail_in -= copy;
s->pfile_in_zip_read->stream.avail_out -= copy;
s->pfile_in_zip_read->stream.next_out += copy;
s->pfile_in_zip_read->stream.next_in += copy;
s->pfile_in_zip_read->stream.total_out += copy;
read += copy;
} else if (pfile_in_zip_read_info->compression_method == Z_BZIP2ED) {
}
else if (s->pfile_in_zip_read->compression_method == Z_BZIP2ED)
{
#ifdef HAVE_BZIP2
uLong total_out_before, total_out_after;
const Bytef *buf_before;
uLong out_bytes;
pfile_in_zip_read_info->bstream.next_in = (char *)pfile_in_zip_read_info->stream.next_in;
pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
pfile_in_zip_read_info->bstream.next_out = (char *)pfile_in_zip_read_info->stream.next_out;
pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
s->pfile_in_zip_read->bstream.next_in = (char*)s->pfile_in_zip_read->stream.next_in;
s->pfile_in_zip_read->bstream.avail_in = s->pfile_in_zip_read->stream.avail_in;
s->pfile_in_zip_read->bstream.total_in_lo32 = (uInt)s->pfile_in_zip_read->stream.total_in;
s->pfile_in_zip_read->bstream.total_in_hi32 = s->pfile_in_zip_read->stream.total_in >> 32;
s->pfile_in_zip_read->bstream.next_out = (char*)s->pfile_in_zip_read->stream.next_out;
s->pfile_in_zip_read->bstream.avail_out = s->pfile_in_zip_read->stream.avail_out;
s->pfile_in_zip_read->bstream.total_out_lo32 = (uInt)s->pfile_in_zip_read->stream.total_out;
s->pfile_in_zip_read->bstream.total_out_hi32 = s->pfile_in_zip_read->stream.total_out >> 32;
total_out_before = s->pfile_in_zip_read->bstream.total_out_lo32 +
(((uLong)s->pfile_in_zip_read->bstream.total_out_hi32) << 32);
buf_before = (const Bytef *)s->pfile_in_zip_read->bstream.next_out;
total_out_before = pfile_in_zip_read_info->bstream.total_out_lo32;
buf_before = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
err = BZ2_bzDecompress(&s->pfile_in_zip_read->bstream);
err = BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
total_out_after = s->pfile_in_zip_read->bstream.total_out_lo32 +
(((uLong)s->pfile_in_zip_read->bstream.total_out_hi32) << 32);
total_out_after = pfile_in_zip_read_info->bstream.total_out_lo32;
out_bytes = total_out_after - total_out_before;
out_bytes = total_out_after-total_out_before;
pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + out_bytes;
pfile_in_zip_read_info->rest_read_uncompressed -= out_bytes;
pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, buf_before, (uInt)(out_bytes));
s->pfile_in_zip_read->total_out_64 = s->pfile_in_zip_read->total_out_64 + out_bytes;
s->pfile_in_zip_read->rest_read_uncompressed -= out_bytes;
s->pfile_in_zip_read->crc32 = crc32(s->pfile_in_zip_read->crc32,buf_before, (uInt)(out_bytes));
read += (uInt)(total_out_after - total_out_before);
pfile_in_zip_read_info->stream.next_in = (Bytef *)pfile_in_zip_read_info->bstream.next_in;
pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
pfile_in_zip_read_info->stream.next_out = (Bytef *)pfile_in_zip_read_info->bstream.next_out;
pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
s->pfile_in_zip_read->stream.next_in = (Bytef*)s->pfile_in_zip_read->bstream.next_in;
s->pfile_in_zip_read->stream.avail_in = s->pfile_in_zip_read->bstream.avail_in;
s->pfile_in_zip_read->stream.total_in = s->pfile_in_zip_read->bstream.total_in_lo32;
s->pfile_in_zip_read->stream.next_out = (Bytef*)s->pfile_in_zip_read->bstream.next_out;
s->pfile_in_zip_read->stream.avail_out = s->pfile_in_zip_read->bstream.avail_out;
s->pfile_in_zip_read->stream.total_out = s->pfile_in_zip_read->bstream.total_out_lo32;
if (err == BZ_STREAM_END)
return (read == 0) ? UNZ_EOF : read;
if (err != BZ_OK)
break;
#endif
} else {
}
else
{
ZPOS64_T total_out_before, total_out_after;
const Bytef *buf_before;
ZPOS64_T out_bytes;
int flush = Z_SYNC_FLUSH;
int flush=Z_SYNC_FLUSH;
total_out_before = pfile_in_zip_read_info->stream.total_out;
buf_before = pfile_in_zip_read_info->stream.next_out;
total_out_before = s->pfile_in_zip_read->stream.total_out;
buf_before = s->pfile_in_zip_read->stream.next_out;
/*
if ((pfile_in_zip_read_info->rest_read_uncompressed ==
......@@ -1455,18 +1507,18 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
(pfile_in_zip_read_info->rest_read_compressed == 0))
flush = Z_FINISH;
*/
err = inflate(&pfile_in_zip_read_info->stream, flush);
err = inflate(&s->pfile_in_zip_read->stream,flush);
if ((err >= 0) && (pfile_in_zip_read_info->stream.msg != NULL))
if ((err >= 0) && (s->pfile_in_zip_read->stream.msg != NULL))
err = Z_DATA_ERROR;
total_out_after = pfile_in_zip_read_info->stream.total_out;
out_bytes = total_out_after - total_out_before;
total_out_after = s->pfile_in_zip_read->stream.total_out;
out_bytes = total_out_after-total_out_before;
pfile_in_zip_read_info->total_out_64 += out_bytes;
pfile_in_zip_read_info->rest_read_uncompressed -= out_bytes;
pfile_in_zip_read_info->crc32 =
crc32(pfile_in_zip_read_info->crc32, buf_before, (uInt)(out_bytes));
s->pfile_in_zip_read->total_out_64 += out_bytes;
s->pfile_in_zip_read->rest_read_uncompressed -= out_bytes;
s->pfile_in_zip_read->crc32 =
crc32(s->pfile_in_zip_read->crc32,buf_before, (uInt)(out_bytes));
read += (uInt)(total_out_after - total_out_before);
......@@ -1484,33 +1536,28 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64(unzFile file)
{
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
s = (unz64_s *)file;
unz64_s* s;
s = (unz64_s*)file;
if (file == NULL)
return 0; /* UNZ_PARAMERROR */
pfile_in_zip_read_info = s->pfile_in_zip_read;
if (pfile_in_zip_read_info == NULL)
if (s->pfile_in_zip_read == NULL)
return 0; /* UNZ_PARAMERROR */
return pfile_in_zip_read_info->pos_in_zipfile + pfile_in_zip_read_info->byte_before_the_zipfile;
return s->pfile_in_zip_read->pos_in_zipfile + s->pfile_in_zip_read->byte_before_the_zipfile;
}
extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len)
{
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
unz64_s* s;
uInt read_now;
ZPOS64_T size_to_read;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
pfile_in_zip_read_info = s->pfile_in_zip_read;
if (pfile_in_zip_read_info == NULL)
s = (unz64_s*)file;
if (s->pfile_in_zip_read == NULL)
return UNZ_PARAMERROR;
size_to_read = pfile_in_zip_read_info->size_local_extrafield - pfile_in_zip_read_info->pos_local_extrafield;
size_to_read = s->pfile_in_zip_read->size_local_extrafield - s->pfile_in_zip_read->pos_local_extrafield;
if (buf == NULL)
return (int)size_to_read;
......@@ -1518,17 +1565,17 @@ extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, unsigned len)
if (len > size_to_read)
read_now = (uInt)size_to_read;
else
read_now = (uInt)len;
read_now = (uInt)len ;
if (read_now == 0)
return 0;
if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, pfile_in_zip_read_info->filestream,
pfile_in_zip_read_info->offset_local_extrafield + pfile_in_zip_read_info->pos_local_extrafield,
if (ZSEEK64(s->pfile_in_zip_read->z_filefunc, s->pfile_in_zip_read->filestream,
s->pfile_in_zip_read->offset_local_extrafield + s->pfile_in_zip_read->pos_local_extrafield,
ZLIB_FILEFUNC_SEEK_SET) != 0)
return UNZ_ERRNO;
if (ZREAD64(pfile_in_zip_read_info->z_filefunc, pfile_in_zip_read_info->filestream, buf, read_now) != read_now)
if (ZREAD64(s->pfile_in_zip_read->z_filefunc, s->pfile_in_zip_read->filestream, buf, read_now) != read_now)
return UNZ_ERRNO;
return (int)read_now;
......@@ -1538,18 +1585,19 @@ extern int ZEXPORT unzCloseCurrentFile(unzFile file)
{
int err = UNZ_OK;
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
unz64_s* s;
file_in_zip64_read_info_s* pfile_in_zip_read_info;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
pfile_in_zip_read_info = s->pfile_in_zip_read;
s = (unz64_s*)file;
pfile_in_zip_read_info=s->pfile_in_zip_read;
if (pfile_in_zip_read_info == NULL)
return UNZ_PARAMERROR;
#ifdef HAVE_AES
if (s->cur_file_info.compression_method == AES_METHOD) {
if (s->cur_file_info.compression_method == AES_METHOD)
{
unsigned char authcode[AES_AUTHCODESIZE];
unsigned char rauthcode[AES_AUTHCODESIZE];
......@@ -1567,7 +1615,8 @@ extern int ZEXPORT unzCloseCurrentFile(unzFile file)
#endif
{
if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
(!pfile_in_zip_read_info->raw)) {
(!pfile_in_zip_read_info->raw))
{
if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
err = UNZ_CRCERROR;
}
......@@ -1594,14 +1643,14 @@ extern int ZEXPORT unzGoToFirstFile2(unzFile file, unz_file_info64 *pfile_info,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size)
{
int err = UNZ_OK;
unz64_s *s;
unz64_s* s;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
s->pos_in_central_dir = s->offset_central_dir;
s->num_file = 0;
err = unz64local_GetCurrentFileInfoInternal(file, &s->cur_file_info, &s->cur_file_info_internal,
filename, filename_size, extrafield, extrafield_size, comment, comment_size);
filename,filename_size, extrafield,extrafield_size, comment,comment_size);
s->current_file_ok = (err == UNZ_OK);
if ((err == UNZ_OK) && (pfile_info != NULL))
memcpy(pfile_info, &s->cur_file_info, sizeof(unz_file_info64));
......@@ -1616,22 +1665,22 @@ extern int ZEXPORT unzGoToFirstFile(unzFile file)
extern int ZEXPORT unzGoToNextFile2(unzFile file, unz_file_info64 *pfile_info, char *filename,
uLong filename_size, void *extrafield, uLong extrafield_size, char *comment, uLong comment_size)
{
unz64_s *s;
unz64_s* s;
int err;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
if (!s->current_file_ok)
return UNZ_END_OF_LIST_OF_FILE;
if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
if (s->num_file + 1 == s->gi.number_entry)
if (s->num_file+1 == s->gi.number_entry)
return UNZ_END_OF_LIST_OF_FILE;
s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment;
s->num_file++;
err = unz64local_GetCurrentFileInfoInternal(file, &s->cur_file_info, &s->cur_file_info_internal,
filename, filename_size, extrafield, extrafield_size, comment, comment_size);
err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, &s->cur_file_info_internal,
filename, filename_size, extrafield,extrafield_size, comment,comment_size);
s->current_file_ok = (err == UNZ_OK);
if ((err == UNZ_OK) && (pfile_info != NULL))
memcpy(pfile_info, &s->cur_file_info, sizeof(unz_file_info64));
......@@ -1645,19 +1694,19 @@ extern int ZEXPORT unzGoToNextFile(unzFile file)
extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func)
{
unz64_s *s;
unz64_s* s;
int err;
unz_file_info64 cur_file_info_saved;
unz_file_info64_internal cur_file_info_internal_saved;
ZPOS64_T num_file_saved;
ZPOS64_T pos_in_central_dir_saved;
char current_filename[UNZ_MAXFILENAMEINZIP + 1];
char current_filename[UNZ_MAXFILENAMEINZIP+1];
if (file == NULL)
return UNZ_PARAMERROR;
if (strlen(filename) >= UNZ_MAXFILENAMEINZIP)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
if (!s->current_file_ok)
return UNZ_END_OF_LIST_OF_FILE;
......@@ -1667,16 +1716,17 @@ extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileName
cur_file_info_saved = s->cur_file_info;
cur_file_info_internal_saved = s->cur_file_info_internal;
err = unzGoToFirstFile2(file, NULL, current_filename, sizeof(current_filename) - 1, NULL, 0, NULL, 0);
err = unzGoToFirstFile2(file, NULL, current_filename, sizeof(current_filename)-1, NULL, 0, NULL, 0);
while (err == UNZ_OK) {
while (err == UNZ_OK)
{
if (filename_compare_func != NULL)
err = filename_compare_func(file, current_filename, filename);
else
err = strcmp(current_filename, filename);
if (err == 0)
return UNZ_OK;
err = unzGoToNextFile2(file, NULL, current_filename, sizeof(current_filename) - 1, NULL, 0, NULL, 0);
err = unzGoToNextFile2(file, NULL, current_filename, sizeof(current_filename)-1, NULL, 0, NULL, 0);
}
/* We failed, so restore the state of the 'current file' to where we were. */
......@@ -1687,18 +1737,19 @@ extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileName
return err;
}
extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos)
extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos* file_pos)
{
unz64_file_pos file_pos64;
int err = unzGetFilePos64(file, &file_pos64);
if (err == UNZ_OK) {
int err = unzGetFilePos64(file,&file_pos64);
if (err == UNZ_OK)
{
file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
file_pos->num_of_file = (uLong)file_pos64.num_of_file;
}
return err;
}
extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos)
extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos* file_pos)
{
unz64_file_pos file_pos64;
......@@ -1706,16 +1757,16 @@ extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos)
return UNZ_PARAMERROR;
file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
file_pos64.num_of_file = file_pos->num_of_file;
return unzGoToFilePos64(file, &file_pos64);
return unzGoToFilePos64(file,&file_pos64);
}
extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos)
extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
{
unz64_s *s;
unz64_s* s;
if (file == NULL || file_pos == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
if (!s->current_file_ok)
return UNZ_END_OF_LIST_OF_FILE;
......@@ -1725,21 +1776,21 @@ extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos)
return UNZ_OK;
}
extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos)
extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
{
unz64_s *s;
unz64_s* s;
int err;
if (file == NULL || file_pos == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
/* jump to the right spot */
s->pos_in_central_dir = file_pos->pos_in_zip_directory;
s->num_file = file_pos->num_of_file;
/* set the current file */
err = unz64local_GetCurrentFileInfoInternal(file, &s->cur_file_info, &s->cur_file_info_internal, NULL, 0, NULL, 0, NULL, 0);
err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, &s->cur_file_info_internal,NULL,0,NULL,0,NULL,0);
/* return results */
s->current_file_ok = (err == UNZ_OK);
return err;
......@@ -1757,11 +1808,11 @@ extern uLong ZEXPORT unzGetOffset(unzFile file)
extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
{
unz64_s *s;
unz64_s* s;
if (file == NULL)
return 0; /* UNZ_PARAMERROR; */
s = (unz64_s *)file;
s = (unz64_s*)file;
if (!s->current_file_ok)
return 0;
if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
......@@ -1777,63 +1828,120 @@ extern int ZEXPORT unzSetOffset(unzFile file, uLong pos)
extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
{
unz64_s *s;
unz64_s* s;
int err;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
s = (unz64_s*)file;
s->pos_in_central_dir = pos;
s->num_file = s->gi.number_entry; /* hack */
err = unz64local_GetCurrentFileInfoInternal(file, &s->cur_file_info, &s->cur_file_info_internal, NULL, 0, NULL, 0, NULL, 0);
s->current_file_ok = (err == UNZ_OK);
return err;
}
extern z_off_t ZEXPORT unztell(unzFile file)
{
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
unz64_s* s;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
pfile_in_zip_read_info = s->pfile_in_zip_read;
if (pfile_in_zip_read_info == NULL)
s = (unz64_s*)file;
if (s->pfile_in_zip_read == NULL)
return UNZ_PARAMERROR;
return (z_off_t)pfile_in_zip_read_info->stream.total_out;
return (z_off_t)s->pfile_in_zip_read->stream.total_out;
}
extern ZPOS64_T ZEXPORT unztell64(unzFile file)
{
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
unz64_s* s;
if (file == NULL)
return (ZPOS64_T)-1;
s = (unz64_s *)file;
pfile_in_zip_read_info = s->pfile_in_zip_read;
if (pfile_in_zip_read_info == NULL)
s = (unz64_s*)file;
if (s->pfile_in_zip_read == NULL)
return (ZPOS64_T)-1;
return s->pfile_in_zip_read->total_out_64;
}
return pfile_in_zip_read_info->total_out_64;
extern int ZEXPORT unzseek(unzFile file, z_off_t offset, int origin)
{
return unzseek64(file, (ZPOS64_T)offset, origin);
}
extern int ZEXPORT unzeof(unzFile file)
extern int ZEXPORT unzseek64(unzFile file, ZPOS64_T offset, int origin)
{
unz64_s *s;
file_in_zip64_read_info_s *pfile_in_zip_read_info;
unz64_s* s;
ZPOS64_T stream_pos_begin;
ZPOS64_T stream_pos_end;
int isWithinBuffer;
ZPOS64_T position;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s *)file;
pfile_in_zip_read_info = s->pfile_in_zip_read;
if (pfile_in_zip_read_info == NULL)
s = (unz64_s*)file;
if (s->pfile_in_zip_read == NULL)
return UNZ_ERRNO;
if (s->pfile_in_zip_read->compression_method != 0)
return UNZ_ERRNO;
if (origin == SEEK_SET)
position = offset;
else if (origin == SEEK_CUR)
position = s->pfile_in_zip_read->total_out_64 + offset;
else if (origin == SEEK_END)
position = s->cur_file_info.compressed_size + offset;
else
return UNZ_PARAMERROR;
if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
if (position > s->cur_file_info.compressed_size)
return UNZ_PARAMERROR;
stream_pos_end = s->pfile_in_zip_read->pos_in_zipfile;
stream_pos_begin = stream_pos_end;
if (stream_pos_begin > UNZ_BUFSIZE)
stream_pos_begin -= UNZ_BUFSIZE;
else
stream_pos_begin = 0;
isWithinBuffer = s->pfile_in_zip_read->stream.avail_in != 0 &&
(s->pfile_in_zip_read->rest_read_compressed != 0 || s->cur_file_info.compressed_size < UNZ_BUFSIZE) &&
position >= stream_pos_begin && position < stream_pos_end;
if (isWithinBuffer)
{
s->pfile_in_zip_read->stream.next_in += position - s->pfile_in_zip_read->total_out_64;
s->pfile_in_zip_read->stream.avail_in = (uInt)(stream_pos_end - position);
}
else
{
s->pfile_in_zip_read->stream.avail_in = 0;
s->pfile_in_zip_read->stream.next_in = 0;
s->pfile_in_zip_read->pos_in_zipfile = s->pfile_in_zip_read->offset_local_extrafield + position;
s->pfile_in_zip_read->rest_read_compressed = s->cur_file_info.compressed_size - position;
}
s->pfile_in_zip_read->rest_read_uncompressed -= (position - s->pfile_in_zip_read->total_out_64);
s->pfile_in_zip_read->stream.total_out = (uLong)position;
s->pfile_in_zip_read->total_out_64 = position;
return UNZ_OK;
}
extern int ZEXPORT unzeof(unzFile file)
{
unz64_s* s;
if (file == NULL)
return UNZ_PARAMERROR;
s = (unz64_s*)file;
if (s->pfile_in_zip_read == NULL)
return UNZ_PARAMERROR;
if (s->pfile_in_zip_read->rest_read_uncompressed == 0)
return 1;
return 0;
}
......@@ -14,13 +14,9 @@
See the accompanying LICENSE file for the full text of the license.
*/
#include "Common.h"
#ifndef _UNZ_H
#define _UNZ_H
#define HAVE_AES
#ifdef __cplusplus
extern "C" {
#endif
......@@ -48,7 +44,6 @@ typedef unzFile__ *unzFile;
typedef voidp unzFile;
#endif
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
......@@ -58,6 +53,78 @@ typedef voidp unzFile;
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_unz;
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info64_s
{
ZPOS64_T number_entry; /* total number of entries in the central dir on this disk */
uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info64;
typedef struct unz_global_info_s
{
uLong number_entry; /* total number of entries in the central dir on this disk */
uLong number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info64_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
ZPOS64_T compressed_size; /* compressed size 8 bytes */
ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
ZPOS64_T disk_offset;
uLong size_file_extra_internal;
} unz_file_info64;
typedef struct unz_file_info_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
uLong compressed_size; /* compressed size 4 bytes */
uLong uncompressed_size; /* uncompressed size 4 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
uLong disk_offset;
} unz_file_info;
/***************************************************************************/
/* Opening and close a zip file */
......@@ -236,6 +303,10 @@ extern z_off_t ZEXPORT unztell OF((unzFile file));
extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
/* return current position in uncompressed data */
extern int ZEXPORT unzseek OF((unzFile file, z_off_t offset, int origin));
extern int ZEXPORT unzseek64 OF((unzFile file, ZPOS64_T offset, int origin));
/* Seek within the uncompressed data if compression method is storage */
extern int ZEXPORT unzeof OF((unzFile file));
/* return 1 if the end of file was reached, 0 elsewhere */
......
......@@ -12,7 +12,7 @@
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>
......@@ -27,7 +27,7 @@
# include <stdlib.h>
#endif
#ifdef NO_ERRNO_H
extern int errno;
extern int errno;
#else
# include <errno.h>
#endif
......@@ -40,10 +40,10 @@ extern int errno;
# define AES_VERSION (0x0001)
# define AES_ENCRYPTIONMODE (0x03)
# include "aes.h"
# include "fileenc.h"
# include "prng.h"
# include "entropy.h"
# include "aes/aes.h"
# include "aes/fileenc.h"
# include "aes/prng.h"
# include "aes/entropy.h"
#endif
#ifndef NOCRYPT
......@@ -56,7 +56,7 @@ extern int errno;
#endif
/* compile with -Dlocal if your debugger can't find static symbols */
#define SIZEDATA_INDATABLOCK (4096 - (4 * 4))
#define SIZEDATA_INDATABLOCK (4096-(4*4))
#define DISKHEADERMAGIC (0x08074b50)
#define LOCALHEADERMAGIC (0x04034b50)
......@@ -81,7 +81,7 @@ extern int errno;
#endif
#ifndef Z_BUFSIZE
# define Z_BUFSIZE (64 * 1024)
# define Z_BUFSIZE (64*1024)
#endif
#ifndef Z_MAXFILENAMEINZIP
# define Z_MAXFILENAMEINZIP (256)
......@@ -91,7 +91,7 @@ extern int errno;
# define ALLOC(size) (malloc(size))
#endif
#ifndef TRYFREE
# define TRYFREE(p) {if (p) free(p); }
# define TRYFREE(p) {if (p) free(p);}
#endif
/* NOT sure that this work on ALL platform */
......@@ -107,20 +107,23 @@ extern int errno;
const char zip_copyright[] = " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
typedef struct linkedlist_datablock_internal_s {
struct linkedlist_datablock_internal_s *next_datablock;
typedef struct linkedlist_datablock_internal_s
{
struct linkedlist_datablock_internal_s* next_datablock;
uLong avail_in_this_block;
uLong filled_in_this_block;
uLong unused; /* for future use and alignment */
unsigned char data[SIZEDATA_INDATABLOCK];
} linkedlist_datablock_internal;
typedef struct linkedlist_data_s {
linkedlist_datablock_internal *first_block;
linkedlist_datablock_internal *last_block;
typedef struct linkedlist_data_s
{
linkedlist_datablock_internal* first_block;
linkedlist_datablock_internal* last_block;
} linkedlist_data;
typedef struct {
typedef struct
{
z_stream stream; /* zLib stream structure for inflate */
#ifdef HAVE_BZIP2
bz_stream bstream; /* bzLib stream structure for bziped */
......@@ -133,7 +136,7 @@ typedef struct {
uInt pos_in_buffered_data; /* last written byte in buffered_data */
ZPOS64_T pos_local_header; /* offset of the local header of the file currently writing */
char *central_header; /* central header data for the current file */
char* central_header; /* central header data for the current file */
uLong size_centralextra;
uLong size_centralheader; /* size of the central header for cur file */
uLong size_centralextrafree; /* Extra bytes allocated to the central header but that are not used */
......@@ -153,12 +156,13 @@ typedef struct {
ZPOS64_T total_uncompressed;
#ifndef NOCRYPT
unsigned long keys[3]; /* keys defining the pseudo-random sequence */
const unsigned long *pcrc_32_tab;
const unsigned long* pcrc_32_tab;
int crypt_header_size;
#endif
} curfile64_info;
typedef struct {
typedef struct
{
zlib_filefunc64_32_def z_filefunc;
voidpf filestream; /* io structure of the zipfile */
voidpf filestream_with_CD; /* io structure of the zipfile with the central dir */
......@@ -179,14 +183,15 @@ typedef struct {
} zip64_internal;
/* Allocate a new data block */
local linkedlist_datablock_internal *allocate_new_datablock OF(());
local linkedlist_datablock_internal *allocate_new_datablock()
local linkedlist_datablock_internal* allocate_new_datablock OF(());
local linkedlist_datablock_internal* allocate_new_datablock()
{
linkedlist_datablock_internal *ldi;
linkedlist_datablock_internal* ldi;
ldi = (linkedlist_datablock_internal *)ALLOC(sizeof(linkedlist_datablock_internal));
ldi = (linkedlist_datablock_internal*)ALLOC(sizeof(linkedlist_datablock_internal));
if (ldi != NULL) {
if (ldi != NULL)
{
ldi->next_datablock = NULL;
ldi->filled_in_this_block = 0;
ldi->avail_in_this_block = SIZEDATA_INDATABLOCK;
......@@ -195,60 +200,64 @@ local linkedlist_datablock_internal *allocate_new_datablock()
}
/* Free data block in linked list */
local void free_datablock OF((linkedlist_datablock_internal * ldi));
local void free_datablock(linkedlist_datablock_internal *ldi)
local void free_datablock OF((linkedlist_datablock_internal* ldi));
local void free_datablock(linkedlist_datablock_internal* ldi)
{
while (ldi != NULL) {
linkedlist_datablock_internal *ldinext = ldi->next_datablock;
while (ldi != NULL)
{
linkedlist_datablock_internal* ldinext = ldi->next_datablock;
TRYFREE(ldi);
ldi = ldinext;
}
}
/* Initialize linked list */
local void init_linkedlist OF((linkedlist_data * ll));
local void init_linkedlist(linkedlist_data *ll)
local void init_linkedlist OF((linkedlist_data* ll));
local void init_linkedlist(linkedlist_data* ll)
{
ll->first_block = ll->last_block = NULL;
}
/* Free entire linked list and all data blocks */
local void free_linkedlist OF((linkedlist_data * ll));
local void free_linkedlist(linkedlist_data *ll)
local void free_linkedlist OF((linkedlist_data* ll));
local void free_linkedlist(linkedlist_data* ll)
{
free_datablock(ll->first_block);
ll->first_block = ll->last_block = NULL;
}
/* Add data to linked list data block */
local int add_data_in_datablock OF((linkedlist_data * ll, const void *buf, uLong len));
local int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
local int add_data_in_datablock OF((linkedlist_data* ll, const void* buf, uLong len));
local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
{
linkedlist_datablock_internal *ldi;
const unsigned char *from_copy;
linkedlist_datablock_internal* ldi;
const unsigned char* from_copy;
if (ll == NULL)
return ZIP_INTERNALERROR;
if (ll->last_block == NULL) {
if (ll->last_block == NULL)
{
ll->first_block = ll->last_block = allocate_new_datablock();
if (ll->first_block == NULL)
return ZIP_INTERNALERROR;
}
ldi = ll->last_block;
from_copy = (unsigned char *)buf;
from_copy = (unsigned char*)buf;
while (len > 0) {
while (len > 0)
{
uInt copy_this;
uInt i;
unsigned char *to_copy;
unsigned char* to_copy;
if (ldi->avail_in_this_block == 0) {
if (ldi->avail_in_this_block == 0)
{
ldi->next_datablock = allocate_new_datablock();
if (ldi->next_datablock == NULL)
return ZIP_INTERNALERROR;
ldi = ldi->next_datablock;
ldi = ldi->next_datablock ;
ll->last_block = ldi;
}
......@@ -260,7 +269,7 @@ local int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
to_copy = &(ldi->data[ldi->filled_in_this_block]);
for (i = 0; i < copy_this; i++)
*(to_copy + i) = *(from_copy + i);
*(to_copy+i) = *(from_copy+i);
ldi->filled_in_this_block += copy_this;
ldi->avail_in_this_block -= copy_this;
......@@ -270,8 +279,8 @@ local int add_data_in_datablock(linkedlist_data *ll, const void *buf, uLong len)
return ZIP_OK;
}
local uLong zip64local_TmzDateToDosDate OF((const tm_zip * ptm));
local uLong zip64local_TmzDateToDosDate(const tm_zip *ptm)
local uLong zip64local_TmzDateToDosDate OF((const tm_zip* ptm));
local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
{
uLong year;
#define zip64local_in_range(min, max, value) ((min) <= (value) && (value) <= (max))
......@@ -299,60 +308,65 @@ local uLong zip64local_TmzDateToDosDate(const tm_zip *ptm)
else /* range [00, 79] */
year += 20;
return
(uLong)(((ptm->tm_mday) + (32 * (ptm->tm_mon + 1)) + (512 * year)) << 16) |
return (uLong)(((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
((ptm->tm_sec / 2) + (32 * ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
}
/* Inputs a long in LSB order to the given file: nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) */
local int zip64local_putValue OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream,
local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream,
ZPOS64_T x, int nbByte));
local int zip64local_putValue(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream,
local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream,
ZPOS64_T x, int nbByte)
{
unsigned char buf[8];
int n;
for (n = 0; n < nbByte; n++) {
for (n = 0; n < nbByte; n++)
{
buf[n] = (unsigned char)(x & 0xff);
x >>= 8;
}
if (x != 0) {
/* data overflow - hack for ZIP64 (X Roche) */
for (n = 0; n < nbByte; n++) {
if (x != 0)
{
/* Data overflow - hack for ZIP64 (X Roche) */
for (n = 0; n < nbByte; n++)
{
buf[n] = 0xff;
}
}
if (ZWRITE64(*pzlib_filefunc_def, filestream, buf, nbByte) != (uLong)nbByte)
if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
return ZIP_ERRNO;
return ZIP_OK;
}
local void zip64local_putValue_inmemory OF((void *dest, ZPOS64_T x, int nbByte));
local void zip64local_putValue_inmemory(void *dest, ZPOS64_T x, int nbByte)
local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
{
unsigned char *buf = (unsigned char *)dest;
unsigned char* buf =(unsigned char*)dest;
int n;
for (n = 0; n < nbByte; n++) {
buf[n] = (unsigned char)(x & 0xff);
x >>= 8;
}
if (x != 0) {
if (x != 0)
{
/* data overflow - hack for ZIP64 */
for (n = 0; n < nbByte; n++) {
for (n = 0; n < nbByte; n++)
{
buf[n] = 0xff;
}
}
}
local int zip64local_getByte OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, int *pi));
local int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, int *pi)
local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
{
unsigned char c;
int err = (int)ZREAD64(*pzlib_filefunc_def, filestream, &c, 1);
if (err == 1) {
int err = (int)ZREAD64(*pzlib_filefunc_def, filestream, &c,1);
if (err == 1)
{
*pi = (int)c;
return ZIP_OK;
}
......@@ -361,8 +375,8 @@ local int zip64local_getByte(const zlib_filefunc64_32_def *pzlib_filefunc_def, v
return ZIP_EOF;
}
local int zip64local_getShort OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, uLong * pX));
local int zip64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
{
uLong x;
int i = 0;
......@@ -381,8 +395,8 @@ local int zip64local_getShort(const zlib_filefunc64_32_def *pzlib_filefunc_def,
return err;
}
local int zip64local_getLong OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, uLong * pX));
local int zip64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, uLong *pX)
local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
{
uLong x;
int i = 0;
......@@ -407,8 +421,8 @@ local int zip64local_getLong(const zlib_filefunc64_32_def *pzlib_filefunc_def, v
return err;
}
local int zip64local_getLong64 OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream, ZPOS64_T * pX));
local int zip64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
{
ZPOS64_T x;
int i = 0;
......@@ -447,13 +461,13 @@ local int zip64local_getLong64(const zlib_filefunc64_32_def *pzlib_filefunc_def,
}
/* Gets the amount of bytes left to write to the current disk for spanning archives */
local int zipGetDiskSizeAvailable OF((zipFile file, ZPOS64_T * size_available));
local int zipGetDiskSizeAvailable OF((zipFile file, ZPOS64_T *size_available));
local int zipGetDiskSizeAvailable(zipFile file, ZPOS64_T *size_available)
{
zip64_internal *zi;
zip64_internal* zi;
ZPOS64_T current_disk_size;
zi = (zip64_internal *)file;
zi = (zip64_internal*)file;
ZSEEK64(zi->z_filefunc, zi->filestream, 0, ZLIB_FILEFUNC_SEEK_END);
current_disk_size = ZTELL64(zi->z_filefunc, zi->filestream);
*size_available = zi->disk_size - current_disk_size;
......@@ -464,10 +478,10 @@ local int zipGetDiskSizeAvailable(zipFile file, ZPOS64_T *size_available)
local int zipGoToSpecificDisk OF((zipFile file, int number_disk, int open_existing));
local int zipGoToSpecificDisk(zipFile file, int number_disk, int open_existing)
{
zip64_internal *zi;
zip64_internal* zi;
int err = ZIP_OK;
zi = (zip64_internal *)file;
zi = (zip64_internal*)file;
if (zi->disk_size == 0)
return err;
......@@ -488,17 +502,17 @@ local int zipGoToSpecificDisk(zipFile file, int number_disk, int open_existing)
local int zipGoToFirstDisk OF((zipFile file));
local int zipGoToFirstDisk(zipFile file)
{
zip64_internal *zi;
zip64_internal* zi;
int number_disk_next;
int err = ZIP_OK;
zi = (zip64_internal *)file;
zi = (zip64_internal*)file;
if (zi->disk_size == 0)
return err;
number_disk_next = 0;
if (zi->number_disk_with_CD > 0)
number_disk_next = (int)zi->number_disk_with_CD - 1;
number_disk_next = zi->number_disk_with_CD - 1;
err = zipGoToSpecificDisk(file, number_disk_next, (zi->append == APPEND_STATUS_ADDINZIP));
if ((err == ZIP_ERRNO) && (zi->append == APPEND_STATUS_ADDINZIP))
err = zipGoToSpecificDisk(file, number_disk_next, 0);
......@@ -512,19 +526,20 @@ local int zipGoToFirstDisk(zipFile file)
local int zipGoToNextDisk OF((zipFile file));
local int zipGoToNextDisk(zipFile file)
{
zip64_internal *zi;
zip64_internal* zi;
ZPOS64_T size_available_in_disk;
int err = ZIP_OK;
int number_disk_next;
zi = (zip64_internal *)file;
zi = (zip64_internal*)file;
if (zi->disk_size == 0)
return err;
number_disk_next = (int)zi->number_disk + 1;
number_disk_next = zi->number_disk + 1;
do {
do
{
err = zipGoToSpecificDisk(file, number_disk_next, (zi->append == APPEND_STATUS_ADDINZIP));
if ((err == ZIP_ERRNO) && (zi->append == APPEND_STATUS_ADDINZIP))
err = zipGoToSpecificDisk(file, number_disk_next, 0);
......@@ -537,29 +552,31 @@ local int zipGoToNextDisk(zipFile file)
zi->number_disk_with_CD = zi->number_disk + 1;
number_disk_next += 1;
} while (size_available_in_disk <= 0);
}
while (size_available_in_disk <= 0);
return err;
}
/* Locate the Central directory of a zipfile (at the end, just before the global comment) */
local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream));
local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream)
local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
{
unsigned char *buf;
unsigned char* buf;
ZPOS64_T file_size;
ZPOS64_T back_read = 4;
ZPOS64_T max_back = 0xffff; /* maximum size of global comment */
ZPOS64_T pos_found = 0;
ZPOS64_T max_back=0xffff; /* maximum size of global comment */
ZPOS64_T pos_found=0;
uLong read_size;
ZPOS64_T read_pos;
int i;
buf = (unsigned char *)ALLOC(BUFREADCOMMENT + 4);
buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
if (buf == NULL)
return 0;
if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0) {
if (ZSEEK64(*pzlib_filefunc_def, filestream, 0, ZLIB_FILEFUNC_SEEK_END) != 0)
{
TRYFREE(buf);
return 0;
}
......@@ -569,27 +586,29 @@ local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_f
if (max_back > file_size)
max_back = file_size;
while (back_read < max_back) {
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) : (uLong)(file_size - read_pos);
read_pos = file_size-back_read;
read_size = ((BUFREADCOMMENT+4) < (file_size-read_pos)) ?
(BUFREADCOMMENT+4) : (uLong)(file_size-read_pos);
if (ZSEEK64(*pzlib_filefunc_def, filestream, read_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
break;
if (ZREAD64(*pzlib_filefunc_def, filestream, buf, read_size) != read_size)
break;
for (i = (int)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;
for (i = (int)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;
}
......@@ -601,9 +620,9 @@ local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def *pzlib_f
}
/* Locate the Central directory 64 of a zipfile (at the end, just before the global comment) */
local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def * pzlib_filefunc_def, voidpf filestream,
local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream,
const ZPOS64_T endcentraloffset));
local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib_filefunc_def, voidpf filestream,
local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream,
const ZPOS64_T endcentraloffset)
{
ZPOS64_T offset;
......@@ -613,24 +632,24 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib
if (ZSEEK64(*pzlib_filefunc_def, filestream, endcentraloffset - SIZECENTRALHEADERLOCATOR, ZLIB_FILEFUNC_SEEK_SET) != 0)
return 0;
/* read locator signature */
/* Read locator signature */
if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK)
return 0;
if (uL != ZIP64ENDLOCHEADERMAGIC)
return 0;
/* number of the disk with the start of the zip64 end of central directory */
/* Number of the disk with the start of the zip64 end of central directory */
if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK)
return 0;
/* relative offset of the zip64 end of central directory record */
/* Relative offset of the zip64 end of central directory record */
if (zip64local_getLong64(pzlib_filefunc_def, filestream, &offset) != ZIP_OK)
return 0;
/* total number of disks */
/* Total number of disks */
if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK)
return 0;
/* Goto end of central directory record */
if (ZSEEK64(*pzlib_filefunc_def, filestream, offset, ZLIB_FILEFUNC_SEEK_SET) != 0)
if (ZSEEK64(*pzlib_filefunc_def,filestream, offset, ZLIB_FILEFUNC_SEEK_SET) != 0)
return 0;
/* the signature */
/* The signature */
if (zip64local_getLong(pzlib_filefunc_def, filestream, &uL) != ZIP_OK)
return 0;
if (uL != ZIP64ENDHEADERMAGIC)
......@@ -639,23 +658,23 @@ local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def *pzlib
return offset;
}
extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment,
zlib_filefunc64_32_def *pzlib_filefunc64_32_def)
extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_size, const char ** globalcomment,
zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
{
zip64_internal ziinit;
zip64_internal *zi;
zip64_internal* zi;
#ifndef NO_ADDFILEINEXISTINGZIP
ZPOS64_T byte_before_the_zipfile; /* byte before the zipfile, (>0 for sfx)*/
ZPOS64_T size_central_dir = 0; /* size of the central directory */
ZPOS64_T offset_central_dir = 0; /* offset of start of central directory */
ZPOS64_T number_entry_CD = 0; /* total number of entries in the central dir */
ZPOS64_T size_central_dir; /* size of the central directory */
ZPOS64_T offset_central_dir; /* offset of start of central directory */
ZPOS64_T number_entry_CD; /* total number of entries in the central dir */
ZPOS64_T number_entry;
ZPOS64_T central_pos;
ZPOS64_T size_central_dir_to_read;
uLong uL;
uLong size_comment = 0;
uLong size_comment;
size_t buf_size = SIZEDATA_INDATABLOCK;
void *buf_read;
void* buf_read;
#endif
int err = ZIP_OK;
int mode;
......@@ -676,12 +695,13 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_
if (ziinit.filestream == NULL)
return NULL;
if (append == APPEND_STATUS_CREATEAFTER) {
if (append == APPEND_STATUS_CREATEAFTER)
{
/* Don't support spanning ZIP with APPEND_STATUS_CREATEAFTER */
if (disk_size > 0)
return NULL;
ZSEEK64(ziinit.z_filefunc, ziinit.filestream, 0, SEEK_END);
ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
}
ziinit.filestream_with_CD = ziinit.filestream;
......@@ -689,153 +709,161 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_
ziinit.number_disk = 0;
ziinit.number_disk_with_CD = 0;
ziinit.disk_size = disk_size;
ziinit.begin_pos = ZTELL64(ziinit.z_filefunc, ziinit.filestream);
ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
ziinit.in_opened_file_inzip = 0;
ziinit.ci.stream_initialised = 0;
ziinit.number_entry = 0;
ziinit.add_position_when_writting_offset = 0;
init_linkedlist(&(ziinit.central_dir));
zi = (zip64_internal *)ALLOC(sizeof(zip64_internal));
if (zi == NULL) {
ZCLOSE64(ziinit.z_filefunc, ziinit.filestream);
zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
if (zi == NULL)
{
ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
return NULL;
}
#ifndef NO_ADDFILEINEXISTINGZIP
/* Add file in a zipfile */
ziinit.globalcomment = NULL;
if (append == APPEND_STATUS_ADDINZIP) {
if (append == APPEND_STATUS_ADDINZIP)
{
/* Read and Cache Central Directory Records */
central_pos = zip64local_SearchCentralDir(&ziinit.z_filefunc, ziinit.filestream);
/* disable to allow appending to empty ZIP archive (must be standard zip, not zip64)
central_pos = zip64local_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream);
/* Disable to allow appending to empty ZIP archive (must be standard zip, not zip64)
if (central_pos == 0)
err = ZIP_ERRNO;
*/
if (err == ZIP_OK) {
/* read end of central directory info */
if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
if (err == ZIP_OK)
{
/* Read end of central directory info */
if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET) != 0)
err = ZIP_ERRNO;
/* the signature, already checked */
/* The signature, already checked */
if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
err = ZIP_ERRNO;
/* number of this disk */
/* Number of this disk */
if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk) != ZIP_OK)
err = ZIP_ERRNO;
/* number of the disk with the start of the central directory */
/* Number of the disk with the start of the central directory */
if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk_with_CD) != ZIP_OK)
err = ZIP_ERRNO;
/* total number of entries in the central dir on this disk */
/* Total number of entries in the central dir on this disk */
number_entry = 0;
if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
err = ZIP_ERRNO;
else
number_entry = uL;
/* total number of entries in the central dir */
/* Total number of entries in the central dir */
number_entry_CD = 0;
if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
err = ZIP_ERRNO;
else
number_entry_CD = uL;
if (number_entry_CD != number_entry)
if (number_entry_CD!=number_entry)
err = ZIP_BADZIPFILE;
/* size of the central directory */
/* Size of the central directory */
size_central_dir = 0;
if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
err = ZIP_ERRNO;
else
size_central_dir = uL;
/* offset of start of central directory with respect to the starting disk number */
/* Offset of start of central directory with respect to the starting disk number */
offset_central_dir = 0;
if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
err = ZIP_ERRNO;
else
offset_central_dir = uL;
/* zipfile global comment length */
/* Zipfile global comment length */
if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &size_comment) != ZIP_OK)
err = ZIP_ERRNO;
if ((err == ZIP_OK) && ((number_entry_CD == 0xffff) || (offset_central_dir == 0xffffffff))) {
if ((err == ZIP_OK) && ((number_entry_CD == 0xffff) || (offset_central_dir == 0xffffffff)))
{
/* Format should be Zip64, as the central directory or file size is too large */
central_pos = zip64local_SearchCentralDir64(&ziinit.z_filefunc, ziinit.filestream, central_pos);
if (central_pos) {
if (central_pos)
{
ZPOS64_T sizeEndOfCentralDirectory;
if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = ZIP_ERRNO;
/* the signature, already checked */
/* The signature, already checked */
if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
err = ZIP_ERRNO;
/* size of zip64 end of central directory record */
/* Size of zip64 end of central directory record */
if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &sizeEndOfCentralDirectory) != ZIP_OK)
err = ZIP_ERRNO;
/* version made by */
/* Version made by */
if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
err = ZIP_ERRNO;
/* version needed to extract */
/* Version needed to extract */
if (zip64local_getShort(&ziinit.z_filefunc, ziinit.filestream, &uL) != ZIP_OK)
err = ZIP_ERRNO;
/* number of this disk */
/* Number of this disk */
if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk) != ZIP_OK)
err = ZIP_ERRNO;
/* number of the disk with the start of the central directory */
/* Number of the disk with the start of the central directory */
if (zip64local_getLong(&ziinit.z_filefunc, ziinit.filestream, &ziinit.number_disk_with_CD) != ZIP_OK)
err = ZIP_ERRNO;
/* total number of entries in the central directory on this disk */
/* Total number of entries in the central directory on this disk */
if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &number_entry) != ZIP_OK)
err = ZIP_ERRNO;
/* total number of entries in the central directory */
/* Total number of entries in the central directory */
if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &number_entry_CD) != ZIP_OK)
err = ZIP_ERRNO;
if (number_entry_CD != number_entry)
if (number_entry_CD!=number_entry)
err = ZIP_BADZIPFILE;
/* size of the central directory */
/* Size of the central directory */
if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &size_central_dir) != ZIP_OK)
err = ZIP_ERRNO;
/* offset of start of central directory with respect to the starting disk number */
/* Offset of start of central directory with respect to the starting disk number */
if (zip64local_getLong64(&ziinit.z_filefunc, ziinit.filestream, &offset_central_dir) != ZIP_OK)
err = ZIP_ERRNO;
} else
}
else
err = ZIP_BADZIPFILE;
}
}
if ((err == ZIP_OK) && (central_pos < offset_central_dir + size_central_dir))
if ((err == ZIP_OK) && (central_pos<offset_central_dir+size_central_dir))
err = ZIP_BADZIPFILE;
if (err != ZIP_OK) {
if (err != ZIP_OK)
{
ZCLOSE64(ziinit.z_filefunc, ziinit.filestream);
TRYFREE(zi);
return NULL;
}
if (size_comment > 0) {
ziinit.globalcomment = (char *)ALLOC(size_comment + 1);
if (ziinit.globalcomment) {
if (size_comment > 0)
{
ziinit.globalcomment = (char*)ALLOC(size_comment+1);
if (ziinit.globalcomment)
{
size_comment = ZREAD64(ziinit.z_filefunc, ziinit.filestream, ziinit.globalcomment, size_comment);
ziinit.globalcomment[size_comment] = 0;
}
}
byte_before_the_zipfile = central_pos - (offset_central_dir + size_central_dir);
byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
ziinit.add_position_when_writting_offset = byte_before_the_zipfile;
/* Store central directory in memory */
size_central_dir_to_read = size_central_dir;
buf_size = SIZEDATA_INDATABLOCK;
buf_read = (void *)ALLOC(buf_size);
if (buf_read == NULL)
err = ZIP_INTERNALERROR;
buf_read = (void*)ALLOC(buf_size);
if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream,
offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = ZIP_ERRNO;
while ((size_central_dir_to_read > 0) && (err == ZIP_OK)) {
while ((size_central_dir_to_read > 0) && (err == ZIP_OK))
{
ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
if (read_this > size_central_dir_to_read)
read_this = size_central_dir_to_read;
......@@ -854,7 +882,7 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_
ziinit.number_entry = number_entry_CD;
if (ZSEEK64(ziinit.z_filefunc, ziinit.filestream,
offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
offset_central_dir+byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = ZIP_ERRNO;
}
......@@ -862,7 +890,8 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_
*globalcomment = ziinit.globalcomment;
#endif
if (err != ZIP_OK) {
if (err != ZIP_OK)
{
#ifndef NO_ADDFILEINEXISTINGZIP
TRYFREE(ziinit.globalcomment);
#endif
......@@ -872,24 +901,26 @@ extern zipFile ZEXPORT zipOpen4(const void *pathname, int append, ZPOS64_T disk_
*zi = ziinit;
zipGoToFirstDisk((zipFile)zi);
return (zipFile)zi;
return(zipFile)zi;
}
extern zipFile ZEXPORT zipOpen2(const char *pathname, int append, zipcharpc *globalcomment,
zlib_filefunc_def *pzlib_filefunc32_def)
extern zipFile ZEXPORT zipOpen2(const char *pathname, int append, const char ** globalcomment,
zlib_filefunc_def* pzlib_filefunc32_def)
{
if (pzlib_filefunc32_def != NULL) {
if (pzlib_filefunc32_def != NULL)
{
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill, pzlib_filefunc32_def);
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
return zipOpen4(pathname, append, 0, globalcomment, &zlib_filefunc64_32_def_fill);
}
return zipOpen4(pathname, append, 0, globalcomment, NULL);
}
extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *globalcomment,
zlib_filefunc64_def *pzlib_filefunc_def)
extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, const char ** globalcomment,
zlib_filefunc64_def* pzlib_filefunc_def)
{
if (pzlib_filefunc_def != NULL) {
if (pzlib_filefunc_def != NULL)
{
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
zlib_filefunc64_32_def_fill.ztell32_file = NULL;
......@@ -899,21 +930,23 @@ extern zipFile ZEXPORT zipOpen2_64(const void *pathname, int append, zipcharpc *
return zipOpen4(pathname, append, 0, globalcomment, NULL);
}
extern zipFile ZEXPORT zipOpen3(const char *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment,
zlib_filefunc_def *pzlib_filefunc32_def)
extern zipFile ZEXPORT zipOpen3(const char *pathname, int append, ZPOS64_T disk_size, const char ** globalcomment,
zlib_filefunc_def* pzlib_filefunc32_def)
{
if (pzlib_filefunc32_def != NULL) {
if (pzlib_filefunc32_def != NULL)
{
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill, pzlib_filefunc32_def);
fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
return zipOpen4(pathname, append, disk_size, globalcomment, &zlib_filefunc64_32_def_fill);
}
return zipOpen4(pathname, append, disk_size, globalcomment, NULL);
}
extern zipFile ZEXPORT zipOpen3_64(const void *pathname, int append, ZPOS64_T disk_size, zipcharpc *globalcomment,
zlib_filefunc64_def *pzlib_filefunc_def)
extern zipFile ZEXPORT zipOpen3_64(const void *pathname, int append, ZPOS64_T disk_size, const char ** globalcomment,
zlib_filefunc64_def* pzlib_filefunc_def)
{
if (pzlib_filefunc_def != NULL) {
if (pzlib_filefunc_def != NULL)
{
zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
zlib_filefunc64_32_def_fill.ztell32_file = NULL;
......@@ -923,22 +956,22 @@ extern zipFile ZEXPORT zipOpen3_64(const void *pathname, int append, ZPOS64_T di
return zipOpen4(pathname, append, disk_size, globalcomment, NULL);
}
extern zipFile ZEXPORT zipOpen(const char *pathname, int append)
extern zipFile ZEXPORT zipOpen(const char* pathname, int append)
{
return zipOpen3((const void *)pathname, append, 0, NULL, NULL);
return zipOpen3((const void*)pathname,append,0,NULL,NULL);
}
extern zipFile ZEXPORT zipOpen64(const void *pathname, int append)
extern zipFile ZEXPORT zipOpen64(const void* pathname, int append)
{
return zipOpen3(pathname, append, 0, NULL, NULL);
return zipOpen3(pathname,append,0,NULL,NULL);
}
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits, int memLevel,
int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64)
extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global,
uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel,
int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64)
{
zip64_internal *zi;
zip64_internal* zi;
uInt size_filename;
uInt size_comment = 0;
uInt i;
......@@ -962,10 +995,11 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
(method != Z_DEFLATED))
return ZIP_PARAMERROR;
zi = (zip64_internal *)file;
zi = (zip64_internal*)file;
if (zi->in_opened_file_inzip == 1) {
err = zipCloseFileInZip(file);
if (zi->in_opened_file_inzip == 1)
{
err = zipCloseFileInZip (file);
if (err != ZIP_OK)
return err;
}
......@@ -979,7 +1013,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
if (zipfi == NULL)
zi->ci.dosDate = 0;
else {
else
{
if (zipfi->dosDate != 0)
zi->ci.dosDate = zipfi->dosDate;
else
......@@ -999,14 +1034,16 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
zi->ci.flag |= 4;
if (level == 1)
zi->ci.flag |= 6;
if (password != NULL) {
if (password != NULL)
{
zi->ci.flag |= 1;
#ifdef HAVE_AES
zi->ci.method = AES_METHOD;
#endif
}
if (zi->disk_size > 0) {
if (zi->disk_size > 0)
{
if ((zi->number_disk == 0) && (zi->number_entry == 0))
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)DISKHEADERMAGIC, 4);
......@@ -1032,50 +1069,47 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
if (zi->ci.method == AES_METHOD)
zi->ci.size_centralextrafree += 11; /* Extra space reserved for AES extra info */
#endif
zi->ci.central_header = (char *)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralextrafree + size_comment);
if (zi->ci.central_header == NULL)
return ZIP_INTERNALERROR;
zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralextrafree + size_comment);
zi->ci.number_disk = zi->number_disk;
/* Write central directory header */
zip64local_putValue_inmemory(zi->ci.central_header, (uLong)CENTRALHEADERMAGIC, 4);
zip64local_putValue_inmemory(zi->ci.central_header + 4, (uLong)versionMadeBy, 2);
zip64local_putValue_inmemory(zi->ci.central_header + 6, (uLong)20, 2);
zip64local_putValue_inmemory(zi->ci.central_header + 8, (uLong)zi->ci.flag, 2);
zip64local_putValue_inmemory(zi->ci.central_header + 10, (uLong)zi->ci.method, 2);
zip64local_putValue_inmemory(zi->ci.central_header + 12, (uLong)zi->ci.dosDate, 4);
zip64local_putValue_inmemory(zi->ci.central_header + 16, (uLong)0, 4); /*crc*/
zip64local_putValue_inmemory(zi->ci.central_header + 20, (uLong)0, 4); /*compr size*/
zip64local_putValue_inmemory(zi->ci.central_header + 24, (uLong)0, 4); /*uncompr size*/
zip64local_putValue_inmemory(zi->ci.central_header + 28, (uLong)size_filename, 2);
zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)size_extrafield_global, 2);
zip64local_putValue_inmemory(zi->ci.central_header + 32, (uLong)size_comment, 2);
zip64local_putValue_inmemory(zi->ci.central_header + 34, (uLong)zi->ci.number_disk, 2); /*disk nm start*/
zip64local_putValue_inmemory(zi->ci.central_header+4, (uLong)versionMadeBy, 2);
zip64local_putValue_inmemory(zi->ci.central_header+6, (uLong)20, 2);
zip64local_putValue_inmemory(zi->ci.central_header+8, (uLong)zi->ci.flag, 2);
zip64local_putValue_inmemory(zi->ci.central_header+10, (uLong)zi->ci.method, 2);
zip64local_putValue_inmemory(zi->ci.central_header+12, (uLong)zi->ci.dosDate, 4);
zip64local_putValue_inmemory(zi->ci.central_header+16, (uLong)0, 4); /*crc*/
zip64local_putValue_inmemory(zi->ci.central_header+20, (uLong)0, 4); /*compr size*/
zip64local_putValue_inmemory(zi->ci.central_header+24, (uLong)0, 4); /*uncompr size*/
zip64local_putValue_inmemory(zi->ci.central_header+28, (uLong)size_filename, 2);
zip64local_putValue_inmemory(zi->ci.central_header+30, (uLong)size_extrafield_global, 2);
zip64local_putValue_inmemory(zi->ci.central_header+32, (uLong)size_comment, 2);
zip64local_putValue_inmemory(zi->ci.central_header+34, (uLong)zi->ci.number_disk, 2); /*disk nm start*/
if (zipfi == NULL)
zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)0, 2);
zip64local_putValue_inmemory(zi->ci.central_header+36, (uLong)0, 2);
else
zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)zipfi->internal_fa, 2);
zip64local_putValue_inmemory(zi->ci.central_header+36, (uLong)zipfi->internal_fa, 2);
if (zipfi == NULL)
zip64local_putValue_inmemory(zi->ci.central_header + 38, (uLong)0, 4);
zip64local_putValue_inmemory(zi->ci.central_header+38, (uLong)0, 4);
else
zip64local_putValue_inmemory(zi->ci.central_header + 38, (uLong)zipfi->external_fa, 4);
zip64local_putValue_inmemory(zi->ci.central_header+38, (uLong)zipfi->external_fa, 4);
if (zi->ci.pos_local_header >= 0xffffffff)
zip64local_putValue_inmemory(zi->ci.central_header + 42, (uLong)0xffffffff, 4);
zip64local_putValue_inmemory(zi->ci.central_header+42, (uLong)0xffffffff, 4);
else
zip64local_putValue_inmemory(zi->ci.central_header + 42,
zip64local_putValue_inmemory(zi->ci.central_header+42,
(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset, 4);
for (i = 0; i < size_filename; i++)
zi->ci.central_header[SIZECENTRALHEADER + i] = filename[i];
zi->ci.central_header[SIZECENTRALHEADER+i] = filename[i];
for (i = 0; i < size_extrafield_global; i++)
zi->ci.central_header[SIZECENTRALHEADER + size_filename + i] =
((const char *)extrafield_global)[i];
zi->ci.central_header[SIZECENTRALHEADER+size_filename+i] =
((const char*)extrafield_global)[i];
/* Store comment at the end for later repositioning */
for (i = 0; i < size_comment; i++)
zi->ci.central_header[zi->ci.size_centralheader +
zi->ci.size_centralextrafree + i] = comment[i];
zi->ci.central_header[zi->ci.size_centralheader+
zi->ci.size_centralextrafree+i] = comment[i];
if (zi->ci.central_header == NULL)
return ZIP_INTERNALERROR;
......@@ -1088,7 +1122,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
/* Write the local header */
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)LOCALHEADERMAGIC, 4);
if (err == ZIP_OK) {
if (err == ZIP_OK)
{
if (zi->ci.zip64)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2); /* version needed to extract */
else
......@@ -1105,13 +1140,15 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0, 4); /* crc 32, unknown */
if (err == ZIP_OK) {
if (err == ZIP_OK)
{
if (zi->ci.zip64)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xFFFFFFFF, 4); /* compressed size, unknown */
else
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0, 4); /* compressed size, unknown */
}
if (err == ZIP_OK) {
if (err == ZIP_OK)
{
if (zi->ci.zip64) /* uncompressed size, unknown */
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xFFFFFFFF, 4);
else /* uncompressed size, unknown */
......@@ -1119,7 +1156,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
}
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_filename, 2);
if (err == ZIP_OK) {
if (err == ZIP_OK)
{
ZPOS64_T size_extrafield = size_extrafield_local;
if (zi->ci.zip64)
size_extrafield += 20;
......@@ -1127,19 +1165,22 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
if (zi->ci.method == AES_METHOD)
size_extrafield += 11;
#endif
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_extrafield, 2);
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_extrafield,2);
}
if ((err == ZIP_OK) && (size_filename > 0)) {
if ((err == ZIP_OK) && (size_filename > 0))
{
if (ZWRITE64(zi->z_filefunc, zi->filestream, filename, size_filename) != size_filename)
err = ZIP_ERRNO;
}
if ((err == ZIP_OK) && (size_extrafield_local > 0)) {
if ((err == ZIP_OK) && (size_extrafield_local > 0))
{
if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
err = ZIP_ERRNO;
}
/* Write the Zip64 extended info */
if ((err == ZIP_OK) && (zi->ci.zip64)) {
if ((err == ZIP_OK) && (zi->ci.zip64))
{
short headerid = 1;
short datasize = 16;
ZPOS64_T compressed_size = 0;
......@@ -1157,7 +1198,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
}
#ifdef HAVE_AES
/* Write the AES extended info */
if ((err == ZIP_OK) && (zi->ci.method == AES_METHOD)) {
if ((err == ZIP_OK) && (zi->ci.method == AES_METHOD))
{
int headerid = 0x9901;
short datasize = 7;
......@@ -1175,7 +1217,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
#ifdef HAVE_BZIP2
zi->ci.bstream.avail_in = (uInt)0;
zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
zi->ci.bstream.next_out = (char *)zi->ci.buffered_data;
zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
zi->ci.bstream.total_in_hi32 = 0;
zi->ci.bstream.total_in_lo32 = 0;
zi->ci.bstream.total_out_hi32 = 0;
......@@ -1189,8 +1231,10 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
zi->ci.stream.total_out = 0;
zi->ci.stream.data_type = Z_BINARY;
if ((err == ZIP_OK) && (!zi->ci.raw)) {
if (method == Z_DEFLATED) {
if ((err == ZIP_OK) && (!zi->ci.raw))
{
if (method == Z_DEFLATED)
{
zi->ci.stream.zalloc = (alloc_func)0;
zi->ci.stream.zfree = (free_func)0;
zi->ci.stream.opaque = (voidpf)zi;
......@@ -1202,7 +1246,9 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
if (err == Z_OK)
zi->ci.stream_initialised = Z_DEFLATED;
} else if (method == Z_BZIP2ED) {
}
else if (method == Z_BZIP2ED)
{
#ifdef HAVE_BZIP2
zi->ci.bstream.bzalloc = 0;
zi->ci.bstream.bzfree = 0;
......@@ -1217,9 +1263,11 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
#ifndef NOCRYPT
zi->ci.crypt_header_size = 0;
if ((err == Z_OK) && ((zi->ci.flag & 1) != 0)) {
if ((err == Z_OK) && ((zi->ci.flag & 1) != 0))
{
#ifdef HAVE_AES
if (zi->ci.method == AES_METHOD) {
if (zi->ci.method == AES_METHOD)
{
unsigned char passverify[AES_PWVERIFYSIZE];
unsigned char saltvalue[AES_MAXSALTLENGTH];
uInt saltlength;
......@@ -1233,7 +1281,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
prng_rand(saltvalue, saltlength, zi->ci.aes_rng);
prng_end(zi->ci.aes_rng);
fcrypt_init(AES_ENCRYPTIONMODE, (unsigned char *)password, (unsigned int)strlen(password), saltvalue, passverify, &zi->ci.aes_ctx);
fcrypt_init(AES_ENCRYPTIONMODE, password, strlen(password), saltvalue, passverify, &zi->ci.aes_ctx);
if (ZWRITE64(zi->z_filefunc, zi->filestream, saltvalue, saltlength) != saltlength)
err = ZIP_ERRNO;
......@@ -1241,7 +1289,8 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
err = ZIP_ERRNO;
zi->ci.crypt_header_size = saltlength + AES_PWVERIFYSIZE + AES_AUTHCODESIZE;
} else
}
else
#endif
{
unsigned char bufHead[RAND_HEAD_LEN];
......@@ -1264,66 +1313,66 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, c
return err;
}
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits,
int memLevel, int strategy, const char *password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase)
extern int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global,
uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits,
int memLevel, int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel,
strategy, password, crcForCrypting, versionMadeBy, flagBase, 0);
}
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits,
int memLevel, int strategy, const char *password, uLong crcForCrypting)
extern int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global,
uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits,
int memLevel, int strategy, const char* password, uLong crcForCrypting)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel,
strategy, password, crcForCrypting, VERSIONMADEBY, 0, 0);
}
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
uInt size_extrafield_global, const char *comment, int method, int level, int raw, int windowBits,
int memLevel, int strategy, const char *password, uLong crcForCrypting, int zip64)
extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global,
uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits,
int memLevel, int strategy, const char* password, uLong crcForCrypting, int zip64)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, raw, windowBits, memLevel, strategy,
password, crcForCrypting, VERSIONMADEBY, 0, zip64);
}
extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
uInt size_extrafield_global, const char *comment, int method, int level, int raw)
extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global,
uInt size_extrafield_global, const char* comment, int method, int level, int raw)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, 0);
}
extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
uInt size_extrafield_global, const char *comment, int method, int level, int raw, int zip64)
extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global,
uInt size_extrafield_global, const char* comment, int method, int level, int raw, int zip64)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, raw, -MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64);
}
extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
uInt size_extrafield_global, const char *comment, int method, int level, int zip64)
extern int ZEXPORT zipOpenNewFileInZip64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void*extrafield_global,
uInt size_extrafield_global, const char* comment, int method, int level, int zip64)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY, NULL, 0, VERSIONMADEBY, 0, zip64);
}
extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const zip_fileinfo *zipfi,
const void *extrafield_local, uInt size_extrafield_local, const void *extrafield_global,
uInt size_extrafield_global, const char *comment, int method, int level)
extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void*extrafield_global,
uInt size_extrafield_global, const char* comment, int method, int level)
{
return zipOpenNewFileInZip4_64(file, filename, zipfi, extrafield_local, size_extrafield_local,
extrafield_global, size_extrafield_global, comment, method, level, 0, -MAX_WBITS, DEF_MEM_LEVEL,
......@@ -1331,8 +1380,8 @@ extern int ZEXPORT zipOpenNewFileInZip(zipFile file, const char *filename, const
}
/* Flushes the write buffer to disk */
local int zip64FlushWriteBuffer OF((zip64_internal * zi));
local int zip64FlushWriteBuffer(zip64_internal *zi)
local int zip64FlushWriteBuffer OF((zip64_internal* zi));
local int zip64FlushWriteBuffer(zip64_internal* zi)
{
int err = ZIP_OK;
uInt written = 0;
......@@ -1341,33 +1390,39 @@ local int zip64FlushWriteBuffer(zip64_internal *zi)
uInt max_write = 0;
ZPOS64_T size_available = 0;
if ((zi->ci.flag & 1) != 0) {
if ((zi->ci.flag & 1) != 0)
{
#ifndef NOCRYPT
#ifdef HAVE_AES
if (zi->ci.method == AES_METHOD) {
if (zi->ci.method == AES_METHOD)
{
fcrypt_encrypt(zi->ci.buffered_data, zi->ci.pos_in_buffered_data, &zi->ci.aes_ctx);
} else
}
else
#endif
{
uInt i;
int t;
for (i = 0; i < zi->ci.pos_in_buffered_data; i++)
zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i], t);
for (i = 0;i < zi->ci.pos_in_buffered_data; i++)
zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
}
#endif
}
write = zi->ci.pos_in_buffered_data;
do {
do
{
max_write = write;
if (zi->disk_size > 0) {
if (zi->disk_size > 0)
{
err = zipGetDiskSizeAvailable((zipFile)zi, &size_available);
if (err != ZIP_OK)
return err;
if (size_available == 0) {
if (size_available == 0)
{
err = zipGoToNextDisk((zipFile)zi);
if (err != ZIP_OK)
return err;
......@@ -1377,25 +1432,29 @@ local int zip64FlushWriteBuffer(zip64_internal *zi)
max_write = (uInt)size_available;
}
written = (unsigned int)ZWRITE64(zi->z_filefunc, zi->filestream, zi->ci.buffered_data + total_written, max_write);
written = ZWRITE64(zi->z_filefunc, zi->filestream, zi->ci.buffered_data + total_written, max_write);
if (ZERROR64(zi->z_filefunc, zi->filestream)) {
if (ZERROR64(zi->z_filefunc, zi->filestream))
{
err = ZIP_ERRNO;
break;
}
total_written += written;
write -= written;
} while (write > 0);
}
while (write > 0);
zi->ci.total_compressed += zi->ci.pos_in_buffered_data;
#ifdef HAVE_BZIP2
if (zi->ci.compression_method == Z_BZIP2ED) {
if (zi->ci.compression_method == Z_BZIP2ED)
{
zi->ci.total_uncompressed += zi->ci.bstream.total_in_lo32;
zi->ci.bstream.total_in_lo32 = 0;
zi->ci.bstream.total_in_hi32 = 0;
} else
}
else
#endif
{
zi->ci.total_uncompressed += zi->ci.stream.total_in;
......@@ -1407,14 +1466,14 @@ local int zip64FlushWriteBuffer(zip64_internal *zi)
return err;
}
extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned int len)
extern int ZEXPORT zipWriteInFileInZip(zipFile file,const void* buf,unsigned int len)
{
zip64_internal *zi;
zip64_internal* zi;
int err = ZIP_OK;
if (file == NULL)
return ZIP_PARAMERROR;
zi = (zip64_internal *)file;
zi = (zip64_internal*)file;
if (zi->in_opened_file_inzip == 0)
return ZIP_PARAMERROR;
......@@ -1422,18 +1481,23 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned i
zi->ci.crc32 = crc32(zi->ci.crc32, buf, (uInt)len);
#ifdef HAVE_BZIP2
if ((zi->ci.compression_method == Z_BZIP2ED) && (!zi->ci.raw)) {
zi->ci.bstream.next_in = (void *)buf;
if ((zi->ci.compression_method == Z_BZIP2ED) && (!zi->ci.raw))
{
zi->ci.bstream.next_in = (void*)buf;
zi->ci.bstream.avail_in = len;
err = BZ_RUN_OK;
while ((err == BZ_RUN_OK) && (zi->ci.bstream.avail_in > 0)) {
if (zi->ci.bstream.avail_out == 0) {
while ((err == BZ_RUN_OK) && (zi->ci.bstream.avail_in > 0))
{
if (zi->ci.bstream.avail_out == 0)
{
if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
err = ZIP_ERRNO;
zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
zi->ci.bstream.next_out = (char *)zi->ci.buffered_data;
} else {
zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
}
else
{
uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
......@@ -1445,14 +1509,17 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned i
if (err == BZ_RUN_OK)
err = ZIP_OK;
} else
}
else
#endif
{
zi->ci.stream.next_in = (Bytef *)buf;
zi->ci.stream.next_in = (Bytef*)buf;
zi->ci.stream.avail_in = len;
while ((err == ZIP_OK) && (zi->ci.stream.avail_in > 0)) {
if (zi->ci.stream.avail_out == 0) {
while ((err == ZIP_OK) && (zi->ci.stream.avail_in > 0))
{
if (zi->ci.stream.avail_out == 0)
{
if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
err = ZIP_ERRNO;
zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
......@@ -1462,20 +1529,23 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned i
if (err != ZIP_OK)
break;
if ((zi->ci.compression_method == Z_DEFLATED) && (!zi->ci.raw)) {
if ((zi->ci.compression_method == Z_DEFLATED) && (!zi->ci.raw))
{
uLong total_out_before = zi->ci.stream.total_out;
err = deflate(&zi->ci.stream, Z_NO_FLUSH);
zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - total_out_before);
} else {
uInt copy_this, i;
}
else
{
uInt copy_this,i;
if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
copy_this = zi->ci.stream.avail_in;
else
copy_this = zi->ci.stream.avail_out;
for (i = 0; i < copy_this; i++)
*(((char *)zi->ci.stream.next_out) + i) =
*(((const char *)zi->ci.stream.next_in) + i);
*(((char*)zi->ci.stream.next_out)+i) =
*(((const char*)zi->ci.stream.next_in)+i);
zi->ci.stream.avail_in -= copy_this;
zi->ci.stream.avail_out -= copy_this;
......@@ -1493,12 +1563,12 @@ extern int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, unsigned i
extern int ZEXPORT zipCloseFileInZipRaw(zipFile file, uLong uncompressed_size, uLong crc32)
{
return zipCloseFileInZipRaw64(file, uncompressed_size, crc32);
return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
}
extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
{
zip64_internal *zi;
zip64_internal* zi;
ZPOS64_T compressed_size;
uLong invalidValue = 0xffffffff;
uLong i = 0;
......@@ -1507,17 +1577,21 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
if (file == NULL)
return ZIP_PARAMERROR;
zi = (zip64_internal *)file;
zi = (zip64_internal*)file;
if (zi->in_opened_file_inzip == 0)
return ZIP_PARAMERROR;
zi->ci.stream.avail_in = 0;
if (!zi->ci.raw) {
if (zi->ci.compression_method == Z_DEFLATED) {
while (err == ZIP_OK) {
if (!zi->ci.raw)
{
if (zi->ci.compression_method == Z_DEFLATED)
{
while (err == ZIP_OK)
{
uLong total_out_before;
if (zi->ci.stream.avail_out == 0) {
if (zi->ci.stream.avail_out == 0)
{
if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
err = ZIP_ERRNO;
zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
......@@ -1527,16 +1601,20 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
err = deflate(&zi->ci.stream, Z_FINISH);
zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - total_out_before);
}
} else if (zi->ci.compression_method == Z_BZIP2ED) {
}
else if (zi->ci.compression_method == Z_BZIP2ED)
{
#ifdef HAVE_BZIP2
err = BZ_FINISH_OK;
while (err == BZ_FINISH_OK) {
while (err == BZ_FINISH_OK)
{
uLong total_out_before;
if (zi->ci.bstream.avail_out == 0) {
if (zi->ci.bstream.avail_out == 0)
{
if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
err = ZIP_ERRNO;
zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
zi->ci.bstream.next_out = (char *)zi->ci.buffered_data;
zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
}
total_out_before = zi->ci.bstream.total_out_lo32;
err = BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
......@@ -1554,13 +1632,15 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
if (err == Z_STREAM_END)
err = ZIP_OK; /* this is normal */
if ((zi->ci.pos_in_buffered_data > 0) && (err == ZIP_OK)) {
if ((zi->ci.pos_in_buffered_data > 0) && (err == ZIP_OK))
{
if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
err = ZIP_ERRNO;
}
#ifdef HAVE_AES
if (zi->ci.method == AES_METHOD) {
if (zi->ci.method == AES_METHOD)
{
unsigned char authcode[AES_AUTHCODESIZE];
fcrypt_end(authcode, &zi->ci.aes_ctx);
......@@ -1570,15 +1650,18 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
}
#endif
if (!zi->ci.raw) {
if (zi->ci.compression_method == Z_DEFLATED) {
if (!zi->ci.raw)
{
if (zi->ci.compression_method == Z_DEFLATED)
{
int tmp_err = deflateEnd(&zi->ci.stream);
if (err == ZIP_OK)
err = tmp_err;
zi->ci.stream_initialised = 0;
}
#ifdef HAVE_BZIP2
else if (zi->ci.compression_method == Z_BZIP2ED) {
else if (zi->ci.compression_method == Z_BZIP2ED)
{
int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
if (err == ZIP_OK)
err = tmperr;
......@@ -1596,21 +1679,22 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
#endif
/* Update current item crc and sizes */
if (compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) {
zip64local_putValue_inmemory(zi->ci.central_header + 4, (uLong)45, 2); /* version made by */
zip64local_putValue_inmemory(zi->ci.central_header + 6, (uLong)45, 2); /* version needed */
if (compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
{
zip64local_putValue_inmemory(zi->ci.central_header+4, (uLong)45, 2); /* version made by */
zip64local_putValue_inmemory(zi->ci.central_header+6, (uLong)45, 2); /* version needed */
}
zip64local_putValue_inmemory(zi->ci.central_header + 16, crc32, 4); /* crc */
zip64local_putValue_inmemory(zi->ci.central_header+16, crc32, 4); /* crc */
if (compressed_size >= 0xffffffff)
zip64local_putValue_inmemory(zi->ci.central_header + 20, invalidValue, 4); /* compr size */
zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue, 4); /* compr size */
else
zip64local_putValue_inmemory(zi->ci.central_header + 20, compressed_size, 4); /* compr size */
zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size, 4); /* compr size */
if (zi->ci.stream.data_type == Z_ASCII)
zip64local_putValue_inmemory(zi->ci.central_header + 36, (uLong)Z_ASCII, 2); /* internal file attrib */
zip64local_putValue_inmemory(zi->ci.central_header+36, (uLong)Z_ASCII, 2); /* internal file attrib */
if (uncompressed_size >= 0xffffffff)
zip64local_putValue_inmemory(zi->ci.central_header + 24, invalidValue, 4); /* uncompr size */
zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue, 4); /* uncompr size */
else
zip64local_putValue_inmemory(zi->ci.central_header + 24, uncompressed_size, 4); /* uncompr size */
zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size, 4); /* uncompr size */
/* Add ZIP64 extra info field for uncompressed size */
if (uncompressed_size >= 0xffffffff)
......@@ -1623,8 +1707,9 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
datasize += 8;
/* Add Extra Information Header for 'ZIP64 information' */
if (datasize > 0) {
char *p = zi->ci.central_header + zi->ci.size_centralheader;
if (datasize > 0)
{
char* p = zi->ci.central_header + zi->ci.size_centralheader;
if ((uLong)(datasize + 4) > zi->ci.size_centralextrafree)
return ZIP_BADZIPFILE;
......@@ -1634,15 +1719,18 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
zip64local_putValue_inmemory(p, datasize, 2);
p += 2;
if (uncompressed_size >= 0xffffffff) {
if (uncompressed_size >= 0xffffffff)
{
zip64local_putValue_inmemory(p, uncompressed_size, 8);
p += 8;
}
if (compressed_size >= 0xffffffff) {
if (compressed_size >= 0xffffffff)
{
zip64local_putValue_inmemory(p, compressed_size, 8);
p += 8;
}
if (zi->ci.pos_local_header >= 0xffffffff) {
if (zi->ci.pos_local_header >= 0xffffffff)
{
zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
p += 8;
}
......@@ -1651,13 +1739,14 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
zi->ci.size_centralheader += datasize + 4;
zi->ci.size_centralextra += datasize + 4;
zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)zi->ci.size_centralextra, 2);
zip64local_putValue_inmemory(zi->ci.central_header+30, (uLong)zi->ci.size_centralextra, 2);
}
#ifdef HAVE_AES
/* Write the AES extended info */
if (zi->ci.method == AES_METHOD) {
char *p = zi->ci.central_header + zi->ci.size_centralheader;
if (zi->ci.method == AES_METHOD)
{
char* p = zi->ci.central_header + zi->ci.size_centralheader;
datasize = 7;
......@@ -1683,13 +1772,13 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
zi->ci.size_centralheader += datasize + 4;
zi->ci.size_centralextra += datasize + 4;
zip64local_putValue_inmemory(zi->ci.central_header + 30, (uLong)zi->ci.size_centralextra, 2);
zip64local_putValue_inmemory(zi->ci.central_header+30, (uLong)zi->ci.size_centralextra, 2);
}
#endif
/* Restore comment to correct position */
for (i = 0; i < zi->ci.size_comment; i++)
zi->ci.central_header[zi->ci.size_centralheader + i] =
zi->ci.central_header[zi->ci.size_centralheader + zi->ci.size_centralextrafree + i];
zi->ci.central_header[zi->ci.size_centralheader+i] =
zi->ci.central_header[zi->ci.size_centralheader+zi->ci.size_centralextrafree+i];
zi->ci.size_centralheader += zi->ci.size_comment;
if (err == ZIP_OK)
......@@ -1697,22 +1786,25 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
free(zi->ci.central_header);
if (err == ZIP_OK) {
if (err == ZIP_OK)
{
/* Update the LocalFileHeader with the new values. */
ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream);
uLong cur_number_disk = zi->number_disk;
/* Local file header is stored on previous disk, switch to make edits */
if (zi->ci.number_disk != cur_number_disk)
err = zipGoToSpecificDisk(file, (int)zi->ci.number_disk, 1);
err = zipGoToSpecificDisk(file, zi->ci.number_disk, 1);
if (ZSEEK64(zi->z_filefunc, zi->filestream, zi->ci.pos_local_header + 14, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = ZIP_ERRNO;
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, crc32, 4); /* crc 32, unknown */
err = zip64local_putValue(&zi->z_filefunc, zi->filestream,crc32,4); /* crc 32, unknown */
if (uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff) {
if (zi->ci.pos_zip64extrainfo > 0) {
if (uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff)
{
if (zi->ci.pos_zip64extrainfo > 0)
{
/* Update the size in the ZIP64 extended field. */
if (ZSEEK64(zi->z_filefunc, zi->filestream, zi->ci.pos_zip64extrainfo + 4, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = ZIP_ERRNO;
......@@ -1721,18 +1813,21 @@ extern int ZEXPORT zipCloseFileInZipRaw64(zipFile file, ZPOS64_T uncompressed_si
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
if (err == ZIP_OK) /* uncompressed size, unknown */
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
} else
}
else
err = ZIP_BADZIPFILE; /* Caller passed zip64 = 0, so no room for zip64 info -> fatal */
} else {
}
else
{
if (err == ZIP_OK) /* compressed size, unknown */
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 4);
err = zip64local_putValue(&zi->z_filefunc, zi->filestream,compressed_size, 4);
if (err == ZIP_OK) /* uncompressed size, unknown */
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 4);
err = zip64local_putValue(&zi->z_filefunc, zi->filestream,uncompressed_size, 4);
}
/* Now switch back again to the disk we were on before */
if (zi->ci.number_disk != cur_number_disk)
err = zipGoToSpecificDisk(file, (int)cur_number_disk, 1);
err = zipGoToSpecificDisk(file, cur_number_disk, 1);
if (ZSEEK64(zi->z_filefunc, zi->filestream, cur_pos_inzip, ZLIB_FILEFUNC_SEEK_SET) != 0)
err = ZIP_ERRNO;
......@@ -1749,9 +1844,9 @@ extern int ZEXPORT zipCloseFileInZip(zipFile file)
return zipCloseFileInZipRaw(file, 0, 0);
}
extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
extern int ZEXPORT zipClose(zipFile file, const char* global_comment)
{
zip64_internal *zi;
zip64_internal* zi;
int err = 0;
uLong size_centraldir = 0;
uInt size_global_comment = 0;
......@@ -1762,7 +1857,7 @@ extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
if (file == NULL)
return ZIP_PARAMERROR;
zi = (zip64_internal *)file;
zi = (zip64_internal*)file;
if (zi->in_opened_file_inzip == 1)
err = zipCloseFileInZip(file);
......@@ -1772,7 +1867,8 @@ extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
global_comment = zi->globalcomment;
#endif
if (zi->filestream != zi->filestream_with_CD) {
if (zi->filestream != zi->filestream_with_CD)
{
if (ZCLOSE64(zi->z_filefunc, zi->filestream) != 0)
if (err == ZIP_OK)
err = ZIP_ERRNO;
......@@ -1783,10 +1879,13 @@ extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
centraldir_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream);
if (err == ZIP_OK) {
linkedlist_datablock_internal *ldi = zi->central_dir.first_block;
while (ldi != NULL) {
if ((err == ZIP_OK) && (ldi->filled_in_this_block > 0)) {
if (err == ZIP_OK)
{
linkedlist_datablock_internal* ldi = zi->central_dir.first_block;
while (ldi!= NULL)
{
if ((err == ZIP_OK) && (ldi->filled_in_this_block > 0))
{
write = ZWRITE64(zi->z_filefunc, zi->filestream, ldi->data, ldi->filled_in_this_block);
if (write != ldi->filled_in_this_block)
err = ZIP_ERRNO;
......@@ -1802,88 +1901,94 @@ extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
/* Write the ZIP64 central directory header */
if (pos >= 0xffffffff || zi->number_entry > 0xffff) {
if (pos >= 0xffffffff || zi->number_entry > 0xffff)
{
ZPOS64_T zip64eocd_pos_inzip = ZTELL64(zi->z_filefunc, zi->filestream);
uLong zip64datasize = 44;
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ZIP64ENDHEADERMAGIC, 4);
/* size of this 'zip64 end of central directory' */
/* Size of this 'zip64 end of central directory' */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)zip64datasize, 8);
/* version made by */
/* Version made by */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2);
/* version needed */
/* Version needed */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)45, 2);
/* number of this disk */
/* Number of this disk */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
/* number of the disk with the start of the central directory */
/* Number of the disk with the start of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
/* total number of entries in the central dir on this disk */
/* Total number of entries in the central dir on this disk */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
/* total number of entries in the central dir */
/* Total number of entries in the central dir */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
/* size of the central directory */
/* Size of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)size_centraldir, 8);
if (err == ZIP_OK) {
/* offset of start of central directory with respect to the starting disk number */
if (err == ZIP_OK)
{
/* Offset of start of central directory with respect to the starting disk number */
ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)pos, 8);
}
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ZIP64ENDLOCHEADERMAGIC, 4);
/* number of the disk with the start of the central directory */
/* Number of the disk with the start of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 4);
/*relative offset to the Zip64EndOfCentralDirectory */
if (err == ZIP_OK) {
/* Relative offset to the Zip64EndOfCentralDirectory */
if (err == ZIP_OK)
{
ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, pos, 8);
}
/* number of the disk with the start of the central directory */
/* Number of the disk with the start of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD + 1, 4);
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD+1, 4);
}
/* Write the central directory header */
/* signature */
/* Signature */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)ENDHEADERMAGIC, 4);
/* number of this disk */
/* Number of this disk */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 2);
/* number of the disk with the start of the central directory */
/* Number of the disk with the start of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_disk_with_CD, 2);
/* total number of entries in the central dir on this disk */
if (err == ZIP_OK) {
/* Total number of entries in the central dir on this disk */
if (err == ZIP_OK)
{
if (zi->number_entry >= 0xffff)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffff, 2); /* use value in ZIP64 record */
else
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_entry, 2);
}
/* total number of entries in the central dir */
if (err == ZIP_OK) {
/* Total number of entries in the central dir */
if (err == ZIP_OK)
{
if (zi->number_entry >= 0xffff)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffff, 2); /* use value in ZIP64 record */
else
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)zi->number_entry, 2);
}
/* size of the central directory */
/* Size of the central directory */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_centraldir,4);
/* Offset of start of central directory with respect to the starting disk number */
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_centraldir, 4);
/* offset of start of central directory with respect to the starting disk number */
if (err == ZIP_OK) {
{
ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
if (pos >= 0xffffffff)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)0xffffffff, 4);
......@@ -1897,7 +2002,8 @@ extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
size_global_comment = (uInt)strlen(global_comment);
if (err == ZIP_OK)
err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (uLong)size_global_comment, 2);
if (err == ZIP_OK && size_global_comment > 0) {
if (err == ZIP_OK && size_global_comment > 0)
{
if (ZWRITE64(zi->z_filefunc, zi->filestream, global_comment, size_global_comment) != size_global_comment)
err = ZIP_ERRNO;
}
......@@ -1912,4 +2018,3 @@ extern int ZEXPORT zipClose(zipFile file, const char *global_comment)
return err;
}
......@@ -15,8 +15,6 @@
#ifndef _ZIP_H
#define _ZIP_H
#define HAVE_AES
#ifdef __cplusplus
extern "C" {
#endif
......@@ -79,8 +77,6 @@ typedef struct
uLong external_fa; /* external file attributes 4 bytes */
} zip_fileinfo;
typedef const char* zipcharpc;
#define APPEND_STATUS_CREATE (0)
#define APPEND_STATUS_CREATEAFTER (1)
#define APPEND_STATUS_ADDINZIP (2)
......@@ -107,18 +103,18 @@ extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
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 OF((const char *pathname, int append, zipcharpc* globalcomment,
extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, int append, const char ** globalcomment,
zlib_filefunc_def* pzlib_filefunc_def));
extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, int append, zipcharpc* globalcomment,
extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, int append, const char ** globalcomment,
zlib_filefunc64_def* pzlib_filefunc_def));
extern zipFile ZEXPORT zipOpen3 OF((const char *pathname, int append, ZPOS64_T disk_size,
zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc_def));
const char ** globalcomment, zlib_filefunc_def* pzlib_filefunc_def));
/* Same as zipOpen2 but allows specification of spanned zip size */
extern zipFile ZEXPORT zipOpen3_64 OF((const void *pathname, int append, ZPOS64_T disk_size,
zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def));
const char ** globalcomment, zlib_filefunc64_def* pzlib_filefunc_def));
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, const char* filename, const zip_fileinfo* zipfi,
const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment