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);
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 if (!_outWindowStream.Create(dictionarySize))
24 if (!_literalDecoder.Create(lp, lc))
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);
31 STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
32 + STDMETHOD(SetDecoderPropertiesRaw)(int lc, int lp, int pb, UInt32 dictionarySize);
34 STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
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
139 + * Copyright (c) 2005-2006 Oleg I. Vdovikin <oleg@cs.msu.su>
141 + * This library is free software; you can redistribute
142 + * it and/or modify it under the terms of the GNU Lesser
143 + * General Public License as published by the Free Software
144 + * Foundation; either version 2.1 of the License, or
145 + * (at your option) any later version.
147 + * This library is distributed in the hope that it will be
148 + * useful, but WITHOUT ANY WARRANTY; without even the implied
149 + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
150 + * PURPOSE. See the GNU Lesser General Public License
151 + * for more details.
153 + * You should have received a copy of the GNU Lesser General
154 + * Public License along with this library; if not, write to
155 + * the Free Software Foundation, Inc., 59 Temple Place,
156 + * Suite 330, Boston, MA 02111-1307 USA
160 + * default values for encoder/decoder used by wrapper
170 +#include <initguid.h>
175 +#include "../../../Common/MyWindows.h"
176 +#include "../LZMA/LZMADecoder.h"
177 +#include "../LZMA/LZMAEncoder.h"
179 +#define STG_E_SEEKERROR ((HRESULT)0x80030019L)
180 +#define STG_E_MEDIUMFULL ((HRESULT)0x80030070L)
182 +class CInMemoryStream:
184 + public IStreamGetSize,
185 + public CMyUnknownImp
188 + CInMemoryStream(const Bytef *data, UInt64 size) :
189 + m_data(data), m_size(size), m_offset(0) {}
191 + virtual ~CInMemoryStream() {}
193 + MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)
195 + STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize)
197 + if (size > m_size - m_offset)
198 + size = m_size - m_offset;
201 + memcpy(data, m_data + m_offset, size);
207 + *processedSize = size;
212 + STDMETHOD(ReadPart)(void *data, UInt32 size, UInt32 *processedSize)
214 + return Read(data, size, processedSize);
217 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
221 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
222 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
223 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
224 + else return STG_E_INVALIDFUNCTION;
226 + if (_offset < 0 || _offset > m_size)
227 + return STG_E_SEEKERROR;
229 + m_offset = _offset;
232 + *newPosition = m_offset;
237 + STDMETHOD(GetSize)(UInt64 *size)
243 + const Bytef *m_data;
248 +class COutMemoryStream:
250 + public CMyUnknownImp
253 + COutMemoryStream(Bytef *data, UInt64 maxsize) :
254 + m_data(data), m_size(0), m_maxsize(maxsize), m_offset(0) {}
255 + virtual ~COutMemoryStream() {}
257 + MY_UNKNOWN_IMP1(IOutStream)
259 + STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize)
261 + if (size > m_maxsize - m_offset)
262 + size = m_maxsize - m_offset;
265 + memcpy(m_data + m_offset, data, size);
270 + if (m_offset > m_size)
274 + *processedSize = size;
279 + STDMETHOD(WritePart)(const void *data, UInt32 size, UInt32 *processedSize)
281 + return Write(data, size, processedSize);
284 + STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
288 + if (seekOrigin == STREAM_SEEK_SET) _offset = offset;
289 + else if (seekOrigin == STREAM_SEEK_CUR) _offset = m_offset + offset;
290 + else if (seekOrigin == STREAM_SEEK_END) _offset = m_size;
291 + else return STG_E_INVALIDFUNCTION;
293 + if (_offset < 0 || _offset > m_maxsize)
294 + return STG_E_SEEKERROR;
296 + m_offset = _offset;
299 + *newPosition = m_offset;
304 + STDMETHOD(SetSize)(Int64 newSize)
306 + if ((UInt64)newSize > m_maxsize)
307 + return STG_E_MEDIUMFULL;
318 +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
319 + const Bytef *source, uLong sourceLen,
322 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
323 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
325 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
326 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
328 + NCompress::NLZMA::CEncoder *encoderSpec =
329 + new NCompress::NLZMA::CEncoder;
330 + CMyComPtr<ICompressCoder> encoder = encoderSpec;
334 + NCoderPropID::kDictionarySize,
335 + NCoderPropID::kPosStateBits,
336 + NCoderPropID::kLitContextBits,
337 + NCoderPropID::kLitPosBits,
338 + NCoderPropID::kAlgorithm,
339 + NCoderPropID::kNumFastBytes,
340 + NCoderPropID::kMatchFinder,
341 + NCoderPropID::kEndMarker
343 + const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
345 + PROPVARIANT properties[kNumProps];
346 + for (int p = 0; p < 6; p++)
347 + properties[p].vt = VT_UI4;
348 + properties[0].ulVal = UInt32(1 << (level + 14));
349 + properties[1].ulVal = UInt32(ZLIB_PB);
350 + properties[2].ulVal = UInt32(ZLIB_LC); // for normal files
351 + properties[3].ulVal = UInt32(ZLIB_LP); // for normal files
352 + properties[4].ulVal = UInt32(2);
353 + properties[5].ulVal = UInt32(128);
355 + properties[6].vt = VT_BSTR;
356 + properties[6].bstrVal = (BSTR)(const wchar_t *)L"BT4";
358 + properties[7].vt = VT_BOOL;
359 + properties[7].boolVal = VARIANT_TRUE;
361 + if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK)
362 + return Z_MEM_ERROR; // should not happen
364 + HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
365 + if (result == E_OUTOFMEMORY)
367 + return Z_MEM_ERROR;
369 + else if (result != S_OK)
371 + return Z_BUF_ERROR; // should not happen
375 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
376 + *destLen = fileSize;
381 +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
382 + const Bytef *source, uLong sourceLen))
384 + CInMemoryStream *inStreamSpec = new CInMemoryStream(source, sourceLen);
385 + CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
387 + COutMemoryStream *outStreamSpec = new COutMemoryStream(dest, *destLen);
388 + CMyComPtr<ISequentialOutStream> outStream = outStreamSpec;
390 + NCompress::NLZMA::CDecoder *decoderSpec =
391 + new NCompress::NLZMA::CDecoder;
392 + CMyComPtr<ICompressCoder> decoder = decoderSpec;
394 + if (decoderSpec->SetDecoderPropertiesRaw(ZLIB_LC,
395 + ZLIB_LP, ZLIB_PB, (1 << 23)) != S_OK) return Z_DATA_ERROR;
397 + UInt64 fileSize = *destLen;
399 + if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
401 + return Z_DATA_ERROR;
404 + outStreamSpec->Seek(0, STREAM_SEEK_END, &fileSize);
405 + *destLen = fileSize;