1 /* ScummVM Tools
2 *
3 * ScummVM Tools is the legal property of its developers, whose
4 * names are too numerous to list here. Please refer to the
5 * COPYRIGHT file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 #include "common/endian.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27
main(int argc,char ** argv)28 int main (int argc, char **argv) {
29 unsigned char * buf;
30 size_t sz;
31 FILE *fin;
32 char fn[1024];
33
34 if (argc < 3) {
35 fprintf (stderr, "USAGE: %s INFILE OUTDIR\n", argv[0]);
36 return -1;
37 }
38
39 fin = fopen (argv[1], "rb");
40 if (fin == NULL) {
41 fprintf (stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
42 return -2;
43 }
44 fseek (fin, 0, SEEK_END);
45 sz = ftell (fin);
46 fseek (fin, 0, SEEK_SET);
47
48 buf = (unsigned char *) malloc (sz);
49
50 fread (buf, 1, sz, fin);
51 fclose (fin);
52
53 if (memcmp (buf, "Pod\0file\0\0\0\0", 12) != 0
54 && memcmp (buf, "Pod File\0\0\0\0", 12) != 0
55 && memcmp (buf, "Pod\0\0\0\0\0\0\0\0\0", 12) != 0) {
56 fprintf (stderr, "Bad signature\n");
57 return 1;
58 }
59
60 int filecnt = READ_LE_UINT32(buf + 12);
61
62 FILE *fout;
63
64 int cur = filecnt * 16 + 16;
65 int ctr = 0;
66
67 fprintf (stderr, "%d files\n", filecnt);
68
69 for (ctr = 0; ctr < filecnt; ctr++) {
70 unsigned char * headptr = buf + 16 + 16 * ctr;
71 char c = headptr[12];
72 headptr[12] = 0;
73 sprintf (fn, "%s/%s", argv[2], headptr);
74 headptr[12] = c;
75 int csz = READ_LE_UINT32(headptr+12);
76 fout = fopen(fn, "wb");
77 if (fout == NULL) {
78 fprintf (stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
79 return -3;
80 }
81 fwrite(buf + cur, csz, 1, fout);
82 fclose(fout);
83 cur += csz;
84 }
85
86 if (cur < (int)sz) {
87 sprintf (fn, "%s/tail.bin", argv[2]);
88 fout = fopen(fn, "wb");
89 if (fout == NULL) {
90 fprintf (stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
91 return -3;
92 }
93 fwrite(buf + cur, sz - cur, 1, fout);
94 fclose(fout);
95 }
96
97 return 0;
98 }
99