mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-10 20:07:05 -06:00
4.27 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
31e7b924e8
commit
d66cf2fcf3
@@ -43,7 +43,7 @@ RSC=rc.exe
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CAB_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CAB_EXPORTS" /Yu"StdAfx.h" /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CAB_EXPORTS" /FAs /Yu"StdAfx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
@@ -70,7 +70,7 @@ LINK32=link.exe
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CAB_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CAB_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CAB_EXPORTS" /FAcs /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
@@ -190,11 +190,11 @@ SOURCE=..\..\..\Windows\PropVariant.h
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CabCopyDecoder.cpp
|
||||
SOURCE=.\CabBlockInStream.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CabCopyDecoder.h
|
||||
SOURCE=.\CabBlockInStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@@ -222,60 +222,8 @@ SOURCE=.\CabIn.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CabInBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CabInBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CabItem.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZXBitDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZXConst.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZXDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZXDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZXExtConst.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZXi86Converter.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZXi86Converter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MSZipConst.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MSZipDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MSZipDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MSZipExtConst.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "7zip Common"
|
||||
|
||||
@@ -298,6 +246,10 @@ SOURCE=..\..\Common\LSBFDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\MSBFDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\OutBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -306,11 +258,11 @@ SOURCE=..\..\Common\OutBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\ProgressUtils.cpp
|
||||
SOURCE=..\..\Common\StreamUtils.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\ProgressUtils.h
|
||||
SOURCE=..\..\Common\StreamUtils.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Compress"
|
||||
@@ -328,6 +280,112 @@ SOURCE=..\..\Compress\LZ\LZOutWindow.cpp
|
||||
SOURCE=..\..\Compress\LZ\LZOutWindow.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Lzx"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Lzx\Lzx.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Lzx\Lzx86Converter.cpp
|
||||
|
||||
!IF "$(CFG)" == "Cab - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Cab - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Lzx\Lzx86Converter.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Lzx\LzxDecoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "Cab - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Cab - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Lzx\LzxDecoder.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Deflate"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Deflate\DeflateConst.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Deflate\DeflateDecoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "Cab - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "Cab - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Deflate\DeflateDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Deflate\DeflateExtConst.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Copy"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Copy\CopyCoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Copy\CopyCoder.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Quantum"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Quantum\QuantumDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Quantum\QuantumDecoder.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Huffman"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Compress\Huffman\HuffmanDecoder.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
|
||||
194
7zip/Archive/Cab/CabBlockInStream.cpp
Executable file
194
7zip/Archive/Cab/CabBlockInStream.cpp
Executable file
@@ -0,0 +1,194 @@
|
||||
// CabBlockInStream.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/Alloc.h"
|
||||
#include "Common/Defs.h"
|
||||
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
#include "CabBlockInStream.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
|
||||
static const UInt32 kBlockSize = (1 << 16);
|
||||
|
||||
bool CCabBlockInStream::Create()
|
||||
{
|
||||
if (!_buffer)
|
||||
_buffer = (Byte *)::MyAlloc(kBlockSize);
|
||||
return (_buffer != 0);
|
||||
}
|
||||
|
||||
CCabBlockInStream::~CCabBlockInStream()
|
||||
{
|
||||
MyFree(_buffer);
|
||||
}
|
||||
|
||||
class CCheckSum2
|
||||
{
|
||||
UInt32 m_Value;
|
||||
int m_Pos;
|
||||
Byte m_Hist[4];
|
||||
public:
|
||||
CCheckSum2(): m_Value(0){};
|
||||
void Init() { m_Value = 0; m_Pos = 0; }
|
||||
void Update(const void *data, UInt32 size);
|
||||
void FinishDataUpdate()
|
||||
{
|
||||
for (int i = 0; i < m_Pos; i++)
|
||||
m_Value ^= ((UInt32)(m_Hist[i])) << (8 * (m_Pos - i - 1));
|
||||
}
|
||||
void UpdateUInt32(UInt32 v) { m_Value ^= v; }
|
||||
UInt32 GetResult() const { return m_Value; }
|
||||
};
|
||||
|
||||
void CCheckSum2::Update(const void *data, UInt32 size)
|
||||
{
|
||||
UInt32 checkSum = m_Value;
|
||||
const Byte *dataPointer = (const Byte *)data;
|
||||
|
||||
while (size != 0 && m_Pos != 0)
|
||||
{
|
||||
m_Hist[m_Pos] = *dataPointer++;
|
||||
m_Pos = (m_Pos + 1) & 3;
|
||||
size--;
|
||||
if (m_Pos == 0)
|
||||
for (int i = 0; i < 4; i++)
|
||||
checkSum ^= ((UInt32)m_Hist[i]) << (8 * i);
|
||||
}
|
||||
|
||||
int numWords = size / 4;
|
||||
|
||||
while (numWords-- != 0)
|
||||
{
|
||||
UInt32 temp = *dataPointer++;
|
||||
temp |= ((UInt32)(*dataPointer++)) << 8;
|
||||
temp |= ((UInt32)(*dataPointer++)) << 16;
|
||||
temp |= ((UInt32)(*dataPointer++)) << 24;
|
||||
checkSum ^= temp;
|
||||
}
|
||||
m_Value = checkSum;
|
||||
|
||||
size &= 3;
|
||||
|
||||
while (size != 0)
|
||||
{
|
||||
m_Hist[m_Pos] = *dataPointer++;
|
||||
m_Pos = (m_Pos + 1) & 3;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
|
||||
static const UInt32 kDataBlockHeaderSize = 8;
|
||||
|
||||
class CTempCabInBuffer2
|
||||
{
|
||||
public:
|
||||
Byte Buffer[kDataBlockHeaderSize];
|
||||
UInt32 Pos;
|
||||
Byte ReadByte()
|
||||
{
|
||||
return Buffer[Pos++];
|
||||
}
|
||||
UInt32 ReadUInt32()
|
||||
{
|
||||
UInt32 value = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
value |= (((UInt32)ReadByte()) << (8 * i));
|
||||
return value;
|
||||
}
|
||||
UInt16 ReadUInt16()
|
||||
{
|
||||
UInt16 value = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
value |= (((UInt16)ReadByte()) << (8 * i));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
HRESULT CCabBlockInStream::PreRead(UInt32 &packSize, UInt32 &unpackSize)
|
||||
{
|
||||
CTempCabInBuffer2 inBuffer;
|
||||
inBuffer.Pos = 0;
|
||||
UInt32 processedSizeLoc;
|
||||
RINOK(ReadStream(_stream, inBuffer.Buffer, kDataBlockHeaderSize, &processedSizeLoc))
|
||||
if (processedSizeLoc != kDataBlockHeaderSize)
|
||||
return S_FALSE; // bad block
|
||||
|
||||
UInt32 checkSum = inBuffer.ReadUInt32();
|
||||
packSize = inBuffer.ReadUInt16();
|
||||
unpackSize = inBuffer.ReadUInt16();
|
||||
if (ReservedSize != 0)
|
||||
{
|
||||
RINOK(ReadStream(_stream, _buffer, ReservedSize, &processedSizeLoc));
|
||||
if(ReservedSize != processedSizeLoc)
|
||||
return S_FALSE; // bad block;
|
||||
}
|
||||
_pos = 0;
|
||||
CCheckSum2 checkSumCalc;
|
||||
checkSumCalc.Init();
|
||||
UInt32 packSize2 = packSize;
|
||||
if (MsZip && _size == 0)
|
||||
{
|
||||
if (packSize < 2)
|
||||
return S_FALSE; // bad block;
|
||||
Byte sig[2];
|
||||
RINOK(ReadStream(_stream, sig, 2, &processedSizeLoc));
|
||||
if(processedSizeLoc != 2)
|
||||
return S_FALSE;
|
||||
if (sig[0] != 0x43 || sig[1] != 0x4B)
|
||||
return S_FALSE;
|
||||
packSize2 -= 2;
|
||||
checkSumCalc.Update(sig, 2);
|
||||
}
|
||||
|
||||
if (kBlockSize - _size < packSize2)
|
||||
return S_FALSE;
|
||||
|
||||
UInt32 curSize = packSize2;
|
||||
if (curSize != 0)
|
||||
{
|
||||
RINOK(ReadStream(_stream, _buffer + _size, curSize, &processedSizeLoc));
|
||||
checkSumCalc.Update(_buffer + _size, processedSizeLoc);
|
||||
_size += processedSizeLoc;
|
||||
if (processedSizeLoc != curSize)
|
||||
return S_FALSE;
|
||||
}
|
||||
TotalPackSize = _size;
|
||||
|
||||
checkSumCalc.FinishDataUpdate();
|
||||
|
||||
bool dataError;
|
||||
if (checkSum == 0)
|
||||
dataError = false;
|
||||
else
|
||||
{
|
||||
checkSumCalc.UpdateUInt32(packSize | (((UInt32)unpackSize) << 16));
|
||||
dataError = (checkSumCalc.GetResult() != checkSum);
|
||||
}
|
||||
DataError |= dataError;
|
||||
return dataError ? S_FALSE : S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCabBlockInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (processedSize != 0)
|
||||
*processedSize = 0;
|
||||
if (size == 0)
|
||||
return S_OK;
|
||||
if (_size != 0)
|
||||
{
|
||||
size = MyMin(_size, size);
|
||||
memmove(data, _buffer + _pos, size);
|
||||
_pos += size;
|
||||
_size -= size;
|
||||
if (processedSize != 0)
|
||||
*processedSize = size;
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK; // no blocks data
|
||||
}
|
||||
|
||||
}}
|
||||
56
7zip/Archive/Cab/CabBlockInStream.h
Executable file
56
7zip/Archive/Cab/CabBlockInStream.h
Executable file
@@ -0,0 +1,56 @@
|
||||
// CabBlockInStream.cpp
|
||||
|
||||
#ifndef __CABBLOCKINSTREAM_H
|
||||
#define __CABBLOCKINSTREAM_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../IStream.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
|
||||
class CCabBlockInStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialInStream> _stream;
|
||||
Byte *_buffer;
|
||||
UInt32 _pos;
|
||||
UInt32 _size;
|
||||
int _align;
|
||||
|
||||
public:
|
||||
UInt32 TotalPackSize;
|
||||
UInt32 ReservedSize;
|
||||
bool DataError;
|
||||
bool MsZip;
|
||||
|
||||
CCabBlockInStream(): _buffer(0), ReservedSize(0), MsZip(false), DataError(false), _align(0), TotalPackSize(0) {}
|
||||
~CCabBlockInStream();
|
||||
bool Create();
|
||||
void SetStream(ISequentialInStream *stream) { _stream = stream; }
|
||||
|
||||
void InitForNewFolder()
|
||||
{
|
||||
_align = 0;
|
||||
TotalPackSize = 0;
|
||||
}
|
||||
|
||||
void InitForNewBlock()
|
||||
{
|
||||
_size = 0;
|
||||
_align = (_align + (int)TotalPackSize) & 1;
|
||||
}
|
||||
|
||||
int GetAlign() const { return _align; }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
|
||||
HRESULT PreRead(UInt32 &packSize, UInt32 &unpackSize);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -1,73 +0,0 @@
|
||||
// CabCopyDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "CabCopyDecoder.h"
|
||||
#include "Common/Defs.h"
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
|
||||
static const UInt32 kBufferSize = 1 << 17;
|
||||
|
||||
void CCopyDecoder::ReleaseStreams()
|
||||
{
|
||||
m_InStream.ReleaseStream();
|
||||
m_OutStream.ReleaseStream();
|
||||
}
|
||||
|
||||
class CCopyDecoderFlusher
|
||||
{
|
||||
CCopyDecoder *m_Decoder;
|
||||
public:
|
||||
CCopyDecoderFlusher(CCopyDecoder *decoder): m_Decoder(decoder) {}
|
||||
~CCopyDecoderFlusher()
|
||||
{
|
||||
m_Decoder->Flush();
|
||||
m_Decoder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
|
||||
STDMETHODIMP CCopyDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
UInt64 size = *outSize;
|
||||
|
||||
if (!m_OutStream.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!m_InStream.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
m_InStream.SetStream(inStream);
|
||||
m_InStream.Init(m_ReservedSize, m_NumInDataBlocks);
|
||||
m_OutStream.SetStream(outStream);
|
||||
m_OutStream.Init();
|
||||
CCopyDecoderFlusher decoderFlusher(this);
|
||||
|
||||
UInt64 nowPos64 = 0;
|
||||
while(nowPos64 < size)
|
||||
{
|
||||
UInt32 blockSize;
|
||||
bool dataAreCorrect;
|
||||
RINOK(m_InStream.ReadBlock(blockSize, dataAreCorrect));
|
||||
if (!dataAreCorrect)
|
||||
{
|
||||
throw 123456;
|
||||
}
|
||||
for (UInt32 i = 0; i < blockSize; i++)
|
||||
m_OutStream.WriteByte(m_InStream.ReadByte());
|
||||
nowPos64 += blockSize;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,41 +0,0 @@
|
||||
// CabCopyDecoder.h
|
||||
|
||||
#ifndef __ARCHIVE_CAB_COPY_DECODER_H
|
||||
#define __ARCHIVE_CAB_COPY_DECODER_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
#include "../../Common/OutBuffer.h"
|
||||
#include "CabInBuffer.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
|
||||
class CCopyDecoder:
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CInBuffer m_InStream;
|
||||
COutBuffer m_OutStream;
|
||||
Byte m_ReservedSize;
|
||||
UInt32 m_NumInDataBlocks;
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
void ReleaseStreams();
|
||||
HRESULT Flush() { return m_OutStream.Flush(); }
|
||||
void SetParams(Byte reservedSize, UInt32 numInDataBlocks)
|
||||
{
|
||||
m_ReservedSize = reservedSize;
|
||||
m_NumInDataBlocks = numInDataBlocks;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,10 +37,7 @@ public:
|
||||
BSTR *name, PROPID *propID, VARTYPE *varType);
|
||||
|
||||
private:
|
||||
CObjectVector<NHeader::CFolder> m_Folders;
|
||||
CObjectVector<CItem> m_Files;
|
||||
CInArchiveInfo m_ArchiveInfo;
|
||||
CMyComPtr<IInStream> m_Stream;
|
||||
CMvDatabaseEx m_Database;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -9,53 +9,15 @@ namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NHeader{
|
||||
|
||||
namespace NArchive {
|
||||
|
||||
namespace NArchive
|
||||
{
|
||||
extern UInt32 kSignature;
|
||||
|
||||
namespace NFlags
|
||||
{
|
||||
const int kPrevCabinet = 0x0001;
|
||||
const int kNextCabinet = 0x0002;
|
||||
const int kReservePresent = 0x0004;
|
||||
}
|
||||
|
||||
const UInt32 kArchiveHeaderSize = 36;
|
||||
/*
|
||||
struct CBlock
|
||||
{
|
||||
UInt32 Signature; // cabinet file signature
|
||||
UInt32 Reserved1; // reserved
|
||||
UInt32 Size; // size of this cabinet file in bytes
|
||||
UInt32 Reserved2; // reserved
|
||||
UInt32 FileOffset; // offset of the first CFFILE entry
|
||||
UInt32 Reserved3; // reserved
|
||||
Byte VersionMinor; // cabinet file format version, minor
|
||||
Byte VersionMajor; // cabinet file format version, major
|
||||
UInt16 NumFolders; // number of CFFOLDER entries in this cabinet
|
||||
UInt16 NumFiles; // number of CFFILE entries in this cabinet
|
||||
UInt16 Flags; // cabinet file option indicators
|
||||
UInt16 SetID; // must be the same for all cabinets in a set
|
||||
UInt16 CabinetNumber; // number of this cabinet file in a set
|
||||
};
|
||||
*/
|
||||
|
||||
const UInt32 kPerDataSizesHeaderSize = 4;
|
||||
|
||||
struct CPerDataSizes
|
||||
{
|
||||
UInt16 PerCabinetAreaSize; // (optional) size of per-cabinet reserved area
|
||||
Byte PerFolderAreaSize; // (optional) size of per-folder reserved area
|
||||
Byte PerDatablockAreaSize; // (optional) size of per-datablock reserved area
|
||||
};
|
||||
|
||||
/*
|
||||
Byte abReserve[]; // (optional) per-cabinet reserved area
|
||||
Byte szCabinetPrev[]; // (optional) name of previous cabinet file
|
||||
Byte szDiskPrev[]; // (optional) name of previous disk
|
||||
Byte szCabinetNext[]; // (optional) name of next cabinet file
|
||||
Byte szDiskNext[]; // (optional) name of next disk
|
||||
*/
|
||||
}
|
||||
|
||||
namespace NCompressionMethodMajor
|
||||
@@ -66,17 +28,6 @@ namespace NCompressionMethodMajor
|
||||
const Byte kLZX = 3;
|
||||
}
|
||||
|
||||
const UInt32 kFolderHeaderSize = 8;
|
||||
struct CFolder
|
||||
{
|
||||
UInt32 DataStart; // offset of the first CFDATA block in this folder
|
||||
UInt16 NumDataBlocks; // number of CFDATA blocks in this folder
|
||||
Byte CompressionTypeMajor;
|
||||
Byte CompressionTypeMinor;
|
||||
// Byte abReserve[]; // (optional) per-folder reserved area
|
||||
Byte GetCompressionMethod() const { return CompressionTypeMajor & 0xF; }
|
||||
};
|
||||
|
||||
const int kFileNameIsUTFAttributeMask = 0x80;
|
||||
|
||||
namespace NFolderIndex
|
||||
@@ -84,34 +35,8 @@ namespace NFolderIndex
|
||||
const int kContinuedFromPrev = 0xFFFD;
|
||||
const int kContinuedToNext = 0xFFFE;
|
||||
const int kContinuedPrevAndNext = 0xFFFF;
|
||||
inline UInt16 GetRealFolderIndex(UInt16 aNumFolders, UInt16 aFolderIndex)
|
||||
{
|
||||
switch(aFolderIndex)
|
||||
{
|
||||
case kContinuedFromPrev:
|
||||
return 0;
|
||||
case kContinuedToNext:
|
||||
case kContinuedPrevAndNext:
|
||||
return aNumFolders - 1;
|
||||
default:
|
||||
return aFolderIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const UInt32 kFileHeaderSize = 16;
|
||||
/*
|
||||
struct CFile
|
||||
{
|
||||
UInt32 UnPackSize; // uncompressed size of this file in bytes
|
||||
UInt32 UnPackOffset; // uncompressed offset of this file in the folder
|
||||
UInt16 FolderIndex; // index into the CFFOLDER area
|
||||
UInt16 PureDate;
|
||||
UInt16 PureTime; // Time
|
||||
UInt16 Attributes; // attribute flags for this file
|
||||
Byte szName[]; // name of this file
|
||||
};
|
||||
*/
|
||||
}}}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
#include "Common/MyCom.h"
|
||||
#include "CabIn.h"
|
||||
#include "Windows/Defs.h"
|
||||
#include "../../Common/InBuffer.h"
|
||||
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
namespace NArchive{
|
||||
namespace NCab{
|
||||
@@ -14,7 +15,7 @@ namespace NCab{
|
||||
static HRESULT ReadBytes(IInStream *inStream, void *data, UInt32 size)
|
||||
{
|
||||
UInt32 realProcessedSize;
|
||||
RINOK(inStream->Read(data, size, &realProcessedSize));
|
||||
RINOK(ReadStream(inStream, data, size, &realProcessedSize));
|
||||
if(realProcessedSize != size)
|
||||
return S_FALSE;
|
||||
return S_OK;
|
||||
@@ -23,7 +24,7 @@ static HRESULT ReadBytes(IInStream *inStream, void *data, UInt32 size)
|
||||
static HRESULT SafeRead(IInStream *inStream, void *data, UInt32 size)
|
||||
{
|
||||
UInt32 realProcessedSize;
|
||||
RINOK(inStream->Read(data, size, &realProcessedSize));
|
||||
RINOK(ReadStream(inStream, data, size, &realProcessedSize));
|
||||
if(realProcessedSize != size)
|
||||
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
|
||||
return S_OK;
|
||||
@@ -37,25 +38,12 @@ static void SafeInByteRead(::CInBuffer &inBuffer, void *data, UInt32 size)
|
||||
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
|
||||
}
|
||||
|
||||
static void SafeReadName(::CInBuffer &inBuffer, AString &name)
|
||||
{
|
||||
name.Empty();
|
||||
while(true)
|
||||
{
|
||||
Byte b;
|
||||
if (!inBuffer.ReadByte(b))
|
||||
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
|
||||
if (b == 0)
|
||||
return;
|
||||
name += char(b);
|
||||
}
|
||||
}
|
||||
|
||||
Byte CInArchive::ReadByte()
|
||||
{
|
||||
if (_blockPos >= _blockSize)
|
||||
throw CInArchiveException(CInArchiveException::kUnexpectedEndOfArchive);
|
||||
return _block[_blockPos++];
|
||||
Byte b;
|
||||
if (!inBuffer.ReadByte(b))
|
||||
throw CInArchiveException(CInArchiveException::kUnsupported);
|
||||
return b;
|
||||
}
|
||||
|
||||
UInt16 CInArchive::ReadUInt16()
|
||||
@@ -80,20 +68,38 @@ UInt32 CInArchive::ReadUInt32()
|
||||
return value;
|
||||
}
|
||||
|
||||
HRESULT CInArchive::Open(IInStream *inStream,
|
||||
const UInt64 *searchHeaderSizeLimit,
|
||||
CInArchiveInfo &inArchiveInfo,
|
||||
CObjectVector<NHeader::CFolder> &folders,
|
||||
CObjectVector<CItem> &files,
|
||||
CProgressVirt *progressVirt)
|
||||
AString CInArchive::SafeReadName()
|
||||
{
|
||||
UInt64 startPosition;
|
||||
RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &startPosition));
|
||||
AString name;
|
||||
while(true)
|
||||
{
|
||||
Byte b = ReadByte();
|
||||
if (b == 0)
|
||||
return name;
|
||||
name += (char)b;
|
||||
}
|
||||
}
|
||||
|
||||
// NHeader::NArchive::CBlock archiveHeader;
|
||||
void CInArchive::ReadOtherArchive(COtherArchive &oa)
|
||||
{
|
||||
oa.FileName = SafeReadName();
|
||||
oa.DiskName = SafeReadName();
|
||||
}
|
||||
|
||||
void CInArchive::Skeep(size_t size)
|
||||
{
|
||||
while (size-- != 0)
|
||||
ReadByte();
|
||||
}
|
||||
|
||||
HRESULT CInArchive::Open2(IInStream *inStream,
|
||||
const UInt64 *searchHeaderSizeLimit,
|
||||
CDatabase &database)
|
||||
{
|
||||
database.Clear();
|
||||
RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &database.StartPosition));
|
||||
|
||||
{
|
||||
::CInBuffer inBuffer;
|
||||
if (!inBuffer.Create(1 << 17))
|
||||
return E_OUTOFMEMORY;
|
||||
inBuffer.SetStream(inStream);
|
||||
@@ -117,141 +123,219 @@ HRESULT CInArchive::Open(IInStream *inStream,
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
startPosition += inBuffer.GetProcessedSize() - kSignatureSize;
|
||||
database.StartPosition += inBuffer.GetProcessedSize() - kSignatureSize;
|
||||
}
|
||||
RINOK(inStream->Seek(startPosition, STREAM_SEEK_SET, NULL));
|
||||
|
||||
RINOK(ReadBytes(inStream, _block, NHeader::NArchive::kArchiveHeaderSize));
|
||||
_blockSize = NHeader::NArchive::kArchiveHeaderSize;
|
||||
_blockPos = 0;
|
||||
CInArchiveInfo &archiveInfo = database.ArchiveInfo;
|
||||
|
||||
ReadUInt32(); // Signature; // cabinet file signature
|
||||
// if (archiveHeader.Signature != NHeader::NArchive::kSignature)
|
||||
// return S_FALSE;
|
||||
archiveInfo.Size = ReadUInt32(); // size of this cabinet file in bytes
|
||||
if (ReadUInt32() != 0)
|
||||
return S_FALSE;
|
||||
archiveInfo.FileHeadersOffset = ReadUInt32(); // offset of the first CFFILE entry
|
||||
if (ReadUInt32() != 0)
|
||||
return S_FALSE;
|
||||
|
||||
UInt32 reserved1 = ReadUInt32();
|
||||
UInt32 size = ReadUInt32(); // size of this cabinet file in bytes
|
||||
UInt32 reserved2 = ReadUInt32();
|
||||
UInt32 fileOffset = ReadUInt32(); // offset of the first CFFILE entry
|
||||
UInt32 reserved3 = ReadUInt32();
|
||||
archiveInfo.VersionMinor = ReadByte(); // cabinet file format version, minor
|
||||
archiveInfo.VersionMajor = ReadByte(); // cabinet file format version, major
|
||||
archiveInfo.NumFolders = ReadUInt16(); // number of CFFOLDER entries in this cabinet
|
||||
archiveInfo.NumFiles = ReadUInt16(); // number of CFFILE entries in this cabinet
|
||||
archiveInfo.Flags = ReadUInt16(); // number of CFFILE entries in this cabinet
|
||||
archiveInfo.SetID = ReadUInt16(); // must be the same for all cabinets in a set
|
||||
archiveInfo.CabinetNumber = ReadUInt16(); // number of this cabinet file in a set
|
||||
|
||||
inArchiveInfo.VersionMinor = ReadByte(); // cabinet file format version, minor
|
||||
inArchiveInfo.VersionMajor = ReadByte(); // cabinet file format version, major
|
||||
inArchiveInfo.NumFolders = ReadUInt16(); // number of CFFOLDER entries in this cabinet
|
||||
inArchiveInfo.NumFiles = ReadUInt16(); // number of CFFILE entries in this cabinet
|
||||
inArchiveInfo.Flags = ReadUInt16(); // number of CFFILE entries in this cabinet
|
||||
UInt16 setID = ReadUInt16(); // must be the same for all cabinets in a set
|
||||
UInt16 cabinetNumber = ReadUInt16(); // number of this cabinet file in a set
|
||||
|
||||
if (reserved1 != 0 || reserved2 != 0 || reserved3 != 0)
|
||||
throw CInArchiveException(CInArchiveException::kUnsupported);
|
||||
|
||||
if (inArchiveInfo.ReserveBlockPresent())
|
||||
if (archiveInfo.ReserveBlockPresent())
|
||||
{
|
||||
RINOK(SafeRead(inStream, _block, NHeader::NArchive::kPerDataSizesHeaderSize));
|
||||
_blockSize = NHeader::NArchive::kPerDataSizesHeaderSize;
|
||||
_blockPos = 0;
|
||||
archiveInfo.PerCabinetAreaSize = ReadUInt16(); // (optional) size of per-cabinet reserved area
|
||||
archiveInfo.PerFolderAreaSize = ReadByte(); // (optional) size of per-folder reserved area
|
||||
archiveInfo.PerDataBlockAreaSize = ReadByte(); // (optional) size of per-datablock reserved area
|
||||
|
||||
inArchiveInfo.PerDataSizes.PerCabinetAreaSize = ReadUInt16(); // (optional) size of per-cabinet reserved area
|
||||
inArchiveInfo.PerDataSizes.PerFolderAreaSize = ReadByte(); // (optional) size of per-folder reserved area
|
||||
inArchiveInfo.PerDataSizes.PerDatablockAreaSize = ReadByte(); // (optional) size of per-datablock reserved area
|
||||
RINOK(inStream->Seek(inArchiveInfo.PerDataSizes.PerCabinetAreaSize,
|
||||
STREAM_SEEK_CUR, NULL));
|
||||
Skeep(archiveInfo.PerCabinetAreaSize);
|
||||
}
|
||||
|
||||
{
|
||||
UInt64 foldersStartPosition;
|
||||
RINOK(inStream->Seek(0, STREAM_SEEK_CUR, &foldersStartPosition));
|
||||
::CInBuffer inBuffer;
|
||||
if (!inBuffer.Create(1 << 17))
|
||||
return E_OUTOFMEMORY;
|
||||
inBuffer.SetStream(inStream);
|
||||
inBuffer.Init();
|
||||
if ((inArchiveInfo.Flags & NHeader::NArchive::NFlags::kPrevCabinet) != 0)
|
||||
{
|
||||
SafeReadName(inBuffer, inArchiveInfo.PreviousCabinetName);
|
||||
SafeReadName(inBuffer, inArchiveInfo.PreviousDiskName);
|
||||
}
|
||||
if ((inArchiveInfo.Flags & NHeader::NArchive::NFlags::kNextCabinet) != 0)
|
||||
{
|
||||
SafeReadName(inBuffer, inArchiveInfo.NextCabinetName);
|
||||
SafeReadName(inBuffer, inArchiveInfo.NextDiskName);
|
||||
}
|
||||
foldersStartPosition += inBuffer.GetProcessedSize();
|
||||
RINOK(inStream->Seek(foldersStartPosition, STREAM_SEEK_SET, NULL));
|
||||
if (archiveInfo.IsTherePrev())
|
||||
ReadOtherArchive(archiveInfo.PreviousArchive);
|
||||
if (archiveInfo.IsThereNext())
|
||||
ReadOtherArchive(archiveInfo.NextArchive);
|
||||
}
|
||||
|
||||
if (progressVirt != NULL)
|
||||
{
|
||||
UInt64 numFiles = inArchiveInfo.NumFiles;
|
||||
RINOK(progressVirt->SetTotal(&numFiles));
|
||||
}
|
||||
folders.Clear();
|
||||
int i;
|
||||
for(i = 0; i < inArchiveInfo.NumFolders; i++)
|
||||
for(i = 0; i < archiveInfo.NumFolders; i++)
|
||||
{
|
||||
if (progressVirt != NULL)
|
||||
{
|
||||
UInt64 numFiles = 0;
|
||||
RINOK(progressVirt->SetCompleted(&numFiles));
|
||||
}
|
||||
NHeader::CFolder folder;
|
||||
RINOK(SafeRead(inStream, _block, NHeader::kFolderHeaderSize));
|
||||
_blockSize = NHeader::kFolderHeaderSize;
|
||||
_blockPos = 0;
|
||||
CFolder folder;
|
||||
|
||||
folder.DataStart = ReadUInt32();
|
||||
folder.NumDataBlocks = ReadUInt16();
|
||||
folder.CompressionTypeMajor = ReadByte();
|
||||
folder.CompressionTypeMinor = ReadByte();
|
||||
|
||||
if (inArchiveInfo.ReserveBlockPresent())
|
||||
{
|
||||
RINOK(inStream->Seek(
|
||||
inArchiveInfo.PerDataSizes.PerFolderAreaSize, STREAM_SEEK_CUR, NULL));
|
||||
}
|
||||
folder.DataStart += (UInt32)startPosition;
|
||||
folders.Add(folder);
|
||||
Skeep(archiveInfo.PerFolderAreaSize);
|
||||
database.Folders.Add(folder);
|
||||
}
|
||||
|
||||
RINOK(inStream->Seek(startPosition + fileOffset,
|
||||
STREAM_SEEK_SET, NULL));
|
||||
RINOK(inStream->Seek(database.StartPosition + archiveInfo.FileHeadersOffset, STREAM_SEEK_SET, NULL));
|
||||
|
||||
::CInBuffer inBuffer;
|
||||
if (!inBuffer.Create(1 << 17))
|
||||
return E_OUTOFMEMORY;
|
||||
inBuffer.SetStream(inStream);
|
||||
inBuffer.Init();
|
||||
files.Clear();
|
||||
if (progressVirt != NULL)
|
||||
for(i = 0; i < archiveInfo.NumFiles; i++)
|
||||
{
|
||||
UInt64 numFiles = files.Size();
|
||||
RINOK(progressVirt->SetCompleted(&numFiles));
|
||||
}
|
||||
for(i = 0; i < inArchiveInfo.NumFiles; i++)
|
||||
{
|
||||
SafeInByteRead(inBuffer, _block, NHeader::kFileHeaderSize);
|
||||
_blockSize = NHeader::kFileHeaderSize;
|
||||
_blockPos = 0;
|
||||
CItem item;
|
||||
item.UnPackSize = ReadUInt32();
|
||||
item.UnPackOffset = ReadUInt32();
|
||||
item.Size = ReadUInt32();
|
||||
item.Offset = ReadUInt32();
|
||||
item.FolderIndex = ReadUInt16();
|
||||
if (item.FolderIndex > inArchiveInfo.NumFolders)
|
||||
return S_FALSE;
|
||||
UInt16 pureDate = ReadUInt16();
|
||||
UInt16 pureTime = ReadUInt16();
|
||||
item.Time = ((UInt32(pureDate) << 16)) | pureTime;
|
||||
item.Attributes = ReadUInt16();
|
||||
SafeReadName(inBuffer, item.Name);
|
||||
files.Add(item);
|
||||
if (progressVirt != NULL)
|
||||
{
|
||||
UInt64 numFiles = files.Size();
|
||||
RINOK(progressVirt->SetCompleted(&numFiles));
|
||||
}
|
||||
item.Name = SafeReadName();
|
||||
int folderIndex = item.GetFolderIndex(database.Folders.Size());
|
||||
if (folderIndex >= database.Folders.Size())
|
||||
return S_FALSE;
|
||||
database.Items.Add(item);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
#define RINOZ(x) { int __tt = (x); if (__tt != 0) return __tt; }
|
||||
|
||||
HRESULT CInArchive::Open(
|
||||
const UInt64 *searchHeaderSizeLimit,
|
||||
CDatabaseEx &database)
|
||||
{
|
||||
return Open2(database.Stream, searchHeaderSizeLimit, database);
|
||||
}
|
||||
|
||||
|
||||
static int CompareMvItems2(const CMvItem *p1, const CMvItem *p2)
|
||||
{
|
||||
RINOZ(MyCompare(p1->VolumeIndex, p2->VolumeIndex));
|
||||
return MyCompare(p1->ItemIndex, p2->ItemIndex);
|
||||
}
|
||||
|
||||
static int CompareMvItems(const CMvItem *p1, const CMvItem *p2, void *param)
|
||||
{
|
||||
const CMvDatabaseEx &mvDb = *(const CMvDatabaseEx *)param;
|
||||
const CDatabaseEx &db1 = mvDb.Volumes[p1->VolumeIndex];
|
||||
const CDatabaseEx &db2 = mvDb.Volumes[p2->VolumeIndex];
|
||||
const CItem &item1 = db1.Items[p1->ItemIndex];
|
||||
const CItem &item2 = db2.Items[p2->ItemIndex];;
|
||||
bool isDir1 = item1.IsDirectory();
|
||||
bool isDir2 = item2.IsDirectory();
|
||||
if (isDir1 && !isDir2)
|
||||
return -1;
|
||||
if (isDir2 && !isDir1)
|
||||
return 1;
|
||||
int f1 = mvDb.GetFolderIndex(p1);
|
||||
int f2 = mvDb.GetFolderIndex(p2);
|
||||
RINOZ(MyCompare(f1, f2));
|
||||
RINOZ(MyCompare(item1.Offset, item2.Offset));
|
||||
RINOZ(MyCompare(item1.Size, item2.Size));
|
||||
return CompareMvItems2(p1, p2);
|
||||
}
|
||||
|
||||
bool CMvDatabaseEx::AreItemsEqual(int i1, int i2)
|
||||
{
|
||||
const CMvItem *p1 = &Items[i1];
|
||||
const CMvItem *p2 = &Items[i2];
|
||||
const CDatabaseEx &db1 = Volumes[p1->VolumeIndex];
|
||||
const CDatabaseEx &db2 = Volumes[p2->VolumeIndex];
|
||||
const CItem &item1 = db1.Items[p1->ItemIndex];
|
||||
const CItem &item2 = db2.Items[p2->ItemIndex];;
|
||||
int f1 = GetFolderIndex(p1);
|
||||
int f2 = GetFolderIndex(p2);
|
||||
if (f1 != f2)
|
||||
return false;
|
||||
if (item1.Offset != item2.Offset)
|
||||
return false;
|
||||
if (item1.Size != item2.Size)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMvDatabaseEx::FillSortAndShrink()
|
||||
{
|
||||
Items.Clear();
|
||||
StartFolderOfVol.Clear();
|
||||
FolderStartFileIndex.Clear();
|
||||
int offset = 0;
|
||||
for (int v = 0; v < Volumes.Size(); v++)
|
||||
{
|
||||
const CDatabaseEx &db = Volumes[v];
|
||||
int curOffset = offset;
|
||||
if (db.IsTherePrevFolder())
|
||||
curOffset--;
|
||||
StartFolderOfVol.Add(curOffset);
|
||||
offset += db.GetNumberOfNewFolders();
|
||||
|
||||
CMvItem mvItem;
|
||||
mvItem.VolumeIndex = v;
|
||||
for (int i = 0 ; i < db.Items.Size(); i++)
|
||||
{
|
||||
mvItem.ItemIndex = i;
|
||||
Items.Add(mvItem);
|
||||
}
|
||||
}
|
||||
|
||||
Items.Sort(CompareMvItems, (void *)this);
|
||||
int j = 1;
|
||||
int i;
|
||||
for (i = 1; i < Items.Size(); i++)
|
||||
if (!AreItemsEqual(i, i -1))
|
||||
Items[j++] = Items[i];
|
||||
Items.DeleteFrom(j);
|
||||
|
||||
for (i = 0; i < Items.Size(); i++)
|
||||
{
|
||||
const CMvItem &mvItem = Items[i];
|
||||
int folderIndex = GetFolderIndex(&mvItem);
|
||||
if (folderIndex >= FolderStartFileIndex.Size())
|
||||
FolderStartFileIndex.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
bool CMvDatabaseEx::Check()
|
||||
{
|
||||
for (int v = 1; v < Volumes.Size(); v++)
|
||||
{
|
||||
const CDatabaseEx &db1 = Volumes[v];
|
||||
if (db1.IsTherePrevFolder())
|
||||
{
|
||||
const CDatabaseEx &db0 = Volumes[v - 1];
|
||||
if (db0.Folders.IsEmpty() || db1.Folders.IsEmpty())
|
||||
return false;
|
||||
const CFolder &f0 = db0.Folders.Back();
|
||||
const CFolder &f1 = db1.Folders.Front();
|
||||
if (f0.CompressionTypeMajor != f1.CompressionTypeMajor ||
|
||||
f0.CompressionTypeMinor != f1.CompressionTypeMinor)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
UInt64 maxPos = 0;
|
||||
int prevFolder = -2;
|
||||
for(int i = 0; i < Items.Size(); i++)
|
||||
{
|
||||
const CMvItem &mvItem = Items[i];
|
||||
int fIndex = GetFolderIndex(&mvItem);
|
||||
if (fIndex >= FolderStartFileIndex.Size())
|
||||
return false;
|
||||
const CItem &item = Volumes[mvItem.VolumeIndex].Items[mvItem.ItemIndex];
|
||||
if (item.IsDirectory())
|
||||
continue;
|
||||
int folderIndex = GetFolderIndex(&mvItem);
|
||||
if (folderIndex != prevFolder)
|
||||
{
|
||||
prevFolder = folderIndex;
|
||||
maxPos = 0;
|
||||
continue;
|
||||
}
|
||||
if (item.Offset < maxPos)
|
||||
return false;
|
||||
maxPos = item.GetEndOffset();
|
||||
if (maxPos < item.Offset)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#define __ARCHIVE_CAB_IN_H
|
||||
|
||||
#include "../../IStream.h"
|
||||
#include "../../Common/InBuffer.h"
|
||||
#include "CabHeader.h"
|
||||
#include "CabItem.h"
|
||||
|
||||
@@ -22,10 +23,14 @@ public:
|
||||
CInArchiveException(CCauseType cause) : Cause(cause) {}
|
||||
};
|
||||
|
||||
class CInArchiveInfo
|
||||
struct COtherArchive
|
||||
{
|
||||
AString FileName;
|
||||
AString DiskName;
|
||||
};
|
||||
|
||||
struct CArchiveInfo
|
||||
{
|
||||
public:
|
||||
UInt32 Size; /* size of this cabinet file in bytes */
|
||||
Byte VersionMinor; /* cabinet file format version, minor */
|
||||
Byte VersionMajor; /* cabinet file format version, major */
|
||||
UInt16 NumFolders; /* number of CFFOLDER entries in this cabinet */
|
||||
@@ -35,39 +40,125 @@ public:
|
||||
UInt16 CabinetNumber; /* number of this cabinet file in a set */
|
||||
|
||||
bool ReserveBlockPresent() const { return (Flags & NHeader::NArchive::NFlags::kReservePresent) != 0; }
|
||||
NHeader::NArchive::CPerDataSizes PerDataSizes;
|
||||
|
||||
AString PreviousCabinetName;
|
||||
AString PreviousDiskName;
|
||||
AString NextCabinetName;
|
||||
AString NextDiskName;
|
||||
bool IsTherePrev() const { return (Flags & NHeader::NArchive::NFlags::kPrevCabinet) != 0; }
|
||||
bool IsThereNext() const { return (Flags & NHeader::NArchive::NFlags::kNextCabinet) != 0; }
|
||||
|
||||
UInt16 PerCabinetAreaSize; // (optional) size of per-cabinet reserved area
|
||||
Byte PerFolderAreaSize; // (optional) size of per-folder reserved area
|
||||
Byte PerDataBlockAreaSize; // (optional) size of per-datablock reserved area
|
||||
|
||||
Byte GetDataBlockReserveSize() const { return (Byte)(ReserveBlockPresent() ? PerDataBlockAreaSize : 0); }
|
||||
|
||||
COtherArchive PreviousArchive;
|
||||
COtherArchive NextArchive;
|
||||
|
||||
CArchiveInfo()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
PerCabinetAreaSize = 0;
|
||||
PerFolderAreaSize = 0;
|
||||
PerDataBlockAreaSize = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class CProgressVirt
|
||||
struct CInArchiveInfo: public CArchiveInfo
|
||||
{
|
||||
UInt32 Size; /* size of this cabinet file in bytes */
|
||||
UInt32 FileHeadersOffset; //offset of the first CFFILE entry
|
||||
};
|
||||
|
||||
|
||||
class CDatabase
|
||||
{
|
||||
public:
|
||||
STDMETHOD(SetTotal)(const UInt64 *numFiles) PURE;
|
||||
STDMETHOD(SetCompleted)(const UInt64 *numFiles) PURE;
|
||||
UInt64 StartPosition;
|
||||
CInArchiveInfo ArchiveInfo;
|
||||
CObjectVector<CFolder> Folders;
|
||||
CObjectVector<CItem> Items;
|
||||
void Clear()
|
||||
{
|
||||
ArchiveInfo.Clear();
|
||||
Folders.Clear();
|
||||
Items.Clear();
|
||||
}
|
||||
bool IsTherePrevFolder() const
|
||||
{
|
||||
for (int i = 0; i < Items.Size(); i++)
|
||||
if (Items[i].ContinuedFromPrev())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
int GetNumberOfNewFolders() const
|
||||
{
|
||||
int res = Folders.Size();
|
||||
if (IsTherePrevFolder())
|
||||
res--;
|
||||
return res;
|
||||
}
|
||||
UInt32 GetFileOffset(int index) const { return Items[index].Offset; }
|
||||
UInt32 GetFileSize(int index) const { return Items[index].Size; }
|
||||
};
|
||||
|
||||
const UInt32 kMaxBlockSize = NHeader::NArchive::kArchiveHeaderSize;
|
||||
class CDatabaseEx: public CDatabase
|
||||
{
|
||||
public:
|
||||
CMyComPtr<IInStream> Stream;
|
||||
};
|
||||
|
||||
struct CMvItem
|
||||
{
|
||||
int VolumeIndex;
|
||||
int ItemIndex;
|
||||
};
|
||||
|
||||
class CMvDatabaseEx
|
||||
{
|
||||
bool AreItemsEqual(int i1, int i2);
|
||||
public:
|
||||
CObjectVector<CDatabaseEx> Volumes;
|
||||
CRecordVector<CMvItem> Items;
|
||||
CRecordVector<int> StartFolderOfVol;
|
||||
CRecordVector<int> FolderStartFileIndex;
|
||||
int GetFolderIndex(const CMvItem *mvi) const
|
||||
{
|
||||
const CDatabaseEx &db = Volumes[mvi->VolumeIndex];
|
||||
return StartFolderOfVol[mvi->VolumeIndex] +
|
||||
db.Items[mvi->ItemIndex].GetFolderIndex(db.Folders.Size());
|
||||
}
|
||||
void Clear()
|
||||
{
|
||||
Volumes.Clear();
|
||||
Items.Clear();
|
||||
StartFolderOfVol.Clear();
|
||||
FolderStartFileIndex.Clear();
|
||||
}
|
||||
void FillSortAndShrink();
|
||||
bool Check();
|
||||
};
|
||||
|
||||
class CInArchive
|
||||
{
|
||||
UInt16 _blockSize;
|
||||
Byte _block[kMaxBlockSize];
|
||||
UInt32 _blockPos;
|
||||
CInBuffer inBuffer;
|
||||
|
||||
Byte ReadByte();
|
||||
UInt16 ReadUInt16();
|
||||
UInt32 ReadUInt32();
|
||||
public:
|
||||
HRESULT Open(IInStream *inStream,
|
||||
AString SafeReadName();
|
||||
void Skeep(size_t size);
|
||||
void ReadOtherArchive(COtherArchive &oa);
|
||||
|
||||
HRESULT Open2(IInStream *inStream,
|
||||
const UInt64 *searchHeaderSizeLimit,
|
||||
CInArchiveInfo &inArchiveInfo,
|
||||
CObjectVector<NHeader::CFolder> &folders,
|
||||
CObjectVector<CItem> &files,
|
||||
CProgressVirt *progressVirt);
|
||||
CDatabase &database);
|
||||
public:
|
||||
HRESULT Open(
|
||||
const UInt64 *searchHeaderSizeLimit,
|
||||
CDatabaseEx &database);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
// Archive/CabInBuffer.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/Alloc.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../../Windows/Defs.h"
|
||||
#include "CabInBuffer.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
|
||||
static const UInt32 kDataBlockHeaderSize = 8;
|
||||
/*
|
||||
struct CDataBlockHeader
|
||||
{
|
||||
UInt32 CheckSum; // checksum of this CFDATA entry
|
||||
UInt16 PackSize; // number of compressed bytes in this block
|
||||
UInt16 UnPackSize; // number of uncompressed bytes in this block
|
||||
// Byte abReserve[]; // (optional) per-datablock reserved area
|
||||
// Byte ab[cbData]; // compressed data bytes
|
||||
};
|
||||
*/
|
||||
|
||||
class CTempCabInBuffer
|
||||
{
|
||||
public:
|
||||
Byte *Buffer;
|
||||
UInt32 Size;
|
||||
UInt32 Pos;
|
||||
Byte ReadByte()
|
||||
{
|
||||
if (Pos >= Size)
|
||||
throw "overflow";
|
||||
return Buffer[Pos++];
|
||||
}
|
||||
UInt32 ReadUInt32()
|
||||
{
|
||||
UInt32 value = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
value |= (((UInt32)ReadByte()) << (8 * i));
|
||||
return value;
|
||||
}
|
||||
UInt16 ReadUInt16()
|
||||
{
|
||||
UInt16 value = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
value |= (((UInt16)ReadByte()) << (8 * i));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
bool CInBuffer::Create(UInt32 bufferSize)
|
||||
{
|
||||
const UInt32 kMinBlockSize = 1;
|
||||
if (bufferSize < kMinBlockSize)
|
||||
bufferSize = kMinBlockSize;
|
||||
if (m_Buffer != 0 && m_BufferSize == bufferSize)
|
||||
return true;
|
||||
Free();
|
||||
m_BufferSize = bufferSize;
|
||||
m_Buffer = (Byte *)::BigAlloc(bufferSize);
|
||||
return (m_Buffer != 0);
|
||||
}
|
||||
|
||||
void CInBuffer::Free()
|
||||
{
|
||||
BigFree(m_Buffer);
|
||||
m_Buffer = 0;
|
||||
}
|
||||
|
||||
void CInBuffer::Init(Byte reservedSize, UInt32 numBlocks)
|
||||
{
|
||||
m_ReservedSize = reservedSize;
|
||||
m_NumBlocks = numBlocks;
|
||||
m_CurrentBlockIndex = 0;
|
||||
m_ProcessedSize = 0;
|
||||
m_Pos = 0;
|
||||
m_NumReadBytesInBuffer = 0;
|
||||
}
|
||||
|
||||
class CCheckSum
|
||||
{
|
||||
UInt32 m_Value;
|
||||
public:
|
||||
CCheckSum(): m_Value(0){};
|
||||
void Init() { m_Value = 0; }
|
||||
void Update(const void *data, UInt32 size);
|
||||
void UpdateUInt32(UInt32 v) { m_Value ^= v; }
|
||||
UInt32 GetResult() const { return m_Value; }
|
||||
};
|
||||
|
||||
void CCheckSum::Update(const void *data, UInt32 size)
|
||||
{
|
||||
UInt32 checkSum = m_Value;
|
||||
const Byte *dataPointer = (const Byte *)data;
|
||||
int numUINT32Words = size / 4; // Number of ULONGs
|
||||
|
||||
UInt32 temp;
|
||||
while (numUINT32Words-- > 0)
|
||||
{
|
||||
temp = *dataPointer++;
|
||||
temp |= (((UInt32)(*dataPointer++)) << 8);
|
||||
temp |= (((UInt32)(*dataPointer++)) << 16);
|
||||
temp |= (((UInt32)(*dataPointer++)) << 24);
|
||||
checkSum ^= temp;
|
||||
}
|
||||
|
||||
temp = 0;
|
||||
int rem = (size & 3);
|
||||
if (rem >= 3)
|
||||
temp |= (((UInt32)(*dataPointer++)) << 16);
|
||||
if (rem >= 2)
|
||||
temp |= (((UInt32)(*dataPointer++)) << 8);
|
||||
if (rem >= 1)
|
||||
temp |= *dataPointer++;
|
||||
checkSum ^= temp;
|
||||
m_Value = checkSum;
|
||||
}
|
||||
|
||||
HRESULT CInBuffer::ReadBlock(UInt32 &uncompressedSize, bool &dataAreCorrect)
|
||||
{
|
||||
if (m_CurrentBlockIndex >= m_NumBlocks)
|
||||
throw "there is no more data blocks";
|
||||
|
||||
m_ProcessedSize += m_NumReadBytesInBuffer;
|
||||
|
||||
Byte buffer[kDataBlockHeaderSize];
|
||||
UInt32 numProcessedBytes;
|
||||
RINOK(m_Stream->Read(buffer, kDataBlockHeaderSize, &numProcessedBytes));
|
||||
if (numProcessedBytes != kDataBlockHeaderSize)
|
||||
throw "bad block";
|
||||
|
||||
CTempCabInBuffer inBuffer;
|
||||
inBuffer.Size = kDataBlockHeaderSize;
|
||||
inBuffer.Buffer = (Byte *)buffer;
|
||||
inBuffer.Pos = 0;
|
||||
|
||||
UInt32 checkSum = inBuffer.ReadUInt32(); // checksum of this CFDATA entry
|
||||
UInt16 packSize = inBuffer.ReadUInt16(); // number of compressed bytes in this block
|
||||
UInt16 unPackSize = inBuffer.ReadUInt16(); // number of uncompressed bytes in this block
|
||||
|
||||
if (m_ReservedSize != 0)
|
||||
{
|
||||
Byte reservedArea[256];
|
||||
RINOK(m_Stream->Read(reservedArea, m_ReservedSize, &numProcessedBytes));
|
||||
if (numProcessedBytes != m_ReservedSize)
|
||||
throw "bad block";
|
||||
}
|
||||
|
||||
RINOK(m_Stream->Read(m_Buffer, packSize, &m_NumReadBytesInBuffer));
|
||||
if (m_NumReadBytesInBuffer != packSize)
|
||||
throw "bad block";
|
||||
|
||||
// Cab specification:
|
||||
// checkSum: May be set to zero if the checksum is not supplied.
|
||||
// but seems it's stupid rule.
|
||||
if (checkSum == 0)
|
||||
dataAreCorrect = true;
|
||||
else
|
||||
{
|
||||
CCheckSum checkSumCalc;
|
||||
checkSumCalc.Update(m_Buffer, packSize);
|
||||
checkSumCalc.UpdateUInt32(packSize | (((UInt32)unPackSize) << 16));
|
||||
dataAreCorrect = (checkSumCalc.GetResult() == checkSum);
|
||||
}
|
||||
|
||||
m_Pos = 0;
|
||||
uncompressedSize = unPackSize;
|
||||
|
||||
m_CurrentBlockIndex++;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -1,66 +0,0 @@
|
||||
// Archive/CabInBuffer.h
|
||||
|
||||
#ifndef __ARCHIVE_CAB_INBUFFER_H
|
||||
#define __ARCHIVE_CAB_INBUFFER_H
|
||||
|
||||
#include "../../IStream.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
|
||||
class CInBuffer
|
||||
{
|
||||
UInt64 m_ProcessedSize;
|
||||
UInt32 m_Pos;
|
||||
UInt32 m_NumReadBytesInBuffer;
|
||||
Byte *m_Buffer;
|
||||
CMyComPtr<ISequentialInStream> m_Stream;
|
||||
UInt32 m_BufferSize;
|
||||
|
||||
UInt32 m_NumBlocks;
|
||||
UInt32 m_CurrentBlockIndex;
|
||||
UInt32 m_ReservedSize;
|
||||
|
||||
public:
|
||||
CInBuffer(): m_Buffer(0) {}
|
||||
~CInBuffer() { Free(); }
|
||||
bool Create(UInt32 bufferSize);
|
||||
void Free();
|
||||
|
||||
void SetStream(ISequentialInStream *inStream) { m_Stream = inStream; }
|
||||
void ReleaseStream() { m_Stream.Release(); }
|
||||
|
||||
void Init(Byte reservedSize, UInt32 numBlocks);
|
||||
void Init() {}
|
||||
|
||||
bool ReadByte(Byte &b)
|
||||
{
|
||||
if(m_Pos >= m_NumReadBytesInBuffer)
|
||||
return false;
|
||||
b = m_Buffer[m_Pos++];
|
||||
return true;
|
||||
}
|
||||
Byte ReadByte()
|
||||
{
|
||||
if(m_Pos >= m_NumReadBytesInBuffer)
|
||||
return 0;
|
||||
return m_Buffer[m_Pos++];
|
||||
}
|
||||
/*
|
||||
void ReadBytes(void *data, UInt32 size, UInt32 &aProcessedSize)
|
||||
{
|
||||
Byte *aDataPointer = (Byte *)data;
|
||||
for(int i = 0; i < size; i++)
|
||||
if (!ReadByte(aDataPointer[i]))
|
||||
break;
|
||||
aProcessedSize = i;
|
||||
}
|
||||
*/
|
||||
HRESULT ReadBlock(UInt32 &uncompressedSize, bool &dataAreCorrect);
|
||||
UInt64 GetProcessedSize() const { return m_ProcessedSize + m_Pos; }
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
// Archive/Cab/ItemInfo.h
|
||||
// Archive/CabItem.h
|
||||
|
||||
#ifndef __ARCHIVE_RAR_ITEMINFO_H
|
||||
#define __ARCHIVE_RAR_ITEMINFO_H
|
||||
#ifndef __ARCHIVE_CAB_ITEM_H
|
||||
#define __ARCHIVE_CAB_ITEM_H
|
||||
|
||||
#include "Common/Types.h"
|
||||
#include "Common/String.h"
|
||||
@@ -10,23 +10,53 @@
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
|
||||
struct CFolder
|
||||
{
|
||||
UInt32 DataStart; // offset of the first CFDATA block in this folder
|
||||
UInt16 NumDataBlocks; // number of CFDATA blocks in this folder
|
||||
Byte CompressionTypeMajor;
|
||||
Byte CompressionTypeMinor;
|
||||
Byte GetCompressionMethod() const { return (Byte)(CompressionTypeMajor & 0xF); }
|
||||
};
|
||||
|
||||
class CItem
|
||||
{
|
||||
public:
|
||||
UInt16 Flags;
|
||||
UInt64 UnPackSize;
|
||||
UInt32 UnPackOffset;
|
||||
UInt16 FolderIndex;
|
||||
AString Name;
|
||||
UInt32 Offset;
|
||||
UInt32 Size;
|
||||
UInt32 Time;
|
||||
UInt16 Attributes;
|
||||
UInt32 GetWinAttributes() const { return Attributes & (Attributes & ~NHeader::kFileNameIsUTFAttributeMask); }
|
||||
UInt16 FolderIndex;
|
||||
UInt16 Flags;
|
||||
UInt16 Attributes;
|
||||
UInt64 GetEndOffset() const { return (UInt64)Offset + Size; }
|
||||
UInt32 GetWinAttributes() const { return (Attributes & ~NHeader::kFileNameIsUTFAttributeMask); }
|
||||
bool IsNameUTF() const { return (Attributes & NHeader::kFileNameIsUTFAttributeMask) != 0; }
|
||||
bool IsDirectory() const { return (Attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }
|
||||
AString Name;
|
||||
|
||||
bool ContinuedFromPrev() const
|
||||
{
|
||||
return
|
||||
(FolderIndex == NHeader::NFolderIndex::kContinuedFromPrev) ||
|
||||
(FolderIndex == NHeader::NFolderIndex::kContinuedPrevAndNext);
|
||||
}
|
||||
bool ContinuedToNext() const
|
||||
{
|
||||
return
|
||||
(FolderIndex == NHeader::NFolderIndex::kContinuedToNext) ||
|
||||
(FolderIndex == NHeader::NFolderIndex::kContinuedPrevAndNext);
|
||||
}
|
||||
|
||||
int GetFolderIndex(int numFolders) const
|
||||
{
|
||||
if (ContinuedFromPrev())
|
||||
return 0;
|
||||
if (ContinuedToNext())
|
||||
return (numFolders - 1);
|
||||
return FolderIndex;
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include "CabHandler.h"
|
||||
#include "../../ICoder.h"
|
||||
|
||||
// {23170F69-40C1-278A-1000-000110060000}
|
||||
// {23170F69-40C1-278A-1000-000110080000}
|
||||
DEFINE_GUID(CLSID_CCabHandler,
|
||||
0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x06, 0x00, 0x00);
|
||||
0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x08, 0x00, 0x00);
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
||||
BOOL WINAPI DllMain(HINSTANCE, DWORD, LPVOID)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
// Archive/Cab/LZXBitDecoder.h
|
||||
|
||||
#ifndef __ARCHIVE_CAB_LZXBITDECODER_H
|
||||
#define __ARCHIVE_CAB_LZXBITDECODER_H
|
||||
|
||||
#include "CabInBuffer.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NLZX {
|
||||
namespace NBitStream {
|
||||
|
||||
const int kNumBigValueBits = 8 * 4;
|
||||
|
||||
const int kNumValueBits = 17;
|
||||
const int kBitDecoderValueMask = (1 << kNumValueBits) - 1;
|
||||
|
||||
class CDecoder
|
||||
{
|
||||
protected:
|
||||
CInBuffer m_Stream;
|
||||
UInt32 m_BitPos;
|
||||
UInt32 m_Value;
|
||||
public:
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialInStream *s) { m_Stream.SetStream(s); }
|
||||
void ReleaseStream() { m_Stream.ReleaseStream(); }
|
||||
void Init(Byte reservedSize, UInt32 numBlocks)
|
||||
{
|
||||
m_Stream.Init(reservedSize, numBlocks);
|
||||
}
|
||||
UInt64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
UInt32 GetBitPosition() const
|
||||
{ return UInt32(m_Stream.GetProcessedSize() * 8 - (kNumBigValueBits - m_BitPos)); }
|
||||
|
||||
void Init()
|
||||
{
|
||||
m_BitPos = kNumBigValueBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
for (;m_BitPos >= 16; m_BitPos -= 16)
|
||||
{
|
||||
Byte b0 = m_Stream.ReadByte();
|
||||
Byte b1 = m_Stream.ReadByte();
|
||||
m_Value = (m_Value << 8) | b1;
|
||||
m_Value = (m_Value << 8) | b0;
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 GetValue(UInt32 numBits)
|
||||
{
|
||||
return ((m_Value >> ((32 - kNumValueBits) - m_BitPos)) & kBitDecoderValueMask) >>
|
||||
(kNumValueBits - numBits);
|
||||
}
|
||||
|
||||
void MovePos(UInt32 numBits)
|
||||
{
|
||||
m_BitPos += numBits;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
UInt32 ReadBits(UInt32 numBits)
|
||||
{
|
||||
UInt32 res = GetValue(numBits);
|
||||
MovePos(numBits);
|
||||
return res;
|
||||
}
|
||||
UInt32 ReadBitsBig(UInt32 numBits)
|
||||
{
|
||||
UInt32 numBits0 = numBits / 2;
|
||||
UInt32 numBits1 = numBits - numBits0;
|
||||
UInt32 res = ReadBits(numBits0) << numBits1;
|
||||
return res + ReadBits(numBits1);
|
||||
}
|
||||
|
||||
Byte DirectReadByte()
|
||||
{
|
||||
if (m_BitPos == kNumBigValueBits)
|
||||
return m_Stream.ReadByte();
|
||||
Byte res;
|
||||
switch(m_BitPos)
|
||||
{
|
||||
case 0:
|
||||
res = Byte(m_Value >> 16);
|
||||
break;
|
||||
case 8:
|
||||
res = Byte(m_Value >> 24);
|
||||
break;
|
||||
case 16:
|
||||
res = Byte(m_Value);
|
||||
break;
|
||||
case 24:
|
||||
res = Byte(m_Value >> 8);
|
||||
break;
|
||||
}
|
||||
m_BitPos += 8;
|
||||
return res;
|
||||
}
|
||||
|
||||
HRESULT ReadBlock(UInt32 &uncompressedSize, bool &dataAreCorrect)
|
||||
{ return m_Stream.ReadBlock(uncompressedSize, dataAreCorrect); }
|
||||
};
|
||||
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -1,110 +0,0 @@
|
||||
// Archive/Cab/LZXConst.h
|
||||
|
||||
#ifndef __ARCHIVE_CAB_LZXCONST_H
|
||||
#define __ARCHIVE_CAB_LZXCONST_H
|
||||
|
||||
#include "LZXExtConst.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NLZX {
|
||||
|
||||
namespace NBlockType
|
||||
{
|
||||
const int kNumBits = 3;
|
||||
enum EEnum
|
||||
{
|
||||
kVerbatim = 1,
|
||||
kAligned = 2,
|
||||
kUncompressed = 3
|
||||
};
|
||||
}
|
||||
|
||||
const int kUncompressedBlockSizeNumBits = 24;
|
||||
|
||||
const UInt32 kLevelTableSize = 20;
|
||||
|
||||
const UInt32 kNumBitsForPreTreeLevel = 4;
|
||||
|
||||
const int kLevelSymbolZeros = 17;
|
||||
const int kLevelSymbolZerosBig = 18;
|
||||
const int kLevelSymbolSame = 19;
|
||||
|
||||
const int kLevelSymbolZerosStartValue = 4;
|
||||
const int kLevelSymbolZerosNumBits = 4;
|
||||
|
||||
const int kLevelSymbolZerosBigStartValue = kLevelSymbolZerosStartValue +
|
||||
(1 << kLevelSymbolZerosNumBits);
|
||||
const int kLevelSymbolZerosBigNumBits = 5;
|
||||
|
||||
const int kNumBitsForAlignLevel = 3;
|
||||
|
||||
const int kLevelSymbolSameNumBits = 1;
|
||||
const int kLevelSymbolSameStartValue = 4;
|
||||
|
||||
// const UInt32 kMainTableSize = 256 + kNumPosLenSlots + 1;
|
||||
|
||||
/*
|
||||
const UInt32 kLenTableSize = 28;
|
||||
|
||||
const UInt32 kLenTableStart = kMainTableSize;
|
||||
const UInt32 kAlignTableStart = kLenTableStart + kLenTableSize;
|
||||
|
||||
const UInt32 kHeapTablesSizesSum = kMainTableSize + kLenTableSize + kAlignTableSize;
|
||||
|
||||
|
||||
const UInt32 kMaxTableSize = kHeapTablesSizesSum;
|
||||
|
||||
const UInt32 kTableDirectLevels = 16;
|
||||
const UInt32 kTableLevelRepNumber = kTableDirectLevels;
|
||||
const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1;
|
||||
const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
|
||||
|
||||
const UInt32 kLevelMask = 0xF;
|
||||
|
||||
const UInt32 kPosLenNumber = 256;
|
||||
const UInt32 kReadTableNumber = 256 + kNumPosLenSlots;
|
||||
|
||||
//const UInt32 kMatchNumber = kReadTableNumber + 1;
|
||||
|
||||
const Byte kLenStart[kLenTableSize] =
|
||||
{0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224};
|
||||
const Byte kLenDirectBits[kLenTableSize] =
|
||||
{0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5};
|
||||
*/
|
||||
|
||||
const UInt32 kDistStart[] =
|
||||
{ 0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,
|
||||
1536,2048,3072,4096,6144,8192,12288,16384,24576,32768,49152,65536,98304,131072,196608,
|
||||
0x40000,
|
||||
0x60000,
|
||||
0x80000,
|
||||
0xA0000,
|
||||
0xC0000,
|
||||
0xE0000,
|
||||
|
||||
0x100000,
|
||||
0x120000,
|
||||
0x140000,
|
||||
0x160000,
|
||||
0x180000,
|
||||
0x1A0000,
|
||||
0x1C0000,
|
||||
0x1E0000
|
||||
};
|
||||
const Byte kDistDirectBits[] =
|
||||
{
|
||||
0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,
|
||||
17, 17, 17, 17, 17, 17,
|
||||
17, 17,17, 17, 17, 17, 17, 17
|
||||
};
|
||||
|
||||
/*
|
||||
const Byte kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
|
||||
|
||||
const UInt32 kDistLimit2 = 0x101 - 1;
|
||||
*/
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -1,310 +0,0 @@
|
||||
// Archive/Cab/LZXDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LZXDecoder.h"
|
||||
|
||||
#include "Common/Defs.h"
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NLZX {
|
||||
|
||||
static const UInt32 kHistorySize = (1 << 21);
|
||||
|
||||
CDecoder::CDecoder()
|
||||
{
|
||||
m_i86TranslationOutStreamSpec = new Ci86TranslationOutStream;
|
||||
m_i86TranslationOutStream = m_i86TranslationOutStreamSpec;
|
||||
}
|
||||
|
||||
void CDecoder::ReleaseStreams()
|
||||
{
|
||||
m_OutWindowStream.ReleaseStream();
|
||||
m_InBitStream.ReleaseStream();
|
||||
m_i86TranslationOutStreamSpec->ReleaseStream();
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::Flush()
|
||||
{
|
||||
RINOK(m_OutWindowStream.Flush());
|
||||
return m_i86TranslationOutStreamSpec->Flush();
|
||||
}
|
||||
|
||||
void CDecoder::ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols)
|
||||
{
|
||||
Byte levelLevels[kLevelTableSize];
|
||||
UInt32 i;
|
||||
for (i = 0; i < kLevelTableSize; i++)
|
||||
levelLevels[i] = Byte(m_InBitStream.ReadBits(kNumBitsForPreTreeLevel));
|
||||
m_LevelDecoder.SetCodeLengths(levelLevels);
|
||||
for (i = 0; i < numSymbols;)
|
||||
{
|
||||
UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
|
||||
if (number <= kNumHuffmanBits)
|
||||
newLevels[i++] = Byte((17 + lastLevels[i] - number) % (kNumHuffmanBits + 1));
|
||||
else if (number == kLevelSymbolZeros || number == kLevelSymbolZerosBig)
|
||||
{
|
||||
int num;
|
||||
if (number == kLevelSymbolZeros)
|
||||
num = kLevelSymbolZerosStartValue +
|
||||
m_InBitStream.ReadBits(kLevelSymbolZerosNumBits);
|
||||
else
|
||||
num = kLevelSymbolZerosBigStartValue +
|
||||
m_InBitStream.ReadBits(kLevelSymbolZerosBigNumBits);
|
||||
for (;num > 0 && i < numSymbols; num--, i++)
|
||||
newLevels[i] = 0;
|
||||
}
|
||||
else if (number == kLevelSymbolSame)
|
||||
{
|
||||
int num = kLevelSymbolSameStartValue + m_InBitStream.ReadBits(kLevelSymbolSameNumBits);
|
||||
UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
|
||||
if (number > kNumHuffmanBits)
|
||||
throw "bad data";
|
||||
Byte symbol = Byte((17 + lastLevels[i] - number) % (kNumHuffmanBits + 1));
|
||||
for (; num > 0 && i < numSymbols; num--, i++)
|
||||
newLevels[i] = symbol;
|
||||
}
|
||||
else
|
||||
throw "bad data";
|
||||
}
|
||||
|
||||
memmove(lastLevels, newLevels, numSymbols);
|
||||
}
|
||||
|
||||
void CDecoder::ReadTables(void)
|
||||
{
|
||||
int blockType = m_InBitStream.ReadBits(NBlockType::kNumBits);
|
||||
|
||||
if (blockType != NBlockType::kVerbatim && blockType != NBlockType::kAligned &&
|
||||
blockType != NBlockType::kUncompressed)
|
||||
throw "bad data";
|
||||
|
||||
m_UnCompressedBlockSize = m_InBitStream.ReadBitsBig(kUncompressedBlockSizeNumBits);
|
||||
|
||||
if (blockType == NBlockType::kUncompressed)
|
||||
{
|
||||
m_UncompressedBlock = true;
|
||||
UInt32 bitPos = m_InBitStream.GetBitPosition() % 16;
|
||||
m_InBitStream.ReadBits(16 - bitPos);
|
||||
for (int i = 0; i < kNumRepDistances; i++)
|
||||
{
|
||||
m_RepDistances[i] = 0;
|
||||
for (int j = 0; j < 4; j++)
|
||||
m_RepDistances[i] |= (m_InBitStream.DirectReadByte()) << (8 * j);
|
||||
m_RepDistances[i]--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_UncompressedBlock = false;
|
||||
|
||||
m_AlignIsUsed = (blockType == NBlockType::kAligned);
|
||||
|
||||
Byte newLevels[kMaxTableSize];
|
||||
|
||||
if (m_AlignIsUsed)
|
||||
{
|
||||
for(int i = 0; i < kAlignTableSize; i++)
|
||||
newLevels[i] = m_InBitStream.ReadBits(kNumBitsForAlignLevel);
|
||||
m_AlignDecoder.SetCodeLengths(newLevels);
|
||||
}
|
||||
|
||||
ReadTable(m_LastByteLevels, newLevels, 256);
|
||||
ReadTable(m_LastPosLenLevels, newLevels + 256, m_NumPosLenSlots);
|
||||
for (int i = m_NumPosLenSlots; i < kNumPosSlotLenSlotSymbols; i++)
|
||||
newLevels[256 + i] = 0;
|
||||
m_MainDecoder.SetCodeLengths(newLevels);
|
||||
|
||||
ReadTable(m_LastLenLevels, newLevels, kNumLenSymbols);
|
||||
m_LenDecoder.SetCodeLengths(newLevels);
|
||||
|
||||
}
|
||||
|
||||
class CDecoderFlusher
|
||||
{
|
||||
CDecoder *m_Decoder;
|
||||
public:
|
||||
CDecoderFlusher(CDecoder *decoder): m_Decoder(decoder) {}
|
||||
~CDecoderFlusher()
|
||||
{
|
||||
m_Decoder->Flush();
|
||||
m_Decoder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void CDecoder::ClearPrevLeveles()
|
||||
{
|
||||
memset(m_LastByteLevels, 0, 256);
|
||||
memset(m_LastPosLenLevels, 0, kNumPosSlotLenSlotSymbols);
|
||||
memset(m_LastLenLevels, 0, kNumLenSymbols);
|
||||
};
|
||||
|
||||
|
||||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
UInt64 size = *outSize;
|
||||
|
||||
if (!m_OutWindowStream.Create(kHistorySize))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!m_InBitStream.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
m_OutWindowStream.SetStream(m_i86TranslationOutStream);
|
||||
m_OutWindowStream.Init();
|
||||
|
||||
m_InBitStream.SetStream(inStream);
|
||||
m_InBitStream.Init(m_ReservedSize, m_NumInDataBlocks);
|
||||
|
||||
CDecoderFlusher flusher(this);
|
||||
|
||||
UInt32 uncompressedCFDataBlockSize;
|
||||
bool dataAreCorrect;
|
||||
RINOK(m_InBitStream.ReadBlock(uncompressedCFDataBlockSize, dataAreCorrect));
|
||||
if (!dataAreCorrect)
|
||||
{
|
||||
throw "Data Error";
|
||||
}
|
||||
UInt32 uncompressedCFDataCurrentValue = 0;
|
||||
m_InBitStream.Init();
|
||||
|
||||
ClearPrevLeveles();
|
||||
|
||||
if (m_InBitStream.ReadBits(1) == 0)
|
||||
m_i86TranslationOutStreamSpec->Init(outStream, false, 0);
|
||||
else
|
||||
{
|
||||
UInt32 i86TranslationSize = m_InBitStream.ReadBits(16) << 16;
|
||||
i86TranslationSize |= m_InBitStream.ReadBits(16);
|
||||
m_i86TranslationOutStreamSpec->Init(outStream, true , i86TranslationSize);
|
||||
}
|
||||
|
||||
for(int i = 0 ; i < kNumRepDistances; i++)
|
||||
m_RepDistances[i] = 0;
|
||||
|
||||
UInt64 nowPos64 = 0;
|
||||
while(nowPos64 < size)
|
||||
{
|
||||
if (uncompressedCFDataCurrentValue == uncompressedCFDataBlockSize)
|
||||
{
|
||||
bool dataAreCorrect;
|
||||
RINOK(m_InBitStream.ReadBlock(uncompressedCFDataBlockSize, dataAreCorrect));
|
||||
if (!dataAreCorrect)
|
||||
{
|
||||
throw "Data Error";
|
||||
}
|
||||
m_InBitStream.Init();
|
||||
uncompressedCFDataCurrentValue = 0;
|
||||
}
|
||||
ReadTables();
|
||||
UInt32 nowPos = 0;
|
||||
UInt32 next = (UInt32)MyMin((UInt64)m_UnCompressedBlockSize, size - nowPos64);
|
||||
if (m_UncompressedBlock)
|
||||
{
|
||||
while(nowPos < next)
|
||||
{
|
||||
m_OutWindowStream.PutByte(m_InBitStream.DirectReadByte());
|
||||
nowPos++;
|
||||
uncompressedCFDataCurrentValue++;
|
||||
if (uncompressedCFDataCurrentValue == uncompressedCFDataBlockSize)
|
||||
{
|
||||
bool dataAreCorrect;
|
||||
RINOK(m_InBitStream.ReadBlock(uncompressedCFDataBlockSize, dataAreCorrect));
|
||||
if (!dataAreCorrect)
|
||||
{
|
||||
throw "Data Error";
|
||||
}
|
||||
// m_InBitStream.Init();
|
||||
uncompressedCFDataCurrentValue = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
int bitPos = m_InBitStream.GetBitPosition() % 16;
|
||||
if (bitPos == 8)
|
||||
m_InBitStream.DirectReadByte();
|
||||
m_InBitStream.Normalize();
|
||||
}
|
||||
else for (;nowPos < next;)
|
||||
{
|
||||
if (uncompressedCFDataCurrentValue == uncompressedCFDataBlockSize)
|
||||
{
|
||||
bool dataAreCorrect;
|
||||
RINOK(m_InBitStream.ReadBlock(uncompressedCFDataBlockSize, dataAreCorrect));
|
||||
if (!dataAreCorrect)
|
||||
{
|
||||
throw "Data Error";
|
||||
}
|
||||
m_InBitStream.Init();
|
||||
uncompressedCFDataCurrentValue = 0;
|
||||
}
|
||||
UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
|
||||
if (number < 256)
|
||||
{
|
||||
m_OutWindowStream.PutByte(Byte(number));
|
||||
nowPos++;
|
||||
uncompressedCFDataCurrentValue++;
|
||||
// continue;
|
||||
}
|
||||
else if (number < 256 + m_NumPosLenSlots)
|
||||
{
|
||||
UInt32 posLenSlot = number - 256;
|
||||
UInt32 posSlot = posLenSlot / kNumLenSlots;
|
||||
UInt32 lenSlot = posLenSlot % kNumLenSlots;
|
||||
UInt32 length = 2 + lenSlot;
|
||||
if (lenSlot == kNumLenSlots - 1)
|
||||
length += m_LenDecoder.DecodeSymbol(&m_InBitStream);
|
||||
|
||||
if (posSlot < kNumRepDistances)
|
||||
{
|
||||
UInt32 distance = m_RepDistances[posSlot];
|
||||
m_OutWindowStream.CopyBlock(distance, length);
|
||||
if (posSlot != 0)
|
||||
{
|
||||
m_RepDistances[posSlot] = m_RepDistances[0];
|
||||
m_RepDistances[0] = distance;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 pos = kDistStart[posSlot];
|
||||
UInt32 posDirectBits = kDistDirectBits[posSlot];
|
||||
if (m_AlignIsUsed && posDirectBits >= kNumAlignBits)
|
||||
{
|
||||
pos += (m_InBitStream.ReadBits(posDirectBits - kNumAlignBits) << kNumAlignBits);
|
||||
pos += m_AlignDecoder.DecodeSymbol(&m_InBitStream);
|
||||
}
|
||||
else
|
||||
pos += m_InBitStream.ReadBits(posDirectBits);
|
||||
UInt32 distance = pos - kNumRepDistances;
|
||||
if (distance >= nowPos64 + nowPos)
|
||||
throw 777123;
|
||||
m_OutWindowStream.CopyBlock(distance, length);
|
||||
m_RepDistances[2] = m_RepDistances[1];
|
||||
m_RepDistances[1] = m_RepDistances[0];
|
||||
m_RepDistances[0] = distance;
|
||||
}
|
||||
nowPos += length;
|
||||
uncompressedCFDataCurrentValue += length;
|
||||
}
|
||||
else
|
||||
throw 98112823;
|
||||
}
|
||||
if (progress != NULL)
|
||||
{
|
||||
UInt64 inSize = m_InBitStream.GetProcessedSize();
|
||||
UInt64 outSize = nowPos64 + nowPos;
|
||||
RINOK(progress->SetRatioInfo(&inSize, &outSize));
|
||||
}
|
||||
nowPos64 += nowPos;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}}}
|
||||
@@ -1,95 +0,0 @@
|
||||
// Archive/Cab/LZXDecoder.h
|
||||
|
||||
#ifndef __ARCHIVE_CAB_LZXDECODER_H
|
||||
#define __ARCHIVE_CAB_LZXDECODER_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
|
||||
#include "../../Compress/Huffman/HuffmanDecoder.h"
|
||||
#include "../../Compress/LZ/LZOutWindow.h"
|
||||
|
||||
#include "LZXExtConst.h"
|
||||
#include "LZXBitDecoder.h"
|
||||
|
||||
#include "LZXi86Converter.h"
|
||||
#include "LZXConst.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NLZX {
|
||||
|
||||
const int kMainTableSize = 256 + kNumPosSlotLenSlotSymbols;
|
||||
|
||||
class CDecoder :
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLZOutWindow m_OutWindowStream;
|
||||
NBitStream::CDecoder m_InBitStream;
|
||||
|
||||
NCompress::NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
|
||||
NCompress::NHuffman::CDecoder<kNumHuffmanBits, kNumLenSymbols> m_LenDecoder;
|
||||
NCompress::NHuffman::CDecoder<kNumHuffmanBits, kAlignTableSize> m_AlignDecoder;
|
||||
NCompress::NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
|
||||
|
||||
UInt32 m_RepDistances[kNumRepDistances];
|
||||
|
||||
Byte m_LastByteLevels[256];
|
||||
Byte m_LastPosLenLevels[kNumPosSlotLenSlotSymbols];
|
||||
Byte m_LastLenLevels[kNumLenSymbols];
|
||||
|
||||
UInt32 m_DictionarySizePowerOf2;
|
||||
UInt32 m_NumPosSlots;
|
||||
UInt32 m_NumPosLenSlots;
|
||||
|
||||
// bool m_i86PreprocessingUsed;
|
||||
// UInt32 m_i86TranslationSize;
|
||||
|
||||
bool m_UncompressedBlock;
|
||||
bool m_AlignIsUsed;
|
||||
|
||||
UInt32 m_UnCompressedBlockSize;
|
||||
|
||||
Ci86TranslationOutStream *m_i86TranslationOutStreamSpec;
|
||||
CMyComPtr<ISequentialOutStream> m_i86TranslationOutStream;
|
||||
|
||||
Byte m_ReservedSize;
|
||||
UInt32 m_NumInDataBlocks;
|
||||
|
||||
void ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols);
|
||||
void ReadTables();
|
||||
void ClearPrevLeveles();
|
||||
|
||||
public:
|
||||
CDecoder();
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
void ReleaseStreams();
|
||||
STDMETHOD(Flush)();
|
||||
|
||||
// ICompressCoder interface
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
void SetParams(Byte reservedSize, UInt32 numInDataBlocks,
|
||||
UInt32 dictionarySizePowerOf2)
|
||||
{
|
||||
m_ReservedSize = reservedSize;
|
||||
m_NumInDataBlocks = numInDataBlocks;
|
||||
m_DictionarySizePowerOf2 = dictionarySizePowerOf2;
|
||||
if (dictionarySizePowerOf2 < 20)
|
||||
m_NumPosSlots = 30 + (dictionarySizePowerOf2 - 15) * 2;
|
||||
else if (dictionarySizePowerOf2 == 20)
|
||||
m_NumPosSlots = 42;
|
||||
else
|
||||
m_NumPosSlots = 50;
|
||||
m_NumPosLenSlots = m_NumPosSlots * kNumLenSlots;
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -1,30 +0,0 @@
|
||||
// Archive/Cab/LZXExtConst.h
|
||||
|
||||
#ifndef __ARCHIVE_CAB_LZXEXTCONST_H
|
||||
#define __ARCHIVE_CAB_LZXEXTCONST_H
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NLZX {
|
||||
|
||||
const UInt32 kNumRepDistances = 3;
|
||||
|
||||
const UInt32 kNumLenSlots = 8;
|
||||
const UInt32 kMatchMinLen = 2;
|
||||
const UInt32 kNumLenSymbols = 249;
|
||||
const UInt32 kMatchMaxLen = kMatchMinLen + (kNumLenSlots - 1) + kNumLenSymbols - 1;
|
||||
|
||||
const Byte kNumAlignBits = 3;
|
||||
const UInt32 kAlignTableSize = 1 << kNumAlignBits;
|
||||
|
||||
const UInt32 kNumHuffmanBits = 16;
|
||||
|
||||
const int kNumPosSlotSymbols = 50;
|
||||
const int kNumPosSlotLenSlotSymbols = kNumPosSlotSymbols * kNumLenSlots;
|
||||
|
||||
const int kMaxTableSize = 256 + kNumPosSlotLenSlotSymbols;
|
||||
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -1,93 +0,0 @@
|
||||
// Archive/Cab/LZXi86Converter.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/Defs.h"
|
||||
|
||||
#include "LZXi86Converter.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NLZX {
|
||||
|
||||
static const int kResidue = 6 + 4;
|
||||
|
||||
void Ci86TranslationOutStream::MakeTranslation()
|
||||
{
|
||||
if (m_Pos <= kResidue)
|
||||
return;
|
||||
UInt32 numBytes = m_Pos - kResidue;
|
||||
for (UInt32 i = 0; i < numBytes;)
|
||||
{
|
||||
if (m_Buffer[i] == 0xE8)
|
||||
{
|
||||
i++;
|
||||
Int32 absValue = 0;
|
||||
int j;
|
||||
for(j = 0; j < 4; j++)
|
||||
absValue += UInt32(m_Buffer[i + j]) << (j * 8);
|
||||
|
||||
Int32 pos = m_ProcessedSize + i - 1;
|
||||
UInt32 offset;
|
||||
if (absValue < -pos || absValue >= Int32(m_TranslationSize))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = (absValue >= 0) ?
|
||||
absValue - pos :
|
||||
absValue + m_TranslationSize;
|
||||
for(j = 0; j < 4; j++)
|
||||
{
|
||||
m_Buffer[i + j] = Byte(offset & 0xFF);
|
||||
offset >>= 8;
|
||||
}
|
||||
}
|
||||
i += 4;
|
||||
}
|
||||
else
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP Ci86TranslationOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
if (!m_TranslationMode)
|
||||
return m_Stream->Write(data, size, processedSize);
|
||||
|
||||
UInt32 realProcessedSize = 0;
|
||||
|
||||
while (realProcessedSize < size)
|
||||
{
|
||||
UInt32 writeSize = MyMin(size - realProcessedSize, kUncompressedBlockSize - m_Pos);
|
||||
memmove(m_Buffer + m_Pos, (const Byte *)data + realProcessedSize, writeSize);
|
||||
m_Pos += writeSize;
|
||||
realProcessedSize += writeSize;
|
||||
if (m_Pos == kUncompressedBlockSize)
|
||||
{
|
||||
RINOK(Flush());
|
||||
}
|
||||
}
|
||||
if (processedSize != NULL)
|
||||
*processedSize = realProcessedSize;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP Ci86TranslationOutStream::WritePart(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
return Write(data, size, processedSize);
|
||||
}
|
||||
|
||||
HRESULT Ci86TranslationOutStream::Flush()
|
||||
{
|
||||
if (m_Pos == 0)
|
||||
return S_OK;
|
||||
MakeTranslation();
|
||||
RINOK(m_Stream->Write(m_Buffer, m_Pos, NULL));
|
||||
m_ProcessedSize += m_Pos;
|
||||
m_Pos = 0;
|
||||
m_TranslationMode = (m_ProcessedSize < (1 << 30));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}}}
|
||||
@@ -1,50 +0,0 @@
|
||||
// Archive/Cab/LZXi86Converter.h
|
||||
|
||||
#ifndef __ARCHIVE_CAB_LZXI86CONVERTER_H
|
||||
#define __ARCHIVE_CAB_LZXI86CONVERTER_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../IStream.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NLZX {
|
||||
|
||||
const int kUncompressedBlockSize = 1 << 15;
|
||||
|
||||
class Ci86TranslationOutStream:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
bool m_TranslationMode;
|
||||
CMyComPtr<ISequentialOutStream> m_Stream;
|
||||
UInt32 m_ProcessedSize;
|
||||
Byte m_Buffer[kUncompressedBlockSize];
|
||||
UInt32 m_Pos;
|
||||
UInt32 m_TranslationSize;
|
||||
|
||||
void MakeTranslation();
|
||||
public:
|
||||
Ci86TranslationOutStream(): m_Pos(0) {}
|
||||
~Ci86TranslationOutStream() { Flush(); }
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
public:
|
||||
void Init(ISequentialOutStream *outStream, bool translationMode, UInt32 translationSize)
|
||||
{
|
||||
m_Stream = outStream;
|
||||
m_TranslationMode = translationMode;
|
||||
m_TranslationSize = translationSize;
|
||||
m_ProcessedSize = 0;
|
||||
m_Pos = 0;
|
||||
}
|
||||
void ReleaseStream() { m_Stream.Release(); }
|
||||
HRESULT Flush();
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -1,92 +0,0 @@
|
||||
// MSZipConst.h
|
||||
|
||||
#ifndef __MSZIP_CONST_H
|
||||
#define __MSZIP_CONST_H
|
||||
|
||||
#include "MSZipExtConst.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NMSZip {
|
||||
|
||||
const UInt32 kLenTableSize = 29;
|
||||
|
||||
const UInt32 kStaticDistTableSize = 32;
|
||||
const UInt32 kStaticLenTableSize = 31;
|
||||
|
||||
const UInt32 kReadTableNumber = 0x100;
|
||||
const UInt32 kMatchNumber = kReadTableNumber + 1;
|
||||
|
||||
const UInt32 kMainTableSize = kMatchNumber + kLenTableSize; //298;
|
||||
const UInt32 kStaticMainTableSize = kMatchNumber + kStaticLenTableSize; //298;
|
||||
|
||||
const UInt32 kDistTableStart = kMainTableSize;
|
||||
|
||||
const UInt32 kHeapTablesSizesSum = kMainTableSize + kDistTableSize;
|
||||
|
||||
const UInt32 kLevelTableSize = 19;
|
||||
|
||||
const UInt32 kMaxTableSize = kHeapTablesSizesSum; // test it
|
||||
const UInt32 kStaticMaxTableSize = kStaticMainTableSize + kStaticDistTableSize;
|
||||
|
||||
const UInt32 kTableDirectLevels = 16;
|
||||
const UInt32 kTableLevelRepNumber = kTableDirectLevels;
|
||||
const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1;
|
||||
const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
|
||||
|
||||
const UInt32 kLevelMask = 0xF;
|
||||
|
||||
const Byte kLenStart[kLenTableSize] = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224, 255};
|
||||
const Byte kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0};
|
||||
|
||||
|
||||
const UInt32 kDistStart[kDistTableSize] = {0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576};
|
||||
const Byte kDistDirectBits[kDistTableSize] = {0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
|
||||
|
||||
const Byte kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7};
|
||||
|
||||
const Byte kCodeLengthAlphabetOrder[kLevelTableSize] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
const UInt32 kMatchMinLen = 3;
|
||||
const UInt32 kMatchMaxLen = kNumLenCombinations + kMatchMinLen - 1; //255 + 2; test it
|
||||
|
||||
const int kFinalBlockFieldSize = 1;
|
||||
|
||||
namespace NFinalBlockField
|
||||
{
|
||||
enum
|
||||
{
|
||||
kNotFinalBlock = 0,
|
||||
kFinalBlock = 1
|
||||
};
|
||||
}
|
||||
|
||||
const int kBlockTypeFieldSize = 2;
|
||||
|
||||
namespace NBlockType
|
||||
{
|
||||
enum
|
||||
{
|
||||
kStored = 0,
|
||||
kFixedHuffman = 1,
|
||||
kDynamicHuffman = 2,
|
||||
kReserved = 3
|
||||
};
|
||||
}
|
||||
|
||||
const UInt32 kDeflateNumberOfLengthCodesFieldSize = 5;
|
||||
const UInt32 kDeflateNumberOfDistanceCodesFieldSize = 5;
|
||||
const UInt32 kDeflateNumberOfLevelCodesFieldSize = 4;
|
||||
|
||||
const UInt32 kDeflateNumberOfLitLenCodesMin = 257;
|
||||
|
||||
const UInt32 kDeflateNumberOfDistanceCodesMin = 1;
|
||||
const UInt32 kDeflateNumberOfLevelCodesMin = 4;
|
||||
|
||||
const UInt32 kDeflateLevelCodeFieldSize = 3;
|
||||
|
||||
const UInt32 kDeflateStoredBlockLengthFieldSizeSize = 16;
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -1,268 +0,0 @@
|
||||
// Archive/Cab/MSZipDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "MSZipDecoder.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NMSZip {
|
||||
|
||||
CDecoder::CDecoder(){}
|
||||
|
||||
HRESULT CDecoder::Flush()
|
||||
{
|
||||
return m_OutWindowStream.Flush();
|
||||
}
|
||||
|
||||
void CDecoder::ReleaseStreams()
|
||||
{
|
||||
m_OutWindowStream.ReleaseStream();
|
||||
m_InBitStream.ReleaseStream();
|
||||
}
|
||||
|
||||
void CDecoder::DeCodeLevelTable(Byte *newLevels, int numLevels)
|
||||
{
|
||||
int i = 0;
|
||||
while (i < numLevels)
|
||||
{
|
||||
UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
|
||||
if (number < kTableDirectLevels)
|
||||
newLevels[i++] = Byte(number);
|
||||
else
|
||||
{
|
||||
if (number == kTableLevelRepNumber)
|
||||
{
|
||||
int t = m_InBitStream.ReadBits(2) + 3;
|
||||
for (int reps = t; reps > 0 && i < numLevels ; reps--, i++)
|
||||
newLevels[i] = newLevels[i - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
int num;
|
||||
if (number == kTableLevel0Number)
|
||||
num = m_InBitStream.ReadBits(3) + 3;
|
||||
else
|
||||
num = m_InBitStream.ReadBits(7) + 11;
|
||||
for (;num > 0 && i < numLevels; num--)
|
||||
newLevels[i++] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDecoder::ReadTables(void)
|
||||
{
|
||||
if(m_FinalBlock) // test it
|
||||
throw CDecoderException(CDecoderException::kData);
|
||||
|
||||
m_FinalBlock = (m_InBitStream.ReadBits(kFinalBlockFieldSize) == NFinalBlockField::kFinalBlock);
|
||||
|
||||
int blockType = m_InBitStream.ReadBits(kBlockTypeFieldSize);
|
||||
|
||||
switch(blockType)
|
||||
{
|
||||
case NBlockType::kStored:
|
||||
{
|
||||
m_StoredMode = true;
|
||||
UInt32 currentBitPosition = m_InBitStream.GetBitPosition();
|
||||
UInt32 numBitsForAlign = currentBitPosition > 0 ? (8 - currentBitPosition): 0;
|
||||
if (numBitsForAlign > 0)
|
||||
m_InBitStream.ReadBits(numBitsForAlign);
|
||||
m_StoredBlockSize = m_InBitStream.ReadBits(kDeflateStoredBlockLengthFieldSizeSize);
|
||||
WORD onesComplementReverse = ~WORD(m_InBitStream.ReadBits(kDeflateStoredBlockLengthFieldSizeSize));
|
||||
if (m_StoredBlockSize != onesComplementReverse)
|
||||
throw CDecoderException(CDecoderException::kData);
|
||||
break;
|
||||
}
|
||||
case NBlockType::kFixedHuffman:
|
||||
case NBlockType::kDynamicHuffman:
|
||||
{
|
||||
m_StoredMode = false;
|
||||
Byte litLenLevels[kStaticMainTableSize];
|
||||
Byte distLevels[kStaticDistTableSize];
|
||||
if (blockType == NBlockType::kFixedHuffman)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Leteral / length levels
|
||||
for (i = 0; i < 144; i++)
|
||||
litLenLevels[i] = 8;
|
||||
for (; i < 256; i++)
|
||||
litLenLevels[i] = 9;
|
||||
for (; i < 280; i++)
|
||||
litLenLevels[i] = 7;
|
||||
for (; i < 288; i++) /* make a complete, but wrong code set */
|
||||
litLenLevels[i] = 8;
|
||||
|
||||
// Distance levels
|
||||
for (i = 0; i < kStaticDistTableSize; i++) // test it: infozip only use kDistTableSize
|
||||
distLevels[i] = 5;
|
||||
}
|
||||
else // in case when (blockType == kDeflateBlockTypeFixedHuffman)
|
||||
{
|
||||
int numLitLenLevels = m_InBitStream.ReadBits(kDeflateNumberOfLengthCodesFieldSize) +
|
||||
kDeflateNumberOfLitLenCodesMin;
|
||||
int numDistLevels = m_InBitStream.ReadBits(kDeflateNumberOfDistanceCodesFieldSize) +
|
||||
kDeflateNumberOfDistanceCodesMin;
|
||||
int numLevelCodes = m_InBitStream.ReadBits(kDeflateNumberOfLevelCodesFieldSize) +
|
||||
kDeflateNumberOfLevelCodesMin;
|
||||
|
||||
int numLevels;
|
||||
numLevels = kHeapTablesSizesSum;
|
||||
|
||||
Byte levelLevels[kLevelTableSize];
|
||||
int i;
|
||||
for (i = 0; i < kLevelTableSize; i++)
|
||||
{
|
||||
int position = kCodeLengthAlphabetOrder[i];
|
||||
if(i < numLevelCodes)
|
||||
levelLevels[position] = Byte(m_InBitStream.ReadBits(kDeflateLevelCodeFieldSize));
|
||||
else
|
||||
levelLevels[position] = 0;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
m_LevelDecoder.SetCodeLengths(levelLevels);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
throw CDecoderException(CDecoderException::kData);
|
||||
}
|
||||
|
||||
Byte tmpLevels[kStaticMaxTableSize];
|
||||
DeCodeLevelTable(tmpLevels, numLitLenLevels + numDistLevels);
|
||||
|
||||
memmove(litLenLevels, tmpLevels, numLitLenLevels);
|
||||
memset(litLenLevels + numLitLenLevels, 0,
|
||||
kStaticMainTableSize - numLitLenLevels);
|
||||
|
||||
memmove(distLevels, tmpLevels + numLitLenLevels, numDistLevels);
|
||||
memset(distLevels + numDistLevels, 0, kStaticDistTableSize - numDistLevels);
|
||||
}
|
||||
try
|
||||
{
|
||||
m_MainDecoder.SetCodeLengths(litLenLevels);
|
||||
m_DistDecoder.SetCodeLengths(distLevels);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
throw CDecoderException(CDecoderException::kData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw CDecoderException(CDecoderException::kData);
|
||||
}
|
||||
}
|
||||
|
||||
class CCoderReleaser
|
||||
{
|
||||
CDecoder *m_Coder;
|
||||
public:
|
||||
CCoderReleaser(CDecoder *aCoder): m_Coder(aCoder) {}
|
||||
~CCoderReleaser()
|
||||
{
|
||||
m_Coder->Flush();
|
||||
m_Coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
|
||||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
UInt64 size = *outSize;
|
||||
|
||||
if (!m_OutWindowStream.Create(kHistorySize))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!m_InBitStream.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
m_OutWindowStream.SetStream(outStream);
|
||||
m_OutWindowStream.Init(false);
|
||||
|
||||
m_InBitStream.SetStream(inStream);
|
||||
m_InBitStream.InitMain(m_ReservedSize, m_NumInDataBlocks);
|
||||
CCoderReleaser coderReleaser(this);
|
||||
|
||||
UInt64 nowPos = 0;
|
||||
while(nowPos < size)
|
||||
{
|
||||
if (progress != NULL)
|
||||
{
|
||||
UInt64 packSize = m_InBitStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&packSize, &nowPos));
|
||||
}
|
||||
UInt32 uncompressedCFDataBlockSize;
|
||||
bool dataAreCorrect;
|
||||
RINOK(m_InBitStream.ReadBlock(uncompressedCFDataBlockSize, dataAreCorrect));
|
||||
if (!dataAreCorrect)
|
||||
{
|
||||
throw "Data Error";
|
||||
}
|
||||
m_InBitStream.Init();
|
||||
if (m_InBitStream.ReadBits(8) != 0x43)
|
||||
throw CDecoderException(CDecoderException::kData);
|
||||
if (m_InBitStream.ReadBits(8) != 0x4B)
|
||||
throw CDecoderException(CDecoderException::kData);
|
||||
UInt32 uncompressedCFDataCurrentValue = 0;
|
||||
m_FinalBlock = false;
|
||||
while (uncompressedCFDataCurrentValue < uncompressedCFDataBlockSize)
|
||||
{
|
||||
ReadTables();
|
||||
if(m_StoredMode)
|
||||
{
|
||||
for (UInt32 i = 0; i < m_StoredBlockSize; i++)
|
||||
m_OutWindowStream.PutByte(Byte(m_InBitStream.ReadBits(8)));
|
||||
nowPos += m_StoredBlockSize;
|
||||
uncompressedCFDataCurrentValue += m_StoredBlockSize;
|
||||
continue;
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
|
||||
|
||||
if (number < 256)
|
||||
{
|
||||
m_OutWindowStream.PutByte(Byte(number));
|
||||
nowPos++;
|
||||
uncompressedCFDataCurrentValue++;
|
||||
continue;
|
||||
}
|
||||
else if (number >= kMatchNumber)
|
||||
{
|
||||
number -= kMatchNumber;
|
||||
UInt32 length = UInt32(kLenStart[number]) + kMatchMinLen;
|
||||
UInt32 numBits;
|
||||
if ((numBits = kLenDirectBits[number]) > 0)
|
||||
length += m_InBitStream.ReadBits(numBits);
|
||||
|
||||
number = m_DistDecoder.DecodeSymbol(&m_InBitStream);
|
||||
UInt32 distance = kDistStart[number] + m_InBitStream.ReadBits(kDistDirectBits[number]);
|
||||
/*
|
||||
if (distance >= nowPos)
|
||||
throw "data error";
|
||||
*/
|
||||
m_OutWindowStream.CopyBlock(distance, length);
|
||||
nowPos += length;
|
||||
uncompressedCFDataCurrentValue += length;
|
||||
}
|
||||
else if (number == kReadTableNumber)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
throw CDecoderException(CDecoderException::kData);
|
||||
}
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}}}
|
||||
@@ -1,85 +0,0 @@
|
||||
// Archive/Cab/MSZipDecoder.h
|
||||
|
||||
#ifndef __ARCHIVE_CAB_DECODER_H
|
||||
#define __ARCHIVE_CAB_DECODER_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
#include "../../Common/LSBFDecoder.h"
|
||||
#include "../../Compress/Huffman/HuffmanDecoder.h"
|
||||
#include "../../Compress/LZ/LZOutWindow.h"
|
||||
|
||||
#include "CabInBuffer.h"
|
||||
#include "MSZipExtConst.h"
|
||||
#include "MSZipConst.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NMSZip {
|
||||
|
||||
class CDecoderException
|
||||
{
|
||||
public:
|
||||
enum ECauseType
|
||||
{
|
||||
kData
|
||||
} m_Cause;
|
||||
CDecoderException(ECauseType aCause): m_Cause(aCause) {}
|
||||
};
|
||||
|
||||
class CMSZipBitDecoder: public NStream::NLSBF::CDecoder<NCab::CInBuffer>
|
||||
{
|
||||
public:
|
||||
void InitMain(Byte reservedSize, UInt32 aNumBlocks)
|
||||
{
|
||||
m_Stream.Init(reservedSize, aNumBlocks);
|
||||
Init();
|
||||
}
|
||||
HRESULT ReadBlock(UInt32 &uncompressedSize, bool &dataAreCorrect)
|
||||
{
|
||||
return m_Stream.ReadBlock(uncompressedSize, dataAreCorrect);
|
||||
}
|
||||
};
|
||||
|
||||
class CDecoder :
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLZOutWindow m_OutWindowStream;
|
||||
CMSZipBitDecoder m_InBitStream;
|
||||
NCompress::NHuffman::CDecoder<kNumHuffmanBits, kStaticMainTableSize> m_MainDecoder;
|
||||
NCompress::NHuffman::CDecoder<kNumHuffmanBits, kStaticDistTableSize> m_DistDecoder;
|
||||
NCompress::NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
|
||||
|
||||
bool m_FinalBlock;
|
||||
bool m_StoredMode;
|
||||
UInt32 m_StoredBlockSize;
|
||||
|
||||
Byte m_ReservedSize;
|
||||
UInt32 m_NumInDataBlocks;
|
||||
|
||||
void DeCodeLevelTable(Byte *newLevels, int numLevels);
|
||||
void ReadTables();
|
||||
public:
|
||||
CDecoder();
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
HRESULT Flush();
|
||||
void ReleaseStreams();
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
void SetParams(Byte reservedSize, UInt32 numInDataBlocks)
|
||||
{
|
||||
m_ReservedSize = reservedSize;
|
||||
m_NumInDataBlocks = numInDataBlocks;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
// DeflateExtConst.h
|
||||
|
||||
#ifndef __DEFLATEEXTCONST_H
|
||||
#define __DEFLATEEXTCONST_H
|
||||
|
||||
#include "Common/Types.h"
|
||||
|
||||
namespace NArchive {
|
||||
namespace NCab {
|
||||
namespace NMSZip {
|
||||
|
||||
const UInt32 kDistTableSize = 30;
|
||||
const UInt32 kHistorySize = 0x8000;
|
||||
const UInt32 kNumLenCombinations = 256;
|
||||
|
||||
const UInt32 kNumHuffmanBits = 15;
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -5,14 +5,10 @@ LIBS = $(LIBS) oleaut32.lib user32.lib
|
||||
|
||||
CAB_OBJS = \
|
||||
$O\DllExports.obj \
|
||||
$O\CabCopyDecoder.obj \
|
||||
$O\CabBlockInStream.obj \
|
||||
$O\CabHandler.obj \
|
||||
$O\CabHeader.obj \
|
||||
$O\CabIn.obj \
|
||||
$O\CabInBuffer.obj \
|
||||
$O\LZXDecoder.obj \
|
||||
$O\LZXi86Converter.obj \
|
||||
$O\MSZipDecoder.obj \
|
||||
|
||||
COMMON_OBJS = \
|
||||
$O\Alloc.obj \
|
||||
@@ -32,6 +28,11 @@ WIN_OBJS = \
|
||||
$O\LSBFDecoder.obj \
|
||||
$O\OutBuffer.obj \
|
||||
$O\ProgressUtils.obj \
|
||||
$O\StreamUtils.obj \
|
||||
|
||||
COMPRESS_LZX_OBJS = \
|
||||
$O\LzxDecoder.obj \
|
||||
$O\Lzx86Converter.obj \
|
||||
|
||||
OBJS = \
|
||||
$O\StdAfx.obj \
|
||||
@@ -39,7 +40,11 @@ OBJS = \
|
||||
$(COMMON_OBJS) \
|
||||
$(WIN_OBJS) \
|
||||
$(7ZIP_COMMON_OBJS) \
|
||||
$(COMPRESS_LZX_OBJS) \
|
||||
$O\DeflateDecoder.obj \
|
||||
$O\QuantumDecoder.obj \
|
||||
$O\LZOutWindow.obj \
|
||||
$O\CopyCoder.obj \
|
||||
$O\resource.res
|
||||
|
||||
!include "../../../Build.mak"
|
||||
@@ -52,5 +57,14 @@ $(WIN_OBJS): ../../../Windows/$(*B).cpp
|
||||
$(COMPL)
|
||||
$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
|
||||
$(COMPL)
|
||||
$(COMPRESS_LZX_OBJS): ../../Compress/Lzx/$(*B).cpp
|
||||
$(COMPL_O2)
|
||||
$O\DeflateDecoder.obj: ../../Compress/Deflate/$(*B).cpp
|
||||
$(COMPL_O2)
|
||||
$O\QuantumDecoder.obj: ../../Compress/Quantum/$(*B).cpp
|
||||
$(COMPL)
|
||||
$O\LZOutWindow.obj: ../../Compress/LZ/$(*B).cpp
|
||||
$(COMPL)
|
||||
$O\CopyCoder.obj: ../../Compress/Copy/$(*B).cpp
|
||||
$(COMPL)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user