1 diff -BurN lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.cpp lzma/SRC/7zip/Compress/LZMA/LZMADecoder.cpp
2 --- lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.cpp 2004-08-25 01:40:48.000000000 +0400
3 +++ lzma/SRC/7zip/Compress/LZMA/LZMADecoder.cpp 2005-01-20 14:47:45.789801629 +0300
5 Byte remainder = (Byte)(properties[0] / 9);
6 int lp = remainder % 5;
7 int pb = remainder / 5;
8 - if (pb > NLength::kNumPosStatesBitsMax)
10 - _posStateMask = (1 << pb) - 1;
11 UInt32 dictionarySize = 0;
12 for (int i = 0; i < 4; i++)
13 dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);
14 + return SetDecoderPropertiesRaw(lc, lp, pb, dictionarySize);
17 +STDMETHODIMP CDecoder::SetDecoderPropertiesRaw(int lc, int lp, int pb, UInt32 dictionarySize)
19 + if (pb > NLength::kNumPosStatesBitsMax)
20 + return E_INVALIDARG;
21 + _posStateMask = (1 << pb) - 1;
22 _dictionarySizeCheck = MyMax(dictionarySize, UInt32(1));
23 UInt32 blockSize = MyMax(_dictionarySizeCheck, UInt32(1 << 12));
24 if (!_outWindowStream.Create(blockSize))
25 diff -BurN lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.h lzma/SRC/7zip/Compress/LZMA/LZMADecoder.h
26 --- lzma406/SRC/7zip/Compress/LZMA/LZMADecoder.h 2004-08-25 01:40:08.000000000 +0400
27 +++ lzma/SRC/7zip/Compress/LZMA/LZMADecoder.h 2005-01-20 13:06:59.081297916 +0300
29 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
30 STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize);
32 + STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);
34 virtual ~CDecoder() {}
37 diff -BurN lzma406/SRC/7zip/Compress/LZMA_Lib/makefile lzma/SRC/7zip/Compress/LZMA_Lib/makefile
38 --- lzma406/SRC/7zip/Compress/LZMA_Lib/makefile 1970-01-01 03:00:00.000000000 +0300
39 +++ lzma/SRC/7zip/Compress/LZMA_Lib/makefile 2005-01-19 13:49:20.000000000 +0300
59 + CommandLineParser.o \
70 + $(AR) r $(PROG) $(OBJS)
73 + $(CXX) $(CFLAGS) ZLib.cpp
75 +LZMADecoder.o: ../LZMA/LZMADecoder.cpp
76 + $(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp
78 +LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp
79 + $(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp
81 +LZInWindow.o: ../LZ/LZInWindow.cpp
82 + $(CXX) $(CFLAGS) ../LZ/LZInWindow.cpp
84 +LZOutWindow.o: ../LZ/LZOutWindow.cpp
85 + $(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp
87 +RangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp
88 + $(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp
90 +InBuffer.o: ../../Common/InBuffer.cpp
91 + $(CXX) $(CFLAGS) ../../Common/InBuffer.cpp
93 +OutBuffer.o: ../../Common/OutBuffer.cpp
94 + $(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp
96 +FileStreams.o: ../../Common/FileStreams.cpp
97 + $(CXX) $(CFLAGS) ../../Common/FileStreams.cpp
99 +Alloc.o: ../../../Common/Alloc.cpp
100 + $(CXX) $(CFLAGS) ../../../Common/Alloc.cpp
102 +C_FileIO.o: ../../../Common/C_FileIO.cpp
103 + $(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp
105 +CommandLineParser.o: ../../../Common/CommandLineParser.cpp
106 + $(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp
108 +CRC.o: ../../../Common/CRC.cpp
109 + $(CXX) $(CFLAGS) ../../../Common/CRC.cpp
111 +MyWindows.o: ../../../Common/MyWindows.cpp
112 + $(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
114 +String.o: ../../../Common/String.cpp
115 + $(CXX) $(CFLAGS) ../../../Common/String.cpp
117 +StringConvert.o: ../../../Common/StringConvert.cpp
118 + $(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp
120 +StringToInt.o: ../../../Common/StringToInt.cpp
121 + $(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp
123 +Vector.o: ../../../Common/Vector.cpp
124 + $(CXX) $(CFLAGS) ../../../Common/Vector.cpp
127 + -$(RM) $(PROG) $(OBJS)
129 diff -BurN lzma406/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp lzma/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp
130 --- lzma406/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp 1970-01-01 03:00:00.000000000 +0300
131 +++ lzma/SRC/7zip/Compress/LZMA_Lib/ZLib.cpp 2005-01-20 15:01:18.439221129 +0300
134 + * lzma zlib simplified wrapper
136 + * Copyright (c) 2005 Oleg I. Vdovikin <oleg@cs.msu.su>
138 + * This library is free software; you can redistribute
139 + * it and/or modify it under the terms of the GNU Lesser
140 + * General Public License as published by the Free Software
141 + * Foundation; either version 2.1 of the License, or
142 + * (at your option) any later version.
144 + * This library is distributed in the hope that it will be
145 + * useful, but WITHOUT ANY WARRANTY; without even the implied
146 + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
147 + * PURPOSE. See the GNU Lesser General Public License
148 + * for more details.
150 + * You should have received a copy of the GNU Lesser General
151 + * Public License along with this library; if not, write to
152 + * the Free Software Foundation, Inc., 59 Temple Place,
153 + * Suite 330, Boston, MA 02111-1307 USA
157 + * default values for encoder/decoder used by wrapper
167 +#include <initguid.h>
172 +#include "../../../Common/MyWindows.h"
173 +#include "../LZMA/LZMADecoder.h"
174 +#include "../LZMA/LZMAEncoder.h"
176 +#define STG_E_SEEKERROR ((HRESULT)0x80030019L)
177 +#define STG_E_MEDIUMFULL ((HRESULT)0x80030070L)
179 +class CInMemoryStream:
181 + public IStreamGetSize,
182 + public CMyUnknownImp
185 + CInMemoryStream(const Bytef *data, UInt64 size) :
186 + m_data(data), m_size(size), m_offset(0) {}
188 + virtual ~CInMemoryStream() {}
190 + MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)
192 + STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)
194 + if (size > m_size - m_offset)
195 + size = m_size - m_offset;
198 + memcpy(data, m_data + m_offset, size);
204 + *processedSize = size;
209 + STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)
211 + return Read(data, size, processedSize);
214 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
218 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
219 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
220 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
221 + else return STG_E_INVALIDFUNCTION;
223 + if (_offset < 0 || _offset > m_size)
224 + return STG_E_SEEKERROR;
226 + m_offset = _offset;
229 + *newPosition = m_offset;
234 + STDMETHOD(GetSize)(UInt64 *size)
240 + const Bytef *m_data;
245 +class COutMemoryStream:
247 + public CMyUnknownImp
250 + COutMemoryStream(Bytef *data, UInt64 maxsize) :
251 + m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}
252 + virtual ~COutMemoryStream() {}
254 + MY_UNKNOWN_IMP1(IOutStream)
256 + STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)
258 + if (size > m_maxsize - m_offset)
259 + size = m_maxsize - m_offset;
262 + memcpy(m_data + m_offset, data, size);
267 + if (m_offset > m_size)
271 + *processedSize = size;
276 + STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)
278 + return Write(data, size, processedSize);
281 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
285 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
286 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
287 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
288 + else return STG_E_INVALIDFUNCTION;
290 + if (_offset < 0 || _offset > m_maxsize)
291 + return STG_E_SEEKERROR;
293 + m_offset = _offset;
296 + *newPosition = m_offset;
301 + STDMETHOD(SetSize)(Int64 newSize)
303 + if ((UInt64)newSize > m_maxsize)
304 + return STG_E_MEDIUMFULL;
315 +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
316 + const Bytef *source, uLong sourceLen,
319 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
320 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
322 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
323 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
325 + NCompress::NLZMA::CEncoder *encoderSpec =
326 + new NCompress::NLZMA::CEncoder;
327 + CMyComPtr<ICompressCoder> encoder = encoderSpec;
331 + NCoderPropID::kDictionarySize,
332 + NCoderPropID::kPosStateBits,
333 + NCoderPropID::kLitContextBits,
334 + NCoderPropID::kLitPosBits,
335 + NCoderPropID::kAlgorithm,
336 + NCoderPropID::kNumFastBytes,
337 + NCoderPropID::kMatchFinder,
338 + NCoderPropID::kEndMarker
340 + const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
342 + PROPVARIANT properties[kNumProps];
343 + for (int p = 0; p < 6; p++)
344 + properties[p].vt = VT_UI4;
345 + properties[0].ulVal = UInt32(1 << (level + 14));
346 + properties[1].ulVal = UInt32(ZLIB_PB);
347 + properties[2].ulVal = UInt32(ZLIB_LC); // for normal files
348 + properties[3].ulVal = UInt32(ZLIB_LP); // for normal files
349 + properties[4].ulVal = UInt32(2);
350 + properties[5].ulVal = UInt32(128);
352 + properties[6].vt = VT_BSTR;
353 + properties[6].bstrVal = (BSTR)(const wchar_t *)L"BT4";
355 + properties[7].vt = VT_BOOL;
356 + properties[7].boolVal = VARIANT_TRUE;
358 + if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
359 + return Z_MEM_ERROR; // should not happen
361 + HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
362 + if (result == E_OUTOFMEMORY)
364 + return Z_MEM_ERROR;
366 + else if (result != S_OK)
368 + return Z_BUF_ERROR; // should not happen
372 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
373 + *destLen = fileSize;
378 +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
379 + const Bytef *source, uLong sourceLen))
381 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
382 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
384 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
385 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
387 + NCompress::NLZMA::CDecoder *decoderSpec =
388 + new NCompress::NLZMA::CDecoder;
389 + CMyComPtr<ICompressCoder> decoder = decoderSpec;
391 + if (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC,
392 + ZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;
394 + UInt64 fileSize = *destLen;
396 + if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
398 + return Z_DATA_ERROR;
401 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
402 + *destLen = fileSize;