1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#ifndef __LZMADECODE_H
23#define __LZMADECODE_H
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#ifndef UInt32
42#ifdef _LZMA_UINT32_IS_ULONG
43#define UInt32 unsigned long
44#else
45#define UInt32 unsigned int
46#endif
47#endif
48
49#ifndef SizeT
50#ifdef _LZMA_SYSTEM_SIZE_T
51#include <stddef.h>
52#define SizeT size_t
53#else
54#define SizeT UInt32
55#endif
56#endif
57
58#ifdef _LZMA_PROB32
59#define CProb UInt32
60#else
61#define CProb unsigned short
62#endif
63
64#define LZMA_RESULT_OK 0
65#define LZMA_RESULT_DATA_ERROR 1
66
67#ifdef _LZMA_IN_CB
68typedef struct _ILzmaInCallback
69{
70 int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
71} ILzmaInCallback;
72#endif
73
74#define LZMA_BASE_SIZE 1846
75#define LZMA_LIT_SIZE 768
76
77#define LZMA_PROPERTIES_SIZE 5
78
79typedef struct _CLzmaProperties
80{
81 int lc;
82 int lp;
83 int pb;
84 #ifdef _LZMA_OUT_READ
85 UInt32 DictionarySize;
86 #endif
87}CLzmaProperties;
88
89int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
90
91#define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
92
93#define kLzmaNeedInitId (-2)
94
95typedef struct _CLzmaDecoderState
96{
97 CLzmaProperties Properties;
98 CProb *Probs;
99
100 #ifdef _LZMA_IN_CB
101 const unsigned char *Buffer;
102 const unsigned char *BufferLim;
103 #endif
104
105 #ifdef _LZMA_OUT_READ
106 unsigned char *Dictionary;
107 UInt32 Range;
108 UInt32 Code;
109 UInt32 DictionaryPos;
110 UInt32 GlobalPos;
111 UInt32 DistanceLimit;
112 UInt32 Reps[4];
113 int State;
114 int RemainLen;
115 unsigned char TempDictionary[4];
116 #endif
117} CLzmaDecoderState;
118
119#ifdef _LZMA_OUT_READ
120#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
121#endif
122
123int LzmaDecode(CLzmaDecoderState *vs,
124 #ifdef _LZMA_IN_CB
125 ILzmaInCallback *inCallback,
126 #else
127 const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
128 #endif
129 unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
130
131#endif
132