Remove raw type

This commit is contained in:
atxr 2024-02-21 16:13:37 +01:00
parent 9f8bcf7769
commit cebaad1ab1
4 changed files with 18 additions and 34 deletions

View file

@ -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);

View file

@ -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];

View file

@ -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)
{

View file

@ -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",