📄 002-lzma_decompress.patch
字号:
Index: linux-2.6.21.7/include/linux/LzmaDecode.h===================================================================--- /dev/null+++ linux-2.6.21.7/include/linux/LzmaDecode.h@@ -0,0 +1,100 @@+/*+ LzmaDecode.h+ LZMA Decoder interface++ LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)+ http://www.7-zip.org/++ LZMA SDK is licensed under two licenses:+ 1) GNU Lesser General Public License (GNU LGPL)+ 2) Common Public License (CPL)+ It means that you can select one of these two licenses and+ follow rules of that license.++ SPECIAL EXCEPTION:+ Igor Pavlov, as the author of this code, expressly permits you to+ statically or dynamically link your code (or bind by name) to the+ interfaces of this file without subjecting your linked code to the+ terms of the CPL or GNU LGPL. Any modifications or additions+ to this file, however, are subject to the LGPL or CPL terms.+*/++#ifndef __LZMADECODE_H+#define __LZMADECODE_H++/* #define _LZMA_IN_CB */+/* Use callback for input data */++/* #define _LZMA_OUT_READ */+/* Use read function for output data */++/* #define _LZMA_PROB32 */+/* It can increase speed on some 32-bit CPUs,+ but memory usage will be doubled in that case */++/* #define _LZMA_LOC_OPT */+/* Enable local speed optimizations inside code */++#ifndef UInt32+#ifdef _LZMA_UINT32_IS_ULONG+#define UInt32 unsigned long+#else+#define UInt32 unsigned int+#endif+#endif++#ifdef _LZMA_PROB32+#define CProb UInt32+#else+#define CProb unsigned short+#endif++#define LZMA_RESULT_OK 0+#define LZMA_RESULT_DATA_ERROR 1+#define LZMA_RESULT_NOT_ENOUGH_MEM 2++#ifdef _LZMA_IN_CB+typedef struct _ILzmaInCallback+{+ int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);+} ILzmaInCallback;+#endif++#define LZMA_BASE_SIZE 1846+#define LZMA_LIT_SIZE 768++/*+bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)+bufferSize += 100 in case of _LZMA_OUT_READ+by default CProb is unsigned short,+but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)+*/++#ifdef _LZMA_OUT_READ+int LzmaDecoderInit(+ unsigned char *buffer, UInt32 bufferSize,+ int lc, int lp, int pb,+ unsigned char *dictionary, UInt32 dictionarySize,+ #ifdef _LZMA_IN_CB+ ILzmaInCallback *inCallback+ #else+ unsigned char *inStream, UInt32 inSize+ #endif+);+#endif++int LzmaDecode(+ unsigned char *buffer,+ #ifndef _LZMA_OUT_READ+ UInt32 bufferSize,+ int lc, int lp, int pb,+ #ifdef _LZMA_IN_CB+ ILzmaInCallback *inCallback,+ #else+ unsigned char *inStream, UInt32 inSize,+ #endif+ #endif+ unsigned char *outStream, UInt32 outSize,+ UInt32 *outSizeProcessed);++#endifIndex: linux-2.6.21.7/lib/LzmaDecode.c===================================================================--- /dev/null+++ linux-2.6.21.7/lib/LzmaDecode.c@@ -0,0 +1,663 @@+/*+ LzmaDecode.c+ LZMA Decoder++ LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)+ http://www.7-zip.org/++ LZMA SDK is licensed under two licenses:+ 1) GNU Lesser General Public License (GNU LGPL)+ 2) Common Public License (CPL)+ It means that you can select one of these two licenses and+ follow rules of that license.++ SPECIAL EXCEPTION:+ Igor Pavlov, as the author of this code, expressly permits you to+ statically or dynamically link your code (or bind by name) to the+ interfaces of this file without subjecting your linked code to the+ terms of the CPL or GNU LGPL. Any modifications or additions+ to this file, however, are subject to the LGPL or CPL terms.+*/++#include <linux/LzmaDecode.h>++#ifndef Byte+#define Byte unsigned char+#endif++#define kNumTopBits 24+#define kTopValue ((UInt32)1 << kNumTopBits)++#define kNumBitModelTotalBits 11+#define kBitModelTotal (1 << kNumBitModelTotalBits)+#define kNumMoveBits 5++typedef struct _CRangeDecoder+{+ Byte *Buffer;+ Byte *BufferLim;+ UInt32 Range;+ UInt32 Code;+ #ifdef _LZMA_IN_CB+ ILzmaInCallback *InCallback;+ int Result;+ #endif+ int ExtraBytes;+} CRangeDecoder;++Byte RangeDecoderReadByte(CRangeDecoder *rd)+{+ if (rd->Buffer == rd->BufferLim)+ {+ #ifdef _LZMA_IN_CB+ UInt32 size;+ rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);+ rd->BufferLim = rd->Buffer + size;+ if (size == 0)+ #endif+ {+ rd->ExtraBytes = 1;+ return 0xFF;+ }+ }+ return (*rd->Buffer++);+}++/* #define ReadByte (*rd->Buffer++) */+#define ReadByte (RangeDecoderReadByte(rd))++void RangeDecoderInit(CRangeDecoder *rd,+ #ifdef _LZMA_IN_CB+ ILzmaInCallback *inCallback+ #else+ Byte *stream, UInt32 bufferSize+ #endif+ )+{+ int i;+ #ifdef _LZMA_IN_CB+ rd->InCallback = inCallback;+ rd->Buffer = rd->BufferLim = 0;+ #else+ rd->Buffer = stream;+ rd->BufferLim = stream + bufferSize;+ #endif+ rd->ExtraBytes = 0;+ rd->Code = 0;+ rd->Range = (0xFFFFFFFF);+ for(i = 0; i < 5; i++)+ rd->Code = (rd->Code << 8) | ReadByte;+}++#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;+#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;+#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }++UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)+{+ RC_INIT_VAR+ UInt32 result = 0;+ int i;+ for (i = numTotalBits; i > 0; i--)+ {+ /* UInt32 t; */+ range >>= 1;++ result <<= 1;+ if (code >= range)+ {+ code -= range;+ result |= 1;+ }+ /*+ t = (code - range) >> 31;+ t &= 1;+ code -= range & (t - 1);+ result = (result + result) | (1 - t);+ */+ RC_NORMALIZE+ }+ RC_FLUSH_VAR+ return result;+}++int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)+{+ UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;+ if (rd->Code < bound)+ {+ rd->Range = bound;+ *prob += (kBitModelTotal - *prob) >> kNumMoveBits;+ if (rd->Range < kTopValue)+ {+ rd->Code = (rd->Code << 8) | ReadByte;+ rd->Range <<= 8;+ }+ return 0;+ }+ else+ {+ rd->Range -= bound;+ rd->Code -= bound;+ *prob -= (*prob) >> kNumMoveBits;+ if (rd->Range < kTopValue)+ {+ rd->Code = (rd->Code << 8) | ReadByte;+ rd->Range <<= 8;+ }+ return 1;+ }+}++#define RC_GET_BIT2(prob, mi, A0, A1) \+ UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \+ if (code < bound) \+ { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \+ else \+ { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \+ RC_NORMALIZE++#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)++int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)+{+ int mi = 1;+ int i;+ #ifdef _LZMA_LOC_OPT+ RC_INIT_VAR+ #endif+ for(i = numLevels; i > 0; i--)+ {+ #ifdef _LZMA_LOC_OPT+ CProb *prob = probs + mi;+ RC_GET_BIT(prob, mi)+ #else+ mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);+ #endif+ }+ #ifdef _LZMA_LOC_OPT+ RC_FLUSH_VAR+ #endif+ return mi - (1 << numLevels);+}++int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)+{+ int mi = 1;+ int i;+ int symbol = 0;+ #ifdef _LZMA_LOC_OPT+ RC_INIT_VAR+ #endif+ for(i = 0; i < numLevels; i++)+ {+ #ifdef _LZMA_LOC_OPT+ CProb *prob = probs + mi;+ RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))+ #else+ int bit = RangeDecoderBitDecode(probs + mi, rd);+ mi = mi + mi + bit;+ symbol |= (bit << i);+ #endif+ }+ #ifdef _LZMA_LOC_OPT+ RC_FLUSH_VAR+ #endif+ return symbol;+}++Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)+{+ int symbol = 1;+ #ifdef _LZMA_LOC_OPT+ RC_INIT_VAR+ #endif+ do+ {+ #ifdef _LZMA_LOC_OPT+ CProb *prob = probs + symbol;+ RC_GET_BIT(prob, symbol)+ #else+ symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);+ #endif+ }+ while (symbol < 0x100);+ #ifdef _LZMA_LOC_OPT+ RC_FLUSH_VAR+ #endif+ return symbol;+}++Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)+{+ int symbol = 1;+ #ifdef _LZMA_LOC_OPT+ RC_INIT_VAR+ #endif+ do+ {+ int bit;+ int matchBit = (matchByte >> 7) & 1;+ matchByte <<= 1;+ #ifdef _LZMA_LOC_OPT+ {+ CProb *prob = probs + ((1 + matchBit) << 8) + symbol;+ RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)+ }+ #else+ bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd);+ symbol = (symbol << 1) | bit;+ #endif+ if (matchBit != bit)+ {+ while (symbol < 0x100)+ {+ #ifdef _LZMA_LOC_OPT+ CProb *prob = probs + symbol;+ RC_GET_BIT(prob, symbol)+ #else+ symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);+ #endif+ }+ break;+ }+ }+ while (symbol < 0x100);+ #ifdef _LZMA_LOC_OPT+ RC_FLUSH_VAR+ #endif+ return symbol;+}++#define kNumPosBitsMax 4+#define kNumPosStatesMax (1 << kNumPosBitsMax)++#define kLenNumLowBits 3+#define kLenNumLowSymbols (1 << kLenNumLowBits)+#define kLenNumMidBits 3+#define kLenNumMidSymbols (1 << kLenNumMidBits)+#define kLenNumHighBits 8+#define kLenNumHighSymbols (1 << kLenNumHighBits)++#define LenChoice 0+#define LenChoice2 (LenChoice + 1)+#define LenLow (LenChoice2 + 1)+#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))+#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -