Track only LFH offsets and init zip struct

This commit is contained in:
atxr 2024-02-21 17:08:57 +01:00
parent 812ff2fe3e
commit 090e17b3d9
5 changed files with 70 additions and 59 deletions

View file

@ -17,50 +17,54 @@ int main(int argc, char** argv)
int read_size = fread(buf, 1, BUF_SIZE, stream);
buf[BUF_SIZE] = '\0';
zip zip;
get_eocd(buf, read_size, &zip);
get_cdh(buf, &zip);
zip zip = init_zip(buf, read_size);
printf(
"eocd = {\n nb of entry: %x\n off cd: %d\n size cd: 0x%x\n}\n",
zip.eocd->number_of_entries,
zip.entries,
zip.eocd->off_cdh,
zip.eocd->size_cdh);
CDH* cdh = (CDH*) zip.cd;
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);
cdh->sig,
cdh->off_lfh,
cdh->compressed_size,
cdh->uncompressed_size);
for (int j = 0; j < zip.cdh[i]->filename_length; j++)
for (int j = 0; j < cdh->filename_length; j++)
{
printf("%c", ((char*) zip.cdh[i])[sizeof(CDH) + j]);
printf("%c", ((char*) cdh)[sizeof(CDH) + j]);
}
printf("\n}\n\n");
cdh = (CDH*) (((char*) cdh) + sizeof(CDH) + cdh->filename_length +
cdh->extraf_length + cdh->file_comment_length);
}
printf("\n--------------------------------------------\n");
for (int i = 0; i < zip.eocd->number_of_entries; i++)
for (int i = 0; i < zip.entries; i++)
{
LFH* lfh = &zip.start[zip.lfh_off[i]];
printf(
"lfh %d = {\n sig: 0x%x\n comp size: 0x%x\n uncomp size: 0x%x\n "
"filename: ",
i,
zip.lfh[i]->sig,
zip.lfh[i]->compressed_size,
zip.lfh[i]->uncompressed_size);
lfh->sig,
lfh->compressed_size,
lfh->uncompressed_size);
for (int j = 0; j < zip.lfh[i]->filename_length; j++)
for (int j = 0; j < lfh->filename_length; j++)
{
printf("%c", ((char*) zip.lfh[i])[sizeof(LFH) + j]);
printf("%c", ((char*) lfh)[sizeof(LFH) + j]);
}
printf("\n}\n\n");