diff --git a/.gitignore b/.gitignore index ca59eff..6703d61 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ xcuserdata ## Obj-C/Swift specific *.hmap *.ipa +*.swiftpm diff --git a/.gitmodules b/.gitmodules index 68173e1..81b5365 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "Dependencies/OpenSSL"] path = Dependencies/OpenSSL - url = https://github.com/krzyzanowskim/OpenSSL.git + url = https://github.com/rileytestut/OpenSSL [submodule "Dependencies/ldid"] path = Dependencies/ldid url = https://github.com/rileytestut/ldid.git diff --git a/AltSign.podspec b/AltSign.podspec deleted file mode 100644 index 97bbb74..0000000 --- a/AltSign.podspec +++ /dev/null @@ -1,62 +0,0 @@ -Pod::Spec.new do |spec| - spec.name = "AltSign" - spec.version = "0.1" - spec.summary = "Open source iOS code-signing framework." - spec.description = "iOS framework to manage Apple developer accounts and resign apps." - spec.homepage = "https://github.com/rileytestut/altsign" - spec.license = "MIT" - spec.platform = :ios, "12.0" - spec.source = { :git => "https://github.com/rileytestut/AltSign.git" } - - spec.author = { "Riley Testut" => "riley@rileytestut.com" } - spec.social_media_url = "https://twitter.com/rileytestut" - - spec.source_files = "AltSign", "AltSign/**/*.{h,m,mm,hpp,cpp}" - spec.public_header_files = "AltSign/**/*.h" - spec.resources = "AltSign/Resources/apple.pem" - spec.library = "c++" - - spec.xcconfig = { - "OTHER_CFLAGS" => "-DCORECRYPTO_DONOT_USE_TRANSPARENT_UNION=1" - } - - # Somewhat hacky subspec usage to ensure directory hierarchies match what header includes expect. - - spec.subspec 'OpenSSL' do |base| - base.source_files = "Dependencies/OpenSSL/ios/include/openssl/*.h" - base.header_mappings_dir = "Dependencies/OpenSSL/ios/include" - base.private_header_files = "Dependencies/OpenSSL/ios/include/openssl/*.h" - base.vendored_libraries = "Dependencies/OpenSSL/ios/lib/libcrypto.a", "Dependencies/OpenSSL/ios/lib/libssl.a" - end - - spec.subspec 'ldid' do |base| - base.source_files = "AltSign/ldid/*.{hpp,h,c,cpp}", "Dependencies/ldid/*.{hpp,h,c,cpp}" - base.private_header_files = "AltSign/ldid/*.hpp", "Dependencies/ldid/*.{hpp,h}" - base.header_mappings_dir = "" - end - - spec.subspec 'plist' do |base| - base.source_files = "Dependencies/ldid/libplist/include/plist/*.h", "Dependencies/ldid/libplist/src/*.{c,cpp}", "Dependencies/ldid/libplist/libcnary/**/*.{h,c}" - base.exclude_files = "Dependencies/ldid/libplist/include/plist/String.h", "Dependencies/ldid/libplist/include/plist/Node.h" # Conflict with string.h and node.h, so exclude them. - base.private_header_files = "Dependencies/ldid/libplist/include/plist/*.h", "Dependencies/ldid/libplist/libcnary/**/*.h" - base.header_mappings_dir = "Dependencies/ldid/libplist" - - # Add libplist include directory so we can still find String.h and Node.h when explicitly requested. - base.xcconfig = { "HEADER_SEARCH_PATHS" => '"$(SRCROOT)/../Dependencies/AltSign/Dependencies/ldid/libplist/include" "$(SRCROOT)/../Dependencies/AltSign/Dependencies/ldid/libplist/src"' } - end - - spec.subspec 'minizip' do |base| - base.source_files = "Dependencies/minizip/*.{h,c}" - base.exclude_files = "Dependencies/minizip/iowin32.*", "Dependencies/minizip/minizip.c", "Dependencies/minizip/miniunz.c" - base.private_header_files = "Dependencies/minizip/*.h" - base.header_mappings_dir = "Dependencies" - end - - spec.subspec 'CoreCrypto' do |base| - base.source_files = "Dependencies/corecrypto/*.{h,m}" - base.exclude_files = "Dependencies/corecrypto/ccperf.h" - base.private_header_files = "Dependencies/corecrypto/*.h" - base.header_mappings_dir = "Dependencies" - end - -end diff --git a/AltSign.xcodeproj/project.pbxproj b/AltSign.xcodeproj/project.pbxproj deleted file mode 100644 index d8fcf2c..0000000 --- a/AltSign.xcodeproj/project.pbxproj +++ /dev/null @@ -1,1355 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 50; - objects = { - -/* Begin PBXBuildFile section */ - BF0C4EA022A1B3BF009A2DD7 /* Uid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8422A1B3BE009A2DD7 /* Uid.cpp */; }; - BF0C4EA122A1B3BF009A2DD7 /* Node.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8522A1B3BE009A2DD7 /* Node.cpp */; }; - BF0C4EA222A1B3BF009A2DD7 /* Real.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8722A1B3BE009A2DD7 /* Real.cpp */; }; - BF0C4EA322A1B3BF009A2DD7 /* Date.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8822A1B3BE009A2DD7 /* Date.cpp */; }; - BF0C4EA422A1B3BF009A2DD7 /* bytearray.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8922A1B3BE009A2DD7 /* bytearray.c */; }; - BF0C4EA522A1B3BF009A2DD7 /* time64.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8A22A1B3BE009A2DD7 /* time64.c */; }; - BF0C4EA622A1B3BF009A2DD7 /* Structure.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8C22A1B3BE009A2DD7 /* Structure.cpp */; }; - BF0C4EA722A1B3BF009A2DD7 /* plist.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8D22A1B3BE009A2DD7 /* plist.c */; }; - BF0C4EA822A1B3BF009A2DD7 /* base64.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E8F22A1B3BE009A2DD7 /* base64.c */; }; - BF0C4EA922A1B3BF009A2DD7 /* Array.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9122A1B3BF009A2DD7 /* Array.cpp */; }; - BF0C4EAA22A1B3BF009A2DD7 /* xplist.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9222A1B3BF009A2DD7 /* xplist.c */; }; - BF0C4EAB22A1B3BF009A2DD7 /* Boolean.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9422A1B3BF009A2DD7 /* Boolean.cpp */; }; - BF0C4EAC22A1B3BF009A2DD7 /* bplist.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9522A1B3BF009A2DD7 /* bplist.c */; }; - BF0C4EAD22A1B3BF009A2DD7 /* Key.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9822A1B3BF009A2DD7 /* Key.cpp */; }; - BF0C4EAE22A1B3BF009A2DD7 /* Dictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9A22A1B3BF009A2DD7 /* Dictionary.cpp */; }; - BF0C4EAF22A1B3BF009A2DD7 /* Integer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9B22A1B3BF009A2DD7 /* Integer.cpp */; }; - BF0C4EB022A1B3BF009A2DD7 /* ptrarray.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9C22A1B3BF009A2DD7 /* ptrarray.c */; }; - BF0C4EB122A1B3BF009A2DD7 /* String.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9D22A1B3BF009A2DD7 /* String.cpp */; }; - BF0C4EB222A1B3BF009A2DD7 /* hashtable.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9E22A1B3BF009A2DD7 /* hashtable.c */; }; - BF0C4EB322A1B3BF009A2DD7 /* Data.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4E9F22A1B3BF009A2DD7 /* Data.cpp */; }; - BF0C4EB722A1B3CC009A2DD7 /* node.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4EB422A1B3CC009A2DD7 /* node.c */; }; - BF0C4EB822A1B3CC009A2DD7 /* cnary.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4EB522A1B3CC009A2DD7 /* cnary.c */; }; - BF0C4EB922A1B3CC009A2DD7 /* node_list.c in Sources */ = {isa = PBXBuildFile; fileRef = BF0C4EB622A1B3CC009A2DD7 /* node_list.c */; }; - BF17BB7322EA839500D7D842 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF17BB7222EA839400D7D842 /* UIKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; - BF48CFEE229437580004760B /* ALTCertificateRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = BF48CFEC229437580004760B /* ALTCertificateRequest.h */; }; - BF48CFF0229438C10004760B /* ALTCertificateRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = BF48CFED229437580004760B /* ALTCertificateRequest.m */; }; - BF48CFF622944FC60004760B /* ALTAppID.h in Headers */ = {isa = PBXBuildFile; fileRef = BF48CFF422944FC60004760B /* ALTAppID.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF48CFF722944FC60004760B /* ALTAppID.m in Sources */ = {isa = PBXBuildFile; fileRef = BF48CFF522944FC60004760B /* ALTAppID.m */; }; - BF50E7B822C161630070E17B /* ALTAppGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = BF50E7B622C161630070E17B /* ALTAppGroup.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF50E7B922C161630070E17B /* ALTAppGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = BF50E7B622C161630070E17B /* ALTAppGroup.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF50E7BA22C161630070E17B /* ALTAppGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = BF50E7B722C161630070E17B /* ALTAppGroup.m */; }; - BF50E7BB22C161630070E17B /* ALTAppGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = BF50E7B722C161630070E17B /* ALTAppGroup.m */; }; - BF50E7BF22C163DC0070E17B /* ALTApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = BF50E7BD22C163DC0070E17B /* ALTApplication.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF50E7C022C163DC0070E17B /* ALTApplication.h in Headers */ = {isa = PBXBuildFile; fileRef = BF50E7BD22C163DC0070E17B /* ALTApplication.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF50E7C122C163DC0070E17B /* ALTApplication.mm in Sources */ = {isa = PBXBuildFile; fileRef = BF50E7BE22C163DC0070E17B /* ALTApplication.mm */; }; - BF50E7C222C163DC0070E17B /* ALTApplication.mm in Sources */ = {isa = PBXBuildFile; fileRef = BF50E7BE22C163DC0070E17B /* ALTApplication.mm */; }; - BF50E7C622C169290070E17B /* alt_ldid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF50E7C322C1690B0070E17B /* alt_ldid.cpp */; }; - BF50E7CF22C28F8B0070E17B /* ALTCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = BF50E7CD22C28F8B0070E17B /* ALTCapabilities.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF50E7D022C28F8B0070E17B /* ALTCapabilities.h in Headers */ = {isa = PBXBuildFile; fileRef = BF50E7CD22C28F8B0070E17B /* ALTCapabilities.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF50E7D122C28F8B0070E17B /* ALTCapabilities.m in Sources */ = {isa = PBXBuildFile; fileRef = BF50E7CE22C28F8B0070E17B /* ALTCapabilities.m */; }; - BF50E7D222C28F8B0070E17B /* ALTCapabilities.m in Sources */ = {isa = PBXBuildFile; fileRef = BF50E7CE22C28F8B0070E17B /* ALTCapabilities.m */; }; - BF5AB3B5228600D100DC914B /* AltSign.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3B3228600D100DC914B /* AltSign.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF5AB3B92286024D00DC914B /* ALTAccount.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3B72286024D00DC914B /* ALTAccount.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF5AB3BA2286024D00DC914B /* ALTAccount.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3B82286024D00DC914B /* ALTAccount.m */; }; - BF5AB3BF2286040400DC914B /* NSError+ALTErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3BD2286040400DC914B /* NSError+ALTErrors.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF5AB3C02286040400DC914B /* NSError+ALTErrors.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3BE2286040400DC914B /* NSError+ALTErrors.m */; }; - BF5AB3C52286157F00DC914B /* ALTTeam.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3C32286157F00DC914B /* ALTTeam.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF5AB3C62286157F00DC914B /* ALTTeam.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3C42286157F00DC914B /* ALTTeam.m */; }; - BF5AB3C92286269B00DC914B /* ALTDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3C72286269B00DC914B /* ALTDevice.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF5AB3CA2286269B00DC914B /* ALTDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3C82286269B00DC914B /* ALTDevice.m */; }; - BF5AB3CD228645DF00DC914B /* ALTCertificate.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3CB228645DF00DC914B /* ALTCertificate.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF5AB3CE228645DF00DC914B /* ALTCertificate.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3CC228645DF00DC914B /* ALTCertificate.m */; }; - BF5C690D24A5205E00C2F854 /* ccsrp.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5C690C24A5205E00C2F854 /* ccsrp.m */; }; - BF5C690E24A5205E00C2F854 /* ccsrp.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5C690C24A5205E00C2F854 /* ccsrp.m */; }; - BF5D43F6237F53BB00EC8745 /* ALTAppleAPISession.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5D43F4237F53BB00EC8745 /* ALTAppleAPISession.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF5D43F7237F53BB00EC8745 /* ALTAppleAPISession.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5D43F4237F53BB00EC8745 /* ALTAppleAPISession.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF5D43F8237F53BB00EC8745 /* ALTAppleAPISession.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5D43F5237F53BB00EC8745 /* ALTAppleAPISession.m */; }; - BF5D43F9237F53BB00EC8745 /* ALTAppleAPISession.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5D43F5237F53BB00EC8745 /* ALTAppleAPISession.m */; }; - BF9B633F229DC27C002F0A62 /* ALTModel+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B633E229DC27C002F0A62 /* ALTModel+Internal.h */; }; - BF9B6340229DC9DD002F0A62 /* openssl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF48CFE7229435DB0004760B /* openssl.framework */; }; - BF9B6375229DCD4D002F0A62 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BFBAC9302295F64600587369 /* libz.tbd */; }; - BF9B637E229DCF3A002F0A62 /* ALTAppleAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = BFBAC88F2295E05600587369 /* ALTAppleAPI.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B637F229DCF3A002F0A62 /* ALTProvisioningProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = BFBAC8892295D90F00587369 /* ALTProvisioningProfile.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6380229DCF3A002F0A62 /* ALTAccount.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3B72286024D00DC914B /* ALTAccount.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6381229DCF3A002F0A62 /* NSError+ALTErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3BD2286040400DC914B /* NSError+ALTErrors.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6382229DCF3A002F0A62 /* ALTCertificate.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3CB228645DF00DC914B /* ALTCertificate.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6383229DCF3A002F0A62 /* ALTCertificateRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = BF48CFEC229437580004760B /* ALTCertificateRequest.h */; }; - BF9B6384229DCF3A002F0A62 /* ALTDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3C72286269B00DC914B /* ALTDevice.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6385229DCF3A002F0A62 /* ALTModel+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B633E229DC27C002F0A62 /* ALTModel+Internal.h */; }; - BF9B6386229DCF3A002F0A62 /* AltSign.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3B3228600D100DC914B /* AltSign.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6387229DCF3A002F0A62 /* ALTTeam.h in Headers */ = {isa = PBXBuildFile; fileRef = BF5AB3C32286157F00DC914B /* ALTTeam.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6388229DCF3A002F0A62 /* ALTAppID.h in Headers */ = {isa = PBXBuildFile; fileRef = BF48CFF422944FC60004760B /* ALTAppID.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B638A229DCF3A002F0A62 /* ALTCertificateRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = BF48CFED229437580004760B /* ALTCertificateRequest.m */; }; - BF9B638B229DCF3A002F0A62 /* ALTProvisioningProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = BFBAC88A2295D90F00587369 /* ALTProvisioningProfile.m */; }; - BF9B638C229DCF3A002F0A62 /* ALTTeam.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3C42286157F00DC914B /* ALTTeam.m */; }; - BF9B638D229DCF3A002F0A62 /* ALTDevice.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3C82286269B00DC914B /* ALTDevice.m */; }; - BF9B638E229DCF3A002F0A62 /* ALTAppleAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = BFBAC8902295E05600587369 /* ALTAppleAPI.m */; }; - BF9B638F229DCF3A002F0A62 /* ALTAppID.m in Sources */ = {isa = PBXBuildFile; fileRef = BF48CFF522944FC60004760B /* ALTAppID.m */; }; - BF9B6390229DCF3A002F0A62 /* ALTCertificate.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3CC228645DF00DC914B /* ALTCertificate.m */; }; - BF9B6391229DCF3A002F0A62 /* ALTAccount.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3B82286024D00DC914B /* ALTAccount.m */; }; - BF9B6392229DCF3A002F0A62 /* NSError+ALTErrors.m in Sources */ = {isa = PBXBuildFile; fileRef = BF5AB3BE2286040400DC914B /* NSError+ALTErrors.m */; }; - BF9B6395229DCF3A002F0A62 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BFBAC9302295F64600587369 /* libz.tbd */; }; - BF9B6397229DCF3A002F0A62 /* libxml2.2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BFBAC8F22295EF0500587369 /* libxml2.2.tbd */; }; - BF9B6399229DCF3A002F0A62 /* libldid.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BFBAC8AA2295ED1900587369 /* libldid.a */; }; - BF9B63A5229DCFAD002F0A62 /* openssl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF48CFE9229435DB0004760B /* openssl.framework */; }; - BF9B6400229E0AA0002F0A62 /* crypt.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63F7229E0A9F002F0A62 /* crypt.h */; }; - BF9B6401229E0AA0002F0A62 /* crypt.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63F7229E0A9F002F0A62 /* crypt.h */; }; - BF9B6402229E0AA0002F0A62 /* ioapi.c in Sources */ = {isa = PBXBuildFile; fileRef = BF9B63F8229E0A9F002F0A62 /* ioapi.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - BF9B6403229E0AA0002F0A62 /* ioapi.c in Sources */ = {isa = PBXBuildFile; fileRef = BF9B63F8229E0A9F002F0A62 /* ioapi.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - BF9B6404229E0AA0002F0A62 /* zip.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63F9229E0A9F002F0A62 /* zip.h */; }; - BF9B6405229E0AA0002F0A62 /* zip.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63F9229E0A9F002F0A62 /* zip.h */; }; - BF9B6406229E0AA0002F0A62 /* ioapi.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63FA229E0AA0002F0A62 /* ioapi.h */; }; - BF9B6407229E0AA0002F0A62 /* ioapi.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63FA229E0AA0002F0A62 /* ioapi.h */; }; - BF9B6408229E0AA0002F0A62 /* mztools.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63FB229E0AA0002F0A62 /* mztools.h */; }; - BF9B6409229E0AA0002F0A62 /* mztools.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63FB229E0AA0002F0A62 /* mztools.h */; }; - BF9B640A229E0AA0002F0A62 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = BF9B63FC229E0AA0002F0A62 /* unzip.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - BF9B640B229E0AA0002F0A62 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = BF9B63FC229E0AA0002F0A62 /* unzip.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - BF9B640C229E0AA0002F0A62 /* zip.c in Sources */ = {isa = PBXBuildFile; fileRef = BF9B63FD229E0AA0002F0A62 /* zip.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - BF9B640D229E0AA0002F0A62 /* zip.c in Sources */ = {isa = PBXBuildFile; fileRef = BF9B63FD229E0AA0002F0A62 /* zip.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - BF9B640E229E0AA0002F0A62 /* mztools.c in Sources */ = {isa = PBXBuildFile; fileRef = BF9B63FE229E0AA0002F0A62 /* mztools.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - BF9B640F229E0AA0002F0A62 /* mztools.c in Sources */ = {isa = PBXBuildFile; fileRef = BF9B63FE229E0AA0002F0A62 /* mztools.c */; settings = {COMPILER_FLAGS = "-w"; }; }; - BF9B6410229E0AA0002F0A62 /* unzip.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63FF229E0AA0002F0A62 /* unzip.h */; }; - BF9B6411229E0AA0002F0A62 /* unzip.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B63FF229E0AA0002F0A62 /* unzip.h */; }; - BF9B6414229E0CCE002F0A62 /* NSFileManager+Apps.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B6412229E0CCE002F0A62 /* NSFileManager+Apps.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6415229E0CCE002F0A62 /* NSFileManager+Apps.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B6412229E0CCE002F0A62 /* NSFileManager+Apps.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B6416229E0CCE002F0A62 /* NSFileManager+Apps.m in Sources */ = {isa = PBXBuildFile; fileRef = BF9B6413229E0CCE002F0A62 /* NSFileManager+Apps.m */; }; - BF9B6417229E0CCE002F0A62 /* NSFileManager+Apps.m in Sources */ = {isa = PBXBuildFile; fileRef = BF9B6413229E0CCE002F0A62 /* NSFileManager+Apps.m */; }; - BF9B641D229E0DF5002F0A62 /* ALTSigner.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B6419229E0DF4002F0A62 /* ALTSigner.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B641E229E0DF5002F0A62 /* ALTSigner.h in Headers */ = {isa = PBXBuildFile; fileRef = BF9B6419229E0DF4002F0A62 /* ALTSigner.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BF9B641F229E0DF5002F0A62 /* ALTSigner.mm in Sources */ = {isa = PBXBuildFile; fileRef = BF9B641A229E0DF4002F0A62 /* ALTSigner.mm */; }; - BF9B6420229E0DF5002F0A62 /* ALTSigner.mm in Sources */ = {isa = PBXBuildFile; fileRef = BF9B641A229E0DF4002F0A62 /* ALTSigner.mm */; }; - BF9B6421229E0DF5002F0A62 /* apple.pem in Resources */ = {isa = PBXBuildFile; fileRef = BF9B641C229E0DF4002F0A62 /* apple.pem */; }; - BF9B6422229E0DF5002F0A62 /* apple.pem in Resources */ = {isa = PBXBuildFile; fileRef = BF9B641C229E0DF4002F0A62 /* apple.pem */; }; - BFBAC88B2295D90F00587369 /* ALTProvisioningProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = BFBAC8892295D90F00587369 /* ALTProvisioningProfile.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BFBAC88C2295D90F00587369 /* ALTProvisioningProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = BFBAC88A2295D90F00587369 /* ALTProvisioningProfile.m */; }; - BFBAC8912295E05600587369 /* ALTAppleAPI.h in Headers */ = {isa = PBXBuildFile; fileRef = BFBAC88F2295E05600587369 /* ALTAppleAPI.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BFBAC8922295E05600587369 /* ALTAppleAPI.m in Sources */ = {isa = PBXBuildFile; fileRef = BFBAC8902295E05600587369 /* ALTAppleAPI.m */; }; - BFBAC8E42295ED6C00587369 /* lookup2.c in Sources */ = {isa = PBXBuildFile; fileRef = BFBAC8E22295ED6C00587369 /* lookup2.c */; }; - BFBAC8F32295EF0500587369 /* libxml2.2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BFBAC8F22295EF0500587369 /* libxml2.2.tbd */; }; - BFBAC8F42295EFE300587369 /* libldid.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BFBAC8AA2295ED1900587369 /* libldid.a */; }; - BFBAC93A2295FCB500587369 /* libxml2.2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = BFBAC8F22295EF0500587369 /* libxml2.2.tbd */; }; - BFD80D4F23809EE100B9C227 /* ALTAppleAPI+Authentication.h in Headers */ = {isa = PBXBuildFile; fileRef = BFD80D4D23809EE100B9C227 /* ALTAppleAPI+Authentication.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BFD80D5023809EE100B9C227 /* ALTAppleAPI+Authentication.h in Headers */ = {isa = PBXBuildFile; fileRef = BFD80D4D23809EE100B9C227 /* ALTAppleAPI+Authentication.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BFD80D5123809EE100B9C227 /* ALTAppleAPI+Authentication.m in Sources */ = {isa = PBXBuildFile; fileRef = BFD80D4E23809EE100B9C227 /* ALTAppleAPI+Authentication.m */; }; - BFD80D5223809EE100B9C227 /* ALTAppleAPI+Authentication.m in Sources */ = {isa = PBXBuildFile; fileRef = BFD80D4E23809EE100B9C227 /* ALTAppleAPI+Authentication.m */; }; - BFD80D542380A00B00B9C227 /* ALTAppleAPI_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = BFD80D532380A00B00B9C227 /* ALTAppleAPI_Private.h */; }; - BFD80D552380A00B00B9C227 /* ALTAppleAPI_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = BFD80D532380A00B00B9C227 /* ALTAppleAPI_Private.h */; }; - BFE20E07237C932600409FF7 /* ALTAnisetteData.h in Headers */ = {isa = PBXBuildFile; fileRef = BFE20E05237C932600409FF7 /* ALTAnisetteData.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BFE20E08237C932600409FF7 /* ALTAnisetteData.h in Headers */ = {isa = PBXBuildFile; fileRef = BFE20E05237C932600409FF7 /* ALTAnisetteData.h */; settings = {ATTRIBUTES = (Public, ); }; }; - BFE20E09237C932600409FF7 /* ALTAnisetteData.m in Sources */ = {isa = PBXBuildFile; fileRef = BFE20E06237C932600409FF7 /* ALTAnisetteData.m */; }; - BFE20E0A237C932600409FF7 /* ALTAnisetteData.m in Sources */ = {isa = PBXBuildFile; fileRef = BFE20E06237C932600409FF7 /* ALTAnisetteData.m */; }; -/* End PBXBuildFile section */ - -/* Begin PBXContainerItemProxy section */ - BF4586B522987AE400BD7491 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = BF48CFE1229435DB0004760B /* OpenSSL.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 9F4A265B223BD82B005CB63A; - remoteInfo = "OpenSSL (iOS)"; - }; - BF48CFE6229435DB0004760B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = BF48CFE1229435DB0004760B /* OpenSSL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9F4A265C223BD82B005CB63A; - remoteInfo = "OpenSSL (iOS)"; - }; - BF48CFE8229435DB0004760B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = BF48CFE1229435DB0004760B /* OpenSSL.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9F4A2716223BE476005CB63A; - remoteInfo = "OpenSSL (macOS)"; - }; - BF9B63A0229DCFA4002F0A62 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = BF48CFE1229435DB0004760B /* OpenSSL.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 9F4A2715223BE476005CB63A; - remoteInfo = "OpenSSL (macOS)"; - }; -/* End PBXContainerItemProxy section */ - -/* Begin PBXCopyFilesBuildPhase section */ - BFBAC8A82295ED1900587369 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = "include/$(PRODUCT_NAME)"; - dstSubfolderSpec = 16; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - BF0C4E8422A1B3BE009A2DD7 /* Uid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Uid.cpp; path = Dependencies/ldid/libplist/src/Uid.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E8522A1B3BE009A2DD7 /* Node.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Node.cpp; path = Dependencies/ldid/libplist/src/Node.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E8622A1B3BE009A2DD7 /* base64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = base64.h; path = Dependencies/ldid/libplist/src/base64.h; sourceTree = SOURCE_ROOT; }; - BF0C4E8722A1B3BE009A2DD7 /* Real.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Real.cpp; path = Dependencies/ldid/libplist/src/Real.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E8822A1B3BE009A2DD7 /* Date.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Date.cpp; path = Dependencies/ldid/libplist/src/Date.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E8922A1B3BE009A2DD7 /* bytearray.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = bytearray.c; path = Dependencies/ldid/libplist/src/bytearray.c; sourceTree = SOURCE_ROOT; }; - BF0C4E8A22A1B3BE009A2DD7 /* time64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = time64.c; path = Dependencies/ldid/libplist/src/time64.c; sourceTree = SOURCE_ROOT; }; - BF0C4E8B22A1B3BE009A2DD7 /* plist.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = plist.h; path = Dependencies/ldid/libplist/src/plist.h; sourceTree = SOURCE_ROOT; }; - BF0C4E8C22A1B3BE009A2DD7 /* Structure.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Structure.cpp; path = Dependencies/ldid/libplist/src/Structure.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E8D22A1B3BE009A2DD7 /* plist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = plist.c; path = Dependencies/ldid/libplist/src/plist.c; sourceTree = SOURCE_ROOT; }; - BF0C4E8E22A1B3BE009A2DD7 /* time64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = time64.h; path = Dependencies/ldid/libplist/src/time64.h; sourceTree = SOURCE_ROOT; }; - BF0C4E8F22A1B3BE009A2DD7 /* base64.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = base64.c; path = Dependencies/ldid/libplist/src/base64.c; sourceTree = SOURCE_ROOT; }; - BF0C4E9022A1B3BE009A2DD7 /* strbuf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = strbuf.h; path = Dependencies/ldid/libplist/src/strbuf.h; sourceTree = SOURCE_ROOT; }; - BF0C4E9122A1B3BF009A2DD7 /* Array.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Array.cpp; path = Dependencies/ldid/libplist/src/Array.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E9222A1B3BF009A2DD7 /* xplist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = xplist.c; path = Dependencies/ldid/libplist/src/xplist.c; sourceTree = SOURCE_ROOT; }; - BF0C4E9322A1B3BF009A2DD7 /* ptrarray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ptrarray.h; path = Dependencies/ldid/libplist/src/ptrarray.h; sourceTree = SOURCE_ROOT; }; - BF0C4E9422A1B3BF009A2DD7 /* Boolean.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Boolean.cpp; path = Dependencies/ldid/libplist/src/Boolean.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E9522A1B3BF009A2DD7 /* bplist.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = bplist.c; path = Dependencies/ldid/libplist/src/bplist.c; sourceTree = SOURCE_ROOT; }; - BF0C4E9622A1B3BF009A2DD7 /* hashtable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = hashtable.h; path = Dependencies/ldid/libplist/src/hashtable.h; sourceTree = SOURCE_ROOT; }; - BF0C4E9722A1B3BF009A2DD7 /* bytearray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = bytearray.h; path = Dependencies/ldid/libplist/src/bytearray.h; sourceTree = SOURCE_ROOT; }; - BF0C4E9822A1B3BF009A2DD7 /* Key.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Key.cpp; path = Dependencies/ldid/libplist/src/Key.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E9922A1B3BF009A2DD7 /* time64_limits.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = time64_limits.h; path = Dependencies/ldid/libplist/src/time64_limits.h; sourceTree = SOURCE_ROOT; }; - BF0C4E9A22A1B3BF009A2DD7 /* Dictionary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Dictionary.cpp; path = Dependencies/ldid/libplist/src/Dictionary.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E9B22A1B3BF009A2DD7 /* Integer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Integer.cpp; path = Dependencies/ldid/libplist/src/Integer.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E9C22A1B3BF009A2DD7 /* ptrarray.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ptrarray.c; path = Dependencies/ldid/libplist/src/ptrarray.c; sourceTree = SOURCE_ROOT; }; - BF0C4E9D22A1B3BF009A2DD7 /* String.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = String.cpp; path = Dependencies/ldid/libplist/src/String.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4E9E22A1B3BF009A2DD7 /* hashtable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = hashtable.c; path = Dependencies/ldid/libplist/src/hashtable.c; sourceTree = SOURCE_ROOT; }; - BF0C4E9F22A1B3BF009A2DD7 /* Data.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Data.cpp; path = Dependencies/ldid/libplist/src/Data.cpp; sourceTree = SOURCE_ROOT; }; - BF0C4EB422A1B3CC009A2DD7 /* node.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = node.c; path = Dependencies/ldid/libplist/libcnary/node.c; sourceTree = SOURCE_ROOT; }; - BF0C4EB522A1B3CC009A2DD7 /* cnary.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cnary.c; path = Dependencies/ldid/libplist/libcnary/cnary.c; sourceTree = SOURCE_ROOT; }; - BF0C4EB622A1B3CC009A2DD7 /* node_list.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = node_list.c; path = Dependencies/ldid/libplist/libcnary/node_list.c; sourceTree = SOURCE_ROOT; }; - BF17BB7222EA839400D7D842 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - BF48CFE1229435DB0004760B /* OpenSSL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = OpenSSL.xcodeproj; path = Dependencies/OpenSSL/OpenSSL.xcodeproj; sourceTree = SOURCE_ROOT; }; - BF48CFEC229437580004760B /* ALTCertificateRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTCertificateRequest.h; sourceTree = ""; }; - BF48CFED229437580004760B /* ALTCertificateRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTCertificateRequest.m; sourceTree = ""; }; - BF48CFF422944FC60004760B /* ALTAppID.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTAppID.h; sourceTree = ""; }; - BF48CFF522944FC60004760B /* ALTAppID.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTAppID.m; sourceTree = ""; }; - BF50E7B622C161630070E17B /* ALTAppGroup.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTAppGroup.h; sourceTree = ""; }; - BF50E7B722C161630070E17B /* ALTAppGroup.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTAppGroup.m; sourceTree = ""; }; - BF50E7BD22C163DC0070E17B /* ALTApplication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTApplication.h; sourceTree = ""; }; - BF50E7BE22C163DC0070E17B /* ALTApplication.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ALTApplication.mm; sourceTree = ""; }; - BF50E7C322C1690B0070E17B /* alt_ldid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = alt_ldid.cpp; sourceTree = ""; }; - BF50E7C822C169560070E17B /* alt_ldid.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = alt_ldid.hpp; sourceTree = ""; }; - BF50E7CD22C28F8B0070E17B /* ALTCapabilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTCapabilities.h; sourceTree = ""; }; - BF50E7CE22C28F8B0070E17B /* ALTCapabilities.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTCapabilities.m; sourceTree = ""; }; - BF5AB3992285FDB200DC914B /* AltSign.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AltSign.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - BF5AB39D2285FDB200DC914B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - BF5AB3B3228600D100DC914B /* AltSign.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AltSign.h; sourceTree = ""; }; - BF5AB3B72286024D00DC914B /* ALTAccount.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTAccount.h; sourceTree = ""; }; - BF5AB3B82286024D00DC914B /* ALTAccount.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTAccount.m; sourceTree = ""; }; - BF5AB3BD2286040400DC914B /* NSError+ALTErrors.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSError+ALTErrors.h"; sourceTree = ""; }; - BF5AB3BE2286040400DC914B /* NSError+ALTErrors.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSError+ALTErrors.m"; sourceTree = ""; }; - BF5AB3C32286157F00DC914B /* ALTTeam.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTTeam.h; sourceTree = ""; }; - BF5AB3C42286157F00DC914B /* ALTTeam.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTTeam.m; sourceTree = ""; }; - BF5AB3C72286269B00DC914B /* ALTDevice.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTDevice.h; sourceTree = ""; }; - BF5AB3C82286269B00DC914B /* ALTDevice.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTDevice.m; sourceTree = ""; }; - BF5AB3CB228645DF00DC914B /* ALTCertificate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTCertificate.h; sourceTree = ""; }; - BF5AB3CC228645DF00DC914B /* ALTCertificate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTCertificate.m; sourceTree = ""; }; - BF5C690C24A5205E00C2F854 /* ccsrp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ccsrp.m; path = Dependencies/corecrypto/ccsrp.m; sourceTree = SOURCE_ROOT; }; - BF5D43F4237F53BB00EC8745 /* ALTAppleAPISession.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTAppleAPISession.h; sourceTree = ""; }; - BF5D43F5237F53BB00EC8745 /* ALTAppleAPISession.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTAppleAPISession.m; sourceTree = ""; }; - BF9B633E229DC27C002F0A62 /* ALTModel+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ALTModel+Internal.h"; sourceTree = ""; }; - BF9B6373229DCD2A002F0A62 /* libzip_iOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = libzip_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - BF9B6376229DCDAC002F0A62 /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; - BF9B639E229DCF3A002F0A62 /* AltSign.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AltSign.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - BF9B63F7229E0A9F002F0A62 /* crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = crypt.h; path = Dependencies/minizip/crypt.h; sourceTree = SOURCE_ROOT; }; - BF9B63F8229E0A9F002F0A62 /* ioapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ioapi.c; path = Dependencies/minizip/ioapi.c; sourceTree = SOURCE_ROOT; }; - BF9B63F9229E0A9F002F0A62 /* zip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = zip.h; path = Dependencies/minizip/zip.h; sourceTree = SOURCE_ROOT; }; - BF9B63FA229E0AA0002F0A62 /* ioapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ioapi.h; path = Dependencies/minizip/ioapi.h; sourceTree = SOURCE_ROOT; }; - BF9B63FB229E0AA0002F0A62 /* mztools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = mztools.h; path = Dependencies/minizip/mztools.h; sourceTree = SOURCE_ROOT; }; - BF9B63FC229E0AA0002F0A62 /* unzip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = unzip.c; path = Dependencies/minizip/unzip.c; sourceTree = SOURCE_ROOT; }; - BF9B63FD229E0AA0002F0A62 /* zip.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = zip.c; path = Dependencies/minizip/zip.c; sourceTree = SOURCE_ROOT; }; - BF9B63FE229E0AA0002F0A62 /* mztools.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mztools.c; path = Dependencies/minizip/mztools.c; sourceTree = SOURCE_ROOT; }; - BF9B63FF229E0AA0002F0A62 /* unzip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = unzip.h; path = Dependencies/minizip/unzip.h; sourceTree = SOURCE_ROOT; }; - BF9B6412229E0CCE002F0A62 /* NSFileManager+Apps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+Apps.h"; sourceTree = ""; }; - BF9B6413229E0CCE002F0A62 /* NSFileManager+Apps.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+Apps.m"; sourceTree = ""; }; - BF9B6419229E0DF4002F0A62 /* ALTSigner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ALTSigner.h; sourceTree = ""; }; - BF9B641A229E0DF4002F0A62 /* ALTSigner.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ALTSigner.mm; sourceTree = ""; }; - BF9B641C229E0DF4002F0A62 /* apple.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = apple.pem; sourceTree = ""; }; - BFBAC8892295D90F00587369 /* ALTProvisioningProfile.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTProvisioningProfile.h; sourceTree = ""; }; - BFBAC88A2295D90F00587369 /* ALTProvisioningProfile.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTProvisioningProfile.m; sourceTree = ""; }; - BFBAC88F2295E05600587369 /* ALTAppleAPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTAppleAPI.h; sourceTree = ""; }; - BFBAC8902295E05600587369 /* ALTAppleAPI.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTAppleAPI.m; sourceTree = ""; }; - BFBAC8AA2295ED1900587369 /* libldid.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libldid.a; sourceTree = BUILT_PRODUCTS_DIR; }; - BFBAC8DF2295ED6C00587369 /* ldid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ldid.cpp; path = Dependencies/ldid/ldid.cpp; sourceTree = SOURCE_ROOT; }; - BFBAC8E02295ED6C00587369 /* sha1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = sha1.h; path = Dependencies/ldid/sha1.h; sourceTree = SOURCE_ROOT; }; - BFBAC8E12295ED6C00587369 /* ldid.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ldid.hpp; path = Dependencies/ldid/ldid.hpp; sourceTree = SOURCE_ROOT; }; - BFBAC8E22295ED6C00587369 /* lookup2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = lookup2.c; path = Dependencies/ldid/lookup2.c; sourceTree = SOURCE_ROOT; }; - BFBAC8F22295EF0500587369 /* libxml2.2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxml2.2.tbd; path = usr/lib/libxml2.2.tbd; sourceTree = SDKROOT; }; - BFBAC9302295F64600587369 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; - BFD80D4D23809EE100B9C227 /* ALTAppleAPI+Authentication.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ALTAppleAPI+Authentication.h"; sourceTree = ""; }; - BFD80D4E23809EE100B9C227 /* ALTAppleAPI+Authentication.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "ALTAppleAPI+Authentication.m"; sourceTree = ""; }; - BFD80D532380A00B00B9C227 /* ALTAppleAPI_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTAppleAPI_Private.h; sourceTree = ""; }; - BFE20E05237C932600409FF7 /* ALTAnisetteData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALTAnisetteData.h; sourceTree = ""; }; - BFE20E06237C932600409FF7 /* ALTAnisetteData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ALTAnisetteData.m; sourceTree = ""; }; - BFE20E0E237CAA3A00409FF7 /* ccder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccder.h; path = Dependencies/corecrypto/ccder.h; sourceTree = SOURCE_ROOT; }; - BFE20E0F237CAA3A00409FF7 /* ccec25519.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccec25519.h; path = Dependencies/corecrypto/ccec25519.h; sourceTree = SOURCE_ROOT; }; - BFE20E10237CAA3A00409FF7 /* ccmode_siv_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccmode_siv_priv.h; path = Dependencies/corecrypto/ccmode_siv_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E11237CAA3A00409FF7 /* cchkdf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cchkdf.h; path = Dependencies/corecrypto/cchkdf.h; sourceTree = SOURCE_ROOT; }; - BFE20E12237CAA3A00409FF7 /* ccec_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccec_priv.h; path = Dependencies/corecrypto/ccec_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E13237CAA3A00409FF7 /* ccansikdf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccansikdf.h; path = Dependencies/corecrypto/ccansikdf.h; sourceTree = SOURCE_ROOT; }; - BFE20E14237CAA3A00409FF7 /* ccpbkdf2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccpbkdf2.h; path = Dependencies/corecrypto/ccpbkdf2.h; sourceTree = SOURCE_ROOT; }; - BFE20E15237CAA3A00409FF7 /* ccrc4.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrc4.h; path = Dependencies/corecrypto/ccrc4.h; sourceTree = SOURCE_ROOT; }; - BFE20E16237CAA3B00409FF7 /* ccder_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccder_priv.h; path = Dependencies/corecrypto/ccder_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E17237CAA3B00409FF7 /* ccrng_ecfips_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng_ecfips_test.h; path = Dependencies/corecrypto/ccrng_ecfips_test.h; sourceTree = SOURCE_ROOT; }; - BFE20E18237CAA3B00409FF7 /* ccrng_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng_test.h; path = Dependencies/corecrypto/ccrng_test.h; sourceTree = SOURCE_ROOT; }; - BFE20E19237CAA3B00409FF7 /* ccrsa_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrsa_priv.h; path = Dependencies/corecrypto/ccrsa_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E1A237CAA3B00409FF7 /* ccrng_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng_priv.h; path = Dependencies/corecrypto/ccrng_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E1B237CAA3B00409FF7 /* ccdrbg.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdrbg.h; path = Dependencies/corecrypto/ccdrbg.h; sourceTree = SOURCE_ROOT; }; - BFE20E1C237CAA3B00409FF7 /* ccz.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccz.h; path = Dependencies/corecrypto/ccz.h; sourceTree = SOURCE_ROOT; }; - BFE20E1D237CAA3B00409FF7 /* ccmd5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccmd5.h; path = Dependencies/corecrypto/ccmd5.h; sourceTree = SOURCE_ROOT; }; - BFE20E1E237CAA3B00409FF7 /* ccec25519_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccec25519_priv.h; path = Dependencies/corecrypto/ccec25519_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E1F237CAA3B00409FF7 /* ccsha1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccsha1.h; path = Dependencies/corecrypto/ccsha1.h; sourceTree = SOURCE_ROOT; }; - BFE20E20237CAA3B00409FF7 /* ccsha2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccsha2.h; path = Dependencies/corecrypto/ccsha2.h; sourceTree = SOURCE_ROOT; }; - BFE20E21237CAA3B00409FF7 /* ccasn1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccasn1.h; path = Dependencies/corecrypto/ccasn1.h; sourceTree = SOURCE_ROOT; }; - BFE20E22237CAA3B00409FF7 /* ccrng_system.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng_system.h; path = Dependencies/corecrypto/ccrng_system.h; sourceTree = SOURCE_ROOT; }; - BFE20E23237CAA3B00409FF7 /* ccdes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdes.h; path = Dependencies/corecrypto/ccdes.h; sourceTree = SOURCE_ROOT; }; - BFE20E24237CAA3B00409FF7 /* ccripemd.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccripemd.h; path = Dependencies/corecrypto/ccripemd.h; sourceTree = SOURCE_ROOT; }; - BFE20E25237CAA3B00409FF7 /* ccder_decode_eckey.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccder_decode_eckey.h; path = Dependencies/corecrypto/ccder_decode_eckey.h; sourceTree = SOURCE_ROOT; }; - BFE20E26237CAA3B00409FF7 /* ccn_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccn_priv.h; path = Dependencies/corecrypto/ccn_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E27237CAA3B00409FF7 /* ccz_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccz_priv.h; path = Dependencies/corecrypto/ccz_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E28237CAA3B00409FF7 /* cc_config.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cc_config.h; path = Dependencies/corecrypto/cc_config.h; sourceTree = SOURCE_ROOT; }; - BFE20E29237CAA3B00409FF7 /* cctest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cctest.h; path = Dependencies/corecrypto/cctest.h; sourceTree = SOURCE_ROOT; }; - BFE20E2A237CAA3B00409FF7 /* ccpad.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccpad.h; path = Dependencies/corecrypto/ccpad.h; sourceTree = SOURCE_ROOT; }; - BFE20E2B237CAA3C00409FF7 /* ccdh_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdh_priv.h; path = Dependencies/corecrypto/ccdh_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E2C237CAA3C00409FF7 /* ccrsa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrsa.h; path = Dependencies/corecrypto/ccrsa.h; sourceTree = SOURCE_ROOT; }; - BFE20E2D237CAA3C00409FF7 /* ccrng_pbkdf2_prng.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng_pbkdf2_prng.h; path = Dependencies/corecrypto/ccrng_pbkdf2_prng.h; sourceTree = SOURCE_ROOT; }; - BFE20E2E237CAA3C00409FF7 /* ccdrbg_impl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdrbg_impl.h; path = Dependencies/corecrypto/ccdrbg_impl.h; sourceTree = SOURCE_ROOT; }; - BFE20E2F237CAA3C00409FF7 /* cccast.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cccast.h; path = Dependencies/corecrypto/cccast.h; sourceTree = SOURCE_ROOT; }; - BFE20E30237CAA3C00409FF7 /* ccchacha20poly1305.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccchacha20poly1305.h; path = Dependencies/corecrypto/ccchacha20poly1305.h; sourceTree = SOURCE_ROOT; }; - BFE20E31237CAA3C00409FF7 /* cc_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cc_priv.h; path = Dependencies/corecrypto/cc_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E32237CAA3C00409FF7 /* ccder_rsa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccder_rsa.h; path = Dependencies/corecrypto/ccder_rsa.h; sourceTree = SOURCE_ROOT; }; - BFE20E33237CAA3C00409FF7 /* cchmac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cchmac.h; path = Dependencies/corecrypto/cchmac.h; sourceTree = SOURCE_ROOT; }; - BFE20E34237CAA3C00409FF7 /* ccrng_drbg.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng_drbg.h; path = Dependencies/corecrypto/ccrng_drbg.h; sourceTree = SOURCE_ROOT; }; - BFE20E35237CAA3C00409FF7 /* ccrng_sequence.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng_sequence.h; path = Dependencies/corecrypto/ccrng_sequence.h; sourceTree = SOURCE_ROOT; }; - BFE20E36237CAA3C00409FF7 /* ccdigest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdigest.h; path = Dependencies/corecrypto/ccdigest.h; sourceTree = SOURCE_ROOT; }; - BFE20E37237CAA3C00409FF7 /* ccdh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdh.h; path = Dependencies/corecrypto/ccdh.h; sourceTree = SOURCE_ROOT; }; - BFE20E38237CAA3C00409FF7 /* ccmd4.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccmd4.h; path = Dependencies/corecrypto/ccmd4.h; sourceTree = SOURCE_ROOT; }; - BFE20E39237CAA3C00409FF7 /* ccec.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccec.h; path = Dependencies/corecrypto/ccec.h; sourceTree = SOURCE_ROOT; }; - BFE20E3A237CAA3C00409FF7 /* ccperf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccperf.h; path = Dependencies/corecrypto/ccperf.h; sourceTree = SOURCE_ROOT; }; - BFE20E3B237CAA3C00409FF7 /* fipspost.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = fipspost.h; path = Dependencies/corecrypto/fipspost.h; sourceTree = SOURCE_ROOT; }; - BFE20E3C237CAA3C00409FF7 /* ccnistkdf.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccnistkdf.h; path = Dependencies/corecrypto/ccnistkdf.h; sourceTree = SOURCE_ROOT; }; - BFE20E3D237CAA3D00409FF7 /* ccdrbg_factory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdrbg_factory.h; path = Dependencies/corecrypto/ccdrbg_factory.h; sourceTree = SOURCE_ROOT; }; - BFE20E3E237CAA3D00409FF7 /* ccrng_rsafips_test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng_rsafips_test.h; path = Dependencies/corecrypto/ccrng_rsafips_test.h; sourceTree = SOURCE_ROOT; }; - BFE20E3F237CAA3D00409FF7 /* ccmode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccmode.h; path = Dependencies/corecrypto/ccmode.h; sourceTree = SOURCE_ROOT; }; - BFE20E40237CAA3D00409FF7 /* ccmode_siv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccmode_siv.h; path = Dependencies/corecrypto/ccmode_siv.h; sourceTree = SOURCE_ROOT; }; - BFE20E41237CAA3D00409FF7 /* cc.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cc.h; path = Dependencies/corecrypto/cc.h; sourceTree = SOURCE_ROOT; }; - BFE20E42237CAA3D00409FF7 /* ccsrp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccsrp.h; path = Dependencies/corecrypto/ccsrp.h; sourceTree = SOURCE_ROOT; }; - BFE20E43237CAA3D00409FF7 /* ccaes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccaes.h; path = Dependencies/corecrypto/ccaes.h; sourceTree = SOURCE_ROOT; }; - BFE20E44237CAA3D00409FF7 /* cc_memory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cc_memory.h; path = Dependencies/corecrypto/cc_memory.h; sourceTree = SOURCE_ROOT; }; - BFE20E45237CAA3D00409FF7 /* cc_debug.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cc_debug.h; path = Dependencies/corecrypto/cc_debug.h; sourceTree = SOURCE_ROOT; }; - BFE20E46237CAA3D00409FF7 /* ccdh_gp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdh_gp.h; path = Dependencies/corecrypto/ccdh_gp.h; sourceTree = SOURCE_ROOT; }; - BFE20E47237CAA3D00409FF7 /* cccmac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cccmac.h; path = Dependencies/corecrypto/cccmac.h; sourceTree = SOURCE_ROOT; }; - BFE20E48237CAA3D00409FF7 /* ccmode_factory.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccmode_factory.h; path = Dependencies/corecrypto/ccmode_factory.h; sourceTree = SOURCE_ROOT; }; - BFE20E49237CAA3E00409FF7 /* ccn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccn.h; path = Dependencies/corecrypto/ccn.h; sourceTree = SOURCE_ROOT; }; - BFE20E4A237CAA3E00409FF7 /* ccchacha20poly1305_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccchacha20poly1305_priv.h; path = Dependencies/corecrypto/ccchacha20poly1305_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E4B237CAA3E00409FF7 /* ccecies_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccecies_priv.h; path = Dependencies/corecrypto/ccecies_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E4C237CAA3E00409FF7 /* ccblowfish.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccblowfish.h; path = Dependencies/corecrypto/ccblowfish.h; sourceTree = SOURCE_ROOT; }; - BFE20E4D237CAA3E00409FF7 /* ccdigest_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccdigest_priv.h; path = Dependencies/corecrypto/ccdigest_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E4E237CAA3E00409FF7 /* ccprime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccprime.h; path = Dependencies/corecrypto/ccprime.h; sourceTree = SOURCE_ROOT; }; - BFE20E4F237CAA3E00409FF7 /* ccwrap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccwrap.h; path = Dependencies/corecrypto/ccwrap.h; sourceTree = SOURCE_ROOT; }; - BFE20E50237CAA3E00409FF7 /* ccrc2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrc2.h; path = Dependencies/corecrypto/ccrc2.h; sourceTree = SOURCE_ROOT; }; - BFE20E51237CAA3E00409FF7 /* ccecies.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccecies.h; path = Dependencies/corecrypto/ccecies.h; sourceTree = SOURCE_ROOT; }; - BFE20E52237CAA3E00409FF7 /* ccrng.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccrng.h; path = Dependencies/corecrypto/ccrng.h; sourceTree = SOURCE_ROOT; }; - BFE20E53237CAA3E00409FF7 /* cc_runtime_config.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cc_runtime_config.h; path = Dependencies/corecrypto/cc_runtime_config.h; sourceTree = SOURCE_ROOT; }; - BFE20E54237CAA3E00409FF7 /* ccder_encode_eckey.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccder_encode_eckey.h; path = Dependencies/corecrypto/ccder_encode_eckey.h; sourceTree = SOURCE_ROOT; }; - BFE20E55237CAA3E00409FF7 /* cczp_priv.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cczp_priv.h; path = Dependencies/corecrypto/cczp_priv.h; sourceTree = SOURCE_ROOT; }; - BFE20E56237CAA3E00409FF7 /* ccmode_impl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccmode_impl.h; path = Dependencies/corecrypto/ccmode_impl.h; sourceTree = SOURCE_ROOT; }; - BFE20E57237CAA3E00409FF7 /* cczp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = cczp.h; path = Dependencies/corecrypto/cczp.h; sourceTree = SOURCE_ROOT; }; - BFE20E58237CAA3E00409FF7 /* ccsrp_gp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccsrp_gp.h; path = Dependencies/corecrypto/ccsrp_gp.h; sourceTree = SOURCE_ROOT; }; - BFE20E59237CAA3E00409FF7 /* ccmd2.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ccmd2.h; path = Dependencies/corecrypto/ccmd2.h; sourceTree = SOURCE_ROOT; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - BF5AB3962285FDB200DC914B /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - BF17BB7322EA839500D7D842 /* UIKit.framework in Frameworks */, - BF9B6375229DCD4D002F0A62 /* libz.tbd in Frameworks */, - BF9B6340229DC9DD002F0A62 /* openssl.framework in Frameworks */, - BFBAC93A2295FCB500587369 /* libxml2.2.tbd in Frameworks */, - BFBAC8F42295EFE300587369 /* libldid.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - BF9B6393229DCF3A002F0A62 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - BF9B63A5229DCFAD002F0A62 /* openssl.framework in Frameworks */, - BF9B6395229DCF3A002F0A62 /* libz.tbd in Frameworks */, - BF9B6397229DCF3A002F0A62 /* libxml2.2.tbd in Frameworks */, - BF9B6399229DCF3A002F0A62 /* libldid.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - BFBAC8A72295ED1900587369 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - BFBAC8F32295EF0500587369 /* libxml2.2.tbd in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - BF48CFE0229435CB0004760B /* Dependencies */ = { - isa = PBXGroup; - children = ( - BFE20E0D237CAA2500409FF7 /* corecrypto */, - BF48CFE1229435DB0004760B /* OpenSSL.xcodeproj */, - BF9B63D3229DD8E8002F0A62 /* minizip */, - ); - name = Dependencies; - sourceTree = ""; - }; - BF48CFE2229435DB0004760B /* Products */ = { - isa = PBXGroup; - children = ( - BF48CFE7229435DB0004760B /* openssl.framework */, - BF48CFE9229435DB0004760B /* openssl.framework */, - ); - name = Products; - sourceTree = ""; - }; - BF48CFEA229435F50004760B /* Frameworks */ = { - isa = PBXGroup; - children = ( - BF17BB7222EA839400D7D842 /* UIKit.framework */, - BF9B6376229DCDAC002F0A62 /* libbz2.tbd */, - BF9B6373229DCD2A002F0A62 /* libzip_iOS.framework */, - BFBAC9302295F64600587369 /* libz.tbd */, - BFBAC8F22295EF0500587369 /* libxml2.2.tbd */, - ); - name = Frameworks; - sourceTree = ""; - }; - BF50E7C722C1694A0070E17B /* ldid */ = { - isa = PBXGroup; - children = ( - BF50E7C822C169560070E17B /* alt_ldid.hpp */, - BF50E7C322C1690B0070E17B /* alt_ldid.cpp */, - ); - path = ldid; - sourceTree = ""; - }; - BF50E7D322C293F80070E17B /* Capabilities */ = { - isa = PBXGroup; - children = ( - BF50E7CD22C28F8B0070E17B /* ALTCapabilities.h */, - BF50E7CE22C28F8B0070E17B /* ALTCapabilities.m */, - ); - path = Capabilities; - sourceTree = ""; - }; - BF50E7D422C29BBF0070E17B /* Apple API */ = { - isa = PBXGroup; - children = ( - BF9B633E229DC27C002F0A62 /* ALTModel+Internal.h */, - BF5AB3B72286024D00DC914B /* ALTAccount.h */, - BF5AB3B82286024D00DC914B /* ALTAccount.m */, - BFE20E05237C932600409FF7 /* ALTAnisetteData.h */, - BFE20E06237C932600409FF7 /* ALTAnisetteData.m */, - BF5AB3C32286157F00DC914B /* ALTTeam.h */, - BF5AB3C42286157F00DC914B /* ALTTeam.m */, - BF5AB3C72286269B00DC914B /* ALTDevice.h */, - BF5AB3C82286269B00DC914B /* ALTDevice.m */, - BF5AB3CB228645DF00DC914B /* ALTCertificate.h */, - BF5AB3CC228645DF00DC914B /* ALTCertificate.m */, - BF48CFEC229437580004760B /* ALTCertificateRequest.h */, - BF48CFED229437580004760B /* ALTCertificateRequest.m */, - BF48CFF422944FC60004760B /* ALTAppID.h */, - BF48CFF522944FC60004760B /* ALTAppID.m */, - BF50E7B622C161630070E17B /* ALTAppGroup.h */, - BF50E7B722C161630070E17B /* ALTAppGroup.m */, - BFBAC8892295D90F00587369 /* ALTProvisioningProfile.h */, - BFBAC88A2295D90F00587369 /* ALTProvisioningProfile.m */, - ); - path = "Apple API"; - sourceTree = ""; - }; - BF5AB38F2285FDB200DC914B = { - isa = PBXGroup; - children = ( - BF5AB39B2285FDB200DC914B /* AltSign */, - BFBAC8AB2295ED1900587369 /* ldid */, - BF5AB39A2285FDB200DC914B /* Products */, - BF48CFEA229435F50004760B /* Frameworks */, - ); - sourceTree = ""; - }; - BF5AB39A2285FDB200DC914B /* Products */ = { - isa = PBXGroup; - children = ( - BF5AB3992285FDB200DC914B /* AltSign.framework */, - BFBAC8AA2295ED1900587369 /* libldid.a */, - BF9B639E229DCF3A002F0A62 /* AltSign.framework */, - ); - name = Products; - sourceTree = ""; - }; - BF5AB39B2285FDB200DC914B /* AltSign */ = { - isa = PBXGroup; - children = ( - BF5AB3B3228600D100DC914B /* AltSign.h */, - BFBAC8992295E1A200587369 /* Apple API */, - BF5AB3C2228604E700DC914B /* Model */, - BF9B6418229E0DF4002F0A62 /* Signing */, - BF50E7D322C293F80070E17B /* Capabilities */, - BF50E7C722C1694A0070E17B /* ldid */, - BF5AB3C12286040800DC914B /* Categories */, - BF9B641B229E0DF4002F0A62 /* Resources */, - BF48CFE0229435CB0004760B /* Dependencies */, - BF5AB39D2285FDB200DC914B /* Info.plist */, - ); - path = AltSign; - sourceTree = ""; - }; - BF5AB3C12286040800DC914B /* Categories */ = { - isa = PBXGroup; - children = ( - BF5AB3BD2286040400DC914B /* NSError+ALTErrors.h */, - BF5AB3BE2286040400DC914B /* NSError+ALTErrors.m */, - BF9B6412229E0CCE002F0A62 /* NSFileManager+Apps.h */, - BF9B6413229E0CCE002F0A62 /* NSFileManager+Apps.m */, - ); - path = Categories; - sourceTree = ""; - }; - BF5AB3C2228604E700DC914B /* Model */ = { - isa = PBXGroup; - children = ( - BF50E7BD22C163DC0070E17B /* ALTApplication.h */, - BF50E7BE22C163DC0070E17B /* ALTApplication.mm */, - BF50E7D422C29BBF0070E17B /* Apple API */, - ); - path = Model; - sourceTree = ""; - }; - BF9B63D3229DD8E8002F0A62 /* minizip */ = { - isa = PBXGroup; - children = ( - BF9B63F7229E0A9F002F0A62 /* crypt.h */, - BF9B63F8229E0A9F002F0A62 /* ioapi.c */, - BF9B63FA229E0AA0002F0A62 /* ioapi.h */, - BF9B63FE229E0AA0002F0A62 /* mztools.c */, - BF9B63FB229E0AA0002F0A62 /* mztools.h */, - BF9B63FC229E0AA0002F0A62 /* unzip.c */, - BF9B63FF229E0AA0002F0A62 /* unzip.h */, - BF9B63FD229E0AA0002F0A62 /* zip.c */, - BF9B63F9229E0A9F002F0A62 /* zip.h */, - ); - name = minizip; - sourceTree = ""; - }; - BF9B6418229E0DF4002F0A62 /* Signing */ = { - isa = PBXGroup; - children = ( - BF9B6419229E0DF4002F0A62 /* ALTSigner.h */, - BF9B641A229E0DF4002F0A62 /* ALTSigner.mm */, - ); - path = Signing; - sourceTree = ""; - }; - BF9B641B229E0DF4002F0A62 /* Resources */ = { - isa = PBXGroup; - children = ( - BF9B641C229E0DF4002F0A62 /* apple.pem */, - ); - path = Resources; - sourceTree = ""; - }; - BFBAC8992295E1A200587369 /* Apple API */ = { - isa = PBXGroup; - children = ( - BFBAC88F2295E05600587369 /* ALTAppleAPI.h */, - BFD80D532380A00B00B9C227 /* ALTAppleAPI_Private.h */, - BFBAC8902295E05600587369 /* ALTAppleAPI.m */, - BFD80D4D23809EE100B9C227 /* ALTAppleAPI+Authentication.h */, - BFD80D4E23809EE100B9C227 /* ALTAppleAPI+Authentication.m */, - BF5D43F4237F53BB00EC8745 /* ALTAppleAPISession.h */, - BF5D43F5237F53BB00EC8745 /* ALTAppleAPISession.m */, - ); - path = "Apple API"; - sourceTree = ""; - }; - BFBAC8AB2295ED1900587369 /* ldid */ = { - isa = PBXGroup; - children = ( - BFBAC8E12295ED6C00587369 /* ldid.hpp */, - BFBAC8DF2295ED6C00587369 /* ldid.cpp */, - BFBAC8E22295ED6C00587369 /* lookup2.c */, - BFBAC8E02295ED6C00587369 /* sha1.h */, - BFBAC8B32295ED3600587369 /* libplist */, - BFBAC8E52295EE2500587369 /* libcnary */, - ); - path = ldid; - sourceTree = ""; - }; - BFBAC8B32295ED3600587369 /* libplist */ = { - isa = PBXGroup; - children = ( - BF0C4E9122A1B3BF009A2DD7 /* Array.cpp */, - BF0C4E8F22A1B3BE009A2DD7 /* base64.c */, - BF0C4E8622A1B3BE009A2DD7 /* base64.h */, - BF0C4E9422A1B3BF009A2DD7 /* Boolean.cpp */, - BF0C4E9522A1B3BF009A2DD7 /* bplist.c */, - BF0C4E8922A1B3BE009A2DD7 /* bytearray.c */, - BF0C4E9722A1B3BF009A2DD7 /* bytearray.h */, - BF0C4E9F22A1B3BF009A2DD7 /* Data.cpp */, - BF0C4E8822A1B3BE009A2DD7 /* Date.cpp */, - BF0C4E9A22A1B3BF009A2DD7 /* Dictionary.cpp */, - BF0C4E9E22A1B3BF009A2DD7 /* hashtable.c */, - BF0C4E9622A1B3BF009A2DD7 /* hashtable.h */, - BF0C4E9B22A1B3BF009A2DD7 /* Integer.cpp */, - BF0C4E9822A1B3BF009A2DD7 /* Key.cpp */, - BF0C4E8522A1B3BE009A2DD7 /* Node.cpp */, - BF0C4E8D22A1B3BE009A2DD7 /* plist.c */, - BF0C4E8B22A1B3BE009A2DD7 /* plist.h */, - BF0C4E9C22A1B3BF009A2DD7 /* ptrarray.c */, - BF0C4E9322A1B3BF009A2DD7 /* ptrarray.h */, - BF0C4E8722A1B3BE009A2DD7 /* Real.cpp */, - BF0C4E9022A1B3BE009A2DD7 /* strbuf.h */, - BF0C4E9D22A1B3BF009A2DD7 /* String.cpp */, - BF0C4E8C22A1B3BE009A2DD7 /* Structure.cpp */, - BF0C4E9922A1B3BF009A2DD7 /* time64_limits.h */, - BF0C4E8A22A1B3BE009A2DD7 /* time64.c */, - BF0C4E8E22A1B3BE009A2DD7 /* time64.h */, - BF0C4E8422A1B3BE009A2DD7 /* Uid.cpp */, - BF0C4E9222A1B3BF009A2DD7 /* xplist.c */, - ); - name = libplist; - sourceTree = ""; - }; - BFBAC8E52295EE2500587369 /* libcnary */ = { - isa = PBXGroup; - children = ( - BF0C4EB522A1B3CC009A2DD7 /* cnary.c */, - BF0C4EB622A1B3CC009A2DD7 /* node_list.c */, - BF0C4EB422A1B3CC009A2DD7 /* node.c */, - ); - name = libcnary; - sourceTree = ""; - }; - BFE20E0D237CAA2500409FF7 /* corecrypto */ = { - isa = PBXGroup; - children = ( - BFE20E28237CAA3B00409FF7 /* cc_config.h */, - BFE20E45237CAA3D00409FF7 /* cc_debug.h */, - BFE20E44237CAA3D00409FF7 /* cc_memory.h */, - BFE20E31237CAA3C00409FF7 /* cc_priv.h */, - BFE20E53237CAA3E00409FF7 /* cc_runtime_config.h */, - BFE20E41237CAA3D00409FF7 /* cc.h */, - BFE20E43237CAA3D00409FF7 /* ccaes.h */, - BFE20E13237CAA3A00409FF7 /* ccansikdf.h */, - BFE20E21237CAA3B00409FF7 /* ccasn1.h */, - BFE20E4C237CAA3E00409FF7 /* ccblowfish.h */, - BFE20E2F237CAA3C00409FF7 /* cccast.h */, - BFE20E4A237CAA3E00409FF7 /* ccchacha20poly1305_priv.h */, - BFE20E30237CAA3C00409FF7 /* ccchacha20poly1305.h */, - BFE20E47237CAA3D00409FF7 /* cccmac.h */, - BFE20E25237CAA3B00409FF7 /* ccder_decode_eckey.h */, - BFE20E54237CAA3E00409FF7 /* ccder_encode_eckey.h */, - BFE20E16237CAA3B00409FF7 /* ccder_priv.h */, - BFE20E32237CAA3C00409FF7 /* ccder_rsa.h */, - BFE20E0E237CAA3A00409FF7 /* ccder.h */, - BFE20E23237CAA3B00409FF7 /* ccdes.h */, - BFE20E46237CAA3D00409FF7 /* ccdh_gp.h */, - BFE20E2B237CAA3C00409FF7 /* ccdh_priv.h */, - BFE20E37237CAA3C00409FF7 /* ccdh.h */, - BFE20E4D237CAA3E00409FF7 /* ccdigest_priv.h */, - BFE20E36237CAA3C00409FF7 /* ccdigest.h */, - BFE20E3D237CAA3D00409FF7 /* ccdrbg_factory.h */, - BFE20E2E237CAA3C00409FF7 /* ccdrbg_impl.h */, - BFE20E1B237CAA3B00409FF7 /* ccdrbg.h */, - BFE20E12237CAA3A00409FF7 /* ccec_priv.h */, - BFE20E39237CAA3C00409FF7 /* ccec.h */, - BFE20E1E237CAA3B00409FF7 /* ccec25519_priv.h */, - BFE20E0F237CAA3A00409FF7 /* ccec25519.h */, - BFE20E4B237CAA3E00409FF7 /* ccecies_priv.h */, - BFE20E51237CAA3E00409FF7 /* ccecies.h */, - BFE20E11237CAA3A00409FF7 /* cchkdf.h */, - BFE20E33237CAA3C00409FF7 /* cchmac.h */, - BFE20E59237CAA3E00409FF7 /* ccmd2.h */, - BFE20E38237CAA3C00409FF7 /* ccmd4.h */, - BFE20E1D237CAA3B00409FF7 /* ccmd5.h */, - BFE20E48237CAA3D00409FF7 /* ccmode_factory.h */, - BFE20E56237CAA3E00409FF7 /* ccmode_impl.h */, - BFE20E10237CAA3A00409FF7 /* ccmode_siv_priv.h */, - BFE20E40237CAA3D00409FF7 /* ccmode_siv.h */, - BFE20E3F237CAA3D00409FF7 /* ccmode.h */, - BFE20E26237CAA3B00409FF7 /* ccn_priv.h */, - BFE20E49237CAA3E00409FF7 /* ccn.h */, - BFE20E3C237CAA3C00409FF7 /* ccnistkdf.h */, - BFE20E2A237CAA3B00409FF7 /* ccpad.h */, - BFE20E14237CAA3A00409FF7 /* ccpbkdf2.h */, - BFE20E3A237CAA3C00409FF7 /* ccperf.h */, - BFE20E4E237CAA3E00409FF7 /* ccprime.h */, - BFE20E50237CAA3E00409FF7 /* ccrc2.h */, - BFE20E15237CAA3A00409FF7 /* ccrc4.h */, - BFE20E24237CAA3B00409FF7 /* ccripemd.h */, - BFE20E34237CAA3C00409FF7 /* ccrng_drbg.h */, - BFE20E17237CAA3B00409FF7 /* ccrng_ecfips_test.h */, - BFE20E2D237CAA3C00409FF7 /* ccrng_pbkdf2_prng.h */, - BFE20E1A237CAA3B00409FF7 /* ccrng_priv.h */, - BFE20E3E237CAA3D00409FF7 /* ccrng_rsafips_test.h */, - BFE20E35237CAA3C00409FF7 /* ccrng_sequence.h */, - BFE20E22237CAA3B00409FF7 /* ccrng_system.h */, - BFE20E18237CAA3B00409FF7 /* ccrng_test.h */, - BFE20E52237CAA3E00409FF7 /* ccrng.h */, - BFE20E19237CAA3B00409FF7 /* ccrsa_priv.h */, - BFE20E2C237CAA3C00409FF7 /* ccrsa.h */, - BFE20E1F237CAA3B00409FF7 /* ccsha1.h */, - BFE20E20237CAA3B00409FF7 /* ccsha2.h */, - BFE20E58237CAA3E00409FF7 /* ccsrp_gp.h */, - BFE20E42237CAA3D00409FF7 /* ccsrp.h */, - BF5C690C24A5205E00C2F854 /* ccsrp.m */, - BFE20E29237CAA3B00409FF7 /* cctest.h */, - BFE20E4F237CAA3E00409FF7 /* ccwrap.h */, - BFE20E27237CAA3B00409FF7 /* ccz_priv.h */, - BFE20E1C237CAA3B00409FF7 /* ccz.h */, - BFE20E55237CAA3E00409FF7 /* cczp_priv.h */, - BFE20E57237CAA3E00409FF7 /* cczp.h */, - BFE20E3B237CAA3C00409FF7 /* fipspost.h */, - ); - name = corecrypto; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - BF5AB3942285FDB200DC914B /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - BFBAC8912295E05600587369 /* ALTAppleAPI.h in Headers */, - BFE20E07237C932600409FF7 /* ALTAnisetteData.h in Headers */, - BF9B6400229E0AA0002F0A62 /* crypt.h in Headers */, - BFBAC88B2295D90F00587369 /* ALTProvisioningProfile.h in Headers */, - BF5AB3B92286024D00DC914B /* ALTAccount.h in Headers */, - BFD80D542380A00B00B9C227 /* ALTAppleAPI_Private.h in Headers */, - BF50E7BF22C163DC0070E17B /* ALTApplication.h in Headers */, - BF5AB3BF2286040400DC914B /* NSError+ALTErrors.h in Headers */, - BF5AB3CD228645DF00DC914B /* ALTCertificate.h in Headers */, - BF48CFEE229437580004760B /* ALTCertificateRequest.h in Headers */, - BF50E7CF22C28F8B0070E17B /* ALTCapabilities.h in Headers */, - BF9B6408229E0AA0002F0A62 /* mztools.h in Headers */, - BF5AB3C92286269B00DC914B /* ALTDevice.h in Headers */, - BF9B6404229E0AA0002F0A62 /* zip.h in Headers */, - BF9B641D229E0DF5002F0A62 /* ALTSigner.h in Headers */, - BF9B6414229E0CCE002F0A62 /* NSFileManager+Apps.h in Headers */, - BF50E7B822C161630070E17B /* ALTAppGroup.h in Headers */, - BF9B6410229E0AA0002F0A62 /* unzip.h in Headers */, - BF9B6406229E0AA0002F0A62 /* ioapi.h in Headers */, - BFD80D4F23809EE100B9C227 /* ALTAppleAPI+Authentication.h in Headers */, - BF9B633F229DC27C002F0A62 /* ALTModel+Internal.h in Headers */, - BF5AB3B5228600D100DC914B /* AltSign.h in Headers */, - BF5AB3C52286157F00DC914B /* ALTTeam.h in Headers */, - BF5D43F6237F53BB00EC8745 /* ALTAppleAPISession.h in Headers */, - BF48CFF622944FC60004760B /* ALTAppID.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - BF9B637D229DCF3A002F0A62 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - BF9B637E229DCF3A002F0A62 /* ALTAppleAPI.h in Headers */, - BFE20E08237C932600409FF7 /* ALTAnisetteData.h in Headers */, - BF9B6401229E0AA0002F0A62 /* crypt.h in Headers */, - BF9B637F229DCF3A002F0A62 /* ALTProvisioningProfile.h in Headers */, - BF9B6380229DCF3A002F0A62 /* ALTAccount.h in Headers */, - BFD80D552380A00B00B9C227 /* ALTAppleAPI_Private.h in Headers */, - BF50E7C022C163DC0070E17B /* ALTApplication.h in Headers */, - BF9B6381229DCF3A002F0A62 /* NSError+ALTErrors.h in Headers */, - BF9B6382229DCF3A002F0A62 /* ALTCertificate.h in Headers */, - BF9B6383229DCF3A002F0A62 /* ALTCertificateRequest.h in Headers */, - BF50E7D022C28F8B0070E17B /* ALTCapabilities.h in Headers */, - BF9B6409229E0AA0002F0A62 /* mztools.h in Headers */, - BF9B6384229DCF3A002F0A62 /* ALTDevice.h in Headers */, - BF9B6405229E0AA0002F0A62 /* zip.h in Headers */, - BF9B641E229E0DF5002F0A62 /* ALTSigner.h in Headers */, - BF9B6415229E0CCE002F0A62 /* NSFileManager+Apps.h in Headers */, - BF50E7B922C161630070E17B /* ALTAppGroup.h in Headers */, - BF9B6411229E0AA0002F0A62 /* unzip.h in Headers */, - BF9B6407229E0AA0002F0A62 /* ioapi.h in Headers */, - BFD80D5023809EE100B9C227 /* ALTAppleAPI+Authentication.h in Headers */, - BF9B6385229DCF3A002F0A62 /* ALTModel+Internal.h in Headers */, - BF9B6386229DCF3A002F0A62 /* AltSign.h in Headers */, - BF9B6387229DCF3A002F0A62 /* ALTTeam.h in Headers */, - BF5D43F7237F53BB00EC8745 /* ALTAppleAPISession.h in Headers */, - BF9B6388229DCF3A002F0A62 /* ALTAppID.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - BF5AB3982285FDB200DC914B /* AltSign */ = { - isa = PBXNativeTarget; - buildConfigurationList = BF5AB3A12285FDB200DC914B /* Build configuration list for PBXNativeTarget "AltSign" */; - buildPhases = ( - BF5AB3942285FDB200DC914B /* Headers */, - BF5AB3952285FDB200DC914B /* Sources */, - BF5AB3962285FDB200DC914B /* Frameworks */, - BF5AB3972285FDB200DC914B /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - BF4586B622987AE400BD7491 /* PBXTargetDependency */, - ); - name = AltSign; - productName = AltSign; - productReference = BF5AB3992285FDB200DC914B /* AltSign.framework */; - productType = "com.apple.product-type.framework"; - }; - BF9B6378229DCF3A002F0A62 /* AltSign-macOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = BF9B639B229DCF3A002F0A62 /* Build configuration list for PBXNativeTarget "AltSign-macOS" */; - buildPhases = ( - BF9B637D229DCF3A002F0A62 /* Headers */, - BF9B6389229DCF3A002F0A62 /* Sources */, - BF9B6393229DCF3A002F0A62 /* Frameworks */, - BF9B639A229DCF3A002F0A62 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - BF9B63A1229DCFA4002F0A62 /* PBXTargetDependency */, - ); - name = "AltSign-macOS"; - productName = AltSign; - productReference = BF9B639E229DCF3A002F0A62 /* AltSign.framework */; - productType = "com.apple.product-type.framework"; - }; - BFBAC8A92295ED1900587369 /* ldid */ = { - isa = PBXNativeTarget; - buildConfigurationList = BFBAC8B02295ED1900587369 /* Build configuration list for PBXNativeTarget "ldid" */; - buildPhases = ( - BFBAC8A62295ED1900587369 /* Sources */, - BFBAC8A72295ED1900587369 /* Frameworks */, - BFBAC8A82295ED1900587369 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = ldid; - productName = ldid; - productReference = BFBAC8AA2295ED1900587369 /* libldid.a */; - productType = "com.apple.product-type.library.static"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - BF5AB3902285FDB200DC914B /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 1020; - ORGANIZATIONNAME = "Riley Testut"; - TargetAttributes = { - BF5AB3982285FDB200DC914B = { - CreatedOnToolsVersion = 10.2.1; - }; - BFBAC8A92295ED1900587369 = { - CreatedOnToolsVersion = 10.2.1; - }; - }; - }; - buildConfigurationList = BF5AB3932285FDB200DC914B /* Build configuration list for PBXProject "AltSign" */; - compatibilityVersion = "Xcode 9.3"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = BF5AB38F2285FDB200DC914B; - productRefGroup = BF5AB39A2285FDB200DC914B /* Products */; - projectDirPath = ""; - projectReferences = ( - { - ProductGroup = BF48CFE2229435DB0004760B /* Products */; - ProjectRef = BF48CFE1229435DB0004760B /* OpenSSL.xcodeproj */; - }, - ); - projectRoot = ""; - targets = ( - BF5AB3982285FDB200DC914B /* AltSign */, - BFBAC8A92295ED1900587369 /* ldid */, - BF9B6378229DCF3A002F0A62 /* AltSign-macOS */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXReferenceProxy section */ - BF48CFE7229435DB0004760B /* openssl.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = openssl.framework; - remoteRef = BF48CFE6229435DB0004760B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - BF48CFE9229435DB0004760B /* openssl.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = openssl.framework; - remoteRef = BF48CFE8229435DB0004760B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - -/* Begin PBXResourcesBuildPhase section */ - BF5AB3972285FDB200DC914B /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - BF9B6421229E0DF5002F0A62 /* apple.pem in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - BF9B639A229DCF3A002F0A62 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - BF9B6422229E0DF5002F0A62 /* apple.pem in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - BF5AB3952285FDB200DC914B /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - BF9B641F229E0DF5002F0A62 /* ALTSigner.mm in Sources */, - BF48CFF0229438C10004760B /* ALTCertificateRequest.m in Sources */, - BFBAC88C2295D90F00587369 /* ALTProvisioningProfile.m in Sources */, - BF5AB3C62286157F00DC914B /* ALTTeam.m in Sources */, - BF5D43F8237F53BB00EC8745 /* ALTAppleAPISession.m in Sources */, - BF5AB3CA2286269B00DC914B /* ALTDevice.m in Sources */, - BF9B640E229E0AA0002F0A62 /* mztools.c in Sources */, - BFD80D5123809EE100B9C227 /* ALTAppleAPI+Authentication.m in Sources */, - BFBAC8922295E05600587369 /* ALTAppleAPI.m in Sources */, - BF50E7BA22C161630070E17B /* ALTAppGroup.m in Sources */, - BF9B6416229E0CCE002F0A62 /* NSFileManager+Apps.m in Sources */, - BF48CFF722944FC60004760B /* ALTAppID.m in Sources */, - BF9B640A229E0AA0002F0A62 /* unzip.c in Sources */, - BF5AB3CE228645DF00DC914B /* ALTCertificate.m in Sources */, - BF5AB3BA2286024D00DC914B /* ALTAccount.m in Sources */, - BF5C690D24A5205E00C2F854 /* ccsrp.m in Sources */, - BF50E7C122C163DC0070E17B /* ALTApplication.mm in Sources */, - BF9B6402229E0AA0002F0A62 /* ioapi.c in Sources */, - BF9B640C229E0AA0002F0A62 /* zip.c in Sources */, - BFE20E09237C932600409FF7 /* ALTAnisetteData.m in Sources */, - BF5AB3C02286040400DC914B /* NSError+ALTErrors.m in Sources */, - BF50E7D122C28F8B0070E17B /* ALTCapabilities.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - BF9B6389229DCF3A002F0A62 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - BF9B6420229E0DF5002F0A62 /* ALTSigner.mm in Sources */, - BF9B638A229DCF3A002F0A62 /* ALTCertificateRequest.m in Sources */, - BF9B638B229DCF3A002F0A62 /* ALTProvisioningProfile.m in Sources */, - BF9B638C229DCF3A002F0A62 /* ALTTeam.m in Sources */, - BF5D43F9237F53BB00EC8745 /* ALTAppleAPISession.m in Sources */, - BF9B638D229DCF3A002F0A62 /* ALTDevice.m in Sources */, - BF9B640F229E0AA0002F0A62 /* mztools.c in Sources */, - BFD80D5223809EE100B9C227 /* ALTAppleAPI+Authentication.m in Sources */, - BF9B638E229DCF3A002F0A62 /* ALTAppleAPI.m in Sources */, - BF50E7BB22C161630070E17B /* ALTAppGroup.m in Sources */, - BF9B6417229E0CCE002F0A62 /* NSFileManager+Apps.m in Sources */, - BF9B638F229DCF3A002F0A62 /* ALTAppID.m in Sources */, - BF9B640B229E0AA0002F0A62 /* unzip.c in Sources */, - BF9B6390229DCF3A002F0A62 /* ALTCertificate.m in Sources */, - BF9B6391229DCF3A002F0A62 /* ALTAccount.m in Sources */, - BF5C690E24A5205E00C2F854 /* ccsrp.m in Sources */, - BF50E7C222C163DC0070E17B /* ALTApplication.mm in Sources */, - BF9B6403229E0AA0002F0A62 /* ioapi.c in Sources */, - BF9B640D229E0AA0002F0A62 /* zip.c in Sources */, - BFE20E0A237C932600409FF7 /* ALTAnisetteData.m in Sources */, - BF9B6392229DCF3A002F0A62 /* NSError+ALTErrors.m in Sources */, - BF50E7D222C28F8B0070E17B /* ALTCapabilities.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - BFBAC8A62295ED1900587369 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - BF0C4EAE22A1B3BF009A2DD7 /* Dictionary.cpp in Sources */, - BF0C4EAA22A1B3BF009A2DD7 /* xplist.c in Sources */, - BF0C4EB222A1B3BF009A2DD7 /* hashtable.c in Sources */, - BF0C4EB122A1B3BF009A2DD7 /* String.cpp in Sources */, - BF0C4EAD22A1B3BF009A2DD7 /* Key.cpp in Sources */, - BF0C4EB022A1B3BF009A2DD7 /* ptrarray.c in Sources */, - BF0C4EA622A1B3BF009A2DD7 /* Structure.cpp in Sources */, - BF0C4EAF22A1B3BF009A2DD7 /* Integer.cpp in Sources */, - BF50E7C622C169290070E17B /* alt_ldid.cpp in Sources */, - BF0C4EA822A1B3BF009A2DD7 /* base64.c in Sources */, - BF0C4EA022A1B3BF009A2DD7 /* Uid.cpp in Sources */, - BFBAC8E42295ED6C00587369 /* lookup2.c in Sources */, - BF0C4EB722A1B3CC009A2DD7 /* node.c in Sources */, - BF0C4EA522A1B3BF009A2DD7 /* time64.c in Sources */, - BF0C4EA922A1B3BF009A2DD7 /* Array.cpp in Sources */, - BF0C4EA422A1B3BF009A2DD7 /* bytearray.c in Sources */, - BF0C4EAB22A1B3BF009A2DD7 /* Boolean.cpp in Sources */, - BF0C4EA722A1B3BF009A2DD7 /* plist.c in Sources */, - BF0C4EB922A1B3CC009A2DD7 /* node_list.c in Sources */, - BF0C4EA322A1B3BF009A2DD7 /* Date.cpp in Sources */, - BF0C4EA122A1B3BF009A2DD7 /* Node.cpp in Sources */, - BF0C4EB322A1B3BF009A2DD7 /* Data.cpp in Sources */, - BF0C4EB822A1B3CC009A2DD7 /* cnary.c in Sources */, - BF0C4EAC22A1B3BF009A2DD7 /* bplist.c in Sources */, - BF0C4EA222A1B3BF009A2DD7 /* Real.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXTargetDependency section */ - BF4586B622987AE400BD7491 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = "OpenSSL (iOS)"; - targetProxy = BF4586B522987AE400BD7491 /* PBXContainerItemProxy */; - }; - BF9B63A1229DCFA4002F0A62 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = "OpenSSL (macOS)"; - targetProxy = BF9B63A0229DCFA4002F0A62 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - -/* Begin XCBuildConfiguration section */ - BF5AB39F2285FDB200DC914B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "\"$(SRCROOT)/Dependencies/OpenSSL/ios/include\"", - "\"$(SRCROOT)/Dependencies\"", - ); - IPHONEOS_DEPLOYMENT_TARGET = 12.0; - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - ONLY_ACTIVE_ARCH = YES; - OTHER_CFLAGS = "-DCORECRYPTO_DONOT_USE_TRANSPARENT_UNION"; - SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - BF5AB3A02285FDB200DC914B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "\"$(SRCROOT)/Dependencies/OpenSSL/ios/include\"", - "\"$(SRCROOT)/Dependencies\"", - ); - IPHONEOS_DEPLOYMENT_TARGET = 12.0; - MTL_ENABLE_DEBUG_INFO = NO; - MTL_FAST_MATH = YES; - OTHER_CFLAGS = "-DCORECRYPTO_DONOT_USE_TRANSPARENT_UNION"; - SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; - VALIDATE_PRODUCT = YES; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - BF5AB3A22285FDB200DC914B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_WARN_DOCUMENTATION_COMMENTS = NO; - CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Manual; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = AltSign/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.rileytestut.AltSign; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SKIP_INSTALL = YES; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - BF5AB3A32285FDB200DC914B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - APPLICATION_EXTENSION_API_ONLY = YES; - CLANG_WARN_DOCUMENTATION_COMMENTS = NO; - CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Manual; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = AltSign/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - PRODUCT_BUNDLE_IDENTIFIER = com.rileytestut.AltSign; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SKIP_INSTALL = YES; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; - BF9B639C229DCF3A002F0A62 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_WARN_DOCUMENTATION_COMMENTS = NO; - CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Manual; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = AltSign/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - MACOSX_DEPLOYMENT_TARGET = 10.14; - PRODUCT_BUNDLE_IDENTIFIER = com.rileytestut.AltSign; - PRODUCT_NAME = AltSign; - PROVISIONING_PROFILE_SPECIFIER = ""; - SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = macosx; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - BF9B639D229DCF3A002F0A62 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_WARN_DOCUMENTATION_COMMENTS = NO; - CODE_SIGN_IDENTITY = ""; - CODE_SIGN_STYLE = Manual; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = AltSign/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = ( - "$(inherited)", - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - MACOSX_DEPLOYMENT_TARGET = 10.14; - PRODUCT_BUNDLE_IDENTIFIER = com.rileytestut.AltSign; - PRODUCT_NAME = AltSign; - PROVISIONING_PROFILE_SPECIFIER = ""; - SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = macosx; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; - BFBAC8B12295ED1900587369 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 6XVY5G3U44; - GCC_WARN_INHIBIT_ALL_WARNINGS = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - "\"$(SRCROOT)/Dependencies/ldid/libplist/include\"", - "\"$(SRCROOT)/Dependencies/ldid/libplist/src\"", - "\"$(SRCROOT)/Dependencies/ldid/libplist/libcnary/include\"", - "\"${SDKROOT}/usr/include/libxml2\"", - ); - IPHONEOS_DEPLOYMENT_TARGET = 12.0; - MACOSX_DEPLOYMENT_TARGET = 10.14; - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx"; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - BFBAC8B22295ED1900587369 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 6XVY5G3U44; - GCC_WARN_INHIBIT_ALL_WARNINGS = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - "\"$(SRCROOT)/Dependencies/ldid/libplist/include\"", - "\"$(SRCROOT)/Dependencies/ldid/libplist/src\"", - "\"$(SRCROOT)/Dependencies/ldid/libplist/libcnary/include\"", - "\"${SDKROOT}/usr/include/libxml2\"", - ); - IPHONEOS_DEPLOYMENT_TARGET = 12.0; - MACOSX_DEPLOYMENT_TARGET = 10.14; - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx"; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - BF5AB3932285FDB200DC914B /* Build configuration list for PBXProject "AltSign" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - BF5AB39F2285FDB200DC914B /* Debug */, - BF5AB3A02285FDB200DC914B /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - BF5AB3A12285FDB200DC914B /* Build configuration list for PBXNativeTarget "AltSign" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - BF5AB3A22285FDB200DC914B /* Debug */, - BF5AB3A32285FDB200DC914B /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - BF9B639B229DCF3A002F0A62 /* Build configuration list for PBXNativeTarget "AltSign-macOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - BF9B639C229DCF3A002F0A62 /* Debug */, - BF9B639D229DCF3A002F0A62 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - BFBAC8B02295ED1900587369 /* Build configuration list for PBXNativeTarget "ldid" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - BFBAC8B12295ED1900587369 /* Debug */, - BFBAC8B22295ED1900587369 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = BF5AB3902285FDB200DC914B /* Project object */; -} diff --git a/AltSign.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/AltSign.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 150efde..0000000 --- a/AltSign.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/AltSign.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/AltSign.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/AltSign.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/AltSign.xcodeproj/xcshareddata/xcschemes/AltSign-macOS.xcscheme b/AltSign.xcodeproj/xcshareddata/xcschemes/AltSign-macOS.xcscheme deleted file mode 100644 index 8fdecc7..0000000 --- a/AltSign.xcodeproj/xcshareddata/xcschemes/AltSign-macOS.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AltSign.xcodeproj/xcshareddata/xcschemes/AltSign.xcscheme b/AltSign.xcodeproj/xcshareddata/xcschemes/AltSign.xcscheme deleted file mode 100644 index f8e2ce4..0000000 --- a/AltSign.xcodeproj/xcshareddata/xcschemes/AltSign.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AltSign.xcodeproj/xcshareddata/xcschemes/ldid.xcscheme b/AltSign.xcodeproj/xcshareddata/xcschemes/ldid.xcscheme deleted file mode 100644 index adfa49a..0000000 --- a/AltSign.xcodeproj/xcshareddata/xcschemes/ldid.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AltSign/Apple API/ALTAppleAPI+Authentication.h b/AltSign/Apple API/ALTAppleAPI+Authentication.h deleted file mode 100644 index c0c425e..0000000 --- a/AltSign/Apple API/ALTAppleAPI+Authentication.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// ALTAppleAPI+Authentication.h -// AltSign -// -// Created by Riley Testut on 11/16/19. -// Copyright © 2019 Riley Testut. All rights reserved. -// - -@class ALTAppleAPISession; - -#import - -@class ALTAppleAPISession; - -NS_ASSUME_NONNULL_BEGIN - -@interface ALTAppleAPI (Authentication) - -- (void)authenticateWithAppleID:(NSString *)appleID - password:(NSString *)password - anisetteData:(ALTAnisetteData *)anisetteData - verificationHandler:(nullable void (^)(void (^completionHandler)(NSString *_Nullable verificationCode)))verificationHandler - completionHandler:(void (^)(ALTAccount *_Nullable account, ALTAppleAPISession *_Nullable session, NSError *_Nullable error))completionHandler -NS_SWIFT_NAME(authenticate(appleID:password:anisetteData:verificationHandler:completionHandler:)); - -@end - -NS_ASSUME_NONNULL_END diff --git a/AltSign/Apple API/ALTAppleAPI+Authentication.m b/AltSign/Apple API/ALTAppleAPI+Authentication.m deleted file mode 100644 index 7a45975..0000000 --- a/AltSign/Apple API/ALTAppleAPI+Authentication.m +++ /dev/null @@ -1,763 +0,0 @@ -// -// ALTAppleAPI+Authentication.m -// AltSign -// -// Created by Riley Testut on 11/16/19. -// Copyright © 2019 Riley Testut. All rights reserved. -// -// Heavily based on sample code provided by Kabir Oberai (https://github.com/kabiroberai) -// - -#import "ALTAppleAPI+Authentication.h" -#import "ALTAppleAPI_Private.h" - -#import "ALTModel+Internal.h" - -// Core Crypto -#import -#import -#import -#import -#import -#import -#import -#import -#import - -static const char ALTHexCharacters[] = "0123456789abcdef"; - -struct ccrng_state *ccDRBGGetRngState(void); - -void ALTDigestUpdateString(const struct ccdigest_info *di_info, struct ccdigest_ctx *di_ctx, NSString *string) -{ - ccdigest_update(di_info, di_ctx, string.length, string.UTF8String); -} - -void ALTDigestUpdateData(const struct ccdigest_info *di_info, struct ccdigest_ctx *di_ctx, NSData *data) -{ - uint32_t data_len = (uint32_t)data.length; // 4 bytes for length - ccdigest_update(di_info, di_ctx, sizeof(data_len), &data_len); - ccdigest_update(di_info, di_ctx, data_len, data.bytes); -} - -NSData *ALTPBKDF2SRP(const struct ccdigest_info *di_info, BOOL isS2k, NSString *password, NSData *salt, int iterations) -{ - const struct ccdigest_info *password_di_info = ccsha256_di(); - char *digest_raw = (char *)malloc(password_di_info->output_size); - const char *passwordUTF8 = password.UTF8String; - ccdigest(password_di_info, strlen(passwordUTF8), passwordUTF8, digest_raw); - - size_t final_digest_len = password_di_info->output_size * (isS2k ? 1 : 2); - char *digest = (char *)malloc(final_digest_len); - - if (isS2k) - { - memcpy(digest, digest_raw, final_digest_len); - } - else - { - for (int i = 0; i < password_di_info->output_size; i++) - { - char byte = digest_raw[i]; - digest[i * 2 + 0] = ALTHexCharacters[(byte >> 4) & 0x0F]; - digest[i * 2 + 1] = ALTHexCharacters[(byte >> 0) & 0x0F]; - } - } - - NSMutableData *data = [NSMutableData dataWithLength:di_info->output_size]; - - if (ccpbkdf2_hmac(di_info, final_digest_len, digest, salt.length, salt.bytes, iterations, di_info->output_size, data.mutableBytes) != 0) - { - return nil; - } - - return data; -} - -NSData *ALTCreateSessionKey(ccsrp_ctx_t srp_ctx, const char *key_name) -{ - size_t key_len; - const void *session_key = ccsrp_get_session_key(srp_ctx, &key_len); - - const struct ccdigest_info *di_info = ccsha256_di(); - - size_t hmac_len = di_info->output_size; - unsigned char *hmac_bytes = (unsigned char *)malloc(hmac_len); - cchmac(di_info, key_len, session_key, strlen(key_name), key_name, hmac_bytes); - - NSData *sessionKey = [NSData dataWithBytes:hmac_bytes length:hmac_len]; - return sessionKey; -} - -NSData *ALTDecryptDataCBC(ccsrp_ctx_t srp_ctx, NSData *spd) -{ - NSData *extraDataKey = ALTCreateSessionKey(srp_ctx, "extra data key:"); - NSData *extraDataIV = ALTCreateSessionKey(srp_ctx, "extra data iv:"); - - NSMutableData *decryptedData = [NSMutableData dataWithLength:spd.length]; - - const struct ccmode_cbc *decrypt_mode = ccaes_cbc_decrypt_mode(); - - cccbc_iv *iv = (cccbc_iv *)malloc(decrypt_mode->block_size); - if (extraDataIV.bytes) - { - memcpy(iv, extraDataIV.bytes, decrypt_mode->block_size); - } - else - { - bzero(iv, decrypt_mode->block_size); - } - - cccbc_ctx *ctx_buf = (cccbc_ctx *)malloc(decrypt_mode->size); - decrypt_mode->init(decrypt_mode, ctx_buf, extraDataKey.length, extraDataKey.bytes); - - size_t length = ccpad_pkcs7_decrypt(decrypt_mode, ctx_buf, iv, spd.length, spd.bytes, decryptedData.mutableBytes); - if (length > spd.length) - { - return nil; - } - - return decryptedData; -} - -NSData *ALTDecryptDataGCM(NSData *sk, NSData *encryptedData) -{ - const struct ccmode_gcm *decrypt_mode = ccaes_gcm_decrypt_mode(); - - ccgcm_ctx *gcm_ctx = (ccgcm_ctx *)malloc(decrypt_mode->size); - decrypt_mode->init(decrypt_mode, gcm_ctx, sk.length, sk.bytes); - - if (encryptedData.length < 35) - { - NSLog(@"ERROR: Encrypted token too short."); - return nil; - } - - if (cc_cmp_safe(3, encryptedData.bytes, "XYZ")) - { - NSLog(@"ERROR: Encrypted token wrong version!"); - return nil; - } - - decrypt_mode->set_iv(gcm_ctx, 16, encryptedData.bytes + 3); - decrypt_mode->gmac(gcm_ctx, 3, encryptedData.bytes); - - size_t decrypted_len = encryptedData.length - 35; - NSMutableData *decryptedData = [NSMutableData dataWithLength:decrypted_len]; - - decrypt_mode->gcm(gcm_ctx, decrypted_len, encryptedData.bytes + 16 + 3, decryptedData.mutableBytes); - - char tag[16]; - decrypt_mode->finalize(gcm_ctx, 16, tag); - - if (cc_cmp_safe(16, encryptedData.bytes + decrypted_len + 19, tag)) - { - NSLog(@"Invalid tag version"); - return nil; - } - - return decryptedData; -} - -NSData *ALTCreateAppTokensChecksum(NSData *sk, NSString *adsid, NSArray *apps) -{ - const struct ccdigest_info *di_info = ccsha256_di(); - size_t hmac_size = cchmac_di_size(di_info); - struct cchmac_ctx *hmac_ctx = (struct cchmac_ctx *)malloc(hmac_size); - cchmac_init(di_info, hmac_ctx, sk.length, sk.bytes); - - const char *key = "apptokens"; - cchmac_update(di_info, hmac_ctx, strlen(key), key); - - const char *adsidUTF8 = adsid.UTF8String; - cchmac_update(di_info, hmac_ctx, strlen(adsidUTF8), adsidUTF8); - - for (NSString *app in apps) - { - cchmac_update(di_info, hmac_ctx, app.length, app.UTF8String); - } - - NSMutableData *checksum = [NSMutableData dataWithLength:di_info->output_size]; - cchmac_final(di_info, hmac_ctx, checksum.mutableBytes); - - return checksum; -} - -@implementation ALTAppleAPI (Authentication) - -- (void)authenticateWithAppleID:(NSString *)appleID - password:(NSString *)password - anisetteData:(ALTAnisetteData *)anisetteData - verificationHandler:(void (^)(void (^ _Nonnull)(NSString * _Nullable)))verificationHandler - completionHandler:(void (^)(ALTAccount * _Nullable, ALTAppleAPISession * _Nullable, NSError * _Nullable))completionHandler -{ - NSMutableDictionary *clientDictionary = [@{ - @"bootstrap": @YES, - @"icscrec": @YES, - @"loc": NSLocale.currentLocale.localeIdentifier, - @"pbe": @NO, - @"prkgen": @YES, - @"svct": @"iCloud", - @"X-Apple-I-Client-Time": [self.dateFormatter stringFromDate:anisetteData.date], - @"X-Apple-Locale": NSLocale.currentLocale.localeIdentifier, - @"X-Apple-I-TimeZone": NSTimeZone.localTimeZone.abbreviation, - @"X-Apple-I-MD": anisetteData.oneTimePassword, - @"X-Apple-I-MD-LU": anisetteData.localUserID, - @"X-Apple-I-MD-M": anisetteData.machineID, - @"X-Apple-I-MD-RINFO": @(anisetteData.routingInfo), - @"X-Mme-Device-Id": anisetteData.deviceUniqueIdentifier, - @"X-Apple-I-SRL-NO": anisetteData.deviceSerialNumber, - } mutableCopy]; - - /* Begin CoreCrypto Logic */ - ccsrp_const_gp_t gp = ccsrp_gp_rfc5054_2048(); - - const struct ccdigest_info *di_info = ccsha256_di(); - struct ccdigest_ctx *di_ctx = (struct ccdigest_ctx *)malloc(ccdigest_di_size(di_info)); - ccdigest_init(di_info, di_ctx); - - const struct ccdigest_info *srp_di = ccsha256_di(); - struct ccsrp_ctx *srp_ctx = (struct ccsrp_ctx *)malloc(ccsrp_sizeof_srp(di_info, gp)); - ccsrp_ctx_init(srp_ctx, srp_di, gp); - ccsrp_client_set_noUsernameInX(srp_ctx, true); - SRP_RNG(srp_ctx) = ccrng(NULL); - - NSArray *ps = @[@"s2k", @"s2k_fo"]; - ALTDigestUpdateString(di_info, di_ctx, ps[0]); - ALTDigestUpdateString(di_info, di_ctx, @","); - ALTDigestUpdateString(di_info, di_ctx, ps[1]); - - size_t A_size = ccsrp_exchange_size(srp_ctx); - char *A_bytes = (char *)malloc(A_size); - ccsrp_client_start_authentication(srp_ctx, ccDRBGGetRngState(), A_bytes); - - NSData *A_data = [NSData dataWithBytes:A_bytes length:A_size]; - - ALTDigestUpdateString(di_info, di_ctx, @"|"); - - NSDictionary *parameters = @{ - @"A2k": A_data, - @"ps": ps, - @"cpd": clientDictionary, - @"u": appleID, - @"o": @"init" - }; - - // 1st Request - [self sendAuthenticationRequestWithParameters:parameters anisetteData:anisetteData completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { - if (responseDictionary == nil) - { - completionHandler(nil, nil, requestError); - return; - } - - size_t M_size = ccsrp_get_session_key_length(srp_ctx); - char *M_bytes = (char *)malloc(A_size); - NSData *M_data = [NSData dataWithBytes:M_bytes length:M_size]; - - NSString *sp = responseDictionary[@"sp"]; - BOOL isS2K = [sp isEqualToString:@"s2k"]; - - ALTDigestUpdateString(di_info, di_ctx, @"|"); - - if (sp) - { - ALTDigestUpdateString(di_info, di_ctx, sp); - } - - NSString *c = responseDictionary[@"c"]; - NSData *salt = responseDictionary[@"s"]; - NSNumber *iterations = responseDictionary[@"i"]; - NSData *B_data = responseDictionary[@"B"]; - - if (c == nil || salt == nil || iterations == nil || B_data == nil) - { - completionHandler(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]); - return; - } - - NSData *passwordKey = ALTPBKDF2SRP(di_info, isS2K, password, salt, [iterations intValue]); - if (passwordKey == nil) - { - completionHandler(nil, nil, [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorAuthenticationHandshakeFailed userInfo:nil]); - return; - } - - int result = ccsrp_client_process_challenge(srp_ctx, appleID.UTF8String, passwordKey.length, passwordKey.bytes, - salt.length, salt.bytes, B_data.bytes, (void *)M_data.bytes); - if (result != 0) - { - completionHandler(nil, nil, [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorAuthenticationHandshakeFailed userInfo:nil]); - return; - } - - NSDictionary *parameters = @{ - @"c": c, - @"M1": M_data, - @"cpd": clientDictionary, - @"u": appleID, - @"o": @"complete" - }; - - // 2nd Request - [self sendAuthenticationRequestWithParameters:parameters anisetteData:anisetteData completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { - if (responseDictionary == nil) - { - completionHandler(nil, nil, requestError); - return; - } - - NSData *M2_data = responseDictionary[@"M2"]; - if (M2_data == nil) - { - NSLog(@"ERROR: M2 data not found!"); - - completionHandler(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]); - return; - } - - if (!ccsrp_client_verify_session(srp_ctx, M2_data.bytes)) - { - NSLog(@"ERROR: Failed to verify session."); - - completionHandler(nil, nil, [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorAuthenticationHandshakeFailed userInfo:nil]); - return; - } - - ALTDigestUpdateString(di_info, di_ctx, @"|"); - - NSData *spd = responseDictionary[@"spd"]; - if (spd) - { - ALTDigestUpdateData(di_info, di_ctx, spd); - } - - ALTDigestUpdateString(di_info, di_ctx, @"|"); - - NSData *sc = responseDictionary[@"sc"]; - if (sc) - { - ALTDigestUpdateData(di_info, di_ctx, sc); - } - - ALTDigestUpdateString(di_info, di_ctx, @"|"); - - NSData *np = responseDictionary[@"np"]; - if (np == nil) - { - NSLog(@"ERROR: Missing np dictionary."); - - completionHandler(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]); - return; - } - - size_t digest_len = di_info->output_size; - if (np.length != digest_len) - { - NSLog(@"ERROR: Neg proto hash is too short."); - - completionHandler(nil, nil, [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorAuthenticationHandshakeFailed userInfo:nil]); - return; - } - - unsigned char *digest = (unsigned char *)malloc(digest_len); - di_info->final(di_info, di_ctx, digest); - - NSData *hmacKey = ALTCreateSessionKey(srp_ctx, "HMAC key:"); - unsigned char *hmac_out = (unsigned char *)malloc(digest_len); - cchmac(di_info, hmacKey.length, hmacKey.bytes, digest_len, digest, hmac_out); - - if (cc_cmp_safe(digest_len, hmac_out, np.bytes)) - { - NSLog(@"ERROR: Invalid neg prot hmac."); - - completionHandler(nil, nil, [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorAuthenticationHandshakeFailed userInfo:nil]); - return; - } - - NSData *decryptedData = ALTDecryptDataCBC(srp_ctx, spd); - if (decryptedData == nil) - { - NSLog(@"ERROR: Could not decrypt login response."); - - completionHandler(nil, nil, [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorAuthenticationHandshakeFailed userInfo:nil]); - return; - } - - NSError *parseError = nil; - NSDictionary *decryptedDictionary = [NSPropertyListSerialization propertyListWithData:decryptedData options:0 format:nil error:&parseError]; - if (decryptedDictionary == nil) - { - NSLog(@"ERROR: Could not parse decrypted login response plist!"); - - completionHandler(nil, nil, parseError); - return; - } - - NSString *adsid = decryptedDictionary[@"adsid"]; - NSString *idmsToken = decryptedDictionary[@"GsIdmsToken"]; - - if (adsid == nil || idmsToken == nil) - { - NSLog(@"ERROR: adsid and/or idmsToken is nil. adsid: %@. idmsToken: %@", adsid, idmsToken); - - completionHandler(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]); - return; - } - - NSDictionary *statusDictionary = responseDictionary[@"Status"]; - - NSString *authType = statusDictionary[@"au"]; - if ([authType isEqualToString:@"trustedDeviceSecondaryAuth"]) - { - // Handle Two-Factor - - if (verificationHandler != nil) - { - [self requestTwoFactorCodeForDSID:adsid idmsToken:idmsToken anisetteData:anisetteData verificationHandler:verificationHandler completionHandler:^(BOOL success, NSError *error) { - if (success) - { - // We've successfully signed-in with two-factor, so restart authentication (which will now succeed). - [self authenticateWithAppleID:appleID password:password anisetteData:anisetteData verificationHandler:verificationHandler completionHandler:completionHandler]; - } - else - { - completionHandler(nil, nil, error); - } - }]; - } - else - { - completionHandler(nil, nil, [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorRequiresTwoFactorAuthentication userInfo:nil]); - } - } - else - { - // Fetch Auth Token - - NSData *sk = decryptedDictionary[@"sk"]; - NSData *c = decryptedDictionary[@"c"]; - - if (sk == nil || c == nil) - { - NSLog(@"ERROR: No ak and/or c data."); - - completionHandler(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]); - return; - } - - NSArray *apps = @[@"com.apple.gs.xcode.auth"]; - NSData *checksum = ALTCreateAppTokensChecksum(sk, adsid, apps); - - NSDictionary *parameters = @{ - @"u": adsid, - @"app": apps, - @"c": c, - @"t": idmsToken, - @"checksum": checksum, - @"cpd": clientDictionary, - @"o": @"apptokens" - }; - - [self fetchAuthTokenWithParameters:parameters sk:sk anisetteData:anisetteData completionHandler:^(NSString *authToken, NSError *error) { - if (authToken == nil) - { - completionHandler(nil, nil, error); - return; - } - - ALTAppleAPISession *session = [[ALTAppleAPISession alloc] initWithDSID:adsid authToken:authToken anisetteData:anisetteData]; - [self fetchAccountForSession:session completionHandler:^(ALTAccount *account, NSError *error) { - if (account == nil) - { - completionHandler(nil, nil, error); - } - else - { - completionHandler(account, session, nil); - } - }]; - }]; - } - }]; - }]; -} - -- (void)fetchAuthTokenWithParameters:(NSDictionary *)parameters sk:(NSData *)sk anisetteData:(ALTAnisetteData *)anisetteData completionHandler:(void (^)(NSString *authToken, NSError *error))completionHandler -{ - [self sendAuthenticationRequestWithParameters:parameters anisetteData:anisetteData completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { - if (responseDictionary == nil) - { - completionHandler(nil, requestError); - return; - } - - NSData *encryptedToken = responseDictionary[@"et"]; - NSData *decryptedToken = ALTDecryptDataGCM(sk, encryptedToken); - - if (decryptedToken == nil) - { - NSLog(@"ERROR: Failed to decrypt apptoken."); - - completionHandler(nil, [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]); - return; - } - - NSError *parseError = nil; - NSDictionary *decryptedTokenDictionary = [NSPropertyListSerialization propertyListWithData:decryptedToken options:0 format:nil error:&parseError]; - if (decryptedTokenDictionary == nil) - { - NSLog(@"ERROR: Could not parse decrypted apptoken plist."); - - completionHandler(nil, parseError); - return; - } - - NSString *app = [parameters[@"app"] firstObject]; - - NSDictionary *tokenDictionary = decryptedTokenDictionary[@"t"][app]; - NSString *token = tokenDictionary[@"token"]; - NSNumber *expirationDataMS = tokenDictionary[@"expiry"]; - - if (token == nil) - { - completionHandler(nil, [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]); - return; - } - - NSDate *expirationDate = [NSDate dateWithTimeIntervalSince1970:(double)expirationDataMS.integerValue / 1000]; - NSLog(@"Got token for %@!\nExpires: %@\nValue: %@\n", app, expirationDate, token); - - completionHandler(token, nil); - }]; -} - -- (void)requestTwoFactorCodeForDSID:(NSString *)dsid idmsToken:(NSString *)idmsToken anisetteData:(ALTAnisetteData *)anisetteData - verificationHandler:(nonnull void (^)(void (^ _Nonnull)(NSString * _Nonnull)))verificationHandler - completionHandler:(void (^)(BOOL success, NSError *error))completionHandler -{ - NSURL *URL = [NSURL URLWithString:@"https://gsa.apple.com/auth/verify/trusteddevice"]; - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; - - NSString *identityToken = [NSString stringWithFormat:@"%@:%@", dsid, idmsToken]; - - NSData *identityTokenData = [identityToken dataUsingEncoding:NSUTF8StringEncoding]; - NSString *encodedIdentityToken = [identityTokenData base64EncodedStringWithOptions:0]; - - NSDictionary *httpHeaders = @{ - @"Content-Type": @"text/x-xml-plist", - @"User-Agent": @"Xcode", - @"Accept": @"text/x-xml-plist", - @"Accept-Language": @"en-us", - @"X-Apple-App-Info": @"com.apple.gs.xcode.auth", - @"X-Xcode-Version": @"11.2 (11B41)", - @"X-Apple-Identity-Token": encodedIdentityToken, - @"X-Apple-I-MD-M": anisetteData.machineID, - @"X-Apple-I-MD": anisetteData.oneTimePassword, - @"X-Apple-I-MD-LU": anisetteData.localUserID, - @"X-Apple-I-MD-RINFO": [@(anisetteData.routingInfo) description], - @"X-Mme-Device-Id": anisetteData.deviceUniqueIdentifier, - @"X-MMe-Client-Info": anisetteData.deviceDescription, - @"X-Apple-I-Client-Time": [self.dateFormatter stringFromDate:anisetteData.date], - @"X-Apple-Locale": anisetteData.locale.localeIdentifier, - @"X-Apple-I-TimeZone": anisetteData.timeZone.abbreviation - }; - - [httpHeaders enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) { - [request setValue:value forHTTPHeaderField:key]; - }]; - - NSURLSessionDataTask *requestCodeTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { - if (data == nil || error != nil) - { - completionHandler(NO, error); - return; - } - - void (^responseHandler)(NSString *) = ^(NSString *_Nullable verificationCode) { - if (verificationCode == nil) - { - completionHandler(NO, [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorRequiresTwoFactorAuthentication userInfo:nil]); - return; - } - - NSMutableDictionary *headers = [httpHeaders mutableCopy]; - headers[@"security-code"] = verificationCode; - - NSURL *URL = [NSURL URLWithString:@"https://gsa.apple.com/grandslam/GsService2/validate"]; - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; - - [headers enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) { - [request setValue:value forHTTPHeaderField:key]; - }]; - - NSURLSessionDataTask *verifyCodeTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { - if (data == nil || error != nil) - { - completionHandler(NO, error); - return; - } - - NSError *parseError = nil; - NSDictionary *responseDictionary = [NSPropertyListSerialization propertyListWithData:data options:0 format:nil error:&parseError]; - - if (responseDictionary == nil) - { - NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:@{NSUnderlyingErrorKey: parseError}]; - completionHandler(NO, error); - return; - } - - NSInteger errorCode = [responseDictionary[@"ec"] integerValue]; // Same for NSString or NSNumber. - if (errorCode != 0) - { - NSError *error = nil; - switch (errorCode) - { - case -21669: - error = [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorIncorrectVerificationCode userInfo:nil]; - break; - - default: - break; - } - - if (error == nil) - { - NSString *errorDescription = responseDictionary[@"em"]; - NSString *localizedDescription = [NSString stringWithFormat:@"%@ (%@)", errorDescription, @(errorCode)]; - - error = [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorUnknown userInfo:@{NSLocalizedDescriptionKey: localizedDescription}]; - } - - completionHandler(NO, error); - } - else - { - completionHandler(YES, nil); - } - }]; - - [verifyCodeTask resume]; - }; - - verificationHandler(responseHandler); - }]; - - [requestCodeTask resume]; -} - -- (void)fetchAccountForSession:(ALTAppleAPISession *)session completionHandler:(void (^)(ALTAccount *account, NSError *error))completionHandler -{ - NSURL *URL = [NSURL URLWithString:@"viewDeveloper.action" relativeToURL:self.baseURL]; - - [self sendRequestWithURL:URL additionalParameters:nil session:session team:nil completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { - if (responseDictionary == nil) - { - completionHandler(nil, requestError); - return; - } - - NSError *error = nil; - ALTAccount *account = [self processResponse:responseDictionary parseHandler:^id _Nullable{ - NSDictionary *dictionary = responseDictionary[@"developer"]; - if (dictionary == nil) - { - return nil; - } - - ALTAccount *account = [[ALTAccount alloc] initWithResponseDictionary:dictionary]; - return account; - } resultCodeHandler:nil error:&error]; - - completionHandler(account, error); - }]; -} - -- (void)sendAuthenticationRequestWithParameters:(NSDictionary *)requestDictionary anisetteData:(ALTAnisetteData *)anisetteData completionHandler:(void (^)(NSDictionary *responseDictionary, NSError *error))completionHandler -{ - NSURL *requestURL = [NSURL URLWithString:@"https://gsa.apple.com/grandslam/GsService2"]; - - NSDictionary *> *parameters = @{ - @"Header": @{ @"Version": @"1.0.1" }, - @"Request": requestDictionary - }; - - NSError *serializationError = nil; - NSData *bodyData = [NSPropertyListSerialization dataWithPropertyList:parameters format:NSPropertyListXMLFormat_v1_0 options:0 error:&serializationError]; - if (bodyData == nil) - { - NSError *error = [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorInvalidParameters userInfo:@{NSUnderlyingErrorKey: serializationError}]; - completionHandler(nil, error); - return; - } - - NSDictionary *httpHeaders = @{ - @"Content-Type": @"text/x-xml-plist", - @"X-MMe-Client-Info": anisetteData.deviceDescription, - @"Accept": @"*/*", - @"User-Agent": @"akd/1.0 CFNetwork/978.0.7 Darwin/18.7.0" - }; - - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL]; - request.HTTPMethod = @"POST"; - request.HTTPBody = bodyData; - [httpHeaders enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) { - [request setValue:value forHTTPHeaderField:key]; - }]; - - NSURLSessionDataTask *dataTask = [self.session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { - if (data == nil) - { - completionHandler(nil, error); - return; - } - - NSError *parseError = nil; - NSDictionary *responseDictionary = [NSPropertyListSerialization propertyListWithData:data options:0 format:nil error:&parseError]; - - if (responseDictionary == nil) - { - NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:@{NSUnderlyingErrorKey: parseError}]; - completionHandler(nil, error); - return; - } - - NSDictionary *dictionary = responseDictionary[@"Response"]; - - NSDictionary *status = dictionary[@"Status"]; - - NSInteger errorCode = [status[@"ec"] integerValue]; - if (errorCode != 0) - { - NSError *error = nil; - switch (errorCode) - { - case -22406: - error = [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorIncorrectCredentials userInfo:nil]; - break; - - default: - break; - } - - if (error == nil) - { - NSString *errorDescription = status[@"em"]; - NSString *localizedDescription = [NSString stringWithFormat:@"%@ (%@)", errorDescription, @(errorCode)]; - - error = [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorUnknown userInfo:@{NSLocalizedDescriptionKey: localizedDescription}]; - } - - completionHandler(nil, error); - } - else - { - completionHandler(dictionary, nil); - } - }]; - - [dataTask resume]; -} - -@end diff --git a/AltSign/Apple API/ALTAppleAPI.h b/AltSign/Apple API/ALTAppleAPI.h index 30cfd46..5ad1e17 100644 --- a/AltSign/Apple API/ALTAppleAPI.h +++ b/AltSign/Apple API/ALTAppleAPI.h @@ -9,6 +9,7 @@ #import #import "ALTCapabilities.h" +#import "ALTDevice.h" @class ALTAppleAPISession; @@ -32,12 +33,12 @@ NS_ASSUME_NONNULL_BEGIN completionHandler:(void (^)(NSArray *_Nullable teams, NSError *_Nullable error))completionHandler; /* Devices */ -- (void)fetchDevicesForTeam:(ALTTeam *)team session:(ALTAppleAPISession *)session +- (void)fetchDevicesForTeam:(ALTTeam *)team types:(ALTDeviceType)types session:(ALTAppleAPISession *)session completionHandler:(void (^)(NSArray *_Nullable devices, NSError *_Nullable error))completionHandler; -- (void)registerDeviceWithName:(NSString *)name identifier:(NSString *)identifier team:(ALTTeam *)team session:(ALTAppleAPISession *)session +- (void)registerDeviceWithName:(NSString *)name identifier:(NSString *)identifier type:(ALTDeviceType)type team:(ALTTeam *)team session:(ALTAppleAPISession *)session completionHandler:(void (^)(ALTDevice *_Nullable device, NSError *_Nullable error))completionHandler -NS_SWIFT_NAME(registerDevice(name:identifier:team:session:completionHandler:)); +NS_SWIFT_NAME(registerDevice(name:identifier:type:team:session:completionHandler:)); /* Certificates */ - (void)fetchCertificatesForTeam:(ALTTeam *)team session:(ALTAppleAPISession *)session @@ -75,7 +76,7 @@ NS_SWIFT_NAME(revoke(_:for:session:completionHandler:)); completionHandler:(void (^)(BOOL success, NSError *_Nullable error))completionHandler; /* Provisioning Profiles */ -- (void)fetchProvisioningProfileForAppID:(ALTAppID *)appID team:(ALTTeam *)team session:(ALTAppleAPISession *)session +- (void)fetchProvisioningProfileForAppID:(ALTAppID *)appID deviceType:(ALTDeviceType)deviceType team:(ALTTeam *)team session:(ALTAppleAPISession *)session completionHandler:(void (^)(ALTProvisioningProfile *_Nullable provisioningProfile, NSError *_Nullable error))completionHandler; - (void)deleteProvisioningProfile:(ALTProvisioningProfile *)provisioningProfile forTeam:(ALTTeam *)team session:(ALTAppleAPISession *)session diff --git a/AltSign/Apple API/ALTAppleAPI.m b/AltSign/Apple API/ALTAppleAPI.m index 8febecb..4da3587 100644 --- a/AltSign/Apple API/ALTAppleAPI.m +++ b/AltSign/Apple API/ALTAppleAPI.m @@ -14,6 +14,7 @@ #import "ALTModel+Internal.h" #import +#import NS_ASSUME_NONNULL_BEGIN @@ -100,7 +101,8 @@ - (void)fetchTeamsForAccount:(ALTAccount *)account session:(ALTAppleAPISession * #pragma mark - Devices - -- (void)fetchDevicesForTeam:(ALTTeam *)team session:(ALTAppleAPISession *)session completionHandler:(void (^)(NSArray * _Nullable, NSError * _Nullable))completionHandler +- (void)fetchDevicesForTeam:(ALTTeam *)team types:(ALTDeviceType)types session:(ALTAppleAPISession *)session + completionHandler:(void (^)(NSArray *_Nullable devices, NSError *_Nullable error))completionHandler { NSURL *URL = [NSURL URLWithString:@"ios/listDevices.action" relativeToURL:self.baseURL]; @@ -128,6 +130,12 @@ - (void)fetchDevicesForTeam:(ALTTeam *)team session:(ALTAppleAPISession *)sessio return nil; } + if ((types & device.type) != device.type) + { + // Device type doesn't match the ones we requested, so ignore it. + continue; + } + [devices addObject:device]; } return devices; @@ -137,11 +145,32 @@ - (void)fetchDevicesForTeam:(ALTTeam *)team session:(ALTAppleAPISession *)sessio }]; } -- (void)registerDeviceWithName:(NSString *)name identifier:(NSString *)identifier team:(ALTTeam *)team session:(ALTAppleAPISession *)session completionHandler:(void (^)(ALTDevice * _Nullable, NSError * _Nullable))completionHandler +- (void)registerDeviceWithName:(NSString *)name identifier:(NSString *)identifier type:(ALTDeviceType)type team:(ALTTeam *)team session:(ALTAppleAPISession *)session + completionHandler:(void (^)(ALTDevice *_Nullable device, NSError *_Nullable error))completionHandler { NSURL *URL = [NSURL URLWithString:@"ios/addDevice.action" relativeToURL:self.baseURL]; - [self sendRequestWithURL:URL additionalParameters:@{@"deviceNumber": identifier, @"name": name} session:session team:team completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { + NSMutableDictionary *parameters = [@{ + @"deviceNumber": identifier, + @"name": name, + } mutableCopy]; + + switch (type) + { + case ALTDeviceTypeiPhone: + case ALTDeviceTypeiPad: + parameters[@"DTDK_Platform"] = @"ios"; + break; + + case ALTDeviceTypeAppleTV: + parameters[@"DTDK_Platform"] = @"tvos"; + parameters[@"subPlatform"] = @"tvOS"; + break; + + default: break; + } + + [self sendRequestWithURL:URL additionalParameters:parameters session:session team:team completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { if (responseDictionary == nil) { completionHandler(nil, requestError); @@ -221,7 +250,7 @@ - (void)fetchCertificatesForTeam:(ALTTeam *)team session:(ALTAppleAPISession *)s - (void)addCertificateWithMachineName:(NSString *)machineName toTeam:(ALTTeam *)team session:(ALTAppleAPISession *)session completionHandler:(void (^)(ALTCertificate * _Nullable, NSError * _Nullable))completionHandler { - ALTCertificateRequest *request = [[ALTCertificateRequest alloc] init]; + ALTCertificateRequest *request = [ALTCertificateRequest newRequest]; if (request == nil) { NSError *error = [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorInvalidCertificateRequest userInfo:nil]; @@ -342,12 +371,18 @@ - (void)addAppIDWithName:(NSString *)name bundleIdentifier:(NSString *)bundleIde { NSURL *URL = [NSURL URLWithString:@"ios/addAppId.action" relativeToURL:self.baseURL]; - NSMutableCharacterSet *allowedCharacters = [NSMutableCharacterSet alphanumericCharacterSet]; + NSMutableCharacterSet *allowedCharacters = [[NSCharacterSet asciiAlphanumericCharacterSet] mutableCopy]; [allowedCharacters formUnionWithCharacterSet:[NSCharacterSet whitespaceCharacterSet]]; NSString *sanitizedName = [name stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:nil]; sanitizedName = [[sanitizedName componentsSeparatedByCharactersInSet:[allowedCharacters invertedSet]] componentsJoinedByString:@""]; + if (sanitizedName.length == 0) + { + // Fallback in case name had no valid characters. + sanitizedName = @"App"; + } + [self sendRequestWithURL:URL additionalParameters:@{@"identifier": bundleIdentifier, @"name": sanitizedName} session:session team:team completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { if (responseDictionary == nil) { @@ -369,7 +404,7 @@ - (void)addAppIDWithName:(NSString *)name bundleIdentifier:(NSString *)bundleIde switch (resultCode) { case 35: - return [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorInvalidAppIDName userInfo:nil]; + return [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorInvalidAppIDName userInfo:@{ALTAppNameErrorKey: sanitizedName}]; case 9120: return [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorMaximumAppIDLimitReached userInfo:nil]; @@ -583,11 +618,31 @@ - (void)assignAppID:(ALTAppID *)appID toGroups:(NSArray *)groups #pragma mark - Provisioning Profiles - -- (void)fetchProvisioningProfileForAppID:(ALTAppID *)appID team:(ALTTeam *)team session:(ALTAppleAPISession *)session completionHandler:(void (^)(ALTProvisioningProfile * _Nullable, NSError * _Nullable))completionHandler +- (void)fetchProvisioningProfileForAppID:(ALTAppID *)appID deviceType:(ALTDeviceType)deviceType team:(ALTTeam *)team session:(ALTAppleAPISession *)session + completionHandler:(void (^)(ALTProvisioningProfile *_Nullable provisioningProfile, NSError *_Nullable error))completionHandler { NSURL *URL = [NSURL URLWithString:@"ios/downloadTeamProvisioningProfile.action" relativeToURL:self.baseURL]; - [self sendRequestWithURL:URL additionalParameters:@{@"appIdId": appID.identifier} session:session team:team completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { + NSMutableDictionary *parameters = [@{ + @"appIdId": appID.identifier, + } mutableCopy]; + + switch (deviceType) + { + case ALTDeviceTypeiPhone: + case ALTDeviceTypeiPad: + parameters[@"DTDK_Platform"] = @"ios"; + break; + + case ALTDeviceTypeAppleTV: + parameters[@"DTDK_Platform"] = @"tvos"; + parameters[@"subPlatform"] = @"tvOS"; + break; + + default: break; + } + + [self sendRequestWithURL:URL additionalParameters:parameters session:session team:team completionHandler:^(NSDictionary *responseDictionary, NSError *requestError) { if (responseDictionary == nil) { completionHandler(nil, requestError); @@ -858,9 +913,9 @@ - (nullable id)processResponse:(NSDictionary *)responseDictionary NSString *errorDescription = [responseDictionary objectForKey:@"userString"] ?: [responseDictionary objectForKey:@"resultString"]; NSString *localizedDescription = [NSString stringWithFormat:@"%@ (%@)", errorDescription, @(resultCode)]; - NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; - userInfo[NSLocalizedDescriptionKey] = localizedDescription; - tempError = [NSError errorWithDomain:ALTAppleAPIErrorDomain code:ALTAppleAPIErrorUnknown userInfo:userInfo]; + tempError = [NSError errorWithDomain:ALTUnderlyingAppleAPIErrorDomain code:resultCode userInfo:@{ + NSLocalizedDescriptionKey: localizedDescription, + }]; } *error = tempError; diff --git a/AltSign/Apple API/ALTAppleAPI_Private.h b/AltSign/Apple API/ALTAppleAPI_Private.h index 0052d88..5fcccad 100644 --- a/AltSign/Apple API/ALTAppleAPI_Private.h +++ b/AltSign/Apple API/ALTAppleAPI_Private.h @@ -6,7 +6,7 @@ // Copyright © 2019 Riley Testut. All rights reserved. // -#import "ALTAppleAPI.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN additionalParameters:(nullable NSDictionary *)additionalParameters session:(ALTAppleAPISession *)session team:(nullable ALTTeam *)team - completionHandler:(void (^)(NSDictionary *responseDictionary, NSError *error))completionHandler; + completionHandler:(void (^)(NSDictionary *_Nullable responseDictionary, NSError *_Nullable error))completionHandler; - (nullable id)processResponse:(NSDictionary *)responseDictionary parseHandler:(id _Nullable (^_Nullable)(void))parseHandler diff --git a/AltSign/Capabilities/ALTCapabilities.h b/AltSign/Capabilities/ALTCapabilities.h index 76f8296..68d3bb2 100644 --- a/AltSign/Capabilities/ALTCapabilities.h +++ b/AltSign/Capabilities/ALTCapabilities.h @@ -18,12 +18,14 @@ extern ALTEntitlement const ALTEntitlementAppGroups; extern ALTEntitlement const ALTEntitlementGetTaskAllow; extern ALTEntitlement const ALTEntitlementTeamIdentifier; extern ALTEntitlement const ALTEntitlementInterAppAudio; +extern ALTEntitlement const ALTEntitlementHealthKit; // Features typedef NSString *ALTFeature NS_TYPED_EXTENSIBLE_ENUM; extern ALTFeature const ALTFeatureGameCenter; extern ALTFeature const ALTFeatureAppGroups; extern ALTFeature const ALTFeatureInterAppAudio; +extern ALTFeature const ALTFeatureHealthKit; _Nullable ALTEntitlement ALTEntitlementForFeature(ALTFeature feature) NS_SWIFT_NAME(ALTEntitlement.init(feature:)); _Nullable ALTFeature ALTFeatureForEntitlement(ALTEntitlement entitlement) NS_SWIFT_NAME(ALTFeature.init(entitlement:)); diff --git a/AltSign/Capabilities/ALTCapabilities.m b/AltSign/Capabilities/ALTCapabilities.m index 302107a..9595d07 100644 --- a/AltSign/Capabilities/ALTCapabilities.m +++ b/AltSign/Capabilities/ALTCapabilities.m @@ -15,11 +15,13 @@ ALTEntitlement const ALTEntitlementGetTaskAllow = @"get-task-allow"; ALTEntitlement const ALTEntitlementTeamIdentifier = @"com.apple.developer.team-identifier"; ALTEntitlement const ALTEntitlementInterAppAudio = @"inter-app-audio"; +ALTEntitlement const ALTEntitlementHealthKit = @"com.apple.developer.healthkit"; // Features ALTFeature const ALTFeatureGameCenter = @"gameCenter"; ALTFeature const ALTFeatureAppGroups = @"APG3427HIY"; ALTFeature const ALTFeatureInterAppAudio = @"IAD53UNK2F"; +ALTFeature const ALTFeatureHealthKit = @"HK421J6T7P"; _Nullable ALTEntitlement ALTEntitlementForFeature(ALTFeature feature) { @@ -31,6 +33,10 @@ _Nullable ALTEntitlement ALTEntitlementForFeature(ALTFeature feature) { return ALTEntitlementInterAppAudio; } + else if ([feature isEqualToString:ALTFeatureHealthKit]) + { + return ALTEntitlementHealthKit; + } return nil; } @@ -45,6 +51,10 @@ _Nullable ALTFeature ALTFeatureForEntitlement(ALTEntitlement entitlement) { return ALTFeatureInterAppAudio; } + else if ([entitlement isEqualToString:ALTEntitlementHealthKit]) + { + return ALTFeatureHealthKit; + } return nil; } diff --git a/AltSign/Categories/NSCharacterSet+ASCII.h b/AltSign/Categories/NSCharacterSet+ASCII.h new file mode 100644 index 0000000..619b695 --- /dev/null +++ b/AltSign/Categories/NSCharacterSet+ASCII.h @@ -0,0 +1,19 @@ +// +// NSCharacterSet+ASCII.h +// AltSign +// +// Created by Riley Testut on 11/30/23. +// Copyright © 2023 Riley Testut. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSCharacterSet (Ascii) + +@property(readonly, class, copy) NSCharacterSet *asciiAlphanumericCharacterSet; + +@end + +NS_ASSUME_NONNULL_END diff --git a/AltSign/Categories/NSCharacterSet+ASCII.m b/AltSign/Categories/NSCharacterSet+ASCII.m new file mode 100644 index 0000000..7b59dfc --- /dev/null +++ b/AltSign/Categories/NSCharacterSet+ASCII.m @@ -0,0 +1,20 @@ +// +// NSCharacterSet+ASCII.m +// AltSign +// +// Created by Riley Testut on 11/30/23. +// Copyright © 2023 Riley Testut. All rights reserved. +// + +#import "NSCharacterSet+ASCII.h" + +@implementation NSCharacterSet (Ascii) + ++ (NSCharacterSet *)asciiAlphanumericCharacterSet +{ + // alphanumericCharacterSet includes characters from non-English languages, which are not supported by Apple's servers. + NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"]; + return characterSet; +} + +@end diff --git a/AltSign/Categories/NSError+ALTErrors.h b/AltSign/Categories/NSError+ALTErrors.h index 2fcfbaa..1c29367 100644 --- a/AltSign/Categories/NSError+ALTErrors.h +++ b/AltSign/Categories/NSError+ALTErrors.h @@ -9,6 +9,13 @@ #import extern NSErrorDomain const AltSignErrorDomain; +extern NSErrorDomain const ALTAppleAPIErrorDomain; +extern NSErrorDomain const ALTUnderlyingAppleAPIErrorDomain; + +extern NSErrorUserInfoKey const ALTSourceFileErrorKey; +extern NSErrorUserInfoKey const ALTSourceLineErrorKey; +extern NSErrorUserInfoKey const ALTAppNameErrorKey; + typedef NS_ERROR_ENUM(AltSignErrorDomain, ALTError) { ALTErrorUnknown, @@ -18,38 +25,39 @@ typedef NS_ERROR_ENUM(AltSignErrorDomain, ALTError) ALTErrorMissingProvisioningProfile, }; -extern NSErrorDomain const ALTAppleAPIErrorDomain; typedef NS_ERROR_ENUM(ALTAppleAPIErrorDomain, ALTAppleAPIError) { - ALTAppleAPIErrorUnknown, - ALTAppleAPIErrorInvalidParameters, + ALTAppleAPIErrorUnknown = 3000, + ALTAppleAPIErrorInvalidParameters = 3001, + + ALTAppleAPIErrorIncorrectCredentials = 3002, + ALTAppleAPIErrorAppSpecificPasswordRequired = 3003, - ALTAppleAPIErrorIncorrectCredentials, - ALTAppleAPIErrorAppSpecificPasswordRequired, + ALTAppleAPIErrorNoTeams = 3004, - ALTAppleAPIErrorNoTeams, + ALTAppleAPIErrorInvalidDeviceID = 3005, + ALTAppleAPIErrorDeviceAlreadyRegistered = 3006, - ALTAppleAPIErrorInvalidDeviceID, - ALTAppleAPIErrorDeviceAlreadyRegistered, + ALTAppleAPIErrorInvalidCertificateRequest = 3007, + ALTAppleAPIErrorCertificateDoesNotExist = 3008, - ALTAppleAPIErrorInvalidCertificateRequest, - ALTAppleAPIErrorCertificateDoesNotExist, + ALTAppleAPIErrorInvalidAppIDName = 3009, + ALTAppleAPIErrorInvalidBundleIdentifier = 3010, + ALTAppleAPIErrorBundleIdentifierUnavailable = 3011, + ALTAppleAPIErrorAppIDDoesNotExist = 3012, + ALTAppleAPIErrorMaximumAppIDLimitReached = 3013, - ALTAppleAPIErrorInvalidAppIDName, - ALTAppleAPIErrorInvalidBundleIdentifier, - ALTAppleAPIErrorBundleIdentifierUnavailable, - ALTAppleAPIErrorAppIDDoesNotExist, - ALTAppleAPIErrorMaximumAppIDLimitReached, + ALTAppleAPIErrorInvalidAppGroup = 3014, + ALTAppleAPIErrorAppGroupDoesNotExist = 3015, - ALTAppleAPIErrorInvalidAppGroup, - ALTAppleAPIErrorAppGroupDoesNotExist, + ALTAppleAPIErrorInvalidProvisioningProfileIdentifier = 3016, + ALTAppleAPIErrorProvisioningProfileDoesNotExist = 3017, - ALTAppleAPIErrorInvalidProvisioningProfileIdentifier, - ALTAppleAPIErrorProvisioningProfileDoesNotExist, + ALTAppleAPIErrorRequiresTwoFactorAuthentication = 3018, + ALTAppleAPIErrorIncorrectVerificationCode = 3019, + ALTAppleAPIErrorAuthenticationHandshakeFailed = 3020, - ALTAppleAPIErrorRequiresTwoFactorAuthentication, - ALTAppleAPIErrorIncorrectVerificationCode, - ALTAppleAPIErrorAuthenticationHandshakeFailed, + ALTAppleAPIErrorInvalidAnisetteData = 3021, }; NS_ASSUME_NONNULL_BEGIN diff --git a/AltSign/Categories/NSError+ALTErrors.m b/AltSign/Categories/NSError+ALTErrors.m index bf0994d..79b61cf 100644 --- a/AltSign/Categories/NSError+ALTErrors.m +++ b/AltSign/Categories/NSError+ALTErrors.m @@ -8,16 +8,36 @@ #import "NSError+ALTErrors.h" -NSErrorDomain const AltSignErrorDomain = @"com.rileytestut.AltSign"; -NSErrorDomain const ALTAppleAPIErrorDomain = @"com.rileytestut.ALTAppleAPI"; +NSErrorDomain const AltSignErrorDomain = @"AltSign.Error"; +NSErrorDomain const ALTAppleAPIErrorDomain = @"AltStore.AppleDeveloperError"; +NSErrorDomain const ALTUnderlyingAppleAPIErrorDomain = @"Apple.APIError"; + +NSErrorUserInfoKey const ALTSourceFileErrorKey = @"ALTSourceFile"; +NSErrorUserInfoKey const ALTSourceLineErrorKey = @"ALTSourceLine"; +NSErrorUserInfoKey const ALTAppNameErrorKey = @"appName"; @implementation NSError (ALTError) + (void)load { [NSError setUserInfoValueProviderForDomain:AltSignErrorDomain provider:^id _Nullable(NSError * _Nonnull error, NSErrorUserInfoKey _Nonnull userInfoKey) { - if ([userInfoKey isEqualToString:NSLocalizedFailureReasonErrorKey]) + if ([userInfoKey isEqualToString:NSLocalizedDescriptionKey]) { + if ([error altsign_localizedFailure] != nil) + { + // Error has localizedFailure, so return nil to construct localizedDescription from it + localizedFailureReason. + return nil; + } + else + { + // Otherwise, return failureReason for localizedDescription to avoid system prepending "Operation Failed" message. + // Do NOT return [error alt_localizedFailureReason], which might be unexpectedly nil if unrecognized error code. + return error.localizedFailureReason; + } + } + else if ([userInfoKey isEqualToString:NSLocalizedFailureReasonErrorKey]) + { + // Return failureReason for both keys to prevent prepending "Operation Failed" message to localizedDescription. return [error alt_localizedFailureReason]; } @@ -27,13 +47,51 @@ + (void)load [NSError setUserInfoValueProviderForDomain:ALTAppleAPIErrorDomain provider:^id _Nullable(NSError * _Nonnull error, NSErrorUserInfoKey _Nonnull userInfoKey) { if ([userInfoKey isEqualToString:NSLocalizedDescriptionKey]) { - return [error alt_appleapi_localizedDescription]; + if ([error altsign_localizedFailure] != nil) + { + // Error has localizedFailure, so return nil to construct localizedDescription from it + localizedFailureReason. + return nil; + } + else + { + // Otherwise, return failureReason for localizedDescription to avoid system prepending "Operation Failed" message. + // Do NOT return [error alt_appleapi_localizedFailureReason], which might be unexpectedly nil if unrecognized error code. + return error.localizedFailureReason; + } + } + else if ([userInfoKey isEqualToString:NSLocalizedFailureReasonErrorKey]) + { + // Return failureReason for both keys to prevent prepending "Operation Failed" message to localizedDescription. + return [error alt_appleapi_localizedFailureReason]; + } + else if ([userInfoKey isEqualToString:NSLocalizedRecoverySuggestionErrorKey]) + { + return [error alt_appleapi_localizedRecoverySuggestion]; } return nil; }]; } +- (nullable NSString *)altsign_localizedFailure +{ + // Copied logic from AltStore's NSError+AltStore.swift. + NSString *localizedFailure = self.userInfo[NSLocalizedFailureErrorKey]; + if (localizedFailure != nil) + { + return localizedFailure; + } + + id (^provider)(NSError *, NSErrorUserInfoKey) = [NSError userInfoValueProviderForDomain:self.domain]; + if (provider == nil) + { + return nil; + } + + localizedFailure = provider(self, NSLocalizedFailureErrorKey); + return localizedFailure; +} + - (nullable NSString *)alt_localizedFailureReason { switch ((ALTError)self.code) @@ -57,7 +115,7 @@ - (nullable NSString *)alt_localizedFailureReason return nil; } -- (nullable NSString *)alt_appleapi_localizedDescription +- (nullable NSString *)alt_appleapi_localizedFailureReason { switch ((ALTAppleAPIError)self.code) { @@ -68,7 +126,7 @@ - (nullable NSString *)alt_appleapi_localizedDescription return NSLocalizedString(@"The provided parameters are invalid.", @""); case ALTAppleAPIErrorIncorrectCredentials: - return NSLocalizedString(@"Incorrect Apple ID or password.", @""); + return NSLocalizedString(@"Your Apple ID or password is incorrect.", @""); case ALTAppleAPIErrorNoTeams: return NSLocalizedString(@"You are not a member of any development teams.", @""); @@ -89,7 +147,15 @@ - (nullable NSString *)alt_appleapi_localizedDescription return NSLocalizedString(@"There is no certificate with the requested serial number for this team.", @""); case ALTAppleAPIErrorInvalidAppIDName: - return NSLocalizedString(@"The name for this app is invalid.", @""); + { + NSString *appName = self.userInfo[ALTAppNameErrorKey]; + if (appName != nil) + { + return [NSString stringWithFormat:NSLocalizedString(@"The name “%@” contains invalid characters.", @""), appName]; + } + + return NSLocalizedString(@"The name of this app contains invalid characters.", @""); + } case ALTAppleAPIErrorInvalidBundleIdentifier: return NSLocalizedString(@"The bundle identifier for this app is invalid.", @""); @@ -123,6 +189,29 @@ - (nullable NSString *)alt_appleapi_localizedDescription case ALTAppleAPIErrorAuthenticationHandshakeFailed: return NSLocalizedString(@"Failed to perform authentication handshake with server.", @""); + + case ALTAppleAPIErrorInvalidAnisetteData: + return NSLocalizedString(@"The provided anisette data is invalid.", @""); + } + + return nil; +} + +- (nullable NSString *)alt_appleapi_localizedRecoverySuggestion +{ + switch ((ALTAppleAPIError)self.code) + { + case ALTAppleAPIErrorIncorrectCredentials: + return NSLocalizedString(@"Please make sure you entered both your Apple ID and password correctly and try again.", @""); + + case ALTAppleAPIErrorInvalidAnisetteData: +#if TARGET_OS_OSX + return NSLocalizedString(@"Make sure this computer's date & time matches your iOS device and try again.", @""); +#else + return NSLocalizedString(@"Make sure your computer's date & time matches your iOS device and try again. You may need to re-install AltStore with AltServer if the problem persists.", @""); +#endif + + default: break; } return nil; diff --git a/AltSign/Categories/NSFileManager+Apps.h b/AltSign/Categories/NSFileManager+Zip.h similarity index 57% rename from AltSign/Categories/NSFileManager+Apps.h rename to AltSign/Categories/NSFileManager+Zip.h index 488b003..7f25a06 100644 --- a/AltSign/Categories/NSFileManager+Apps.h +++ b/AltSign/Categories/NSFileManager+Zip.h @@ -1,5 +1,5 @@ // -// NSFileManager+Apps.h +// NSFileManager+Zip.h // AltSign // // Created by Riley Testut on 5/28/19. @@ -10,7 +10,10 @@ NS_ASSUME_NONNULL_BEGIN -@interface NSFileManager (Apps) +@interface NSFileManager (Zip) + +- (BOOL)unzipArchiveAtURL:(NSURL *)archiveURL toDirectory:(NSURL *)directoryURL error:(NSError **)error; +- (BOOL)unzipArchiveAtURL:(NSURL *)archiveURL toDirectory:(NSURL *)directoryURL progress:(NSProgress *)progress error:(NSError **)error; - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)directoryURL error:(NSError **)error; - (nullable NSURL *)zipAppBundleAtURL:(NSURL *)appBundleURL error:(NSError **)error; diff --git a/AltSign/Categories/NSFileManager+Apps.m b/AltSign/Categories/NSFileManager+Zip.m similarity index 82% rename from AltSign/Categories/NSFileManager+Apps.m rename to AltSign/Categories/NSFileManager+Zip.m index d2da4cf..c28546a 100644 --- a/AltSign/Categories/NSFileManager+Apps.m +++ b/AltSign/Categories/NSFileManager+Zip.m @@ -1,12 +1,12 @@ // -// NSFileManager+Apps.m +// NSFileManager+Zip.m // AltSign // // Created by Riley Testut on 5/28/19. // Copyright © 2019 Riley Testut. All rights reserved. // -#import "NSFileManager+Apps.h" +#import "NSFileManager+Zip.h" #import "NSError+ALTErrors.h" @@ -20,18 +20,28 @@ #define READ_BUFFER_SIZE 8192 #define MAX_FILENAME 512 -@implementation NSFileManager (Apps) +@implementation NSFileManager (Zip) -- (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)directoryURL error:(NSError **)error +- (BOOL)unzipArchiveAtURL:(NSURL *)archiveURL toDirectory:(NSURL *)directoryURL error:(NSError **)error +{ + NSProgress *progress = [NSProgress progressWithTotalUnitCount:0]; + [progress setKind:NSProgressKindFile]; + [progress setUserInfoObject:NSProgressFileOperationKindDecompressingAfterDownloading forKey:NSProgressFileOperationKindKey]; + + return [self unzipArchiveAtURL:archiveURL toDirectory:directoryURL progress:progress error:error]; +} + +- (BOOL)unzipArchiveAtURL:(NSURL *)archiveURL toDirectory:(NSURL *)directoryURL progress:(NSProgress *)progress error:(NSError **)error { - unzFile zipFile = unzOpen(ipaURL.fileSystemRepresentation); + unzFile zipFile = unzOpen(archiveURL.fileSystemRepresentation); if (zipFile == NULL) { - *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileNoSuchFileError userInfo:@{NSURLErrorKey: ipaURL}]; - return nil; + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileNoSuchFileError userInfo:@{NSURLErrorKey: archiveURL}]; + return NO; } FILE *outputFile = nil; + char buffer[ALTReadBufferSize]; void (^finish)(void) = ^{ if (outputFile != nil) @@ -46,15 +56,55 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir unz_global_info zipInfo; if (unzGetGlobalInfo(zipFile, &zipInfo) != UNZ_OK) { - *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{NSURLErrorKey: ipaURL}]; + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadCorruptFileError userInfo:@{NSURLErrorKey: archiveURL}]; finish(); - return nil; + return NO; } - NSProgress *progress = [NSProgress progressWithTotalUnitCount:zipInfo.number_entry]; + // Calculate total uncompressed size for accurate progress reporting. + int64_t uncompressedSize = 0; - char buffer[ALTReadBufferSize]; + for (int i = 0; i < zipInfo.number_entry; i++) + { + unz_file_info info; + char cFilename[ALTMaxFilenameLength]; + + if (unzGetCurrentFileInfo(zipFile, &info, cFilename, ALTMaxFilenameLength, NULL, 0, NULL, 0) != UNZ_OK) + { + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSURLErrorKey: archiveURL}]; + + finish(); + return NO; + } + + NSString *filename = [[NSString alloc] initWithCString:cFilename encoding:NSUTF8StringEncoding]; + if (![filename hasPrefix:@"__MACOSX"] && [filename characterAtIndex:filename.length - 1] != ALTDirectoryDeliminator) + { + uncompressedSize += info.uncompressed_size; + } + + if (i + 1 < zipInfo.number_entry) + { + if (unzGoToNextFile(zipFile) != UNZ_OK) + { + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSURLErrorKey: archiveURL}]; + + finish(); + return NO; + } + } + } + + if (unzGoToFirstFile(zipFile) != UNZ_OK) + { + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSURLErrorKey: archiveURL}]; + + finish(); + return NO; + } + + progress.totalUnitCount = uncompressedSize; for (int i = 0; i < zipInfo.number_entry; i++) { @@ -63,10 +113,10 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir if (unzGetCurrentFileInfo(zipFile, &info, cFilename, ALTMaxFilenameLength, NULL, 0, NULL, 0) != UNZ_OK) { - *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSURLErrorKey: ipaURL}]; + *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSURLErrorKey: archiveURL}]; finish(); - return nil; + return NO; } NSString *filename = [[NSString alloc] initWithCString:cFilename encoding:NSUTF8StringEncoding]; @@ -79,7 +129,7 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSFilePathErrorKey: filename}]; finish(); - return nil; + return NO; } } @@ -106,18 +156,18 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir if (directoryError != nil) { *error = directoryError; - return nil; + return NO; } } else { - // File + // File if (unzOpenCurrentFile(zipFile) != UNZ_OK) { *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSURLErrorKey: fileURL}]; finish(); - return nil; + return NO; } NSURL *parentDirectory = [fileURL URLByDeletingLastPathComponent]; @@ -127,7 +177,7 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir if (directoryError != nil) { *error = directoryError; - return nil; + return NO; } } @@ -138,7 +188,7 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{NSURLErrorKey: fileURL, NSUnderlyingErrorKey: underlyingError}]; finish(); - return nil; + return NO; } int result = UNZ_OK; @@ -152,7 +202,7 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSURLErrorKey: fileURL}]; finish(); - return nil; + return NO; } size_t count = fwrite(buffer, result, 1, outputFile); @@ -161,16 +211,18 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileWriteUnknownError userInfo:@{NSURLErrorKey: fileURL}]; finish(); - return nil; + return NO; } + progress.completedUnitCount += result; + } while (result > 0); short permissions = (info.external_fa >> 16) & 0x01FF; if (![self setAttributes:@{NSFilePosixPermissions: @(permissions)} ofItemAtPath:fileURL.path error:error]) { finish(); - return nil; + return NO; } fclose(outputFile); @@ -179,8 +231,6 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir unzCloseCurrentFile(zipFile); - progress.completedUnitCount += 1; - if (i + 1 < zipInfo.number_entry) { if (unzGoToNextFile(zipFile) != UNZ_OK) @@ -188,18 +238,27 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{NSURLErrorKey: fileURL}]; finish(); - return nil; + return NO; } } } finish(); + return YES; +} + +- (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)directoryURL error:(NSError **)error +{ + if (![self unzipArchiveAtURL:ipaURL toDirectory:directoryURL error:error]) + { + return nil; + } + NSURL *payloadDirectory = [directoryURL URLByAppendingPathComponent:@"Payload"]; NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:payloadDirectory.path error:error]; if (contents == nil) { - finish(); return nil; } @@ -212,7 +271,6 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir if (![[NSFileManager defaultManager] moveItemAtURL:appBundleURL toURL:outputURL error:error]) { - finish(); return nil; } @@ -221,7 +279,6 @@ - (nullable NSURL *)unzipAppBundleAtURL:(NSURL *)ipaURL toDirectory:(NSURL *)dir { *error = deleteError; - finish(); return nil; } diff --git a/AltSign/Info.plist b/AltSign/Info.plist deleted file mode 100644 index e1fe4cf..0000000 --- a/AltSign/Info.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleVersion - $(CURRENT_PROJECT_VERSION) - - diff --git a/AltSign/Model/ALTApplication.h b/AltSign/Model/ALTApplication.h index a28b010..773cda2 100644 --- a/AltSign/Model/ALTApplication.h +++ b/AltSign/Model/ALTApplication.h @@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *name; @property (nonatomic, copy, readonly) NSString *bundleIdentifier; @property (nonatomic, copy, readonly) NSString *version; +@property (nonatomic, copy, readonly) NSString *buildVersion; #if TARGET_OS_IPHONE @property (nonatomic, readonly, nullable) UIImage *icon; @@ -39,6 +40,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSString *entitlementsString; @property (nonatomic, copy, readonly) NSURL *fileURL; +@property (nonatomic, readonly) NSBundle *bundle; + +@property (nonatomic, assign) BOOL hasPrivateEntitlements; - (nullable instancetype)initWithFileURL:(NSURL *)fileURL; diff --git a/AltSign/Model/ALTApplication.mm b/AltSign/Model/ALTApplication.mm index 2c98e67..2865312 100644 --- a/AltSign/Model/ALTApplication.mm +++ b/AltSign/Model/ALTApplication.mm @@ -61,9 +61,11 @@ - (instancetype)initWithFileURL:(NSURL *)fileURL return nil; } + // These technically can be nil, but in practice every app should have a version and build version. NSString *version = infoDictionary[@"CFBundleShortVersionString"] ?: @"1.0"; - NSString *minimumVersionString = infoDictionary[@"MinimumOSVersion"] ?: @"1.0"; + NSString *buildVersion = infoDictionary[(NSString *)kCFBundleVersionKey] ?: @"1"; + NSString *minimumVersionString = infoDictionary[@"MinimumOSVersion"] ?: @"1.0"; NSArray *versionComponents = [minimumVersionString componentsSeparatedByString:@"."]; NSInteger majorVersion = [versionComponents.firstObject integerValue]; @@ -118,12 +120,14 @@ - (instancetype)initWithFileURL:(NSURL *)fileURL { iconName = infoDictionary[@"CFBundleIconFile"]; } - } + } + _bundle = bundle; _fileURL = [fileURL copy]; _name = [name copy]; _bundleIdentifier = [bundleIdentifier copy]; _version = [version copy]; + _buildVersion = [buildVersion copy]; _minimumiOSVersion = minimumVersion; _supportedDeviceTypes = supportedDeviceTypes; _iconName = [iconName copy]; @@ -135,19 +139,13 @@ - (instancetype)initWithFileURL:(NSURL *)fileURL #if TARGET_OS_IPHONE - (UIImage *)icon { - NSBundle *bundle = [NSBundle bundleWithURL:self.fileURL]; - if (bundle == nil) - { - return nil; - } - NSString *iconName = self.iconName; if (iconName == nil) { return nil; } - UIImage *icon = [UIImage imageNamed:iconName inBundle:bundle compatibleWithTraitCollection:nil]; + UIImage *icon = [UIImage imageNamed:iconName inBundle:self.bundle compatibleWithTraitCollection:nil]; return icon; } #endif @@ -185,7 +183,9 @@ - (NSString *)entitlementsString { if (_entitlementsString == nil) { - std::string rawEntitlements = ldid::Entitlements(self.fileURL.fileSystemRepresentation); + NSString *path = [self.fileURL.path.stringByStandardizingPath stringByAppendingString:@"/"]; + + std::string rawEntitlements = ldid::Entitlements(path.fileSystemRepresentation); _entitlementsString = @(rawEntitlements.c_str()); } @@ -205,11 +205,9 @@ - (ALTProvisioningProfile *)provisioningProfile - (NSSet *)appExtensions { - NSBundle *bundle = [NSBundle bundleWithURL:self.fileURL]; - NSMutableSet *appExtensions = [NSMutableSet set]; - NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:bundle.builtInPlugInsURL includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsSubdirectoryDescendants errorHandler:nil]; + NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:self.bundle.builtInPlugInsURL includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsSubdirectoryDescendants errorHandler:nil]; for (NSURL *fileURL in enumerator) { if (![fileURL.pathExtension.lowercaseString isEqualToString:@"appex"]) diff --git a/AltSign/Model/Apple API/ALTCertificate.m b/AltSign/Model/Apple API/ALTCertificate.m index 89a97b5..5ccc377 100644 --- a/AltSign/Model/Apple API/ALTCertificate.m +++ b/AltSign/Model/Apple API/ALTCertificate.m @@ -47,7 +47,16 @@ - (instancetype)initWithResponseDictionary:(NSDictionary *)responseDictionary } NSString *machineName = attributesDictionary[@"machineName"]; + if ([machineName isKindOfClass:[NSNull class]]) + { + machineName = nil; + } + NSString *machineIdentifier = attributesDictionary[@"machineId"]; + if ([machineIdentifier isKindOfClass:[NSNull class]]) + { + machineIdentifier = nil; + } if (data != nil) { @@ -176,7 +185,7 @@ - (nullable instancetype)initWithData:(NSData *)data X509_NAME_ENTRY *nameEntry = X509_NAME_get_entry(subject, index); ASN1_STRING *nameData = X509_NAME_ENTRY_get_data(nameEntry); - unsigned char *cName = ASN1_STRING_data(nameData); + const unsigned char *cName = ASN1_STRING_get0_data(nameData); /* Serial Number */ diff --git a/AltSign/Model/Apple API/ALTCertificateRequest.h b/AltSign/Model/Apple API/ALTCertificateRequest.h index 16cc43d..ce67703 100644 --- a/AltSign/Model/Apple API/ALTCertificateRequest.h +++ b/AltSign/Model/Apple API/ALTCertificateRequest.h @@ -15,7 +15,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, readonly) NSData *data; @property (nonatomic, copy, readonly) NSData *privateKey; -- (nullable instancetype)init; +// Can't mark init nullable without warnings, so use factory method instead. ++ (nullable instancetype)newRequest NS_SWIFT_NAME(ALTCertificateRequest.makeRequest()); + +- (instancetype)init NS_UNAVAILABLE; @end diff --git a/AltSign/Model/Apple API/ALTCertificateRequest.m b/AltSign/Model/Apple API/ALTCertificateRequest.m index 9d5bf10..6aed9a8 100644 --- a/AltSign/Model/Apple API/ALTCertificateRequest.m +++ b/AltSign/Model/Apple API/ALTCertificateRequest.m @@ -12,20 +12,26 @@ @implementation ALTCertificateRequest -- (instancetype)init ++ (nullable instancetype)newRequest +{ + NSData *data = nil; + NSData *privateKey = nil; + [ALTCertificateRequest generateRequest:&data privateKey:&privateKey]; + + if (data == nil || privateKey == nil) + { + return nil; + } + + ALTCertificateRequest *request = [[ALTCertificateRequest alloc] initWithData:data privateKey:privateKey]; + return request; +} + +- (instancetype)initWithData:(NSData *)data privateKey:(NSData *)privateKey { self = [super init]; if (self) { - NSData *data = nil; - NSData *privateKey = nil; - [self generateRequest:&data privateKey:&privateKey]; - - if (data == nil || privateKey == nil) - { - return nil; - } - _data = [data copy]; _privateKey = [privateKey copy]; } @@ -34,7 +40,7 @@ - (instancetype)init } // Based on https://www.codepool.biz/how-to-use-openssl-to-generate-x-509-certificate-request.html -- (void)generateRequest:(NSData **)outputRequest privateKey:(NSData **)outputPrivateKey ++ (void)generateRequest:(NSData **)outputRequest privateKey:(NSData **)outputPrivateKey { BIGNUM *bignum = NULL; __block RSA *rsa = NULL; diff --git a/AltSign/Model/Apple API/ALTDevice.h b/AltSign/Model/Apple API/ALTDevice.h index e06db85..477c5ee 100644 --- a/AltSign/Model/Apple API/ALTDevice.h +++ b/AltSign/Model/Apple API/ALTDevice.h @@ -8,6 +8,11 @@ #import +// NS_SWIFT_NAME can only prefix types with types from same module. +// Re-declare NSOperatingSystemVersion as _NSOperatingSystemVersion, +// which will still map to OperatingSystemVersion in Swift. +typedef NSOperatingSystemVersion _NSOperatingSystemVersion; + typedef NS_OPTIONS(NSInteger, ALTDeviceType) { ALTDeviceTypeiPhone NS_SWIFT_NAME(iphone) = 1 << 1, @@ -18,6 +23,26 @@ typedef NS_OPTIONS(NSInteger, ALTDeviceType) ALTDeviceTypeAll = (ALTDeviceTypeiPhone | ALTDeviceTypeiPad | ALTDeviceTypeAppleTV), }; +#ifdef __cplusplus +extern "C" { +#endif + +NS_SWIFT_NAME(_NSOperatingSystemVersion.unknown) +extern const NSOperatingSystemVersion NSOperatingSystemVersionUnknown; + +NS_SWIFT_NAME(_NSOperatingSystemVersion.init(string:)) +extern NSOperatingSystemVersion NSOperatingSystemVersionFromString(NSString *_Nonnull osVersionString); + +NS_SWIFT_NAME(getter:_NSOperatingSystemVersion.stringValue(self:)) +extern NSString *_Nonnull NSStringFromOperatingSystemVersion(NSOperatingSystemVersion osVersion); + +NS_SWIFT_NAME(getter:ALTDeviceType.osName(self:)) +extern NSString *_Nullable ALTOperatingSystemNameForDeviceType(ALTDeviceType deviceType); + +#ifdef __cplusplus +} +#endif + NS_ASSUME_NONNULL_BEGIN @interface ALTDevice : NSObject @@ -25,6 +50,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy) NSString *name; @property (nonatomic, copy) NSString *identifier; @property (nonatomic) ALTDeviceType type; +@property (nonatomic) NSOperatingSystemVersion osVersion; - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithName:(NSString *)name identifier:(NSString *)identifier type:(ALTDeviceType)type NS_DESIGNATED_INITIALIZER; diff --git a/AltSign/Model/Apple API/ALTDevice.m b/AltSign/Model/Apple API/ALTDevice.m index bea36cd..e78d2bb 100644 --- a/AltSign/Model/Apple API/ALTDevice.m +++ b/AltSign/Model/Apple API/ALTDevice.m @@ -8,6 +8,60 @@ #import "ALTDevice.h" +#ifdef __cplusplus +extern "C" { +#endif + +NSOperatingSystemVersion const NSOperatingSystemVersionUnknown = (NSOperatingSystemVersion){0, 0, 0}; + +NSOperatingSystemVersion NSOperatingSystemVersionFromString(NSString *osVersionString) +{ + NSArray *versionComponents = [osVersionString componentsSeparatedByString:@"."]; + + NSInteger majorVersion = [versionComponents.firstObject integerValue]; + NSInteger minorVersion = (versionComponents.count > 1) ? [versionComponents[1] integerValue] : 0; + NSInteger patchVersion = (versionComponents.count > 2) ? [versionComponents[2] integerValue] : 0; + + NSOperatingSystemVersion osVersion; + osVersion.majorVersion = majorVersion; + osVersion.minorVersion = minorVersion; + osVersion.patchVersion = patchVersion; + return osVersion; +} + +NSString *_Nonnull NSStringFromOperatingSystemVersion(NSOperatingSystemVersion osVersion) +{ + NSString *stringValue = [NSString stringWithFormat:@"%@.%@", @(osVersion.majorVersion), @(osVersion.minorVersion)]; + if (osVersion.patchVersion != 0) + { + stringValue = [NSString stringWithFormat:@"%@.%@", stringValue, @(osVersion.patchVersion)]; + } + + return stringValue; +} + +NSString *_Nullable ALTOperatingSystemNameForDeviceType(ALTDeviceType deviceType) +{ + switch (deviceType) + { + case ALTDeviceTypeiPhone: + case ALTDeviceTypeiPad: + return @"iOS"; + + case ALTDeviceTypeAppleTV: + return @"tvOS"; + + case ALTDeviceTypeNone: + case ALTDeviceTypeAll: + default: + return nil; + } +} + +#ifdef __cplusplus +} +#endif + @implementation ALTDevice - (instancetype)initWithName:(NSString *)name identifier:(NSString *)identifier type:(ALTDeviceType)type @@ -82,6 +136,7 @@ - (NSUInteger)hash - (nonnull id)copyWithZone:(nullable NSZone *)zone { ALTDevice *device = [[ALTDevice alloc] initWithName:self.name identifier:self.identifier type:self.type]; + device.osVersion = self.osVersion; return device; } diff --git a/AltSign/Model/Apple API/ALTModel+Internal.h b/AltSign/Model/Apple API/ALTModel+Internal.h index f58928c..1f6dbe7 100644 --- a/AltSign/Model/Apple API/ALTModel+Internal.h +++ b/AltSign/Model/Apple API/ALTModel+Internal.h @@ -6,14 +6,14 @@ // Copyright © 2019 Riley Testut. All rights reserved. // -#import "ALTAccount.h" -#import "ALTTeam.h" -#import "ALTDevice.h" -#import "ALTCertificate.h" -#import "ALTCertificateRequest.h" -#import "ALTAppID.h" -#import "ALTAppGroup.h" -#import "ALTProvisioningProfile.h" +#import +#import +#import +#import +#import +#import +#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/AltSign/Model/Apple API/ALTProvisioningProfile.h b/AltSign/Model/Apple API/ALTProvisioningProfile.h index 01a6004..696e55b 100644 --- a/AltSign/Model/Apple API/ALTProvisioningProfile.h +++ b/AltSign/Model/Apple API/ALTProvisioningProfile.h @@ -22,7 +22,9 @@ NS_ASSUME_NONNULL_BEGIN @property (copy, nonatomic, readonly) NSUUID *UUID; @property (copy, nonatomic, readonly) NSString *bundleIdentifier; + @property (copy, nonatomic, readonly) NSString *teamIdentifier; +@property (copy, nonatomic, readonly) NSString *teamName; @property (copy, nonatomic, readonly) NSDate *creationDate; @property (copy, nonatomic, readonly) NSDate *expirationDate; @@ -36,7 +38,9 @@ NS_ASSUME_NONNULL_BEGIN @property (copy, nonatomic, readonly) NSData *data; - (nullable instancetype)initWithData:(NSData *)data NS_DESIGNATED_INITIALIZER; + - (nullable instancetype)initWithURL:(NSURL *)fileURL; +- (nullable instancetype)initWithURL:(NSURL *)fileURL options:(NSDataReadingOptions)options error:(NSError *_Nullable *)error; - (instancetype)init NS_UNAVAILABLE; diff --git a/AltSign/Model/Apple API/ALTProvisioningProfile.m b/AltSign/Model/Apple API/ALTProvisioningProfile.m index 1db7a03..8fa9a59 100644 --- a/AltSign/Model/Apple API/ALTProvisioningProfile.m +++ b/AltSign/Model/Apple API/ALTProvisioningProfile.m @@ -44,7 +44,20 @@ - (nullable instancetype)initWithResponseDictionary:(NSDictionary *)responseDict - (nullable instancetype)initWithURL:(NSURL *)fileURL { - NSData *data = [NSData dataWithContentsOfURL:fileURL]; + NSError *error = nil; + self = [self initWithURL:fileURL options:0 error:&error]; + + if (self == nil) + { + NSLog(@"Error loading provisioning profile from disk: %@", error); + } + + return self; +} + +- (nullable instancetype)initWithURL:(NSURL *)fileURL options:(NSDataReadingOptions)options error:(NSError **)error +{ + NSData *data = [NSData dataWithContentsOfURL:fileURL options:options error:error]; if (data == nil) { return nil; @@ -69,6 +82,7 @@ - (nullable instancetype)initWithData:(NSData *)data NSUUID *UUID = [[NSUUID alloc] initWithUUIDString:dictionary[@"UUID"]]; NSString *teamIdentifier = [dictionary[@"TeamIdentifier"] firstObject]; + NSString *teamName = dictionary[@"TeamName"]; NSDate *creationDate = dictionary[@"CreationDate"]; NSDate *expirationDate = dictionary[@"ExpirationDate"]; @@ -76,7 +90,7 @@ - (nullable instancetype)initWithData:(NSData *)data NSDictionary *entitlements = dictionary[@"Entitlements"]; NSArray *deviceIDs = dictionary[@"ProvisionedDevices"]; - if (name == nil || UUID == nil || teamIdentifier == nil || creationDate == nil || expirationDate == nil || entitlements == nil || deviceIDs == nil) + if (name == nil || UUID == nil || teamIdentifier == nil || teamName == nil || creationDate == nil || expirationDate == nil || entitlements == nil || deviceIDs == nil) { return nil; } @@ -89,6 +103,7 @@ - (nullable instancetype)initWithData:(NSData *)data _UUID = [UUID copy]; _teamIdentifier = [teamIdentifier copy]; + _teamName = [teamName copy]; _creationDate = [creationDate copy]; _expirationDate = [expirationDate copy]; @@ -218,25 +233,25 @@ - (id)copyWithZone:(NSZone *)zone /* Start parsing */ unsigned char *pointer = (unsigned char *)encodedData.bytes; - if (*pointer != ASN1_SEQUENCE) + if (!pointer || *pointer != ASN1_SEQUENCE) { return nil; } pointer = advanceToNextItem(pointer); - if (*pointer != ASN1_OBJECT_IDENTIFIER) + if (!pointer || *pointer != ASN1_OBJECT_IDENTIFIER) { return nil; } pointer = skipNextItem(pointer); - if (*pointer != ASN1_CONTAINER) + if (!pointer || *pointer != ASN1_CONTAINER) { return nil; } pointer = advanceToNextItem(pointer); - if (*pointer != ASN1_SEQUENCE) + if (!pointer || *pointer != ASN1_SEQUENCE) { return nil; } @@ -249,25 +264,25 @@ - (id)copyWithZone:(NSZone *)zone pointer = skipNextItem(pointer); } - if (*pointer != ASN1_SEQUENCE) + if (!pointer || *pointer != ASN1_SEQUENCE) { return nil; } pointer = advanceToNextItem(pointer); - if (*pointer != ASN1_OBJECT_IDENTIFIER) + if (!pointer || *pointer != ASN1_OBJECT_IDENTIFIER) { return nil; } pointer = skipNextItem(pointer); - if (*pointer != ASN1_CONTAINER) + if (!pointer || *pointer != ASN1_CONTAINER) { return nil; } pointer = advanceToNextItem(pointer); - if (*pointer != ASN1_OCTET_STRING) + if (!pointer || *pointer != ASN1_OCTET_STRING) { return nil; } diff --git a/AltSign/Resources/apple.pem b/AltSign/Resources/apple.pem deleted file mode 100644 index 681ea31..0000000 --- a/AltSign/Resources/apple.pem +++ /dev/null @@ -1,53 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIEuzCCA6OgAwIBAgIBAjANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQGEwJVUzET -MBEGA1UEChMKQXBwbGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlv -biBBdXRob3JpdHkxFjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwHhcNMDYwNDI1MjE0 -MDM2WhcNMzUwMjA5MjE0MDM2WjBiMQswCQYDVQQGEwJVUzETMBEGA1UEChMKQXBw -bGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkx -FjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw -ggEKAoIBAQDkkakJH5HbHkdQ6wXtXnmELes2oldMVeyLGYne+Uts9QerIjAC6Bg+ -+FAJ039BqJj50cpmnCRrEdCju+QbKsMflZ56DKRHi1vUFjczy8QPTc4UadHJGXL1 -XQ7Vf1+b8iUDulWPTV0N8WQ1IxVLFVkds5T39pyez1C6wVhQZ48ItCD3y6wsIG9w -tj8BMIy3Q88PnT3zK0koGsj+zrW5DtleHNbLPbU6rfQPDgCSC7EhFi501TwN22IW -q6NxkkdTVcGvL0Gz+PvjcM3mo0xFfh9Ma1CWQYnEdGILEINBhzOKgbEwWOxaBDKM -aLOPHd5lc/9nXmW8Sdh2nzMUZaF3lMktAgMBAAGjggF6MIIBdjAOBgNVHQ8BAf8E -BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUK9BpR5R2Cf70a40uQKb3 -R01/CF4wHwYDVR0jBBgwFoAUK9BpR5R2Cf70a40uQKb3R01/CF4wggERBgNVHSAE -ggEIMIIBBDCCAQAGCSqGSIb3Y2QFATCB8jAqBggrBgEFBQcCARYeaHR0cHM6Ly93 -d3cuYXBwbGUuY29tL2FwcGxlY2EvMIHDBggrBgEFBQcCAjCBthqBs1JlbGlhbmNl -IG9uIHRoaXMgY2VydGlmaWNhdGUgYnkgYW55IHBhcnR5IGFzc3VtZXMgYWNjZXB0 -YW5jZSBvZiB0aGUgdGhlbiBhcHBsaWNhYmxlIHN0YW5kYXJkIHRlcm1zIGFuZCBj -b25kaXRpb25zIG9mIHVzZSwgY2VydGlmaWNhdGUgcG9saWN5IGFuZCBjZXJ0aWZp -Y2F0aW9uIHByYWN0aWNlIHN0YXRlbWVudHMuMA0GCSqGSIb3DQEBBQUAA4IBAQBc -NplMLXi37Yyb3PN3m/J20ncwT8EfhYOFG5k9RzfyqZtAjizUsZAS2L70c5vu0mQP -y3lPNNiiPvl4/2vIB+x9OYOLUyDTOMSxv5pPCmv/K/xZpwUJfBdAVhEedNO3iyM7 -R6PVbyTi69G3cN8PReEnyvFteO3ntRcXqNx+IjXKJdXZD9Zr1KIkIxH3oayPc4Fg -xhtbCS+SsvhESPBgOJ4V9T0mZyCKM2r3DYLP3uujL/lTaltkwGMzd/c6ByxW69oP -IQ7aunMZT7XZNn/Bh1XZp5m5MkL72NVxnn6hUrcbvZNCJBIqxw8dtk2cXmPIS4AX -UKqK1drk/NAJBzewdXUh ------END CERTIFICATE----- ------BEGIN CERTIFICATE----- -MIIEIjCCAwqgAwIBAgIIAd68xDltoBAwDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UE -BhMCVVMxEzARBgNVBAoTCkFwcGxlIEluYy4xJjAkBgNVBAsTHUFwcGxlIENlcnRp -ZmljYXRpb24gQXV0aG9yaXR5MRYwFAYDVQQDEw1BcHBsZSBSb290IENBMB4XDTEz -MDIwNzIxNDg0N1oXDTIzMDIwNzIxNDg0N1owgZYxCzAJBgNVBAYTAlVTMRMwEQYD -VQQKDApBcHBsZSBJbmMuMSwwKgYDVQQLDCNBcHBsZSBXb3JsZHdpZGUgRGV2ZWxv -cGVyIFJlbGF0aW9uczFEMEIGA1UEAww7QXBwbGUgV29ybGR3aWRlIERldmVsb3Bl -ciBSZWxhdGlvbnMgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEiMA0GCSqGSIb3 -DQEBAQUAA4IBDwAwggEKAoIBAQDKOFSmy1aqyCQ5SOmM7uxfuH8mkbw0U3rOfGOA -YXdkXqUHI7Y5/lAtFVZYcC1+xG7BSoU+L/DehBqhV8mvexj/avoVEkkVCBmsqtsq -Mu2WY2hSFT2Miuy/axiV4AOsAX2XBWfODoWVN2rtCbauZ81RZJ/GXNG8V25nNYB2 -NqSHgW44j9grFU57Jdhav06DwY3Sk9UacbVgnJ0zTlX5ElgMhrgWDcHld0WNUEi6 -Ky3klIXh6MSdxmilsKP8Z35wugJZS3dCkTm59c3hTO/AO0iMpuUhXf1qarunFjVg -0uat80YpyejDi+l5wGphZxWy8P3laLxiX27Pmd3vG2P+kmWrAgMBAAGjgaYwgaMw -HQYDVR0OBBYEFIgnFwmpthhgi+zruvZHWcVSVKO3MA8GA1UdEwEB/wQFMAMBAf8w -HwYDVR0jBBgwFoAUK9BpR5R2Cf70a40uQKb3R01/CF4wLgYDVR0fBCcwJTAjoCGg -H4YdaHR0cDovL2NybC5hcHBsZS5jb20vcm9vdC5jcmwwDgYDVR0PAQH/BAQDAgGG -MBAGCiqGSIb3Y2QGAgEEAgUAMA0GCSqGSIb3DQEBBQUAA4IBAQBPz+9Zviz1smwv -j+4ThzLoBTWobot9yWkMudkXvHcs1Gfi/ZptOllc34MBvbKuKmFysa/Nw0Uwj6OD -Dc4dR7Txk4qjdJukw5hyhzs+r0ULklS5MruQGFNrCk4QttkdUGwhgAqJTleMa1s8 -Pab93vcNIx0LSiaHP7qRkkykGRIZbVf1eliHe2iK5IaMSuviSRSqpd1VAKmuu0sw -ruGgsbwpgOYJd+W+NKIByn/c4grmO7i77LpilfMFY0GCzQ87HUyVpNur+cmV6U/k -TecmmYHpvPm0KdIBembhLoz2IYrF+Hjhga6/05Cdqa3zr/04GpZnMBxRpVzscYqC -tGwPDBUf ------END CERTIFICATE----- diff --git a/AltSign/Signing/ALTSigner.mm b/AltSign/Signing/ALTSigner.mm index 5d99d6b..b1a18ed 100644 --- a/AltSign/Signing/ALTSigner.mm +++ b/AltSign/Signing/ALTSigner.mm @@ -13,20 +13,103 @@ #import "ALTProvisioningProfile.h" #import "ALTApplication.h" -#import "NSFileManager+Apps.h" +#import "NSFileManager+Zip.h" #import "NSError+ALTErrors.h" -#include "ldid.hpp" +#import "alt_ldid.hpp" #include #include #include +const char *AppleRootCertificateData = "" +"-----BEGIN CERTIFICATE-----\n" +"MIIEuzCCA6OgAwIBAgIBAjANBgkqhkiG9w0BAQUFADBiMQswCQYDVQQGEwJVUzET\n" +"MBEGA1UEChMKQXBwbGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlv\n" +"biBBdXRob3JpdHkxFjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwHhcNMDYwNDI1MjE0\n" +"MDM2WhcNMzUwMjA5MjE0MDM2WjBiMQswCQYDVQQGEwJVUzETMBEGA1UEChMKQXBw\n" +"bGUgSW5jLjEmMCQGA1UECxMdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkx\n" +"FjAUBgNVBAMTDUFwcGxlIFJvb3QgQ0EwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw\n" +"ggEKAoIBAQDkkakJH5HbHkdQ6wXtXnmELes2oldMVeyLGYne+Uts9QerIjAC6Bg+\n" +"+FAJ039BqJj50cpmnCRrEdCju+QbKsMflZ56DKRHi1vUFjczy8QPTc4UadHJGXL1\n" +"XQ7Vf1+b8iUDulWPTV0N8WQ1IxVLFVkds5T39pyez1C6wVhQZ48ItCD3y6wsIG9w\n" +"tj8BMIy3Q88PnT3zK0koGsj+zrW5DtleHNbLPbU6rfQPDgCSC7EhFi501TwN22IW\n" +"q6NxkkdTVcGvL0Gz+PvjcM3mo0xFfh9Ma1CWQYnEdGILEINBhzOKgbEwWOxaBDKM\n" +"aLOPHd5lc/9nXmW8Sdh2nzMUZaF3lMktAgMBAAGjggF6MIIBdjAOBgNVHQ8BAf8E\n" +"BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUK9BpR5R2Cf70a40uQKb3\n" +"R01/CF4wHwYDVR0jBBgwFoAUK9BpR5R2Cf70a40uQKb3R01/CF4wggERBgNVHSAE\n" +"ggEIMIIBBDCCAQAGCSqGSIb3Y2QFATCB8jAqBggrBgEFBQcCARYeaHR0cHM6Ly93\n" +"d3cuYXBwbGUuY29tL2FwcGxlY2EvMIHDBggrBgEFBQcCAjCBthqBs1JlbGlhbmNl\n" +"IG9uIHRoaXMgY2VydGlmaWNhdGUgYnkgYW55IHBhcnR5IGFzc3VtZXMgYWNjZXB0\n" +"YW5jZSBvZiB0aGUgdGhlbiBhcHBsaWNhYmxlIHN0YW5kYXJkIHRlcm1zIGFuZCBj\n" +"b25kaXRpb25zIG9mIHVzZSwgY2VydGlmaWNhdGUgcG9saWN5IGFuZCBjZXJ0aWZp\n" +"Y2F0aW9uIHByYWN0aWNlIHN0YXRlbWVudHMuMA0GCSqGSIb3DQEBBQUAA4IBAQBc\n" +"NplMLXi37Yyb3PN3m/J20ncwT8EfhYOFG5k9RzfyqZtAjizUsZAS2L70c5vu0mQP\n" +"y3lPNNiiPvl4/2vIB+x9OYOLUyDTOMSxv5pPCmv/K/xZpwUJfBdAVhEedNO3iyM7\n" +"R6PVbyTi69G3cN8PReEnyvFteO3ntRcXqNx+IjXKJdXZD9Zr1KIkIxH3oayPc4Fg\n" +"xhtbCS+SsvhESPBgOJ4V9T0mZyCKM2r3DYLP3uujL/lTaltkwGMzd/c6ByxW69oP\n" +"IQ7aunMZT7XZNn/Bh1XZp5m5MkL72NVxnn6hUrcbvZNCJBIqxw8dtk2cXmPIS4AX\n" +"UKqK1drk/NAJBzewdXUh\n" +"-----END CERTIFICATE-----\n"; + +const char *AppleWWDRCertificateData = "" +"-----BEGIN CERTIFICATE-----\n" +"MIIEUTCCAzmgAwIBAgIQfK9pCiW3Of57m0R6wXjF7jANBgkqhkiG9w0BAQsFADBi\n" +"MQswCQYDVQQGEwJVUzETMBEGA1UEChMKQXBwbGUgSW5jLjEmMCQGA1UECxMdQXBw\n" +"bGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxFjAUBgNVBAMTDUFwcGxlIFJvb3Qg\n" +"Q0EwHhcNMjAwMjE5MTgxMzQ3WhcNMzAwMjIwMDAwMDAwWjB1MUQwQgYDVQQDDDtB\n" +"cHBsZSBXb3JsZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9ucyBDZXJ0aWZpY2F0aW9u\n" +"IEF1dGhvcml0eTELMAkGA1UECwwCRzMxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJ\n" +"BgNVBAYTAlVTMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2PWJ/KhZ\n" +"C4fHTJEuLVaQ03gdpDDppUjvC0O/LYT7JF1FG+XrWTYSXFRknmxiLbTGl8rMPPbW\n" +"BpH85QKmHGq0edVny6zpPwcR4YS8Rx1mjjmi6LRJ7TrS4RBgeo6TjMrA2gzAg9Dj\n" +"+ZHWp4zIwXPirkbRYp2SqJBgN31ols2N4Pyb+ni743uvLRfdW/6AWSN1F7gSwe0b\n" +"5TTO/iK1nkmw5VW/j4SiPKi6xYaVFuQAyZ8D0MyzOhZ71gVcnetHrg21LYwOaU1A\n" +"0EtMOwSejSGxrC5DVDDOwYqGlJhL32oNP/77HK6XF8J4CjDgXx9UO0m3JQAaN4LS\n" +"VpelUkl8YDib7wIDAQABo4HvMIHsMBIGA1UdEwEB/wQIMAYBAf8CAQAwHwYDVR0j\n" +"BBgwFoAUK9BpR5R2Cf70a40uQKb3R01/CF4wRAYIKwYBBQUHAQEEODA2MDQGCCsG\n" +"AQUFBzABhihodHRwOi8vb2NzcC5hcHBsZS5jb20vb2NzcDAzLWFwcGxlcm9vdGNh\n" +"MC4GA1UdHwQnMCUwI6AhoB+GHWh0dHA6Ly9jcmwuYXBwbGUuY29tL3Jvb3QuY3Js\n" +"MB0GA1UdDgQWBBQJ/sAVkPmvZAqSErkmKGMMl+ynsjAOBgNVHQ8BAf8EBAMCAQYw\n" +"EAYKKoZIhvdjZAYCAQQCBQAwDQYJKoZIhvcNAQELBQADggEBAK1lE+j24IF3RAJH\n" +"Qr5fpTkg6mKp/cWQyXMT1Z6b0KoPjY3L7QHPbChAW8dVJEH4/M/BtSPp3Ozxb8qA\n" +"HXfCxGFJJWevD8o5Ja3T43rMMygNDi6hV0Bz+uZcrgZRKe3jhQxPYdwyFot30ETK\n" +"XXIDMUacrptAGvr04NM++i+MZp+XxFRZ79JI9AeZSWBZGcfdlNHAwWx/eCHvDOs7\n" +"bJmCS1JgOLU5gm3sUjFTvg+RTElJdI+mUcuER04ddSduvfnSXPN/wmwLCTbiZOTC\n" +"NwMUGdXqapSqqdv+9poIZ4vvK7iqF0mDr8/LvOnP6pVxsLRFoszlh6oKw0E6eVza\n" +"UDSdlTs=\n" +"-----END CERTIFICATE-----\n"; + +const char *LegacyAppleWWDRCertificateData = "" +"-----BEGIN CERTIFICATE-----\n" +"MIIEIjCCAwqgAwIBAgIIAd68xDltoBAwDQYJKoZIhvcNAQEFBQAwYjELMAkGA1UE\n" +"BhMCVVMxEzARBgNVBAoTCkFwcGxlIEluYy4xJjAkBgNVBAsTHUFwcGxlIENlcnRp\n" +"ZmljYXRpb24gQXV0aG9yaXR5MRYwFAYDVQQDEw1BcHBsZSBSb290IENBMB4XDTEz\n" +"MDIwNzIxNDg0N1oXDTIzMDIwNzIxNDg0N1owgZYxCzAJBgNVBAYTAlVTMRMwEQYD\n" +"VQQKDApBcHBsZSBJbmMuMSwwKgYDVQQLDCNBcHBsZSBXb3JsZHdpZGUgRGV2ZWxv\n" +"cGVyIFJlbGF0aW9uczFEMEIGA1UEAww7QXBwbGUgV29ybGR3aWRlIERldmVsb3Bl\n" +"ciBSZWxhdGlvbnMgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEiMA0GCSqGSIb3\n" +"DQEBAQUAA4IBDwAwggEKAoIBAQDKOFSmy1aqyCQ5SOmM7uxfuH8mkbw0U3rOfGOA\n" +"YXdkXqUHI7Y5/lAtFVZYcC1+xG7BSoU+L/DehBqhV8mvexj/avoVEkkVCBmsqtsq\n" +"Mu2WY2hSFT2Miuy/axiV4AOsAX2XBWfODoWVN2rtCbauZ81RZJ/GXNG8V25nNYB2\n" +"NqSHgW44j9grFU57Jdhav06DwY3Sk9UacbVgnJ0zTlX5ElgMhrgWDcHld0WNUEi6\n" +"Ky3klIXh6MSdxmilsKP8Z35wugJZS3dCkTm59c3hTO/AO0iMpuUhXf1qarunFjVg\n" +"0uat80YpyejDi+l5wGphZxWy8P3laLxiX27Pmd3vG2P+kmWrAgMBAAGjgaYwgaMw\n" +"HQYDVR0OBBYEFIgnFwmpthhgi+zruvZHWcVSVKO3MA8GA1UdEwEB/wQFMAMBAf8w\n" +"HwYDVR0jBBgwFoAUK9BpR5R2Cf70a40uQKb3R01/CF4wLgYDVR0fBCcwJTAjoCGg\n" +"H4YdaHR0cDovL2NybC5hcHBsZS5jb20vcm9vdC5jcmwwDgYDVR0PAQH/BAQDAgGG\n" +"MBAGCiqGSIb3Y2QGAgEEAgUAMA0GCSqGSIb3DQEBBQUAA4IBAQBPz+9Zviz1smwv\n" +"j+4ThzLoBTWobot9yWkMudkXvHcs1Gfi/ZptOllc34MBvbKuKmFysa/Nw0Uwj6OD\n" +"Dc4dR7Txk4qjdJukw5hyhzs+r0ULklS5MruQGFNrCk4QttkdUGwhgAqJTleMa1s8\n" +"Pab93vcNIx0LSiaHP7qRkkykGRIZbVf1eliHe2iK5IaMSuviSRSqpd1VAKmuu0sw\n" +"ruGgsbwpgOYJd+W+NKIByn/c4grmO7i77LpilfMFY0GCzQ87HUyVpNur+cmV6U/k\n" +"TecmmYHpvPm0KdIBembhLoz2IYrF+Hjhga6/05Cdqa3zr/04GpZnMBxRpVzscYqC\n" +"tGwPDBUf\n" +"-----END CERTIFICATE-----\n"; + std::string CertificatesContent(ALTCertificate *altCertificate) { - NSURL *pemURL = [[NSBundle bundleForClass:ALTSigner.class] URLForResource:@"apple" withExtension:@"pem"]; - NSData *altCertificateP12Data = [altCertificate p12Data]; BIO *inputP12Buffer = BIO_new(BIO_s_mem()); @@ -39,14 +122,34 @@ X509 *certificate; PKCS12_parse(inputP12, "", &key, &certificate, NULL); - // Open .pem from file. - auto pemFile = fopen(pemURL.path.fileSystemRepresentation, "r"); - - // Extract certificates from .pem. + // Prepare certificate chain of trust. auto *certificates = sk_X509_new(NULL); - while (auto certificate = PEM_read_X509(pemFile, NULL, NULL, NULL)) + + BIO *rootCertificateBuffer = BIO_new_mem_buf(AppleRootCertificateData, (int)strlen(AppleRootCertificateData)); + BIO *wwdrCertificateBuffer = nil; + + unsigned long issuerHash = X509_issuer_name_hash(certificate); + if (issuerHash == 0x817d2f7a) + { + // Use legacy WWDR certificate. + wwdrCertificateBuffer = BIO_new_mem_buf(LegacyAppleWWDRCertificateData, (int)strlen(LegacyAppleWWDRCertificateData)); + } + else { - sk_X509_push(certificates, certificate); + // Use latest WWDR certificate. + wwdrCertificateBuffer = BIO_new_mem_buf(AppleWWDRCertificateData, (int)strlen(AppleWWDRCertificateData)); + } + + auto rootCertificate = PEM_read_bio_X509(rootCertificateBuffer, NULL, NULL, NULL); + if (rootCertificate != NULL) + { + sk_X509_push(certificates, rootCertificate); + } + + auto wwdrCertificate = PEM_read_bio_X509(wwdrCertificateBuffer, NULL, NULL, NULL); + if (wwdrCertificate != NULL) + { + sk_X509_push(certificates, wwdrCertificate); } // Create new .p12 in memory with private key and certificate chain. @@ -65,16 +168,34 @@ PKCS12_free(inputP12); PKCS12_free(outputP12); + BIO_free(wwdrCertificateBuffer); + BIO_free(rootCertificateBuffer); + BIO_free(inputP12Buffer); BIO_free(outputP12Buffer); - // Close files - fclose(pemFile); - std::string output((const char *)p12Data.bytes, (size_t)p12Data.length); return output; } +struct ALTProgress: public ldid::Progress +{ + NSProgress *progress = nil; + + virtual void operator()(const std::string &value) const + { + this->progress.completedUnitCount += 1; + } + + virtual void operator()(double value) const + { + } + + ALTProgress(NSProgress *progress) : progress(progress) + { + } +}; + @implementation ALTSigner + (void)load @@ -213,21 +334,66 @@ - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray"]; + NSRange commentEndRange = [app.entitlementsString rangeOfString:@""]; + if (commentStartRange.location != NSNotFound && commentEndRange.location != NSNotFound && commentEndRange.location > commentStartRange.location) + { + // Most likely using private (commented out) entitlements to exploit Psychic Paper https://github.com/Siguza/psychicpaper + // Assume they know what they are doing and extract private entitlements to merge with profile's. + + NSRange commentRange = NSMakeRange(commentStartRange.location, (commentEndRange.location + commentEndRange.length) - commentStartRange.location); + NSString *commentedEntitlements = [app.entitlementsString substringWithRange:commentRange]; + + additionalEntitlements = commentedEntitlements; + } + } - NSRange commentStartRange = [app.entitlementsString rangeOfString:@""]; - NSRange commentEndRange = [app.entitlementsString rangeOfString:@""]; - if (commentStartRange.location != NSNotFound && commentEndRange.location != NSNotFound && commentEndRange.location > commentStartRange.location) + NSMutableDictionary *filteredEntitlements = [profile.entitlements mutableCopy]; + for (NSString *entitlement in profile.entitlements) { - // Most likely using private (commented out) entitlements to exploit Psychic Paper https://github.com/Siguza/psychicpaper - // Assume they know what they are doing and extract private entitlements to merge with profile's. - - NSRange commentRange = NSMakeRange(commentStartRange.location, (commentEndRange.location + commentEndRange.length) - commentStartRange.location); - NSString *commentedEntitlements = [app.entitlementsString substringWithRange:commentRange]; - - additionalEntitlements = commentedEntitlements; + id entitlementValue = app.entitlements[entitlement]; + if (entitlementValue != nil) + { + if ([entitlement isEqualToString:ALTEntitlementKeychainAccessGroups]) + { + // Replace profile's keychain-access-groups wildcard value with correct groups. + + NSMutableArray *keychainAccessGroups = [NSMutableArray array]; + for (NSString *keychainGroup in entitlementValue) + { + NSRange range = [keychainGroup rangeOfString:@"."]; + NSString *rawKeychainGroup = [keychainGroup substringFromIndex:range.location]; + + // rawKeychainGroup is prefixed with period already. + NSString *fixedKeychainGroup = [NSString stringWithFormat:@"%@%@", profile.teamIdentifier, rawKeychainGroup]; + [keychainAccessGroups addObject:fixedKeychainGroup]; + } + + filteredEntitlements[entitlement] = keychainAccessGroups; + } + else + { + // Downloaded app has this entitlement, so don't remove. + continue; + } + } + else + { + if ([entitlement isEqualToString:ALTEntitlementApplicationIdentifier] || [entitlement isEqualToString:ALTEntitlementTeamIdentifier] || [entitlement isEqualToString:ALTEntitlementGetTaskAllow]) + { + // Apps signed with development profiles _must_ have these entitlements, so never remove them, + // even if downloaded app doesn't have them originally. + continue; + } + + // Original app does not have this entitlement, so don't give it to resigned app. + filteredEntitlements[entitlement] = nil; + } } - NSData *entitlementsData = [NSPropertyListSerialization dataWithPropertyList:profile.entitlements format:NSPropertyListXMLFormat_v1_0 options:0 error:&error]; + NSData *entitlementsData = [NSPropertyListSerialization dataWithPropertyList:filteredEntitlements format:NSPropertyListXMLFormat_v1_0 options:0 error:&error]; if (entitlementsData == nil) { return error; @@ -241,7 +407,8 @@ - (NSProgress *)signAppAtURL:(NSURL *)appURL provisioningProfiles:(NSArray std::string { - NSString *filename = [NSString stringWithCString:path.c_str() encoding:NSUTF8StringEncoding]; + try + { + // Sign application + NSString *filePath = [application.fileURL.path.stringByStandardizingPath stringByAppendingString:@"/"]; + ldid::DiskFolder appBundle(filePath.UTF8String); - NSURL *fileURL = nil; + std::string key = CertificatesContent(self.certificate); + ALTProgress altProgress(progress); - if (filename.length == 0) - { - fileURL = application.fileURL; - } - else - { - fileURL = [application.fileURL URLByAppendingPathComponent:filename isDirectory:YES]; - } - - NSString *entitlements = entitlementsByFileURL[fileURL]; - return entitlements.UTF8String; - }), - ldid::fun([&](const std::string &string) { - progress.completedUnitCount += 1; - }), - ldid::fun([&](const double signingProgress) { - })); - - - // Dispatch after to allow time to finish signing binary. - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - if (ipaURL != nil) - { - NSURL *resignedIPAURL = [[NSFileManager defaultManager] zipAppBundleAtURL:appBundleURL error:&error]; + ldid::Sign("", appBundle, key, "", ldid::fun([&](const std::string &path, const std::string &binaryEntitlements) -> std::string { + NSString *filename = [NSString stringWithCString:path.c_str() encoding:NSUTF8StringEncoding]; + + NSURL *fileURL = nil; - if (![[NSFileManager defaultManager] replaceItemAtURL:ipaURL withItemAtURL:resignedIPAURL backupItemName:nil options:0 resultingItemURL:nil error:&error]) + if (filename.length == 0) { - finish(NO, error); + fileURL = application.fileURL; } - } + else + { + fileURL = [application.fileURL URLByAppendingPathComponent:filename isDirectory:YES]; + } + + NSURL *resolvedURL = [fileURL URLByResolvingSymlinksInPath]; + + NSString *entitlements = entitlementsByFileURL[resolvedURL]; + return entitlements.UTF8String; + }), altProgress); - finish(YES, nil); - }); + // Dispatch after to allow time to finish signing binary. + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + if (ipaURL != nil) + { + NSURL *resignedIPAURL = [[NSFileManager defaultManager] zipAppBundleAtURL:appBundleURL error:&error]; + + if (![[NSFileManager defaultManager] replaceItemAtURL:ipaURL withItemAtURL:resignedIPAURL backupItemName:nil options:0 resultingItemURL:nil error:&error]) + { + finish(NO, error); + return; + } + } + + finish(YES, nil); + }); + } + catch (std::exception& exception) + { + NSError *error = [NSError errorWithDomain:AltSignErrorDomain code:ALTErrorUnknown userInfo:@{ + NSLocalizedFailureReasonErrorKey: @(exception.what()), + ALTSourceFileErrorKey: @(__FILE__).lastPathComponent, + ALTSourceLineErrorKey: @(__LINE__) + }]; + finish(NO, error); + } }); return progress; diff --git a/AltSign/Sources/ALTAppleAPI+Authentication.swift b/AltSign/Sources/ALTAppleAPI+Authentication.swift new file mode 100644 index 0000000..2d3e50c --- /dev/null +++ b/AltSign/Sources/ALTAppleAPI+Authentication.swift @@ -0,0 +1,521 @@ +// +// ALTAppleAPI+Authentication.swift +// AltSign +// +// Created by Riley Testut on 8/15/20. +// Copyright © 2020 Riley Testut. All rights reserved. +// + +import Foundation + +@_exported import CAltSign +import CAltSign.Private + +public extension ALTAppleAPIError +{ + static func unknown(userInfo: [String: Any] = [:], sourceFile: String = #fileID, sourceLine: UInt = #line) -> ALTAppleAPIError + { + var userInfo = userInfo + userInfo[ALTSourceFileErrorKey] = sourceFile + userInfo[ALTSourceLineErrorKey] = sourceLine + + let error = ALTAppleAPIError(.unknown, userInfo: userInfo) + return error + } +} + +public extension ALTAppleAPI +{ + @objc func authenticate(appleID unsanitizedAppleID: String, + password: String, + anisetteData: ALTAnisetteData, + verificationHandler: ((@escaping (String?) -> Void) -> Void)?, + completionHandler: @escaping (ALTAccount?, ALTAppleAPISession?, Error?) -> Void) + { + // Authenticating only works with lowercase email address, even if Apple ID contains capital letters. + let sanitizedAppleID = unsanitizedAppleID.lowercased() + + do + { + let clientDictionary = [ + "bootstrap": true, + "icscrec": true, + "pbe": false, + "prkgen": true, + "svct": "iCloud", + "loc": Locale.current.identifier, + "X-Apple-Locale": Locale.current.identifier, + "X-Apple-I-MD": anisetteData.oneTimePassword, + "X-Apple-I-MD-M": anisetteData.machineID, + "X-Mme-Device-Id": anisetteData.deviceUniqueIdentifier, + "X-Apple-I-MD-LU": anisetteData.localUserID, + "X-Apple-I-MD-RINFO": anisetteData.routingInfo, + "X-Apple-I-SRL-NO": anisetteData.deviceSerialNumber, + "X-Apple-I-Client-Time": self.dateFormatter.string(from: anisetteData.date), + "X-Apple-I-TimeZone": TimeZone.current.abbreviation() ?? "PST", + ] as [String: Any] + + let context = GSAContext(username: sanitizedAppleID, password: password) + guard let publicKey = context.start() else { throw ALTAppleAPIError(.authenticationHandshakeFailed) } + + let parameters = [ + "A2k": publicKey, + "cpd": clientDictionary, + "ps": ["s2k", "s2k_fo"], + "o": "init", + "u": sanitizedAppleID + ] as [String: Any] + + self.sendAuthenticationRequest(parameters: parameters, anisetteData: anisetteData) { (result) in + do + { + let responseDictionary = try result.get() + + guard let c = responseDictionary["c"] as? String, + let salt = responseDictionary["s"] as? Data, + let iterations = responseDictionary["i"] as? Int, + let serverPublicKey = responseDictionary["B"] as? Data + else { throw URLError(.badServerResponse) } + + context.salt = salt + context.serverPublicKey = serverPublicKey + + let sp = responseDictionary["sp"] as? String + let isHexadecimal = (sp == "s2k_fo") + + guard let verificationMessage = context.makeVerificationMessage(iterations: iterations, isHexadecimal: isHexadecimal) else { + throw ALTAppleAPIError(.authenticationHandshakeFailed) + } + + let parameters = [ + "c": c, + "cpd": clientDictionary, + "M1": verificationMessage, + "o": "complete", + "u": sanitizedAppleID + ] as [String: Any] + + self.sendAuthenticationRequest(parameters: parameters, anisetteData: anisetteData) { (result) in + do + { + let responseDictionary = try result.get() + + guard let serverVerificationMessage = responseDictionary["M2"] as? Data, + let serverDictionary = responseDictionary["spd"] as? Data, + let statusDictionary = responseDictionary["Status"] as? [String: Any] + else { throw URLError(.badServerResponse) } + + guard context.verifyServerVerificationMessage(serverVerificationMessage) else { throw ALTAppleAPIError(.authenticationHandshakeFailed) } + guard let decryptedData = serverDictionary.decryptedCBC(context: context) else { throw ALTAppleAPIError(.authenticationHandshakeFailed) } + + guard let decryptedDictionary = try PropertyListSerialization.propertyList(from: decryptedData, format: nil) as? [String: Any], + let dsid = decryptedDictionary["adsid"] as? String, + let idmsToken = decryptedDictionary["GsIdmsToken"] as? String + else { throw URLError(.badServerResponse) } + + context.dsid = dsid + + let authType = statusDictionary["au"] as? String + switch authType + { + case "trustedDeviceSecondaryAuth": + guard let verificationHandler = verificationHandler else { throw ALTAppleAPIError(.requiresTwoFactorAuthentication) } + + self.requestTrustedDeviceTwoFactorCode(dsid: dsid, idmsToken: idmsToken, anisetteData: anisetteData, verificationHandler: verificationHandler) { (result) in + switch result + { + case .failure(let error): completionHandler(nil, nil, error) + case .success: + self.authenticate(appleID: unsanitizedAppleID, password: password, anisetteData: anisetteData, verificationHandler: verificationHandler, completionHandler: completionHandler) + } + } + + case "secondaryAuth": + guard let verificationHandler = verificationHandler else { throw ALTAppleAPIError(.requiresTwoFactorAuthentication) } + + self.requestSMSTwoFactorCode(dsid: dsid, idmsToken: idmsToken, anisetteData: anisetteData, verificationHandler: verificationHandler) { (result) in + switch result + { + case .failure(let error): completionHandler(nil, nil, error) + case .success: + self.authenticate(appleID: unsanitizedAppleID, password: password, anisetteData: anisetteData, verificationHandler: verificationHandler, completionHandler: completionHandler) + } + } + + default: + guard let sessionKey = decryptedDictionary["sk"] as? Data, + let c = decryptedDictionary["c"] as? Data + else { throw URLError(.badServerResponse) } + + context.sessionKey = sessionKey + + let app = "com.apple.gs.xcode.auth" + guard let checksum = context.makeChecksum(appName: app) else { throw ALTAppleAPIError(.authenticationHandshakeFailed) } + + let parameters = [ + "app": [app], + "c": c, + "checksum": checksum, + "cpd": clientDictionary, + "o": "apptokens", + "t": idmsToken, + "u": dsid + ] as [String: Any] + + self.fetchAuthToken(app: app, parameters: parameters, context: context, anisetteData: anisetteData) { (result) in + switch result + { + case .failure(let error): completionHandler(nil, nil, error) + case .success(let token): + + let session = ALTAppleAPISession(dsid: dsid, authToken: token, anisetteData: anisetteData) + self.fetchAccount(session: session) { (result) in + switch result + { + case .failure(let error): completionHandler(nil, nil, error) + case .success(let account): completionHandler(account, session, nil) + } + } + } + } + } + } + catch + { + completionHandler(nil, nil, error) + } + } + } + catch + { + completionHandler(nil, nil, error) + } + } + } + catch + { + completionHandler(nil, nil, error) + } + } +} + +private extension ALTAppleAPI +{ + func fetchAuthToken(app: String, parameters: [String: Any], context: GSAContext, anisetteData: ALTAnisetteData, completionHandler: @escaping (Result) -> Void) + { + self.sendAuthenticationRequest(parameters: parameters, anisetteData: anisetteData) { (result) in + do + { + let responseDictionary = try result.get() + + guard let encryptedToken = responseDictionary["et"] as? Data else { throw URLError(.badServerResponse) } + guard let token = encryptedToken.decryptedGCM(context: context) else { throw ALTAppleAPIError(.authenticationHandshakeFailed) } + + guard let tokensDictionary = try PropertyListSerialization.propertyList(from: token, format: nil) as? [String: Any] else { + throw URLError(.badServerResponse) + } + + guard let appTokens = tokensDictionary["t"] as? [String: Any], + let tokens = appTokens[app] as? [String: Any], + let authToken = tokens["token"] as? String + else { throw URLError(.badServerResponse) } + + completionHandler(.success(authToken)) + } + catch + { + completionHandler(.failure(error)) + } + } + } + + func requestTrustedDeviceTwoFactorCode(dsid: String, + idmsToken: String, + anisetteData: ALTAnisetteData, + verificationHandler: @escaping (@escaping (String?) -> Void) -> Void, + completionHandler: @escaping (Result) -> Void) + { + let requestURL = URL(string: "https://gsa.apple.com/auth/verify/trusteddevice")! + let verifyURL = URL(string: "https://gsa.apple.com/grandslam/GsService2/validate")! + + let request = self.makeTwoFactorCodeRequest(url: requestURL, dsid: dsid, idmsToken: idmsToken, anisetteData: anisetteData) + + let requestCodeTask = self.session.dataTask(with: request) { (data, response, error) in + do + { + guard error == nil else { throw error! } + + func responseHandler(verificationCode: String?) + { + do + { + guard let verificationCode = verificationCode else { throw ALTAppleAPIError(.requiresTwoFactorAuthentication) } + + var request = self.makeTwoFactorCodeRequest(url: verifyURL, dsid: dsid, idmsToken: idmsToken, anisetteData: anisetteData) + request.allHTTPHeaderFields?["security-code"] = verificationCode + + let verifyCodeTask = self.session.dataTask(with: request) { (data, response, error) in + do + { + guard let data = data else { throw error ?? ALTAppleAPIError.unknown() } + + guard let responseDictionary = try PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any] else { + throw URLError(.badServerResponse) + } + + let errorCode = responseDictionary["ec"] as? Int ?? 0 + guard errorCode != 0 else { return completionHandler(.success(())) } + + switch errorCode + { + case -21669: throw ALTAppleAPIError(.incorrectVerificationCode) + default: + guard let errorDescription = responseDictionary["em"] as? String else { throw ALTAppleAPIError.unknown() } + + let localizedDescription = errorDescription + " (\(errorCode))" + throw NSError(domain: ALTUnderlyingAppleAPIErrorDomain, code: errorCode, userInfo: [NSLocalizedDescriptionKey: localizedDescription]) + } + } + catch + { + completionHandler(.failure(error)) + } + } + + verifyCodeTask.resume() + } + catch + { + completionHandler(.failure(error)) + } + } + + verificationHandler(responseHandler) + } + catch + { + completionHandler(.failure(error)) + } + } + + requestCodeTask.resume() + } + + func requestSMSTwoFactorCode(dsid: String, + idmsToken: String, + anisetteData: ALTAnisetteData, + verificationHandler: @escaping (@escaping (String?) -> Void) -> Void, + completionHandler: @escaping (Result) -> Void) + { + let requestURL = URL(string: "https://gsa.apple.com/auth/verify/phone/put?mode=sms")! + let verifyURL = URL(string: "https://gsa.apple.com/auth/verify/phone/securitycode?referrer=/auth/verify/phone/put")! + + var request = self.makeTwoFactorCodeRequest(url: requestURL, dsid: dsid, idmsToken: idmsToken, anisetteData: anisetteData) + request.httpMethod = "POST" + + do + { + let bodyXML = [ + "serverInfo": [ + "phoneNumber.id": "1" + ] + ] as [String : Any] + + let bodyData = try PropertyListSerialization.data(fromPropertyList: bodyXML, format: .xml, options: 0) + request.httpBody = bodyData + } + catch + { + completionHandler(.failure(error)) + return + } + + let requestCodeTask = self.session.dataTask(with: request) { (data, response, error) in + do + { + guard error == nil else { throw error! } + + func responseHandler(verificationCode: String?) + { + do + { + guard let verificationCode = verificationCode else { throw ALTAppleAPIError(.requiresTwoFactorAuthentication) } + + var request = self.makeTwoFactorCodeRequest(url: verifyURL, dsid: dsid, idmsToken: idmsToken, anisetteData: anisetteData) + request.httpMethod = "POST" + + let bodyXML = [ + "securityCode.code": verificationCode, + "serverInfo": [ + "mode": "sms", + "phoneNumber.id": "1" + ] + ] as [String : Any] + + let bodyData = try PropertyListSerialization.data(fromPropertyList: bodyXML, format: .xml, options: 0) + request.httpBody = bodyData + + let verifyCodeTask = self.session.dataTask(with: request) { (data, response, error) in + do + { + guard error == nil else { throw error! } + + guard let httpResponse = response as? HTTPURLResponse, + httpResponse.statusCode == 200, + httpResponse.allHeaderFields.keys.contains("X-Apple-PE-Token") // PE token is included in headers if we sent correct verification code. + else { throw ALTAppleAPIError(.incorrectVerificationCode) } + + completionHandler(.success(())) + } + catch + { + completionHandler(.failure(error)) + } + } + + verifyCodeTask.resume() + } + catch + { + completionHandler(.failure(error)) + } + } + + verificationHandler(responseHandler) + } + catch + { + completionHandler(.failure(error)) + } + } + + requestCodeTask.resume() + } + + func fetchAccount(session: ALTAppleAPISession, completionHandler: @escaping (Result) -> Void) + { + let url = URL(string: "viewDeveloper.action", relativeTo: self.baseURL)! + + self.sendRequest(with: url, additionalParameters: nil, session: session, team: nil) { (responseDictionary, requestError) in + do + { + guard let responseDictionary = responseDictionary else { throw requestError ?? ALTAppleAPIError.unknown() } + + guard let account = try self.processResponse(responseDictionary, parseHandler: { () -> Any? in + guard let dictionary = responseDictionary["developer"] as? [String: Any] else { return nil } + let account = ALTAccount(responseDictionary: dictionary) + return account + }, resultCodeHandler: nil) as? ALTAccount else { + throw ALTAppleAPIError.unknown() + } + + completionHandler(.success(account)) + } + catch + { + completionHandler(.failure(error)) + } + } + } +} + +private extension ALTAppleAPI +{ + func sendAuthenticationRequest(parameters requestParameters: [String: Any], anisetteData: ALTAnisetteData, completionHandler: @escaping (Result<[String: Any], Error>) -> Void) + { + do + { + let requestURL = URL(string: "https://gsa.apple.com/grandslam/GsService2")! + + let parameters = [ + "Header": ["Version": "1.0.1"], + "Request": requestParameters + ] + + let httpHeaders = [ + "Content-Type": "text/x-xml-plist", + "X-MMe-Client-Info": anisetteData.deviceDescription, + "Accept": "*/*", + "User-Agent": "akd/1.0 CFNetwork/978.0.7 Darwin/18.7.0" + ] + + let bodyData = try PropertyListSerialization.data(fromPropertyList: parameters, format: .xml, options: 0) + + var request = URLRequest(url: requestURL) + request.httpMethod = "POST" + request.httpBody = bodyData + httpHeaders.forEach { request.addValue($0.value, forHTTPHeaderField: $0.key) } + + let dataTask = self.session.dataTask(with: request) { (data, response, error) in + do + { + guard let data = data else { throw error ?? ALTAppleAPIError.unknown() } + + guard let responseDictionary = try PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any], + let dictionary = responseDictionary["Response"] as? [String: Any], + let status = dictionary["Status"] as? [String: Any] + else { throw URLError(.badServerResponse) } + + let errorCode = status["ec"] as? Int ?? 0 + guard errorCode != 0 else { return completionHandler(.success(dictionary)) } + + switch errorCode + { + case -20101, -22406: throw ALTAppleAPIError(.incorrectCredentials) + case -22421: throw ALTAppleAPIError(.invalidAnisetteData) + default: + guard let errorDescription = status["em"] as? String else { throw ALTAppleAPIError.unknown() } + + let localizedDescription = errorDescription + " (\(errorCode))" + throw NSError(domain: ALTUnderlyingAppleAPIErrorDomain, code: errorCode, userInfo: [NSLocalizedDescriptionKey: localizedDescription]) + } + } + catch + { + completionHandler(.failure(error)) + } + } + + dataTask.resume() + } + catch + { + completionHandler(.failure(error)) + } + } + + func makeTwoFactorCodeRequest(url: URL, + dsid: String, + idmsToken: String, + anisetteData: ALTAnisetteData) -> URLRequest + { + let identityToken = dsid + ":" + idmsToken + + let identityTokenData = identityToken.data(using: .utf8)! + let encodedIdentityToken = identityTokenData.base64EncodedString() + + let httpHeaders = [ + "Accept": "application/x-buddyml", + "Accept-Language": "en-us", + "Content-Type": "application/x-plist", + "User-Agent": "Xcode", + "X-Apple-App-Info": "com.apple.gs.xcode.auth", + "X-Xcode-Version": "11.2 (11B41)", + "X-Apple-Identity-Token": encodedIdentityToken, + "X-Apple-I-MD-M": anisetteData.machineID, + "X-Apple-I-MD": anisetteData.oneTimePassword, + "X-Apple-I-MD-LU": anisetteData.localUserID, + "X-Apple-I-MD-RINFO": "\(anisetteData.routingInfo)", + "X-Mme-Device-Id": anisetteData.deviceUniqueIdentifier, + "X-MMe-Client-Info": anisetteData.deviceDescription, + "X-Apple-I-Client-Time": self.dateFormatter.string(from: anisetteData.date), + "X-Apple-Locale": anisetteData.locale.identifier, + "X-Apple-I-TimeZone": anisetteData.timeZone.abbreviation() ?? "PST" + ] + + var request = URLRequest(url: url) + httpHeaders.forEach { request.addValue($0.value, forHTTPHeaderField: $0.key) } + + return request + } +} diff --git a/AltSign/Sources/Data+Encryption.swift b/AltSign/Sources/Data+Encryption.swift new file mode 100644 index 0000000..cbb96f0 --- /dev/null +++ b/AltSign/Sources/Data+Encryption.swift @@ -0,0 +1,110 @@ +// +// Data+Encryption.swift +// AltSign +// +// Created by Riley Testut on 8/20/20. +// Copyright © 2020 Riley Testut. All rights reserved. +// + +import Foundation + +#if !MARKETPLACE +import CoreCrypto +#endif + +extension Data +{ + static func makeBuffer(size: Int, type: T.Type) -> UnsafeMutablePointer + { + return UnsafeMutableRawPointer.allocate(byteCount: size, alignment: MemoryLayout.alignment).assumingMemoryBound(to: type) + } + + func hexadecimal() -> Data + { + let hexString = self.map { String(format: "%02hhx", $0) }.joined() + + let hexData = Data(hexString.flatMap { $0.utf8.map { UInt8($0) } }) + return hexData + } + + func decryptedCBC(context gsaContext: GSAContext) -> Data? + { + #if MARKETPLACE + + return nil + + #else + + guard let mode = ccaes_cbc_decrypt_mode() else { return nil } + + let context = Data.makeBuffer(size: mode.pointee.size, type: cccbc_ctx.self) + defer { context.deallocate() } + + let sessionKey = gsaContext.makeHMACKey("extra data key:") + _ = sessionKey.withUnsafeBytes { mode.pointee.`init`(mode, context, sessionKey.count, $0.baseAddress) } + + var initializationVector = gsaContext.makeHMACKey("extra data iv:") + var decryptedData = Data(repeating: 0, count: self.count) + + let size = decryptedData.withUnsafeMutableBytes { (decryptedBytes) in + self.withUnsafeBytes { (dataBytes) in + initializationVector.withUnsafeMutableBytes { (ivBytes) -> size_t in + let ivPointer = ivBytes.baseAddress!.assumingMemoryBound(to: cccbc_iv.self) + return ccpad_pkcs7_decrypt(mode, context, ivPointer, self.count, dataBytes.baseAddress, decryptedBytes.baseAddress) + } + } + } + + guard size <= self.count else { return nil } + return decryptedData + + #endif + } + + func decryptedGCM(context gsaContext: GSAContext) -> Data? + { + #if MARKETPLACE + + return nil + + #else + + guard let mode = ccaes_gcm_decrypt_mode(), + let sessionKey = gsaContext.sessionKey else { return nil } + + let context = Data.makeBuffer(size: mode.pointee.size, type: ccgcm_ctx.self) + defer { context.deallocate() } + + _ = sessionKey.withUnsafeBytes { mode.pointee.`init`(mode, context, sessionKey.count, $0.baseAddress!) } + + let versionSize = 3 + let ivSize = 16 + let tagSize = 16 + + let decryptedSize = self.count - (versionSize + ivSize + tagSize) + guard decryptedSize > 0 else { return nil } + + let version = self[0 ..< versionSize] + let initializationVector = self[versionSize ..< versionSize + ivSize] + let ciphertext = self.dropFirst(versionSize + ivSize).dropLast(tagSize) + let tag = self[self.endIndex - tagSize ..< self.endIndex] + + _ = initializationVector.withUnsafeBytes { mode.pointee.set_iv(context, ivSize, $0.baseAddress) } + _ = version.withUnsafeBytes { mode.pointee.gmac(context, version.count, $0.baseAddress) } + + var decryptedData = Data(repeating: 0, count: decryptedSize) + _ = ciphertext.withUnsafeBytes { (ciphertextBytes) in + decryptedData.withUnsafeMutableBytes { (decryptedBytes) in + mode.pointee.gcm(context, decryptedSize, ciphertextBytes.baseAddress, decryptedBytes.baseAddress) + } + } + + var decryptedTag = Data(repeating: 0, count: tagSize) + _ = decryptedTag.withUnsafeMutableBytes { mode.pointee.finalize(context, tagSize, $0.baseAddress) } + + guard tag == decryptedTag else { return nil } + return decryptedData + + #endif + } +} diff --git a/AltSign/Sources/GSAContext.swift b/AltSign/Sources/GSAContext.swift new file mode 100644 index 0000000..d5dff0a --- /dev/null +++ b/AltSign/Sources/GSAContext.swift @@ -0,0 +1,249 @@ +// +// GSAContext.swift +// AltSign +// +// Created by Riley Testut on 8/15/20. +// Copyright © 2020 Riley Testut. All rights reserved. +// + +import Foundation + +#if !MARKETPLACE +import CoreCrypto +#endif + +class GSAContext +{ + let username: String + let password: String + + /// salt (obtained from server) + var salt: Data? + + /// B (Public) + var serverPublicKey: Data? + + /// K + var sessionKey: Data? + + var dsid: String? + + /// A (Public) + private(set) var publicKey: Data? + + /// x (derived with KDF) + private(set) var derivedPasswordKey: Data? + + /// M1 + private(set) var verificationMessage: Data? + + #if !MARKETPLACE + + /// SRP group: https://tools.ietf.org/html/rfc5054#page-16 + private let srpGroup = ccsrp_gp_rfc5054_2048()! + + private let digestInfo = ccsha256_di()! + + private lazy var srpContext: ccsrp_ctx_t = { + let size = ccsrp_sizeof_srp(self.digestInfo, self.srpGroup) + let context = UnsafeMutableRawPointer.allocate(byteCount: size, alignment: MemoryLayout.alignment).assumingMemoryBound(to: ccsrp_ctx.self) + ccsrp_ctx_init(context, self.digestInfo, self.srpGroup) + ccsrp_client_set_noUsernameInX(context, true) + context.pointee.blinding_rng = ccrng(nil) + return context + }() + + #endif + + init(username: String, password: String) + { + self.username = username + self.password = password + } + + deinit + { + #if !MARKETPLACE + self.srpContext.deallocate() + #endif + } +} + +extension GSAContext +{ + func start() -> Data? + { + guard self.publicKey == nil else { return nil } + + self.publicKey = self.makeAKey() + return self.publicKey + } + + func makeVerificationMessage(iterations: Int, isHexadecimal: Bool) -> Data? + { + guard self.verificationMessage == nil else { return nil } + guard let salt = self.salt, let serverPublicKey = self.serverPublicKey else { return nil } + + guard let derivedPasswordKey = self.makeX(password: self.password, salt: salt, iterations: iterations, isHexadecimal: isHexadecimal) else { return nil } + self.derivedPasswordKey = derivedPasswordKey + + self.verificationMessage = self.makeM1(username: self.username, derivedPasswordKey: derivedPasswordKey, salt: salt, serverPublicKey: serverPublicKey) + return self.verificationMessage + } + + func verifyServerVerificationMessage(_ serverVerificationMessage: Data) -> Bool + { + #if MARKETPLACE + + return false + + #else + + guard !serverVerificationMessage.isEmpty else { return false } + + let isValid = serverVerificationMessage.withUnsafeBytes { (bytes) -> Bool in + let pointer = bytes.baseAddress!.assumingMemoryBound(to: UInt8.self) + return ccsrp_client_verify_session(self.srpContext, pointer) + } + + return isValid + + #endif + } + + func makeChecksum(appName: String) -> Data? + { + #if MARKETPLACE + + return nil + + #else + + guard let sessionKey = self.sessionKey, let dsid = self.dsid else { return nil } + + let size = cchmac_di_size(self.digestInfo) + + let context = Data.makeBuffer(size: size, type: cchmac_ctx.self) + defer { context.deallocate() } + + sessionKey.withUnsafeBytes { cchmac_init(self.digestInfo, context, sessionKey.count, $0.baseAddress) } + + for string in ["apptokens", dsid, appName] + { + cchmac_update(self.digestInfo, context, string.count, string) + } + + var checksum = Data(repeating: 0, count: self.digestInfo.pointee.output_size) + checksum.withUnsafeMutableBytes { cchmac_final(self.digestInfo, context, $0.baseAddress?.assumingMemoryBound(to: UInt8.self)) } + return checksum + + #endif + } +} + +internal extension GSAContext +{ + func makeHMACKey(_ string: String) -> Data + { + #if MARKETPLACE + + return Data() + + #else + + var keySize = 0 + let rawSessionKey = ccsrp_get_session_key(self.srpContext, &keySize) + + var sessionKey = Data(repeating: 0, count: keySize) + sessionKey.withUnsafeMutableBytes { cchmac(self.digestInfo, keySize, rawSessionKey, string.count, string, $0.baseAddress?.assumingMemoryBound(to: UInt8.self)) } + return sessionKey + + #endif + } +} + +private extension GSAContext +{ + func makeAKey() -> Data? + { + #if MARKETPLACE + + return nil + + #else + + let size = ccsrp_exchange_size(self.srpContext) + + var keyA = Data(repeating: 0, count: size) + let result = keyA.withUnsafeMutableBytes { ccsrp_client_start_authentication(self.srpContext, ccrng(nil), $0.baseAddress!) } + + guard result == 0 else { return nil } + return keyA + + #endif + } + + func makeX(password: String, salt: Data, iterations: Int, isHexadecimal: Bool) -> Data? + { + #if MARKETPLACE + + return nil + + #else + + var digest = Data(repeating: 0, count: self.digestInfo.pointee.output_size) + digest.withUnsafeMutableBytes { ccdigest(self.digestInfo, password.utf8.count, password, $0.baseAddress!) } + + let digestLength = isHexadecimal ? self.digestInfo.pointee.output_size * 2 : self.digestInfo.pointee.output_size + + if isHexadecimal + { + let hexDigest = digest.hexadecimal() + digest = hexDigest + } + + var x = Data(repeating: 0, count: self.digestInfo.pointee.output_size) + + let result = x.withUnsafeMutableBytes { (xBytes) in + digest.withUnsafeBytes { (digestBytes) in + salt.withUnsafeBytes { (saltBytes) in + ccpbkdf2_hmac(self.digestInfo, digestLength, digestBytes.baseAddress, salt.count, saltBytes.baseAddress, iterations, self.digestInfo.pointee.output_size, xBytes.baseAddress) + } + } + } + + guard result == 0 else { return nil } + return x + + #endif + } + + func makeM1(username: String, derivedPasswordKey x: Data, salt: Data, serverPublicKey B: Data) -> Data? + { + #if MARKETPLACE + + return nil + + #else + + let size = ccsrp_get_session_key_length(self.srpContext) + + var M1 = Data(repeating: 0, count: size) + + let result = M1.withUnsafeMutableBytes { (m1Bytes) in + x.withUnsafeBytes { (xBytes) in + salt.withUnsafeBytes { (saltBytes) in + B.withUnsafeBytes { (bBytes) in + ccsrp_client_process_challenge(self.srpContext, username, xBytes.count, xBytes.baseAddress!, + salt.count, saltBytes.baseAddress!, bBytes.baseAddress!, m1Bytes.baseAddress!) + } + } + } + } + + guard result == 0 else { return nil } + return M1 + + #endif + } +} diff --git a/AltSign/AltSign.h b/AltSign/include/AltSign.h similarity index 90% rename from AltSign/AltSign.h rename to AltSign/include/AltSign.h index c18fa50..89b25d6 100644 --- a/AltSign/AltSign.h +++ b/AltSign/include/AltSign.h @@ -8,7 +8,6 @@ // Apple API #import -#import #import // Signing @@ -27,7 +26,8 @@ // Categories #import -#import +#import +#import // Capabilities #import diff --git a/AltSign/include/AltSign/ALTAccount.h b/AltSign/include/AltSign/ALTAccount.h new file mode 120000 index 0000000..661d898 --- /dev/null +++ b/AltSign/include/AltSign/ALTAccount.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTAccount.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTAnisetteData.h b/AltSign/include/AltSign/ALTAnisetteData.h new file mode 120000 index 0000000..cad4d6c --- /dev/null +++ b/AltSign/include/AltSign/ALTAnisetteData.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTAnisetteData.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTAppGroup.h b/AltSign/include/AltSign/ALTAppGroup.h new file mode 120000 index 0000000..9a36f2c --- /dev/null +++ b/AltSign/include/AltSign/ALTAppGroup.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTAppGroup.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTAppID.h b/AltSign/include/AltSign/ALTAppID.h new file mode 120000 index 0000000..714e239 --- /dev/null +++ b/AltSign/include/AltSign/ALTAppID.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTAppID.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTAppleAPI.h b/AltSign/include/AltSign/ALTAppleAPI.h new file mode 120000 index 0000000..dab67d7 --- /dev/null +++ b/AltSign/include/AltSign/ALTAppleAPI.h @@ -0,0 +1 @@ +../../Apple API/ALTAppleAPI.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTAppleAPISession.h b/AltSign/include/AltSign/ALTAppleAPISession.h new file mode 120000 index 0000000..815e232 --- /dev/null +++ b/AltSign/include/AltSign/ALTAppleAPISession.h @@ -0,0 +1 @@ +../../Apple API/ALTAppleAPISession.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTAppleAPI_Private.h b/AltSign/include/AltSign/ALTAppleAPI_Private.h new file mode 120000 index 0000000..320833a --- /dev/null +++ b/AltSign/include/AltSign/ALTAppleAPI_Private.h @@ -0,0 +1 @@ +../../Apple API/ALTAppleAPI_Private.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTApplication.h b/AltSign/include/AltSign/ALTApplication.h new file mode 120000 index 0000000..244fea6 --- /dev/null +++ b/AltSign/include/AltSign/ALTApplication.h @@ -0,0 +1 @@ +../../Model/ALTApplication.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTCapabilities.h b/AltSign/include/AltSign/ALTCapabilities.h new file mode 120000 index 0000000..c7b9067 --- /dev/null +++ b/AltSign/include/AltSign/ALTCapabilities.h @@ -0,0 +1 @@ +../../Capabilities/ALTCapabilities.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTCertificate.h b/AltSign/include/AltSign/ALTCertificate.h new file mode 120000 index 0000000..2085d25 --- /dev/null +++ b/AltSign/include/AltSign/ALTCertificate.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTCertificate.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTCertificateRequest.h b/AltSign/include/AltSign/ALTCertificateRequest.h new file mode 120000 index 0000000..6b6fef1 --- /dev/null +++ b/AltSign/include/AltSign/ALTCertificateRequest.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTCertificateRequest.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTDevice.h b/AltSign/include/AltSign/ALTDevice.h new file mode 120000 index 0000000..c123d93 --- /dev/null +++ b/AltSign/include/AltSign/ALTDevice.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTDevice.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTModel+Internal.h b/AltSign/include/AltSign/ALTModel+Internal.h new file mode 120000 index 0000000..e8eb844 --- /dev/null +++ b/AltSign/include/AltSign/ALTModel+Internal.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTModel+Internal.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTProvisioningProfile.h b/AltSign/include/AltSign/ALTProvisioningProfile.h new file mode 120000 index 0000000..2401758 --- /dev/null +++ b/AltSign/include/AltSign/ALTProvisioningProfile.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTProvisioningProfile.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTSigner.h b/AltSign/include/AltSign/ALTSigner.h new file mode 120000 index 0000000..0f76abc --- /dev/null +++ b/AltSign/include/AltSign/ALTSigner.h @@ -0,0 +1 @@ +../../Signing/ALTSigner.h \ No newline at end of file diff --git a/AltSign/include/AltSign/ALTTeam.h b/AltSign/include/AltSign/ALTTeam.h new file mode 120000 index 0000000..9d9b053 --- /dev/null +++ b/AltSign/include/AltSign/ALTTeam.h @@ -0,0 +1 @@ +../../Model/Apple API/ALTTeam.h \ No newline at end of file diff --git a/AltSign/include/AltSign/NSCharacterSet+ASCII.h b/AltSign/include/AltSign/NSCharacterSet+ASCII.h new file mode 120000 index 0000000..ccf5759 --- /dev/null +++ b/AltSign/include/AltSign/NSCharacterSet+ASCII.h @@ -0,0 +1 @@ +../../Categories/NSCharacterSet+ASCII.h \ No newline at end of file diff --git a/AltSign/include/AltSign/NSError+ALTErrors.h b/AltSign/include/AltSign/NSError+ALTErrors.h new file mode 120000 index 0000000..82ce6eb --- /dev/null +++ b/AltSign/include/AltSign/NSError+ALTErrors.h @@ -0,0 +1 @@ +../../Categories/NSError+ALTErrors.h \ No newline at end of file diff --git a/AltSign/include/AltSign/NSFileManager+Zip.h b/AltSign/include/AltSign/NSFileManager+Zip.h new file mode 120000 index 0000000..21fbacb --- /dev/null +++ b/AltSign/include/AltSign/NSFileManager+Zip.h @@ -0,0 +1 @@ +../../Categories/NSFileManager+Zip.h \ No newline at end of file diff --git a/AltSign/include/module.modulemap b/AltSign/include/module.modulemap new file mode 100644 index 0000000..7af9cab --- /dev/null +++ b/AltSign/include/module.modulemap @@ -0,0 +1,11 @@ +module CAltSign { + umbrella header "AltSign.h" + export * + + explicit module Private { + header "AltSign/ALTAppleAPI_Private.h" + header "AltSign/ALTModel+Internal.h" + header "AltSign/ALTCertificateRequest.h" + export * + } +} diff --git a/Dependencies/OpenSSL b/Dependencies/OpenSSL index d3c021d..d0afc3f 160000 --- a/Dependencies/OpenSSL +++ b/Dependencies/OpenSSL @@ -1 +1 @@ -Subproject commit d3c021d85fb7a68eff9dc907b7e48f3615a43124 +Subproject commit d0afc3f44f5a0fbc52e08ef12d9d10f8ad9677b4 diff --git a/Dependencies/corecrypto/Sources/CoreCryptoMacros.swift b/Dependencies/corecrypto/Sources/CoreCryptoMacros.swift new file mode 100644 index 0000000..9069c30 --- /dev/null +++ b/Dependencies/corecrypto/Sources/CoreCryptoMacros.swift @@ -0,0 +1,55 @@ +// +// CoreCryptoMacros.swift +// AltSign +// +// Created by Riley Testut on 8/20/20. +// Copyright © 2020 Riley Testut. All rights reserved. +// + +@_exported import CCoreCrypto + +/// Reimplementations of various CoreCrypto macros that are unavailable in Swift. + +public func ccdigest_ctx_size(_ stateSize: Int, _ blockSize: Int) -> Int +{ + (stateSize + MemoryLayout.size + blockSize + MemoryLayout.size) +} + +public func ccdigest_di_size(_ digestInfo: UnsafePointer) -> Int +{ + ccdigest_ctx_size(digestInfo.pointee.state_size, digestInfo.pointee.block_size) +} + +public func ccsrp_gpbuf_size(_ group: ccdh_const_gp_t) -> Int +{ + ccdh_ccn_size(group) * 4 +} + +public func ccsrp_dibuf_size(_ digestInfo: UnsafePointer) -> Int +{ + digestInfo.pointee.output_size * 4 +} + +public func ccsrp_sizeof_srp(_ digestInfo: UnsafePointer, _ group: ccdh_const_gp_t) -> Int +{ + MemoryLayout.size + ccsrp_gpbuf_size(group) + ccsrp_dibuf_size(digestInfo) +} + +public func cchmac_ctx_size(_ stateSize: Int, _ blockSize: Int) -> Int +{ + ccdigest_ctx_size(stateSize, blockSize) + stateSize +} + +public func cchmac_di_size(_ digestInfo: UnsafePointer) -> Int +{ + if #available(iOS 14, macOS 11, *) + { + // CoreCrypto headers aren't accurate for iOS 14 or macOS 11 yet, + // so return bigger buffer size to ensure against invalid memory access. + return cchmac_ctx_size(digestInfo.pointee.state_size, digestInfo.pointee.block_size) * 2 + } + else + { + return cchmac_ctx_size(digestInfo.pointee.state_size, digestInfo.pointee.block_size) + } +} diff --git a/Dependencies/corecrypto/ccsrp.m b/Dependencies/corecrypto/Sources/ccsrp.m similarity index 100% rename from Dependencies/corecrypto/ccsrp.m rename to Dependencies/corecrypto/Sources/ccsrp.m diff --git a/Dependencies/corecrypto/cc.h b/Dependencies/corecrypto/include/corecrypto/cc.h similarity index 100% rename from Dependencies/corecrypto/cc.h rename to Dependencies/corecrypto/include/corecrypto/cc.h diff --git a/Dependencies/corecrypto/cc_config.h b/Dependencies/corecrypto/include/corecrypto/cc_config.h similarity index 100% rename from Dependencies/corecrypto/cc_config.h rename to Dependencies/corecrypto/include/corecrypto/cc_config.h diff --git a/Dependencies/corecrypto/cc_debug.h b/Dependencies/corecrypto/include/corecrypto/cc_debug.h similarity index 100% rename from Dependencies/corecrypto/cc_debug.h rename to Dependencies/corecrypto/include/corecrypto/cc_debug.h diff --git a/Dependencies/corecrypto/cc_memory.h b/Dependencies/corecrypto/include/corecrypto/cc_memory.h similarity index 100% rename from Dependencies/corecrypto/cc_memory.h rename to Dependencies/corecrypto/include/corecrypto/cc_memory.h diff --git a/Dependencies/corecrypto/cc_priv.h b/Dependencies/corecrypto/include/corecrypto/cc_priv.h similarity index 100% rename from Dependencies/corecrypto/cc_priv.h rename to Dependencies/corecrypto/include/corecrypto/cc_priv.h diff --git a/Dependencies/corecrypto/cc_runtime_config.h b/Dependencies/corecrypto/include/corecrypto/cc_runtime_config.h similarity index 100% rename from Dependencies/corecrypto/cc_runtime_config.h rename to Dependencies/corecrypto/include/corecrypto/cc_runtime_config.h diff --git a/Dependencies/corecrypto/ccaes.h b/Dependencies/corecrypto/include/corecrypto/ccaes.h similarity index 100% rename from Dependencies/corecrypto/ccaes.h rename to Dependencies/corecrypto/include/corecrypto/ccaes.h diff --git a/Dependencies/corecrypto/ccansikdf.h b/Dependencies/corecrypto/include/corecrypto/ccansikdf.h similarity index 100% rename from Dependencies/corecrypto/ccansikdf.h rename to Dependencies/corecrypto/include/corecrypto/ccansikdf.h diff --git a/Dependencies/corecrypto/ccasn1.h b/Dependencies/corecrypto/include/corecrypto/ccasn1.h similarity index 100% rename from Dependencies/corecrypto/ccasn1.h rename to Dependencies/corecrypto/include/corecrypto/ccasn1.h diff --git a/Dependencies/corecrypto/ccblowfish.h b/Dependencies/corecrypto/include/corecrypto/ccblowfish.h similarity index 100% rename from Dependencies/corecrypto/ccblowfish.h rename to Dependencies/corecrypto/include/corecrypto/ccblowfish.h diff --git a/Dependencies/corecrypto/cccast.h b/Dependencies/corecrypto/include/corecrypto/cccast.h similarity index 100% rename from Dependencies/corecrypto/cccast.h rename to Dependencies/corecrypto/include/corecrypto/cccast.h diff --git a/Dependencies/corecrypto/ccchacha20poly1305.h b/Dependencies/corecrypto/include/corecrypto/ccchacha20poly1305.h similarity index 100% rename from Dependencies/corecrypto/ccchacha20poly1305.h rename to Dependencies/corecrypto/include/corecrypto/ccchacha20poly1305.h diff --git a/Dependencies/corecrypto/ccchacha20poly1305_priv.h b/Dependencies/corecrypto/include/corecrypto/ccchacha20poly1305_priv.h similarity index 100% rename from Dependencies/corecrypto/ccchacha20poly1305_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccchacha20poly1305_priv.h diff --git a/Dependencies/corecrypto/cccmac.h b/Dependencies/corecrypto/include/corecrypto/cccmac.h similarity index 100% rename from Dependencies/corecrypto/cccmac.h rename to Dependencies/corecrypto/include/corecrypto/cccmac.h diff --git a/Dependencies/corecrypto/ccder.h b/Dependencies/corecrypto/include/corecrypto/ccder.h similarity index 100% rename from Dependencies/corecrypto/ccder.h rename to Dependencies/corecrypto/include/corecrypto/ccder.h diff --git a/Dependencies/corecrypto/ccder_decode_eckey.h b/Dependencies/corecrypto/include/corecrypto/ccder_decode_eckey.h similarity index 100% rename from Dependencies/corecrypto/ccder_decode_eckey.h rename to Dependencies/corecrypto/include/corecrypto/ccder_decode_eckey.h diff --git a/Dependencies/corecrypto/ccder_encode_eckey.h b/Dependencies/corecrypto/include/corecrypto/ccder_encode_eckey.h similarity index 100% rename from Dependencies/corecrypto/ccder_encode_eckey.h rename to Dependencies/corecrypto/include/corecrypto/ccder_encode_eckey.h diff --git a/Dependencies/corecrypto/ccder_priv.h b/Dependencies/corecrypto/include/corecrypto/ccder_priv.h similarity index 100% rename from Dependencies/corecrypto/ccder_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccder_priv.h diff --git a/Dependencies/corecrypto/ccder_rsa.h b/Dependencies/corecrypto/include/corecrypto/ccder_rsa.h similarity index 100% rename from Dependencies/corecrypto/ccder_rsa.h rename to Dependencies/corecrypto/include/corecrypto/ccder_rsa.h diff --git a/Dependencies/corecrypto/ccdes.h b/Dependencies/corecrypto/include/corecrypto/ccdes.h similarity index 100% rename from Dependencies/corecrypto/ccdes.h rename to Dependencies/corecrypto/include/corecrypto/ccdes.h diff --git a/Dependencies/corecrypto/ccdh.h b/Dependencies/corecrypto/include/corecrypto/ccdh.h similarity index 100% rename from Dependencies/corecrypto/ccdh.h rename to Dependencies/corecrypto/include/corecrypto/ccdh.h diff --git a/Dependencies/corecrypto/ccdh_gp.h b/Dependencies/corecrypto/include/corecrypto/ccdh_gp.h similarity index 100% rename from Dependencies/corecrypto/ccdh_gp.h rename to Dependencies/corecrypto/include/corecrypto/ccdh_gp.h diff --git a/Dependencies/corecrypto/ccdh_priv.h b/Dependencies/corecrypto/include/corecrypto/ccdh_priv.h similarity index 100% rename from Dependencies/corecrypto/ccdh_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccdh_priv.h diff --git a/Dependencies/corecrypto/ccdigest.h b/Dependencies/corecrypto/include/corecrypto/ccdigest.h similarity index 100% rename from Dependencies/corecrypto/ccdigest.h rename to Dependencies/corecrypto/include/corecrypto/ccdigest.h diff --git a/Dependencies/corecrypto/ccdigest_priv.h b/Dependencies/corecrypto/include/corecrypto/ccdigest_priv.h similarity index 100% rename from Dependencies/corecrypto/ccdigest_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccdigest_priv.h diff --git a/Dependencies/corecrypto/ccdrbg.h b/Dependencies/corecrypto/include/corecrypto/ccdrbg.h similarity index 100% rename from Dependencies/corecrypto/ccdrbg.h rename to Dependencies/corecrypto/include/corecrypto/ccdrbg.h diff --git a/Dependencies/corecrypto/ccdrbg_factory.h b/Dependencies/corecrypto/include/corecrypto/ccdrbg_factory.h similarity index 100% rename from Dependencies/corecrypto/ccdrbg_factory.h rename to Dependencies/corecrypto/include/corecrypto/ccdrbg_factory.h diff --git a/Dependencies/corecrypto/ccdrbg_impl.h b/Dependencies/corecrypto/include/corecrypto/ccdrbg_impl.h similarity index 100% rename from Dependencies/corecrypto/ccdrbg_impl.h rename to Dependencies/corecrypto/include/corecrypto/ccdrbg_impl.h diff --git a/Dependencies/corecrypto/ccec.h b/Dependencies/corecrypto/include/corecrypto/ccec.h similarity index 100% rename from Dependencies/corecrypto/ccec.h rename to Dependencies/corecrypto/include/corecrypto/ccec.h diff --git a/Dependencies/corecrypto/ccec25519.h b/Dependencies/corecrypto/include/corecrypto/ccec25519.h similarity index 100% rename from Dependencies/corecrypto/ccec25519.h rename to Dependencies/corecrypto/include/corecrypto/ccec25519.h diff --git a/Dependencies/corecrypto/ccec25519_priv.h b/Dependencies/corecrypto/include/corecrypto/ccec25519_priv.h similarity index 100% rename from Dependencies/corecrypto/ccec25519_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccec25519_priv.h diff --git a/Dependencies/corecrypto/ccec_priv.h b/Dependencies/corecrypto/include/corecrypto/ccec_priv.h similarity index 100% rename from Dependencies/corecrypto/ccec_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccec_priv.h diff --git a/Dependencies/corecrypto/ccecies.h b/Dependencies/corecrypto/include/corecrypto/ccecies.h similarity index 100% rename from Dependencies/corecrypto/ccecies.h rename to Dependencies/corecrypto/include/corecrypto/ccecies.h diff --git a/Dependencies/corecrypto/ccecies_priv.h b/Dependencies/corecrypto/include/corecrypto/ccecies_priv.h similarity index 100% rename from Dependencies/corecrypto/ccecies_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccecies_priv.h diff --git a/Dependencies/corecrypto/cchkdf.h b/Dependencies/corecrypto/include/corecrypto/cchkdf.h similarity index 100% rename from Dependencies/corecrypto/cchkdf.h rename to Dependencies/corecrypto/include/corecrypto/cchkdf.h diff --git a/Dependencies/corecrypto/cchmac.h b/Dependencies/corecrypto/include/corecrypto/cchmac.h similarity index 100% rename from Dependencies/corecrypto/cchmac.h rename to Dependencies/corecrypto/include/corecrypto/cchmac.h diff --git a/Dependencies/corecrypto/ccmd2.h b/Dependencies/corecrypto/include/corecrypto/ccmd2.h similarity index 100% rename from Dependencies/corecrypto/ccmd2.h rename to Dependencies/corecrypto/include/corecrypto/ccmd2.h diff --git a/Dependencies/corecrypto/ccmd4.h b/Dependencies/corecrypto/include/corecrypto/ccmd4.h similarity index 100% rename from Dependencies/corecrypto/ccmd4.h rename to Dependencies/corecrypto/include/corecrypto/ccmd4.h diff --git a/Dependencies/corecrypto/ccmd5.h b/Dependencies/corecrypto/include/corecrypto/ccmd5.h similarity index 100% rename from Dependencies/corecrypto/ccmd5.h rename to Dependencies/corecrypto/include/corecrypto/ccmd5.h diff --git a/Dependencies/corecrypto/ccmode.h b/Dependencies/corecrypto/include/corecrypto/ccmode.h similarity index 100% rename from Dependencies/corecrypto/ccmode.h rename to Dependencies/corecrypto/include/corecrypto/ccmode.h diff --git a/Dependencies/corecrypto/ccmode_factory.h b/Dependencies/corecrypto/include/corecrypto/ccmode_factory.h similarity index 100% rename from Dependencies/corecrypto/ccmode_factory.h rename to Dependencies/corecrypto/include/corecrypto/ccmode_factory.h diff --git a/Dependencies/corecrypto/ccmode_impl.h b/Dependencies/corecrypto/include/corecrypto/ccmode_impl.h similarity index 100% rename from Dependencies/corecrypto/ccmode_impl.h rename to Dependencies/corecrypto/include/corecrypto/ccmode_impl.h diff --git a/Dependencies/corecrypto/ccmode_siv.h b/Dependencies/corecrypto/include/corecrypto/ccmode_siv.h similarity index 100% rename from Dependencies/corecrypto/ccmode_siv.h rename to Dependencies/corecrypto/include/corecrypto/ccmode_siv.h diff --git a/Dependencies/corecrypto/ccmode_siv_priv.h b/Dependencies/corecrypto/include/corecrypto/ccmode_siv_priv.h similarity index 100% rename from Dependencies/corecrypto/ccmode_siv_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccmode_siv_priv.h diff --git a/Dependencies/corecrypto/ccn.h b/Dependencies/corecrypto/include/corecrypto/ccn.h similarity index 100% rename from Dependencies/corecrypto/ccn.h rename to Dependencies/corecrypto/include/corecrypto/ccn.h diff --git a/Dependencies/corecrypto/ccn_priv.h b/Dependencies/corecrypto/include/corecrypto/ccn_priv.h similarity index 100% rename from Dependencies/corecrypto/ccn_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccn_priv.h diff --git a/Dependencies/corecrypto/ccnistkdf.h b/Dependencies/corecrypto/include/corecrypto/ccnistkdf.h similarity index 100% rename from Dependencies/corecrypto/ccnistkdf.h rename to Dependencies/corecrypto/include/corecrypto/ccnistkdf.h diff --git a/Dependencies/corecrypto/ccpad.h b/Dependencies/corecrypto/include/corecrypto/ccpad.h similarity index 100% rename from Dependencies/corecrypto/ccpad.h rename to Dependencies/corecrypto/include/corecrypto/ccpad.h diff --git a/Dependencies/corecrypto/ccpbkdf2.h b/Dependencies/corecrypto/include/corecrypto/ccpbkdf2.h similarity index 100% rename from Dependencies/corecrypto/ccpbkdf2.h rename to Dependencies/corecrypto/include/corecrypto/ccpbkdf2.h diff --git a/Dependencies/corecrypto/ccperf.h b/Dependencies/corecrypto/include/corecrypto/ccperf.h similarity index 100% rename from Dependencies/corecrypto/ccperf.h rename to Dependencies/corecrypto/include/corecrypto/ccperf.h diff --git a/Dependencies/corecrypto/ccprime.h b/Dependencies/corecrypto/include/corecrypto/ccprime.h similarity index 100% rename from Dependencies/corecrypto/ccprime.h rename to Dependencies/corecrypto/include/corecrypto/ccprime.h diff --git a/Dependencies/corecrypto/ccrc2.h b/Dependencies/corecrypto/include/corecrypto/ccrc2.h similarity index 100% rename from Dependencies/corecrypto/ccrc2.h rename to Dependencies/corecrypto/include/corecrypto/ccrc2.h diff --git a/Dependencies/corecrypto/ccrc4.h b/Dependencies/corecrypto/include/corecrypto/ccrc4.h similarity index 100% rename from Dependencies/corecrypto/ccrc4.h rename to Dependencies/corecrypto/include/corecrypto/ccrc4.h diff --git a/Dependencies/corecrypto/ccripemd.h b/Dependencies/corecrypto/include/corecrypto/ccripemd.h similarity index 100% rename from Dependencies/corecrypto/ccripemd.h rename to Dependencies/corecrypto/include/corecrypto/ccripemd.h diff --git a/Dependencies/corecrypto/ccrng.h b/Dependencies/corecrypto/include/corecrypto/ccrng.h similarity index 100% rename from Dependencies/corecrypto/ccrng.h rename to Dependencies/corecrypto/include/corecrypto/ccrng.h diff --git a/Dependencies/corecrypto/ccrng_drbg.h b/Dependencies/corecrypto/include/corecrypto/ccrng_drbg.h similarity index 100% rename from Dependencies/corecrypto/ccrng_drbg.h rename to Dependencies/corecrypto/include/corecrypto/ccrng_drbg.h diff --git a/Dependencies/corecrypto/ccrng_ecfips_test.h b/Dependencies/corecrypto/include/corecrypto/ccrng_ecfips_test.h similarity index 100% rename from Dependencies/corecrypto/ccrng_ecfips_test.h rename to Dependencies/corecrypto/include/corecrypto/ccrng_ecfips_test.h diff --git a/Dependencies/corecrypto/ccrng_pbkdf2_prng.h b/Dependencies/corecrypto/include/corecrypto/ccrng_pbkdf2_prng.h similarity index 100% rename from Dependencies/corecrypto/ccrng_pbkdf2_prng.h rename to Dependencies/corecrypto/include/corecrypto/ccrng_pbkdf2_prng.h diff --git a/Dependencies/corecrypto/ccrng_priv.h b/Dependencies/corecrypto/include/corecrypto/ccrng_priv.h similarity index 100% rename from Dependencies/corecrypto/ccrng_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccrng_priv.h diff --git a/Dependencies/corecrypto/ccrng_rsafips_test.h b/Dependencies/corecrypto/include/corecrypto/ccrng_rsafips_test.h similarity index 100% rename from Dependencies/corecrypto/ccrng_rsafips_test.h rename to Dependencies/corecrypto/include/corecrypto/ccrng_rsafips_test.h diff --git a/Dependencies/corecrypto/ccrng_sequence.h b/Dependencies/corecrypto/include/corecrypto/ccrng_sequence.h similarity index 100% rename from Dependencies/corecrypto/ccrng_sequence.h rename to Dependencies/corecrypto/include/corecrypto/ccrng_sequence.h diff --git a/Dependencies/corecrypto/ccrng_system.h b/Dependencies/corecrypto/include/corecrypto/ccrng_system.h similarity index 100% rename from Dependencies/corecrypto/ccrng_system.h rename to Dependencies/corecrypto/include/corecrypto/ccrng_system.h diff --git a/Dependencies/corecrypto/ccrng_test.h b/Dependencies/corecrypto/include/corecrypto/ccrng_test.h similarity index 100% rename from Dependencies/corecrypto/ccrng_test.h rename to Dependencies/corecrypto/include/corecrypto/ccrng_test.h diff --git a/Dependencies/corecrypto/ccrsa.h b/Dependencies/corecrypto/include/corecrypto/ccrsa.h similarity index 100% rename from Dependencies/corecrypto/ccrsa.h rename to Dependencies/corecrypto/include/corecrypto/ccrsa.h diff --git a/Dependencies/corecrypto/ccrsa_priv.h b/Dependencies/corecrypto/include/corecrypto/ccrsa_priv.h similarity index 100% rename from Dependencies/corecrypto/ccrsa_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccrsa_priv.h diff --git a/Dependencies/corecrypto/ccsha1.h b/Dependencies/corecrypto/include/corecrypto/ccsha1.h similarity index 100% rename from Dependencies/corecrypto/ccsha1.h rename to Dependencies/corecrypto/include/corecrypto/ccsha1.h diff --git a/Dependencies/corecrypto/ccsha2.h b/Dependencies/corecrypto/include/corecrypto/ccsha2.h similarity index 100% rename from Dependencies/corecrypto/ccsha2.h rename to Dependencies/corecrypto/include/corecrypto/ccsha2.h diff --git a/Dependencies/corecrypto/ccsrp.h b/Dependencies/corecrypto/include/corecrypto/ccsrp.h similarity index 100% rename from Dependencies/corecrypto/ccsrp.h rename to Dependencies/corecrypto/include/corecrypto/ccsrp.h diff --git a/Dependencies/corecrypto/ccsrp_gp.h b/Dependencies/corecrypto/include/corecrypto/ccsrp_gp.h similarity index 100% rename from Dependencies/corecrypto/ccsrp_gp.h rename to Dependencies/corecrypto/include/corecrypto/ccsrp_gp.h diff --git a/Dependencies/corecrypto/cctest.h b/Dependencies/corecrypto/include/corecrypto/cctest.h similarity index 100% rename from Dependencies/corecrypto/cctest.h rename to Dependencies/corecrypto/include/corecrypto/cctest.h diff --git a/Dependencies/corecrypto/ccwrap.h b/Dependencies/corecrypto/include/corecrypto/ccwrap.h similarity index 100% rename from Dependencies/corecrypto/ccwrap.h rename to Dependencies/corecrypto/include/corecrypto/ccwrap.h diff --git a/Dependencies/corecrypto/ccz.h b/Dependencies/corecrypto/include/corecrypto/ccz.h similarity index 100% rename from Dependencies/corecrypto/ccz.h rename to Dependencies/corecrypto/include/corecrypto/ccz.h diff --git a/Dependencies/corecrypto/ccz_priv.h b/Dependencies/corecrypto/include/corecrypto/ccz_priv.h similarity index 100% rename from Dependencies/corecrypto/ccz_priv.h rename to Dependencies/corecrypto/include/corecrypto/ccz_priv.h diff --git a/Dependencies/corecrypto/cczp.h b/Dependencies/corecrypto/include/corecrypto/cczp.h similarity index 100% rename from Dependencies/corecrypto/cczp.h rename to Dependencies/corecrypto/include/corecrypto/cczp.h diff --git a/Dependencies/corecrypto/cczp_priv.h b/Dependencies/corecrypto/include/corecrypto/cczp_priv.h similarity index 100% rename from Dependencies/corecrypto/cczp_priv.h rename to Dependencies/corecrypto/include/corecrypto/cczp_priv.h diff --git a/Dependencies/corecrypto/fipspost.h b/Dependencies/corecrypto/include/corecrypto/fipspost.h similarity index 100% rename from Dependencies/corecrypto/fipspost.h rename to Dependencies/corecrypto/include/corecrypto/fipspost.h diff --git a/Dependencies/corecrypto/include/module.modulemap b/Dependencies/corecrypto/include/module.modulemap new file mode 100644 index 0000000..4d09cf4 --- /dev/null +++ b/Dependencies/corecrypto/include/module.modulemap @@ -0,0 +1,14 @@ +module CCoreCrypto [system] { + header "corecrypto/ccsrp.h" + header "corecrypto/ccdrbg.h" + header "corecrypto/ccsrp_gp.h" + header "corecrypto/ccdigest.h" + header "corecrypto/ccsha2.h" + header "corecrypto/ccpbkdf2.h" + header "corecrypto/cchmac.h" + header "corecrypto/ccaes.h" + header "corecrypto/ccpad.h" + header "corecrypto/ccn.h" + + export * +} diff --git a/Dependencies/ldid b/Dependencies/ldid index 4f9427f..6a6a92d 160000 --- a/Dependencies/ldid +++ b/Dependencies/ldid @@ -1 +1 @@ -Subproject commit 4f9427f833b16bacfae248bd99e463d0e7cc0589 +Subproject commit 6a6a92de56ae2110e4d6f292b315df0f586d6af5 diff --git a/Dependencies/minizip/ChangeLogUnzip b/Dependencies/minizip/ChangeLogUnzip deleted file mode 100644 index e62af14..0000000 --- a/Dependencies/minizip/ChangeLogUnzip +++ /dev/null @@ -1,67 +0,0 @@ -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 (submited by 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) diff --git a/Dependencies/minizip/Makefile b/Dependencies/minizip/Makefile index fbba3ac..84eaad2 100644 --- a/Dependencies/minizip/Makefile +++ b/Dependencies/minizip/Makefile @@ -1,25 +1,25 @@ -CC=cc -CFLAGS=-O -I../.. - -UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a -ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a - -.c.o: - $(CC) -c $(CFLAGS) $*.c - -all: miniunz minizip - -miniunz: $(UNZ_OBJS) - $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) - -minizip: $(ZIP_OBJS) - $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) - -test: miniunz minizip - ./minizip test readme.txt - ./miniunz -l test.zip - mv readme.txt readme.old - ./miniunz test.zip - -clean: - /bin/rm -f *.o *~ minizip miniunz +CC=cc +CFLAGS=-O -I../.. + +UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a +ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a + +.c.o: + $(CC) -c $(CFLAGS) $*.c + +all: miniunz minizip + +miniunz: $(UNZ_OBJS) + $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) + +minizip: $(ZIP_OBJS) + $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) + +test: miniunz minizip + ./minizip test readme.txt + ./miniunz -l test.zip + mv readme.txt readme.old + ./miniunz test.zip + +clean: + /bin/rm -f *.o *~ minizip miniunz diff --git a/Dependencies/minizip/Makefile.am b/Dependencies/minizip/Makefile.am new file mode 100644 index 0000000..d343011 --- /dev/null +++ b/Dependencies/minizip/Makefile.am @@ -0,0 +1,45 @@ +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 \ + mztools.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 \ + mztools.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 diff --git a/Dependencies/minizip/MiniZip64_Changes.txt b/Dependencies/minizip/MiniZip64_Changes.txt new file mode 100644 index 0000000..13a1bd9 --- /dev/null +++ b/Dependencies/minizip/MiniZip64_Changes.txt @@ -0,0 +1,6 @@ + +MiniZip 1.1 was derrived from MiniZip at version 1.01f + +Change in 1.0 (Okt 2009) + - **TODO - Add history** + diff --git a/Dependencies/minizip/MiniZip64_info.txt b/Dependencies/minizip/MiniZip64_info.txt new file mode 100644 index 0000000..57d7152 --- /dev/null +++ b/Dependencies/minizip/MiniZip64_info.txt @@ -0,0 +1,74 @@ +MiniZip - Copyright (c) 1998-2010 - by Gilles Vollant - version 1.1 64 bits from Mathias Svensson + +Introduction +--------------------- +MiniZip 1.1 is built from MiniZip 1.0 by Gilles Vollant ( http://www.winimage.com/zLibDll/minizip.html ) + +When adding ZIP64 support into minizip it would result into risk of breaking compatibility with minizip 1.0. +All possible work was done for compatibility. + + +Background +--------------------- +When adding ZIP64 support Mathias Svensson found that Even Rouault have added ZIP64 +support for unzip.c into minizip for a open source project called gdal ( http://www.gdal.org/ ) + +That was used as a starting point. And after that ZIP64 support was added to zip.c +some refactoring and code cleanup was also done. + + +Changed from MiniZip 1.0 to MiniZip 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 + Daniel Borca - BZip Compression method support in unzip + Mathias Svensson - ZIP64 zip support + Mathias Svensson - BZip Compression method support in zip + + Resources + + ZipLayout http://result42.com/projects/ZipFileLayout + Command line tool for Windows that shows the layout and information of the headers in a zip archive. + Used when debugging and validating the creation of zip files using MiniZip64 + + + ZIP App Note http://www.pkware.com/documents/casestudies/APPNOTE.TXT + Zip File specification + + +Notes. + * To be able to use BZip compression method in zip64.c or unzip64.c the BZIP2 lib is needed and HAVE_BZIP2 need to be defined. + +License +---------------------------------------------------------- + Condition of use and distribution are the same than 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 acknowledgment 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. + +---------------------------------------------------------- + diff --git a/Dependencies/minizip/configure.ac b/Dependencies/minizip/configure.ac new file mode 100644 index 0000000..5b11970 --- /dev/null +++ b/Dependencies/minizip/configure.ac @@ -0,0 +1,32 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_INIT([minizip], [1.2.11], [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 diff --git a/Dependencies/minizip/crypt.h b/Dependencies/minizip/crypt.h index f14a628..1e9e820 100644 --- a/Dependencies/minizip/crypt.h +++ b/Dependencies/minizip/crypt.h @@ -1,132 +1,131 @@ -/* crypt.h -- base code for crypt/uncrypt ZIPfile - - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This code is a modified version of crypting code in Infozip distribution - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - - If you don't need crypting in your application, just define symbols - NOCRYPT and NOUNCRYPT. - - This code support the "Traditional PKWARE Encryption". - - The new AES encryption added on Zip format by Winzip (see the page - http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong - Encryption is not supported. -*/ - -#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) - -/*********************************************************************** - * Return the next byte in the pseudo-random sequence - */ -static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) -{ - unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an - * unpredictable manner on 16-bit systems; not a problem - * with any known compiler so far, though */ - - temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; - return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); -} - -/*********************************************************************** - * 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) -{ - (*(pkeys+0)) = CRC32((*(pkeys+0)), c); - (*(pkeys+1)) += (*(pkeys+0)) & 0xff; - (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; - { - register int keyshift = (int)((*(pkeys+1)) >> 24); - (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); - } - return c; -} - - -/*********************************************************************** - * 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) -{ - *(pkeys+0) = 305419896L; - *(pkeys+1) = 591751049L; - *(pkeys+2) = 878082192L; - 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))) - -#define zencode(pkeys,pcrc_32_tab,c,t) \ - (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) - -#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED - -#define RAND_HEAD_LEN 12 - /* "last resort" source for second part of crypt seed pattern */ -# ifndef ZCR_SEED2 -# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ -# endif - -static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) - const char *passwd; /* password string */ - unsigned char *buf; /* where to write header */ - int bufSize; - unsigned long* pkeys; - const unsigned long* pcrc_32_tab; - unsigned long crcForCrypting; -{ - int n; /* index in random header */ - int t; /* temporary */ - int c; /* random byte */ - unsigned char header[RAND_HEAD_LEN-2]; /* random header */ - static unsigned calls = 0; /* ensure different random header each time */ - - if (bufSize> 7) & 0xff; - header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); - } - /* Encrypt random header (last two bytes is high word of crc) */ - init_keys(passwd, pkeys, pcrc_32_tab); - for (n = 0; n < RAND_HEAD_LEN-2; n++) - { - buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); - } - buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); - buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); - return n; -} - -#endif +/* crypt.h -- base code for crypt/uncrypt ZIPfile + + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This code is a modified version of crypting code in Infozip distribution + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + If you don't need crypting in your application, just define symbols + NOCRYPT and NOUNCRYPT. + + This code support the "Traditional PKWARE Encryption". + + The new AES encryption added on Zip format by Winzip (see the page + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong + Encryption is not supported. +*/ + +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) + +/*********************************************************************** + * Return the next byte in the pseudo-random sequence + */ +static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) +{ + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an + * unpredictable manner on 16-bit systems; not a problem + * with any known compiler so far, though */ + + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); +} + +/*********************************************************************** + * Update the encryption keys with the next byte of plain text + */ +static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c) +{ + (*(pkeys+0)) = CRC32((*(pkeys+0)), c); + (*(pkeys+1)) += (*(pkeys+0)) & 0xff; + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; + { + register int keyshift = (int)((*(pkeys+1)) >> 24); + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); + } + return c; +} + + +/*********************************************************************** + * Initialize the encryption keys and the random header according to + * the given password. + */ +static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab) +{ + *(pkeys+0) = 305419896L; + *(pkeys+1) = 591751049L; + *(pkeys+2) = 878082192L; + while (*passwd != '\0') { + update_keys(pkeys,pcrc_32_tab,(int)*passwd); + passwd++; + } +} + +#define zdecode(pkeys,pcrc_32_tab,c) \ + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) + +#define zencode(pkeys,pcrc_32_tab,c,t) \ + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) + +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED + +#define RAND_HEAD_LEN 12 + /* "last resort" source for second part of crypt seed pattern */ +# ifndef ZCR_SEED2 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ +# endif + +static int crypthead(const char* passwd, /* password string */ + unsigned char* buf, /* where to write header */ + int bufSize, + unsigned long* pkeys, + const z_crc_t* pcrc_32_tab, + unsigned long crcForCrypting) +{ + int n; /* index in random header */ + int t; /* temporary */ + int c; /* random byte */ + unsigned char header[RAND_HEAD_LEN-2]; /* random header */ + static unsigned calls = 0; /* ensure different random header each time */ + + if (bufSize> 7) & 0xff; + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); + } + /* Encrypt random header (last two bytes is high word of crc) */ + init_keys(passwd, pkeys, pcrc_32_tab); + for (n = 0; n < RAND_HEAD_LEN-2; n++) + { + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); + } + buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); + buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); + return n; +} + +#endif diff --git a/Dependencies/minizip/ioapi.c b/Dependencies/minizip/ioapi.c index 7f20c18..7f5c191 100644 --- a/Dependencies/minizip/ioapi.c +++ b/Dependencies/minizip/ioapi.c @@ -1,177 +1,247 @@ -/* ioapi.c -- IO base function header for compress/uncompress .zip - files using zlib + zip or unzip API - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant -*/ - -#include -#include -#include - -#include "zlib.h" -#include "ioapi.h" - - - -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -voidpf ZCALLBACK fopen_file_func OF(( - voidpf opaque, - const char* filename, - int mode)); - -uLong ZCALLBACK fread_file_func OF(( - voidpf opaque, - voidpf stream, - void* buf, - uLong size)); - -uLong ZCALLBACK fwrite_file_func OF(( - voidpf opaque, - voidpf stream, - const void* buf, - uLong size)); - -long ZCALLBACK ftell_file_func OF(( - voidpf opaque, - voidpf stream)); - -long ZCALLBACK fseek_file_func OF(( - voidpf opaque, - voidpf stream, - uLong offset, - int origin)); - -int ZCALLBACK fclose_file_func OF(( - voidpf opaque, - voidpf stream)); - -int ZCALLBACK ferror_file_func OF(( - voidpf opaque, - voidpf stream)); - - -voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) - voidpf opaque; - const char* filename; - int mode; -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - file = fopen(filename, mode_fopen); - return file; -} - - -uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) - voidpf opaque; - voidpf stream; - void* buf; - uLong size; -{ - uLong ret; - ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - - -uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) - voidpf opaque; - voidpf stream; - const void* buf; - uLong size; -{ - uLong ret; - ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -long ZCALLBACK ftell_file_func (opaque, stream) - voidpf opaque; - voidpf stream; -{ - long ret; - ret = ftell((FILE *)stream); - return ret; -} - -long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) - voidpf opaque; - voidpf stream; - uLong offset; - int origin; -{ - int fseek_origin=0; - long ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - ret = 0; - fseek((FILE *)stream, offset, fseek_origin); - return ret; -} - -int ZCALLBACK fclose_file_func (opaque, stream) - voidpf opaque; - voidpf stream; -{ - int ret; - ret = fclose((FILE *)stream); - return ret; -} - -int ZCALLBACK ferror_file_func (opaque, stream) - voidpf opaque; - voidpf stream; -{ - int ret; - ret = ferror((FILE *)stream); - return ret; -} - -void fill_fopen_filefunc (pzlib_filefunc_def) - zlib_filefunc_def* pzlib_filefunc_def; -{ - pzlib_filefunc_def->zopen_file = fopen_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell_file = ftell_file_func; - pzlib_filefunc_def->zseek_file = fseek_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} +/* ioapi.h -- IO base function header for compress/uncompress .zip + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + +*/ + +#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) + #define _CRT_SECURE_NO_WARNINGS +#endif + +#if defined(__APPLE__) || defined(IOAPI_NO_64) +// 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 "ioapi.h" + +voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) +{ + if (pfilefunc->zfile_func64.zopen64_file != NULL) + return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); + else + { + return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); + } +} + +long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) +{ + if (pfilefunc->zfile_func64.zseek64_file != NULL) + return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); + else + { + uLong offsetTruncated = (uLong)offset; + if (offsetTruncated != offset) + return -1; + else + return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); + } +} + +ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) +{ + if (pfilefunc->zfile_func64.zseek64_file != NULL) + return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); + else + { + uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); + if ((tell_uLong) == MAXU32) + return (ZPOS64_T)-1; + else + return tell_uLong; + } +} + +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) +{ + p_filefunc64_32->zfile_func64.zopen64_file = NULL; + p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; + p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; + p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; + p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; + p_filefunc64_32->zfile_func64.ztell64_file = NULL; + p_filefunc64_32->zfile_func64.zseek64_file = NULL; + p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; + p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; + p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; + p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; + p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; +} + + + +static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); +static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); +static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); +static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); +static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); +static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); + +static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) +{ + FILE* file = NULL; + const char* mode_fopen = NULL; + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) + mode_fopen = "rb"; + else + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + mode_fopen = "r+b"; + else + if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mode_fopen = "wb"; + + if ((filename!=NULL) && (mode_fopen != NULL)) + file = fopen(filename, mode_fopen); + return file; +} + +static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) +{ + FILE* file = NULL; + const char* mode_fopen = NULL; + if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) + mode_fopen = "rb"; + else + if (mode & ZLIB_FILEFUNC_MODE_EXISTING) + mode_fopen = "r+b"; + else + if (mode & ZLIB_FILEFUNC_MODE_CREATE) + mode_fopen = "wb"; + + if ((filename!=NULL) && (mode_fopen != NULL)) + file = FOPEN_FUNC((const char*)filename, mode_fopen); + return file; +} + + +static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) +{ + uLong ret; + ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); + return ret; +} + +static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) +{ + uLong ret; + ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); + return ret; +} + +static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) +{ + long ret; + ret = ftell((FILE *)stream); + return ret; +} + + +static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) +{ + ZPOS64_T ret; + ret = FTELLO_FUNC((FILE *)stream); + return ret; +} + +static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) +{ + int fseek_origin=0; + long ret; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + fseek_origin = SEEK_CUR; + break; + case ZLIB_FILEFUNC_SEEK_END : + fseek_origin = SEEK_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + fseek_origin = SEEK_SET; + break; + default: return -1; + } + ret = 0; + if (fseek((FILE *)stream, offset, fseek_origin) != 0) + ret = -1; + return ret; +} + +static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) +{ + int fseek_origin=0; + long ret; + switch (origin) + { + case ZLIB_FILEFUNC_SEEK_CUR : + fseek_origin = SEEK_CUR; + break; + case ZLIB_FILEFUNC_SEEK_END : + fseek_origin = SEEK_END; + break; + case ZLIB_FILEFUNC_SEEK_SET : + fseek_origin = SEEK_SET; + break; + default: return -1; + } + ret = 0; + + if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) + ret = -1; + + return ret; +} + + +static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) +{ + int ret; + ret = fclose((FILE *)stream); + return ret; +} + +static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) +{ + int ret; + ret = ferror((FILE *)stream); + return ret; +} + +void fill_fopen_filefunc (pzlib_filefunc_def) + zlib_filefunc_def* pzlib_filefunc_def; +{ + pzlib_filefunc_def->zopen_file = fopen_file_func; + pzlib_filefunc_def->zread_file = fread_file_func; + pzlib_filefunc_def->zwrite_file = fwrite_file_func; + pzlib_filefunc_def->ztell_file = ftell_file_func; + pzlib_filefunc_def->zseek_file = fseek_file_func; + pzlib_filefunc_def->zclose_file = fclose_file_func; + pzlib_filefunc_def->zerror_file = ferror_file_func; + pzlib_filefunc_def->opaque = NULL; +} + +void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) +{ + pzlib_filefunc_def->zopen64_file = fopen64_file_func; + pzlib_filefunc_def->zread_file = fread_file_func; + pzlib_filefunc_def->zwrite_file = fwrite_file_func; + pzlib_filefunc_def->ztell64_file = ftell64_file_func; + pzlib_filefunc_def->zseek64_file = fseek64_file_func; + pzlib_filefunc_def->zclose_file = fclose_file_func; + pzlib_filefunc_def->zerror_file = ferror_file_func; + pzlib_filefunc_def->opaque = NULL; +} diff --git a/Dependencies/minizip/ioapi.h b/Dependencies/minizip/ioapi.h index e73a3b2..8dcbdb0 100644 --- a/Dependencies/minizip/ioapi.h +++ b/Dependencies/minizip/ioapi.h @@ -1,75 +1,208 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - files using zlib + zip or unzip API - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant -*/ - -#ifndef _ZLIBIOAPI_H -#define _ZLIBIOAPI_H - - -#define ZLIB_FILEFUNC_SEEK_CUR (1) -#define ZLIB_FILEFUNC_SEEK_END (2) -#define ZLIB_FILEFUNC_SEEK_SET (0) - -#define ZLIB_FILEFUNC_MODE_READ (1) -#define ZLIB_FILEFUNC_MODE_WRITE (2) -#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) - -#define ZLIB_FILEFUNC_MODE_EXISTING (4) -#define ZLIB_FILEFUNC_MODE_CREATE (8) - - -#ifndef ZCALLBACK - -#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) -#define ZCALLBACK CALLBACK -#else -#define ZCALLBACK -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); - -typedef struct zlib_filefunc_def_s -{ - open_file_func zopen_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell_file_func ztell_file; - seek_file_func zseek_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc_def; - - - -void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); - -#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) -#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) -#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) -#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) -#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) -#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) - - -#ifdef __cplusplus -} -#endif - -#endif - +/* ioapi.h -- IO base function header for compress/uncompress .zip + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + Changes + + Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) + Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. + More if/def section may be needed to support other platforms + Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. + (but you should use iowin32.c for windows instead) + +*/ + +#ifndef _ZLIBIOAPI64_H +#define _ZLIBIOAPI64_H + +#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) + + // Linux needs this to support file operation on files larger then 4+GB + // But might need better if/def to select just the platforms that needs them. + + #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 + +#include +#include +#include "zlib.h" + +#if defined(USE_FILE32API) +#define fopen64 fopen +#define ftello64 ftell +#define fseeko64 fseek +#else +#ifdef __FreeBSD__ +#define fopen64 fopen +#define ftello64 ftello +#define fseeko64 fseeko +#endif +#ifdef _MSC_VER + #define fopen64 fopen + #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) + #define ftello64 _ftelli64 + #define fseeko64 _fseeki64 + #else // old MSC + #define ftello64 ftell + #define fseeko64 fseek + #endif +#endif +#endif + +/* +#ifndef ZPOS64_T + #ifdef _WIN32 + #define ZPOS64_T fpos_t + #else + #include + #define ZPOS64_T uint64_t + #endif +#endif +*/ + +#ifdef HAVE_MINIZIP64_CONF_H +#include "mz64conf.h" +#endif + +/* a type choosen by DEFINE */ +#ifdef HAVE_64BIT_INT_CUSTOM +typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; +#else +#ifdef HAS_STDINT_H +#include "stdint.h" +typedef uint64_t ZPOS64_T; +#else + +/* Maximum unsigned 32-bit value used as placeholder for zip64 */ +#define MAXU32 0xffffffff + +#if defined(_MSC_VER) || defined(__BORLANDC__) +typedef unsigned __int64 ZPOS64_T; +#else +typedef unsigned long long int ZPOS64_T; +#endif +#endif +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + + +#define ZLIB_FILEFUNC_SEEK_CUR (1) +#define ZLIB_FILEFUNC_SEEK_END (2) +#define ZLIB_FILEFUNC_SEEK_SET (0) + +#define ZLIB_FILEFUNC_MODE_READ (1) +#define ZLIB_FILEFUNC_MODE_WRITE (2) +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) + +#define ZLIB_FILEFUNC_MODE_EXISTING (4) +#define ZLIB_FILEFUNC_MODE_CREATE (8) + + +#ifndef ZCALLBACK + #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) + #define ZCALLBACK CALLBACK + #else + #define ZCALLBACK + #endif +#endif + + + + +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); + +typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); +typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); + + +/* here is the "old" 32 bits structure structure */ +typedef struct zlib_filefunc_def_s +{ + open_file_func zopen_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell_file_func ztell_file; + seek_file_func zseek_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; +} zlib_filefunc_def; + +typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); +typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); +typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); + +typedef struct zlib_filefunc64_def_s +{ + open64_file_func zopen64_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell64_file_func ztell64_file; + seek64_file_func zseek64_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; +} zlib_filefunc64_def; + +void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); +void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); + +/* now internal definition, only for zip.c and unzip.h */ +typedef struct zlib_filefunc64_32_def_s +{ + zlib_filefunc64_def zfile_func64; + open_file_func zopen32_file; + tell_file_func ztell32_file; + seek_file_func zseek32_file; +} zlib_filefunc64_32_def; + + +#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) +#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) +//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) +//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) +#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) +#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) + +voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); +long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); +ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); + +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); + +#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) +#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) +#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/Dependencies/minizip/iowin32.c b/Dependencies/minizip/iowin32.c index 694bc03..274f39e 100644 --- a/Dependencies/minizip/iowin32.c +++ b/Dependencies/minizip/iowin32.c @@ -1,270 +1,462 @@ -/* iowin32.c -- IO base function header for compress/uncompress .zip - files using zlib + zip or unzip API - This IO API version uses the Win32 API (for Microsoft Windows) - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant -*/ - -#include - -#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 - -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)); - -long ZCALLBACK win32_tell_file_func OF(( - voidpf opaque, - voidpf stream)); - -long ZCALLBACK win32_seek_file_func OF(( - voidpf opaque, - voidpf stream, - uLong 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; -} WIN32FILE_IOWIN; - -voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode) - voidpf opaque; - const char* filename; - int mode; -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = 0; - voidpf ret=NULL; - - dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0; - - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - { - dwDesiredAccess = GENERIC_READ; - dwCreationDisposition = OPEN_EXISTING; - dwShareMode = FILE_SHARE_READ; - } - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - { - dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; - dwCreationDisposition = OPEN_EXISTING; - } - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - { - dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; - dwCreationDisposition = CREATE_ALWAYS; - } - - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, - dwCreationDisposition, dwFlagsAndAttributes, NULL); - - if (hFile == INVALID_HANDLE_VALUE) - hFile = NULL; - - if (hFile != NULL) - { - WIN32FILE_IOWIN w32fiow; - w32fiow.hf = hFile; - w32fiow.error = 0; - ret = malloc(sizeof(WIN32FILE_IOWIN)); - if (ret==NULL) - CloseHandle(hFile); - else *((WIN32FILE_IOWIN*)ret) = w32fiow; - } - return ret; -} - - -uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) - 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 (opaque, stream, buf, size) - 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; -} - -long ZCALLBACK win32_tell_file_func (opaque, stream) - voidpf opaque; - voidpf stream; -{ - long ret=-1; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - if (hFile != NULL) - { - DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); - if (dwSet == INVALID_SET_FILE_POINTER) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = -1; - } - else - ret=(long)dwSet; - } - return ret; -} - -long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) - 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) - { - DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); - if (dwSet == INVALID_SET_FILE_POINTER) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = -1; - } - else - ret=0; - } - return ret; -} - -int ZCALLBACK win32_close_file_func (opaque, stream) - voidpf opaque; - voidpf stream; -{ - int ret=-1; - - if (stream!=NULL) - { - HANDLE hFile; - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - if (hFile != NULL) - { - CloseHandle(hFile); - ret=0; - } - free(stream); - } - return ret; -} - -int ZCALLBACK win32_error_file_func (opaque, stream) - voidpf opaque; - voidpf stream; -{ - int ret=-1; - if (stream!=NULL) - { - ret = ((WIN32FILE_IOWIN*)stream) -> error; - } - return ret; -} - -void fill_win32_filefunc (pzlib_filefunc_def) - zlib_filefunc_def* pzlib_filefunc_def; -{ - pzlib_filefunc_def->zopen_file = win32_open_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; -} +/* iowin32.c -- IO base function header for compress/uncompress .zip + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + +*/ + +#include + +#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 + + +// see Include/shared/winapifamily.h in the Windows Kit +#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API))) +#if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP) +#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; +} 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) +{ + voidpf ret=NULL; + + if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) + { + WIN32FILE_IOWIN w32fiow; + w32fiow.hf = hFile; + w32fiow.error = 0; + ret = malloc(sizeof(WIN32FILE_IOWIN)); + + if (ret==NULL) + CloseHandle(hFile); + else + *((WIN32FILE_IOWIN*)ret) = w32fiow; + } + return ret; +} + +voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode) +{ + const char* mode_fopen = NULL; + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; + HANDLE hFile = NULL; + + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); + +#ifdef IOWIN32_USING_WINRT_API +#ifdef UNICODE + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); +#else + if ((filename!=NULL) && (dwDesiredAccess != 0)) + { + 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 + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); +#endif + + return win32_build_iowin(hFile); +} + + +voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) +{ + const char* mode_fopen = NULL; + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; + HANDLE hFile = NULL; + + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); + +#ifdef IOWIN32_USING_WINRT_API + if ((filename!=NULL) && (dwDesiredAccess != 0)) + { + 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 + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); +#endif + + return win32_build_iowin(hFile); +} + + +voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode) +{ + const char* mode_fopen = NULL; + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; + HANDLE hFile = NULL; + + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); + +#ifdef IOWIN32_USING_WINRT_API + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,NULL); +#else + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); +#endif + + return win32_build_iowin(hFile); +} + + +voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode) +{ + const char* mode_fopen = NULL; + DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; + HANDLE hFile = NULL; + + win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); + +#ifdef IOWIN32_USING_WINRT_API +#ifdef UNICODE + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); +#else + if ((filename!=NULL) && (dwDesiredAccess != 0)) + { + 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 + if ((filename!=NULL) && (dwDesiredAccess != 0)) + hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); +#endif + + return win32_build_iowin(hFile); +} + + +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 MySetFilePointerEx(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; + DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod); + BOOL fOk = TRUE; + if (dwNewPos == 0xFFFFFFFF) + if (GetLastError() != NO_ERROR) + fOk = FALSE; + if ((newPos != NULL) && (fOk)) + { + newPos->LowPart = dwNewPos; + newPos->HighPart = lHigh; + } + return fOk; +#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 (!MySetFilePointerEx(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 (!MySetFilePointerEx(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 (!MySetFilePointerEx(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 (!MySetFilePointerEx(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) +{ + int ret=-1; + + if (stream!=NULL) + { + HANDLE hFile; + hFile = ((WIN32FILE_IOWIN*)stream) -> hf; + if (hFile != NULL) + { + CloseHandle(hFile); + ret=0; + } + free(stream); + } + return ret; +} + +int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream) +{ + int ret=-1; + if (stream!=NULL) + { + 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->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->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->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->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; +} diff --git a/Dependencies/minizip/iowin32.h b/Dependencies/minizip/iowin32.h index e9c5f8b..0ca0969 100644 --- a/Dependencies/minizip/iowin32.h +++ b/Dependencies/minizip/iowin32.h @@ -1,21 +1,28 @@ -/* iowin32.h -- IO base function header for compress/uncompress .zip - files using zlib + zip or unzip API - This IO API version uses the Win32 API (for Microsoft Windows) - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant -*/ - -#include - - -#ifdef __cplusplus -extern "C" { -#endif - -void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); - -#ifdef __cplusplus -} -#endif +/* iowin32.h -- IO base function header for compress/uncompress .zip + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + +*/ + +#include + + +#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 diff --git a/Dependencies/minizip/make_vms.com b/Dependencies/minizip/make_vms.com new file mode 100644 index 0000000..9ac13a9 --- /dev/null +++ b/Dependencies/minizip/make_vms.com @@ -0,0 +1,25 @@ +$ if f$search("ioapi.h_orig") .eqs. "" then copy ioapi.h ioapi.h_orig +$ open/write zdef vmsdefs.h +$ copy sys$input: zdef +$ deck +#define unix +#define fill_zlib_filefunc64_32_def_from_filefunc32 fillzffunc64from +#define Write_Zip64EndOfCentralDirectoryLocator Write_Zip64EoDLocator +#define Write_Zip64EndOfCentralDirectoryRecord Write_Zip64EoDRecord +#define Write_EndOfCentralDirectoryRecord Write_EoDRecord +$ eod +$ close zdef +$ copy vmsdefs.h,ioapi.h_orig ioapi.h +$ cc/include=[--]/prefix=all ioapi.c +$ cc/include=[--]/prefix=all miniunz.c +$ cc/include=[--]/prefix=all unzip.c +$ cc/include=[--]/prefix=all minizip.c +$ cc/include=[--]/prefix=all zip.c +$ link miniunz,unzip,ioapi,[--]libz.olb/lib +$ link minizip,zip,ioapi,[--]libz.olb/lib +$ mcr []minizip test minizip_info.txt +$ mcr []miniunz -l test.zip +$ rename minizip_info.txt; minizip_info.txt_old +$ mcr []miniunz test.zip +$ delete test.zip;* +$exit diff --git a/Dependencies/minizip/miniunz.c b/Dependencies/minizip/miniunz.c index 82d8702..3d65401 100644 --- a/Dependencies/minizip/miniunz.c +++ b/Dependencies/minizip/miniunz.c @@ -1,585 +1,660 @@ -/* - miniunz.c - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant -*/ - - -#include -#include -#include -#include -#include -#include - -#ifdef unix -# include -# include -#else -# include -# include -#endif - -#include "unzip.h" - -#define CASESENSITIVITY (0) -#define WRITEBUFFERSIZE (8192) -#define MAXFILENAME (256) - -#ifdef WIN32 -#define USEWIN32IOAPI -#include "iowin32.h" -#endif -/* - mini unzip, demo of unzip package - - usage : - Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] - - list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT - if it exists -*/ - - -/* change_file_date : change the date/time of a file - filename : the filename of the file where date/time must be modified - dosdate : the new date at the MSDos format (4 bytes) - tmu_date : the SAME new date at the tm_unz format */ -void change_file_date(filename,dosdate,tmu_date) - const char *filename; - uLong dosdate; - tm_unz tmu_date; -{ -#ifdef WIN32 - HANDLE hFile; - FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; - - hFile = CreateFile(filename,GENERIC_READ | GENERIC_WRITE, - 0,NULL,OPEN_EXISTING,0,NULL); - GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); - DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); - LocalFileTimeToFileTime(&ftLocal,&ftm); - SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); - CloseHandle(hFile); -#else -#ifdef unix - 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 -} - - -/* mymkdir and change_file_date are not 100 % portable - As I don't know well Unix, I wait feedback for the unix portion */ - -int mymkdir(dirname) - const char* dirname; -{ - int ret=0; -#ifdef WIN32 - ret = mkdir(dirname); -#else -#ifdef unix - ret = mkdir (dirname,0775); -#endif -#endif - return ret; -} - -int makedir (newdir) - char *newdir; -{ - char *buffer ; - char *p; - int len = (int)strlen(newdir); - - if (len <= 0) - return 0; - - buffer = (char*)malloc(len+1); - strcpy(buffer,newdir); - - if (buffer[len-1] == '/') { - buffer[len-1] = '\0'; - } - if (mymkdir(buffer) == 0) - { - free(buffer); - return 1; - } - - p = buffer+1; - while (1) - { - char hold; - - while(*p && *p != '\\' && *p != '/') - p++; - hold = *p; - *p = 0; - if ((mymkdir(buffer) == -1) && (errno == ENOENT)) - { - printf("couldn't create directory %s\n",buffer); - free(buffer); - return 0; - } - if (hold == 0) - break; - *p++ = hold; - } - free(buffer); - return 1; -} - -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/unzip.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(uf) - unzFile uf; -{ - uLong i; - unz_global_info gi; - int err; - - err = unzGetGlobalInfo (uf,&gi); - if (err!=UNZ_OK) - printf("error %d with zipfile in unzGetGlobalInfo \n",err); - printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); - printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); - for (i=0;i0) - ratio = (file_info.compressed_size*100)/file_info.uncompressed_size; - - /* display a '*' if the file is crypted */ - 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 - string_method="Unkn. "; - - printf("%7lu %6s%c%7lu %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", - file_info.uncompressed_size,string_method, - charCrypt, - file_info.compressed_size, - 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); - if ((i+1)='a') && (rep<='z')) - rep -= 0x20; - } - while ((rep!='Y') && (rep!='N') && (rep!='A')); - } - - if (rep == 'N') - skip = 1; - - if (rep == 'A') - *popt_overwrite=1; - } - - if ((skip==0) && (err==UNZ_OK)) - { - fout=fopen(write_filename,"wb"); - - /* some zipfile don't contain directory alone before file */ - if ((fout==NULL) && ((*popt_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(write_filename,"wb"); - } - - if (fout==NULL) - { - printf("error opening %s\n",write_filename); - } - } - - 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) - if (fwrite(buf,err,1,fout)!=1) - { - printf("error in writing extracted file\n"); - err=UNZ_ERRNO; - break; - } - } - while (err>0); - if (fout) - fclose(fout); - - if (err==0) - change_file_date(write_filename,file_info.dosDate, - file_info.tmu_date); - } - - if (err==UNZ_OK) - { - err = unzCloseCurrentFile (uf); - if (err!=UNZ_OK) - { - printf("error %d with zipfile in unzCloseCurrentFile\n",err); - } - } - else - unzCloseCurrentFile(uf); /* don't lose the error */ - } - - free(buf); - return err; -} - - -int do_extract(uf,opt_extract_without_path,opt_overwrite,password) - unzFile uf; - int opt_extract_without_path; - int opt_overwrite; - const char* password; -{ - uLong i; - unz_global_info gi; - int err; - FILE* fout=NULL; - - err = unzGetGlobalInfo (uf,&gi); - if (err!=UNZ_OK) - printf("error %d with zipfile in unzGetGlobalInfo \n",err); - - for (i=0;i +#include +#include +#include +#include +#include + +#ifdef _WIN32 +# include +# include +#else +# include +# include +#endif + + +#include "unzip.h" + +#define CASESENSITIVITY (0) +#define WRITEBUFFERSIZE (8192) +#define MAXFILENAME (256) + +#ifdef _WIN32 +#define USEWIN32IOAPI +#include "iowin32.h" +#endif +/* + mini unzip, demo of unzip package + + usage : + Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] + + list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT + if it exists +*/ + + +/* change_file_date : change the date/time of a file + filename : the filename of the file where date/time must be modified + dosdate : the new date at the MSDos format (4 bytes) + tmu_date : the SAME new date at the tm_unz format */ +void change_file_date(filename,dosdate,tmu_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); + GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); + DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); + LocalFileTimeToFileTime(&ftLocal,&ftm); + SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); + CloseHandle(hFile); +#else +#ifdef unix || __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 +} + + +/* mymkdir and change_file_date are not 100 % portable + As I don't know well Unix, I wait feedback for the unix portion */ + +int mymkdir(dirname) + const char* dirname; +{ + int ret=0; +#ifdef _WIN32 + ret = _mkdir(dirname); +#elif unix + ret = mkdir (dirname,0775); +#elif __APPLE__ + ret = mkdir (dirname,0775); +#endif + return ret; +} + +int makedir (newdir) + char *newdir; +{ + char *buffer ; + char *p; + 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 (mymkdir(buffer) == 0) + { + free(buffer); + return 1; + } + + p = buffer+1; + while (1) + { + char hold; + + while(*p && *p != '\\' && *p != '/') + p++; + hold = *p; + *p = 0; + if ((mymkdir(buffer) == -1) && (errno == ENOENT)) + { + printf("couldn't create directory %s\n",buffer); + free(buffer); + return 0; + } + if (hold == 0) + break; + *p++ = hold; + } + free(buffer); + return 1; +} + +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/unzip.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"); +} + +void Display64BitsSize(ZPOS64_T n, int size_char) +{ + /* to avoid compatibility problem , we do here the conversion */ + char number[21]; + int offset=19; + int pos_string = 19; + number[20]=0; + for (;;) { + number[offset]=(char)((n%10)+'0'); + if (number[offset] != '0') + pos_string=offset; + n/=10; + if (offset==0) + break; + offset--; + } + { + int size_display_string = 19-pos_string; + while (size_char > size_display_string) + { + size_char--; + printf(" "); + } + } + + printf("%s",&number[pos_string]); +} + +int do_list(uf) + unzFile uf; +{ + uLong i; + unz_global_info64 gi; + int err; + + err = unzGetGlobalInfo64(uf,&gi); + if (err!=UNZ_OK) + printf("error %d with zipfile in unzGetGlobalInfo \n",err); + printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); + printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); + for (i=0;i0) + ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); + + /* display a '*' if the file is crypted */ + 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. "; + + Display64BitsSize(file_info.uncompressed_size,7); + printf(" %6s%c",string_method,charCrypt); + Display64BitsSize(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); + if ((i+1)='a') && (rep<='z')) + rep -= 0x20; + } + while ((rep!='Y') && (rep!='N') && (rep!='A')); + } + + if (rep == 'N') + skip = 1; + + if (rep == 'A') + *popt_overwrite=1; + } + + if ((skip==0) && (err==UNZ_OK)) + { + fout=FOPEN_FUNC(write_filename,"wb"); + /* some zipfile don't contain directory alone before file */ + if ((fout==NULL) && ((*popt_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); + } + } + + 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) + if (fwrite(buf,err,1,fout)!=1) + { + printf("error in writing extracted file\n"); + err=UNZ_ERRNO; + break; + } + } + while (err>0); + if (fout) + fclose(fout); + + if (err==0) + change_file_date(write_filename,file_info.dosDate, + file_info.tmu_date); + } + + if (err==UNZ_OK) + { + err = unzCloseCurrentFile (uf); + if (err!=UNZ_OK) + { + printf("error %d with zipfile in unzCloseCurrentFile\n",err); + } + } + else + unzCloseCurrentFile(uf); /* don't lose the error */ + } + + free(buf); + return err; +} + + +int do_extract(uf,opt_extract_without_path,opt_overwrite,password) + unzFile uf; + int opt_extract_without_path; + int opt_overwrite; + const char* password; +{ + uLong i; + unz_global_info64 gi; + int err; + FILE* fout=NULL; + + err = unzGetGlobalInfo64(uf,&gi); + if (err!=UNZ_OK) + printf("error %d with zipfile in unzGetGlobalInfo \n",err); + + for (i=0;i insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +miniunzip - uncompress and examine ZIP archives +.SH SYNOPSIS +.B miniunzip +.RI [ -exvlo ] +zipfile [ files_to_extract ] [-d tempdir] +.SH DESCRIPTION +.B minizip +is a simple tool which allows the extraction of compressed file +archives in the ZIP format used by the MS-DOS utility PKZIP. It was +written as a demonstration of the +.IR zlib (3) +library and therefore lack many of the features of the +.IR unzip (1) +program. +.SH OPTIONS +A number of options are supported. With the exception of +.BI \-d\ tempdir +these must be supplied before any +other arguments and are: +.TP +.BI \-l\ ,\ \-\-v +List the files in the archive without extracting them. +.TP +.B \-o +Overwrite files without prompting for confirmation. +.TP +.B \-x +Extract files (default). +.PP +The +.I zipfile +argument is the name of the archive to process. The next argument can be used +to specify a single file to extract from the archive. + +Lastly, the following option can be specified at the end of the command-line: +.TP +.BI \-d\ tempdir +Extract the archive in the directory +.I tempdir +rather than the current directory. +.SH SEE ALSO +.BR minizip (1), +.BR zlib (3), +.BR unzip (1). +.SH AUTHOR +This program was written by Gilles Vollant. This manual page was +written by Mark Brown . The -d tempdir option +was added by Dirk Eddelbuettel . diff --git a/Dependencies/minizip/minizip.1 b/Dependencies/minizip/minizip.1 new file mode 100644 index 0000000..1154484 --- /dev/null +++ b/Dependencies/minizip/minizip.1 @@ -0,0 +1,46 @@ +.\" Hey, EMACS: -*- nroff -*- +.TH minizip 1 "May 2, 2001" +.\" Please adjust this date whenever revising the manpage. +.\" +.\" Some roff macros, for reference: +.\" .nh disable hyphenation +.\" .hy enable hyphenation +.\" .ad l left justify +.\" .ad b justify to both left and right margins +.\" .nf disable filling +.\" .fi enable filling +.\" .br insert line break +.\" .sp insert n+1 empty lines +.\" for manpage-specific macros, see man(7) +.SH NAME +minizip - create ZIP archives +.SH SYNOPSIS +.B minizip +.RI [ -o ] +zipfile [ " files" ... ] +.SH DESCRIPTION +.B minizip +is a simple tool which allows the creation of compressed file archives +in the ZIP format used by the MS-DOS utility PKZIP. It was written as +a demonstration of the +.IR zlib (3) +library and therefore lack many of the features of the +.IR zip (1) +program. +.SH OPTIONS +The first argument supplied is the name of the ZIP archive to create or +.RI -o +in which case it is ignored and the second argument treated as the +name of the ZIP file. If the ZIP file already exists it will be +overwritten. +.PP +Subsequent arguments specify a list of files to place in the ZIP +archive. If none are specified then an empty archive will be created. +.SH SEE ALSO +.BR miniunzip (1), +.BR zlib (3), +.BR zip (1). +.SH AUTHOR +This program was written by Gilles Vollant. This manual page was +written by Mark Brown . + diff --git a/Dependencies/minizip/minizip.c b/Dependencies/minizip/minizip.c index 70fee02..4288962 100644 --- a/Dependencies/minizip/minizip.c +++ b/Dependencies/minizip/minizip.c @@ -1,420 +1,520 @@ -/* - minizip.c - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant -*/ - -#include -#include -#include -#include -#include -#include - -#ifdef unix -# include -# include -# include -# include -#else -# include -# include -#endif - -#include "zip.h" - -#ifdef WIN32 -#define USEWIN32IOAPI -#include "iowin32.h" -#endif - - - -#define WRITEBUFFERSIZE (16384) -#define MAXFILENAME (256) - -#ifdef WIN32 -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - int ret = 0; - { - FILETIME ftLocal; - HANDLE hFind; - WIN32_FIND_DATA ff32; - - hFind = FindFirstFile(f,&ff32); - if (hFind != INVALID_HANDLE_VALUE) - { - FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); - FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); - FindClose(hFind); - ret = 1; - } - } - return ret; -} -#else -#ifdef unix -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - int ret=0; - struct stat s; /* results of stat() */ - struct tm* filedate; - time_t tm_t=0; - - if (strcmp(f,"-")!=0) - { - char name[MAXFILENAME+1]; - int len = strlen(f); - if (len > MAXFILENAME) - len = MAXFILENAME; - - strncpy(name, f,MAXFILENAME-1); - /* strncpy doesnt append the trailing NULL, of the string is too long. */ - 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; - - return ret; -} -#else -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - return 0; -} -#endif -#endif - - - - -int check_exist_file(filename) - const char* filename; -{ - FILE* ftestexist; - int ret = 1; - ftestexist = fopen(filename,"rb"); - if (ftestexist==NULL) - ret = 0; - else - fclose(ftestexist); - return ret; -} - -void do_banner() -{ - printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n"); - printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); -} - -void do_help() -{ - printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] 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"); -} - -/* calculate the CRC32 of a file, - because to encrypt a file, we need known the CRC32 of the file before */ -int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) -{ - unsigned long calculate_crc=0; - int err=ZIP_OK; - FILE * fin = fopen(filenameinzip,"rb"); - unsigned long size_read = 0; - unsigned long total_read = 0; - if (fin==NULL) - { - err = ZIP_ERRNO; - } - - if (err == ZIP_OK) - do - { - err = ZIP_OK; - size_read = (int)fread(buf,1,size_buf,fin); - if (size_read < size_buf) - if (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); - total_read += size_read; - - } while ((err == ZIP_OK) && (size_read>0)); - - if (fin) - fclose(fin); - - *result_crc=calculate_crc; - printf("file %s crc %x\n",filenameinzip,calculate_crc); - return err; -} - -int main(argc,argv) - int argc; - char *argv[]; -{ - int i; - int opt_overwrite=0; - int opt_compress_level=Z_DEFAULT_COMPRESSION; - int zipfilenamearg = 0; - char filename_try[MAXFILENAME+16]; - int zipok; - int err=0; - int size_buf=0; - void* buf=NULL; - const char* password=NULL; - - - do_banner(); - if (argc==1) - { - do_help(); - return 0; - } - else - { - for (i=1;i='0') && (c<='9')) - opt_compress_level = c-'0'; - - if (((c=='p') || (c=='P')) && (i+1='a') && (rep<='z')) - rep -= 0x20; - } - while ((rep!='Y') && (rep!='N') && (rep!='A')); - if (rep=='N') - zipok = 0; - if (rep=='A') - opt_overwrite = 2; - } - } - - if (zipok==1) - { - zipFile zf; - int errclose; -# ifdef USEWIN32IOAPI - zlib_filefunc_def ffunc; - fill_win32_filefunc(&ffunc); - zf = zipOpen2(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); -# else - zf = zipOpen(filename_try,(opt_overwrite==2) ? 2 : 0); -# endif - - if (zf == NULL) - { - printf("error opening %s\n",filename_try); - err= ZIP_ERRNO; - } - else - printf("creating %s\n",filename_try); - - for (i=zipfilenamearg+1;(i='0') || (argv[i][1]<='9'))) && - (strlen(argv[i]) == 2))) - { - FILE * fin; - int size_read; - const char* filenameinzip = argv[i]; - zip_fileinfo zi; - unsigned long crcFile=0; - - zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = - zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; - zi.dosDate = 0; - zi.internal_fa = 0; - zi.external_fa = 0; - filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); - -/* - err = zipOpenNewFileInZip(zf,filenameinzip,&zi, - NULL,0,NULL,0,NULL / * comment * /, - (opt_compress_level != 0) ? Z_DEFLATED : 0, - opt_compress_level); -*/ - if ((password != NULL) && (err==ZIP_OK)) - err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); - - err = zipOpenNewFileInZip3(zf,filenameinzip,&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, */ - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - password,crcFile); - - if (err != ZIP_OK) - printf("error in opening %s in zipfile\n",filenameinzip); - else - { - fin = fopen(filenameinzip,"rb"); - if (fin==NULL) - { - err=ZIP_ERRNO; - printf("error in opening %s for reading\n",filenameinzip); - } - } - - if (err == ZIP_OK) - do - { - err = ZIP_OK; - size_read = (int)fread(buf,1,size_buf,fin); - if (size_read < size_buf) - if (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\n", - filenameinzip); - } - - } - } 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\n", - filenameinzip); - } - } - } - errclose = zipClose(zf,NULL); - if (errclose != ZIP_OK) - printf("error in closing %s\n",filename_try); - } - else - { - do_help(); - } - - free(buf); - return 0; -} +/* + minizip.c + Version 1.1, February 14h, 2010 + sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) +*/ + + +#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 +#include +#include +#include +#include +#include + +#ifdef _WIN32 +# include +# include +#else +# include +# include +# include +# include +#endif + +#include "zip.h" + +#ifdef _WIN32 + #define USEWIN32IOAPI + #include "iowin32.h" +#endif + + + +#define WRITEBUFFERSIZE (16384) +#define MAXFILENAME (256) + +#ifdef _WIN32 +uLong filetime(f, tmzip, dt) + char *f; /* name of file to get info on */ + tm_zip *tmzip; /* return value: access, modific. and creation times */ + uLong *dt; /* dostime */ +{ + int ret = 0; + { + FILETIME ftLocal; + HANDLE hFind; + WIN32_FIND_DATAA ff32; + + hFind = FindFirstFileA(f,&ff32); + if (hFind != INVALID_HANDLE_VALUE) + { + FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); + FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); + FindClose(hFind); + ret = 1; + } + } + return ret; +} +#else +#ifdef unix || __APPLE__ +uLong filetime(f, tmzip, dt) + char *f; /* name of file to get info on */ + tm_zip *tmzip; /* return value: access, modific. and creation times */ + uLong *dt; /* dostime */ +{ + int ret=0; + struct stat s; /* results of stat() */ + struct tm* filedate; + time_t tm_t=0; + + if (strcmp(f,"-")!=0) + { + char name[MAXFILENAME+1]; + int len = strlen(f); + if (len > MAXFILENAME) + len = MAXFILENAME; + + strncpy(name, f,MAXFILENAME-1); + /* strncpy doesnt append the trailing NULL, of the string is too long. */ + 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; + + return ret; +} +#else +uLong filetime(f, tmzip, dt) + char *f; /* name of file to get info on */ + tm_zip *tmzip; /* return value: access, modific. and creation times */ + uLong *dt; /* dostime */ +{ + return 0; +} +#endif +#endif + + + + +int check_exist_file(filename) + const char* filename; +{ + FILE* ftestexist; + int ret = 1; + ftestexist = FOPEN_FUNC(filename,"rb"); + if (ftestexist==NULL) + ret = 0; + else + fclose(ftestexist); + return ret; +} + +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"); +} + +/* calculate the CRC32 of a file, + because to encrypt a file, we need known the CRC32 of the file before */ +int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) +{ + unsigned long calculate_crc=0; + int err=ZIP_OK; + FILE * fin = FOPEN_FUNC(filenameinzip,"rb"); + + unsigned long size_read = 0; + unsigned long total_read = 0; + if (fin==NULL) + { + err = ZIP_ERRNO; + } + + if (err == ZIP_OK) + do + { + err = ZIP_OK; + size_read = (int)fread(buf,1,size_buf,fin); + if (size_read < size_buf) + if (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); + total_read += size_read; + + } while ((err == ZIP_OK) && (size_read>0)); + + if (fin) + fclose(fin); + + *result_crc=calculate_crc; + printf("file %s crc %lx\n", filenameinzip, calculate_crc); + return err; +} + +int isLargeFile(const char* filename) +{ + int largeFile = 0; + ZPOS64_T pos = 0; + FILE* pFile = FOPEN_FUNC(filename, "rb"); + + if(pFile != NULL) + { + int n = FSEEKO_FUNC(pFile, 0, SEEK_END); + pos = FTELLO_FUNC(pFile); + + printf("File : %s is %lld bytes\n", filename, pos); + + if(pos >= 0xffffffff) + largeFile = 1; + + fclose(pFile); + } + + return largeFile; +} + +int main(argc,argv) + int argc; + char *argv[]; +{ + int i; + int opt_overwrite=0; + int opt_compress_level=Z_DEFAULT_COMPRESSION; + int opt_exclude_path=0; + int zipfilenamearg = 0; + char filename_try[MAXFILENAME+16]; + int zipok; + int err=0; + int size_buf=0; + void* buf=NULL; + const char* password=NULL; + + + do_banner(); + if (argc==1) + { + do_help(); + return 0; + } + else + { + for (i=1;i='0') && (c<='9')) + opt_compress_level = c-'0'; + if ((c=='j') || (c=='J')) + opt_exclude_path = 1; + + if (((c=='p') || (c=='P')) && (i+1='a') && (rep<='z')) + rep -= 0x20; + } + while ((rep!='Y') && (rep!='N') && (rep!='A')); + if (rep=='N') + zipok = 0; + if (rep=='A') + opt_overwrite = 2; + } + } + + if (zipok==1) + { + zipFile zf; + int errclose; +# ifdef USEWIN32IOAPI + zlib_filefunc64_def ffunc; + fill_win32_filefunc64A(&ffunc); + zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); +# else + zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0); +# endif + + if (zf == NULL) + { + printf("error opening %s\n",filename_try); + err= ZIP_ERRNO; + } + else + printf("creating %s\n",filename_try); + + for (i=zipfilenamearg+1;(i='0') || (argv[i][1]<='9'))) && + (strlen(argv[i]) == 2))) + { + FILE * fin; + int size_read; + const char* filenameinzip = argv[i]; + const char *savefilenameinzip; + zip_fileinfo zi; + unsigned long crcFile=0; + int zip64 = 0; + + zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = + zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; + zi.dosDate = 0; + zi.internal_fa = 0; + zi.external_fa = 0; + filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); + +/* + err = zipOpenNewFileInZip(zf,filenameinzip,&zi, + NULL,0,NULL,0,NULL / * comment * /, + (opt_compress_level != 0) ? Z_DEFLATED : 0, + opt_compress_level); +*/ + if ((password != NULL) && (err==ZIP_OK)) + err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); + + zip64 = isLargeFile(filenameinzip); + + /* 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 zip file contain any path at all?*/ + if( opt_exclude_path ) + { + const char *tmpptr; + 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. + } + } + + /**/ + 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, */ + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, + password,crcFile, zip64); + + if (err != ZIP_OK) + printf("error in opening %s in zipfile\n",filenameinzip); + 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) + do + { + err = ZIP_OK; + size_read = (int)fread(buf,1,size_buf,fin); + if (size_read < size_buf) + if (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\n", + filenameinzip); + } + + } + } 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\n", + filenameinzip); + } + } + } + errclose = zipClose(zf,NULL); + if (errclose != ZIP_OK) + printf("error in closing %s\n",filename_try); + } + else + { + do_help(); + } + + free(buf); + return 0; +} diff --git a/Dependencies/minizip/minizip.pc.in b/Dependencies/minizip/minizip.pc.in new file mode 100644 index 0000000..69b5b7f --- /dev/null +++ b/Dependencies/minizip/minizip.pc.in @@ -0,0 +1,12 @@ +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} diff --git a/Dependencies/minizip/mztools.c b/Dependencies/minizip/mztools.c index bc5c798..96891c2 100644 --- a/Dependencies/minizip/mztools.c +++ b/Dependencies/minizip/mztools.c @@ -1,281 +1,291 @@ -/* - Additional tools for Minizip - Code: Xavier Roche '2004 - License: Same as ZLIB (www.gzip.org) -*/ - -/* Code */ -#include -#include -#include -#include "zlib.h" -#include "unzip.h" - -#define READ_8(adr) ((unsigned char)*(adr)) -#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) -#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) - -#define WRITE_8(buff, n) do { \ - *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ -} while(0) -#define WRITE_16(buff, n) do { \ - WRITE_8((unsigned char*)(buff), n); \ - WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ -} while(0) -#define WRITE_32(buff, n) do { \ - WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ - WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ -} while(0) - -extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) -const char* file; -const char* fileOut; -const char* fileOutTmp; -uLong* nRecovered; -uLong* bytesRecovered; -{ - int err = Z_OK; - FILE* fpZip = fopen(file, "rb"); - FILE* fpOut = fopen(fileOut, "wb"); - FILE* fpOutCD = fopen(fileOutTmp, "wb"); - if (fpZip != NULL && fpOut != NULL) { - int entries = 0; - uLong totalBytes = 0; - char header[30]; - char filename[256]; - char extra[1024]; - int offset = 0; - int offsetCD = 0; - while ( fread(header, 1, 30, fpZip) == 30 ) { - int currentOffset = offset; - - /* File entry */ - if (READ_32(header) == 0x04034b50) { - unsigned int version = READ_16(header + 4); - unsigned int gpflag = READ_16(header + 6); - unsigned int method = READ_16(header + 8); - unsigned int filetime = READ_16(header + 10); - unsigned int filedate = READ_16(header + 12); - unsigned int crc = READ_32(header + 14); /* crc */ - unsigned int cpsize = READ_32(header + 18); /* compressed size */ - unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ - unsigned int fnsize = READ_16(header + 26); /* file name length */ - unsigned int extsize = READ_16(header + 28); /* extra field length */ - filename[0] = extra[0] = '\0'; - - /* Header */ - if (fwrite(header, 1, 30, fpOut) == 30) { - offset += 30; - } else { - err = Z_ERRNO; - break; - } - - /* Filename */ - if (fnsize > 0) { - if (fread(filename, 1, fnsize, fpZip) == fnsize) { - if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { - offset += fnsize; - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_STREAM_ERROR; - break; - } - - /* Extra field */ - if (extsize > 0) { - if (fread(extra, 1, extsize, fpZip) == extsize) { - if (fwrite(extra, 1, extsize, fpOut) == extsize) { - offset += extsize; - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_ERRNO; - break; - } - } - - /* Data */ - { - int dataSize = cpsize; - if (dataSize == 0) { - dataSize = uncpsize; - } - if (dataSize > 0) { - char* data = malloc(dataSize); - if (data != NULL) { - if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { - if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { - offset += dataSize; - totalBytes += dataSize; - } else { - err = Z_ERRNO; - } - } else { - err = Z_ERRNO; - } - free(data); - if (err != Z_OK) { - break; - } - } else { - err = Z_MEM_ERROR; - break; - } - } - } - - /* Central directory entry */ - { - char header[46]; - char* comment = ""; - int comsize = (int) strlen(comment); - WRITE_32(header, 0x02014b50); - WRITE_16(header + 4, version); - WRITE_16(header + 6, version); - WRITE_16(header + 8, gpflag); - WRITE_16(header + 10, method); - WRITE_16(header + 12, filetime); - WRITE_16(header + 14, filedate); - WRITE_32(header + 16, crc); - WRITE_32(header + 20, cpsize); - WRITE_32(header + 24, uncpsize); - WRITE_16(header + 28, fnsize); - WRITE_16(header + 30, extsize); - WRITE_16(header + 32, comsize); - WRITE_16(header + 34, 0); /* disk # */ - WRITE_16(header + 36, 0); /* int attrb */ - WRITE_32(header + 38, 0); /* ext attrb */ - WRITE_32(header + 42, currentOffset); - /* Header */ - if (fwrite(header, 1, 46, fpOutCD) == 46) { - offsetCD += 46; - - /* Filename */ - if (fnsize > 0) { - if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { - offsetCD += fnsize; - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_STREAM_ERROR; - break; - } - - /* Extra field */ - if (extsize > 0) { - if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { - offsetCD += extsize; - } else { - err = Z_ERRNO; - break; - } - } - - /* Comment field */ - if (comsize > 0) { - if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { - offsetCD += comsize; - } else { - err = Z_ERRNO; - break; - } - } - - - } else { - err = Z_ERRNO; - break; - } - } - - /* Success */ - entries++; - - } else { - break; - } - } - - /* Final central directory */ - { - int entriesZip = entries; - char header[22]; - char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; - int comsize = (int) strlen(comment); - if (entriesZip > 0xffff) { - entriesZip = 0xffff; - } - WRITE_32(header, 0x06054b50); - WRITE_16(header + 4, 0); /* disk # */ - WRITE_16(header + 6, 0); /* disk # */ - WRITE_16(header + 8, entriesZip); /* hack */ - WRITE_16(header + 10, entriesZip); /* hack */ - WRITE_32(header + 12, offsetCD); /* size of CD */ - WRITE_32(header + 16, offset); /* offset to CD */ - WRITE_16(header + 20, comsize); /* comment */ - - /* Header */ - if (fwrite(header, 1, 22, fpOutCD) == 22) { - - /* Comment field */ - if (comsize > 0) { - if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { - err = Z_ERRNO; - } - } - - } else { - err = Z_ERRNO; - } - } - - /* Final merge (file + central directory) */ - fclose(fpOutCD); - if (err == Z_OK) { - fpOutCD = fopen(fileOutTmp, "rb"); - if (fpOutCD != NULL) { - int nRead; - char buffer[8192]; - while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { - if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { - err = Z_ERRNO; - break; - } - } - fclose(fpOutCD); - } - } - - /* Close */ - fclose(fpZip); - fclose(fpOut); - - /* Wipe temporary file */ - (void)remove(fileOutTmp); - - /* Number of recovered entries */ - if (err == Z_OK) { - if (nRecovered != NULL) { - *nRecovered = entries; - } - if (bytesRecovered != NULL) { - *bytesRecovered = totalBytes; - } - } - } else { - err = Z_STREAM_ERROR; - } - return err; -} +/* + Additional tools for Minizip + Code: Xavier Roche '2004 + License: Same as ZLIB (www.gzip.org) +*/ + +/* Code */ +#include +#include +#include +#include "zlib.h" +#include "unzip.h" + +#define READ_8(adr) ((unsigned char)*(adr)) +#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) +#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) + +#define WRITE_8(buff, n) do { \ + *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ +} while(0) +#define WRITE_16(buff, n) do { \ + WRITE_8((unsigned char*)(buff), n); \ + WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ +} while(0) +#define WRITE_32(buff, n) do { \ + WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ + WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ +} while(0) + +extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) +const char* file; +const char* fileOut; +const char* fileOutTmp; +uLong* nRecovered; +uLong* bytesRecovered; +{ + int err = Z_OK; + FILE* fpZip = fopen(file, "rb"); + FILE* fpOut = fopen(fileOut, "wb"); + FILE* fpOutCD = fopen(fileOutTmp, "wb"); + if (fpZip != NULL && fpOut != NULL) { + int entries = 0; + uLong totalBytes = 0; + char header[30]; + char filename[1024]; + char extra[1024]; + int offset = 0; + int offsetCD = 0; + while ( fread(header, 1, 30, fpZip) == 30 ) { + int currentOffset = offset; + + /* File entry */ + if (READ_32(header) == 0x04034b50) { + unsigned int version = READ_16(header + 4); + unsigned int gpflag = READ_16(header + 6); + unsigned int method = READ_16(header + 8); + unsigned int filetime = READ_16(header + 10); + unsigned int filedate = READ_16(header + 12); + unsigned int crc = READ_32(header + 14); /* crc */ + unsigned int cpsize = READ_32(header + 18); /* compressed size */ + unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ + unsigned int fnsize = READ_16(header + 26); /* file name length */ + unsigned int extsize = READ_16(header + 28); /* extra field length */ + filename[0] = extra[0] = '\0'; + + /* Header */ + if (fwrite(header, 1, 30, fpOut) == 30) { + offset += 30; + } else { + err = Z_ERRNO; + break; + } + + /* Filename */ + if (fnsize > 0) { + if (fnsize < sizeof(filename)) { + if (fread(filename, 1, fnsize, fpZip) == fnsize) { + if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { + offset += fnsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_STREAM_ERROR; + break; + } + + /* Extra field */ + if (extsize > 0) { + if (extsize < sizeof(extra)) { + if (fread(extra, 1, extsize, fpZip) == extsize) { + if (fwrite(extra, 1, extsize, fpOut) == extsize) { + offset += extsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_ERRNO; + break; + } + } + + /* Data */ + { + int dataSize = cpsize; + if (dataSize == 0) { + dataSize = uncpsize; + } + if (dataSize > 0) { + char* data = malloc(dataSize); + if (data != NULL) { + if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { + if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { + offset += dataSize; + totalBytes += dataSize; + } else { + err = Z_ERRNO; + } + } else { + err = Z_ERRNO; + } + free(data); + if (err != Z_OK) { + break; + } + } else { + err = Z_MEM_ERROR; + break; + } + } + } + + /* Central directory entry */ + { + char header[46]; + char* comment = ""; + int comsize = (int) strlen(comment); + WRITE_32(header, 0x02014b50); + WRITE_16(header + 4, version); + WRITE_16(header + 6, version); + WRITE_16(header + 8, gpflag); + WRITE_16(header + 10, method); + WRITE_16(header + 12, filetime); + WRITE_16(header + 14, filedate); + WRITE_32(header + 16, crc); + WRITE_32(header + 20, cpsize); + WRITE_32(header + 24, uncpsize); + WRITE_16(header + 28, fnsize); + WRITE_16(header + 30, extsize); + WRITE_16(header + 32, comsize); + WRITE_16(header + 34, 0); /* disk # */ + WRITE_16(header + 36, 0); /* int attrb */ + WRITE_32(header + 38, 0); /* ext attrb */ + WRITE_32(header + 42, currentOffset); + /* Header */ + if (fwrite(header, 1, 46, fpOutCD) == 46) { + offsetCD += 46; + + /* Filename */ + if (fnsize > 0) { + if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { + offsetCD += fnsize; + } else { + err = Z_ERRNO; + break; + } + } else { + err = Z_STREAM_ERROR; + break; + } + + /* Extra field */ + if (extsize > 0) { + if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { + offsetCD += extsize; + } else { + err = Z_ERRNO; + break; + } + } + + /* Comment field */ + if (comsize > 0) { + if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { + offsetCD += comsize; + } else { + err = Z_ERRNO; + break; + } + } + + + } else { + err = Z_ERRNO; + break; + } + } + + /* Success */ + entries++; + + } else { + break; + } + } + + /* Final central directory */ + { + int entriesZip = entries; + char header[22]; + char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; + int comsize = (int) strlen(comment); + if (entriesZip > 0xffff) { + entriesZip = 0xffff; + } + WRITE_32(header, 0x06054b50); + WRITE_16(header + 4, 0); /* disk # */ + WRITE_16(header + 6, 0); /* disk # */ + WRITE_16(header + 8, entriesZip); /* hack */ + WRITE_16(header + 10, entriesZip); /* hack */ + WRITE_32(header + 12, offsetCD); /* size of CD */ + WRITE_32(header + 16, offset); /* offset to CD */ + WRITE_16(header + 20, comsize); /* comment */ + + /* Header */ + if (fwrite(header, 1, 22, fpOutCD) == 22) { + + /* Comment field */ + if (comsize > 0) { + if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { + err = Z_ERRNO; + } + } + + } else { + err = Z_ERRNO; + } + } + + /* Final merge (file + central directory) */ + fclose(fpOutCD); + if (err == Z_OK) { + fpOutCD = fopen(fileOutTmp, "rb"); + if (fpOutCD != NULL) { + int nRead; + char buffer[8192]; + while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { + if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { + err = Z_ERRNO; + break; + } + } + fclose(fpOutCD); + } + } + + /* Close */ + fclose(fpZip); + fclose(fpOut); + + /* Wipe temporary file */ + (void)remove(fileOutTmp); + + /* Number of recovered entries */ + if (err == Z_OK) { + if (nRecovered != NULL) { + *nRecovered = entries; + } + if (bytesRecovered != NULL) { + *bytesRecovered = totalBytes; + } + } + } else { + err = Z_STREAM_ERROR; + } + return err; +} diff --git a/Dependencies/minizip/mztools.h b/Dependencies/minizip/mztools.h index 82d1597..a49a426 100644 --- a/Dependencies/minizip/mztools.h +++ b/Dependencies/minizip/mztools.h @@ -1,31 +1,37 @@ -/* - Additional tools for Minizip - Code: Xavier Roche '2004 - License: Same as ZLIB (www.gzip.org) -*/ - -#ifndef _zip_tools_H -#define _zip_tools_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#include "unzip.h" - -/* Repair a ZIP file (missing central directory) - file: file to recover - fileOut: output file after recovery - fileOutTmp: temporary file name used for recovery -*/ -extern int ZEXPORT unzRepair(const char* file, - const char* fileOut, - const char* fileOutTmp, - uLong* nRecovered, - uLong* bytesRecovered); - -#endif +/* + Additional tools for Minizip + Code: Xavier Roche '2004 + License: Same as ZLIB (www.gzip.org) +*/ + +#ifndef _zip_tools_H +#define _zip_tools_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#include "unzip.h" + +/* Repair a ZIP file (missing central directory) + file: file to recover + fileOut: output file after recovery + fileOutTmp: temporary file name used for recovery +*/ +extern int ZEXPORT unzRepair(const char* file, + const char* fileOut, + const char* fileOutTmp, + uLong* nRecovered, + uLong* bytesRecovered); + + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/Dependencies/minizip/unzip.c b/Dependencies/minizip/unzip.c index 3a70629..bcfb941 100644 --- a/Dependencies/minizip/unzip.c +++ b/Dependencies/minizip/unzip.c @@ -1,1598 +1,2125 @@ -/* unzip.c -- IO for uncompress .zip files using zlib - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - Read unzip.h for more info -*/ - -/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of -compatibility with older software. The following is from the original crypt.c. Code -woven in by Terry Thorsen 1/2003. -*/ -/* - Copyright (c) 1990-2000 Info-ZIP. All rights reserved. - - See the accompanying file LICENSE, version 2000-Apr-09 or later - (the contents of which are also included in zip.h) for terms of use. - If, for some reason, all these files are missing, the Info-ZIP license - also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html -*/ -/* - crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - */ - -/* - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - */ - - -#include -#include -#include -#include "zlib.h" -#include "unzip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - - -#ifndef CASESENSITIVITYDEFAULT_NO -# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) -# define CASESENSITIVITYDEFAULT_NO -# endif -#endif - - -#ifndef UNZ_BUFSIZE -#define UNZ_BUFSIZE (16384) -#endif - -#ifndef UNZ_MAXFILENAMEINZIP -#define UNZ_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) - - - - -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_info_internal_s -{ - uLong offset_curfile;/* relative offset of local header 4 bytes */ -} unz_file_info_internal; - - -/* file_in_zip_read_info_s contain internal information about a file in zipfile, - when reading and decompress it */ -typedef struct -{ - char *read_buffer; /* internal buffer for compressed data */ - z_stream stream; /* zLib stream structure for inflate */ - - uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ - uLong stream_initialised; /* flag set if stream structure is initialised*/ - - uLong offset_local_extrafield;/* offset of the local extra field */ - uInt size_local_extrafield;/* size of the local extra field */ - uLong pos_local_extrafield; /* position in the local extra field in read*/ - - uLong crc32; /* crc32 of all data uncompressed */ - uLong crc32_wait; /* crc32 we must obtain after decompress all */ - uLong rest_read_compressed; /* number of byte to be decompressed */ - uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ - zlib_filefunc_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ - uLong compression_method; /* compression method (0==store) */ - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - int raw; -} file_in_zip_read_info_s; - - -/* unz_s contain internal information about the zipfile -*/ -typedef struct -{ - zlib_filefunc_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ - unz_global_info gi; /* public global information */ - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - uLong num_file; /* number of the current file in the zipfile*/ - uLong pos_in_central_dir; /* pos of the current file in the central dir*/ - uLong current_file_ok; /* flag about the usability of the current file*/ - uLong central_pos; /* position of the beginning of the central dir*/ - - uLong size_central_dir; /* size of the central directory */ - uLong offset_central_dir; /* offset of start of central directory with - respect to the starting disk number */ - - unz_file_info cur_file_info; /* public info about the current file in zip*/ - unz_file_info_internal cur_file_info_internal; /* private info about it*/ - file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current - file if we are decompressing it */ - int encrypted; -# ifndef NOUNCRYPT - unsigned long keys[3]; /* keys defining the pseudo-random sequence */ - const unsigned long* pcrc_32_tab; -# endif -} unz_s; - - -#ifndef NOUNCRYPT -#include "crypt.h" -#endif - -/* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been sucessfully opened for reading. -*/ - - -local int unzlocal_getByte OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - int *pi)); - -local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - int *pi; -{ - unsigned char c; - int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) - { - *pi = (int)c; - return UNZ_OK; - } - else - { - if (ZERROR(*pzlib_filefunc_def,filestream)) - return UNZ_ERRNO; - else - return UNZ_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int unzlocal_getShort OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unzlocal_getLong OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - - -/* My own strcmpi / strcasecmp */ -local int strcmpcasenosensitive_internal (fileName1,fileName2) - const char* fileName1; - const char* fileName2; -{ - for (;;) - { - char c1=*(fileName1++); - char c2=*(fileName2++); - if ((c1>='a') && (c1<='z')) - c1 -= 0x20; - if ((c2>='a') && (c2<='z')) - c2 -= 0x20; - if (c1=='\0') - return ((c2=='\0') ? 0 : -1); - if (c2=='\0') - return 1; - if (c1c2) - return 1; - } -} - - -#ifdef CASESENSITIVITYDEFAULT_NO -#define CASESENSITIVITYDEFAULTVALUE 2 -#else -#define CASESENSITIVITYDEFAULTVALUE 1 -#endif - -#ifndef STRCMPCASENOSENTIVEFUNCTION -#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal -#endif - -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) - -*/ -extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) - const char* fileName1; - const char* fileName2; - int iCaseSensitivity; -{ - if (iCaseSensitivity==0) - iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; - - if (iCaseSensitivity==1) - return strcmp(fileName1,fileName2); - - return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); -} - -#ifndef BUFREADCOMMENT -#define BUFREADCOMMENT (0x400) -#endif - -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local uLong unzlocal_SearchCentralDir OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream)); - -local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; -{ - unsigned char* buf; - uLong uSizeFile; - uLong uBackRead; - uLong uMaxBack=0xffff; /* maximum size of global comment */ - uLong uPosFound=0; - - if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); - if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} - -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer - "zlib/zlib114.zip". - If the zipfile cannot be opened (file doesn't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ -extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) - const char *path; - zlib_filefunc_def* pzlib_filefunc_def; -{ - unz_s us; - unz_s *s; - uLong central_pos,uL; - - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ - uLong number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - - int err=UNZ_OK; - - if (unz_copyright[0]!=' ') - return NULL; - - if (pzlib_filefunc_def==NULL) - fill_fopen_filefunc(&us.z_filefunc); - else - us.z_filefunc = *pzlib_filefunc_def; - - us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, - path, - ZLIB_FILEFUNC_MODE_READ | - ZLIB_FILEFUNC_MODE_EXISTING); - if (us.filestream==NULL) - return NULL; - - central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); - if (central_pos==0) - err=UNZ_ERRNO; - - if (ZSEEK(us.z_filefunc, us.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir on this disk */ - if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir */ - if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* zipfile comment length */ - if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((central_pospfile_in_zip_read!=NULL) - unzCloseCurrentFile(file); - - ZCLOSE(s->z_filefunc, s->filestream); - TRYFREE(s); - return UNZ_OK; -} - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) - unzFile file; - unz_global_info *pglobal_info; -{ - unz_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - *pglobal_info=s->gi; - return UNZ_OK; -} - - -/* - Translate date/time from Dos format to tm_unz (readable more easilty) -*/ -local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) - uLong ulDosDate; - tm_unz* ptm; -{ - uLong uDate; - uDate = (uLong)(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)) ; -} - -/* - Get Info about the current file in the zipfile, with internal only info -*/ -local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, - unz_file_info *pfile_info, - unz_file_info_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -local int unzlocal_GetCurrentFileInfoInternal (file, - pfile_info, - pfile_info_internal, - szFileName, fileNameBufferSize, - extraField, extraFieldBufferSize, - szComment, commentBufferSize) - unzFile file; - unz_file_info *pfile_info; - unz_file_info_internal *pfile_info_internal; - char *szFileName; - uLong fileNameBufferSize; - void *extraField; - uLong extraFieldBufferSize; - char *szComment; - uLong commentBufferSize; -{ - unz_s* s; - unz_file_info file_info; - unz_file_info_internal file_info_internal; - int err=UNZ_OK; - uLong uMagic; - long lSeek=0; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (ZSEEK(s->z_filefunc, s->filestream, - s->pos_in_central_dir+s->byte_before_the_zipfile, - ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - - /* we check the magic */ - if (err==UNZ_OK) - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x02014b50) - err=UNZ_BADZIPFILE; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) - err=UNZ_ERRNO; - - unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - - lSeek+=file_info.size_filename; - if ((err==UNZ_OK) && (szFileName!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_filename0) && (fileNameBufferSize>0)) - if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - lSeek -= uSizeRead; - } - - - if ((err==UNZ_OK) && (extraField!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) - if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - lSeek += file_info.size_file_extra - uSizeRead; - } - else - lSeek+=file_info.size_file_extra; - - - if ((err==UNZ_OK) && (szComment!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - if ((file_info.size_file_comment>0) && (commentBufferSize>0)) - if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - lSeek+=file_info.size_file_comment - uSizeRead; - } - else - lSeek+=file_info.size_file_comment; - - if ((err==UNZ_OK) && (pfile_info!=NULL)) - *pfile_info=file_info; - - if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) - *pfile_info_internal=file_info_internal; - - return err; -} - - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. -*/ -extern int ZEXPORT unzGetCurrentFileInfo (file, - pfile_info, - szFileName, fileNameBufferSize, - extraField, extraFieldBufferSize, - szComment, commentBufferSize) - unzFile file; - unz_file_info *pfile_info; - char *szFileName; - uLong fileNameBufferSize; - void *extraField; - uLong extraFieldBufferSize; - char *szComment; - uLong commentBufferSize; -{ - return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); -} - -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ -extern int ZEXPORT unzGoToFirstFile (file) - unzFile file; -{ - int err=UNZ_OK; - unz_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - s->pos_in_central_dir=s->offset_central_dir; - s->num_file=0; - err=unzlocal_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; -} - -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ -extern int ZEXPORT unzGoToNextFile (file) - unzFile file; -{ - unz_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_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) - 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 = unzlocal_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; -} - - -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzipStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ -extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) - unzFile file; - const char *szFileName; - int iCaseSensitivity; -{ - unz_s* s; - int err; - - /* We remember the 'current' position in the file so that we can jump - * back there if we fail. - */ - unz_file_info cur_file_infoSaved; - unz_file_info_internal cur_file_info_internalSaved; - uLong num_fileSaved; - uLong pos_in_central_dirSaved; - - - if (file==NULL) - return UNZ_PARAMERROR; - - if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) - return UNZ_PARAMERROR; - - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - /* Save the current state */ - num_fileSaved = s->num_file; - pos_in_central_dirSaved = s->pos_in_central_dir; - cur_file_infoSaved = s->cur_file_info; - cur_file_info_internalSaved = s->cur_file_info_internal; - - err = unzGoToFirstFile(file); - - while (err == UNZ_OK) - { - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - err = unzGetCurrentFileInfo(file,NULL, - szCurrentFileName,sizeof(szCurrentFileName)-1, - NULL,0,NULL,0); - if (err == UNZ_OK) - { - if (unzStringFileNameCompare(szCurrentFileName, - szFileName,iCaseSensitivity)==0) - return UNZ_OK; - err = unzGoToNextFile(file); - } - } - - /* We failed, so restore the state of the 'current file' to where we - * were. - */ - s->num_file = num_fileSaved ; - s->pos_in_central_dir = pos_in_central_dirSaved ; - s->cur_file_info = cur_file_infoSaved; - s->cur_file_info_internal = cur_file_info_internalSaved; - return err; -} - - -/* -/////////////////////////////////////////// -// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) -// I need random access -// -// Further optimization could be realized by adding an ability -// to cache the directory in memory. The goal being a single -// comprehensive file read to put the file I need in a memory. -*/ - -/* -typedef struct unz_file_pos_s -{ - uLong pos_in_zip_directory; // offset in file - uLong num_of_file; // # of file -} unz_file_pos; -*/ - -extern int ZEXPORT unzGetFilePos(file, file_pos) - unzFile file; - unz_file_pos* file_pos; -{ - unz_s* s; - - if (file==NULL || file_pos==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - file_pos->pos_in_zip_directory = s->pos_in_central_dir; - file_pos->num_of_file = s->num_file; - - return UNZ_OK; -} - -extern int ZEXPORT unzGoToFilePos(file, file_pos) - unzFile file; - unz_file_pos* file_pos; -{ - unz_s* s; - int err; - - if (file==NULL || file_pos==NULL) - return UNZ_PARAMERROR; - s=(unz_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 = unzlocal_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; -} - -/* -// Unzip Helper Functions - should be here? -/////////////////////////////////////////// -*/ - -/* - 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 unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, - poffset_local_extrafield, - psize_local_extrafield) - unz_s* s; - uInt* piSizeVar; - uLong *poffset_local_extrafield; - uInt *psize_local_extrafield; -{ - uLong uMagic,uData,uFlags; - uLong size_filename; - uLong size_extra_field; - int err=UNZ_OK; - - *piSizeVar = 0; - *poffset_local_extrafield = 0; - *psize_local_extrafield = 0; - - if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + - s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - - if (err==UNZ_OK) - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x04034b50) - err=UNZ_BADZIPFILE; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) - err=UNZ_ERRNO; -/* - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) - err=UNZ_BADZIPFILE; -*/ - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) - err=UNZ_ERRNO; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) - err=UNZ_BADZIPFILE; - - if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ - err=UNZ_ERRNO; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && - ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) - err=UNZ_BADZIPFILE; - - *piSizeVar += (uInt)size_filename; - - if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) - err=UNZ_ERRNO; - *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + - SIZEZIPLOCALHEADER + size_filename; - *psize_local_extrafield = (uInt)size_extra_field; - - *piSizeVar += (uInt)size_extra_field; - - return err; -} - -/* - 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 (file, method, level, raw, password) - unzFile file; - int* method; - int* level; - int raw; - const char* password; -{ - int err=UNZ_OK; - uInt iSizeVar; - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - uLong offset_local_extrafield; /* offset of the local extra field */ - uInt size_local_extrafield; /* size of the local extra field */ -# ifndef NOUNCRYPT - char source[12]; -# else - if (password != NULL) - return UNZ_PARAMERROR; -# endif - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (!s->current_file_ok) - return UNZ_PARAMERROR; - - if (s->pfile_in_zip_read != NULL) - unzCloseCurrentFile(file); - - if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, - &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) - return UNZ_BADZIPFILE; - - pfile_in_zip_read_info = (file_in_zip_read_info_s*) - ALLOC(sizeof(file_in_zip_read_info_s)); - if (pfile_in_zip_read_info==NULL) - return UNZ_INTERNALERROR; - - pfile_in_zip_read_info->read_buffer=(char*)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) - { - TRYFREE(pfile_in_zip_read_info); - return UNZ_INTERNALERROR; - } - - pfile_in_zip_read_info->stream_initialised=0; - - if (method!=NULL) - *method = (int)s->cur_file_info.compression_method; - - 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; - } - } - - if ((s->cur_file_info.compression_method!=0) && - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - - pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; - pfile_in_zip_read_info->crc32=0; - pfile_in_zip_read_info->compression_method = - s->cur_file_info.compression_method; - pfile_in_zip_read_info->filestream=s->filestream; - pfile_in_zip_read_info->z_filefunc=s->z_filefunc; - pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; - - pfile_in_zip_read_info->stream.total_out = 0; - - if ((s->cur_file_info.compression_method==Z_DEFLATED) && - (!raw)) - { - 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)0; - pfile_in_zip_read_info->stream.next_in = (voidpf)0; - pfile_in_zip_read_info->stream.avail_in = 0; - - err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=1; - else - { - TRYFREE(pfile_in_zip_read_info); - return err; - } - /* windowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. - * In unzip, i don't wait absolutely Z_STREAM_END because I known the - * size of both compressed and uncompressed data - */ - } - pfile_in_zip_read_info->rest_read_compressed = - s->cur_file_info.compressed_size ; - pfile_in_zip_read_info->rest_read_uncompressed = - s->cur_file_info.uncompressed_size ; - - - pfile_in_zip_read_info->pos_in_zipfile = - s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + - iSizeVar; - - pfile_in_zip_read_info->stream.avail_in = (uInt)0; - - s->pfile_in_zip_read = pfile_in_zip_read_info; - -# ifndef NOUNCRYPT - if (password != NULL) - { - int i; - s->pcrc_32_tab = get_crc_table(); - init_keys(password,s->keys,s->pcrc_32_tab); - if (ZSEEK(s->z_filefunc, s->filestream, - s->pfile_in_zip_read->pos_in_zipfile + - s->pfile_in_zip_read->byte_before_the_zipfile, - SEEK_SET)!=0) - return UNZ_INTERNALERROR; - if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12) - return UNZ_INTERNALERROR; - - for (i = 0; i<12; i++) - zdecode(s->keys,s->pcrc_32_tab,source[i]); - - s->pfile_in_zip_read->pos_in_zipfile+=12; - s->encrypted=1; - } -# endif - - - return UNZ_OK; -} - -extern int ZEXPORT unzOpenCurrentFile (file) - unzFile file; -{ - return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); -} - -extern int ZEXPORT unzOpenCurrentFilePassword (file, password) - unzFile file; - const char* password; -{ - return unzOpenCurrentFile3(file, NULL, NULL, 0, password); -} - -extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) - unzFile file; - int* method; - int* level; - int raw; -{ - return unzOpenCurrentFile3(file, method, level, raw, NULL); -} - -/* - Read bytes from the current file. - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ -extern int ZEXPORT unzReadCurrentFile (file, buf, len) - unzFile file; - voidp buf; - unsigned len; -{ - int err=UNZ_OK; - uInt iRead = 0; - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if ((pfile_in_zip_read_info->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 ((len>pfile_in_zip_read_info->rest_read_uncompressed) && - (!(pfile_in_zip_read_info->raw))) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_uncompressed; - - if ((len>pfile_in_zip_read_info->rest_read_compressed+ - pfile_in_zip_read_info->stream.avail_in) && - (pfile_in_zip_read_info->raw)) - 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; - - while (pfile_in_zip_read_info->stream.avail_out>0) - { - if ((pfile_in_zip_read_info->stream.avail_in==0) && - (pfile_in_zip_read_info->rest_read_compressed>0)) - { - uInt uReadThis = UNZ_BUFSIZE; - if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; - if (uReadThis == 0) - return UNZ_EOF; - if (ZSEEK(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, - ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - if (ZREAD(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->read_buffer, - uReadThis)!=uReadThis) - return UNZ_ERRNO; - - -# ifndef NOUNCRYPT - if(s->encrypted) - { - uInt i; - for(i=0;iread_buffer[i] = - zdecode(s->keys,s->pcrc_32_tab, - pfile_in_zip_read_info->read_buffer[i]); - } -# endif - - - pfile_in_zip_read_info->pos_in_zipfile += uReadThis; - - pfile_in_zip_read_info->rest_read_compressed-=uReadThis; - - 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)uReadThis; - } - - if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) - { - uInt uDoCopy,i ; - - if ((pfile_in_zip_read_info->stream.avail_in == 0) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - return (iRead==0) ? UNZ_EOF : iRead; - - if (pfile_in_zip_read_info->stream.avail_out < - pfile_in_zip_read_info->stream.avail_in) - uDoCopy = pfile_in_zip_read_info->stream.avail_out ; - else - uDoCopy = pfile_in_zip_read_info->stream.avail_in ; - - for (i=0;istream.next_out+i) = - *(pfile_in_zip_read_info->stream.next_in+i); - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, - pfile_in_zip_read_info->stream.next_out, - uDoCopy); - pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; - pfile_in_zip_read_info->stream.avail_in -= uDoCopy; - pfile_in_zip_read_info->stream.avail_out -= uDoCopy; - pfile_in_zip_read_info->stream.next_out += uDoCopy; - pfile_in_zip_read_info->stream.next_in += uDoCopy; - pfile_in_zip_read_info->stream.total_out += uDoCopy; - iRead += uDoCopy; - } - else - { - uLong uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - uLong uOutThis; - int flush=Z_SYNC_FLUSH; - - uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; - bufBefore = pfile_in_zip_read_info->stream.next_out; - - /* - if ((pfile_in_zip_read_info->rest_read_uncompressed == - pfile_in_zip_read_info->stream.avail_out) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - flush = Z_FINISH; - */ - err=inflate(&pfile_in_zip_read_info->stream,flush); - - if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) - err = Z_DATA_ERROR; - - uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->crc32 = - crc32(pfile_in_zip_read_info->crc32,bufBefore, - (uInt)(uOutThis)); - - pfile_in_zip_read_info->rest_read_uncompressed -= - uOutThis; - - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - if (err==Z_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=Z_OK) - break; - } - } - - if (err==Z_OK) - return iRead; - return err; -} - - -/* - Give the current position in uncompressed data -*/ -extern z_off_t ZEXPORT unztell (file) - unzFile file; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - return (z_off_t)pfile_in_zip_read_info->stream.total_out; -} - - -/* - return 1 if the end of file was reached, 0 elsewhere -*/ -extern int ZEXPORT unzeof (file) - unzFile file; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - if (pfile_in_zip_read_info->rest_read_uncompressed == 0) - return 1; - else - return 0; -} - - - -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field that can be read - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ -extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) - unzFile file; - voidp buf; - unsigned len; -{ - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - uInt read_now; - uLong size_to_read; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - size_to_read = (pfile_in_zip_read_info->size_local_extrafield - - pfile_in_zip_read_info->pos_local_extrafield); - - if (buf==NULL) - return (int)size_to_read; - - if (len>size_to_read) - read_now = (uInt)size_to_read; - else - read_now = (uInt)len ; - - if (read_now==0) - return 0; - - if (ZSEEK(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, - ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - if (ZREAD(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - buf,read_now)!=read_now) - return UNZ_ERRNO; - - return (int)read_now; -} - -/* - Close the file in zip opened with unzipOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ -extern int ZEXPORT unzCloseCurrentFile (file) - unzFile file; -{ - int err=UNZ_OK; - - unz_s* s; - file_in_zip_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && - (!pfile_in_zip_read_info->raw)) - { - if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) - err=UNZ_CRCERROR; - } - - - TRYFREE(pfile_in_zip_read_info->read_buffer); - pfile_in_zip_read_info->read_buffer = NULL; - if (pfile_in_zip_read_info->stream_initialised) - inflateEnd(&pfile_in_zip_read_info->stream); - - pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); - - s->pfile_in_zip_read=NULL; - - return err; -} - - -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ -extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) - unzFile file; - char *szComment; - uLong uSizeBuf; -{ - int err=UNZ_OK; - unz_s* s; - uLong uReadThis ; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - - uReadThis = uSizeBuf; - if (uReadThis>s->gi.size_comment) - uReadThis = s->gi.size_comment; - - if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - if (uReadThis>0) - { - *szComment='\0'; - if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) - return UNZ_ERRNO; - } - - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) - *(szComment+s->gi.size_comment)='\0'; - return (int)uReadThis; -} - -/* Additions by RX '2004 */ -extern uLong ZEXPORT unzGetOffset (file) - unzFile file; -{ - unz_s* s; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - if (!s->current_file_ok) - return 0; - if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) - if (s->num_file==s->gi.number_entry) - return 0; - return s->pos_in_central_dir; -} - -extern int ZEXPORT unzSetOffset (file, pos) - unzFile file; - uLong pos; -{ - unz_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz_s*)file; - - s->pos_in_central_dir = pos; - s->num_file = s->gi.number_entry; /* hack */ - err = unzlocal_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; -} +/* unzip.c -- IO for uncompress .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + + ------------------------------------------------------------------------------------ + Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of + compatibility with older software. The following is from the original crypt.c. + Code woven in by Terry Thorsen 1/2003. + + Copyright (c) 1990-2000 Info-ZIP. All rights reserved. + + See the accompanying file LICENSE, version 2000-Apr-09 or later + (the contents of which are also included in zip.h) for terms of use. + If, for some reason, all these files are missing, the Info-ZIP license + also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html + + crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + ------------------------------------------------------------------------------------ + + Changes in unzip.c + + 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos + 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* + 2007-2008 - Even Rouault - Remove old C style function prototypes + 2007-2008 - Even Rouault - Add unzip support for ZIP64 + + Copyright (C) 2007-2008 Even Rouault + + + Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). + Oct-2009 - Mathias Svensson - 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 + Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant + Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) + Patch created by Daniel Borca + + Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer + + Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson + +*/ + + +#include +#include +#include + +#ifndef NOUNCRYPT + #define NOUNCRYPT +#endif + +#include "zlib.h" +#include "unzip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + + +#ifndef CASESENSITIVITYDEFAULT_NO +# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) +# define CASESENSITIVITYDEFAULT_NO +# endif +#endif + + +#ifndef UNZ_BUFSIZE +#define UNZ_BUFSIZE (16384) +#endif + +#ifndef UNZ_MAXFILENAMEINZIP +#define UNZ_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) + + +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 +{ + ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ +} unz_file_info64_internal; + + +/* file_in_zip_read_info_s contain internal information about a file in zipfile, + when reading and decompress it */ +typedef struct +{ + char *read_buffer; /* internal buffer for compressed data */ + z_stream stream; /* zLib stream structure for inflate */ + +#ifdef HAVE_BZIP2 + bz_stream bstream; /* bzLib stream structure for bziped */ +#endif + + ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ + uLong stream_initialised; /* flag set if stream structure is initialised*/ + + ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ + uInt size_local_extrafield;/* size of the local extra field */ + ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ + ZPOS64_T total_out_64; + + uLong crc32; /* crc32 of all data uncompressed */ + uLong crc32_wait; /* crc32 we must obtain after decompress all */ + ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ + ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ + zlib_filefunc64_32_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + uLong compression_method; /* compression method (0==store) */ + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + int raw; +} file_in_zip64_read_info_s; + + +/* unz64_s contain internal information about the zipfile +*/ +typedef struct +{ + zlib_filefunc64_32_def z_filefunc; + int is64bitOpenFunction; + voidpf filestream; /* io structore of the zipfile */ + unz_global_info64 gi; /* public global information */ + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + ZPOS64_T num_file; /* number of the current file in the zipfile*/ + ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ + ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ + ZPOS64_T central_pos; /* position of the beginning of the central dir*/ + + ZPOS64_T size_central_dir; /* size of the central directory */ + ZPOS64_T offset_central_dir; /* offset of start of central directory with + respect to the starting disk number */ + + 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; /* structure about the current + file if we are decompressing it */ + int encrypted; + + int isZip64; + +# ifndef NOUNCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const z_crc_t* pcrc_32_tab; +# endif +} unz64_s; + + +#ifndef NOUNCRYPT +#include "crypt.h" +#endif + +/* =========================================================================== + Read a byte from a gz_stream; update next_in and avail_in. Return EOF + for end of file. + IN assertion: the stream s has been successfully opened for reading. +*/ + + +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) + { + *pi = (int)c; + return UNZ_OK; + } + else + { + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return UNZ_ERRNO; + else + return UNZ_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +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; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<8; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + 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) +{ + uLong x ; + int i = 0; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<8; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((uLong)i)<<16; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<24; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + 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) +{ + ZPOS64_T x ; + int i = 0; + int err; + + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (ZPOS64_T)i; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<8; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<16; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<24; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<32; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<40; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<48; + + if (err==UNZ_OK) + err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); + x |= ((ZPOS64_T)i)<<56; + + if (err==UNZ_OK) + *pX = x; + else + *pX = 0; + return err; +} + +/* My own strcmpi / strcasecmp */ +local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) +{ + for (;;) + { + char c1=*(fileName1++); + char c2=*(fileName2++); + if ((c1>='a') && (c1<='z')) + c1 -= 0x20; + if ((c2>='a') && (c2<='z')) + c2 -= 0x20; + if (c1=='\0') + return ((c2=='\0') ? 0 : -1); + if (c2=='\0') + return 1; + if (c1c2) + return 1; + } +} + + +#ifdef CASESENSITIVITYDEFAULT_NO +#define CASESENSITIVITYDEFAULTVALUE 2 +#else +#define CASESENSITIVITYDEFAULTVALUE 1 +#endif + +#ifndef STRCMPCASENOSENTIVEFUNCTION +#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal +#endif + +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) + +*/ +extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, + const char* fileName2, + int iCaseSensitivity) + +{ + if (iCaseSensitivity==0) + iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; + + if (iCaseSensitivity==1) + return strcmp(fileName1,fileName2); + + return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif + +/* + Locate the Central directory of a zipfile (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) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + + +/* + 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(const zlib_filefunc64_32_def* pzlib_filefunc_def, + voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + uLong uL; + ZPOS64_T relativeOffset; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + if (uPosFound == 0) + return 0; + + /* Zip64 end of central directory locator */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature, already checked */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + + /* number of the disk with the start of the zip64 end of central directory */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + if (uL != 0) + return 0; + + /* relative offset of the zip64 end of central directory record */ + if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) + return 0; + + /* total number of disks */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + if (uL != 1) + return 0; + + /* Goto end of central directory record */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature */ + if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) + return 0; + + if (uL != 0x06064b50) + return 0; + + return relativeOffset; +} + +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer + "zlib/zlib114.zip". + If the zipfile cannot be opened (file doesn't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. +*/ +local unzFile unzOpenInternal (const void *path, + zlib_filefunc64_32_def* pzlib_filefunc64_32_def, + int is64bitOpenFunction) +{ + unz64_s us; + unz64_s *s; + ZPOS64_T central_pos; + uLong uL; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + ZPOS64_T number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + + int err=UNZ_OK; + + if (unz_copyright[0]!=' ') + return NULL; + + us.z_filefunc.zseek32_file = NULL; + us.z_filefunc.ztell32_file = NULL; + if (pzlib_filefunc64_32_def==NULL) + fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); + else + us.z_filefunc = *pzlib_filefunc64_32_def; + us.is64bitOpenFunction = is64bitOpenFunction; + + + + us.filestream = ZOPEN64(us.z_filefunc, + path, + ZLIB_FILEFUNC_MODE_READ | + ZLIB_FILEFUNC_MODE_EXISTING); + if (us.filestream==NULL) + return NULL; + + central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); + if (central_pos) + { + uLong uS; + ZPOS64_T uL64; + + us.isZip64 = 1; + + if (ZSEEK64(us.z_filefunc, us.filestream, + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* size of zip64 end of central directory record */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) + err=UNZ_ERRNO; + + /* version made by */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) + err=UNZ_ERRNO; + + /* version needed to extract */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central directory on this disk */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central directory */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) + err=UNZ_ERRNO; + + /* 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; + + us.gi.size_comment = 0; + } + else + { + central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); + if (central_pos==0) + err=UNZ_ERRNO; + + us.isZip64 = 0; + + if (ZSEEK64(us.z_filefunc, us.filestream, + central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + /* the signature, already checked */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of this disk */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) + err=UNZ_ERRNO; + + /* number of the disk with the start of the central directory */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) + err=UNZ_ERRNO; + + /* total number of entries in the central dir on this disk */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.gi.number_entry = uL; + + /* total number of entries in the central dir */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + number_entry_CD = uL; + + if ((number_entry_CD!=us.gi.number_entry) || + (number_disk_with_CD!=0) || + (number_disk!=0)) + err=UNZ_BADZIPFILE; + + /* size of the central directory */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.size_central_dir = uL; + + /* offset of start of central directory with respect to the + starting disk number */ + if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) + err=UNZ_ERRNO; + us.offset_central_dir = uL; + + /* zipfile comment length */ + if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) + err=UNZ_ERRNO; + } + + if ((central_pospfile_in_zip_read!=NULL) + unzCloseCurrentFile(file); + + ZCLOSE64(s->z_filefunc, s->filestream); + TRYFREE(s); + return UNZ_OK; +} + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ +extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) +{ + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + *pglobal_info=s->gi; + return UNZ_OK; +} + +extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) +{ + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + 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; + return UNZ_OK; +} +/* + Translate date/time from Dos format to tm_unz (readable more easilty) +*/ +local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) +{ + ZPOS64_T uDate; + 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)) ; +} + +/* + Get Info about the current file in the zipfile, with internal only info +*/ +local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, + unz_file_info64 *pfile_info, + unz_file_info64_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +local int unz64local_GetCurrentFileInfoInternal (unzFile file, + unz_file_info64 *pfile_info, + unz_file_info64_internal + *pfile_info_internal, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize) +{ + unz64_s* s; + unz_file_info64 file_info; + unz_file_info64_internal file_info_internal; + int err=UNZ_OK; + uLong uMagic; + long lSeek=0; + uLong uL; + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (ZSEEK64(s->z_filefunc, s->filestream, + s->pos_in_central_dir+s->byte_before_the_zipfile, + ZLIB_FILEFUNC_SEEK_SET)!=0) + err=UNZ_ERRNO; + + + /* we check the magic */ + if (err==UNZ_OK) + { + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x02014b50) + err=UNZ_BADZIPFILE; + } + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) + err=UNZ_ERRNO; + + unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info.compressed_size = uL; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info.uncompressed_size = uL; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) + err=UNZ_ERRNO; + + // relative offset of local header + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + file_info_internal.offset_curfile = uL; + + lSeek+=file_info.size_filename; + if ((err==UNZ_OK) && (szFileName!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_filename0) && (fileNameBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek -= uSizeRead; + } + + // Read extrafield + if ((err==UNZ_OK) && (extraField!=NULL)) + { + ZPOS64_T uSizeRead ; + if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + + lSeek += file_info.size_file_extra - (uLong)uSizeRead; + } + else + lSeek += file_info.size_file_extra; + + + if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) + { + uLong acc = 0; + + // since lSeek now points to after the extra field we need to move back + lSeek -= file_info.size_file_extra; + + if (lSeek!=0) + { + if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + while(acc < file_info.size_file_extra) + { + uLong headerId; + uLong dataSize; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) + err=UNZ_ERRNO; + + /* ZIP64 extra fields */ + if (headerId == 0x0001) + { + uLong uL; + + if(file_info.uncompressed_size == MAXU32) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info.compressed_size == MAXU32) + { + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info_internal.offset_curfile == MAXU32) + { + /* Relative Header offset */ + if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) + err=UNZ_ERRNO; + } + + if(file_info.disk_num_start == MAXU32) + { + /* Disk Start Number */ + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) + err=UNZ_ERRNO; + } + + } + else + { + if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) + err=UNZ_ERRNO; + } + + acc += 2 + 2 + dataSize; + } + } + + if ((err==UNZ_OK) && (szComment!=NULL)) + { + uLong uSizeRead ; + if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) + lSeek=0; + else + err=UNZ_ERRNO; + } + + if ((file_info.size_file_comment>0) && (commentBufferSize>0)) + if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) + err=UNZ_ERRNO; + lSeek+=file_info.size_file_comment - uSizeRead; + } + else + lSeek+=file_info.size_file_comment; + + + if ((err==UNZ_OK) && (pfile_info!=NULL)) + *pfile_info=file_info; + + if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) + *pfile_info_internal=file_info_internal; + + return err; +} + + + +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. +*/ +extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, + unz_file_info64 * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) +{ + return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); +} + +extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, + unz_file_info * pfile_info, + char * szFileName, uLong fileNameBufferSize, + void *extraField, uLong extraFieldBufferSize, + char* szComment, uLong commentBufferSize) +{ + int err; + unz_file_info64 file_info64; + err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, + szFileName,fileNameBufferSize, + extraField,extraFieldBufferSize, + szComment,commentBufferSize); + 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; + pfile_info->compression_method = file_info64.compression_method; + pfile_info->dosDate = file_info64.dosDate; + pfile_info->crc = file_info64.crc; + + pfile_info->size_filename = file_info64.size_filename; + pfile_info->size_file_extra = file_info64.size_file_extra; + pfile_info->size_file_comment = file_info64.size_file_comment; + + pfile_info->disk_num_start = file_info64.disk_num_start; + pfile_info->internal_fa = file_info64.internal_fa; + pfile_info->external_fa = file_info64.external_fa; + + pfile_info->tmu_date = file_info64.tmu_date, + + + pfile_info->compressed_size = (uLong)file_info64.compressed_size; + pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; + + } + return err; +} +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ +extern int ZEXPORT unzGoToFirstFile (unzFile file) +{ + int err=UNZ_OK; + unz64_s* s; + if (file==NULL) + return UNZ_PARAMERROR; + 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, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ +extern int ZEXPORT unzGoToNextFile (unzFile file) +{ + unz64_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + 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) + 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, + NULL,0,NULL,0,NULL,0); + s->current_file_ok = (err == UNZ_OK); + return err; +} + + +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ +extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) +{ + unz64_s* s; + int err; + + /* We remember the 'current' position in the file so that we can jump + * back there if we fail. + */ + unz_file_info64 cur_file_infoSaved; + unz_file_info64_internal cur_file_info_internalSaved; + ZPOS64_T num_fileSaved; + ZPOS64_T pos_in_central_dirSaved; + + + if (file==NULL) + return UNZ_PARAMERROR; + + if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) + return UNZ_PARAMERROR; + + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + /* Save the current state */ + num_fileSaved = s->num_file; + pos_in_central_dirSaved = s->pos_in_central_dir; + cur_file_infoSaved = s->cur_file_info; + cur_file_info_internalSaved = s->cur_file_info_internal; + + err = unzGoToFirstFile(file); + + while (err == UNZ_OK) + { + char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; + err = unzGetCurrentFileInfo64(file,NULL, + szCurrentFileName,sizeof(szCurrentFileName)-1, + NULL,0,NULL,0); + if (err == UNZ_OK) + { + if (unzStringFileNameCompare(szCurrentFileName, + szFileName,iCaseSensitivity)==0) + return UNZ_OK; + err = unzGoToNextFile(file); + } + } + + /* We failed, so restore the state of the 'current file' to where we + * were. + */ + s->num_file = num_fileSaved ; + s->pos_in_central_dir = pos_in_central_dirSaved ; + s->cur_file_info = cur_file_infoSaved; + s->cur_file_info_internal = cur_file_info_internalSaved; + return err; +} + + +/* +/////////////////////////////////////////// +// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) +// I need random access +// +// Further optimization could be realized by adding an ability +// to cache the directory in memory. The goal being a single +// comprehensive file read to put the file I need in a memory. +*/ + +/* +typedef struct unz_file_pos_s +{ + ZPOS64_T pos_in_zip_directory; // offset in file + ZPOS64_T num_of_file; // # of file +} unz_file_pos; +*/ + +extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) +{ + unz64_s* s; + + if (file==NULL || file_pos==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_END_OF_LIST_OF_FILE; + + file_pos->pos_in_zip_directory = s->pos_in_central_dir; + file_pos->num_of_file = s->num_file; + + return UNZ_OK; +} + +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) + { + 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 unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) +{ + unz64_s* s; + int err; + + if (file==NULL || file_pos==NULL) + return UNZ_PARAMERROR; + 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); + /* return results */ + s->current_file_ok = (err == UNZ_OK); + return err; +} + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos) +{ + unz64_file_pos file_pos64; + if (file_pos == NULL) + 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); +} + +/* +// Unzip Helper Functions - should be here? +/////////////////////////////////////////// +*/ + +/* + 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, + uInt * psize_local_extrafield) +{ + uLong uMagic,uData,uFlags; + uLong size_filename; + uLong size_extra_field; + int err=UNZ_OK; + + *piSizeVar = 0; + *poffset_local_extrafield = 0; + *psize_local_extrafield = 0; + + if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + + s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + + if (err==UNZ_OK) + { + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) + err=UNZ_ERRNO; + else if (uMagic!=0x04034b50) + err=UNZ_BADZIPFILE; + } + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) + err=UNZ_ERRNO; +/* + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) + err=UNZ_BADZIPFILE; +*/ + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) + err=UNZ_ERRNO; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) + err=UNZ_BADZIPFILE; + + if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && +/* #ifdef HAVE_BZIP2 */ + (s->cur_file_info.compression_method!=Z_BZIP2ED) && +/* #endif */ + (s->cur_file_info.compression_method!=Z_DEFLATED)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ + err=UNZ_ERRNO; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ + err=UNZ_ERRNO; + else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ + err=UNZ_ERRNO; + else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) + err=UNZ_BADZIPFILE; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) + err=UNZ_ERRNO; + else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) + err=UNZ_BADZIPFILE; + + *piSizeVar += (uInt)size_filename; + + if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) + err=UNZ_ERRNO; + *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + + SIZEZIPLOCALHEADER + size_filename; + *psize_local_extrafield = (uInt)size_extra_field; + + *piSizeVar += (uInt)size_extra_field; + + return err; +} + +/* + 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) +{ + int err=UNZ_OK; + uInt iSizeVar; + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ + uInt size_local_extrafield; /* size of the local extra field */ +# ifndef NOUNCRYPT + char source[12]; +# else + if (password != NULL) + return UNZ_PARAMERROR; +# endif + + if (file==NULL) + return UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return UNZ_PARAMERROR; + + if (s->pfile_in_zip_read != NULL) + unzCloseCurrentFile(file); + + 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)); + if (pfile_in_zip_read_info==NULL) + return UNZ_INTERNALERROR; + + pfile_in_zip_read_info->read_buffer=(char*)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) + { + TRYFREE(pfile_in_zip_read_info); + return UNZ_INTERNALERROR; + } + + pfile_in_zip_read_info->stream_initialised=0; + + if (method!=NULL) + *method = (int)s->cur_file_info.compression_method; + + 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; + } + } + + if ((s->cur_file_info.compression_method!=0) && +/* #ifdef HAVE_BZIP2 */ + (s->cur_file_info.compression_method!=Z_BZIP2ED) && +/* #endif */ + (s->cur_file_info.compression_method!=Z_DEFLATED)) + + err=UNZ_BADZIPFILE; + + pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; + pfile_in_zip_read_info->crc32=0; + pfile_in_zip_read_info->total_out_64=0; + pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; + pfile_in_zip_read_info->filestream=s->filestream; + pfile_in_zip_read_info->z_filefunc=s->z_filefunc; + pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; + + pfile_in_zip_read_info->stream.total_out = 0; + + if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) + { +#ifdef HAVE_BZIP2 + 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; + + 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)0; + pfile_in_zip_read_info->stream.next_in = (voidpf)0; + pfile_in_zip_read_info->stream.avail_in = 0; + + 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 + { + TRYFREE(pfile_in_zip_read_info); + return err; + } +#else + pfile_in_zip_read_info->raw=1; +#endif + } + else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) + { + 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)0; + pfile_in_zip_read_info->stream.next_in = 0; + pfile_in_zip_read_info->stream.avail_in = 0; + + err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); + if (err == Z_OK) + pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; + else + { + TRYFREE(pfile_in_zip_read_info); + return err; + } + /* windowBits is passed < 0 to tell that there is no zlib header. + * Note that in this case inflate *requires* an extra "dummy" byte + * after the compressed stream in order to complete decompression and + * return Z_STREAM_END. + * In unzip, i don't wait absolutely Z_STREAM_END because I known the + * size of both compressed and uncompressed data + */ + } + pfile_in_zip_read_info->rest_read_compressed = + s->cur_file_info.compressed_size ; + pfile_in_zip_read_info->rest_read_uncompressed = + s->cur_file_info.uncompressed_size ; + + + pfile_in_zip_read_info->pos_in_zipfile = + s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + + iSizeVar; + + pfile_in_zip_read_info->stream.avail_in = (uInt)0; + + s->pfile_in_zip_read = pfile_in_zip_read_info; + s->encrypted = 0; + +# ifndef NOUNCRYPT + if (password != NULL) + { + int i; + s->pcrc_32_tab = get_crc_table(); + init_keys(password,s->keys,s->pcrc_32_tab); + if (ZSEEK64(s->z_filefunc, s->filestream, + s->pfile_in_zip_read->pos_in_zipfile + + s->pfile_in_zip_read->byte_before_the_zipfile, + SEEK_SET)!=0) + return UNZ_INTERNALERROR; + if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) + return UNZ_INTERNALERROR; + + for (i = 0; i<12; i++) + zdecode(s->keys,s->pcrc_32_tab,source[i]); + + s->pfile_in_zip_read->pos_in_zipfile+=12; + s->encrypted=1; + } +# endif + + + return UNZ_OK; +} + +extern int ZEXPORT unzOpenCurrentFile (unzFile file) +{ + return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); +} + +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) +{ + return unzOpenCurrentFile3(file, method, level, raw, NULL); +} + +/** Addition for GDAL : START */ + +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; + if (file==NULL) + return 0; //UNZ_PARAMERROR; + pfile_in_zip_read_info=s->pfile_in_zip_read; + if (pfile_in_zip_read_info==NULL) + return 0; //UNZ_PARAMERROR; + return pfile_in_zip_read_info->pos_in_zipfile + + pfile_in_zip_read_info->byte_before_the_zipfile; +} + +/** Addition for GDAL : END */ + +/* + Read bytes from the current file. + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ +extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) +{ + int err=UNZ_OK; + uInt iRead = 0; + 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; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if (pfile_in_zip_read_info->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 ((len>pfile_in_zip_read_info->rest_read_uncompressed) && + (!(pfile_in_zip_read_info->raw))) + pfile_in_zip_read_info->stream.avail_out = + (uInt)pfile_in_zip_read_info->rest_read_uncompressed; + + if ((len>pfile_in_zip_read_info->rest_read_compressed+ + pfile_in_zip_read_info->stream.avail_in) && + (pfile_in_zip_read_info->raw)) + 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; + + while (pfile_in_zip_read_info->stream.avail_out>0) + { + if ((pfile_in_zip_read_info->stream.avail_in==0) && + (pfile_in_zip_read_info->rest_read_compressed>0)) + { + uInt uReadThis = UNZ_BUFSIZE; + if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; + if (uReadThis == 0) + return UNZ_EOF; + 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, + ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + if (ZREAD64(pfile_in_zip_read_info->z_filefunc, + pfile_in_zip_read_info->filestream, + pfile_in_zip_read_info->read_buffer, + uReadThis)!=uReadThis) + return UNZ_ERRNO; + + +# ifndef NOUNCRYPT + if(s->encrypted) + { + uInt i; + for(i=0;iread_buffer[i] = + zdecode(s->keys,s->pcrc_32_tab, + pfile_in_zip_read_info->read_buffer[i]); + } +# endif + + + pfile_in_zip_read_info->pos_in_zipfile += uReadThis; + + pfile_in_zip_read_info->rest_read_compressed-=uReadThis; + + 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)uReadThis; + } + + if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) + { + uInt uDoCopy,i ; + + if ((pfile_in_zip_read_info->stream.avail_in == 0) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + return (iRead==0) ? UNZ_EOF : iRead; + + if (pfile_in_zip_read_info->stream.avail_out < + pfile_in_zip_read_info->stream.avail_in) + uDoCopy = pfile_in_zip_read_info->stream.avail_out ; + else + uDoCopy = pfile_in_zip_read_info->stream.avail_in ; + + for (i=0;istream.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 + uDoCopy; + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, + pfile_in_zip_read_info->stream.next_out, + uDoCopy); + pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; + pfile_in_zip_read_info->stream.avail_in -= uDoCopy; + pfile_in_zip_read_info->stream.avail_out -= uDoCopy; + pfile_in_zip_read_info->stream.next_out += uDoCopy; + pfile_in_zip_read_info->stream.next_in += uDoCopy; + pfile_in_zip_read_info->stream.total_out += uDoCopy; + iRead += uDoCopy; + } + else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) + { +#ifdef HAVE_BZIP2 + uLong uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + uLong uOutThis; + + 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; + + uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; + bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; + + err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); + + uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; + + pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); + pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + 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; + + if (err==BZ_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=BZ_OK) + break; +#endif + } // end Z_BZIP2ED + else + { + ZPOS64_T uTotalOutBefore,uTotalOutAfter; + const Bytef *bufBefore; + ZPOS64_T uOutThis; + int flush=Z_SYNC_FLUSH; + + uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; + bufBefore = pfile_in_zip_read_info->stream.next_out; + + /* + if ((pfile_in_zip_read_info->rest_read_uncompressed == + pfile_in_zip_read_info->stream.avail_out) && + (pfile_in_zip_read_info->rest_read_compressed == 0)) + flush = Z_FINISH; + */ + err=inflate(&pfile_in_zip_read_info->stream,flush); + + if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) + err = Z_DATA_ERROR; + + uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; + uOutThis = uTotalOutAfter-uTotalOutBefore; + + pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; + + pfile_in_zip_read_info->crc32 = + crc32(pfile_in_zip_read_info->crc32,bufBefore, + (uInt)(uOutThis)); + + pfile_in_zip_read_info->rest_read_uncompressed -= + uOutThis; + + iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); + + if (err==Z_STREAM_END) + return (iRead==0) ? UNZ_EOF : iRead; + if (err!=Z_OK) + break; + } + } + + if (err==Z_OK) + return iRead; + return err; +} + + +/* + Give the current position in uncompressed data +*/ +extern z_off_t ZEXPORT unztell (unzFile file) +{ + 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; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + return (z_off_t)pfile_in_zip_read_info->stream.total_out; +} + +extern ZPOS64_T ZEXPORT unztell64 (unzFile file) +{ + + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + 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) + return (ZPOS64_T)-1; + + return pfile_in_zip_read_info->total_out_64; +} + + +/* + return 1 if the end of file was reached, 0 elsewhere +*/ +extern int ZEXPORT unzeof (unzFile file) +{ + 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; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + if (pfile_in_zip_read_info->rest_read_uncompressed == 0) + return 1; + else + return 0; +} + + + +/* +Read extra field from the current file (opened by unzOpenCurrentFile) +This is the local-header version of the extra field (sometimes, there is +more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field that can be read + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ +extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) +{ + unz64_s* s; + file_in_zip64_read_info_s* pfile_in_zip_read_info; + 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) + return UNZ_PARAMERROR; + + size_to_read = (pfile_in_zip_read_info->size_local_extrafield - + pfile_in_zip_read_info->pos_local_extrafield); + + if (buf==NULL) + return (int)size_to_read; + + if (len>size_to_read) + read_now = (uInt)size_to_read; + else + 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, + 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) + return UNZ_ERRNO; + + return (int)read_now; +} + +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ +extern int ZEXPORT unzCloseCurrentFile (unzFile file) +{ + int err=UNZ_OK; + + 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; + + if (pfile_in_zip_read_info==NULL) + return UNZ_PARAMERROR; + + + if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && + (!pfile_in_zip_read_info->raw)) + { + if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) + err=UNZ_CRCERROR; + } + + + TRYFREE(pfile_in_zip_read_info->read_buffer); + pfile_in_zip_read_info->read_buffer = NULL; + if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) + inflateEnd(&pfile_in_zip_read_info->stream); +#ifdef HAVE_BZIP2 + else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) + BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); +#endif + + + pfile_in_zip_read_info->stream_initialised = 0; + TRYFREE(pfile_in_zip_read_info); + + s->pfile_in_zip_read=NULL; + + return err; +} + + +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ +extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) +{ + unz64_s* s; + uLong uReadThis ; + if (file==NULL) + return (int)UNZ_PARAMERROR; + s=(unz64_s*)file; + + uReadThis = uSizeBuf; + if (uReadThis>s->gi.size_comment) + uReadThis = s->gi.size_comment; + + if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) + return UNZ_ERRNO; + + if (uReadThis>0) + { + *szComment='\0'; + if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) + return UNZ_ERRNO; + } + + if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) + *(szComment+s->gi.size_comment)='\0'; + return (int)uReadThis; +} + +/* Additions by RX '2004 */ +extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) +{ + unz64_s* s; + + if (file==NULL) + return 0; //UNZ_PARAMERROR; + s=(unz64_s*)file; + if (!s->current_file_ok) + return 0; + if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) + if (s->num_file==s->gi.number_entry) + return 0; + return s->pos_in_central_dir; +} + +extern uLong ZEXPORT unzGetOffset (unzFile file) +{ + ZPOS64_T offset64; + + if (file==NULL) + return 0; //UNZ_PARAMERROR; + offset64 = unzGetOffset64(file); + return (uLong)offset64; +} + +extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) +{ + unz64_s* s; + int err; + + if (file==NULL) + return UNZ_PARAMERROR; + 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 int ZEXPORT unzSetOffset (unzFile file, uLong pos) +{ + return unzSetOffset64(file,pos); +} diff --git a/Dependencies/minizip/unzip.h b/Dependencies/minizip/unzip.h index c3206a0..2104e39 100644 --- a/Dependencies/minizip/unzip.h +++ b/Dependencies/minizip/unzip.h @@ -1,354 +1,437 @@ -/* unzip.h -- IO for uncompress .zip files using zlib - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g - WinZip, InfoZip tools and compatible. - - Multi volume ZipFile (span) are not supported. - Encryption compatible with pkzip 2.04g only supported - Old compressions used by old PKZip 1.x are not supported - - - I WAIT FEEDBACK at mail info@winimage.com - Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution - - Condition of use and distribution are the same than 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 acknowledgment 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. - - -*/ - -/* for more info about .ZIP format, see - http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip - http://www.info-zip.org/pub/infozip/doc/ - PkWare has also a specification at : - ftp://ftp.pkware.com/probdesc.zip -*/ - -#ifndef _unz_H -#define _unz_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagunzFile__ { int unused; } unzFile__; -typedef unzFile__ *unzFile; -#else -typedef voidp unzFile; -#endif - - -#define UNZ_OK (0) -#define UNZ_END_OF_LIST_OF_FILE (-100) -#define UNZ_ERRNO (Z_ERRNO) -#define UNZ_EOF (0) -#define UNZ_PARAMERROR (-102) -#define UNZ_BADZIPFILE (-103) -#define UNZ_INTERNALERROR (-104) -#define UNZ_CRCERROR (-105) - -/* 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_info_s -{ - uLong number_entry; /* total number of entries in - the central dir on this disk */ - 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_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; -} unz_file_info; - -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) -*/ - - -extern unzFile ZEXPORT unzOpen OF((const char *path)); -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer - "zlib/zlib113.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ - -extern unzFile ZEXPORT unzOpen2 OF((const char *path, - zlib_filefunc_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unzOpen, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -extern int ZEXPORT unzClose OF((unzFile file)); -/* - Close a ZipFile opened with unzipOpen. - If there is files inside the .Zip opened with unzOpenCurrentFile (see later), - these files MUST be closed with unzipCloseCurrentFile before call unzipClose. - return UNZ_OK if there is no problem. */ - -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ - - -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ - - -/***************************************************************************/ -/* Unzip package allow you browse the directory of the zipfile */ - -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ - -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ - - -/* ****************************************** */ -/* Ryan supplied functions */ -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_pos_s -{ - uLong pos_in_zip_directory; /* offset in zip file directory */ - uLong num_of_file; /* # of file */ -} unz_file_pos; - -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos); - -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos); - -/* ****************************************** */ - -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); -/* - Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about - the current file - if szFileName!=NULL, the filemane string will be copied in szFileName - (fileNameBufferSize is the size of the buffer) - if extraField!=NULL, the extra field information will be copied in extraField - (extraFieldBufferSize is the size of the buffer). - This is the Central-header version of the extra field - if szComment!=NULL, the comment string of the file will be copied in szComment - (commentBufferSize is the size of the buffer) -*/ - -/***************************************************************************/ -/* for reading the content of the current zipfile, you can open it, read data - from it, and close it (you can close it before reading all the file) - */ - -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); -/* - Open for reading data the current file in the zipfile. - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, - const char* password)); -/* - Open for reading data the current file in the zipfile. - password is a crypting password - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, - int* method, - int* level, - int raw)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - -extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, - int* method, - int* level, - int raw, - const char* password)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - - -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ - -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read bytes from the current file (opened by unzOpenCurrentFile) - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ - -extern z_off_t ZEXPORT unztell OF((unzFile file)); -/* - Give the current position in uncompressed data -*/ - -extern int ZEXPORT unzeof OF((unzFile file)); -/* - return 1 if the end of file was reached, 0 elsewhere -*/ - -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ - -/***************************************************************************/ - -/* Get the current file offset */ -extern uLong ZEXPORT unzGetOffset (unzFile file); - -/* Set the current file offset */ -extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); - - - -#ifdef __cplusplus -} -#endif - -#endif /* _unz_H */ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------------- + + Condition of use and distribution are the same than 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 acknowledgment 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. + + --------------------------------------------------------------------------------- + + Changes + + See header of unzip64.c + +*/ + +#ifndef _unz64_H +#define _unz64_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +/* 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 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 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; +} 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; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((const char *path)); +extern unzFile ZEXPORT unzOpen64 OF((const void *path)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer + "zlib/zlib113.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. + the "64" function take a const void* pointer, because the path is just the + value passed to the open64_file_func callback. + Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path + is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* + does not describe the reality +*/ + + +extern unzFile ZEXPORT unzOpen2 OF((const char *path, + zlib_filefunc_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unzOpen, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, + zlib_filefunc64_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unz64Open, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzCloseCurrentFile before call unzClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); + +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, + unz_global_info64 *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +/* ****************************************** */ +/* Ryan supplied functions */ +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_pos_s +{ + uLong pos_in_zip_directory; /* offset in zip file directory */ + uLong num_of_file; /* # of file */ +} unz_file_pos; + +extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos); + +typedef struct unz64_file_pos_s +{ + ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ + ZPOS64_T num_of_file; /* # of file */ +} unz64_file_pos; + +extern int ZEXPORT unzGetFilePos64( + unzFile file, + unz64_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos64( + unzFile file, + const unz64_file_pos* file_pos); + +/* ****************************************** */ + +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, + unz_file_info64 *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + + +/** Addition for GDAL : START */ + +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); + +/** Addition for GDAL : END */ + + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, + const char* password)); +/* + Open for reading data the current file in the zipfile. + password is a crypting password + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, + int* method, + int* level, + int raw)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, + int* method, + int* level, + int raw, + const char* password)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); + +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +/***************************************************************************/ + +/* Get the current file offset */ +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); +extern uLong ZEXPORT unzGetOffset (unzFile file); + +/* Set the current file offset */ +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); + + + +#ifdef __cplusplus +} +#endif + +#endif /* _unz64_H */ diff --git a/Dependencies/minizip/zip.c b/Dependencies/minizip/zip.c index 400e2ba..44e88a9 100644 --- a/Dependencies/minizip/zip.c +++ b/Dependencies/minizip/zip.c @@ -1,1219 +1,2007 @@ -/* zip.c -- IO on .zip files using zlib - Version 1.01e, February 12th, 2005 - - 27 Dec 2004 Rolf Kalbermatter - Modification to zipOpen2 to support globalComment retrieval. - - Copyright (C) 1998-2005 Gilles Vollant - - Read zip.h for more info -*/ - - -#include -#include -#include -#include -#include "zlib.h" -#include "zip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -#ifndef VERSIONMADEBY -# define VERSIONMADEBY (0x0) /* platform depedent */ -#endif - -#ifndef Z_BUFSIZE -#define Z_BUFSIZE (16384) -#endif - -#ifndef Z_MAXFILENAMEINZIP -#define Z_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -/* -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) -*/ - -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -#ifndef DEF_MEM_LEVEL -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -#endif -const char zip_copyright[] = - " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; - - -#define SIZEDATA_INDATABLOCK (4096-(4*4)) - -#define LOCALHEADERMAGIC (0x04034b50) -#define CENTRALHEADERMAGIC (0x02014b50) -#define ENDHEADERMAGIC (0x06054b50) - -#define FLAG_LOCALHEADER_OFFSET (0x06) -#define CRC_LOCALHEADER_OFFSET (0x0e) - -#define SIZECENTRALHEADER (0x2e) /* 46 */ - -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 alignement */ - unsigned char data[SIZEDATA_INDATABLOCK]; -} linkedlist_datablock_internal; - -typedef struct linkedlist_data_s -{ - linkedlist_datablock_internal* first_block; - linkedlist_datablock_internal* last_block; -} linkedlist_data; - - -typedef struct -{ - z_stream stream; /* zLib stream structure for inflate */ - int stream_initialised; /* 1 is stream is initialised */ - uInt pos_in_buffered_data; /* last written byte in buffered_data */ - - uLong pos_local_header; /* offset of the local header of the file - currenty writing */ - char* central_header; /* central header data for the current file */ - uLong size_centralheader; /* size of the central header for cur file */ - uLong flag; /* flag of the file currently writing */ - - int method; /* compression method of file currenty wr.*/ - int raw; /* 1 for directly writing raw data */ - Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ - uLong dosDate; - uLong crc32; - int encrypt; -#ifndef NOCRYPT - unsigned long keys[3]; /* keys defining the pseudo-random sequence */ - const unsigned long* pcrc_32_tab; - int crypt_header_size; -#endif -} curfile_info; - -typedef struct -{ - zlib_filefunc_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ - linkedlist_data central_dir;/* datablock with central dir in construction*/ - int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ - curfile_info ci; /* info on the file curretly writing */ - - uLong begin_pos; /* position of the beginning of the zipfile */ - uLong add_position_when_writting_offset; - uLong number_entry; -#ifndef NO_ADDFILEINEXISTINGZIP - char *globalcomment; -#endif -} zip_internal; - - - -#ifndef NOCRYPT -#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED -#include "crypt.h" -#endif - -local linkedlist_datablock_internal* allocate_new_datablock() -{ - linkedlist_datablock_internal* ldi; - ldi = (linkedlist_datablock_internal*) - ALLOC(sizeof(linkedlist_datablock_internal)); - if (ldi!=NULL) - { - ldi->next_datablock = NULL ; - ldi->filled_in_this_block = 0 ; - ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; - } - return ldi; -} - -local void free_datablock(ldi) - linkedlist_datablock_internal* ldi; -{ - while (ldi!=NULL) - { - linkedlist_datablock_internal* ldinext = ldi->next_datablock; - TRYFREE(ldi); - ldi = ldinext; - } -} - -local void init_linkedlist(ll) - linkedlist_data* ll; -{ - ll->first_block = ll->last_block = NULL; -} - -local void free_linkedlist(ll) - linkedlist_data* ll; -{ - free_datablock(ll->first_block); - ll->first_block = ll->last_block = NULL; -} - - -local int add_data_in_datablock(ll,buf,len) - linkedlist_data* ll; - const void* buf; - uLong len; -{ - linkedlist_datablock_internal* ldi; - const unsigned char* from_copy; - - if (ll==NULL) - return ZIP_INTERNALERROR; - - 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; - - while (len>0) - { - uInt copy_this; - uInt i; - unsigned char* to_copy; - - 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 ; - ll->last_block = ldi; - } - - if (ldi->avail_in_this_block < len) - copy_this = (uInt)ldi->avail_in_this_block; - else - copy_this = (uInt)len; - - to_copy = &(ldi->data[ldi->filled_in_this_block]); - - for (i=0;ifilled_in_this_block += copy_this; - ldi->avail_in_this_block -= copy_this; - from_copy += copy_this ; - len -= copy_this; - } - return ZIP_OK; -} - - - -/****************************************************************************/ - -#ifndef NO_ADDFILEINEXISTINGZIP -/* =========================================================================== - Inputs a long in LSB order to the given file - nbByte == 1, 2 or 4 (byte, short or long) -*/ - -local int ziplocal_putValue OF((const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, uLong x, int nbByte)); -local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - uLong x; - int nbByte; -{ - unsigned char buf[4]; - int 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++) - { - buf[n] = 0xff; - } - } - - if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) - return ZIP_ERRNO; - else - return ZIP_OK; -} - -local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte)); -local void ziplocal_putValue_inmemory (dest, x, nbByte) - void* dest; - uLong x; - int nbByte; -{ - 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) - { /* data overflow - hack for ZIP64 */ - for (n = 0; n < nbByte; n++) - { - buf[n] = 0xff; - } - } -} - -/****************************************************************************/ - - -local uLong ziplocal_TmzDateToDosDate(ptm,dosDate) - const tm_zip* ptm; - uLong dosDate; -{ - uLong year = (uLong)ptm->tm_year; - if (year>1980) - year-=1980; - else if (year>80) - year-=80; - 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)); -} - - -/****************************************************************************/ - -local int ziplocal_getByte OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - int *pi)); - -local int ziplocal_getByte(pzlib_filefunc_def,filestream,pi) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - int *pi; -{ - unsigned char c; - int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) - { - *pi = (int)c; - return ZIP_OK; - } - else - { - if (ZERROR(*pzlib_filefunc_def,filestream)) - return ZIP_ERRNO; - else - return ZIP_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int ziplocal_getShort OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int ziplocal_getShort (pzlib_filefunc_def,filestream,pX) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==ZIP_OK) - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<8; - - if (err==ZIP_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int ziplocal_getLong OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int ziplocal_getLong (pzlib_filefunc_def,filestream,pX) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; - uLong *pX; -{ - uLong x ; - int i; - int err; - - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==ZIP_OK) - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<8; - - if (err==ZIP_OK) - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<16; - - if (err==ZIP_OK) - err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==ZIP_OK) - *pX = x; - else - *pX = 0; - return err; -} - -#ifndef BUFREADCOMMENT -#define BUFREADCOMMENT (0x400) -#endif -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local uLong ziplocal_SearchCentralDir OF(( - const zlib_filefunc_def* pzlib_filefunc_def, - voidpf filestream)); - -local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream) - const zlib_filefunc_def* pzlib_filefunc_def; - voidpf filestream; -{ - unsigned char* buf; - uLong uSizeFile; - uLong uBackRead; - uLong uMaxBack=0xffff; /* maximum size of global comment */ - uLong uPosFound=0; - - if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); - if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} -#endif /* !NO_ADDFILEINEXISTINGZIP*/ - -/************************************************************/ -extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc_def) - const char *pathname; - int append; - zipcharpc* globalcomment; - zlib_filefunc_def* pzlib_filefunc_def; -{ - zip_internal ziinit; - zip_internal* zi; - int err=ZIP_OK; - - - if (pzlib_filefunc_def==NULL) - fill_fopen_filefunc(&ziinit.z_filefunc); - else - ziinit.z_filefunc = *pzlib_filefunc_def; - - ziinit.filestream = (*(ziinit.z_filefunc.zopen_file)) - (ziinit.z_filefunc.opaque, - pathname, - (append == APPEND_STATUS_CREATE) ? - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); - - if (ziinit.filestream == NULL) - return NULL; - ziinit.begin_pos = ZTELL(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 = (zip_internal*)ALLOC(sizeof(zip_internal)); - if (zi==NULL) - { - ZCLOSE(ziinit.z_filefunc,ziinit.filestream); - return NULL; - } - - /* now we add file in a zipfile */ -# ifndef NO_ADDFILEINEXISTINGZIP - ziinit.globalcomment = NULL; - if (append == APPEND_STATUS_ADDINZIP) - { - uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - - uLong size_central_dir; /* size of the central directory */ - uLong offset_central_dir; /* offset of start of central directory */ - uLong central_pos,uL; - - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ - uLong number_entry; - uLong number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - uLong size_comment; - - central_pos = ziplocal_SearchCentralDir(&ziinit.z_filefunc,ziinit.filestream); - if (central_pos==0) - err=ZIP_ERRNO; - - if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=ZIP_ERRNO; - - /* the signature, already checked */ - if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&uL)!=ZIP_OK) - err=ZIP_ERRNO; - - /* number of this disk */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk)!=ZIP_OK) - err=ZIP_ERRNO; - - /* number of the disk with the start of the central directory */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_disk_with_CD)!=ZIP_OK) - err=ZIP_ERRNO; - - /* total number of entries in the central dir on this disk */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry)!=ZIP_OK) - err=ZIP_ERRNO; - - /* total number of entries in the central dir */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&number_entry_CD)!=ZIP_OK) - err=ZIP_ERRNO; - - if ((number_entry_CD!=number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=ZIP_BADZIPFILE; - - /* size of the central directory */ - if (ziplocal_getLong(&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 */ - if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK) - err=ZIP_ERRNO; - - /* zipfile global comment length */ - if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK) - err=ZIP_ERRNO; - - if ((central_pos0) - { - ziinit.globalcomment = ALLOC(size_comment+1); - if (ziinit.globalcomment) - { - size_comment = ZREAD(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); - ziinit.add_position_when_writting_offset = byte_before_the_zipfile; - - { - uLong size_central_dir_to_read = size_central_dir; - size_t buf_size = SIZEDATA_INDATABLOCK; - void* buf_read = (void*)ALLOC(buf_size); - if (ZSEEK(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)) - { - uLong read_this = SIZEDATA_INDATABLOCK; - if (read_this > size_central_dir_to_read) - read_this = size_central_dir_to_read; - if (ZREAD(ziinit.z_filefunc, ziinit.filestream,buf_read,read_this) != read_this) - err=ZIP_ERRNO; - - if (err==ZIP_OK) - err = add_data_in_datablock(&ziinit.central_dir,buf_read, - (uLong)read_this); - size_central_dir_to_read-=read_this; - } - TRYFREE(buf_read); - } - ziinit.begin_pos = byte_before_the_zipfile; - ziinit.number_entry = number_entry_CD; - - if (ZSEEK(ziinit.z_filefunc, ziinit.filestream, - offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=ZIP_ERRNO; - } - - if (globalcomment) - { - *globalcomment = ziinit.globalcomment; - } -# endif /* !NO_ADDFILEINEXISTINGZIP*/ - - if (err != ZIP_OK) - { -# ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(ziinit.globalcomment); -# endif /* !NO_ADDFILEINEXISTINGZIP*/ - TRYFREE(zi); - return NULL; - } - else - { - *zi = ziinit; - return (zipFile)zi; - } -} - -extern zipFile ZEXPORT zipOpen (pathname, append) - const char *pathname; - int append; -{ - return zipOpen2(pathname,append,NULL,NULL); -} - -extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - windowBits, memLevel, strategy, - password, crcForCrypting) - 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; -{ - zip_internal* zi; - uInt size_filename; - uInt size_comment; - uInt i; - int err = ZIP_OK; - -# ifdef NOCRYPT - if (password != NULL) - return ZIP_PARAMERROR; -# endif - - if (file == NULL) - return ZIP_PARAMERROR; - if ((method!=0) && (method!=Z_DEFLATED)) - return ZIP_PARAMERROR; - - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - if (err != ZIP_OK) - return err; - } - - - if (filename==NULL) - filename="-"; - - if (comment==NULL) - size_comment = 0; - else - size_comment = (uInt)strlen(comment); - - size_filename = (uInt)strlen(filename); - - if (zipfi == NULL) - zi->ci.dosDate = 0; - else - { - if (zipfi->dosDate != 0) - zi->ci.dosDate = zipfi->dosDate; - else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate); - } - - zi->ci.flag = 0; - if ((level==8) || (level==9)) - zi->ci.flag |= 2; - if ((level==2)) - zi->ci.flag |= 4; - if ((level==1)) - zi->ci.flag |= 6; - if (password != NULL) - zi->ci.flag |= 1; - - zi->ci.crc32 = 0; - zi->ci.method = method; - zi->ci.encrypt = 0; - zi->ci.stream_initialised = 0; - zi->ci.pos_in_buffered_data = 0; - zi->ci.raw = raw; - zi->ci.pos_local_header = ZTELL(zi->z_filefunc,zi->filestream) ; - zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + - size_extrafield_global + size_comment; - zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader); - - ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); - /* version info */ - ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2); - ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); - ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); - ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); - ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); - ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ - ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ - ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ - ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); - ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); - ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); - ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ - - if (zipfi==NULL) - ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); - else - ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); - - if (zipfi==NULL) - ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); - else - ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); - - ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header- zi->add_position_when_writting_offset,4); - - for (i=0;ici.central_header+SIZECENTRALHEADER+i) = *(filename+i); - - for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+i) = - *(((const char*)extrafield_global)+i); - - for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+ - size_extrafield_global+i) = *(comment+i); - if (zi->ci.central_header == NULL) - return ZIP_INTERNALERROR; - - /* write the local header */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC,4); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield_local,2); - - if ((err==ZIP_OK) && (size_filename>0)) - if (ZWRITE(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) - err = ZIP_ERRNO; - - if ((err==ZIP_OK) && (size_extrafield_local>0)) - if (ZWRITE(zi->z_filefunc,zi->filestream,extrafield_local,size_extrafield_local) - !=size_extrafield_local) - err = ZIP_ERRNO; - - zi->ci.stream.avail_in = (uInt)0; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - zi->ci.stream.total_in = 0; - zi->ci.stream.total_out = 0; - - if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - zi->ci.stream.zalloc = (alloc_func)0; - zi->ci.stream.zfree = (free_func)0; - zi->ci.stream.opaque = (voidpf)0; - - if (windowBits>0) - windowBits = -windowBits; - - err = deflateInit2(&zi->ci.stream, level, - Z_DEFLATED, windowBits, memLevel, strategy); - - if (err==Z_OK) - zi->ci.stream_initialised = 1; - } -# ifndef NOCRYPT - zi->ci.crypt_header_size = 0; - if ((err==Z_OK) && (password != NULL)) - { - unsigned char bufHead[RAND_HEAD_LEN]; - unsigned int sizeHead; - zi->ci.encrypt = 1; - zi->ci.pcrc_32_tab = get_crc_table(); - /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ - - sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); - zi->ci.crypt_header_size = sizeHead; - - if (ZWRITE(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) - err = ZIP_ERRNO; - } -# endif - - if (err==Z_OK) - zi->in_opened_file_inzip = 1; - return err; -} - -extern int ZEXPORT zipOpenNewFileInZip2(file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw) - 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 zipOpenNewFileInZip3 (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); -} - -extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level) - 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 zipOpenNewFileInZip2 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, 0); -} - -local int zipFlushWriteBuffer(zi) - zip_internal* zi; -{ - int err=ZIP_OK; - - if (zi->ci.encrypt != 0) - { -#ifndef NOCRYPT - uInt i; - int t; - for (i=0;ici.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 - } - if (ZWRITE(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) - !=zi->ci.pos_in_buffered_data) - err = ZIP_ERRNO; - zi->ci.pos_in_buffered_data = 0; - return err; -} - -extern int ZEXPORT zipWriteInFileInZip (file, buf, len) - zipFile file; - const void* buf; - unsigned len; -{ - zip_internal* zi; - int err=ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - - zi->ci.stream.next_in = (void*)buf; - zi->ci.stream.avail_in = len; - zi->ci.crc32 = crc32(zi->ci.crc32,buf,len); - - while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) - { - if (zi->ci.stream.avail_out == 0) - { - if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) - err = ZIP_ERRNO; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - - - if(err != ZIP_OK) - break; - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - uLong uTotalOutBefore = 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 - uTotalOutBefore) ; - - } - 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;ici.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; - zi->ci.stream.next_in+= copy_this; - zi->ci.stream.next_out+= copy_this; - zi->ci.stream.total_in+= copy_this; - zi->ci.stream.total_out+= copy_this; - zi->ci.pos_in_buffered_data += copy_this; - } - } - } - - return err; -} - -extern int ZEXPORT zipCloseFileInZipRaw (file, uncompressed_size, crc32) - zipFile file; - uLong uncompressed_size; - uLong crc32; -{ - zip_internal* zi; - uLong compressed_size; - int err=ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - zi->ci.stream.avail_in = 0; - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - while (err==ZIP_OK) - { - uLong uTotalOutBefore; - if (zi->ci.stream.avail_out == 0) - { - if (zipFlushWriteBuffer(zi) == ZIP_ERRNO) - err = ZIP_ERRNO; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - uTotalOutBefore = zi->ci.stream.total_out; - err=deflate(&zi->ci.stream, Z_FINISH); - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; - } - - if (err==Z_STREAM_END) - err=ZIP_OK; /* this is normal */ - - if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) - if (zipFlushWriteBuffer(zi)==ZIP_ERRNO) - err = ZIP_ERRNO; - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - err=deflateEnd(&zi->ci.stream); - zi->ci.stream_initialised = 0; - } - - if (!zi->ci.raw) - { - crc32 = (uLong)zi->ci.crc32; - uncompressed_size = (uLong)zi->ci.stream.total_in; - } - compressed_size = (uLong)zi->ci.stream.total_out; -# ifndef NOCRYPT - compressed_size += zi->ci.crypt_header_size; -# endif - - ziplocal_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ - ziplocal_putValue_inmemory(zi->ci.central_header+20, - compressed_size,4); /*compr size*/ - if (zi->ci.stream.data_type == Z_ASCII) - ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); - ziplocal_putValue_inmemory(zi->ci.central_header+24, - uncompressed_size,4); /*uncompr size*/ - - if (err==ZIP_OK) - err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header, - (uLong)zi->ci.size_centralheader); - free(zi->ci.central_header); - - if (err==ZIP_OK) - { - long cur_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream); - if (ZSEEK(zi->z_filefunc,zi->filestream, - zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) - err = ZIP_ERRNO; - - if (err==ZIP_OK) - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ - - if (err==ZIP_OK) /* compressed size, unknown */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); - - if (err==ZIP_OK) /* uncompressed size, unknown */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); - - if (ZSEEK(zi->z_filefunc,zi->filestream, - cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) - err = ZIP_ERRNO; - } - - zi->number_entry ++; - zi->in_opened_file_inzip = 0; - - return err; -} - -extern int ZEXPORT zipCloseFileInZip (file) - zipFile file; -{ - return zipCloseFileInZipRaw (file,0,0); -} - -extern int ZEXPORT zipClose (file, global_comment) - zipFile file; - const char* global_comment; -{ - zip_internal* zi; - int err = 0; - uLong size_centraldir = 0; - uLong centraldir_pos_inzip; - uInt size_global_comment; - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - } - -#ifndef NO_ADDFILEINEXISTINGZIP - if (global_comment==NULL) - global_comment = zi->globalcomment; -#endif - if (global_comment==NULL) - size_global_comment = 0; - else - size_global_comment = (uInt)strlen(global_comment); - - centraldir_pos_inzip = ZTELL(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 (ZWRITE(zi->z_filefunc,zi->filestream, - ldi->data,ldi->filled_in_this_block) - !=ldi->filled_in_this_block ) - err = ZIP_ERRNO; - - size_centraldir += ldi->filled_in_this_block; - ldi = ldi->next_datablock; - } - } - free_datablock(zi->central_dir.first_block); - - if (err==ZIP_OK) /* Magic End */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); - - if (err==ZIP_OK) /* number of this disk */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); - - if (err==ZIP_OK) /* number of the disk with the start of the central directory */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); - - if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); - - if (err==ZIP_OK) /* total number of entries in the central dir */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); - - if (err==ZIP_OK) /* size of the central directory */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); - - if (err==ZIP_OK) /* offset of start of central directory with respect to the - starting disk number */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream, - (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); - - if (err==ZIP_OK) /* zipfile comment length */ - err = ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); - - if ((err==ZIP_OK) && (size_global_comment>0)) - if (ZWRITE(zi->z_filefunc,zi->filestream, - global_comment,size_global_comment) != size_global_comment) - err = ZIP_ERRNO; - - if (ZCLOSE(zi->z_filefunc,zi->filestream) != 0) - if (err == ZIP_OK) - err = ZIP_ERRNO; - -#ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(zi->globalcomment); -#endif - TRYFREE(zi); - - return err; -} +/* zip.c -- IO on .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + Changes + Oct-2009 - Mathias Svensson - Remove old C style function prototypes + Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives + Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. + Oct-2009 - Mathias Svensson - 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 automatically added to items that needs it, and existing ZIP64 data need to be removed. + Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) + Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer + +*/ + + +#include +#include +#include +#include +#include "zlib.h" +#include "zip.h" + +#ifdef STDC +# include +# include +# include +#endif +#ifdef NO_ERRNO_H + extern int errno; +#else +# include +#endif + + +#ifndef local +# define local static +#endif +/* compile with -Dlocal if your debugger can't find static symbols */ + +#ifndef VERSIONMADEBY +# define VERSIONMADEBY (0x0) /* platform depedent */ +#endif + +#ifndef Z_BUFSIZE +#define Z_BUFSIZE (64*1024) //(16384) +#endif + +#ifndef Z_MAXFILENAMEINZIP +#define Z_MAXFILENAMEINZIP (256) +#endif + +#ifndef ALLOC +# define ALLOC(size) (malloc(size)) +#endif +#ifndef TRYFREE +# define TRYFREE(p) {if (p) free(p);} +#endif + +/* +#define SIZECENTRALDIRITEM (0x2e) +#define SIZEZIPLOCALHEADER (0x1e) +*/ + +/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ + + +// NOT sure that this work on ALL platform +#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32)) + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef DEF_MEM_LEVEL +#if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +#else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +#endif +#endif +const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; + + +#define SIZEDATA_INDATABLOCK (4096-(4*4)) + +#define LOCALHEADERMAGIC (0x04034b50) +#define CENTRALHEADERMAGIC (0x02014b50) +#define ENDHEADERMAGIC (0x06054b50) +#define ZIP64ENDHEADERMAGIC (0x6064b50) +#define ZIP64ENDLOCHEADERMAGIC (0x7064b50) + +#define FLAG_LOCALHEADER_OFFSET (0x06) +#define CRC_LOCALHEADER_OFFSET (0x0e) + +#define SIZECENTRALHEADER (0x2e) /* 46 */ + +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; +} linkedlist_data; + + +typedef struct +{ + z_stream stream; /* zLib stream structure for inflate */ +#ifdef HAVE_BZIP2 + bz_stream bstream; /* bzLib stream structure for bziped */ +#endif + + int stream_initialised; /* 1 is stream is initialised */ + uInt pos_in_buffered_data; /* last written byte in buffered_data */ + + ZPOS64_T pos_local_header; /* offset of the local header of the file + currenty writing */ + 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 centralheader but that are not used */ + uLong flag; /* flag of the file currently writing */ + + int method; /* compression method of file currenty wr.*/ + int raw; /* 1 for directly writing raw data */ + Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ + uLong dosDate; + uLong crc32; + int encrypt; + int zip64; /* Add ZIP64 extened information in the extra field */ + ZPOS64_T pos_zip64extrainfo; + ZPOS64_T totalCompressedData; + ZPOS64_T totalUncompressedData; +#ifndef NOCRYPT + unsigned long keys[3]; /* keys defining the pseudo-random sequence */ + const z_crc_t* pcrc_32_tab; + int crypt_header_size; +#endif +} curfile64_info; + +typedef struct +{ + zlib_filefunc64_32_def z_filefunc; + voidpf filestream; /* io structore of the zipfile */ + linkedlist_data central_dir;/* datablock with central dir in construction*/ + int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ + curfile64_info ci; /* info on the file curretly writing */ + + ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ + ZPOS64_T add_position_when_writing_offset; + ZPOS64_T number_entry; + +#ifndef NO_ADDFILEINEXISTINGZIP + char *globalcomment; +#endif + +} zip64_internal; + + +#ifndef NOCRYPT +#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED +#include "crypt.h" +#endif + +local linkedlist_datablock_internal* allocate_new_datablock() +{ + linkedlist_datablock_internal* ldi; + ldi = (linkedlist_datablock_internal*) + ALLOC(sizeof(linkedlist_datablock_internal)); + if (ldi!=NULL) + { + ldi->next_datablock = NULL ; + ldi->filled_in_this_block = 0 ; + ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; + } + return ldi; +} + +local void free_datablock(linkedlist_datablock_internal* ldi) +{ + while (ldi!=NULL) + { + linkedlist_datablock_internal* ldinext = ldi->next_datablock; + TRYFREE(ldi); + ldi = ldinext; + } +} + +local void init_linkedlist(linkedlist_data* ll) +{ + ll->first_block = ll->last_block = NULL; +} + +local void free_linkedlist(linkedlist_data* ll) +{ + free_datablock(ll->first_block); + ll->first_block = ll->last_block = NULL; +} + + +local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) +{ + linkedlist_datablock_internal* ldi; + const unsigned char* from_copy; + + if (ll==NULL) + return ZIP_INTERNALERROR; + + 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; + + while (len>0) + { + uInt copy_this; + uInt i; + unsigned char* to_copy; + + 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 ; + ll->last_block = ldi; + } + + if (ldi->avail_in_this_block < len) + copy_this = (uInt)ldi->avail_in_this_block; + else + copy_this = (uInt)len; + + to_copy = &(ldi->data[ldi->filled_in_this_block]); + + for (i=0;ifilled_in_this_block += copy_this; + ldi->avail_in_this_block -= copy_this; + from_copy += copy_this ; + len -= copy_this; + } + return ZIP_OK; +} + + + +/****************************************************************************/ + +#ifndef NO_ADDFILEINEXISTINGZIP +/* =========================================================================== + 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, ZPOS64_T x, int nbByte)); +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++) + { + buf[n] = (unsigned char)(x & 0xff); + x >>= 8; + } + 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) + return ZIP_ERRNO; + else + 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) +{ + 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) + { /* data overflow - hack for ZIP64 */ + for (n = 0; n < nbByte; n++) + { + buf[n] = 0xff; + } + } +} + +/****************************************************************************/ + + +local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) +{ + uLong year = (uLong)ptm->tm_year; + if (year>=1980) + year-=1980; + else if (year>=80) + year-=80; + 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)); +} + + +/****************************************************************************/ + +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) + { + *pi = (int)c; + return ZIP_OK; + } + else + { + if (ZERROR64(*pzlib_filefunc_def,filestream)) + return ZIP_ERRNO; + else + return ZIP_EOF; + } +} + + +/* =========================================================================== + Reads a long in LSB order from the given gz_stream. Sets +*/ +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; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + 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) +{ + uLong x ; + int i = 0; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (uLong)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<8; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<16; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((uLong)i)<<24; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + 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) +{ + ZPOS64_T x; + int i = 0; + int err; + + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x = (ZPOS64_T)i; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<8; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<16; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<24; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<32; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<40; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<48; + + if (err==ZIP_OK) + err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); + x += ((ZPOS64_T)i)<<56; + + if (err==ZIP_OK) + *pX = x; + else + *pX = 0; + + return err; +} + +#ifndef BUFREADCOMMENT +#define BUFREADCOMMENT (0x400) +#endif +/* + 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) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && + ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) + { + uPosFound = uReadPos+i; + break; + } + + if (uPosFound!=0) + break; + } + TRYFREE(buf); + return uPosFound; +} + +/* +Locate the End of Zip64 Central directory locator and from there find the CD 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(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) +{ + unsigned char* buf; + ZPOS64_T uSizeFile; + ZPOS64_T uBackRead; + ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ + ZPOS64_T uPosFound=0; + uLong uL; + ZPOS64_T relativeOffset; + + if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) + return 0; + + uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); + + if (uMaxBack>uSizeFile) + uMaxBack = uSizeFile; + + buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); + if (buf==NULL) + return 0; + + uBackRead = 4; + while (uBackReaduMaxBack) + uBackRead = uMaxBack; + else + uBackRead+=BUFREADCOMMENT; + uReadPos = uSizeFile-uBackRead ; + + uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? + (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); + if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) + break; + + if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) + break; + + for (i=(int)uReadSize-3; (i--)>0;) + { + // Signature "0x07064b50" Zip64 end of central directory locater + if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) + { + uPosFound = uReadPos+i; + break; + } + } + + if (uPosFound!=0) + break; + } + + TRYFREE(buf); + if (uPosFound == 0) + return 0; + + /* Zip64 end of central directory locator */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature, already checked */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + + /* 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; + if (uL != 0) + return 0; + + /* relative offset of the zip64 end of central directory record */ + if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK) + return 0; + + /* total number of disks */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + if (uL != 1) + return 0; + + /* Goto Zip64 end of central directory record */ + if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) + return 0; + + /* the signature */ + if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) + return 0; + + if (uL != 0x06064b50) // signature of 'Zip64 end of central directory' + return 0; + + return relativeOffset; +} + +int LoadCentralDirectoryRecord(zip64_internal* pziinit) +{ + int err=ZIP_OK; + ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ + + ZPOS64_T size_central_dir; /* size of the central directory */ + ZPOS64_T offset_central_dir; /* offset of start of central directory */ + ZPOS64_T central_pos; + uLong uL; + + uLong number_disk; /* number of the current dist, used for + spaning ZIP, unsupported, always 0*/ + uLong number_disk_with_CD; /* number the the disk with central dir, used + for spaning ZIP, unsupported, always 0*/ + ZPOS64_T number_entry; + ZPOS64_T number_entry_CD; /* total number of entries in + the central dir + (same than number_entry on nospan) */ + uLong VersionMadeBy; + uLong VersionNeeded; + uLong size_comment; + + int hasZIP64Record = 0; + + // check first if we find a ZIP64 record + central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream); + if(central_pos > 0) + { + hasZIP64Record = 1; + } + else if(central_pos == 0) + { + central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream); + } + +/* disable to allow appending to empty ZIP archive + if (central_pos==0) + err=ZIP_ERRNO; +*/ + + if(hasZIP64Record) + { + ZPOS64_T sizeEndOfCentralDirectory; + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + /* the signature, already checked */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) + err=ZIP_ERRNO; + + /* size of zip64 end of central directory record */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK) + err=ZIP_ERRNO; + + /* version made by */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK) + err=ZIP_ERRNO; + + /* version needed to extract */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of this disk */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of the disk with the start of the central directory */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central directory on this disk */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central directory */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) + err=ZIP_BADZIPFILE; + + /* size of the central directory */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK) + err=ZIP_ERRNO; + + /* offset of start of central directory with respect to the + starting disk number */ + if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK) + err=ZIP_ERRNO; + + // TODO.. + // read the comment from the standard central header. + size_comment = 0; + } + else + { + // Read End of central Directory info + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) + err=ZIP_ERRNO; + + /* the signature, already checked */ + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of this disk */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) + err=ZIP_ERRNO; + + /* number of the disk with the start of the central directory */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) + err=ZIP_ERRNO; + + /* total number of entries in the central dir on this disk */ + number_entry = 0; + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + number_entry = uL; + + /* total number of entries in the central dir */ + number_entry_CD = 0; + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + number_entry_CD = uL; + + if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) + err=ZIP_BADZIPFILE; + + /* size of the central directory */ + size_central_dir = 0; + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->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_central_dir = 0; + if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) + err=ZIP_ERRNO; + else + offset_central_dir = uL; + + + /* zipfile global comment length */ + if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK) + err=ZIP_ERRNO; + } + + if ((central_posz_filefunc, pziinit->filestream); + return ZIP_ERRNO; + } + + if (size_comment>0) + { + pziinit->globalcomment = (char*)ALLOC(size_comment+1); + if (pziinit->globalcomment) + { + size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment); + pziinit->globalcomment[size_comment]=0; + } + } + + byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); + pziinit->add_position_when_writing_offset = byte_before_the_zipfile; + + { + ZPOS64_T size_central_dir_to_read = size_central_dir; + size_t buf_size = SIZEDATA_INDATABLOCK; + void* buf_read = (void*)ALLOC(buf_size); + if (ZSEEK64(pziinit->z_filefunc, pziinit->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)) + { + ZPOS64_T read_this = SIZEDATA_INDATABLOCK; + if (read_this > size_central_dir_to_read) + read_this = size_central_dir_to_read; + + if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this) + err=ZIP_ERRNO; + + if (err==ZIP_OK) + err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this); + + size_central_dir_to_read-=read_this; + } + TRYFREE(buf_read); + } + pziinit->begin_pos = byte_before_the_zipfile; + pziinit->number_entry = number_entry_CD; + + if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0) + err=ZIP_ERRNO; + + return err; +} + + +#endif /* !NO_ADDFILEINEXISTINGZIP*/ + + +/************************************************************/ +extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) +{ + zip64_internal ziinit; + zip64_internal* zi; + int err=ZIP_OK; + + ziinit.z_filefunc.zseek32_file = NULL; + ziinit.z_filefunc.ztell32_file = NULL; + if (pzlib_filefunc64_32_def==NULL) + fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); + else + ziinit.z_filefunc = *pzlib_filefunc64_32_def; + + ziinit.filestream = ZOPEN64(ziinit.z_filefunc, + pathname, + (append == APPEND_STATUS_CREATE) ? + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : + (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); + + if (ziinit.filestream == NULL) + return NULL; + + if (append == APPEND_STATUS_CREATEAFTER) + ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END); + + 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_writing_offset = 0; + init_linkedlist(&(ziinit.central_dir)); + + + + zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); + if (zi==NULL) + { + ZCLOSE64(ziinit.z_filefunc,ziinit.filestream); + return NULL; + } + + /* now we add file in a zipfile */ +# ifndef NO_ADDFILEINEXISTINGZIP + ziinit.globalcomment = NULL; + if (append == APPEND_STATUS_ADDINZIP) + { + // Read and Cache Central Directory Records + err = LoadCentralDirectoryRecord(&ziinit); + } + + if (globalcomment) + { + *globalcomment = ziinit.globalcomment; + } +# endif /* !NO_ADDFILEINEXISTINGZIP*/ + + if (err != ZIP_OK) + { +# ifndef NO_ADDFILEINEXISTINGZIP + TRYFREE(ziinit.globalcomment); +# endif /* !NO_ADDFILEINEXISTINGZIP*/ + TRYFREE(zi); + return NULL; + } + else + { + *zi = ziinit; + return (zipFile)zi; + } +} + +extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) +{ + 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 zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); + } + else + return zipOpen3(pathname, append, globalcomment, NULL); +} + +extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) +{ + 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; + zlib_filefunc64_32_def_fill.zseek32_file = NULL; + return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); + } + else + return zipOpen3(pathname, append, globalcomment, NULL); +} + + + +extern zipFile ZEXPORT zipOpen (const char* pathname, int append) +{ + return zipOpen3((const void*)pathname,append,NULL,NULL); +} + +extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append) +{ + return zipOpen3(pathname,append,NULL,NULL); +} + +int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) +{ + /* write the local header */ + int err; + uInt size_filename = (uInt)strlen(filename); + uInt size_extrafield = size_extrafield_local; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4); + + if (err==ZIP_OK) + { + if(zi->ci.zip64) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */ + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); + + // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ + 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(zi->ci.zip64) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */ + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); + + if(zi->ci.zip64) + { + size_extrafield += 20; + } + + if (err==ZIP_OK) + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2); + + 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 (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local) + err = ZIP_ERRNO; + } + + + if ((err==ZIP_OK) && (zi->ci.zip64)) + { + // write the Zip64 extended info + short HeaderID = 1; + short DataSize = 16; + ZPOS64_T CompressedSize = 0; + ZPOS64_T UncompressedSize = 0; + + // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) + zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream); + + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2); + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2); + + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8); + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8); + } + + return err; +} + +/* + NOTE. + When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped + before calling this function it can be done with zipRemoveExtraInfoBlock + + It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize + unnecessary allocations. + */ +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; + uInt size_filename; + uInt size_comment; + uInt i; + int err = ZIP_OK; + +# ifdef NOCRYPT + (crcForCrypting); + if (password != NULL) + return ZIP_PARAMERROR; +# endif + + if (file == NULL) + return ZIP_PARAMERROR; + +#ifdef HAVE_BZIP2 + if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED)) + return ZIP_PARAMERROR; +#else + if ((method!=0) && (method!=Z_DEFLATED)) + return ZIP_PARAMERROR; +#endif + + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 1) + { + err = zipCloseFileInZip (file); + if (err != ZIP_OK) + return err; + } + + if (filename==NULL) + filename="-"; + + if (comment==NULL) + size_comment = 0; + else + size_comment = (uInt)strlen(comment); + + size_filename = (uInt)strlen(filename); + + if (zipfi == NULL) + zi->ci.dosDate = 0; + else + { + if (zipfi->dosDate != 0) + zi->ci.dosDate = zipfi->dosDate; + else + zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date); + } + + zi->ci.flag = flagBase; + if ((level==8) || (level==9)) + zi->ci.flag |= 2; + if (level==2) + zi->ci.flag |= 4; + if (level==1) + zi->ci.flag |= 6; + if (password != NULL) + zi->ci.flag |= 1; + + zi->ci.crc32 = 0; + zi->ci.method = method; + zi->ci.encrypt = 0; + zi->ci.stream_initialised = 0; + zi->ci.pos_in_buffered_data = 0; + zi->ci.raw = raw; + zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream); + + zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment; + zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data + + zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree); + + zi->ci.size_centralExtra = size_extrafield_global; + zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); + /* version info */ + 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)0,2); /*disk nm start*/ + + if (zipfi==NULL) + 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); + + if (zipfi==NULL) + 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); + + if(zi->ci.pos_local_header >= 0xffffffff) + zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4); + else + zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writing_offset,4); + + for (i=0;ici.central_header+SIZECENTRALHEADER+i) = *(filename+i); + + for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+i) = + *(((const char*)extrafield_global)+i); + + for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+ + size_extrafield_global+i) = *(comment+i); + if (zi->ci.central_header == NULL) + return ZIP_INTERNALERROR; + + zi->ci.zip64 = zip64; + zi->ci.totalCompressedData = 0; + zi->ci.totalUncompressedData = 0; + zi->ci.pos_zip64extrainfo = 0; + + err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local); + +#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.total_in_hi32 = 0; + zi->ci.bstream.total_in_lo32 = 0; + zi->ci.bstream.total_out_hi32 = 0; + zi->ci.bstream.total_out_lo32 = 0; +#endif + + zi->ci.stream.avail_in = (uInt)0; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + zi->ci.stream.total_in = 0; + zi->ci.stream.total_out = 0; + zi->ci.stream.data_type = Z_BINARY; + +#ifdef HAVE_BZIP2 + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) +#else + if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) +#endif + { + if(zi->ci.method == Z_DEFLATED) + { + zi->ci.stream.zalloc = (alloc_func)0; + zi->ci.stream.zfree = (free_func)0; + zi->ci.stream.opaque = (voidpf)0; + + if (windowBits>0) + windowBits = -windowBits; + + err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy); + + if (err==Z_OK) + zi->ci.stream_initialised = Z_DEFLATED; + } + else if(zi->ci.method == Z_BZIP2ED) + { +#ifdef HAVE_BZIP2 + // Init BZip stuff here + zi->ci.bstream.bzalloc = 0; + zi->ci.bstream.bzfree = 0; + zi->ci.bstream.opaque = (voidpf)0; + + err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35); + if(err == BZ_OK) + zi->ci.stream_initialised = Z_BZIP2ED; +#endif + } + + } + +# ifndef NOCRYPT + zi->ci.crypt_header_size = 0; + if ((err==Z_OK) && (password != NULL)) + { + unsigned char bufHead[RAND_HEAD_LEN]; + unsigned int sizeHead; + zi->ci.encrypt = 1; + zi->ci.pcrc_32_tab = get_crc_table(); + /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ + + sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); + zi->ci.crypt_header_size = sizeHead; + + if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) + err = ZIP_ERRNO; + } +# endif + + if (err==Z_OK) + zi->in_opened_file_inzip = 1; + 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) +{ + 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) +{ + 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) +{ + 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) +{ + 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) +{ + 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) +{ + 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) +{ + 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, 0); +} + +local int zip64FlushWriteBuffer(zip64_internal* zi) +{ + int err=ZIP_OK; + + if (zi->ci.encrypt != 0) + { +#ifndef NOCRYPT + uInt i; + int t; + for (i=0;ici.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 + } + + if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data) + err = ZIP_ERRNO; + + zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data; + +#ifdef HAVE_BZIP2 + if(zi->ci.method == Z_BZIP2ED) + { + zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32; + zi->ci.bstream.total_in_lo32 = 0; + zi->ci.bstream.total_in_hi32 = 0; + } + else +#endif + { + zi->ci.totalUncompressedData += zi->ci.stream.total_in; + zi->ci.stream.total_in = 0; + } + + + zi->ci.pos_in_buffered_data = 0; + + return err; +} + +extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len) +{ + zip64_internal* zi; + int err=ZIP_OK; + + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 0) + return ZIP_PARAMERROR; + + zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len); + +#ifdef HAVE_BZIP2 + if(zi->ci.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) + { + 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; + } + + + if(err != BZ_RUN_OK) + break; + + if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) + { + uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32; +// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; + err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN); + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ; + } + } + + if(err == BZ_RUN_OK) + err = ZIP_OK; + } + else +#endif + { + 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) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + } + + + if(err != ZIP_OK) + break; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + uLong uTotalOutBefore = zi->ci.stream.total_out; + err=deflate(&zi->ci.stream, Z_NO_FLUSH); + if(uTotalOutBefore > zi->ci.stream.total_out) + { + int bBreak = 0; + bBreak++; + } + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; + } + 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); + { + zi->ci.stream.avail_in -= copy_this; + zi->ci.stream.avail_out-= copy_this; + zi->ci.stream.next_in+= copy_this; + zi->ci.stream.next_out+= copy_this; + zi->ci.stream.total_in+= copy_this; + zi->ci.stream.total_out+= copy_this; + zi->ci.pos_in_buffered_data += copy_this; + } + } + }// while(...) + } + + return err; +} + +extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32) +{ + return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32); +} + +extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32) +{ + zip64_internal* zi; + ZPOS64_T compressed_size; + uLong invalidValue = 0xffffffff; + short datasize = 0; + int err=ZIP_OK; + + if (file == NULL) + return ZIP_PARAMERROR; + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 0) + return ZIP_PARAMERROR; + zi->ci.stream.avail_in = 0; + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + while (err==ZIP_OK) + { + uLong uTotalOutBefore; + if (zi->ci.stream.avail_out == 0) + { + if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) + err = ZIP_ERRNO; + zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; + zi->ci.stream.next_out = zi->ci.buffered_data; + } + uTotalOutBefore = zi->ci.stream.total_out; + err=deflate(&zi->ci.stream, Z_FINISH); + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; + } + } + else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) + { +#ifdef HAVE_BZIP2 + err = BZ_FINISH_OK; + while (err==BZ_FINISH_OK) + { + uLong uTotalOutBefore; + 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; + } + uTotalOutBefore = zi->ci.bstream.total_out_lo32; + err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH); + if(err == BZ_STREAM_END) + err = Z_STREAM_END; + + zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore); + } + + if(err == BZ_FINISH_OK) + err = ZIP_OK; +#endif + } + + if (err==Z_STREAM_END) + err=ZIP_OK; /* this is normal */ + + if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) + { + if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO) + err = ZIP_ERRNO; + } + + if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) + { + 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.method == Z_BZIP2ED) && (!zi->ci.raw)) + { + int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream); + if (err==ZIP_OK) + err = tmperr; + zi->ci.stream_initialised = 0; + } +#endif + + if (!zi->ci.raw) + { + crc32 = (uLong)zi->ci.crc32; + uncompressed_size = zi->ci.totalUncompressedData; + } + compressed_size = zi->ci.totalCompressedData; + +# ifndef NOCRYPT + compressed_size += zi->ci.crypt_header_size; +# endif + + // update Current Item crc and sizes, + if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) + { + /*version Made by*/ + zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2); + /*version needed*/ + zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2); + + } + + 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*/ + else + zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/ + + /// set internal file attributes field + if (zi->ci.stream.data_type == Z_ASCII) + zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); + + if(uncompressed_size >= 0xffffffff) + 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*/ + + // Add ZIP64 extra info field for uncompressed size + if(uncompressed_size >= 0xffffffff) + datasize += 8; + + // Add ZIP64 extra info field for compressed size + if(compressed_size >= 0xffffffff) + datasize += 8; + + // Add ZIP64 extra info field for relative offset to local file header of current file + if(zi->ci.pos_local_header >= 0xffffffff) + datasize += 8; + + if(datasize > 0) + { + char* p = NULL; + + if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) + { + // we can not write more data to the buffer that we have room for. + return ZIP_BADZIPFILE; + } + + p = zi->ci.central_header + zi->ci.size_centralheader; + + // Add Extra Information Header for 'ZIP64 information' + zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID + p += 2; + zip64local_putValue_inmemory(p, datasize, 2); // DataSize + p += 2; + + if(uncompressed_size >= 0xffffffff) + { + zip64local_putValue_inmemory(p, uncompressed_size, 8); + p += 8; + } + + if(compressed_size >= 0xffffffff) + { + zip64local_putValue_inmemory(p, compressed_size, 8); + p += 8; + } + + if(zi->ci.pos_local_header >= 0xffffffff) + { + zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8); + p += 8; + } + + // Update how much extra free space we got in the memory buffer + // and increase the centralheader size so the new ZIP64 fields are included + // ( 4 below is the size of HeaderID and DataSize field ) + zi->ci.size_centralExtraFree -= datasize + 4; + zi->ci.size_centralheader += datasize + 4; + + // Update the extra info size field + zi->ci.size_centralExtra += datasize + 4; + zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2); + } + + if (err==ZIP_OK) + err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader); + + free(zi->ci.central_header); + + if (err==ZIP_OK) + { + // Update the LocalFileHeader with the new values. + + ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); + + 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 */ + + 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; + + if (err==ZIP_OK) /* compressed size, unknown */ + 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 + err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal + } + else + { + if (err==ZIP_OK) /* compressed size, unknown */ + 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); + } + + if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) + err = ZIP_ERRNO; + } + + zi->number_entry ++; + zi->in_opened_file_inzip = 0; + + return err; +} + +extern int ZEXPORT zipCloseFileInZip (zipFile file) +{ + return zipCloseFileInZipRaw (file,0,0); +} + +int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) +{ + int err = ZIP_OK; + ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writing_offset; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4); + + /*num disks*/ + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + /*relative offset*/ + if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8); + + /*total disks*/ /* Do not support spawning of disk so always say 1 here*/ + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4); + + return err; +} + +int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) +{ + int err = ZIP_OK; + + uLong Zip64DataSize = 44; + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4); + + if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ? + + if (err==ZIP_OK) /* version made by */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); + + if (err==ZIP_OK) /* version needed */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); + + if (err==ZIP_OK) /* number of this disk */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); + + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); + + if (err==ZIP_OK) /* total number of entries in the central dir */ + err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); + + if (err==ZIP_OK) /* size of the central directory */ + 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 */ + { + ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8); + } + return err; +} +int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) +{ + int err = ZIP_OK; + + /*signature*/ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); + + if (err==ZIP_OK) /* number of this disk */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); + + if (err==ZIP_OK) /* number of the disk with the start of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); + + if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ + { + { + 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); + } + } + + if (err==ZIP_OK) /* total number of entries in the central dir */ + { + 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); + } + + if (err==ZIP_OK) /* size of the central directory */ + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); + + 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_writing_offset; + if(pos >= 0xffffffff) + { + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4); + } + else + err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writing_offset),4); + } + + return err; +} + +int Write_GlobalComment(zip64_internal* zi, const char* global_comment) +{ + int err = ZIP_OK; + uInt size_global_comment = 0; + + if(global_comment != NULL) + size_global_comment = (uInt)strlen(global_comment); + + err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); + + 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; + } + return err; +} + +extern int ZEXPORT zipClose (zipFile file, const char* global_comment) +{ + zip64_internal* zi; + int err = 0; + uLong size_centraldir = 0; + ZPOS64_T centraldir_pos_inzip; + ZPOS64_T pos; + + if (file == NULL) + return ZIP_PARAMERROR; + + zi = (zip64_internal*)file; + + if (zi->in_opened_file_inzip == 1) + { + err = zipCloseFileInZip (file); + } + +#ifndef NO_ADDFILEINEXISTINGZIP + if (global_comment==NULL) + global_comment = zi->globalcomment; +#endif + + 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 (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block) + err = ZIP_ERRNO; + } + + size_centraldir += ldi->filled_in_this_block; + ldi = ldi->next_datablock; + } + } + free_linkedlist(&(zi->central_dir)); + + pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; + if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) + { + ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); + Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); + + Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos); + } + + if (err==ZIP_OK) + err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); + + if(err == ZIP_OK) + err = Write_GlobalComment(zi, global_comment); + + if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0) + if (err == ZIP_OK) + err = ZIP_ERRNO; + +#ifndef NO_ADDFILEINEXISTINGZIP + TRYFREE(zi->globalcomment); +#endif + TRYFREE(zi); + + return err; +} + +extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader) +{ + char* p = pData; + int size = 0; + char* pNewHeader; + char* pTmp; + short header; + short dataSize; + + int retVal = ZIP_OK; + + if(pData == NULL || *dataLen < 4) + return ZIP_PARAMERROR; + + pNewHeader = (char*)ALLOC(*dataLen); + pTmp = pNewHeader; + + while(p < (pData + *dataLen)) + { + header = *(short*)p; + dataSize = *(((short*)p)+1); + + if( header == sHeader ) // Header found. + { + p += dataSize + 4; // skip it. do not copy to temp buffer + } + else + { + // Extra Info block should not be removed, So copy it to the temp buffer. + memcpy(pTmp, p, dataSize + 4); + p += dataSize + 4; + size += dataSize + 4; + } + + } + + if(size < *dataLen) + { + // clean old extra info block. + memset(pData,0, *dataLen); + + // copy the new extra info block over the old + if(size > 0) + memcpy(pData, pNewHeader, size); + + // set the new extra info size + *dataLen = size; + + retVal = ZIP_OK; + } + else + retVal = ZIP_ERRNO; + + TRYFREE(pNewHeader); + + return retVal; +} diff --git a/Dependencies/minizip/zip.h b/Dependencies/minizip/zip.h index cd38b67..8aaebb6 100644 --- a/Dependencies/minizip/zip.h +++ b/Dependencies/minizip/zip.h @@ -1,235 +1,362 @@ -/* zip.h -- IO for compress .zip files using zlib - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This unzip package allow creates .ZIP file, compatible with PKZip 2.04g - WinZip, InfoZip tools and compatible. - Multi volume ZipFile (span) are not supported. - Encryption compatible with pkzip 2.04g only supported - Old compressions used by old PKZip 1.x are not supported - - For uncompress .zip file, look at unzip.h - - - I WAIT FEEDBACK at mail info@winimage.com - Visit also http://www.winimage.com/zLibDll/unzip.html for evolution - - Condition of use and distribution are the same than 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 acknowledgment 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. - - -*/ - -/* for more info about .ZIP format, see - http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip - http://www.info-zip.org/pub/infozip/doc/ - PkWare has also a specification at : - ftp://ftp.pkware.com/probdesc.zip -*/ - -#ifndef _zip_H -#define _zip_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagzipFile__ { int unused; } zipFile__; -typedef zipFile__ *zipFile; -#else -typedef voidp zipFile; -#endif - -#define ZIP_OK (0) -#define ZIP_EOF (0) -#define ZIP_ERRNO (Z_ERRNO) -#define ZIP_PARAMERROR (-102) -#define ZIP_BADZIPFILE (-103) -#define ZIP_INTERNALERROR (-104) - -#ifndef DEF_MEM_LEVEL -# if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -# else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -# endif -#endif -/* default memLevel */ - -/* tm_zip contain date/time info */ -typedef struct tm_zip_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_zip; - -typedef struct -{ - tm_zip tmz_date; /* date in understandable format */ - uLong dosDate; /* if dos_date == 0, tmu_date is used */ -/* uLong flag; */ /* general purpose bit flag 2 bytes */ - - uLong internal_fa; /* internal file attributes 2 bytes */ - 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) - -extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); -/* - Create a zipfile. - pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on - an Unix computer "zlib/zlib113.zip". - if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip - will be created at the end of the file. - (useful if the file contain a self extractor code) - if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will - add files in existing zip (be sure you don't add file that doesn't exist) - If the zipfile cannot be opened, the return value is NULL. - Else, the return value is a zipFile Handle, usable with other function - of this zip package. -*/ - -/* Note : there is no delete function into a zipfile. - If you want delete file into a zipfile, you must open a zipfile, and create another - Of couse, you can use RAW reading and writing to copy the file you did not want delte -*/ - -extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, - int append, - zipcharpc* globalcomment, - zlib_filefunc_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, - uInt size_extrafield_global, - const char* comment, - int method, - int level)); -/* - Open a file in the ZIP for writing. - filename : the filename in zip (if NULL, '-' without quote will be used - *zipfi contain supplemental information - if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local - contains the extrafield data the the local header - if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global - contains the extrafield data the the local header - if comment != NULL, comment contain the comment string - method contain the compression method (0 for store, Z_DEFLATED for deflate) - level contain the level of compression (can be Z_DEFAULT_COMPRESSION) -*/ - - -extern int ZEXPORT zipOpenNewFileInZip2 OF((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)); - -/* - Same than zipOpenNewFileInZip, except if raw=1, we write raw file - */ - -extern int ZEXPORT zipOpenNewFileInZip3 OF((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 crcForCtypting)); - -/* - Same than zipOpenNewFileInZip2, except - windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 - password : crypting password (NULL for no crypting) - crcForCtypting : crc of file to compress (needed for crypting) - */ - - -extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, - const void* buf, - unsigned len)); -/* - Write data in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); -/* - Close the current file in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, - uLong uncompressed_size, - uLong crc32)); -/* - Close the current file in the zipfile, for fiel opened with - parameter raw=1 in zipOpenNewFileInZip2 - uncompressed_size and crc32 are value for the uncompressed size -*/ - -extern int ZEXPORT zipClose OF((zipFile file, - const char* global_comment)); -/* - Close the zipfile -*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _zip_H */ +/* zip.h -- IO on .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------- + + Condition of use and distribution are the same than 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 acknowledgment 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. + + --------------------------------------------------------------------------- + + Changes + + See header of zip.h + +*/ + +#ifndef _zip12_H +#define _zip12_H + +#ifdef __cplusplus +extern "C" { +#endif + +//#define HAVE_BZIP2 + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagzipFile__ { int unused; } zipFile__; +typedef zipFile__ *zipFile; +#else +typedef voidp zipFile; +#endif + +#define ZIP_OK (0) +#define ZIP_EOF (0) +#define ZIP_ERRNO (Z_ERRNO) +#define ZIP_PARAMERROR (-102) +#define ZIP_BADZIPFILE (-103) +#define ZIP_INTERNALERROR (-104) + +#ifndef DEF_MEM_LEVEL +# if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +# else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +# endif +#endif +/* default memLevel */ + +/* tm_zip contain date/time info */ +typedef struct tm_zip_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_zip; + +typedef struct +{ + tm_zip tmz_date; /* date in understandable format */ + uLong dosDate; /* if dos_date == 0, tmu_date is used */ +/* uLong flag; */ /* general purpose bit flag 2 bytes */ + + uLong internal_fa; /* internal file attributes 2 bytes */ + 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) + +extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); +extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); +/* + Create a zipfile. + pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on + an Unix computer "zlib/zlib113.zip". + if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip + will be created at the end of the file. + (useful if the file contain a self extractor code) + if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will + add files in existing zip (be sure you don't add file that doesn't exist) + If the zipfile cannot be opened, the return value is NULL. + Else, the return value is a zipFile Handle, usable with other function + of this zip package. +*/ + +/* Note : there is no delete function into a zipfile. + If you want delete file into a zipfile, you must open a zipfile, and create another + Of couse, you can use RAW reading and writing to copy the file you did not want delte +*/ + +extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, + int append, + zipcharpc* globalcomment, + zlib_filefunc_def* pzlib_filefunc_def)); + +extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, + int append, + zipcharpc* 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, + uInt size_extrafield_global, + const char* comment, + int method, + int level)); + +extern int ZEXPORT zipOpenNewFileInZip64 OF((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)); + +/* + Open a file in the ZIP for writing. + filename : the filename in zip (if NULL, '-' without quote will be used + *zipfi contain supplemental information + if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local + contains the extrafield data the the local header + if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global + contains the extrafield data the the local header + if comment != NULL, comment contain the comment string + method contain the compression method (0 for store, Z_DEFLATED for deflate) + level contain the level of compression (can be Z_DEFAULT_COMPRESSION) + zip64 is set to 1 if a zip64 extended information block should be added to the local file header. + this MUST be '1' if the uncompressed size is >= 0xffffffff. + +*/ + + +extern int ZEXPORT zipOpenNewFileInZip2 OF((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_64 OF((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)); +/* + Same than zipOpenNewFileInZip, except if raw=1, we write raw file + */ + +extern int ZEXPORT zipOpenNewFileInZip3 OF((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_64 OF((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 + )); + +/* + Same than zipOpenNewFileInZip2, except + windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 + password : crypting password (NULL for no crypting) + crcForCrypting : crc of file to compress (needed for crypting) + */ + +extern int ZEXPORT zipOpenNewFileInZip4 OF((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_64 OF((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 + )); +/* + Same than zipOpenNewFileInZip4, except + versionMadeBy : value for Version made by field + flag : value for flag field (compression level info will be added) + */ + + +extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, + const void* buf, + unsigned len)); +/* + Write data in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); +/* + Close the current file in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, + uLong uncompressed_size, + uLong crc32)); + +extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, + ZPOS64_T uncompressed_size, + uLong crc32)); + +/* + Close the current file in the zipfile, for file opened with + parameter raw=1 in zipOpenNewFileInZip2 + uncompressed_size and crc32 are value for the uncompressed size +*/ + +extern int ZEXPORT zipClose OF((zipFile file, + const char* global_comment)); +/* + Close the zipfile +*/ + + +extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader)); +/* + zipRemoveExtraInfoBlock - Added by Mathias Svensson + + Remove extra information block from a extra information data for the local file header or central directory header + + It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode. + + 0x0001 is the signature header for the ZIP64 extra information blocks + + usage. + Remove ZIP64 Extra information from a central director extra field data + zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001); + + Remove ZIP64 Extra information from a Local File Header extra field data + zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001); +*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _zip64_H */ diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..7378243 --- /dev/null +++ b/Package.swift @@ -0,0 +1,185 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import Foundation +import PackageDescription + +let package = Package( + name: "AltSign", + platforms: [ + .iOS(.v14), + .macOS(.v11), + ], + products: [ + .library( + name: "AltSign-Dynamic", + type: .dynamic, + targets: ["AltSign", "CAltSign", "CoreCrypto", "CCoreCrypto", "ldid", "ldid-core", "OpenSSL"] + ), + .library( + name: "AltSign-Static", + targets: ["AltSign", "CAltSign", "CoreCrypto", "CCoreCrypto", "ldid", "ldid-core"] + ), + ], + dependencies: [], + targets: [ + .binaryTarget( + name: "OpenSSL", + path: "Dependencies/OpenSSL/Frameworks/OpenSSL.xcframework" + ), + + .target( + name: "ldid-core", + path: "Dependencies/ldid", + exclude: [ + "ldid.hpp", + "ldid.cpp", + "version.sh", + "COPYING", + "control.sh", + "control", + "ios.sh", + "make.sh", + "deb.sh", + "plist.sh", + "libplist/include", + "libplist/include/Makefile.am", + "libplist/fuzz", + "libplist/cython", + "libplist/m4", + "libplist/test", + "libplist/tools", + "libplist/AUTHORS", + "libplist/autogen.sh", + "libplist/configure.ac", + "libplist/COPYING", + "libplist/COPYING.LESSER", + "libplist/doxygen.cfg.in", + "libplist/Makefile.am", + "libplist/NEWS", + "libplist/README.md", + "libplist/src/Makefile.am", + "libplist/src/libplist++.pc.in", + "libplist/src/libplist.pc.in", + "libplist/libcnary/cnary.c", + "libplist/libcnary/COPYING", + "libplist/libcnary/Makefile.am", + "libplist/libcnary/README", + ], + sources: [ + "lookup2.c", + "libplist/src", + "libplist/libcnary", + ], + publicHeadersPath: "", + cSettings: [ + .headerSearchPath("libplist/include"), + .headerSearchPath("libplist/src"), + .headerSearchPath("libplist/libcnary/include"), + .headerSearchPath("../OpenSSL/ios/include"), + + .unsafeFlags(["-w"]) + ], + cxxSettings: [ + .unsafeFlags(["-w"]) + ] + ), + .target( + name: "ldid", + dependencies: ["ldid-core"], + path: "AltSign/ldid", + exclude: [ + "alt_ldid.hpp", + ], + sources: [ + "alt_ldid.cpp", + ], + publicHeadersPath: "", + cSettings: [ + .headerSearchPath("../../Dependencies/ldid"), + .headerSearchPath("../../Dependencies/ldid/libplist/include"), + .headerSearchPath("../../Dependencies/ldid/libplist/src"), + .headerSearchPath("../../Dependencies/ldid/libplist/libcnary/include"), + .headerSearchPath("../../Dependencies/OpenSSL/ios/include"), + ], + cxxSettings: [ + .unsafeFlags(["-w"]) + ] + ), + + .target( + name: "CCoreCrypto", + path: "Dependencies/corecrypto", + exclude: [ + "Sources/CoreCryptoMacros.swift" + ], + cSettings: [ + .headerSearchPath("include/corecrypto"), + .define("CORECRYPTO_DONOT_USE_TRANSPARENT_UNION=1") + ] + ), + .target( + name: "CoreCrypto", + dependencies: ["CCoreCrypto"], + path: "Dependencies/corecrypto/Sources", + exclude: [ + "ccsrp.m" + ], + sources: [ + "CoreCryptoMacros.swift" + ], + cSettings: [ + .define("CORECRYPTO_DONOT_USE_TRANSPARENT_UNION=1") + ] + ), + + .target( + name: "CAltSign", + dependencies: ["CoreCrypto", "ldid"], + path: "", + exclude: [ + "AltSign/ldid/alt_ldid.cpp", + "AltSign/ldid/alt_ldid.hpp", + "AltSign/Sources", + "AltSign/include/module.modulemap", + "Dependencies/corecrypto", + "Dependencies/ldid", + "Dependencies/OpenSSL", + "Dependencies/minizip/iowin32.c", + "Dependencies/minizip/Makefile", + "Dependencies/minizip/minizip.c", + "Dependencies/minizip/miniunz.c", + ], + publicHeadersPath: "AltSign/include", + cSettings: [ + // Recursive wildcard paths no longer work as of Xcode 16 :( + // .headerSearchPath("AltSign/**"), + .headerSearchPath("AltSign/include/AltSign"), + .headerSearchPath("Dependencies/minizip"), + .headerSearchPath("Dependencies/OpenSSL/ios/include"), + .headerSearchPath("Dependencies/ldid/libplist/include"), + .headerSearchPath("Dependencies/ldid"), + .define("unix=1"), + ], + linkerSettings: [ + .linkedFramework("UIKit", .when(platforms: [.iOS])), + .linkedFramework("Security"), + ] + ), + .target( + name: "AltSign", + dependencies: ["CAltSign"], + path: "AltSign/Sources", + cSettings: [ + .headerSearchPath("Dependencies/minizip"), + .define("CORECRYPTO_DONOT_USE_TRANSPARENT_UNION=1"), + ], + swiftSettings: [ + .define("MARKETPLACE") + ] + ) + ], + + cLanguageStandard: CLanguageStandard.gnu11, + cxxLanguageStandard: .cxx14 +)