OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / user / unrar / unpack.hpp
1 #ifndef _RAR_UNPACK_
2 #define _RAR_UNPACK_
3
4 enum BLOCK_TYPES {BLOCK_LZ,BLOCK_PPM};
5
6 struct Decode
7 {
8   unsigned int MaxNum;
9   unsigned int DecodeLen[16];
10   unsigned int DecodePos[16];
11   unsigned int DecodeNum[2];
12 };
13
14 struct LitDecode
15 {
16   unsigned int MaxNum;
17   unsigned int DecodeLen[16];
18   unsigned int DecodePos[16];
19   unsigned int DecodeNum[NC];
20 };
21
22 struct DistDecode
23 {
24   unsigned int MaxNum;
25   unsigned int DecodeLen[16];
26   unsigned int DecodePos[16];
27   unsigned int DecodeNum[DC];
28 };
29
30 struct LowDistDecode
31 {
32   unsigned int MaxNum;
33   unsigned int DecodeLen[16];
34   unsigned int DecodePos[16];
35   unsigned int DecodeNum[LDC];
36 };
37
38 struct RepDecode
39 {
40   unsigned int MaxNum;
41   unsigned int DecodeLen[16];
42   unsigned int DecodePos[16];
43   unsigned int DecodeNum[RC];
44 };
45
46 struct BitDecode
47 {
48   unsigned int MaxNum;
49   unsigned int DecodeLen[16];
50   unsigned int DecodePos[16];
51   unsigned int DecodeNum[BC];
52 };
53
54 struct UnpackFilter
55 {
56   unsigned int BlockStart;
57   unsigned int BlockLength;
58   unsigned int ExecCount;
59   bool NextWindow;
60   VM_PreparedProgram Prg;
61 };
62
63 /***************************** Unpack v 2.0 *********************************/
64 struct MultDecode
65 {
66   unsigned int MaxNum;
67   unsigned int DecodeLen[16];
68   unsigned int DecodePos[16];
69   unsigned int DecodeNum[MC20];
70 };
71
72 struct AudioVariables
73 {
74   int K1,K2,K3,K4,K5;
75   int D1,D2,D3,D4;
76   int LastDelta;
77   unsigned int Dif[11];
78   unsigned int ByteCount;
79   int LastChar;
80 };
81 /***************************** Unpack v 2.0 *********************************/
82
83
84 class Unpack:private BitInput
85 {
86   private:
87     friend class Pack;
88
89     void Unpack29(bool Solid);
90     bool UnpReadBuf();
91     void UnpWriteBuf();
92     void ExecuteCode(VM_PreparedProgram *Prg);
93     void UnpWriteArea(unsigned int StartPtr,unsigned int EndPtr);
94     void UnpWriteData(byte *Data,int Size);
95     bool ReadTables();
96     void MakeDecodeTables(unsigned char *LenTab,struct Decode *Dec,int Size);
97     int DecodeNumber(struct Decode *Dec);
98     void CopyString();
99     inline void InsertOldDist(unsigned int Distance);
100     inline void InsertLastMatch(unsigned int Length,unsigned int Distance);
101     void UnpInitData(int Solid);
102     void CopyString(unsigned int Length,unsigned int Distance);
103     bool ReadEndOfBlock();
104     bool ReadVMCode();
105     bool ReadVMCodePPM();
106     bool AddVMCode(unsigned int FirstByte,byte *Code,int CodeSize);
107     void InitFilters();
108
109     ComprDataIO *UnpIO;
110     ModelPPM PPM;
111     int PPMEscChar;
112
113     RarVM VM;
114     Array<UnpackFilter*> Filters;
115     Array<UnpackFilter*> PrgStack;
116     Array<int> OldFilterLengths;
117     int LastFilter;
118
119     bool TablesRead;
120     struct LitDecode LD;
121     struct DistDecode DD;
122     struct LowDistDecode LDD;
123     struct RepDecode RD;
124     struct BitDecode BD;
125
126     unsigned int OldDist[4],OldDistPtr;
127     unsigned int LastDist,LastLength;
128
129     unsigned int UnpPtr,WrPtr;
130     
131     int ReadTop;
132     int ReadBorder;
133
134     unsigned char UnpOldTable[HUFF_TABLE_SIZE];
135
136     int UnpBlockType;
137
138     byte *Window;
139     bool ExternalWindow;
140
141
142     Int64 DestUnpSize;
143
144     bool Suspended;
145     bool UnpAllBuf;
146     bool UnpSomeRead;
147     Int64 WrittenFileSize;
148     bool FileExtracted;
149     bool PPMError;
150
151     int PrevLowDist,LowDistRepCount;
152
153 /***************************** Unpack v 1.5 *********************************/
154     void Unpack15(bool Solid);
155     void ShortLZ();
156     void LongLZ();
157     void HuffDecode();
158     void GetFlagsBuf();
159     void OldUnpInitData(int Solid);
160     void InitHuff();
161     void CorrHuff(unsigned int *CharSet,unsigned int *NumToPlace);
162     void OldCopyString(unsigned int Distance,unsigned int Length);
163     unsigned int DecodeNum(int Num,unsigned int StartPos,
164       unsigned int *DecTab,unsigned int *PosTab);
165     void OldUnpWriteBuf();
166
167     unsigned int ChSet[256],ChSetA[256],ChSetB[256],ChSetC[256];
168     unsigned int Place[256],PlaceA[256],PlaceB[256],PlaceC[256];
169     unsigned int NToPl[256],NToPlB[256],NToPlC[256];
170     unsigned int FlagBuf,AvrPlc,AvrPlcB,AvrLn1,AvrLn2,AvrLn3;
171     int Buf60,NumHuf,StMode,LCount,FlagsCnt;
172     unsigned int Nhfb,Nlzb,MaxDist3;
173 /***************************** Unpack v 1.5 *********************************/
174
175 /***************************** Unpack v 2.0 *********************************/
176     void Unpack20(bool Solid);
177     struct MultDecode MD[4];
178     unsigned char UnpOldTable20[MC20*4];
179     int UnpAudioBlock,UnpChannels,UnpCurChannel,UnpChannelDelta;
180     void CopyString20(unsigned int Length,unsigned int Distance);
181     bool ReadTables20();
182     void UnpInitData20(int Solid);
183     void ReadLastTables();
184     byte DecodeAudio(int Delta);
185     struct AudioVariables AudV[4];
186 /***************************** Unpack v 2.0 *********************************/
187
188   public:
189     Unpack(ComprDataIO *DataIO);
190     ~Unpack();
191     void Init(byte *Window=NULL);
192     void DoUnpack(int Method,bool Solid);
193     bool IsFileExtracted() {return(FileExtracted);}
194     void SetDestSize(Int64 DestSize) {DestUnpSize=DestSize;FileExtracted=false;}
195     void SetSuspended(bool Suspended) {Unpack::Suspended=Suspended;}
196
197     unsigned int GetChar()
198     {
199       if (InAddr>BitInput::MAX_SIZE-30)
200         UnpReadBuf();
201       return(InBuf[InAddr++]);
202     }
203 };
204
205 #endif