Get eocd and cdh entries

This commit is contained in:
atxr 2024-02-06 20:13:46 +01:00
parent 8bb984e61a
commit f24444a7b1
2 changed files with 27 additions and 6 deletions

View file

@ -68,7 +68,8 @@ typedef struct zip
EOCD* eocd; EOCD* eocd;
} zip; } zip;
void find_cdh(raw* raw, zip* out); void get_eocd(raw* raw, zip* out);
void get_cdh(raw* raw, zip* out);
void parse_zip(char* filename, zip* out); void parse_zip(char* filename, zip* out);
#endif #endif

View file

@ -1,20 +1,40 @@
#include "libmineziper_zip.h" #include "libmineziper_zip.h"
#include <string.h> #include <string.h>
void find_cdh(raw* raw, zip* out) void get_eocd(raw* raw, zip* out)
{ {
if (raw->size < START_CDH_SEARCH) if (raw->size < START_EOCD_SEARCH)
return; return;
char* se = raw->buf + raw->size - START_CDH_SEARCH; char* se = raw->buf + raw->size - START_EOCD_SEARCH;
while (se > raw->buf) while (se > raw->buf)
{ {
if (strcmp(se, CDH_MB) == 0) if (strcmp(se, EOCD_SIG) == 0)
{ {
out->cd = (CDH*) se; out->eocd = se;
out->cdh = (CDH**) malloc(out->eocd->number_of_entries * sizeof(CDH*));
break; break;
} }
se--; se--;
} }
} }
void get_cdh(raw* raw, zip* out)
{
if (out->eocd == 0 || out->eocd->off_cdh == 0)
{
printf("<get_cdh> error: No EOCD found.\n");
exit(-1);
}
out->cd = raw->buf + out->eocd->off_cdh;
CDH* cdh = out->cd;
for (int i = 0; i < out->eocd->number_of_entries; i++)
{
out->cdh[i] = cdh;
cdh = (CDH*) (((char*) cdh) + sizeof(CDH) + cdh->filename_length +
cdh->extra_field_length + cdh->file_comment_length);
}
}