Decode lengths/distances from token
This commit is contained in:
parent
4cdc14e48b
commit
84b33095b0
2 changed files with 35 additions and 3 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef LIBMINEZIPER_ZIP_H
|
#ifndef LIBMINEZIPER_ZIP_H
|
||||||
#define LIBMINEZIPER_ZIP_H
|
#define LIBMINEZIPER_ZIP_H
|
||||||
|
|
||||||
|
#include "libmineziper_bitstream.h"
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
#define START_EOCD_SEARCH 22
|
#define START_EOCD_SEARCH 22
|
||||||
|
|
@ -9,9 +11,7 @@
|
||||||
#define CDH_SIG "PK\01\02"
|
#define CDH_SIG "PK\01\02"
|
||||||
#define DEFLATE 8
|
#define DEFLATE 8
|
||||||
|
|
||||||
#define NUM_OF_CODE 26 * 2 + 10
|
#define END_OF_BLOCK 256
|
||||||
const char* SYMBOLS =
|
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
||||||
|
|
||||||
typedef struct raw
|
typedef struct raw
|
||||||
{
|
{
|
||||||
|
|
@ -109,4 +109,24 @@ char* get_encoded_data(zip* in, int n);
|
||||||
void parse_zip(char* filename, zip* out);
|
void parse_zip(char* filename, zip* out);
|
||||||
void deflate(zip* in);
|
void deflate(zip* in);
|
||||||
|
|
||||||
|
static const short length_codes[] = {
|
||||||
|
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27,
|
||||||
|
31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258};
|
||||||
|
|
||||||
|
static const char extra_bits_length_codes[] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
|
||||||
|
1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
|
||||||
|
4, 4, 4, 4, 5, 5, 5, 5, 0};
|
||||||
|
|
||||||
|
static const int distance_codes[] = {
|
||||||
|
1, 2, 3, 4, 5, 7, 9, 13, 17, 25,
|
||||||
|
33, 49, 65, 97, 129, 193, 257, 385, 513, 769,
|
||||||
|
1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577};
|
||||||
|
|
||||||
|
static const char extra_bits_distance_codes[] = {
|
||||||
|
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6,
|
||||||
|
6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13};
|
||||||
|
|
||||||
|
short decode_length_token(bitstream* bs, int token);
|
||||||
|
int decode_distance_token(bitstream* bs, int token);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -51,3 +51,15 @@ char* get_encoded_data(zip* in, int n)
|
||||||
in->lfh[n]->extra_field_length;
|
in->lfh[n]->extra_field_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short decode_length_token(bitstream* bs, int token)
|
||||||
|
{
|
||||||
|
token -= END_OF_BLOCK + 1;
|
||||||
|
int extra = get_bits(bs, extra_bits_length_codes[token]);
|
||||||
|
return length_codes[token] + extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
int decode_distance_token(bitstream* bs, int token)
|
||||||
|
{
|
||||||
|
int extra = get_bits(bs, extra_bits_distance_codes[token]);
|
||||||
|
return distance_codes[token] + extra;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue