diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2016-09-29 03:00:00 +0300 |
---|---|---|
committer | Kornel LesinĚski <kornel@geekhood.net> | 2016-12-08 15:12:54 +0300 |
commit | 232ce7957441b06193c4cbdc1bc9e71436fadfdb (patch) | |
tree | cbfba61cb993434ebb38be4e058a977d91a8676a /CPP/7zip/Archive/Nsis | |
parent | 1eddf527cacc149016ec987d554d3dfb52b69131 (diff) |
16.0316.03
Diffstat (limited to 'CPP/7zip/Archive/Nsis')
-rw-r--r-- | CPP/7zip/Archive/Nsis/NsisDecode.cpp | 45 | ||||
-rw-r--r-- | CPP/7zip/Archive/Nsis/NsisDecode.h | 9 | ||||
-rw-r--r-- | CPP/7zip/Archive/Nsis/NsisIn.cpp | 22 |
3 files changed, 61 insertions, 15 deletions
diff --git a/CPP/7zip/Archive/Nsis/NsisDecode.cpp b/CPP/7zip/Archive/Nsis/NsisDecode.cpp index 0bbf6094..daf3df6e 100644 --- a/CPP/7zip/Archive/Nsis/NsisDecode.cpp +++ b/CPP/7zip/Archive/Nsis/NsisDecode.cpp @@ -12,7 +12,6 @@ #include "../../Compress/BcjCoder.h" #include "../../Compress/BZip2Decoder.h" -#include "../../Compress/DeflateDecoder.h" #define Get32(p) GetUi32(p) @@ -27,12 +26,16 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter) if (Method != _curMethod) Release(); _curMethod = Method; + if (!_codecInStream) { switch (Method) { // case NMethodType::kCopy: return E_NOTIMPL; - case NMethodType::kDeflate: _codecInStream = new NCompress::NDeflate::NDecoder::CNsisCOMCoder(); break; + case NMethodType::kDeflate: + _deflateDecoder = new NCompress::NDeflate::NDecoder::CCOMCoder(); + _codecInStream = _deflateDecoder; + break; case NMethodType::kBZip2: _codecInStream = new NCompress::NBZip2::CNsisDecoder(); break; case NMethodType::kLZMA: _lzmaDecoder = new NCompress::NLzma::CDecoder(); @@ -42,6 +45,9 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter) } } + if (Method == NMethodType::kDeflate) + _deflateDecoder->SetNsisMode(IsNsisDeflate); + if (FilterFlag) { Byte flag; @@ -199,9 +205,8 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp if (outBuf) { - if (!unpackSizeDefined) - return S_FALSE; - outBuf->Alloc(unpackSize); + if (unpackSizeDefined) + outBuf->Alloc(unpackSize); } UInt64 inSizeStart = 0; @@ -213,6 +218,8 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp unpackSize = 0xFFFFFFFF; UInt32 offset = 0; + HRESULT res = S_OK; + for (;;) { size_t rem = unpackSize - offset; @@ -225,11 +232,25 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp if (size == 0) { if (unpackSizeDefined) - return S_FALSE; + res = S_FALSE; break; } + if (outBuf) + { + size_t nextSize = offset + size; + if (outBuf->Size() < nextSize) + { + { + const size_t nextSize2 = outBuf->Size() * 2; + if (nextSize < nextSize2) + nextSize = nextSize2; + } + outBuf->ChangeSize_KeepData(nextSize, offset); + } memcpy((Byte *)*outBuf + (size_t)offset, Buffer, size); + } + StreamPos += size; offset += (UInt32)size; @@ -243,9 +264,17 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp UInt64 outSize = offset; RINOK(progress->SetRatioInfo(&inSize, &outSize)); if (realOutStream) - RINOK(WriteStream(realOutStream, Buffer, size)); + { + res = WriteStream(realOutStream, Buffer, size); + if (res != S_OK) + break; + } } - return S_OK; + + if (outBuf && offset != outBuf->Size()) + outBuf->ChangeSize_KeepData(offset, offset); + + return res; } }} diff --git a/CPP/7zip/Archive/Nsis/NsisDecode.h b/CPP/7zip/Archive/Nsis/NsisDecode.h index 7b22181e..ec713d05 100644 --- a/CPP/7zip/Archive/Nsis/NsisDecode.h +++ b/CPP/7zip/Archive/Nsis/NsisDecode.h @@ -8,6 +8,7 @@ #include "../../Common/FilterCoder.h" #include "../../Common/StreamUtils.h" +#include "../../Compress/DeflateDecoder.h" #include "../../Compress/LzmaDecoder.h" namespace NArchive { @@ -37,6 +38,7 @@ class CDecoder CMyComPtr<ISequentialInStream> _codecInStream; CMyComPtr<ISequentialInStream> _decoderInStream; + NCompress::NDeflate::NDecoder::CCOMCoder *_deflateDecoder; NCompress::NLzma::CDecoder *_lzmaDecoder; public: @@ -46,9 +48,16 @@ public: NMethodType::EEnum Method; bool FilterFlag; bool Solid; + bool IsNsisDeflate; CByteBuffer Buffer; // temp buf. + CDecoder(): + FilterFlag(false), + Solid(true), + IsNsisDeflate(true) + {} + void Release() { _filterInStream.Release(); diff --git a/CPP/7zip/Archive/Nsis/NsisIn.cpp b/CPP/7zip/Archive/Nsis/NsisIn.cpp index e04a97a8..a3bfcaec 100644 --- a/CPP/7zip/Archive/Nsis/NsisIn.cpp +++ b/CPP/7zip/Archive/Nsis/NsisIn.cpp @@ -175,7 +175,7 @@ static const CCommandInfo k_Commands[kNumCmds] = { 0 }, // "BringToFront" }, { 2 }, // "SetDetailsView" }, { 2 }, // "SetFileAttributes" }, - { 2 }, // CreateDirectory, SetOutPath + { 3 }, // CreateDirectory, SetOutPath { 3 }, // "IfFileExists" }, { 3 }, // SetRebootFlag, ... { 4 }, // "If" }, // IfAbort, IfSilent, IfErrors, IfRebootFlag @@ -1395,7 +1395,7 @@ void CInArchive::AddRegRoot(UInt32 val) Script += s; } -static const char *g_WinAttrib[] = +static const char * const g_WinAttrib[] = { "READONLY" , "HIDDEN" @@ -3362,6 +3362,11 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh) #ifdef NSIS_SCRIPT s += isSetOutPath ? "SetOutPath" : "CreateDirectory"; AddParam(params[0]); + if (params[2] != 0) + { + SmallSpaceComment(); + s += "CreateRestrictedDirectory"; + } #endif break; @@ -3378,11 +3383,8 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh) params[2] == 0 && params[3] == 0) { - if (IsVarStr(params[1], kVar_OUTDIR)) - { - spec_outdir_U = UPrefixes.Back(); // outdir_U; - spec_outdir_A = APrefixes.Back();// outdir_A; - } + spec_outdir_U = UPrefixes.Back(); // outdir_U; + spec_outdir_A = APrefixes.Back(); // outdir_A; } } @@ -5045,6 +5047,9 @@ HRESULT CInArchive::Parse() DetectNsisType(bhEntries, _data + bhEntries.Offset); + Decoder.IsNsisDeflate = (NsisType != k_NsisType_Nsis3); + + #ifdef NSIS_SCRIPT { @@ -5606,6 +5611,9 @@ HRESULT CInArchive::Open2(const Byte *sig, size_t size) Decoder.Method = Method; Decoder.FilterFlag = FilterFlag; Decoder.Solid = IsSolid; + + Decoder.IsNsisDeflate = true; // we need some smart check that NSIS is not NSIS3 here. + Decoder.InputStream = _stream; Decoder.Buffer.Alloc(kInputBufSize); Decoder.StreamPos = 0; |