summaryrefslogtreecommitdiff
path: root/PE/extract.cpp
blob: 001964a1772efdbd87c29d0f2346650727eadad2 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>

#define INDEX 0x838da

#define N1 100
#define N2 600

int index1[N1];
int index2[N2];

int main(void) {
    FILE * s, * f;
    short int t, b;
    int n1 = 0, n2 = 0, i, j, size;
    char fn[50], buff[2048];
    
    s = fopen("slus_006.62", "r");
    
    fseek(s, INDEX, SEEK_SET);
    
    while (1) {
	fread(&t, 2, 1, s);
	if (!t)
	    break;
	index1[n1++] = t;
	fprintf(stderr, "I1 - %3i - %4i\n", n1, t);
    }
    
    b = index1[n1 - 1];
    
    fseek(s, 6, SEEK_CUR);
    
    while (1) {
	fread(&t, 2, 1, s);
	if (!t)
	    break;
	index2[n2++] = t + b;
	fprintf(stderr, "I2 - %3i - %4i\n", n2, t);
    }
    
    fclose(s);
    
    s = fopen("pe.img", "r");
    
    for (i = 0; i < (n1 - 1); i++) {
	sprintf(fn, "dump/%04i.out", i);
	if (!(index1[i + 1] - index1[i]))
	    continue;
	f = fopen(fn, "w");
	fprintf(stderr, "Dumping %3i sectors at %4i (%8i) into %s\n", index1[i + 1] - index1[i], index1[i], index1[i] * 2048, fn);
	fseek(s, index1[i] * 2048, SEEK_SET);
	for (j = index1[i]; j < index1[i + 1]; j++) {
	    fread(buff, 2048, 1, s);
	    fwrite(buff, 2048, 1, f);
	}
	fclose(f);
    }

    for (i = 0; i < (n2 - 1); i++) {
	sprintf(fn, "musics/song-%04i.out", i);
	if (!(index2[i + 1] - index2[i]))
	    continue;
	f = fopen(fn, "w");
	fprintf(stderr, "Music - Dumping %3i sectors at %4i into %s\n", index2[i + 1] - index2[i], index2[i], fn);
	fseek(s, index2[i] * 2048, SEEK_SET);
	for (j = index2[i]; j < index2[i + 1]; j++) {
	    fread(buff, 2048, 1, s);
	    fwrite(buff, 2048, 1, f);
	}
	fclose(f);
    }
}