1 | /* |
---|
2 | * explode.h -- header file for PKWARE data decompression library |
---|
3 | * used by mpq-tools. |
---|
4 | * |
---|
5 | * Copyright (C) 2003 Maik Broemme <mbroemme@plusserver.de> |
---|
6 | * |
---|
7 | * This source was adepted from the C++ version of pklib.h included |
---|
8 | * in stormlib. The C++ version belongs to the following authors, |
---|
9 | * |
---|
10 | * Ladislav Zezula <ladik.zezula.net> |
---|
11 | * |
---|
12 | * This program is free software; you can redistribute it and/or modify |
---|
13 | * it under the terms of the GNU General Public License as published by |
---|
14 | * the Free Software Foundation; either version 2 of the License, or |
---|
15 | * (at your option) any later version. |
---|
16 | * |
---|
17 | * This program is distributed in the hope that it will be useful, |
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | * GNU General Public License for more details. |
---|
21 | * |
---|
22 | * You should have received a copy of the GNU General Public License |
---|
23 | * along with this program; if not, write to the Free Software |
---|
24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
25 | */ |
---|
26 | |
---|
27 | #ifndef _EXPLODE_H |
---|
28 | #define _EXPLODE_H |
---|
29 | |
---|
30 | #define LIBMPQ_PKZIP_EXP_BUFFER_SIZE 12596 /* Size of decompress buffer */ |
---|
31 | #define LIBMPQ_PKZIP_CMP_BINARY 0 /* Binary compression */ |
---|
32 | #define LIBMPQ_PKZIP_CMP_ASCII 1 /* Ascii compression */ |
---|
33 | #define LIBMPQ_PKZIP_CMP_NO_ERROR 0 |
---|
34 | #define LIBMPQ_PKZIP_CMP_INV_DICTSIZE 1 |
---|
35 | #define LIBMPQ_PKZIP_CMP_INV_MODE 2 |
---|
36 | #define LIBMPQ_PKZIP_CMP_BAD_DATA 3 |
---|
37 | #define LIBMPQ_PKZIP_CMP_ABORT 4 |
---|
38 | |
---|
39 | /* Compression structure (size: 12596 bytes on x86-32) */ |
---|
40 | typedef struct { |
---|
41 | unsigned long offs0000; /* 0000 */ |
---|
42 | unsigned long cmp_type; /* 0004 - Compression type (LIBMPQ_PZIP_CMP_BINARY or LIBMPQ_PKZIP_CMP_ASCII) */ |
---|
43 | unsigned long out_pos; /* 0008 - Position in output buffer */ |
---|
44 | unsigned long dsize_bits; /* 000C - Dict size (4, 5, 6 for 0x400, 0x800, 0x1000) */ |
---|
45 | unsigned long dsize_mask; /* 0010 - Dict size bitmask (0x0F, 0x1F, 0x3F for 0x400, 0x800, 0x1000) */ |
---|
46 | unsigned long bit_buf; /* 0014 - 16-bit buffer for processing input data */ |
---|
47 | unsigned long extra_bits; /* 0018 - Number of extra (above 8) bits in bit buffer */ |
---|
48 | unsigned int in_pos; /* 001C - Position in in_buf */ |
---|
49 | unsigned long in_bytes; /* 0020 - Number of bytes in input buffer */ |
---|
50 | void *param; /* 0024 - Custom parameter */ |
---|
51 | unsigned int (*read_buf)(char *buf, unsigned int *size, void *param); /* 0028 */ |
---|
52 | void (*write_buf)(char *buf, unsigned int *size, void *param); /* 002C */ |
---|
53 | unsigned char out_buf[0x2000]; /* 0030 - Output circle buffer. Starting position is 0x1000 */ |
---|
54 | unsigned char offs_2030[0x204]; /* 2030 - ??? */ |
---|
55 | unsigned char in_buf[0x800]; /* 2234 - Buffer for data to be decompressed */ |
---|
56 | unsigned char pos1[0x100]; /* 2A34 - Positions in buffers */ |
---|
57 | unsigned char pos2[0x100]; /* 2B34 - Positions in buffers */ |
---|
58 | unsigned char offs_2c34[0x100]; /* 2C34 - Buffer for */ |
---|
59 | unsigned char offs_2d34[0x100]; /* 2D34 - Buffer for */ |
---|
60 | unsigned char offs_2e34[0x80]; /* 2EB4 - Buffer for */ |
---|
61 | unsigned char offs_2eb4[0x100]; /* 2EB4 - Buffer for */ |
---|
62 | unsigned char bits_asc[0x100]; /* 2FB4 - Buffer for */ |
---|
63 | unsigned char dist_bits[0x40]; /* 30B4 - Numbers of bytes to skip copied block length */ |
---|
64 | unsigned char slen_bits[0x10]; /* 30F4 - Numbers of bits for skip copied block length */ |
---|
65 | unsigned char clen_bits[0x10]; /* 3104 - Number of valid bits for copied block */ |
---|
66 | unsigned short len_base[0x10]; /* 3114 - Buffer for */ |
---|
67 | } pkzip_data_cmp; |
---|
68 | // __attribute__ ((packed)) pkzip_data_cmp; |
---|
69 | |
---|
70 | typedef struct { |
---|
71 | char *in_buf; /* Pointer to input data buffer */ |
---|
72 | unsigned int in_pos; /* Current offset in input data buffer */ |
---|
73 | int in_bytes; /* Number of bytes in the input buffer */ |
---|
74 | char *out_buf; /* Pointer to output data buffer */ |
---|
75 | unsigned int out_pos; /* Position in the output buffer */ |
---|
76 | int max_out; /* Maximum number of bytes in the output buffer */ |
---|
77 | } pkzip_data; |
---|
78 | |
---|
79 | extern unsigned int libmpq_pkzip_explode( |
---|
80 | unsigned int (*read_buf)(char *buf, unsigned int *size, void *param), |
---|
81 | void (*write_buf)(char *buf, unsigned int *size, void *param), |
---|
82 | char *work_buf, |
---|
83 | void *param |
---|
84 | ); |
---|
85 | |
---|
86 | #endif /* _EXPLODE_H */ |
---|