From cebaad1ab184da048d0f3fc34966fbed53b7c322 Mon Sep 17 00:00:00 2001 From: atxr Date: Wed, 21 Feb 2024 16:13:37 +0100 Subject: [PATCH] Remove raw type --- libmineziper/include/libmineziper_zip.h | 11 ++--------- libmineziper/src/libmineziper_zip.c | 17 +++++++---------- tests/test_decode_fixed_tree.c | 13 +++++-------- tests/test_get_cdh.c | 11 ++++------- 4 files changed, 18 insertions(+), 34 deletions(-) diff --git a/libmineziper/include/libmineziper_zip.h b/libmineziper/include/libmineziper_zip.h index 69462dc..df69ac5 100644 --- a/libmineziper/include/libmineziper_zip.h +++ b/libmineziper/include/libmineziper_zip.h @@ -13,13 +13,6 @@ #define END_OF_BLOCK 256 -typedef struct raw -{ - char* buf; - char* stream; - int size; -} raw; - typedef struct LFH { int sig; // LFH_SIG "PK\03\04" @@ -96,8 +89,8 @@ typedef struct zip EOCD* eocd; } zip; -void get_eocd(raw* raw, zip* out); -void get_cdh(raw* raw, zip* out); +void get_eocd(char* data, int size, zip* out); +void get_cdh(char* data, zip* out); char* get_encoded_block(zip* in, int n); void parse_zip(char* filename, zip* out); void deflate(zip* in); diff --git a/libmineziper/src/libmineziper_zip.c b/libmineziper/src/libmineziper_zip.c index 8c76ba0..d6f37cc 100644 --- a/libmineziper/src/libmineziper_zip.c +++ b/libmineziper/src/libmineziper_zip.c @@ -5,13 +5,13 @@ #include "libmineziper_huffman_tree.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; - char* se = raw->buf + raw->size - START_EOCD_SEARCH; - while (se > raw->buf) + char* se = &data[size - START_EOCD_SEARCH]; + while (se > data) { 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) { @@ -33,13 +33,13 @@ void get_cdh(raw* raw, zip* out) exit(-1); } - out->cd = raw->buf + out->eocd->off_cdh; + out->cd = data + out->eocd->off_cdh; CDH* cdh = (CDH*) out->cd; for (int i = 0; i < out->eocd->number_of_entries; i++) { 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->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) { - printf("token[%d]: 0x%x\n", 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); - printf("token[%d]: token[-%d] with length %d\n", i, distance, length); - for (int j = 0; j < length; j++) { decoded_data[i] = decoded_data[i - distance]; diff --git a/tests/test_decode_fixed_tree.c b/tests/test_decode_fixed_tree.c index 235fdbe..b06fff4 100644 --- a/tests/test_decode_fixed_tree.c +++ b/tests/test_decode_fixed_tree.c @@ -20,22 +20,19 @@ void main() } char buf[BUF_SIZE + 1]; - zip zip; - raw raw; - - raw.size = fread(buf, 1, BUF_SIZE, stream); + int read_size = fread(buf, 1, BUF_SIZE, stream); buf[BUF_SIZE] = '\0'; - raw.buf = buf; - raw.stream = buf; - get_eocd(&raw, &zip); - get_cdh(&raw, &zip); + zip zip; + get_eocd(buf, read_size, &zip); + get_cdh(buf, &zip); for (int k = 0; k < zip.eocd->number_of_entries; k++) { printf("BLOC %d:\n", k); unsigned int uncompressed_size = zip.lfh[k]->uncompressed_size; + printf("UNCOMPRESSED SIZE: 0x%x\n", uncompressed_size); if (zip.lfh[k]->compressed_size == 0) { diff --git a/tests/test_get_cdh.c b/tests/test_get_cdh.c index 18560d0..cb475c3 100644 --- a/tests/test_get_cdh.c +++ b/tests/test_get_cdh.c @@ -14,15 +14,12 @@ int main(int argc, char** argv) } char buf[BUF_SIZE + 1]; - zip zip; - raw raw; - - raw.size = fread(buf, 1, BUF_SIZE, stream); + int read_size = fread(buf, 1, BUF_SIZE, stream); buf[BUF_SIZE] = '\0'; - raw.buf = buf; - get_eocd(&raw, &zip); - get_cdh(&raw, &zip); + zip zip; + get_eocd(buf, read_size, &zip); + get_cdh(buf, &zip); printf( "eocd = {\n nb of entry: %x\n off cd: %d\n size cd: 0x%x\n}\n",