summaryrefslogtreecommitdiff
path: root/MegamanX5/unarc.cpp
blob: c9ab2befa6f9b60b7ace8e456b988ad60259fd7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdlib.h>
#include "generic.h"
#include "fileutils.h"

int main(int argc, char ** argv) {
    FILE * f;
    
    int i = 0;
    
    f = fopen(argv[1], "r");
    
    int offset = 0;
    while (1) {
	int sector, size;
	fseek(f, offset, SEEK_SET);
	fread(&sector, 4, 1, f);
	fread(&size, 4, 1, f);
	offset += 8;
	
	if (!sector)
	    break;
	
	fseek(f, sector <<= 9, SEEK_SET);
	
	char * buffer = (char *) malloc(size);
	
	fread(buffer, 1, size, f);
	
	char fname[64];
	sprintf(fname, "unarc-%03i.out", i);
	FILE * o = fopen(fname, "w");
	fwrite(buffer, 1, size, o);
	fclose(o);
	i++;
	
	free(buffer);
    }
    
    exit(-1);
}