This commit is contained in:
Igor Pavlov
2009-02-03 00:00:00 +00:00
committed by Kornel Lesiński
parent 1dc92281fa
commit 8874e4fbc9
34 changed files with 216 additions and 148 deletions

View File

@@ -586,7 +586,7 @@ HRESULT COutHandler::SetProperty(const wchar_t *nameSpec, const PROPVARIANT &val
if (number <= mainDicMethodIndex)
mainDicSize = dicSize;
}
else if (realName.Left(1).CompareNoCase(L"B") == 0)
else if (realName.Left(1).CompareNoCase(L"C") == 0)
{
UInt32 blockSize;
RINOK(ParsePropDictionaryValue(realName.Mid(1), value, blockSize));

View File

@@ -198,7 +198,7 @@ HRESULT CInArchive::GetNextItem(bool &filled, CItemEx &item)
RINOK(GetNextItemReal(filled, item));
if (!filled)
return S_OK;
if (item.Name.CompareNoCase("debian-binary") != 0)
if (item.Name.Compare("debian-binary") != 0)
return S_OK;
if (item.Size != 4)
return S_OK;

View File

@@ -308,11 +308,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
static AString GetName(const char *name)
{
AString res;
char *p = res.GetBuffer(kNameSize);
strncpy(p, name, kNameSize);
p[kNameSize] = 0;
res.ReleaseBuffer();
char res[kNameSize + 1];
memcpy(res, name, kNameSize);
res[kNameSize] = 0;
return res;
}

View File

@@ -2,19 +2,19 @@
#include "StdAfx.h"
#include "NsisHandler.h"
#include "../../../../C/CpuArch.h"
#include "Common/StringConvert.h"
#include "Common/ComTry.h"
#include "Common/IntToString.h"
#include "Common/NewHandler.h"
#include "Common/ComTry.h"
#include "Windows/PropVariant.h"
#include "../Common/ItemNameUtils.h"
#include "../../Common/StreamUtils.h"
#include "../../../../C/CpuArch.h"
#include "../Common/ItemNameUtils.h"
#include "NsisHandler.h"
#define Get32(p) GetUi32(p)
@@ -228,12 +228,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
{
case kpidPath:
{
UString s;
if (_archive.IsUnicode)
s = item.GetReducedNameU();
else
s = MultiByteToUnicodeString(item.GetReducedNameA(), CP_ACP);
s = NItemName::WinNameToOSName(s);
UString s = NItemName::WinNameToOSName(item.GetReducedName(_archive.IsUnicode));
if (!s.IsEmpty())
prop = (const wchar_t *)s;
break;
@@ -320,6 +315,11 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
_inStream, _archive.Method, _archive.FilterFlag, useFilter));
}
CByteBuffer byteBuf;
const UInt32 kBufferLength = 1 << 16;
byteBuf.SetCapacity(kBufferLength);
Byte *buffer = byteBuf;
bool dataError = false;
for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
{
@@ -363,9 +363,6 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
bool sizeIsKnown = false;
UInt32 fullSize = 0;
const UInt32 kBufferLength = 1 << 11;
Byte buffer[kBufferLength];
if (_archive.IsSolid)
{
UInt64 pos = _archive.GetPosOfSolidItem(index);
@@ -389,12 +386,13 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
}
if (streamPos == pos)
{
Byte buffer2[4];
size_t processedSize = 4;
RINOK(_archive.Decoder.Read(buffer, &processedSize));
RINOK(_archive.Decoder.Read(buffer2, &processedSize));
if (processedSize != 4)
return E_FAIL;
streamPos += processedSize;
fullSize = Get32(buffer);
fullSize = Get32(buffer2);
sizeIsKnown = true;
needDecompress = true;
}
@@ -409,7 +407,9 @@ STDMETHODIMP CHandler::Extract(const UInt32* indices, UInt32 numItems,
RINOK(_archive.Decoder.Init(
EXTERNAL_CODECS_VARS
_inStream, _archive.Method, _archive.FilterFlag, useFilter));
fullSize = Get32(buffer);
// fullSize = Get32(buffer); // It's bug !!!
// Test it: what is exact fullSize?
fullSize = 0xFFFFFFFF;
}
else
fullSize = item.Size;

View File

@@ -3,16 +3,17 @@
#ifndef __ARCHIVE_NSIS_IN_H
#define __ARCHIVE_NSIS_IN_H
#include "Common/MyCom.h"
#include "Common/IntToString.h"
#include "Common/Buffer.h"
#include "Common/IntToString.h"
#include "Common/MyCom.h"
#include "Common/StringConvert.h"
#include "../../Common/CreateCoder.h"
#include "../../IStream.h"
#include "NsisDecode.h"
#include "../../Common/CreateCoder.h"
// #define NSIS_SCRIPT
namespace NArchive {
@@ -81,32 +82,25 @@ struct CItem
return (PrefixA.Length() >= 3 || PrefixU.Length() >= 3);
}
AString GetReducedNameA() const
UString GetReducedName(bool unicode) const
{
AString prefix = PrefixA;
if (prefix.Length() > 0)
if (prefix[prefix.Length() - 1] != '\\')
prefix += '\\';
AString s2 = prefix + NameA;
UString s;
if (unicode)
s = PrefixU;
else
s = MultiByteToUnicodeString(PrefixA);
if (s.Length() > 0)
if (s[s.Length() - 1] != L'\\')
s += L'\\';
if (unicode)
s += NameU;
else
s += MultiByteToUnicodeString(NameA);
const int len = 9;
if (s2.Left(len).CompareNoCase("$INSTDIR\\") == 0)
s2 = s2.Mid(len);
return s2;
if (s.Left(len).CompareNoCase(L"$INSTDIR\\") == 0)
s = s.Mid(len);
return s;
}
UString GetReducedNameU() const
{
UString prefix = PrefixU;
if (prefix.Length() > 0)
if (prefix[prefix.Length() - 1] != L'\\')
prefix += L'\\';
UString s2 = prefix + NameU;
const int len = 9;
if (s2.Left(len).CompareNoCase(L"$INSTDIR\\") == 0)
s2 = s2.Mid(len);
return s2;
}
};
class CInArchive

