Remove raw type
This commit is contained in:
parent
9f8bcf7769
commit
cebaad1ab1
4 changed files with 18 additions and 34 deletions
|
|
@ -13,13 +13,6 @@
|
||||||
|
|
||||||
#define END_OF_BLOCK 256
|
#define END_OF_BLOCK 256
|
||||||
|
|
||||||
typedef struct raw
|
|
||||||
{
|
|
||||||
char* buf;
|
|
||||||
char* stream;
|
|
||||||
int size;
|
|
||||||
} raw;
|
|
||||||
|
|
||||||
typedef struct LFH
|
typedef struct LFH
|
||||||
{
|
{
|
||||||
int sig; // LFH_SIG "PK\03\04"
|
int sig; // LFH_SIG "PK\03\04"
|
||||||
|
|
@ -96,8 +89,8 @@ typedef struct zip
|
||||||
EOCD* eocd;
|
EOCD* eocd;
|
||||||
} zip;
|
} zip;
|
||||||
|
|
||||||
void get_eocd(raw* raw, zip* out);
|
void get_eocd(char* data, int size, zip* out);
|
||||||
void get_cdh(raw* raw, zip* out);
|
void get_cdh(char* data, zip* out);
|
||||||
char* get_encoded_block(zip* in, int n);
|
char* get_encoded_block(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);
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@
|
||||||
#include "libmineziper_huffman_tree.h"
|
#include "libmineziper_huffman_tree.h"
|
||||||
#include "libmineziper_zip.h"
|
#include "libmineziper_zip.h"
|
||||||
|
|
||||||
void get_eocd(raw* raw, zip* out)
|
void get_eocd(char* data, int size, zip* out)
|
||||||
{
|
{
|
||||||
if (raw->size < START_EOCD_SEARCH)
|
if (size < START_EOCD_SEARCH)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char* se = raw->buf + raw->size - START_EOCD_SEARCH;
|
char* se = &data[size - START_EOCD_SEARCH];
|
||||||
while (se > raw->buf)
|
while (se > data)
|
||||||
{
|
{
|
||||||
if (strcmp(se, EOCD_SIG) == 0)
|
if (strcmp(se, EOCD_SIG) == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -25,7 +25,7 @@ void get_eocd(raw* raw, zip* out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void get_cdh(raw* raw, zip* out)
|
void get_cdh(char* data, zip* out)
|
||||||
{
|
{
|
||||||
if (out->eocd == 0 || out->eocd->off_cdh == 0)
|
if (out->eocd == 0 || out->eocd->off_cdh == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -33,13 +33,13 @@ void get_cdh(raw* raw, zip* out)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
out->cd = raw->buf + out->eocd->off_cdh;
|
out->cd = data + out->eocd->off_cdh;
|
||||||
|
|
||||||
CDH* cdh = (CDH*) out->cd;
|
CDH* cdh = (CDH*) out->cd;
|
||||||
for (int i = 0; i < out->eocd->number_of_entries; i++)
|
for (int i = 0; i < out->eocd->number_of_entries; i++)
|
||||||
{
|
{
|
||||||
out->cdh[i] = cdh;
|
out->cdh[i] = cdh;
|
||||||
out->lfh[i] = (LFH*) (raw->buf + cdh->off_lfh);
|
out->lfh[i] = (LFH*) (data + cdh->off_lfh);
|
||||||
|
|
||||||
cdh = (CDH*) (((char*) cdh) + sizeof(CDH) + cdh->filename_length +
|
cdh = (CDH*) (((char*) cdh) + sizeof(CDH) + cdh->filename_length +
|
||||||
cdh->extra_field_length + cdh->file_comment_length);
|
cdh->extra_field_length + cdh->file_comment_length);
|
||||||
|
|
@ -62,7 +62,6 @@ char* decode_type1_block(bitstream* bs, int uncompressed_size, char* decoded_dat
|
||||||
{
|
{
|
||||||
if (token < END_OF_BLOCK)
|
if (token < END_OF_BLOCK)
|
||||||
{
|
{
|
||||||
printf("token[%d]: 0x%x\n", i, token);
|
|
||||||
decoded_data[i++] = token;
|
decoded_data[i++] = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,8 +77,6 @@ char* decode_type1_block(bitstream* bs, int uncompressed_size, char* decoded_dat
|
||||||
|
|
||||||
int distance = decode_distance_token(bs, token);
|
int distance = decode_distance_token(bs, token);
|
||||||
|
|
||||||
printf("token[%d]: token[-%d] with length %d\n", i, distance, length);
|
|
||||||
|
|
||||||
for (int j = 0; j < length; j++)
|
for (int j = 0; j < length; j++)
|
||||||
{
|
{
|
||||||
decoded_data[i] = decoded_data[i - distance];
|
decoded_data[i] = decoded_data[i - distance];
|
||||||
|
|
|
||||||
|
|
@ -20,22 +20,19 @@ void main()
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[BUF_SIZE + 1];
|
char buf[BUF_SIZE + 1];
|
||||||
zip zip;
|
int read_size = fread(buf, 1, BUF_SIZE, stream);
|
||||||
raw raw;
|
|
||||||
|
|
||||||
raw.size = fread(buf, 1, BUF_SIZE, stream);
|
|
||||||
buf[BUF_SIZE] = '\0';
|
buf[BUF_SIZE] = '\0';
|
||||||
raw.buf = buf;
|
|
||||||
raw.stream = buf;
|
|
||||||
|
|
||||||
get_eocd(&raw, &zip);
|
zip zip;
|
||||||
get_cdh(&raw, &zip);
|
get_eocd(buf, read_size, &zip);
|
||||||
|
get_cdh(buf, &zip);
|
||||||
|
|
||||||
for (int k = 0; k < zip.eocd->number_of_entries; k++)
|
for (int k = 0; k < zip.eocd->number_of_entries; k++)
|
||||||
{
|
{
|
||||||
printf("BLOC %d:\n", k);
|
printf("BLOC %d:\n", k);
|
||||||
|
|
||||||
unsigned int uncompressed_size = zip.lfh[k]->uncompressed_size;
|
unsigned int uncompressed_size = zip.lfh[k]->uncompressed_size;
|
||||||
|
printf("UNCOMPRESSED SIZE: 0x%x\n", uncompressed_size);
|
||||||
|
|
||||||
if (zip.lfh[k]->compressed_size == 0)
|
if (zip.lfh[k]->compressed_size == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,12 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[BUF_SIZE + 1];
|
char buf[BUF_SIZE + 1];
|
||||||
zip zip;
|
int read_size = fread(buf, 1, BUF_SIZE, stream);
|
||||||
raw raw;
|
|
||||||
|
|
||||||
raw.size = fread(buf, 1, BUF_SIZE, stream);
|
|
||||||
buf[BUF_SIZE] = '\0';
|
buf[BUF_SIZE] = '\0';
|
||||||
raw.buf = buf;
|
|
||||||
|
|
||||||
get_eocd(&raw, &zip);
|
zip zip;
|
||||||
get_cdh(&raw, &zip);
|
get_eocd(buf, read_size, &zip);
|
||||||
|
get_cdh(buf, &zip);
|
||||||
|
|
||||||
printf(
|
printf(
|
||||||
"eocd = {\n nb of entry: %x\n off cd: %d\n size cd: 0x%x\n}\n",
|
"eocd = {\n nb of entry: %x\n off cd: %d\n size cd: 0x%x\n}\n",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue