This commit is contained in:
Igor Pavlov
2023-12-22 17:17:05 +00:00
committed by Kornel
parent ec44a8a070
commit a36c48cece
954 changed files with 42199 additions and 25482 deletions

View File

@@ -40,7 +40,7 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
if (!_codecInStream)
{
switch (Method)
switch ((int)Method)
{
// case NMethodType::kCopy: return E_NOTIMPL;
case NMethodType::kDeflate:
@@ -65,7 +65,7 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
if (FilterFlag)
{
Byte flag;
RINOK(ReadStream_FALSE(inStream, &flag, 1));
RINOK(ReadStream_FALSE(inStream, &flag, 1))
if (flag > 1)
return E_NOTIMPL;
useFilter = (flag != 0);
@@ -79,9 +79,9 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
{
_filter = new CFilterCoder(false);
_filterInStream = _filter;
_filter->Filter = new NCompress::NBcj::CCoder(false);
_filter->Filter = new NCompress::NBcj::CCoder2(z7_BranchConvSt_X86_Dec);
}
RINOK(_filter->SetInStream(_codecInStream));
RINOK(_filter->SetInStream(_codecInStream))
_decoderInStream = _filterInStream;
}
@@ -89,8 +89,8 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
{
const unsigned kPropsSize = LZMA_PROPS_SIZE;
Byte props[kPropsSize];
RINOK(ReadStream_FALSE(inStream, props, kPropsSize));
RINOK(_lzmaDecoder->SetDecoderProperties2((const Byte *)props, kPropsSize));
RINOK(ReadStream_FALSE(inStream, props, kPropsSize))
RINOK(_lzmaDecoder->SetDecoderProperties2((const Byte *)props, kPropsSize))
}
{
@@ -98,7 +98,7 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
_codecInStream.QueryInterface(IID_ICompressSetInStream, &setInStream);
if (!setInStream)
return E_NOTIMPL;
RINOK(setInStream->SetInStream(inStream));
RINOK(setInStream->SetInStream(inStream))
}
{
@@ -106,12 +106,12 @@ HRESULT CDecoder::Init(ISequentialInStream *inStream, bool &useFilter)
_codecInStream.QueryInterface(IID_ICompressSetOutStreamSize, &setOutStreamSize);
if (!setOutStreamSize)
return E_NOTIMPL;
RINOK(setOutStreamSize->SetOutStreamSize(NULL));
RINOK(setOutStreamSize->SetOutStreamSize(NULL))
}
if (useFilter)
{
RINOK(_filter->SetOutStreamSize(NULL));
RINOK(_filter->SetOutStreamSize(NULL))
}
return S_OK;
@@ -130,14 +130,14 @@ HRESULT CDecoder::SetToPos(UInt64 pos, ICompressProgressInfo *progress)
while (StreamPos < pos)
{
size_t size = (size_t)MyMin(pos - StreamPos, (UInt64)Buffer.Size());
RINOK(Read(Buffer, &size));
RINOK(Read(Buffer, &size))
if (size == 0)
return S_FALSE;
StreamPos += size;
offset += size;
const UInt64 inSize = GetInputProcessedSize() - inSizeStart;
RINOK(progress->SetRatioInfo(&inSize, &offset));
RINOK(progress->SetRatioInfo(&inSize, &offset))
}
return S_OK;
}
@@ -156,7 +156,7 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
{
Byte temp[4];
size_t processedSize = 4;
RINOK(Read(temp, &processedSize));
RINOK(Read(temp, &processedSize))
StreamPos += processedSize;
if (processedSize != 4)
return S_FALSE;
@@ -171,7 +171,7 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
Byte temp[4];
{
size_t processedSize = 4;
RINOK(ReadStream(InputStream, temp, &processedSize));
RINOK(ReadStream(InputStream, temp, &processedSize))
StreamPos += processedSize;
if (processedSize != 4)
return S_FALSE;
@@ -192,7 +192,7 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
{
UInt32 curSize = (UInt32)MyMin((size_t)size, Buffer.Size());
UInt32 processedSize;
RINOK(InputStream->Read(Buffer, curSize, &processedSize));
RINOK(InputStream->Read(Buffer, curSize, &processedSize))
if (processedSize == 0)
return S_FALSE;
if (outBuf)
@@ -202,8 +202,8 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
StreamPos += processedSize;
unpackSizeRes += processedSize;
if (realOutStream)
RINOK(WriteStream(realOutStream, Buffer, processedSize));
RINOK(progress->SetRatioInfo(&offset, &offset));
RINOK(WriteStream(realOutStream, Buffer, processedSize))
RINOK(progress->SetRatioInfo(&offset, &offset))
}
return S_OK;
@@ -217,7 +217,7 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
limitedStreamSpec->Init(size);
{
bool useFilter;
RINOK(Init(limitedStream, useFilter));
RINOK(Init(limitedStream, useFilter))
}
}
@@ -244,7 +244,7 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
size_t size = Buffer.Size();
if (size > rem)
size = rem;
RINOK(Read(Buffer, &size));
RINOK(Read(Buffer, &size))
if (size == 0)
{
if (unpackSizeDefined)
@@ -277,7 +277,7 @@ HRESULT CDecoder::Decode(CByteBuffer *outBuf, bool unpackSizeDefined, UInt32 unp
unpackSizeRes += (UInt32)size;
UInt64 outSize = offset;
RINOK(progress->SetRatioInfo(&inSize, &outSize));
RINOK(progress->SetRatioInfo(&inSize, &outSize))
if (realOutStream)
{
res = WriteStream(realOutStream, Buffer, size);

View File

@@ -1,7 +1,7 @@
// NsisDecode.h
#ifndef __NSIS_DECODE_H
#define __NSIS_DECODE_H
#ifndef ZIP7_INC_NSIS_DECODE_H
#define ZIP7_INC_NSIS_DECODE_H
#include "../../../Common/MyBuffer.h"
@@ -82,7 +82,7 @@ public:
HRESULT Read(void *data, size_t *processedSize)
{
return ReadStream(_decoderInStream, data, processedSize);;
return ReadStream(_decoderInStream, data, processedSize);
}

View File

@@ -61,22 +61,19 @@ IMP_IInArchive_Props
IMP_IInArchive_ArcProps
static AString UInt32ToString(UInt32 val)
static void AddDictProp(AString &s, UInt32 val)
{
char s[16];
ConvertUInt32ToString(val, s);
return (AString)s;
}
static AString GetStringForSizeValue(UInt32 val)
{
for (int i = 31; i >= 0; i--)
for (unsigned i = 0; i < 32; i++)
if (((UInt32)1 << i) == val)
return UInt32ToString(i);
{
s.Add_UInt32(i);
return;
}
char c = 'b';
if ((val & ((1 << 20) - 1)) == 0) { val >>= 20; c = 'm'; }
else if ((val & ((1 << 10) - 1)) == 0) { val >>= 10; c = 'k'; }
return UInt32ToString(val) + c;
s.Add_UInt32(val);
s += c;
}
static AString GetMethod(bool useFilter, NMethodType::EEnum method, UInt32 dict)
@@ -87,11 +84,11 @@ static AString GetMethod(bool useFilter, NMethodType::EEnum method, UInt32 dict)
s += kBcjMethod;
s.Add_Space();
}
s += ((unsigned)method < ARRAY_SIZE(kMethods)) ? kMethods[(unsigned)method] : kUnknownMethod;
s += ((unsigned)method < Z7_ARRAY_SIZE(kMethods)) ? kMethods[(unsigned)method] : kUnknownMethod;
if (method == NMethodType::kLZMA)
{
s += ':';
s += GetStringForSizeValue(dict);
AddDictProp(s, dict);
}
return s;
}
@@ -105,7 +102,7 @@ AString CHandler::GetMethod(NMethodType::EEnum method, bool useItemFilter, UInt3
s += kBcjMethod;
s.Add_Space();
}
s += (method < ARRAY_SIZE(kMethods)) ? kMethods[method] : kUnknownMethod;
s += (method < Z7_ARRAY_SIZE(kMethods)) ? kMethods[method] : kUnknownMethod;
if (method == NMethodType::kLZMA)
{
s += ':';
@@ -115,7 +112,7 @@ AString CHandler::GetMethod(NMethodType::EEnum method, bool useItemFilter, UInt3
}
*/
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -162,7 +159,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
if (!_archive.IsInstaller)
{
if (!s.IsEmpty())
s += '.';
s.Add_Dot();
s += "Uninstall";
}
#endif
@@ -190,7 +187,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
}
STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback * /* openArchiveCallback */)
Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *maxCheckStartPosition, IArchiveOpenCallback * /* openArchiveCallback */))
{
COM_TRY_BEGIN
Close();
@@ -215,18 +212,18 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *maxCheckStartPositi
COM_TRY_END
}
STDMETHODIMP CHandler::Close()
Z7_COM7F_IMF(CHandler::Close())
{
_archive.Clear();
_archive.Release();
return S_OK;
}
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
{
*numItems = _archive.Items.Size()
#ifdef NSIS_SCRIPT
+ 1 + _archive.LicenseFiles.Size();
+ 1 + _archive.LicenseFiles.Size()
#endif
;
return S_OK;
@@ -240,7 +237,7 @@ bool CHandler::GetUncompressedSize(unsigned index, UInt32 &size) const
size = item.Size;
else if (_archive.IsSolid && item.EstimatedSize_Defined)
size = item.EstimatedSize;
else
else if (!item.IsEmptyFile)
return false;
return true;
}
@@ -272,7 +269,7 @@ bool CHandler::GetCompressedSize(unsigned index, UInt32 &size) const
}
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -360,21 +357,21 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
}
static bool UninstallerPatch(const Byte *p, size_t size, CByteBuffer &dest)
static bool UninstallerPatch(const Byte *p, size_t size, Byte *dest, size_t destSize)
{
for (;;)
{
if (size < 4)
return false;
UInt32 len = Get32(p);
const UInt32 len = Get32(p);
if (len == 0)
return size == 4;
if (size < 8)
return false;
UInt32 offs = Get32(p + 4);
const UInt32 offs = Get32(p + 4);
p += 8;
size -= 8;
if (size < len || offs > dest.Size() || len > dest.Size() - offs)
if (size < len || offs > destSize || len > destSize - offs)
return false;
memcpy(dest + offs, p, len);
p += len;
@@ -383,11 +380,11 @@ static bool UninstallerPatch(const Byte *p, size_t size, CByteBuffer &dest)
}
STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback)
Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback))
{
COM_TRY_BEGIN
bool allFilesMode = (numItems == (UInt32)(Int32)-1);
const bool allFilesMode = (numItems == (UInt32)(Int32)-1);
if (allFilesMode)
GetNumberOfItems(&numItems);
if (numItems == 0)
@@ -399,7 +396,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
UInt32 i;
for (i = 0; i < numItems; i++)
{
UInt32 index = (allFilesMode ? i : indices[i]);
const UInt32 index = (allFilesMode ? i : indices[i]);
#ifdef NSIS_SCRIPT
if (index >= _archive.Items.Size())
@@ -436,8 +433,8 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (_archive.IsSolid)
{
RINOK(_archive.SeekTo_DataStreamOffset());
RINOK(_archive.InitDecoder());
RINOK(_archive.SeekTo_DataStreamOffset())
RINOK(_archive.InitDecoder())
_archive.Decoder.StreamPos = 0;
}
@@ -476,16 +473,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
curPacked = 0;
curUnpacked = 0;
RINOK(lps->SetCur());
RINOK(lps->SetCur())
// RINOK(extractCallback->SetCompleted(&currentTotalSize));
// RINOK(extractCallback->SetCompleted(&currentTotalSize))
CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode = testMode ?
const Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract;
const UInt32 index = allFilesMode ? i : indices[i];
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
bool dataError = false;
@@ -511,9 +508,9 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
curUnpacked = size;
if (!testMode && !realOutStream)
continue;
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->PrepareOperation(askMode))
if (realOutStream)
RINOK(WriteStream(realOutStream, data, size));
RINOK(WriteStream(realOutStream, data, size))
}
else
#endif
@@ -526,15 +523,20 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (!testMode && !realOutStream)
continue;
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->PrepareOperation(askMode))
dataError = solidDataError;
bool needDecompress = !solidDataError;
if (needDecompress)
bool needDecompress = false;
if (!item.IsEmptyFile)
{
if (testMode && _archive.IsSolid && _archive.GetPosOfSolidItem(index) == prevPos)
needDecompress = false;
needDecompress = !solidDataError;
if (needDecompress)
{
if (testMode && _archive.IsSolid && _archive.GetPosOfSolidItem(index) == prevPos)
needDecompress = false;
}
}
if (needDecompress)
@@ -544,7 +546,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (!_archive.IsSolid)
{
RINOK(_archive.SeekToNonSolidItem(index));
RINOK(_archive.SeekToNonSolidItem(index))
}
else
{
@@ -566,10 +568,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
}
else if (!testMode && i + 1 < numItems)
{
UInt32 next = allFilesMode ? i + 1 : indices[i + 1];
const UInt32 next = allFilesMode ? i + 1 : indices[i + 1];
if (next < _archive.Items.Size())
{
UInt64 nextPos = _archive.GetPosOfSolidItem(next);
// next cannot be IsEmptyFile
const UInt64 nextPos = _archive.GetPosOfSolidItem(next);
if (nextPos == pos)
{
writeToTemp = true;
@@ -581,12 +584,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
prevPos = pos;
}
/* nsis 3.08 can use (PatchSize == 0) for uninstaller without patched section */
const bool is_PatchedUninstaller = item.Is_PatchedUninstaller();
if (!dataError)
{
// UInt32 unpackSize = 0;
// bool unpackSize_Defined = false;
bool writeToTemp1 = writeToTemp;
if (item.IsUninstaller)
if (is_PatchedUninstaller)
{
// unpackSize = item.PatchSize;
// unpackSize_Defined = true;
@@ -603,16 +610,16 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (readFromTemp)
{
if (realOutStream && !item.IsUninstaller)
RINOK(WriteStream(realOutStream, tempBuf, tempBuf.Size()));
if (realOutStream && !is_PatchedUninstaller)
RINOK(WriteStream(realOutStream, tempBuf, tempBuf.Size()))
}
else
{
UInt32 curUnpacked32 = 0;
HRESULT res = _archive.Decoder.Decode(
const HRESULT res = _archive.Decoder.Decode(
writeToTemp1 ? &tempBuf : NULL,
item.IsUninstaller, item.PatchSize,
item.IsUninstaller ? NULL : (ISequentialOutStream *)realOutStream,
is_PatchedUninstaller, item.PatchSize,
is_PatchedUninstaller ? NULL : (ISequentialOutStream *)realOutStream,
progress,
curPacked, curUnpacked32);
curUnpacked = curUnpacked32;
@@ -629,21 +636,20 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
}
}
if (!dataError && item.IsUninstaller)
if (!dataError && is_PatchedUninstaller)
{
if (_archive.ExeStub.Size() != 0)
{
CByteBuffer destBuf = _archive.ExeStub;
dataError = !UninstallerPatch(tempBuf, tempBuf.Size(), destBuf);
dataError = !UninstallerPatch(tempBuf, tempBuf.Size(), destBuf, destBuf.Size());
if (realOutStream)
RINOK(WriteStream(realOutStream, destBuf, destBuf.Size()));
RINOK(WriteStream(realOutStream, destBuf, destBuf.Size()))
}
if (readFromTemp)
{
if (realOutStream)
RINOK(WriteStream(realOutStream, tempBuf2, tempBuf2.Size()));
RINOK(WriteStream(realOutStream, tempBuf2, tempBuf2.Size()))
}
else
{
@@ -652,10 +658,10 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (!_archive.IsSolid)
{
RINOK(_archive.SeekTo(_archive.GetPosOfNonSolidItem(index) + 4 + curPacked ));
RINOK(_archive.SeekTo(_archive.GetPosOfNonSolidItem(index) + 4 + curPacked ))
}
HRESULT res = _archive.Decoder.Decode(
const HRESULT res = _archive.Decoder.Decode(
writeToTemp ? &tempBuf2 : NULL,
false, 0,
realOutStream,
@@ -679,7 +685,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
realOutStream.Release();
RINOK(extractCallback->SetOperationResult(dataError ?
NExtract::NOperationResult::kDataError :
NExtract::NOperationResult::kOK));
NExtract::NOperationResult::kOK))
}
return S_OK;
COM_TRY_END

View File

@@ -1,7 +1,7 @@
// NSisHandler.h
#ifndef __NSIS_HANDLER_H
#define __NSIS_HANDLER_H
#ifndef ZIP7_INC_NSIS_HANDLER_H
#define ZIP7_INC_NSIS_HANDLER_H
#include "../../../Common/MyCom.h"
@@ -14,10 +14,8 @@
namespace NArchive {
namespace NNsis {
class CHandler:
public IInArchive,
public CMyUnknownImp
{
Z7_CLASS_IMP_CHandler_IInArchive_0
CInArchive _archive;
AString _methodString;
@@ -25,10 +23,6 @@ class CHandler:
bool GetCompressedSize(unsigned index, UInt32 &size) const;
// AString GetMethod(NMethodType::EEnum method, bool useItemFilter, UInt32 dictionary) const;
public:
MY_UNKNOWN_IMP1(IInArchive)
INTERFACE_IInArchive(;)
};
}}

View File

@@ -6,7 +6,6 @@
#include "../../../Common/StringToInt.h"
#include "../../Common/LimitedStreams.h"
#include "../../Common/StreamUtils.h"
#include "NsisIn.h"
@@ -32,7 +31,7 @@ static const unsigned kCmdSize = 4 + kNumCommandParams * 4;
static const char * const kErrorStr = "$_ERROR_STR_";
#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
#define RINOZ(x) { int _tt_ = (x); if (_tt_ != 0) return _tt_; }
/* There are several versions of NSIS:
@@ -466,8 +465,8 @@ void CInArchive::AddLicense(UInt32 param, Int32 langID)
}
strUsed[param] = 1;
UInt32 start = _stringsPos + (IsUnicode ? param * 2 : param);
UInt32 offset = start + (IsUnicode ? 2 : 1);
const UInt32 start = _stringsPos + (IsUnicode ? param * 2 : param);
const UInt32 offset = start + (IsUnicode ? 2 : 1);
{
FOR_VECTOR (i, LicenseFiles)
{
@@ -484,16 +483,16 @@ void CInArchive::AddLicense(UInt32 param, Int32 langID)
{
fileName += "\\license-";
// LangId_To_String(fileName, langID);
UIntToString(fileName, langID);
UIntToString(fileName, (UInt32)langID);
}
else if (++_numRootLicenses > 1)
{
fileName += '-';
fileName.Add_Minus();
UIntToString(fileName, _numRootLicenses);
}
const Byte *sz = (_data + start);
unsigned marker = IsUnicode ? Get16(sz) : *sz;
bool isRTF = (marker == 2);
const unsigned marker = IsUnicode ? Get16(sz) : *sz;
const bool isRTF = (marker == 2);
fileName += isRTF ? ".rtf" : ".txt"; // if (*sz == 1) it's text;
Script += fileName;
@@ -505,7 +504,7 @@ void CInArchive::AddLicense(UInt32 param, Int32 langID)
else
{
sz += 2;
UInt32 len = GetUi16Str_Len(sz);
const UInt32 len = GetUi16Str_Len(sz);
lic.Size = len * 2;
if (isRTF)
{
@@ -526,6 +525,26 @@ void CInArchive::AddLicense(UInt32 param, Int32 langID)
#endif
#ifdef NSIS_SCRIPT
#define Z7_NSIS_WIN_GENERIC_READ ((UInt32)1 << 31)
#endif
#define Z7_NSIS_WIN_GENERIC_WRITE ((UInt32)1 << 30)
#ifdef NSIS_SCRIPT
#define Z7_NSIS_WIN_GENERIC_EXECUTE ((UInt32)1 << 29)
#define Z7_NSIS_WIN_GENERIC_ALL ((UInt32)1 << 28)
#endif
#ifdef NSIS_SCRIPT
#define Z7_NSIS_WIN_CREATE_NEW 1
#endif
#define Z7_NSIS_WIN_CREATE_ALWAYS 2
#ifdef NSIS_SCRIPT
#define Z7_NSIS_WIN_OPEN_EXISTING 3
#define Z7_NSIS_WIN_OPEN_ALWAYS 4
#define Z7_NSIS_WIN_TRUNCATE_EXISTING 5
#endif
// #define kVar_CMDLINE 20
#define kVar_INSTDIR 21
#define kVar_OUTDIR 22
@@ -562,9 +581,9 @@ static const char * const kVarStrings[] =
, "_OUTDIR" // NSIS 2.04+
};
static const unsigned kNumInternalVars = 20 + ARRAY_SIZE(kVarStrings);
static const unsigned kNumInternalVars = 20 + Z7_ARRAY_SIZE(kVarStrings);
#define GET_NUM_INTERNAL_VARS (IsNsis200 ? kNumInternalVars - 3 : IsNsis225 ? kNumInternalVars - 2 : kNumInternalVars);
#define GET_NUM_INTERNAL_VARS (IsNsis200 ? kNumInternalVars - 3 : IsNsis225 ? kNumInternalVars - 2 : kNumInternalVars)
void CInArchive::GetVar2(AString &res, UInt32 index)
{
@@ -643,7 +662,7 @@ void CInArchive::AddParam_UInt(UInt32 value)
#define IS_NS_SPEC_CHAR(c) ((c) >= NS_CODE_SKIP)
#define IS_PARK_SPEC_CHAR(c) ((c) >= PARK_CODE_SKIP && (c) <= PARK_CODE_LANG)
#define DECODE_NUMBER_FROM_2_CHARS(c0, c1) (((c0) & 0x7F) | (((unsigned)((c1) & 0x7F)) << 7))
#define DECODE_NUMBER_FROM_2_CHARS(c0, c1) (((unsigned)(c0) & 0x7F) | (((unsigned)((c1) & 0x7F)) << 7))
#define CONVERT_NUMBER_NS_3_UNICODE(n) n = ((n & 0x7F) | (((n >> 8) & 0x7F) << 7))
#define CONVERT_NUMBER_PARK(n) n &= 0x7FFF
@@ -738,7 +757,7 @@ void CInArchive::GetShellString(AString &s, unsigned index1, unsigned index2)
}
s += '$';
if (index1 < ARRAY_SIZE(kShellStrings))
if (index1 < Z7_ARRAY_SIZE(kShellStrings))
{
const char *sz = kShellStrings[index1];
if (sz)
@@ -747,7 +766,7 @@ void CInArchive::GetShellString(AString &s, unsigned index1, unsigned index2)
return;
}
}
if (index2 < ARRAY_SIZE(kShellStrings))
if (index2 < Z7_ARRAY_SIZE(kShellStrings))
{
const char *sz = kShellStrings[index2];
if (sz)
@@ -1151,7 +1170,7 @@ void CInArchive::ReadString2_Raw(UInt32 pos)
Raw_AString.Empty();
Raw_UString.Empty();
if ((Int32)pos < 0)
Add_LangStr(Raw_AString, -((Int32)pos + 1));
Add_LangStr(Raw_AString, (UInt32)-((Int32)pos + 1));
else if (pos >= NumStringChars)
{
Raw_AString += kErrorStr;
@@ -1361,7 +1380,7 @@ void CInArchive::ReadString2(AString &s, UInt32 pos)
{
if ((Int32)pos < 0)
{
Add_LangStr(s, -((Int32)pos + 1));
Add_LangStr(s, (UInt32)-((Int32)pos + 1));
return;
}
@@ -1537,7 +1556,7 @@ static const UInt32 CMD_REF_Leave = (1 << 4);
static const UInt32 CMD_REF_OnFunc = (1 << 5);
static const UInt32 CMD_REF_Section = (1 << 6);
static const UInt32 CMD_REF_InitPluginDir = (1 << 7);
// static const UInt32 CMD_REF_Creator = (1 << 5); // _Pre is used instead
// static const UInt32 CMD_REF_Creator = (1 << 5); // CMD_REF_Pre is used instead
static const unsigned CMD_REF_OnFunc_NumShifts = 28; // it uses for onFunc too
static const unsigned CMD_REF_Page_NumShifts = 16; // it uses for onFunc too
static const UInt32 CMD_REF_Page_Mask = 0x0FFF0000;
@@ -1617,7 +1636,7 @@ void CInArchive::Add_GotoVar(UInt32 param)
{
Space();
if ((Int32)param < 0)
Add_Var(-((Int32)param + 1));
Add_Var((UInt32)-((Int32)param + 1));
else
Add_LabelName(param - 1);
}
@@ -1647,8 +1666,8 @@ static bool NoLabels(const UInt32 *labels, UInt32 num)
static const char * const k_REBOOTOK = " /REBOOTOK";
#define MY__MB_ABORTRETRYIGNORE 2
#define MY__MB_RETRYCANCEL 5
#define Z7_NSIS_WIN_MB_ABORTRETRYIGNORE 2
#define Z7_NSIS_WIN_MB_RETRYCANCEL 5
static const char * const k_MB_Buttons[] =
{
@@ -1661,7 +1680,7 @@ static const char * const k_MB_Buttons[] =
, "CANCELTRYCONTINUE"
};
#define MY__MB_ICONSTOP (1 << 4)
#define Z7_NSIS_WIN_MB_ICONSTOP (1 << 4)
static const char * const k_MB_Icons[] =
{
@@ -1684,8 +1703,8 @@ static const char * const k_MB_Flags[] =
// , "SERVICE_NOTIFICATION" // unsupported. That bit is used for NSIS purposes
};
#define MY__IDCANCEL 2
#define MY__IDIGNORE 5
#define Z7_NSIS_WIN_IDCANCEL 2
#define Z7_NSIS_WIN_IDIGNORE 5
static const char * const k_Button_IDs[] =
{
@@ -1706,7 +1725,7 @@ static const char * const k_Button_IDs[] =
void CInArchive::Add_ButtonID(UInt32 buttonID)
{
Space();
if (buttonID < ARRAY_SIZE(k_Button_IDs))
if (buttonID < Z7_ARRAY_SIZE(k_Button_IDs))
Script += k_Button_IDs[buttonID];
else
{
@@ -1774,19 +1793,8 @@ void CNsis_CtlColors::Parse(const Byte *p, bool is64)
}
// Win32 constants
#define MY__TRANSPARENT 1
// #define MY__OPAQUE 2
#define MY__GENERIC_READ ((UInt32)1 << 31)
#define MY__GENERIC_WRITE ((UInt32)1 << 30)
#define MY__GENERIC_EXECUTE ((UInt32)1 << 29)
#define MY__GENERIC_ALL ((UInt32)1 << 28)
#define MY__CREATE_NEW 1
#define MY__CREATE_ALWAYS 2
#define MY__OPEN_EXISTING 3
#define MY__OPEN_ALWAYS 4
#define MY__TRUNCATE_EXISTING 5
#define Z7_NSIS_WIN_TRANSPARENT 1
// #define Z7_NSIS_WIN_OPAQUE 2
// text/bg colors
#define kColorsFlags_TEXT 1
@@ -1821,12 +1829,12 @@ void CInArchive::Add_Color(UInt32 v)
Add_Color2(v);
}
#define MY__SW_HIDE 0
#define MY__SW_SHOWNORMAL 1
#define Z7_NSIS_WIN_SW_HIDE 0
#define Z7_NSIS_WIN_SW_SHOWNORMAL 1
#define MY__SW_SHOWMINIMIZED 2
#define MY__SW_SHOWMINNOACTIVE 7
#define MY__SW_SHOWNA 8
#define Z7_NSIS_WIN_SW_SHOWMINIMIZED 2
#define Z7_NSIS_WIN_SW_SHOWMINNOACTIVE 7
#define Z7_NSIS_WIN_SW_SHOWNA 8
static const char * const kShowWindow_Commands[] =
{
@@ -1846,7 +1854,7 @@ static const char * const kShowWindow_Commands[] =
static void Add_ShowWindow_Cmd_2(AString &s, UInt32 cmd)
{
if (cmd < ARRAY_SIZE(kShowWindow_Commands))
if (cmd < Z7_ARRAY_SIZE(kShowWindow_Commands))
{
s += "SW_";
s += kShowWindow_Commands[cmd];
@@ -1857,7 +1865,7 @@ static void Add_ShowWindow_Cmd_2(AString &s, UInt32 cmd)
void CInArchive::Add_ShowWindow_Cmd(UInt32 cmd)
{
if (cmd < ARRAY_SIZE(kShowWindow_Commands))
if (cmd < Z7_ARRAY_SIZE(kShowWindow_Commands))
{
Script += "SW_";
Script += kShowWindow_Commands[cmd];
@@ -1877,7 +1885,7 @@ void CInArchive::Add_TypeFromList(const char * const *table, unsigned tableSize,
}
}
#define ADD_TYPE_FROM_LIST(table, type) Add_TypeFromList(table, ARRAY_SIZE(table), type)
#define ADD_TYPE_FROM_LIST(table, type) Add_TypeFromList(table, Z7_ARRAY_SIZE(table), type)
enum
{
@@ -1894,7 +1902,7 @@ enum
k_ExecFlags_rtl,
k_ExecFlags_ErrorLevel,
k_ExecFlags_RegView,
k_ExecFlags_DetailsPrint = 13,
k_ExecFlags_DetailsPrint = 13
};
// Names for NSIS exec_flags_t structure vars
@@ -2097,7 +2105,7 @@ void CSection::Parse(const Byte *p)
StartCmdIndex = Get32(p + 12);
NumCommands = Get32(p + 16);
SizeKB = Get32(p + 20);
};
}
// used for section->flags
#define SF_SELECTED (1 << 0)
@@ -2182,7 +2190,7 @@ bool CInArchive::PrintSectionBegin(const CSection &sect, unsigned index)
{
TabString("SectionIn");
UInt32 instTypes = sect.InstallTypes;
for (int i = 0; i < 32; i++, instTypes >>= 1)
for (unsigned i = 0; i < 32; i++, instTypes >>= 1)
if ((instTypes & 1) != 0)
{
AddParam_UInt(i + 1);
@@ -2270,7 +2278,7 @@ void CInArchive::MessageBox_MB_Part(UInt32 param)
{
UInt32 v = param & 0xF;
Script += " MB_";
if (v < ARRAY_SIZE(k_MB_Buttons))
if (v < Z7_ARRAY_SIZE(k_MB_Buttons))
Script += k_MB_Buttons[v];
else
{
@@ -2283,7 +2291,7 @@ void CInArchive::MessageBox_MB_Part(UInt32 param)
if (icon != 0)
{
Script += "|MB_";
if (icon < ARRAY_SIZE(k_MB_Icons) && k_MB_Icons[icon] != 0)
if (icon < Z7_ARRAY_SIZE(k_MB_Icons) && k_MB_Icons[icon])
Script += k_MB_Icons[icon];
else
{
@@ -2308,7 +2316,7 @@ void CInArchive::MessageBox_MB_Part(UInt32 param)
else if (modal == 2) Script += "|MB_TASKMODAL";
else if (modal == 3) Script += "|0x3000";
UInt32 flags = (param >> 14);
for (unsigned i = 0; i < ARRAY_SIZE(k_MB_Flags); i++)
for (unsigned i = 0; i < Z7_ARRAY_SIZE(k_MB_Flags); i++)
if ((flags & (1 << i)) != 0)
{
Script += "|MB_";
@@ -2381,7 +2389,7 @@ AString CInArchive::GetFormatDescription() const
if (BadCmd >= 0)
{
AddString(s, "BadCmd=");
UIntToString(s, BadCmd);
UIntToString(s, (UInt32)BadCmd);
}
return s;
}
@@ -2455,7 +2463,7 @@ void CInArchive::FindBadCmd(const CBlockHeader &bh, const Byte *p)
for (UInt32 kkk = 0; kkk < bh.Num; kkk++, p += kCmdSize)
{
UInt32 id = GetCmd(Get32(p));
const UInt32 id = GetCmd(Get32(p));
if (id >= kNumCmds)
continue;
if (BadCmd >= 0 && id >= (unsigned)BadCmd)
@@ -2465,7 +2473,7 @@ void CInArchive::FindBadCmd(const CBlockHeader &bh, const Byte *p)
{
if (id == EW_RESERVEDOPCODE)
{
BadCmd = id;
BadCmd = (int)id;
continue;
}
}
@@ -2474,23 +2482,23 @@ void CInArchive::FindBadCmd(const CBlockHeader &bh, const Byte *p)
// if (id == EW_GETLABELADDR || id == EW_GETFUNCTIONADDR)
if (id == EW_RESERVEDOPCODE || id == EW_GETOSINFO)
{
BadCmd = id;
BadCmd = (int)id;
continue;
}
}
for (i = 6; i != 0; i--)
{
UInt32 param = Get32(p + i * 4);
const UInt32 param = Get32(p + i * 4);
if (param != 0)
break;
}
if (id == EW_FINDPROC && i == 0)
{
BadCmd = id;
BadCmd = (int)id;
continue;
}
if (k_Commands[id].NumParams < i)
BadCmd = id;
BadCmd = (int)id;
}
}
@@ -2770,13 +2778,13 @@ Int32 CInArchive::GetVarIndex(UInt32 strPos) const
else if (c != NS_CODE_VAR)
return -1;
unsigned c0 = p[1];
const unsigned c0 = p[1];
if (c0 == 0)
return -1;
unsigned c1 = p[2];
const unsigned c1 = p[2];
if (c1 == 0)
return -1;
return DECODE_NUMBER_FROM_2_CHARS(c0, c1);
return (Int32)DECODE_NUMBER_FROM_2_CHARS(c0, c1);
}
Int32 CInArchive::GetVarIndex(UInt32 strPos, UInt32 &resOffset) const
@@ -2870,18 +2878,18 @@ static bool IsAbsolutePath(const char *s)
void CInArchive::SetItemName(CItem &item, UInt32 strPos)
{
ReadString2_Raw(strPos);
bool isAbs = IsAbsolutePathVar(strPos);
const bool isAbs = IsAbsolutePathVar(strPos);
if (IsUnicode)
{
item.NameU = Raw_UString;
if (!isAbs && !IsAbsolutePath(Raw_UString))
item.Prefix = UPrefixes.Size() - 1;
item.Prefix = (int)UPrefixes.Size() - 1;
}
else
{
item.NameA = Raw_AString;
if (!isAbs && !IsAbsolutePath(Raw_AString))
item.Prefix = APrefixes.Size() - 1;
item.Prefix = (int)APrefixes.Size() - 1;
}
}
@@ -2949,9 +2957,9 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
for (int i = 0; i < 5; i++)
params[i] = Get32(p + 44 + 4 * i);
SET_FUNC_REF(preFunc, CMD_REF_Pre);
SET_FUNC_REF(showFunc, CMD_REF_Show);
SET_FUNC_REF(leaveFunc, CMD_REF_Leave);
SET_FUNC_REF(preFunc, CMD_REF_Pre)
SET_FUNC_REF(showFunc, CMD_REF_Show)
SET_FUNC_REF(leaveFunc, CMD_REF_Leave)
if (wndProcID == PWP_COMPLETED)
CommentOpen();
@@ -2969,7 +2977,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
else
s += IsInstaller ? "Page " : "UninstPage ";
if (wndProcID < ARRAY_SIZE(kPageTypes))
if (wndProcID < Z7_ARRAY_SIZE(kPageTypes))
s += kPageTypes[wndProcID];
else
Add_UInt(wndProcID);
@@ -3189,11 +3197,11 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
}
*/
if (IsFunc(flg)
&& bh.Num - kkk >= ARRAY_SIZE(k_InitPluginDir_Commands)
&& CompareCommands(p, k_InitPluginDir_Commands, ARRAY_SIZE(k_InitPluginDir_Commands)))
&& bh.Num - kkk >= Z7_ARRAY_SIZE(k_InitPluginDir_Commands)
&& CompareCommands(p, k_InitPluginDir_Commands, Z7_ARRAY_SIZE(k_InitPluginDir_Commands)))
{
InitPluginsDir_Start = kkk;
InitPluginsDir_End = (int)(kkk + ARRAY_SIZE(k_InitPluginDir_Commands));
InitPluginsDir_Start = (int)kkk;
InitPluginsDir_End = (int)(kkk + Z7_ARRAY_SIZE(k_InitPluginDir_Commands));
labels[kkk] |= CMD_REF_InitPluginDir;
break;
}
@@ -3356,7 +3364,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
unsigned numSkipParams = 0;
if (commandId < ARRAY_SIZE(k_Commands) && commandId < numSupportedCommands)
if (commandId < Z7_ARRAY_SIZE(k_Commands) && commandId < numSupportedCommands)
{
numSkipParams = k_Commands[commandId].NumParams;
const char *sz = k_CommandNames[commandId];
@@ -3505,9 +3513,9 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
UInt32 b1 = nsisMB >> 21; // NSIS 2.06+
UInt32 b2 = nsisMB >> 20; // NSIS old
Int32 asf = (Int32)nsisMB;
if (mb == (MY__MB_ABORTRETRYIGNORE | MY__MB_ICONSTOP) && (b1 == MY__IDIGNORE || b2 == MY__IDIGNORE))
if (mb == (Z7_NSIS_WIN_MB_ABORTRETRYIGNORE | Z7_NSIS_WIN_MB_ICONSTOP) && (b1 == Z7_NSIS_WIN_IDIGNORE || b2 == Z7_NSIS_WIN_IDIGNORE))
asf = -1;
else if (mb == (MY__MB_RETRYCANCEL | MY__MB_ICONSTOP) && (b1 == MY__IDCANCEL || b2 == MY__IDCANCEL))
else if (mb == (Z7_NSIS_WIN_MB_RETRYCANCEL | Z7_NSIS_WIN_MB_ICONSTOP) && (b1 == Z7_NSIS_WIN_IDCANCEL || b2 == Z7_NSIS_WIN_IDCANCEL))
asf = -2;
else
{
@@ -3591,7 +3599,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
#ifdef NSIS_SCRIPT
AddParam(params[0]);
Space();
FlagsToString2(s, g_WinAttrib, ARRAY_SIZE(g_WinAttrib), params[1]);
FlagsToString2(s, g_WinAttrib, Z7_ARRAY_SIZE(g_WinAttrib), params[1]);
#endif
break;
}
@@ -3603,7 +3611,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
NSIS installer uses alternative path, if main path
from params[0] is not absolute path */
bool pathOk = (params[0] > 0) && IsGoodString(params[0]);
const bool pathOk = (params[0] > 0) && IsGoodString(params[0]);
if (!pathOk)
{
@@ -3613,9 +3621,11 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
break;
}
#ifdef NSIS_SCRIPT
bool altPathOk = true;
UInt32 altParam = params[3];
const UInt32 altParam = params[3];
if (altParam != 0)
{
altPathOk = false;
@@ -3624,9 +3634,6 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
altPathOk = AreTwoParamStringsEqual(altParam + additional, params[0]);
}
#ifdef NSIS_SCRIPT
AddParam(params[0]);
/*
@@ -3640,8 +3647,6 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
AddParam(params[3]);
}
#endif
if (!altPathOk)
{
#ifdef NSIS_SCRIPT
@@ -3649,9 +3654,11 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
#endif
}
#endif
if (BadCmd >= 0 && BadCmd <= EW_WRITEUNINSTALLER)
{
/* We don't cases with incorrect installer commands.
/* We don't support cases with incorrect installer commands.
Such bad installer item can break unpacking for other items. */
#ifdef NSIS_SCRIPT
AddError("SKIP possible BadCmd");
@@ -3659,13 +3666,23 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
break;
}
CItem &item = Items.AddNew();;
CItem &item = Items.AddNew();
SetItemName(item, params[0]);
item.Pos = params[1];
item.PatchSize = params[2];
item.IsUninstaller = true;
const UInt32 param3 = params[3];
if (param3 != 0 && item.Prefix != -1)
{
/* (item.Prefix != -1) case means that param[0] path was not absolute.
So we use params[3] in that case, as original nsis */
SetItemName(item, param3);
}
/* UNINSTALLER file doesn't use directory prefixes.
So we remove prefix: */
item.Prefix = -1;
/*
// we can add second time to test the code
@@ -3834,12 +3851,12 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
s += "Call ";
if ((Int32)params[0] < 0)
Add_Var(-((Int32)params[0] + 1));
Add_Var((UInt32)-((Int32)params[0] + 1));
else if (params[0] == 0)
s += '0';
else
{
UInt32 val = params[0] - 1;
const UInt32 val = params[0] - 1;
if (params[1] == 1) // it's Call :Label
{
s += ':';
@@ -3860,8 +3877,8 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
case EW_CHDETAILSVIEW:
{
if (params[0] == MY__SW_SHOWNA && params[1] == MY__SW_HIDE) s += " show";
else if (params[1] == MY__SW_SHOWNA && params[0] == MY__SW_HIDE) s += " hide";
if (params[0] == Z7_NSIS_WIN_SW_SHOWNA && params[1] == Z7_NSIS_WIN_SW_HIDE) s += " show";
else if (params[1] == Z7_NSIS_WIN_SW_SHOWNA && params[0] == Z7_NSIS_WIN_SW_HIDE) s += " hide";
else
for (int i = 0; i < 2; i++)
{
@@ -3935,7 +3952,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
Add_ExecFlags(params[2]);
Add_GotoVars2(&params[0]);
/*
static const unsigned kIfErrors = 2;
const unsigned kIfErrors = 2;
if (params[2] != kIfErrors && params[3] != 0xFFFFFFFF ||
params[2] == kIfErrors && params[3] != 0)
{
@@ -4244,7 +4261,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
AString bk;
bool bkc = false;
if (colors.bkmode == MY__TRANSPARENT)
if (colors.bkmode == Z7_NSIS_WIN_TRANSPARENT)
bk += " transparent";
else if (colors.flags & kColorsFlags_BKB)
{
@@ -4305,7 +4322,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
bool valDefined = false;
if (StringToUInt32(sw, val))
{
if (val < ARRAY_SIZE(kShowWindow_Commands))
if (val < Z7_ARRAY_SIZE(kShowWindow_Commands))
{
sw.Empty();
sw += "${";
@@ -4338,10 +4355,10 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
case EW_SHELLEXEC:
{
AddParams(params, 2);
if (params[2] != 0 || params[3] != MY__SW_SHOWNORMAL)
if (params[2] != 0 || params[3] != Z7_NSIS_WIN_SW_SHOWNORMAL)
{
AddParam(params[2]);
if (params[3] != MY__SW_SHOWNORMAL)
if (params[3] != Z7_NSIS_WIN_SW_SHOWNORMAL)
{
Space();
Add_ShowWindow_Cmd(params[3]);
@@ -4442,8 +4459,8 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
UInt32 sw = (spec >> sw_shift) & sw_mask;
Space();
// NSIS encoder replaces these names:
if (sw == MY__SW_SHOWMINNOACTIVE)
sw = MY__SW_SHOWMINIMIZED;
if (sw == Z7_NSIS_WIN_SW_SHOWMINNOACTIVE)
sw = Z7_NSIS_WIN_SW_SHOWMINIMIZED;
if (sw == 0)
AddQuotes();
else
@@ -4467,7 +4484,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
if (modKey & 4) s += "ALT|";
if (modKey & 8) s += "EXT|";
static const unsigned kMy_VK_F1 = 0x70;
const unsigned kMy_VK_F1 = 0x70;
if (key >= kMy_VK_F1 && key <= kMy_VK_F1 + 23)
{
s += 'F';
@@ -4559,7 +4576,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
case EW_WRITEREG:
{
const char *s2 = 0;
const char *s2 = NULL;
switch (params[4])
{
case 1: s2 = "Str"; break;
@@ -4642,20 +4659,42 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
break;
}
#endif
case EW_FOPEN:
{
/*
the pattern for empty files is following:
FileOpen $0 "file_name" w
FileClose $0
*/
const UInt32 acc = params[1]; // dwDesiredAccess
const UInt32 creat = params[2]; // dwCreationDisposition
if (creat == Z7_NSIS_WIN_CREATE_ALWAYS && acc == Z7_NSIS_WIN_GENERIC_WRITE)
{
if (kkk + 1 < bh.Num)
if (Get32(p + kCmdSize) == EW_FCLOSE)
if (Get32(p + kCmdSize + 4) == params[0])
{
CItem &item = Items.AddNew();
item.IsEmptyFile = true;
SetItemName(item, params[3]);
}
}
#ifdef NSIS_SCRIPT
AddParam_Var(params[0]);
AddParam(params[3]);
UInt32 acc = params[1]; // dwDesiredAccess
UInt32 creat = params[2]; // dwCreationDisposition
if (acc == 0 && creat == 0)
break;
char cc = 0;
if (acc == MY__GENERIC_READ && creat == OPEN_EXISTING)
if (creat == Z7_NSIS_WIN_OPEN_EXISTING && acc == Z7_NSIS_WIN_GENERIC_READ)
cc = 'r';
else if (creat == CREATE_ALWAYS && acc == MY__GENERIC_WRITE)
else if (creat == Z7_NSIS_WIN_CREATE_ALWAYS && acc == Z7_NSIS_WIN_GENERIC_WRITE)
cc = 'w';
else if (creat == OPEN_ALWAYS && (acc == (MY__GENERIC_WRITE | MY__GENERIC_READ)))
else if (creat == Z7_NSIS_WIN_OPEN_ALWAYS && (acc == (Z7_NSIS_WIN_GENERIC_WRITE | Z7_NSIS_WIN_GENERIC_READ)))
cc = 'a';
// cc = 0;
if (cc != 0)
@@ -4665,28 +4704,32 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
break;
}
if (acc & MY__GENERIC_READ) s += " GENERIC_READ";
if (acc & MY__GENERIC_WRITE) s += " GENERIC_WRITE";
if (acc & MY__GENERIC_EXECUTE) s += " GENERIC_EXECUTE";
if (acc & MY__GENERIC_ALL) s += " GENERIC_ALL";
if (acc & Z7_NSIS_WIN_GENERIC_READ) s += " GENERIC_READ";
if (acc & Z7_NSIS_WIN_GENERIC_WRITE) s += " GENERIC_WRITE";
if (acc & Z7_NSIS_WIN_GENERIC_EXECUTE) s += " GENERIC_EXECUTE";
if (acc & Z7_NSIS_WIN_GENERIC_ALL) s += " GENERIC_ALL";
const char *s2 = NULL;
switch (creat)
{
case MY__CREATE_NEW: s2 = "CREATE_NEW"; break;
case MY__CREATE_ALWAYS: s2 = "CREATE_ALWAYS"; break;
case MY__OPEN_EXISTING: s2 = "OPEN_EXISTING"; break;
case MY__OPEN_ALWAYS: s2 = "OPEN_ALWAYS"; break;
case MY__TRUNCATE_EXISTING: s2 = "TRUNCATE_EXISTING"; break;
case Z7_NSIS_WIN_CREATE_NEW: s2 = "CREATE_NEW"; break;
case Z7_NSIS_WIN_CREATE_ALWAYS: s2 = "CREATE_ALWAYS"; break;
case Z7_NSIS_WIN_OPEN_EXISTING: s2 = "OPEN_EXISTING"; break;
case Z7_NSIS_WIN_OPEN_ALWAYS: s2 = "OPEN_ALWAYS"; break;
case Z7_NSIS_WIN_TRUNCATE_EXISTING: s2 = "TRUNCATE_EXISTING"; break;
}
Space();
if (s2)
s += s2;
else
Add_UInt(creat);
#endif
break;
}
#ifdef NSIS_SCRIPT
case EW_FPUTS:
case EW_FPUTWS:
{
@@ -4780,7 +4823,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
else
{
s += "Set";
UInt32 t = -(Int32)params[2] - 1;
const UInt32 t = (UInt32)(-(Int32)params[2] - 1);
Add_SectOp(t);
AddParam(params[0]);
AddParam(params[t == 0 ? 4 : 1]);
@@ -4793,7 +4836,7 @@ HRESULT CInArchive::ReadEntries(const CBlockHeader &bh)
case EW_INSTTYPESET:
{
int numQwParams = 0;
unsigned numQwParams = 0;
const char *s2;
if (params[3] == 0)
{
@@ -4952,7 +4995,18 @@ static int CompareItems(void *const *p1, void *const *p2, void *param)
{
const CItem &i1 = **(const CItem *const *)p1;
const CItem &i2 = **(const CItem *const *)p2;
RINOZ(MyCompare(i1.Pos, i2.Pos));
RINOZ(MyCompare(i1.Pos, i2.Pos))
/* In another code we check CItem::Pos after each solid item.
So here we place empty files before all non empty files */
if (i1.IsEmptyFile)
{
if (!i2.IsEmptyFile)
return -1;
}
else if (i2.IsEmptyFile)
return 1;
const CInArchive *inArchive = (const CInArchive *)param;
if (inArchive->IsUnicode)
{
@@ -4962,9 +5016,9 @@ static int CompareItems(void *const *p1, void *const *p2, void *param)
if (i2.Prefix < 0) return 1;
RINOZ(
inArchive->UPrefixes[i1.Prefix].Compare(
inArchive->UPrefixes[i2.Prefix]));
inArchive->UPrefixes[i2.Prefix]))
}
RINOZ(i1.NameU.Compare(i2.NameU));
RINOZ(i1.NameU.Compare(i2.NameU))
}
else
{
@@ -4974,9 +5028,9 @@ static int CompareItems(void *const *p1, void *const *p2, void *param)
if (i2.Prefix < 0) return 1;
RINOZ(strcmp(
inArchive->APrefixes[i1.Prefix],
inArchive->APrefixes[i2.Prefix]));
inArchive->APrefixes[i2.Prefix]))
}
RINOZ(strcmp(i1.NameA, i2.NameA));
RINOZ(strcmp(i1.NameA, i2.NameA))
}
return 0;
}
@@ -4990,6 +5044,8 @@ HRESULT CInArchive::SortItems()
for (i = 0; i + 1 < Items.Size(); i++)
{
const CItem &i1 = Items[i];
if (i1.IsEmptyFile)
continue;
const CItem &i2 = Items[i + 1];
if (i1.Pos != i2.Pos)
continue;
@@ -5019,10 +5075,14 @@ HRESULT CInArchive::SortItems()
for (i = 0; i < Items.Size(); i++)
{
CItem &item = Items[i];
UInt32 curPos = item.Pos + 4;
if (item.IsEmptyFile)
continue;
const UInt32 curPos = item.Pos + 4;
for (unsigned nextIndex = i + 1; nextIndex < Items.Size(); nextIndex++)
{
UInt32 nextPos = Items[nextIndex].Pos;
const CItem &nextItem = Items[nextIndex];
// if (nextItem.IsEmptyFile) continue;
const UInt32 nextPos = nextItem.Pos;
if (curPos <= nextPos)
{
item.EstimatedSize_Defined = true;
@@ -5037,11 +5097,13 @@ HRESULT CInArchive::SortItems()
for (i = 0; i < Items.Size(); i++)
{
CItem &item = Items[i];
RINOK(SeekToNonSolidItem(i));
if (item.IsEmptyFile)
continue;
RINOK(SeekToNonSolidItem(i))
const UInt32 kSigSize = 4 + 1 + 1 + 4; // size,[flag],prop,dict
BYTE sig[kSigSize];
size_t processedSize = kSigSize;
RINOK(ReadStream(_stream, sig, &processedSize));
RINOK(ReadStream(_stream, sig, &processedSize))
if (processedSize < 4)
return S_FALSE;
UInt32 size = Get32(sig);
@@ -5218,7 +5280,7 @@ HRESULT CInArchive::Parse()
if (Method != NMethodType::kCopy)
{
const char *m = NULL;
switch (Method)
switch ((int)Method)
{
case NMethodType::kDeflate: m = "zlib"; break;
case NMethodType::kBZip2: m = "bzip2"; break;
@@ -5451,7 +5513,7 @@ HRESULT CInArchive::Parse()
if (val != 0)
{
Script += "LicenseLangString ";
Add_LangStr_Simple(licenseLangIndex);
Add_LangStr_Simple((UInt32)licenseLangIndex);
AddParam_UInt(langID);
AddLicense(val, langID);
noParseStringIndexes.AddToUniqueSorted(val);
@@ -5470,7 +5532,7 @@ HRESULT CInArchive::Parse()
const UInt16 langID = Get16(p);
if (i == 0 || langID == 1033)
_mainLang = p + 10;
for (unsigned k = 0; k < ARRAY_SIZE(names) && k < numStrings; k++)
for (unsigned k = 0; k < Z7_ARRAY_SIZE(names) && k < numStrings; k++)
{
UInt32 v = Get32(p + 10 + k * 4);
if (v != 0 && (langID == 1033 || names[k] == 0))
@@ -5567,7 +5629,7 @@ HRESULT CInArchive::Parse()
}
onFuncOffset = paramsOffset + 40;
numOnFunc = ARRAY_SIZE(kOnFunc);
numOnFunc = Z7_ARRAY_SIZE(kOnFunc);
if (bhPages.Offset == 276)
numOnFunc--;
p2 += 40 + numOnFunc * 4;
@@ -5629,7 +5691,7 @@ HRESULT CInArchive::Parse()
#endif
RINOK(ReadEntries(bhEntries));
RINOK(ReadEntries(bhEntries))
#ifdef NSIS_SCRIPT
@@ -5747,14 +5809,14 @@ HRESULT CInArchive::Open2(const Byte *sig, size_t size)
if (IsSolid)
{
RINOK(SeekTo_DataStreamOffset());
RINOK(SeekTo_DataStreamOffset())
}
else
{
_headerIsCompressed = ((compressedHeaderSize & kMask_IsCompressed) != 0);
compressedHeaderSize &= ~kMask_IsCompressed;
_nonSolidStartOffset = compressedHeaderSize;
RINOK(SeekTo(DataStreamOffset + 4));
RINOK(SeekTo(DataStreamOffset + 4))
}
if (FirstHeader.HeaderSize == 0)
@@ -5775,12 +5837,12 @@ HRESULT CInArchive::Open2(const Byte *sig, size_t size)
if (_headerIsCompressed)
{
RINOK(Decoder.Init(_stream, UseFilter));
RINOK(Decoder.Init(_stream, UseFilter))
if (IsSolid)
{
size_t processedSize = 4;
Byte buf[4];
RINOK(Decoder.Read(buf, &processedSize));
RINOK(Decoder.Read(buf, &processedSize))
if (processedSize != 4)
return S_FALSE;
if (Get32((const Byte *)buf) != FirstHeader.HeaderSize)
@@ -5788,7 +5850,7 @@ HRESULT CInArchive::Open2(const Byte *sig, size_t size)
}
{
size_t processedSize = FirstHeader.HeaderSize;
RINOK(Decoder.Read(_data, &processedSize));
RINOK(Decoder.Read(_data, &processedSize))
if (processedSize != FirstHeader.HeaderSize)
return S_FALSE;
}
@@ -5800,7 +5862,7 @@ HRESULT CInArchive::Open2(const Byte *sig, size_t size)
AfterHeaderSize = (1 << 12);
_afterHeader.Alloc(AfterHeaderSize);
size_t processedSize = AfterHeaderSize;
RINOK(Decoder.Read(_afterHeader, &processedSize));
RINOK(Decoder.Read(_afterHeader, &processedSize))
AfterHeaderSize = (UInt32)processedSize;
}
#endif
@@ -5808,7 +5870,7 @@ HRESULT CInArchive::Open2(const Byte *sig, size_t size)
else
{
size_t processedSize = FirstHeader.HeaderSize;
RINOK(ReadStream(_stream, (Byte *)_data, &processedSize));
RINOK(ReadStream(_stream, (Byte *)_data, &processedSize))
if (processedSize < FirstHeader.HeaderSize)
return S_FALSE;
}
@@ -5892,7 +5954,7 @@ HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *maxCheckStartPositio
{
Clear();
RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &StartOffset));
RINOK(InStream_GetPos(inStream, StartOffset))
const UInt32 kStartHeaderSize = 4 * 7;
const unsigned kStep = 512; // nsis start is aligned for 512
@@ -5904,7 +5966,7 @@ HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *maxCheckStartPositio
for (;;)
{
bufSize = kStep;
RINOK(ReadStream(inStream, buf, &bufSize));
RINOK(ReadStream(inStream, buf, &bufSize))
if (bufSize < kStartHeaderSize)
return S_FALSE;
if (memcmp(buf + 4, kSignature, kSignatureSize) == 0)
@@ -5936,8 +5998,8 @@ HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *maxCheckStartPositio
if (pos - posCur > (1 << 20))
break;
bufSize = kStep;
RINOK(inStream->Seek(posCur, STREAM_SEEK_SET, NULL));
RINOK(ReadStream(inStream, buf, &bufSize));
RINOK(InStream_SeekSet(inStream, posCur))
RINOK(ReadStream(inStream, buf, &bufSize))
if (bufSize < kStep)
break;
if (IsArc_Pe(buf, bufSize))
@@ -5949,8 +6011,8 @@ HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *maxCheckStartPositio
// restore buf to nsis header
bufSize = kStep;
RINOK(inStream->Seek(pos, STREAM_SEEK_SET, NULL));
RINOK(ReadStream(inStream, buf, &bufSize));
RINOK(InStream_SeekSet(inStream, pos))
RINOK(ReadStream(inStream, buf, &bufSize))
if (bufSize < kStartHeaderSize)
return S_FALSE;
}
@@ -5990,15 +6052,15 @@ HRESULT CInArchive::Open(IInStream *inStream, const UInt64 *maxCheckStartPositio
}
*/
RINOK(inStream->Seek(0, STREAM_SEEK_END, &_fileSize));
RINOK(InStream_GetSize_SeekToEnd(inStream, _fileSize))
IsArc = true;
if (peSize != 0)
{
ExeStub.Alloc(peSize);
RINOK(inStream->Seek(pePos, STREAM_SEEK_SET, NULL));
RINOK(ReadStream_FALSE(inStream, ExeStub, peSize));
RINOK(InStream_SeekSet(inStream, pePos))
RINOK(ReadStream_FALSE(inStream, ExeStub, peSize))
}
HRESULT res = S_FALSE;

View File

@@ -1,7 +1,7 @@
// NsisIn.h
#ifndef __ARCHIVE_NSIS_IN_H
#define __ARCHIVE_NSIS_IN_H
#ifndef ZIP7_INC_ARCHIVE_NSIS_IN_H
#define ZIP7_INC_ARCHIVE_NSIS_IN_H
#include "../../../../C/CpuArch.h"
@@ -11,6 +11,8 @@
#include "../../../Common/StringConvert.h"
#include "../../../Common/UTFConvert.h"
#include "../../Common/StreamUtils.h"
#include "NsisDecode.h"
/* If NSIS_SCRIPT is defined, it will decompile NSIS script to [NSIS].nsi file.
@@ -68,6 +70,7 @@ struct CBlockHeader
struct CItem
{
bool IsEmptyFile;
bool IsCompressed;
bool Size_Defined;
bool CompressedSize_Defined;
@@ -77,7 +80,7 @@ struct CItem
// bool UseFilter;
UInt32 Attrib;
UInt32 Pos;
UInt32 Pos; // = 0, if (IsEmptyFile == true)
UInt32 Size;
UInt32 CompressedSize;
UInt32 EstimatedSize;
@@ -89,7 +92,10 @@ struct CItem
AString NameA;
UString NameU;
bool Is_PatchedUninstaller() const { return PatchSize != 0; }
CItem():
IsEmptyFile(false),
IsCompressed(true),
Size_Defined(false),
CompressedSize_Defined(false),
@@ -354,7 +360,7 @@ public:
HRESULT SeekTo(UInt64 pos)
{
return _stream->Seek(pos, STREAM_SEEK_SET, NULL);
return InStream_SeekSet(_stream, pos);
}
HRESULT SeekTo_DataStreamOffset()
@@ -433,7 +439,7 @@ public:
if (s[0] == L'\\')
s.DeleteFrontal(1);
}
if (item.IsUninstaller && ExeStub.Size() == 0)
if (item.Is_PatchedUninstaller() && ExeStub.Size() == 0)
s += ".nsis";
return s;
}

View File

@@ -10,7 +10,7 @@ namespace NArchive {
namespace NNsis {
REGISTER_ARC_I(
"Nsis", "nsis", 0, 0x9,
"Nsis", "nsis", NULL, 0x9,
kSignature,
4,
NArcInfoFlags::kFindSignature |

View File

@@ -1,8 +1,11 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#ifndef ZIP7_INC_STDAFX_H
#define ZIP7_INC_STDAFX_H
#if defined(_MSC_VER) && _MSC_VER >= 1800
#pragma warning(disable : 4464) // relative include path contains '..'
#endif
#include "../../../Common/Common.h"
#endif