annotate mysteryffs/dump2.c @ 24:9f3a7b014e63

MysteryFFS dump2: dumping all file fragments
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 18 May 2013 21:09:33 +0000
parents 671db68916c7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This program attempts to traverse the FFS directory tree
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * from the root down, following the descendant and sibling
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * pointers, and dumps everything it encounters.
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 *
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 * The objective is to understand how to extract the precise
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 * content of data files.
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 */
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <sys/types.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <sys/file.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <sys/stat.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include <endian.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include <ctype.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include <stdio.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include <string.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 #include <strings.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 #include <stdlib.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 #include <unistd.h>
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 typedef unsigned char u8;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 typedef unsigned short u16;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 typedef unsigned int u32;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 u8 mysteryffs_hdr[6] = {'F', 'f', 's', '#', 0x10, 0x02};
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 struct index_entry {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 u16 len;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 u8 unknown_b1;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 u8 type;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 u16 descend;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 u16 sibling;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 u32 dataptr;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 u16 unknown_w1;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 u16 unknown_w2;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 };
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 char *imgfile;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 u32 eraseblk_size;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 int total_blocks;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 u32 total_img_size;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 u8 *image, *indexblk;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 char workpath[512];
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 read_img_file()
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 int fd;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 struct stat st;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 fd = open(imgfile, O_RDONLY);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 if (fd < 0) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 perror(imgfile);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 exit(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 fstat(fd, &st);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 if (!S_ISREG(st.st_mode)) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 fprintf(stderr, "%s is not a regular file\n", imgfile);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 exit(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 if (st.st_size < total_img_size) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 fprintf(stderr, "%s has fewer than 0x%x bytes\n", imgfile,
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 total_img_size);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 exit(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 image = malloc(total_img_size);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 if (!image) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 perror("malloc");
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 exit(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 read(fd, image, total_img_size);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 close(fd);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 find_index_block()
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 int i;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 u8 *ptr;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 for (ptr = image, i = 0; i < total_blocks; i++, ptr += eraseblk_size) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 if (bcmp(ptr, mysteryffs_hdr, 6))
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 continue;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 if (ptr[8] != 0xAB)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 continue;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 printf("Found index in erase block #%d (offset %x)\n", i,
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 ptr - image);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 indexblk = ptr;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 fprintf(stderr, "could not find a MysteryFFS index block in %s\n",
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 imgfile);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 exit(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 get_index_entry(num, host)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 int num;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 struct index_entry *host;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 struct index_entry *le;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 le = (struct index_entry *) indexblk + num;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 host->len = le16toh(le->len);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 host->unknown_b1 = le->unknown_b1;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 host->type = le->type;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 host->descend = le16toh(le->descend);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 host->sibling = le16toh(le->sibling);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 host->dataptr = le32toh(le->dataptr);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 host->unknown_w1 = le16toh(le->unknown_w1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 host->unknown_w2 = le16toh(le->unknown_w2);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 is_namestr_ok(s)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 char *s;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 int cnt;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 for (cnt = 0; *s; s++, cnt++) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 if (cnt >= 32)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 if (!isprint(*s))
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 if (cnt)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 return(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 else
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 char *
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 get_name(dptr)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 u32 dptr;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 u8 *name;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 if (dptr > 0x0FFFFFFF)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 dptr <<= 4;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 if (dptr >= total_img_size - 32)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 name = image + dptr;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 if (is_namestr_ok(name))
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 return(name);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 else
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 dump_common(idx, rec, path_prefix, typestr, newprefix)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 int idx, path_prefix, *newprefix;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 struct index_entry *rec;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 char *typestr;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 u8 *name;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 name = get_name(rec->dataptr);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 if (!name) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 printf("entry #%x has an invalid name pointer!\n", idx);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 return(-1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 if (sizeof(workpath) - path_prefix < strlen(name) + 2) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 printf("entry #%x: pathname buffer overflow!\n", idx);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 return(-1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 path_prefix += sprintf(workpath + path_prefix, "/%s", name);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 printf("\n%s (%s)\n", workpath, typestr);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 printf("len=%x, unknown fields: %02X %04X %04X\n", rec->len,
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 rec->unknown_b1, rec->unknown_w1, rec->unknown_w2);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 if (newprefix)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 *newprefix = path_prefix;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 dump_data_frag(entryidx, rec)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 struct index_entry *rec;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 u32 dptr, endptr;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 int i, c;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 if (rec->len & 0xF || !rec->len) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 printf("entry #%x: don't know how to dump fragment of length %x\n",
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 entryidx, rec->len);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 return(-1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 dptr = rec->dataptr;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 if (dptr > 0x0FFFFFFF) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 inv: printf("entry #%x: invalid data pointer\n", entryidx);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 return(-1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
187 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
188 dptr <<= 4;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
189 if (dptr > total_img_size - rec->len)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
190 goto inv;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
191 for (endptr = dptr + rec->len; dptr < endptr; dptr += 0x10) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
192 printf("%08X: ", dptr);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
193 for (i = 0; i < 16; i++) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
194 printf("%02X ", image[dptr + i]);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
195 if (i == 7 || i == 15)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
196 putchar(' ');
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
197 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
198 for (i = 0; i < 16; i++) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
199 c = image[dptr + i];
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
200 if (!isprint(c))
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
201 c = '.';
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
202 putchar(c);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
203 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
204 putchar('\n');
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
205 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
206 return(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
207 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
208
24
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
209 dump_file_chain(firstent)
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
210 {
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
211 struct index_entry rec;
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
212 int ent;
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
213
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
214 for (ent = firstent; ent != 0xFFFF; ent = rec.descend) {
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
215 get_index_entry(ent, &rec);
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
216 if (rec.type == 0xF4) {
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
217 printf("\nfile continuation (entry #%x)\n", ent);
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
218 printf("len=%x, unknown fields: %02X %04X %04X\n",
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
219 rec.len, rec.unknown_b1,
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
220 rec.unknown_w1, rec.unknown_w2);
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
221 dump_data_frag(ent, &rec);
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
222 } else {
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
223 printf("\ncontinuation entry at %x: type %02X != F4\n",
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
224 ent, rec.type);
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
225 printf("len=%x, unknown fields: %02X %04X %04X\n",
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
226 rec.len, rec.unknown_b1,
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
227 rec.unknown_w1, rec.unknown_w2);
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
228 }
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
229 if (rec.sibling != 0xFFFF)
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
230 printf("warning: non-nil sibling pointer\n");
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
231 }
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
232 }
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
233
23
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
234 dump_dir(firstent, path_prefix)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
235 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
236 struct index_entry rec;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
237 int ent;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
238 int subprefix;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
239
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
240 for (ent = firstent; ent != 0xFFFF; ent = rec.sibling) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
241 get_index_entry(ent, &rec);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
242 switch (rec.type) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
243 case 0x00:
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
244 /* deleted object - skip it */
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
245 continue;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
246 case 0xF2:
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
247 /* subdirectory */
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
248 if (dump_common(ent, &rec, path_prefix, "directory",
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
249 &subprefix) < 0)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
250 continue;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
251 dump_dir(rec.descend, subprefix);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
252 continue;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
253 case 0xF1:
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
254 /* regular file */
24
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
255 if (dump_common(ent, &rec, path_prefix, "file", 0) < 0)
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
256 continue;
23
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
257 dump_data_frag(ent, &rec);
24
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
258 dump_file_chain(rec.descend);
23
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
259 continue;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
260 case 0xE1:
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
261 /* special .journal file */
24
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
262 if (dump_common(ent, &rec, path_prefix, "E1 file", 0)<0)
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
263 continue;
23
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
264 dump_data_frag(ent, &rec);
24
9f3a7b014e63 MysteryFFS dump2: dumping all file fragments
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 23
diff changeset
265 dump_file_chain(rec.descend);
23
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
266 continue;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
267 default:
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
268 printf("entry #%x: unexpected type %02X\n", ent,
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
269 rec.type);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
270 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
271 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
272 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
273
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
274 dump_root()
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
275 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
276 struct index_entry rec;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
277 char *name;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
278
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
279 get_index_entry(1, &rec);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
280 if (rec.type != 0xF2) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
281 fprintf(stderr,
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
282 "error: entry #1 (expected root dir) is not a directory\n");
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
283 exit(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
284 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
285 name = get_name(rec.dataptr);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
286 if (!name) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
287 fprintf(stderr, "root entry has an invalid name pointer!\n");
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
288 exit(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
289 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
290 printf("Root node name: %s\n", name);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
291 printf("len=%x, unknown fields: %02X %04X %04X\n", rec.len,
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
292 rec.unknown_b1, rec.unknown_w1, rec.unknown_w2);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
293 if (rec.sibling != 0xFFFF)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
294 printf("warning: root entry has a non-nil sibling pointer\n");
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
295 dump_dir(rec.descend, 0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
296 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
297
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
298 main(argc, argv)
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
299 char **argv;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
300 {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
301 if (argc != 4) {
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
302 fprintf(stderr, "usage: %s imgfile blksize nblocks\n", argv[0]);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
303 exit(1);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
304 }
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
305 imgfile = argv[1];
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
306 eraseblk_size = strtoul(argv[2], 0, 0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
307 total_blocks = strtoul(argv[3], 0, 0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
308 total_img_size = eraseblk_size * total_blocks;
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
309 read_img_file();
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
310 find_index_block();
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
311 dump_root();
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
312 exit(0);
671db68916c7 MysteryFFS: dump2 started, dumping the initial frag of each file
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
313 }