Skip to content

Instantly share code, notes, and snippets.

@misodengaku
Created September 25, 2014 17:37
Show Gist options
  • Save misodengaku/6096e6e30c0c9ee20566 to your computer and use it in GitHub Desktop.
Save misodengaku/6096e6e30c0c9ee20566 to your computer and use it in GitHub Desktop.
weissman
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef struct _hdr {
uint8_t magic[8];
uint32_t version;
uint32_t num_files;
} hdr;
typedef struct _entry {
uint32_t magic;
uint32_t compressed_size;
uint32_t uncompressed_size;
uint8_t filename[32];
} entry;
int main(int argc, char* argv[])
{
FILE *fp, *ofp;
hdr head;
entry file;
char* data;
int count = 0;
fp = fopen(argv[1], "r");
fread(&head, sizeof(hdr), 1, fp);
printf("magic: %s\nversion: %d\nnum: %d\n", head.magic, head.version, head.num_files);
//files = (entry *)malloc(sizeof(entry) * head.num_files);
while(count < head.num_files)
{
fread(&file, sizeof(entry), 1, fp);
printf("filename: %s\n\tmagic: %d\n\tcompressed_size: %d\n\tuncompressed_size: %d\n", file.filename, file.magic, file.compressed_size, file.uncompressed_size);
data = (char *)malloc(file.compressed_size);
fread(data, file.compressed_size, 1, fp);
ofp = fopen(file.filename, "w");
fwrite(data, file.compressed_size, 1, ofp);
fclose(ofp);
free(data);
count++;
}
//free(files);
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment