19 #define BITS_TYPE struct mszipd_stream
21 #define BITS_ORDER_LSB
22 #define BITS_LSB_TABLE
23 #define READ_BYTES do { \
25 INJECT_BITS(*i_ptr++, 8); \
30 #define TABLEBITS(tbl) MSZIP_##tbl##_TABLEBITS
31 #define MAXSYMBOLS(tbl) MSZIP_##tbl##_MAXSYMBOLS
32 #define HUFF_TABLE(tbl,idx) zip->tbl##_table[idx]
33 #define HUFF_LEN(tbl,idx) zip->tbl##_len[idx]
34 #define HUFF_ERROR return INF_ERR_HUFFSYM
37 #define FLUSH_IF_NEEDED do { \
38 if (zip->window_posn == MSZIP_FRAME_SIZE) { \
39 if (zip->flush_window(zip, MSZIP_FRAME_SIZE)) { \
40 return INF_ERR_FLUSH; \
42 zip->window_posn = 0; \
48 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27,
49 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258
54 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385,
55 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
60 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2,
61 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0
66 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
67 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13
72 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
76 #define INF_ERR_BLOCKTYPE (-1)
77 #define INF_ERR_COMPLEMENT (-2)
78 #define INF_ERR_FLUSH (-3)
79 #define INF_ERR_BITBUF (-4)
80 #define INF_ERR_SYMLENS (-5)
81 #define INF_ERR_BITLENTBL (-6)
82 #define INF_ERR_LITERALTBL (-7)
83 #define INF_ERR_DISTANCETBL (-8)
84 #define INF_ERR_BITOVERRUN (-9)
85 #define INF_ERR_BADBITLEN (-10)
86 #define INF_ERR_LITCODE (-11)
87 #define INF_ERR_DISTCODE (-12)
88 #define INF_ERR_DISTANCE (-13)
89 #define INF_ERR_HUFFSYM (-14)
93 register unsigned int bit_buffer;
94 register int bits_left;
95 unsigned char *i_ptr, *i_end;
98 unsigned short bl_table[(1 << 7)];
99 unsigned char bl_len[19];
102 unsigned int lit_codes, dist_codes,
code, last_code=0, bitlen_codes,
i,
run;
107 READ_BITS(lit_codes, 5); lit_codes += 257;
108 READ_BITS(dist_codes, 5); dist_codes += 1;
109 READ_BITS(bitlen_codes, 4); bitlen_codes += 4;
123 for (
i = 0;
i < (lit_codes + dist_codes);
i++) {
129 if (
code < 16) lens[
i] = last_code =
code;
145 zip->sys->copy(&lens[0], &
zip->LITERAL_len[0],
i);
149 zip->sys->copy(&lens[lit_codes], &
zip->DISTANCE_len[0],
i);
158 unsigned int last_block, block_type, distance,
length, this_run,
i;
161 register unsigned int bit_buffer;
162 register int bits_left;
163 register unsigned short sym;
164 unsigned char *i_ptr, *i_end;
175 if (block_type == 0) {
177 unsigned char lens_buf[4];
183 for (
i = 0; (bits_left >= 8);
i++) {
191 lens_buf[
i++] = *i_ptr++;
195 length = lens_buf[0] | (lens_buf[1] << 8);
196 i = lens_buf[2] | (lens_buf[3] << 8);
204 if (this_run > (
unsigned int)(i_end - i_ptr)) this_run = i_end - i_ptr;
208 zip->sys->copy(i_ptr, &
zip->window[
zip->window_posn], this_run);
209 zip->window_posn += this_run;
215 else if ((block_type == 1) || (block_type == 2)) {
217 unsigned int match_posn,
code;
219 if (block_type == 1) {
222 while (
i < 144)
zip->LITERAL_len[
i++] = 8;
223 while (
i < 256)
zip->LITERAL_len[
i++] = 9;
224 while (
i < 280)
zip->LITERAL_len[
i++] = 7;
225 while (
i < 288)
zip->LITERAL_len[
i++] = 8;
226 for (
i = 0;
i < 32;
i++)
zip->DISTANCE_len[
i] = 5;
238 &
zip->LITERAL_len[0], &
zip->LITERAL_table[0]))
244 &
zip->DISTANCE_len[0], &
zip->DISTANCE_table[0]))
253 zip->window[
zip->window_posn++] = (
unsigned char)
code;
256 else if (
code == 256) {
275 +
zip->window_posn - distance;
281 zip->window[
zip->window_posn++] =
zip->window[match_posn++];
288 unsigned char *runsrc, *rundest;
296 rundest = &
zip->window[
zip->window_posn];
zip->window_posn += this_run;
297 runsrc = &
zip->window[match_posn]; match_posn += this_run;
299 while (this_run--) *rundest++ = *runsrc++;
313 }
while (!last_block);
316 if (
zip->window_posn) {
331 unsigned int data_flushed)
333 zip->bytes_output += data_flushed;
335 D((
"overflow: %u bytes flushed, total is now %u",
336 data_flushed,
zip->bytes_output))
345 int input_buffer_size,
350 if (!system)
return NULL;
353 input_buffer_size = (input_buffer_size + 1) & -2;
354 if (input_buffer_size < 2)
return NULL;
362 zip->inbuf = (
unsigned char *) system->
alloc(system, (
size_t) input_buffer_size);
372 zip->inbuf_size = input_buffer_size;
378 zip->i_ptr =
zip->i_end = &
zip->inbuf[0];
380 zip->bit_buffer = 0;
zip->bits_left = 0;
398 if ((
off_t)
i > out_bytes)
i = (
int) out_bytes;
400 if (
zip->sys->write(
zip->output,
zip->o_ptr,
i) !=
i) {
409 while (out_bytes > 0) {
421 }
while (
state != 2);
424 zip->window_posn = 0;
425 zip->bytes_output = 0;
428 D((
"inflate error %d",
error))
429 if (
zip->repair_mode) {
431 if (
zip->bytes_output == 0 &&
zip->window_posn > 0) {
432 zip->flush_window(
zip,
zip->window_posn);
434 zip->sys->message(
NULL,
"MSZIP error, %u bytes of data lost.",
437 zip->window[
i] =
'\0';
445 zip->o_ptr = &
zip->window[0];
446 zip->o_end = &
zip->o_ptr[
zip->bytes_output];
449 i = (out_bytes < (
off_t)
zip->bytes_output) ?
450 (
int)out_bytes :
zip->bytes_output;
463 D((
"bytes left to output"))
486 if (block_len == 0)
break;
493 zip->window_posn = 0;
494 zip->bytes_output = 0;
497 D((
"inflate error %d",
error))
502 if (
zip->sys->write(
zip->output, &
zip->window[0],
zip->bytes_output)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
while(len< limit &&buf1[len]==buf2[len])++len
static int run(int i, const char *arg)
void *(* alloc)(struct mspack_system *self, size_t bytes)
void error(const char *msg)
if(dbg->bits==RZ_SYS_BITS_64)
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)