Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2008-12-31 03:00:00 +0300
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:58 +0300
commit3a524e5ba2d7bb0c46e11502822f8093dd2ab0f4 (patch)
treeb33da9cac0a5fc22a16bdf4de106c8a9eefd1465 /CPP/7zip/Archive/Zip
parentc1f1243a70558e86e14b1ea09dc287737378894b (diff)
4.634.63
Diffstat (limited to 'CPP/7zip/Archive/Zip')
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipAddCommon.cpp17
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipAddCommon.h16
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipHandler.cpp146
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipHandlerOut.cpp19
-rwxr-xr-xCPP/7zip/Archive/Zip/ZipUpdate.cpp21
5 files changed, 112 insertions, 107 deletions
diff --git a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
index 9010a5e4..212a8b4b 100755
--- a/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
+++ b/CPP/7zip/Archive/Zip/ZipAddCommon.cpp
@@ -1,4 +1,4 @@
-// AddCommon.cpp
+// ZipAddCommon.cpp
#include "StdAfx.h"
@@ -8,14 +8,17 @@ extern "C"
}
#include "Windows/PropVariant.h"
-#include "Windows/Defs.h"
-#include "../../MyVersion.h"
+
#include "../../ICoder.h"
#include "../../IPassword.h"
+#include "../../MyVersion.h"
+
#include "../../Common/CreateCoder.h"
#include "../../Common/StreamObjects.h"
#include "../../Common/StreamUtils.h"
-#include "../../Compress/LZMA/LZMAEncoder.h"
+
+#include "../../Compress/LzmaEncoder.h"
+
#include "../Common/InStreamWithCRC.h"
#include "ZipAddCommon.h"
@@ -34,7 +37,7 @@ class CLzmaEncoder:
public ICompressCoder,
public CMyUnknownImp
{
- NCompress::NLZMA::CEncoder *EncoderSpec;
+ NCompress::NLzma::CEncoder *EncoderSpec;
CMyComPtr<ICompressCoder> Encoder;
Byte Header[kLzmaHeaderSize];
public:
@@ -49,7 +52,7 @@ HRESULT CLzmaEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIAN
{
if (!Encoder)
{
- EncoderSpec = new NCompress::NLZMA::CEncoder;
+ EncoderSpec = new NCompress::NLzma::CEncoder;
Encoder = EncoderSpec;
}
CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;
@@ -153,7 +156,7 @@ HRESULT CAddCommon::Compress(
}
if (_options.IsAesMode)
{
- _cryptoStreamSpec->Filter = _aesFilter = _filterAesSpec = new NCrypto::NWzAES::CEncoder;
+ _cryptoStreamSpec->Filter = _aesFilter = _filterAesSpec = new NCrypto::NWzAes::CEncoder;
_filterAesSpec->SetKeyMode(_options.AesKeyMode);
RINOK(_filterAesSpec->CryptoSetPassword(
(const Byte *)(const char *)_options.Password, _options.Password.Length()));
diff --git a/CPP/7zip/Archive/Zip/ZipAddCommon.h b/CPP/7zip/Archive/Zip/ZipAddCommon.h
index 6c766037..8f5b568d 100755
--- a/CPP/7zip/Archive/Zip/ZipAddCommon.h
+++ b/CPP/7zip/Archive/Zip/ZipAddCommon.h
@@ -1,16 +1,18 @@
-// Zip/AddCommon.h
+// ZipAddCommon.h
-#ifndef __ZIP_ADDCOMMON_H
-#define __ZIP_ADDCOMMON_H
+#ifndef __ZIP_ADD_COMMON_H
+#define __ZIP_ADD_COMMON_H
#include "../../ICoder.h"
#include "../../IProgress.h"
-#include "../../Compress/Copy/CopyCoder.h"
#include "../../Common/CreateCoder.h"
#include "../../Common/FilterCoder.h"
-#include "../../Crypto/Zip/ZipCipher.h"
-#include "../../Crypto/WzAES/WzAES.h"
+
+#include "../../Compress/CopyCoder.h"
+
+#include "../../Crypto/ZipCrypto.h"
+#include "../../Crypto/WzAes.h"
#include "ZipCompressionMode.h"
@@ -38,7 +40,7 @@ class CAddCommon
CMyComPtr<ISequentialOutStream> _cryptoStream;
NCrypto::NZip::CEncoder *_filterSpec;
- NCrypto::NWzAES::CEncoder *_filterAesSpec;
+ NCrypto::NWzAes::CEncoder *_filterAesSpec;
CMyComPtr<ICompressFilter> _zipCryptoFilter;
CMyComPtr<ICompressFilter> _aesFilter;
diff --git a/CPP/7zip/Archive/Zip/ZipHandler.cpp b/CPP/7zip/Archive/Zip/ZipHandler.cpp
index 40d131f0..3054ae02 100755
--- a/CPP/7zip/Archive/Zip/ZipHandler.cpp
+++ b/CPP/7zip/Archive/Zip/ZipHandler.cpp
@@ -2,40 +2,35 @@
#include "StdAfx.h"
-#include "ZipHandler.h"
-
-#include "Common/Defs.h"
-#include "Common/StringConvert.h"
#include "Common/ComTry.h"
+#include "Common/Defs.h"
#include "Common/IntToString.h"
+#include "Common/StringConvert.h"
-#include "Windows/Time.h"
#include "Windows/PropVariant.h"
+#include "Windows/Time.h"
#include "../../IPassword.h"
+#include "../../Common/CreateCoder.h"
+#include "../../Common/FilterCoder.h"
#include "../../Common/ProgressUtils.h"
#include "../../Common/StreamObjects.h"
#include "../../Common/StreamUtils.h"
-#include "../../Common/CreateCoder.h"
-#include "../../Common/FilterCoder.h"
-#include "../../Compress/Copy/CopyCoder.h"
-#include "../../Compress/LZMA/LZMADecoder.h"
+#include "../../Compress/CopyCoder.h"
+#include "../../Compress/LzmaDecoder.h"
+#include "../../Compress/ImplodeDecoder.h"
+#include "../../Compress/ShrinkDecoder.h"
+
+#include "../../Crypto/WzAes.h"
+#include "../../Crypto/ZipCrypto.h"
+#include "../../Crypto/ZipStrong.h"
#include "../Common/ItemNameUtils.h"
#include "../Common/OutStreamWithCRC.h"
-#include "../../Compress/Shrink/ShrinkDecoder.h"
-#include "../../Compress/Implode/ImplodeDecoder.h"
-
-
-#include "../../Crypto/Zip/ZipCipher.h"
-#include "../../Crypto/WzAES/WzAES.h"
-
-#ifdef ZIP_STRONG_SUPORT
-#include "../../Crypto/ZipStrong/ZipStrong.h"
-#endif
+#include "ZipHandler.h"
using namespace NWindows;
@@ -381,7 +376,7 @@ class CLzmaDecoder:
public ICompressCoder,
public CMyUnknownImp
{
- NCompress::NLZMA::CDecoder *DecoderSpec;
+ NCompress::NLzma::CDecoder *DecoderSpec;
CMyComPtr<ICompressCoder> Decoder;
public:
CLzmaDecoder();
@@ -393,7 +388,7 @@ public:
CLzmaDecoder::CLzmaDecoder()
{
- DecoderSpec = new NCompress::NLZMA::CDecoder;
+ DecoderSpec = new NCompress::NLzma::CDecoder;
Decoder = DecoderSpec;
}
@@ -417,20 +412,24 @@ struct CMethodItem
class CZipDecoder
{
NCrypto::NZip::CDecoder *_zipCryptoDecoderSpec;
- NCrypto::NWzAES::CDecoder *_aesDecoderSpec;
+ NCrypto::NZipStrong::CDecoder *_pkAesDecoderSpec;
+ NCrypto::NWzAes::CDecoder *_wzAesDecoderSpec;
+
CMyComPtr<ICompressFilter> _zipCryptoDecoder;
- CMyComPtr<ICompressFilter> _aesDecoder;
- #ifdef ZIP_STRONG_SUPORT
- NCrypto::NZipStrong::CDecoder *_zsDecoderSpec;
- CMyComPtr<ICompressFilter> _zsDecoder;
- #endif
+ CMyComPtr<ICompressFilter> _pkAesDecoder;
+ CMyComPtr<ICompressFilter> _wzAesDecoder;
+
CFilterCoder *filterStreamSpec;
CMyComPtr<ISequentialInStream> filterStream;
CMyComPtr<ICryptoGetTextPassword> getTextPassword;
CObjectVector<CMethodItem> methodItems;
public:
- CZipDecoder(): _zipCryptoDecoderSpec(0), _aesDecoderSpec(0), filterStreamSpec(0) {}
+ CZipDecoder():
+ _zipCryptoDecoderSpec(0),
+ _pkAesDecoderSpec(0),
+ _wzAesDecoderSpec(0),
+ filterStreamSpec(0) {}
HRESULT Decode(
DECL_EXTERNAL_CODECS_LOC_VARS
@@ -453,23 +452,19 @@ HRESULT CZipDecoder::Decode(
CInStreamReleaser inStreamReleaser;
bool needCRC = true;
- bool aesMode = false;
- #ifdef ZIP_STRONG_SUPORT
+ bool wzAesMode = false;
bool pkAesMode = false;
- #endif
UInt16 methodId = item.CompressionMethod;
if (item.IsEncrypted())
{
if (item.IsStrongEncrypted())
{
- #ifdef ZIP_STRONG_SUPORT
CStrongCryptoField f;
if (item.CentralExtra.GetStrongCryptoField(f))
{
pkAesMode = true;
}
if (!pkAesMode)
- #endif
{
res = NArchive::NExtract::NOperationResult::kUnSupportedMethod;
return S_OK;
@@ -480,7 +475,7 @@ HRESULT CZipDecoder::Decode(
CWzAesExtraField aesField;
if (item.CentralExtra.GetWzAesField(aesField))
{
- aesMode = true;
+ wzAesMode = true;
needCRC = aesField.NeedCrc();
}
}
@@ -496,11 +491,11 @@ HRESULT CZipDecoder::Decode(
CMyComPtr<ISequentialInStream> inStream;
{
UInt64 packSize = item.PackSize;
- if (aesMode)
+ if (wzAesMode)
{
- if (packSize < NCrypto::NWzAES::kMacSize)
+ if (packSize < NCrypto::NWzAes::kMacSize)
return S_OK;
- packSize -= NCrypto::NWzAES::kMacSize;
+ packSize -= NCrypto::NWzAes::kMacSize;
}
UInt64 dataPos = item.GetDataPosition();
inStream.Attach(archive.CreateLimitedStream(dataPos, packSize));
@@ -510,32 +505,30 @@ HRESULT CZipDecoder::Decode(
CMyComPtr<ICompressFilter> cryptoFilter;
if (item.IsEncrypted())
{
- if (aesMode)
+ if (wzAesMode)
{
CWzAesExtraField aesField;
if (!item.CentralExtra.GetWzAesField(aesField))
return S_OK;
methodId = aesField.Method;
- if (!_aesDecoder)
+ if (!_wzAesDecoder)
{
- _aesDecoderSpec = new NCrypto::NWzAES::CDecoder;
- _aesDecoder = _aesDecoderSpec;
+ _wzAesDecoderSpec = new NCrypto::NWzAes::CDecoder;
+ _wzAesDecoder = _wzAesDecoderSpec;
}
- cryptoFilter = _aesDecoder;
+ cryptoFilter = _wzAesDecoder;
Byte properties = aesField.Strength;
- RINOK(_aesDecoderSpec->SetDecoderProperties2(&properties, 1));
+ RINOK(_wzAesDecoderSpec->SetDecoderProperties2(&properties, 1));
}
- #ifdef ZIP_STRONG_SUPORT
else if (pkAesMode)
{
- if (!_zsDecoder)
+ if (!_pkAesDecoder)
{
- _zsDecoderSpec = new NCrypto::NZipStrong::CDecoder;
- _zsDecoder = _zsDecoderSpec;
+ _pkAesDecoderSpec = new NCrypto::NZipStrong::CDecoder;
+ _pkAesDecoder = _pkAesDecoderSpec;
}
- cryptoFilter = _zsDecoder;
+ cryptoFilter = _pkAesDecoder;
}
- #endif
else
{
if (!_zipCryptoDecoder)
@@ -556,11 +549,7 @@ HRESULT CZipDecoder::Decode(
CMyComBSTR password;
RINOK(getTextPassword->CryptoGetTextPassword(&password));
AString charPassword;
- if (aesMode
- #ifdef ZIP_STRONG_SUPORT
- || pkAesMode
- #endif
- )
+ if (wzAesMode || pkAesMode)
{
charPassword = UnicodeStringToMultiByte((const wchar_t *)password, CP_ACP);
/*
@@ -583,9 +572,9 @@ HRESULT CZipDecoder::Decode(
// we use OEM. WinZip/Windows probably use ANSI for some files
charPassword = UnicodeStringToMultiByte((const wchar_t *)password, CP_OEMCP);
}
- HRESULT res = cryptoSetPassword->CryptoSetPassword(
+ HRESULT result = cryptoSetPassword->CryptoSetPassword(
(const Byte *)(const char *)charPassword, charPassword.Length());
- if (res != S_OK)
+ if (result != S_OK)
return S_OK;
}
else
@@ -660,7 +649,7 @@ HRESULT CZipDecoder::Decode(
#endif
{
- HRESULT result;
+ HRESULT result = S_OK;
CMyComPtr<ISequentialInStream> inStreamNew;
if (item.IsEncrypted())
{
@@ -670,33 +659,42 @@ HRESULT CZipDecoder::Decode(
filterStream = filterStreamSpec;
}
filterStreamSpec->Filter = cryptoFilter;
- if (aesMode)
+ if (wzAesMode)
{
- RINOK(_aesDecoderSpec->ReadHeader(inStream));
+ result = _wzAesDecoderSpec->ReadHeader(inStream);
+ if (result == S_OK)
+ {
+ if (!_wzAesDecoderSpec->CheckPasswordVerifyCode())
+ result = S_FALSE;
+ }
}
- #ifdef ZIP_STRONG_SUPORT
else if (pkAesMode)
{
- RINOK(_zsDecoderSpec->ReadHeader(inStream));
+ result =_pkAesDecoderSpec->ReadHeader(inStream, item.FileCRC, item.UnPackSize);
+ if (result == S_OK)
+ {
+ bool passwOK;
+ result = _pkAesDecoderSpec->CheckPassword(passwOK);
+ if (result == S_OK && !passwOK)
+ result = S_FALSE;
+ }
}
- #endif
else
{
- RINOK(_zipCryptoDecoderSpec->ReadHeader(inStream));
+ result = _zipCryptoDecoderSpec->ReadHeader(inStream);
}
- RINOK(filterStreamSpec->SetInStream(inStream));
- inStreamReleaser.FilterCoder = filterStreamSpec;
- inStreamNew = filterStream;
-
- if (aesMode)
+
+ if (result == S_OK)
{
- if (!_aesDecoderSpec->CheckPasswordVerifyCode())
- return S_OK;
+ RINOK(filterStreamSpec->SetInStream(inStream));
+ inStreamReleaser.FilterCoder = filterStreamSpec;
+ inStreamNew = filterStream;
}
}
else
inStreamNew = inStream;
- result = coder->Code(inStreamNew, outStream, NULL, &item.UnPackSize, compressProgress);
+ if (result == S_OK)
+ result = coder->Code(inStreamNew, outStream, NULL, &item.UnPackSize, compressProgress);
if (result == S_FALSE)
return S_OK;
if (result == E_NOTIMPL)
@@ -711,10 +709,10 @@ HRESULT CZipDecoder::Decode(
bool authOk = true;
if (needCRC)
crcOK = (outStreamSpec->GetCRC() == item.FileCRC);
- if (aesMode)
+ if (wzAesMode)
{
- inStream.Attach(archive.CreateLimitedStream(authenticationPos, NCrypto::NWzAES::kMacSize));
- if (_aesDecoderSpec->CheckMac(inStream, authOk) != S_OK)
+ inStream.Attach(archive.CreateLimitedStream(authenticationPos, NCrypto::NWzAes::kMacSize));
+ if (_wzAesDecoderSpec->CheckMac(inStream, authOk) != S_OK)
authOk = false;
}
diff --git a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp
index ea46e131..fe2c16e7 100755
--- a/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp
+++ b/CPP/7zip/Archive/Zip/ZipHandlerOut.cpp
@@ -1,22 +1,25 @@
-// Zip/HandlerOut.cpp
+// ZipHandlerOut.cpp
#include "StdAfx.h"
-#include "ZipHandler.h"
-#include "ZipUpdate.h"
-
-#include "Common/StringConvert.h"
#include "Common/ComTry.h"
+#include "Common/StringConvert.h"
#include "Common/StringToInt.h"
#include "Windows/PropVariant.h"
#include "Windows/Time.h"
#include "../../IPassword.h"
+
+#include "../../Common/OutBuffer.h"
+
+#include "../../Crypto/WzAes.h"
+
#include "../Common/ItemNameUtils.h"
#include "../Common/ParseProperties.h"
-#include "../../Crypto/WzAES/WzAES.h"
-#include "../../Common/OutBuffer.h"
+
+#include "ZipHandler.h"
+#include "ZipUpdate.h"
using namespace NWindows;
using namespace NCOM;
@@ -253,7 +256,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
return E_INVALIDARG;
if (m_IsAesMode)
{
- if (options.Password.Length() > NCrypto::NWzAES::kPasswordSizeMax)
+ if (options.Password.Length() > NCrypto::NWzAes::kPasswordSizeMax)
return E_INVALIDARG;
}
options.Password = UnicodeStringToMultiByte((const wchar_t *)password, CP_OEMCP);
diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
index b10f801e..5c7e64db 100755
--- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp
+++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
@@ -2,27 +2,26 @@
#include "StdAfx.h"
-#include <stdio.h>
-
-#include "ZipUpdate.h"
-#include "ZipAddCommon.h"
-#include "ZipOut.h"
-
-#include "Common/Defs.h"
#include "Common/AutoPtr.h"
+#include "Common/Defs.h"
#include "Common/StringConvert.h"
+
#include "Windows/Defs.h"
#include "Windows/Thread.h"
+#include "../../Common/CreateCoder.h"
+#include "../../Common/LimitedStreams.h"
+#include "../../Common/OutMemStream.h"
#include "../../Common/ProgressUtils.h"
#ifdef COMPRESS_MT
#include "../../Common/ProgressMt.h"
#endif
-#include "../../Common/LimitedStreams.h"
-#include "../../Common/OutMemStream.h"
-#include "../../Common/CreateCoder.h"
-#include "../../Compress/Copy/CopyCoder.h"
+#include "../../Compress/CopyCoder.h"
+
+#include "ZipAddCommon.h"
+#include "ZipOut.h"
+#include "ZipUpdate.h"
using namespace NWindows;
using namespace NSynchronization;