1 diff -Nur lzma/C/7zip/Compress/LZMA/LZMADecoder.cpp lzma.patched/C/7zip/Compress/LZMA/LZMADecoder.cpp
2 --- lzma/C/7zip/Compress/LZMA/LZMADecoder.cpp 2005-09-22 10:55:34.000000000 +0200
3 +++ lzma.patched/C/7zip/Compress/LZMA/LZMADecoder.cpp 2006-03-25 11:04:53.000000000 +0100
5 Byte remainder = (Byte)(properties[0] / 9);
\r
6 int lp = remainder % 5;
\r
7 int pb = remainder / 5;
\r
8 - if (pb > NLength::kNumPosStatesBitsMax)
\r
9 - return E_INVALIDARG;
\r
10 - _posStateMask = (1 << pb) - 1;
\r
11 UInt32 dictionarySize = 0;
\r
12 for (int i = 0; i < 4; i++)
\r
13 dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);
\r
14 + return SetDecoderPropertiesRaw(lc, lp, pb, dictionarySize);
\r
17 +STDMETHODIMP CDecoder::SetDecoderPropertiesRaw(int lc, int lp, int pb, UInt32 dictionarySize)
\r
19 + if (pb > NLength::kNumPosStatesBitsMax)
\r
20 + return E_INVALIDARG;
\r
21 + _posStateMask = (1 << pb) - 1;
\r
22 if (!_outWindowStream.Create(dictionarySize))
\r
23 return E_OUTOFMEMORY;
\r
24 if (!_literalDecoder.Create(lp, lc))
\r
25 diff -Nur lzma/C/7zip/Compress/LZMA/LZMADecoder.h lzma.patched/C/7zip/Compress/LZMA/LZMADecoder.h
26 --- lzma/C/7zip/Compress/LZMA/LZMADecoder.h 2005-09-19 08:10:06.000000000 +0200
27 +++ lzma.patched/C/7zip/Compress/LZMA/LZMADecoder.h 2006-03-25 11:04:53.000000000 +0100
29 ICompressProgressInfo *progress);
\r
31 STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
\r
32 + STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);
\r
34 STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
\r
36 diff -Nur lzma/C/7zip/Compress/LZMA_Lib/makefile lzma.patched/C/7zip/Compress/LZMA_Lib/makefile
37 --- lzma/C/7zip/Compress/LZMA_Lib/makefile 1970-01-01 01:00:00.000000000 +0100
38 +++ lzma.patched/C/7zip/Compress/LZMA_Lib/makefile 2006-03-25 11:29:46.000000000 +0100
44 +CFLAGS = -c -I ../../../
58 + 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 +StreamUtils.o: ../../Common/StreamUtils.cpp
97 + $(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp
99 +FileStreams.o: ../../Common/FileStreams.cpp
100 + $(CXX) $(CFLAGS) ../../Common/FileStreams.cpp
102 +Alloc.o: ../../../Common/Alloc.cpp
103 + $(CXX) $(CFLAGS) ../../../Common/Alloc.cpp
105 +C_FileIO.o: ../../../Common/C_FileIO.cpp
106 + $(CXX) $(CFLAGS) ../../../Common/C_FileIO.cpp
108 +CommandLineParser.o: ../../../Common/CommandLineParser.cpp
109 + $(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp
111 +CRC.o: ../../../Common/CRC.cpp
112 + $(CXX) $(CFLAGS) ../../../Common/CRC.cpp
114 +MyWindows.o: ../../../Common/MyWindows.cpp
115 + $(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
117 +String.o: ../../../Common/String.cpp
118 + $(CXX) $(CFLAGS) ../../../Common/String.cpp
120 +StringConvert.o: ../../../Common/StringConvert.cpp
121 + $(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp
123 +StringToInt.o: ../../../Common/StringToInt.cpp
124 + $(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp
126 +Vector.o: ../../../Common/Vector.cpp
127 + $(CXX) $(CFLAGS) ../../../Common/Vector.cpp
130 + -$(RM) $(PROG) $(OBJS)
132 diff -Nur lzma/C/7zip/Compress/LZMA_Lib/ZLib.cpp lzma.patched/C/7zip/Compress/LZMA_Lib/ZLib.cpp
133 --- lzma/C/7zip/Compress/LZMA_Lib/ZLib.cpp 1970-01-01 01:00:00.000000000 +0100
134 +++ lzma.patched/C/7zip/Compress/LZMA_Lib/ZLib.cpp 2006-03-25 11:04:53.000000000 +0100
137 + * lzma zlib simplified wrapper
\r
139 + * Copyright (c) 2005-2006 Oleg I. Vdovikin <oleg@cs.msu.su>
\r
141 + * This library is free software; you can redistribute
\r
142 + * it and/or modify it under the terms of the GNU Lesser
\r
143 + * General Public License as published by the Free Software
\r
144 + * Foundation; either version 2.1 of the License, or
\r
145 + * (at your option) any later version.
\r
147 + * This library is distributed in the hope that it will be
\r
148 + * useful, but WITHOUT ANY WARRANTY; without even the implied
\r
149 + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
150 + * PURPOSE. See the GNU Lesser General Public License
\r
151 + * for more details.
\r
153 + * You should have received a copy of the GNU Lesser General
\r
154 + * Public License along with this library; if not, write to
\r
155 + * the Free Software Foundation, Inc., 59 Temple Place,
\r
156 + * Suite 330, Boston, MA 02111-1307 USA
\r
160 + * default values for encoder/decoder used by wrapper
\r
170 +#include <initguid.h>
\r
175 +#include "../../../Common/MyWindows.h"
\r
176 +#include "../LZMA/LZMADecoder.h"
\r
177 +#include "../LZMA/LZMAEncoder.h"
\r
179 +#define STG_E_SEEKERROR ((HRESULT)0x80030019L)
\r
180 +#define STG_E_MEDIUMFULL ((HRESULT)0x80030070L)
\r
182 +class CInMemoryStream:
\r
183 + public IInStream,
\r
184 + public IStreamGetSize,
\r
185 + public CMyUnknownImp
\r
188 + CInMemoryStream(const Bytef *data, UInt64 size) :
\r
189 + m_data(data), m_size(size), m_offset(0) {}
\r
191 + virtual ~CInMemoryStream() {}
\r
193 + MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)
\r
195 + STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)
\r
197 + if (size > m_size - m_offset)
\r
198 + size = m_size - m_offset;
\r
201 + memcpy(data, m_data + m_offset, size);
\r
204 + m_offset += size;
\r
206 + if (processedSize)
\r
207 + *processedSize = size;
\r
212 + STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)
\r
214 + return Read(data, size, processedSize);
\r
217 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
\r
221 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
\r
222 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
\r
223 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
\r
224 + else return STG_E_INVALIDFUNCTION;
\r
226 + if (_offset < 0 || _offset > m_size)
\r
227 + return STG_E_SEEKERROR;
\r
229 + m_offset = _offset;
\r
232 + *newPosition = m_offset;
\r
237 + STDMETHOD(GetSize)(UInt64 *size)
\r
243 + const Bytef *m_data;
\r
248 +class COutMemoryStream:
\r
249 + public IOutStream,
\r
250 + public CMyUnknownImp
\r
253 + COutMemoryStream(Bytef *data, UInt64 maxsize) :
\r
254 + m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}
\r
255 + virtual ~COutMemoryStream() {}
\r
257 + MY_UNKNOWN_IMP1(IOutStream)
\r
259 + STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)
\r
261 + if (size > m_maxsize - m_offset)
\r
262 + size = m_maxsize - m_offset;
\r
265 + memcpy(m_data + m_offset, data, size);
\r
268 + m_offset += size;
\r
270 + if (m_offset > m_size)
\r
271 + m_size = m_offset;
\r
273 + if (processedSize)
\r
274 + *processedSize = size;
\r
279 + STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)
\r
281 + return Write(data, size, processedSize);
\r
284 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
\r
288 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
\r
289 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
\r
290 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
\r
291 + else return STG_E_INVALIDFUNCTION;
\r
293 + if (_offset < 0 || _offset > m_maxsize)
\r
294 + return STG_E_SEEKERROR;
\r
296 + m_offset = _offset;
\r
299 + *newPosition = m_offset;
\r
304 + STDMETHOD(SetSize)(Int64 newSize)
\r
306 + if ((UInt64)newSize > m_maxsize)
\r
307 + return STG_E_MEDIUMFULL;
\r
314 + UInt64 m_maxsize;
\r
318 +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
\r
319 + const Bytef *source, uLong sourceLen,
\r
322 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
\r
323 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
\r
325 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
\r
326 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
\r
328 + NCompress::NLZMA::CEncoder *encoderSpec =
\r
329 + new NCompress::NLZMA::CEncoder;
\r
330 + CMyComPtr<ICompressCoder> encoder = encoderSpec;
\r
332 + PROPID propIDs[] =
\r
334 + NCoderPropID::kDictionarySize,
\r
335 + NCoderPropID::kPosStateBits,
\r
336 + NCoderPropID::kLitContextBits,
\r
337 + NCoderPropID::kLitPosBits,
\r
338 + NCoderPropID::kAlgorithm,
\r
339 + NCoderPropID::kNumFastBytes,
\r
340 + NCoderPropID::kMatchFinder,
\r
341 + NCoderPropID::kEndMarker
\r
343 + const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
\r
345 + PROPVARIANT properties[kNumProps];
\r
346 + for (int p = 0; p < 6; p++)
\r
347 + properties[p].vt = VT_UI4;
\r
348 + properties[0].ulVal = UInt32(1 << (level + 14));
\r
349 + properties[1].ulVal = UInt32(ZLIB_PB);
\r
350 + properties[2].ulVal = UInt32(ZLIB_LC); // for normal files
\r
351 + properties[3].ulVal = UInt32(ZLIB_LP); // for normal files
\r
352 + properties[4].ulVal = UInt32(2);
\r
353 + properties[5].ulVal = UInt32(128);
\r
355 + properties[6].vt = VT_BSTR;
\r
356 + properties[6].bstrVal = (BSTR)(const wchar_t *)L"BT4";
\r
358 + properties[7].vt = VT_BOOL;
\r
359 + properties[7].boolVal = VARIANT_TRUE;
\r
361 + if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
\r
362 + return Z_MEM_ERROR; // should not happen
\r
364 + HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
\r
365 + if (result == E_OUTOFMEMORY)
\r
367 + return Z_MEM_ERROR;
\r
369 + else if (result != S_OK)
\r
371 + return Z_BUF_ERROR; // should not happen
\r
375 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
\r
376 + *destLen = fileSize;
\r
381 +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
\r
382 + const Bytef *source, uLong sourceLen))
\r
384 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
\r
385 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
\r
387 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
\r
388 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
\r
390 + NCompress::NLZMA::CDecoder *decoderSpec =
\r
391 + new NCompress::NLZMA::CDecoder;
\r
392 + CMyComPtr<ICompressCoder> decoder = decoderSpec;
\r
394 + if (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC,
\r
395 + ZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;
\r
397 + UInt64 fileSize = *destLen;
\r
399 + if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
\r
401 + return Z_DATA_ERROR;
\r
404 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
\r
405 + *destLen = fileSize;
\r