View File

@@ -55,6 +55,7 @@ private:
UInt32 m_NumMatchFinderCycles;
bool m_NumMatchFinderCyclesDefined;
bool m_ForceAesMode;
bool m_IsAesMode;
Byte m_AesKeyMode;
@@ -78,6 +79,7 @@ private:
m_NumFastBytes =
m_NumMatchFinderCycles = 0xFFFFFFFF;
m_NumMatchFinderCyclesDefined = false;
m_ForceAesMode = false;
m_IsAesMode = false;
m_AesKeyMode = 3; // aes-256
m_WriteNtfsTimeExtra = false;

View File

@@ -98,6 +98,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
{
COM_TRY_BEGIN2
CObjectVector<CUpdateItem> updateItems;
bool thereAreAesUpdates = false;
for (UInt32 i = 0; i < numItems; i++)
{
CUpdateItem ui;
@@ -111,7 +112,11 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
ui.NewData = IntToBool(newData);
ui.IndexInArchive = indexInArchive;
ui.IndexInClient = i;
// bool existInArchive = (indexInArchive != UInt32(-1));
bool existInArchive = (indexInArchive != UInt32(-1));
if (existInArchive && newData)
if (m_Items[indexInArchive].IsAesEncrypted())
thereAreAesUpdates = true;
if (IntToBool(newProperties))
{
UString name;
@@ -237,7 +242,6 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
}
CMyComPtr<ICryptoGetTextPassword2> getTextPassword;
if (!getTextPassword)
{
CMyComPtr<IArchiveUpdateCallback> udateCallBack2(callback);
udateCallBack2.QueryInterface(IID_ICryptoGetTextPassword2, &getTextPassword);
@@ -252,16 +256,17 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
options.PasswordIsDefined = IntToBool(passwordIsDefined);
if (options.PasswordIsDefined)
{
options.IsAesMode = (m_ForceAesMode ? m_IsAesMode : thereAreAesUpdates);
options.AesKeyMode = m_AesKeyMode;
if (!IsAsciiString((const wchar_t *)password))
return E_INVALIDARG;
if (m_IsAesMode)
if (options.IsAesMode)
{
if (options.Password.Length() > NCrypto::NWzAes::kPasswordSizeMax)
return E_INVALIDARG;
}
options.Password = UnicodeStringToMultiByte((const wchar_t *)password, CP_OEMCP);
options.IsAesMode = m_IsAesMode;
options.AesKeyMode = m_AesKeyMode;
}
}
else
@@ -422,9 +427,13 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t **names, const PROPVARIANT *v
else
return E_INVALIDARG;
m_IsAesMode = true;
m_ForceAesMode = true;
}
else if (valueString == L"ZIPCRYPTO")
{
m_IsAesMode = false;
m_ForceAesMode = true;
}
else
return E_INVALIDARG;
}

View File

@@ -187,6 +187,7 @@ public:
bool IsEncrypted() const { return (Flags & NFileHeader::NFlags::kEncrypted) != 0; }
bool IsStrongEncrypted() const { return IsEncrypted() && (Flags & NFileHeader::NFlags::kStrongEncrypted) != 0; };
bool IsAesEncrypted() const { return IsEncrypted() && (IsStrongEncrypted() || CompressionMethod == NFileHeader::NCompressionMethod::kWzAES); };
bool IsLzmaEOS() const { return (Flags & NFileHeader::NFlags::kLzmaEOS) != 0; }