Skip to content

Instantly share code, notes, and snippets.

@himanshugoel2797
Created January 14, 2018 23:16
Show Gist options
  • Save himanshugoel2797/4a9a28706f60171e40bbd36b1bea2dcc to your computer and use it in GitHub Desktop.
Save himanshugoel2797/4a9a28706f60171e40bbd36b1bea2dcc to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stddef.h>
typedef struct {
uint32_t magic;
uint32_t count;
uint8_t stuff[12];
} Hdr;
typedef struct {
int32_t offset;
int32_t len;
} FileEntry;
int main(int argc, char *argv[]) {
Hdr hdr;
FileEntry ent;
FILE *f = fopen(argv[1], "rb");
FILE *c = fopen(argv[2], "rb");
fread(&hdr, sizeof(Hdr), 1, f);
for(int i = 0; i <= hdr.count; i++) {
fread(&ent, sizeof(FileEntry), 1, f);
if(ent.len < 0)
continue;
//Read the entry
char *buf = malloc(ent.len);
fseek(c, ent.offset, SEEK_SET);
fread(buf, 1, ent.len, c);
//Build the filename
char fname[256] = "file";
char num[256];
itoa(i, num, 10);
strcat(fname, num);
strcat(fname, ".bin");
FILE* n = fopen(fname, "wb");
fwrite(buf, 1, ent.len, n);
fclose(n);
free(buf);
}
fclose(c);
fclose(f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment