Created
January 14, 2018 23:16
-
-
Save himanshugoel2797/4a9a28706f60171e40bbd36b1bea2dcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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