annotate mysteryffs/extract.c @ 25:ae5337f881e3

MysteryFFS: beginning of the extract utility
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 18 May 2013 23:08:13 +0000
parents
children d19b4e20ff9f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This program is the logical culmination of the MysteryFFS reverse eng
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * experiments: it walks the FFS directory tree from the root down,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * recreates a matching tree in the local Unix file system, and
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 * extracts the full content of all data files.
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 *
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 * All acquired understanding of the MysteryFFS structure is tested
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 * in the process.
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <sys/types.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <sys/file.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include <sys/stat.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include <endian.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include <ctype.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include <stdio.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 #include <string.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 #include <strings.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 #include <stdlib.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 #include <unistd.h>
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 typedef unsigned char u8;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 typedef unsigned short u16;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 typedef unsigned int u32;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 u8 mysteryffs_hdr[6] = {'F', 'f', 's', '#', 0x10, 0x02};
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 /* actual MysteryFFS on-media structure */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 struct mysteryffs_index {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 u16 len;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 u8 unknown_b1;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 u8 type;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 u16 descend;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 u16 sibling;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 u32 dataptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 u16 unknown_w1;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 u16 unknown_w2;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 };
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 /* our own struct for convenience */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 struct objinfo {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 u16 entryno;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 struct mysteryffs_index *idxrec;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 u8 *dataptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 u32 offset;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 u16 len;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 u8 type;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 u16 descend;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 u16 sibling;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 };
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 char *imgfile;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 u32 eraseblk_size;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 int total_blocks;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 u32 total_img_size;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 u8 *image, *indexblk;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 char workpath[512];
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 read_img_file()
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 int fd;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 struct stat st;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 fd = open(imgfile, O_RDONLY);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 if (fd < 0) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 perror(imgfile);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 fstat(fd, &st);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 if (!S_ISREG(st.st_mode)) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 fprintf(stderr, "%s is not a regular file\n", imgfile);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 if (st.st_size < total_img_size) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 fprintf(stderr, "%s has fewer than 0x%x bytes\n", imgfile,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 total_img_size);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 image = malloc(total_img_size);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 if (!image) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 perror("malloc");
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 read(fd, image, total_img_size);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 close(fd);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 find_index_block()
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 int i;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 u8 *ptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 for (ptr = image, i = 0; i < total_blocks; i++, ptr += eraseblk_size) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 if (bcmp(ptr, mysteryffs_hdr, 6))
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 continue;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 if (ptr[8] != 0xAB)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 continue;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 printf("Found index in erase block #%d (offset %x)\n", i,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 ptr - image);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 indexblk = ptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 return(0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 fprintf(stderr, "could not find a MysteryFFS index block in %s\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 imgfile);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 get_index_entry(oi)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 struct objinfo *oi;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 struct mysteryffs_index *le;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 if (oi->entryno >= (eraseblk_size >> 4)) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 fprintf(stderr,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 "error: index block pointer %x past the erase block size!\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 oi->entryno);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 le = (struct mysteryffs_index *) indexblk + oi->entryno;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 oi->idxrec = le;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 oi->len = le16toh(le->len);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 oi->type = le->type;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 oi->descend = le16toh(le->descend);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 oi->sibling = le16toh(le->sibling);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 return(0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 validate_chunk(oi)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 struct objinfo *oi;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 u32 dptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 if (oi->len & 0xF || !oi->len) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 fprintf(stderr, "index entry #%x: invalid chunk length\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 oi->entryno);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 dptr = le32toh(oi->idxrec->dataptr);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 if (dptr > 0x0FFFFFFF) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 invdptr: fprintf(stderr, "index entry #%x: invalid data pointer\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 oi->entryno);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 dptr <<= 4;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 if (dptr >= total_img_size - oi->len)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 goto invdptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 oi->offset = dptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 oi->dataptr = image + dptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 return(0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 validate_obj_name(oi)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 struct objinfo *oi;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 u8 *cp;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 int cnt;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 for (cp = oi->dataptr, cnt = 0; ; cp++, cnt++) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 if (cnt >= oi->len) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 fprintf(stderr,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 "object at index %x: name expected at %x: length overrun\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 oi->entryno, oi->offset);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 if (!*cp)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 break;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 if (*cp < '!' || *cp > '~') {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 fprintf(stderr,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 "object at index %x: name expected at %x: bad character\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 oi->entryno, oi->offset);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 if (!cnt) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 fprintf(stderr,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 "object at index %x: name expected at %x: null string\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 oi->entryno, oi->offset);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 return(0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 name_safe_for_extract(oi)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 struct objinfo *oi;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187 char *s;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 s = (char *)oi->dataptr;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 if (!isalnum(*s) && *s != '_')
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 return(0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 for (s++; *s; s++)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193 if (!isalnum(*s) && *s != '_' && *s != '.')
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 return(0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 return(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 dump_dir(firstent, path_prefix)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 int ent;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 struct objinfo obj;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 int typechar;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 u32 length;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 for (ent = firstent; ent != 0xFFFF; ent = obj.sibling) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 obj.entryno = ent;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 get_index_entry(&obj);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208 if (!obj.type) /* skip deleted objects w/o further validation */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
209 continue;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
210 validate_chunk(&obj);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
211 validate_obj_name(&obj);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
212 if (path_prefix + strlen(obj.dataptr) + 2 > sizeof workpath) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
213 fprintf(stderr,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
214 "handling object at index %x, name \"%s\": path buffer overflow\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
215 obj.entryno, (char *)obj.dataptr);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
216 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
217 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
218 sprintf(workpath + path_prefix, "/%s", (char *)obj.dataptr);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
219 switch (obj.type) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
220 case 0xF2:
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
221 /* directory */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
222 printf("dir: %s\n", workpath);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
223 /* mkdir will go here */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
224 dump_dir(obj.descend, strlen(workpath));
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
225 continue;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
226 case 0xF1:
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
227 /* regular file */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
228 printf("file: %s\n", workpath);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
229 /* file extraction will go here */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
230 continue;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
231 case 0xE1:
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
232 /* special .journal file */
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
233 if (path_prefix == 0 &&
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 !strcmp((char *)obj.dataptr, ".journal"))
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 printf("skipping /.journal\n");
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 else
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 printf("skipping unexpected E1 file: %s\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 workpath);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239 continue;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 default:
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241 printf("%s (index entry #%x): unexpected type %02X; skipping\n",
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 workpath, obj.entryno, obj.type);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 continue;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 dump_root()
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 struct objinfo root;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 root.entryno = 1;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253 get_index_entry(&root);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254 validate_chunk(&root);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
255 validate_obj_name(&root);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
256 printf("Root node name: %s\n", (char *)root.dataptr);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 if (root.type != 0xF2) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
258 fprintf(stderr,
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 "error: index entry #1 (expected root dir) is not a directory\n");
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
262 if (root.sibling != 0xFFFF)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
263 printf("warning: root entry has a non-nil sibling pointer\n");
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264 dump_dir(root.descend, 0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
265 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 main(argc, argv)
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 char **argv;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270 if (argc != 4) {
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 fprintf(stderr, "usage: %s imgfile blksize nblocks\n", argv[0]);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 exit(1);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273 }
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274 imgfile = argv[1];
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 eraseblk_size = strtoul(argv[2], 0, 0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 total_blocks = strtoul(argv[3], 0, 0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277 total_img_size = eraseblk_size * total_blocks;
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278 read_img_file();
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 find_index_block();
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280 dump_root();
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281 exit(0);
ae5337f881e3 MysteryFFS: beginning of the extract utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282 }