[CABINET]
[reactos.git] / reactos / dll / win32 / cabinet / cabinet.h
1 /*
2 * cabinet.h
3 *
4 * Copyright 2002 Greg Turner
5 * Copyright 2005 Gerold Jens Wucherpfennig
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21 #ifndef __WINE_CABINET_H
22 #define __WINE_CABINET_H
23
24 #include <config.h>
25
26 #include <stdarg.h>
27
28 #define WIN32_NO_STATUS
29 #define _INC_WINDOWS
30 #define COM_NO_WINDOWS_H
31
32 #include <windef.h>
33 #include <winbase.h>
34 #include <winnt.h>
35 #include <fdi.h>
36 #include <fci.h>
37
38 #include <wine/debug.h>
39 WINE_DEFAULT_DEBUG_CHANNEL(cabinet);
40
41 /* from msvcrt/sys/stat.h */
42 #define _S_IWRITE 0x0080
43 #define _S_IREAD 0x0100
44
45 /* from msvcrt/fcntl.h */
46 #define _O_RDONLY 0
47 #define _O_WRONLY 1
48 #define _O_RDWR 2
49 #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)
50 #define _O_APPEND 0x0008
51 #define _O_RANDOM 0x0010
52 #define _O_SEQUENTIAL 0x0020
53 #define _O_TEMPORARY 0x0040
54 #define _O_NOINHERIT 0x0080
55 #define _O_CREAT 0x0100
56 #define _O_TRUNC 0x0200
57 #define _O_EXCL 0x0400
58 #define _O_SHORT_LIVED 0x1000
59 #define _O_TEXT 0x4000
60 #define _O_BINARY 0x8000
61
62 #define CAB_SPLITMAX (10)
63
64 #define CAB_SEARCH_SIZE (32*1024)
65
66 typedef unsigned char cab_UBYTE; /* 8 bits */
67 typedef UINT16 cab_UWORD; /* 16 bits */
68 typedef UINT32 cab_ULONG; /* 32 bits */
69 typedef INT32 cab_LONG; /* 32 bits */
70
71 typedef UINT32 cab_off_t;
72
73 /* number of bits in a ULONG */
74 #define CAB_ULONG_BITS (sizeof(cab_ULONG) * 8) /* CHAR_BIT */
75
76 /* structure offsets */
77 #define cfhead_Signature (0x00)
78 #define cfhead_CabinetSize (0x08)
79 #define cfhead_FileOffset (0x10)
80 #define cfhead_MinorVersion (0x18)
81 #define cfhead_MajorVersion (0x19)
82 #define cfhead_NumFolders (0x1A)
83 #define cfhead_NumFiles (0x1C)
84 #define cfhead_Flags (0x1E)
85 #define cfhead_SetID (0x20)
86 #define cfhead_CabinetIndex (0x22)
87 #define cfhead_SIZEOF (0x24)
88 #define cfheadext_HeaderReserved (0x00)
89 #define cfheadext_FolderReserved (0x02)
90 #define cfheadext_DataReserved (0x03)
91 #define cfheadext_SIZEOF (0x04)
92 #define cffold_DataOffset (0x00)
93 #define cffold_NumBlocks (0x04)
94 #define cffold_CompType (0x06)
95 #define cffold_SIZEOF (0x08)
96 #define cffile_UncompressedSize (0x00)
97 #define cffile_FolderOffset (0x04)
98 #define cffile_FolderIndex (0x08)
99 #define cffile_Date (0x0A)
100 #define cffile_Time (0x0C)
101 #define cffile_Attribs (0x0E)
102 #define cffile_SIZEOF (0x10)
103 #define cfdata_CheckSum (0x00)
104 #define cfdata_CompressedSize (0x04)
105 #define cfdata_UncompressedSize (0x06)
106 #define cfdata_SIZEOF (0x08)
107
108 /* flags */
109 #define cffoldCOMPTYPE_MASK (0x000f)
110 #define cffoldCOMPTYPE_NONE (0x0000)
111 #define cffoldCOMPTYPE_MSZIP (0x0001)
112 #define cffoldCOMPTYPE_QUANTUM (0x0002)
113 #define cffoldCOMPTYPE_LZX (0x0003)
114 #define cfheadPREV_CABINET (0x0001)
115 #define cfheadNEXT_CABINET (0x0002)
116 #define cfheadRESERVE_PRESENT (0x0004)
117 #define cffileCONTINUED_FROM_PREV (0xFFFD)
118 #define cffileCONTINUED_TO_NEXT (0xFFFE)
119 #define cffileCONTINUED_PREV_AND_NEXT (0xFFFF)
120 #define cffile_A_RDONLY (0x01)
121 #define cffile_A_HIDDEN (0x02)
122 #define cffile_A_SYSTEM (0x04)
123 #define cffile_A_ARCH (0x20)
124 #define cffile_A_EXEC (0x40)
125 #define cffile_A_NAME_IS_UTF (0x80)
126
127 /****************************************************************************/
128 /* our archiver information / state */
129
130 /* MSZIP stuff */
131 #define ZIPWSIZE 0x8000 /* window size */
132 #define ZIPLBITS 9 /* bits in base literal/length lookup table */
133 #define ZIPDBITS 6 /* bits in base distance lookup table */
134 #define ZIPBMAX 16 /* maximum bit length of any code */
135 #define ZIPN_MAX 288 /* maximum number of codes in any set */
136
137 struct Ziphuft {
138 cab_UBYTE e; /* number of extra bits or operation */
139 cab_UBYTE b; /* number of bits in this code or subcode */
140 union {
141 cab_UWORD n; /* literal, length base, or distance base */
142 struct Ziphuft *t; /* pointer to next level of table */
143 } v;
144 };
145
146 struct ZIPstate {
147 cab_ULONG window_posn; /* current offset within the window */
148 cab_ULONG bb; /* bit buffer */
149 cab_ULONG bk; /* bits in bit buffer */
150 cab_ULONG ll[288+32]; /* literal/length and distance code lengths */
151 cab_ULONG c[ZIPBMAX+1]; /* bit length count table */
152 cab_LONG lx[ZIPBMAX+1]; /* memory for l[-1..ZIPBMAX-1] */
153 struct Ziphuft *u[ZIPBMAX]; /* table stack */
154 cab_ULONG v[ZIPN_MAX]; /* values in order of bit length */
155 cab_ULONG x[ZIPBMAX+1]; /* bit offsets, then code stack */
156 cab_UBYTE *inpos;
157 };
158
159 /* Quantum stuff */
160
161 struct QTMmodelsym {
162 cab_UWORD sym, cumfreq;
163 };
164
165 struct QTMmodel {
166 int shiftsleft, entries;
167 struct QTMmodelsym *syms;
168 cab_UWORD tabloc[256];
169 };
170
171 struct QTMstate {
172 cab_UBYTE *window; /* the actual decoding window */
173 cab_ULONG window_size; /* window size (1Kb through 2Mb) */
174 cab_ULONG actual_size; /* window size when it was first allocated */
175 cab_ULONG window_posn; /* current offset within the window */
176
177 struct QTMmodel model7;
178 struct QTMmodelsym m7sym[7+1];
179
180 struct QTMmodel model4, model5, model6pos, model6len;
181 struct QTMmodelsym m4sym[0x18 + 1];
182 struct QTMmodelsym m5sym[0x24 + 1];
183 struct QTMmodelsym m6psym[0x2a + 1], m6lsym[0x1b + 1];
184
185 struct QTMmodel model00, model40, model80, modelC0;
186 struct QTMmodelsym m00sym[0x40 + 1], m40sym[0x40 + 1];
187 struct QTMmodelsym m80sym[0x40 + 1], mC0sym[0x40 + 1];
188 };
189
190 /* LZX stuff */
191
192 /* some constants defined by the LZX specification */
193 #define LZX_MIN_MATCH (2)
194 #define LZX_MAX_MATCH (257)
195 #define LZX_NUM_CHARS (256)
196 #define LZX_BLOCKTYPE_INVALID (0) /* also blocktypes 4-7 invalid */
197 #define LZX_BLOCKTYPE_VERBATIM (1)
198 #define LZX_BLOCKTYPE_ALIGNED (2)
199 #define LZX_BLOCKTYPE_UNCOMPRESSED (3)
200 #define LZX_PRETREE_NUM_ELEMENTS (20)
201 #define LZX_ALIGNED_NUM_ELEMENTS (8) /* aligned offset tree #elements */
202 #define LZX_NUM_PRIMARY_LENGTHS (7) /* this one missing from spec! */
203 #define LZX_NUM_SECONDARY_LENGTHS (249) /* length tree #elements */
204
205 /* LZX huffman defines: tweak tablebits as desired */
206 #define LZX_PRETREE_MAXSYMBOLS (LZX_PRETREE_NUM_ELEMENTS)
207 #define LZX_PRETREE_TABLEBITS (6)
208 #define LZX_MAINTREE_MAXSYMBOLS (LZX_NUM_CHARS + 50*8)
209 #define LZX_MAINTREE_TABLEBITS (12)
210 #define LZX_LENGTH_MAXSYMBOLS (LZX_NUM_SECONDARY_LENGTHS+1)
211 #define LZX_LENGTH_TABLEBITS (12)
212 #define LZX_ALIGNED_MAXSYMBOLS (LZX_ALIGNED_NUM_ELEMENTS)
213 #define LZX_ALIGNED_TABLEBITS (7)
214
215 #define LZX_LENTABLE_SAFETY (64) /* we allow length table decoding overruns */
216
217 #define LZX_DECLARE_TABLE(tbl) \
218 cab_UWORD tbl##_table[(1<<LZX_##tbl##_TABLEBITS) + (LZX_##tbl##_MAXSYMBOLS<<1)];\
219 cab_UBYTE tbl##_len [LZX_##tbl##_MAXSYMBOLS + LZX_LENTABLE_SAFETY]
220
221 struct LZXstate {
222 cab_UBYTE *window; /* the actual decoding window */
223 cab_ULONG window_size; /* window size (32Kb through 2Mb) */
224 cab_ULONG actual_size; /* window size when it was first allocated */
225 cab_ULONG window_posn; /* current offset within the window */
226 cab_ULONG R0, R1, R2; /* for the LRU offset system */
227 cab_UWORD main_elements; /* number of main tree elements */
228 int header_read; /* have we started decoding at all yet? */
229 cab_UWORD block_type; /* type of this block */
230 cab_ULONG block_length; /* uncompressed length of this block */
231 cab_ULONG block_remaining; /* uncompressed bytes still left to decode */
232 cab_ULONG frames_read; /* the number of CFDATA blocks processed */
233 cab_LONG intel_filesize; /* magic header value used for transform */
234 cab_LONG intel_curpos; /* current offset in transform space */
235 int intel_started; /* have we seen any translatable data yet? */
236
237 LZX_DECLARE_TABLE(PRETREE);
238 LZX_DECLARE_TABLE(MAINTREE);
239 LZX_DECLARE_TABLE(LENGTH);
240 LZX_DECLARE_TABLE(ALIGNED);
241 };
242
243 struct lzx_bits {
244 cab_ULONG bb;
245 int bl;
246 cab_UBYTE *ip;
247 };
248
249 /* CAB data blocks are <= 32768 bytes in uncompressed form. Uncompressed
250 * blocks have zero growth. MSZIP guarantees that it won't grow above
251 * uncompressed size by more than 12 bytes. LZX guarantees it won't grow
252 * more than 6144 bytes.
253 */
254 #define CAB_BLOCKMAX (32768)
255 #define CAB_INPUTMAX (CAB_BLOCKMAX+6144)
256
257 struct cab_file {
258 struct cab_file *next; /* next file in sequence */
259 struct cab_folder *folder; /* folder that contains this file */
260 LPCSTR filename; /* output name of file */
261 HANDLE fh; /* open file handle or NULL */
262 cab_ULONG length; /* uncompressed length of file */
263 cab_ULONG offset; /* uncompressed offset in folder */
264 cab_UWORD index; /* magic index number of folder */
265 cab_UWORD time, date, attribs; /* MS-DOS time/date/attributes */
266 };
267
268
269 struct cab_folder {
270 struct cab_folder *next;
271 struct cabinet *cab[CAB_SPLITMAX]; /* cabinet(s) this folder spans */
272 cab_off_t offset[CAB_SPLITMAX]; /* offset to data blocks */
273 cab_UWORD comp_type; /* compression format/window size */
274 cab_ULONG comp_size; /* compressed size of folder */
275 cab_UBYTE num_splits; /* number of split blocks + 1 */
276 cab_UWORD num_blocks; /* total number of blocks */
277 struct cab_file *contfile; /* the first split file */
278 };
279
280 struct cabinet {
281 struct cabinet *next; /* for making a list of cabinets */
282 LPCSTR filename; /* input name of cabinet */
283 HANDLE *fh; /* open file handle or NULL */
284 cab_off_t filelen; /* length of cabinet file */
285 cab_off_t blocks_off; /* offset to data blocks in file */
286 struct cabinet *prevcab, *nextcab; /* multipart cabinet chains */
287 char *prevname, *nextname; /* and their filenames */
288 char *previnfo, *nextinfo; /* and their visible names */
289 struct cab_folder *folders; /* first folder in this cabinet */
290 struct cab_file *files; /* first file in this cabinet */
291 cab_UBYTE block_resv; /* reserved space in datablocks */
292 cab_UBYTE flags; /* header flags */
293 };
294
295 typedef struct cds_forward {
296 struct cab_folder *current; /* current folder we're extracting from */
297 cab_ULONG offset; /* uncompressed offset within folder */
298 cab_UBYTE *outpos; /* (high level) start of data to use up */
299 cab_UWORD outlen; /* (high level) amount of data to use up */
300 cab_UWORD split; /* at which split in current folder? */
301 int (*decompress)(int, int, struct cds_forward *); /* chosen compress fn */
302 cab_UBYTE inbuf[CAB_INPUTMAX+2]; /* +2 for lzx bitbuffer overflows! */
303 cab_UBYTE outbuf[CAB_BLOCKMAX];
304 cab_UBYTE q_length_base[27], q_length_extra[27], q_extra_bits[42];
305 cab_ULONG q_position_base[42];
306 cab_ULONG lzx_position_base[51];
307 cab_UBYTE extra_bits[51];
308 union {
309 struct ZIPstate zip;
310 struct QTMstate qtm;
311 struct LZXstate lzx;
312 } methods;
313 } cab_decomp_state;
314
315 /*
316 * the rest of these are somewhat kludgy macros which are shared between fdi.c
317 * and cabextract.c.
318 */
319
320 /* Bitstream reading macros (Quantum / normal byte order)
321 *
322 * Q_INIT_BITSTREAM should be used first to set up the system
323 * Q_READ_BITS(var,n) takes N bits from the buffer and puts them in var.
324 * unlike LZX, this can loop several times to get the
325 * requisite number of bits.
326 * Q_FILL_BUFFER adds more data to the bit buffer, if there is room
327 * for another 16 bits.
328 * Q_PEEK_BITS(n) extracts (without removing) N bits from the bit
329 * buffer
330 * Q_REMOVE_BITS(n) removes N bits from the bit buffer
331 *
332 * These bit access routines work by using the area beyond the MSB and the
333 * LSB as a free source of zeroes. This avoids having to mask any bits.
334 * So we have to know the bit width of the bitbuffer variable. This is
335 * defined as ULONG_BITS.
336 *
337 * ULONG_BITS should be at least 16 bits. Unlike LZX's Huffman decoding,
338 * Quantum's arithmetic decoding only needs 1 bit at a time, it doesn't
339 * need an assured number. Retrieving larger bitstrings can be done with
340 * multiple reads and fills of the bitbuffer. The code should work fine
341 * for machines where ULONG >= 32 bits.
342 *
343 * Also note that Quantum reads bytes in normal order; LZX is in
344 * little-endian order.
345 */
346
347 #define Q_INIT_BITSTREAM do { bitsleft = 0; bitbuf = 0; } while (0)
348
349 #define Q_FILL_BUFFER do { \
350 if (bitsleft <= (CAB_ULONG_BITS - 16)) { \
351 bitbuf |= ((inpos[0]<<8)|inpos[1]) << (CAB_ULONG_BITS-16 - bitsleft); \
352 bitsleft += 16; inpos += 2; \
353 } \
354 } while (0)
355
356 #define Q_PEEK_BITS(n) (bitbuf >> (CAB_ULONG_BITS - (n)))
357 #define Q_REMOVE_BITS(n) ((bitbuf <<= (n)), (bitsleft -= (n)))
358
359 #define Q_READ_BITS(v,n) do { \
360 (v) = 0; \
361 for (bitsneed = (n); bitsneed; bitsneed -= bitrun) { \
362 Q_FILL_BUFFER; \
363 bitrun = (bitsneed > bitsleft) ? bitsleft : bitsneed; \
364 (v) = ((v) << bitrun) | Q_PEEK_BITS(bitrun); \
365 Q_REMOVE_BITS(bitrun); \
366 } \
367 } while (0)
368
369 #define Q_MENTRIES(model) (QTM(model).entries)
370 #define Q_MSYM(model,symidx) (QTM(model).syms[(symidx)].sym)
371 #define Q_MSYMFREQ(model,symidx) (QTM(model).syms[(symidx)].cumfreq)
372
373 /* GET_SYMBOL(model, var) fetches the next symbol from the stated model
374 * and puts it in var. it may need to read the bitstream to do this.
375 */
376 #define GET_SYMBOL(m, var) do { \
377 range = ((H - L) & 0xFFFF) + 1; \
378 symf = ((((C - L + 1) * Q_MSYMFREQ(m,0)) - 1) / range) & 0xFFFF; \
379 \
380 for (i=1; i < Q_MENTRIES(m); i++) { \
381 if (Q_MSYMFREQ(m,i) <= symf) break; \
382 } \
383 (var) = Q_MSYM(m,i-1); \
384 \
385 range = (H - L) + 1; \
386 H = L + ((Q_MSYMFREQ(m,i-1) * range) / Q_MSYMFREQ(m,0)) - 1; \
387 L = L + ((Q_MSYMFREQ(m,i) * range) / Q_MSYMFREQ(m,0)); \
388 while (1) { \
389 if ((L & 0x8000) != (H & 0x8000)) { \
390 if ((L & 0x4000) && !(H & 0x4000)) { \
391 /* underflow case */ \
392 C ^= 0x4000; L &= 0x3FFF; H |= 0x4000; \
393 } \
394 else break; \
395 } \
396 L <<= 1; H = (H << 1) | 1; \
397 Q_FILL_BUFFER; \
398 C = (C << 1) | Q_PEEK_BITS(1); \
399 Q_REMOVE_BITS(1); \
400 } \
401 \
402 QTMupdatemodel(&(QTM(m)), i); \
403 } while (0)
404
405 /* Bitstream reading macros (LZX / intel little-endian byte order)
406 *
407 * INIT_BITSTREAM should be used first to set up the system
408 * READ_BITS(var,n) takes N bits from the buffer and puts them in var
409 *
410 * ENSURE_BITS(n) ensures there are at least N bits in the bit buffer.
411 * it can guarantee up to 17 bits (i.e. it can read in
412 * 16 new bits when there is down to 1 bit in the buffer,
413 * and it can read 32 bits when there are 0 bits in the
414 * buffer).
415 * PEEK_BITS(n) extracts (without removing) N bits from the bit buffer
416 * REMOVE_BITS(n) removes N bits from the bit buffer
417 *
418 * These bit access routines work by using the area beyond the MSB and the
419 * LSB as a free source of zeroes. This avoids having to mask any bits.
420 * So we have to know the bit width of the bitbuffer variable.
421 */
422
423 #define INIT_BITSTREAM do { bitsleft = 0; bitbuf = 0; } while (0)
424
425 /* Quantum reads bytes in normal order; LZX is little-endian order */
426 #define ENSURE_BITS(n) \
427 while (bitsleft < (n)) { \
428 bitbuf |= ((inpos[1]<<8)|inpos[0]) << (CAB_ULONG_BITS-16 - bitsleft); \
429 bitsleft += 16; inpos+=2; \
430 }
431
432 #define PEEK_BITS(n) (bitbuf >> (CAB_ULONG_BITS - (n)))
433 #define REMOVE_BITS(n) ((bitbuf <<= (n)), (bitsleft -= (n)))
434
435 #define READ_BITS(v,n) do { \
436 if (n) { \
437 ENSURE_BITS(n); \
438 (v) = PEEK_BITS(n); \
439 REMOVE_BITS(n); \
440 } \
441 else { \
442 (v) = 0; \
443 } \
444 } while (0)
445
446 /* Huffman macros */
447
448 #define TABLEBITS(tbl) (LZX_##tbl##_TABLEBITS)
449 #define MAXSYMBOLS(tbl) (LZX_##tbl##_MAXSYMBOLS)
450 #define SYMTABLE(tbl) (LZX(tbl##_table))
451 #define LENTABLE(tbl) (LZX(tbl##_len))
452
453 /* BUILD_TABLE(tablename) builds a huffman lookup table from code lengths.
454 * In reality, it just calls make_decode_table() with the appropriate
455 * values - they're all fixed by some #defines anyway, so there's no point
456 * writing each call out in full by hand.
457 */
458 #define BUILD_TABLE(tbl) \
459 if (make_decode_table( \
460 MAXSYMBOLS(tbl), TABLEBITS(tbl), LENTABLE(tbl), SYMTABLE(tbl) \
461 )) { return DECR_ILLEGALDATA; }
462
463 /* READ_HUFFSYM(tablename, var) decodes one huffman symbol from the
464 * bitstream using the stated table and puts it in var.
465 */
466 #define READ_HUFFSYM(tbl,var) do { \
467 ENSURE_BITS(16); \
468 hufftbl = SYMTABLE(tbl); \
469 if ((i = hufftbl[PEEK_BITS(TABLEBITS(tbl))]) >= MAXSYMBOLS(tbl)) { \
470 j = 1 << (CAB_ULONG_BITS - TABLEBITS(tbl)); \
471 do { \
472 j >>= 1; i <<= 1; i |= (bitbuf & j) ? 1 : 0; \
473 if (!j) { return DECR_ILLEGALDATA; } \
474 } while ((i = hufftbl[i]) >= MAXSYMBOLS(tbl)); \
475 } \
476 j = LENTABLE(tbl)[(var) = i]; \
477 REMOVE_BITS(j); \
478 } while (0)
479
480 /* READ_LENGTHS(tablename, first, last) reads in code lengths for symbols
481 * first to last in the given table. The code lengths are stored in their
482 * own special LZX way.
483 */
484 #define READ_LENGTHS(tbl,first,last,fn) do { \
485 lb.bb = bitbuf; lb.bl = bitsleft; lb.ip = inpos; \
486 if (fn(LENTABLE(tbl),(first),(last),&lb,decomp_state)) { \
487 return DECR_ILLEGALDATA; \
488 } \
489 bitbuf = lb.bb; bitsleft = lb.bl; inpos = lb.ip; \
490 } while (0)
491
492 /* Tables for deflate from PKZIP's appnote.txt. */
493
494 #define THOSE_ZIP_CONSTS \
495 static const cab_UBYTE Zipborder[] = /* Order of the bit length code lengths */ \
496 { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; \
497 static const cab_UWORD Zipcplens[] = /* Copy lengths for literal codes 257..285 */ \
498 { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, \
499 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; \
500 static const cab_UWORD Zipcplext[] = /* Extra bits for literal codes 257..285 */ \
501 { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, \
502 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */ \
503 static const cab_UWORD Zipcpdist[] = /* Copy offsets for distance codes 0..29 */ \
504 { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, \
505 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; \
506 static const cab_UWORD Zipcpdext[] = /* Extra bits for distance codes */ \
507 { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, \
508 10, 11, 11, 12, 12, 13, 13}; \
509 /* And'ing with Zipmask[n] masks the lower n bits */ \
510 static const cab_UWORD Zipmask[17] = { \
511 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, \
512 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff \
513 }
514
515 /* SESSION Operation */
516 #define EXTRACT_FILLFILELIST 0x00000001
517 #define EXTRACT_EXTRACTFILES 0x00000002
518
519 struct FILELIST{
520 LPSTR FileName;
521 struct FILELIST *next;
522 BOOL DoExtract;
523 };
524
525 typedef struct {
526 INT FileSize;
527 ERF Error;
528 struct FILELIST *FileList;
529 INT FileCount;
530 INT Operation;
531 CHAR Destination[MAX_PATH];
532 CHAR CurrentFile[MAX_PATH];
533 CHAR Reserved[MAX_PATH];
534 struct FILELIST *FilterList;
535 } SESSION;
536
537 #endif /* __WINE_CABINET_H */