annotate mysteryffs/scan1.c @ 47:3b6296382e24

pirollback: dumpjournal utility written, works
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 07 Jul 2013 06:52:04 +0000
parents d41c555d7f1d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This program is the first MysteryFFS analysis tool written.
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * Here I'm trying to understand the meaning of various fields
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 * in the index block records.
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 */
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <sys/types.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <sys/file.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <sys/stat.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <endian.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include <ctype.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include <stdio.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include <string.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include <strings.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 #include <stdlib.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 #include <unistd.h>
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 typedef unsigned char u8;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 typedef unsigned short u16;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 typedef unsigned int u32;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 u8 blank_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 u8 mysteryffs_hdr[6] = {'F', 'f', 's', '#', 0x10, 0x02};
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 struct index_entry {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 u16 len;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 u8 unknown1;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 u8 type;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 u16 nptr1;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 u16 nptr2;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 u32 dataptr;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 u16 unknown2;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 u16 version;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 };
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 char *imgfile;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 u32 eraseblk_size;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 int total_blocks;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 u32 total_img_size;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 u8 *image, *indexblk;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 read_img_file()
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 int fd;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 struct stat st;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 fd = open(imgfile, O_RDONLY);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 if (fd < 0) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 perror(imgfile);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 exit(1);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 fstat(fd, &st);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 if (!S_ISREG(st.st_mode)) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 fprintf(stderr, "%s is not a regular file\n", imgfile);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 exit(1);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 if (st.st_size < total_img_size) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 fprintf(stderr, "%s has fewer than 0x%x bytes\n", imgfile,
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 total_img_size);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 exit(1);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 image = malloc(total_img_size);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 if (!image) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 perror("malloc");
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 exit(1);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 read(fd, image, total_img_size);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 close(fd);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 find_index_block()
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 int i;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 u8 *ptr;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 for (ptr = image, i = 0; i < total_blocks; i++, ptr += eraseblk_size) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 if (bcmp(ptr, mysteryffs_hdr, 6))
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 continue;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 if (ptr[8] != 0xAB)
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 continue;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 indexblk = ptr;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 return(0);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 fprintf(stderr, "could not find a MysteryFFS index block in %s\n",
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 imgfile);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 exit(1);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 is_namestr_ok(s)
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 char *s;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 int cnt;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 for (cnt = 0; *s; s++, cnt++) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 if (cnt >= 32)
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 return(0);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 if (!isprint(*s))
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 return(0);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 if (cnt)
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 return(1);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 else
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 return(0);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 char *
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 dataptr_to_name(dptr)
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 u32 dptr;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 u8 *data;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 if (dptr > 0x0FFFFFFF) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 inv: return("<invptr>");
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 dptr <<= 4;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 if (dptr >= total_img_size)
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 goto inv;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 data = image + dptr;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 if (is_namestr_ok(data))
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 return(data);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 else
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 return("<notname>");
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 dump_entry(rawptr, entrynum)
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 u8 *rawptr;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 struct index_entry ent;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 bcopy(rawptr, &ent, 0x10);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 ent.len = le16toh(ent.len);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 ent.nptr1 = le16toh(ent.nptr1);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 ent.nptr2 = le16toh(ent.nptr2);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 ent.dataptr = le32toh(ent.dataptr);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 ent.unknown2 = le16toh(ent.unknown2);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 ent.version = le16toh(ent.version);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 printf("%x %s: len=%x %02X %02X nptr1=%x nptr2=%x %04X %04X\n",
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 entrynum, dataptr_to_name(ent.dataptr),
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 ent.len, ent.unknown1, ent.type,
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 ent.nptr1, ent.nptr2,
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 ent.unknown2, ent.version);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 dump_index()
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 u32 offset;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 u8 *entry;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 for (offset = 0x10; offset < eraseblk_size; offset += 0x10) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 entry = indexblk + offset;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 if (!bcmp(entry, blank_line, 16))
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 continue;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 dump_entry(entry, offset >> 4);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 main(argc, argv)
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 char **argv;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 if (argc != 4) {
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 fprintf(stderr, "usage: %s imgfile blksize nblocks\n", argv[0]);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 exit(1);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 }
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 imgfile = argv[1];
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 eraseblk_size = strtoul(argv[2], 0, 0);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 total_blocks = strtoul(argv[3], 0, 0);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 total_img_size = eraseblk_size * total_blocks;
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 read_img_file();
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 find_index_block();
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 dump_index();
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 exit(0);
d41c555d7f1d beginning to explore MysteryFFS
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 }