annotate mysteryffs/dump1.c @ 179:d0e8cdb82117

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