Find cdh in zip
This commit is contained in:
parent
0b199784ec
commit
4692b1e643
2 changed files with 35 additions and 2 deletions
|
|
@ -1,8 +1,19 @@
|
|||
#ifndef LIBMINEZIPER_ZIP_H
|
||||
#define LIBMINEZIPER_ZIP_H
|
||||
|
||||
#define START_CDH_SEARCH 22
|
||||
#define CDH_MB "PK\05\06"
|
||||
#define LFH_MB "PK\03\04"
|
||||
|
||||
typedef struct raw
|
||||
{
|
||||
char* buf;
|
||||
int size;
|
||||
} raw;
|
||||
|
||||
typedef struct CDH
|
||||
{
|
||||
char mb[4]; // CDH_MB "PK\05\06"
|
||||
void* crc32; // TODO TYPE?
|
||||
LFH* lfh;
|
||||
void* filename; // TODO TYPE?
|
||||
|
|
@ -10,6 +21,7 @@ typedef struct CDH
|
|||
|
||||
typedef struct LFH
|
||||
{
|
||||
char mb[4]; // CDH_MB "PK\03\04"
|
||||
void* crc32; // TODO TYPE?
|
||||
LFH* lfh;
|
||||
int size_compressed_data;
|
||||
|
|
@ -24,6 +36,7 @@ typedef struct zip
|
|||
CDH* central_directory;
|
||||
} zip;
|
||||
|
||||
void find_cdh(raw* raw, zip* out);
|
||||
void parse_zip(char* filename, zip* out);
|
||||
|
||||
#endif
|
||||
20
libmineziper/src/libmineziper_zip.c
Normal file
20
libmineziper/src/libmineziper_zip.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include "libmineziper_zip.h"
|
||||
#include <string.h>
|
||||
|
||||
void find_cdh(raw* raw, zip* out)
|
||||
{
|
||||
if (raw->size < START_CDH_SEARCH)
|
||||
return;
|
||||
|
||||
char* se = raw->buf + raw->size - START_CDH_SEARCH;
|
||||
while (se > raw->buf)
|
||||
{
|
||||
if (strcmp(se, CDH_MB) == 0)
|
||||
{
|
||||
zip->cdh = se;
|
||||
break;
|
||||
}
|
||||
|
||||
se--;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue