From fe7ca3c37a356be9c54fc373fa992534bf192e1f Mon Sep 17 00:00:00 2001 From: atxr Date: Tue, 6 Feb 2024 20:15:05 +0100 Subject: [PATCH] Add first test to parse cdh --- tests/test_get_cdh.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/test_get_cdh.c b/tests/test_get_cdh.c index 6c75724..98d53ca 100644 --- a/tests/test_get_cdh.c +++ b/tests/test_get_cdh.c @@ -1,7 +1,7 @@ #include #include "libmineziper_zip.h" -#define BUF_SIZE 10000 +#define BUF_SIZE 0xfffff int main(int argc, char** argv) { @@ -16,11 +16,37 @@ int main(int argc, char** argv) zip zip; raw raw; - raw.size = fread(buf, BUF_SIZE, 1, stream); + raw.size = fread(buf, 1, BUF_SIZE, stream); buf[BUF_SIZE] = '\0'; raw.buf = buf; - find_cdh(&raw, &zip); + get_eocd(&raw, &zip); + get_cdh(&raw, &zip); + + printf( + "eocd = {\n nb of entry: %x\n off cd: %d\n size cd: 0x%x\n}\n", + zip.eocd->number_of_entries, + zip.eocd->off_cdh, + zip.eocd->size_cdh); + + for (int i = 0; i < zip.eocd->number_of_entries; i++) + { + printf( + "cdh %d = {\n sig: 0x%x\n off lfh: 0x%x\n " + "comp size: 0x%x\n uncomp size: 0x%x\n filename: ", + i, + zip.cdh[i]->sig, + zip.cdh[i]->off_lfh, + zip.cdh[i]->compressed_size, + zip.cdh[i]->uncompressed_size); + + for (int j = 0; j < zip.cdh[i]->filename_length; j++) + { + printf("%c", ((char*) zip.cdh[i])[sizeof(CDH) + j]); + } + + printf("\n}\n\n"); + } return 0; } \ No newline at end of file