ReactOS 0.4.16-dev-197-g92996da
mszip.h
Go to the documentation of this file.
1/*
2 * MSZIP decompression header (taken from cabinet.h of cabinet dll)
3 *
4 * Copyright 2002 Greg Turner
5 * Copyright 2005 Gerold Jens Wucherpfennig
6 * Copyright 2010 Christian Costa
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23#include "fdi.h"
24
25typedef unsigned char cab_UBYTE; /* 8 bits */
26typedef UINT16 cab_UWORD; /* 16 bits */
27typedef UINT32 cab_ULONG; /* 32 bits */
28typedef INT32 cab_LONG; /* 32 bits */
29
30typedef struct {
31 unsigned int FDI_Intmagic;
41
42/* cast an HFDI into a PFDI_Int */
43#define PFDI_INT(hfdi) ((PFDI_Int)(hfdi))
44
45#define PFDI_ALLOC(hfdi, size) ((*PFDI_INT(hfdi)->pfnalloc) (size))
46#define PFDI_FREE(hfdi, ptr) ((*PFDI_INT(hfdi)->pfnfree) (ptr))
47
48/* MSZIP stuff */
49#define ZIPWSIZE 0x8000 /* window size */
50#define ZIPLBITS 9 /* bits in base literal/length lookup table */
51#define ZIPDBITS 6 /* bits in base distance lookup table */
52#define ZIPBMAX 16 /* maximum bit length of any code */
53#define ZIPN_MAX 288 /* maximum number of codes in any set */
54
55struct Ziphuft {
56 cab_UBYTE e; /* number of extra bits or operation */
57 cab_UBYTE b; /* number of bits in this code or subcode */
58 union {
59 cab_UWORD n; /* literal, length base, or distance base */
60 struct Ziphuft *t; /* pointer to next level of table */
61 } v;
62};
63
64struct ZIPstate {
65 cab_ULONG window_posn; /* current offset within the window */
66 cab_ULONG bb; /* bit buffer */
67 cab_ULONG bk; /* bits in bit buffer */
68 cab_ULONG ll[288+32]; /* literal/length and distance code lengths */
69 cab_ULONG c[ZIPBMAX+1]; /* bit length count table */
70 cab_LONG lx[ZIPBMAX+1]; /* memory for l[-1..ZIPBMAX-1] */
71 struct Ziphuft *u[ZIPBMAX]; /* table stack */
72 cab_ULONG v[ZIPN_MAX]; /* values in order of bit length */
73 cab_ULONG x[ZIPBMAX+1]; /* bit offsets, then code stack */
75};
76
77#define CAB(x) (decomp_state->x)
78#define ZIP(x) (decomp_state->methods.zip.x)
79#define DECR_OK (0)
80#define DECR_DATAFORMAT (1)
81#define DECR_ILLEGALDATA (2)
82#define DECR_NOMEMORY (3)
83#define DECR_CHECKSUM (4)
84#define DECR_INPUT (5)
85#define DECR_OUTPUT (6)
86#define DECR_USERABORT (7)
87
88#define ZIPNEEDBITS(n) {while(k<(n)){cab_LONG c=*(ZIP(inpos)++);\
89 b|=((cab_ULONG)c)<<k;k+=8;}}
90#define ZIPDUMPBITS(n) {b>>=(n);k-=(n);}
91
92/* CAB data blocks are <= 32768 bytes in uncompressed form. Uncompressed
93 * blocks have zero growth. MSZIP guarantees that it won't grow above
94 * uncompressed size by more than 12 bytes. LZX guarantees it won't grow
95 * more than 6144 bytes.
96 */
97#define CAB_BLOCKMAX (32768)
98#define CAB_INPUTMAX (CAB_BLOCKMAX+6144)
99
100typedef struct fdi_cds_fwd {
101 void *hfdi; /* the hfdi we are using */
102 cab_UBYTE inbuf[CAB_INPUTMAX+2]; /* +2 for lzx bitbuffer overflows! */
104 union {
105 struct ZIPstate zip;
108
109/* Tables for deflate from PKZIP's appnote.txt. */
110
111#define THOSE_ZIP_CONSTS \
112static const cab_UBYTE Zipborder[] = /* Order of the bit length code lengths */ \
113{ 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; \
114static const cab_UWORD Zipcplens[] = /* Copy lengths for literal codes 257..285 */ \
115{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, \
116 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; \
117static const cab_UWORD Zipcplext[] = /* Extra bits for literal codes 257..285 */ \
118{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, \
119 4, 5, 5, 5, 5, 0, 99, 99}; /* 99==invalid */ \
120static const cab_UWORD Zipcpdist[] = /* Copy offsets for distance codes 0..29 */ \
121{ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, \
122513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; \
123static const cab_UWORD Zipcpdext[] = /* Extra bits for distance codes */ \
124{ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, \
12510, 11, 11, 12, 12, 13, 13}; \
126/* And'ing with Zipmask[n] masks the lower n bits */ \
127static const cab_UWORD Zipmask[17] = { \
128 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, \
129 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff \
130}
unsigned short UINT16
signed int INT32
unsigned int UINT32
INT32 cab_LONG
Definition: mszip.h:28
struct fdi_cds_fwd fdi_decomp_state
struct FDI_Int * PFDI_Int
#define CAB_BLOCKMAX
Definition: mszip.h:97
UINT32 cab_ULONG
Definition: mszip.h:27
#define CAB_INPUTMAX
Definition: mszip.h:98
UINT16 cab_UWORD
Definition: mszip.h:26
unsigned char cab_UBYTE
Definition: mszip.h:25
INT32 cab_LONG
Definition: cabinet.h:60
UINT32 cab_ULONG
Definition: cabinet.h:59
#define ZIPBMAX
Definition: cabinet.h:125
UINT16 cab_UWORD
Definition: cabinet.h:58
#define ZIPN_MAX
Definition: cabinet.h:126
unsigned char cab_UBYTE
Definition: cabinet.h:57
UINT(__cdecl * PFNWRITE)(INT_PTR hf, void *pv, UINT cb)
Definition: fdi.h:214
int(__cdecl * PFNCLOSE)(INT_PTR hf)
Definition: fdi.h:217
UINT(__cdecl * PFNREAD)(INT_PTR hf, void *pv, UINT cb)
Definition: fdi.h:211
void(__cdecl * PFNFREE)(void *pv)
Definition: fdi.h:205
void *(__cdecl * PFNALLOC)(ULONG cb)
Definition: fdi.h:202
INT_PTR(__cdecl * PFNOPEN)(char *pszFile, int oflag, int pmode)
Definition: fdi.h:208
LONG(__cdecl * PFNSEEK)(INT_PTR hf, LONG dist, int seektype)
Definition: fdi.h:220
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLdouble * v
Definition: gl.h:2040
const GLubyte * c
Definition: glext.h:8905
Definition: fci.h:44
Definition: mszip.h:30
PFNALLOC pfnalloc
Definition: mszip.h:32
PFNREAD pfnread
Definition: mszip.h:35
PFNOPEN pfnopen
Definition: mszip.h:34
PFNWRITE pfnwrite
Definition: mszip.h:36
PFNSEEK pfnseek
Definition: mszip.h:38
PERF perf
Definition: mszip.h:39
unsigned int FDI_Intmagic
Definition: mszip.h:31
PFNFREE pfnfree
Definition: mszip.h:33
PFNCLOSE pfnclose
Definition: mszip.h:37
Definition: mszip.h:64
struct Ziphuft * u[ZIPBMAX]
Definition: mszip.h:71
cab_ULONG bk
Definition: mszip.h:67
cab_ULONG ll[288+32]
Definition: mszip.h:68
cab_UBYTE * inpos
Definition: mszip.h:74
cab_ULONG bb
Definition: mszip.h:66
cab_LONG lx[ZIPBMAX+1]
Definition: mszip.h:70
cab_ULONG window_posn
Definition: mszip.h:65
Definition: mszip.h:55
cab_UWORD n
Definition: mszip.h:59
cab_UBYTE b
Definition: mszip.h:57
union Ziphuft::@247 v
cab_UBYTE e
Definition: mszip.h:56
struct Ziphuft * t
Definition: mszip.h:60
union fdi_cds_fwd::@248 methods
cab_UBYTE outbuf[CAB_BLOCKMAX]
Definition: mszip.h:103
struct ZIPstate zip
Definition: mszip.h:105
void * hfdi
Definition: mszip.h:101
cab_UBYTE inbuf[CAB_INPUTMAX+2]
Definition: mszip.h:102