FreeCalypso > hg > freecalypso-reveng
annotate pirollback/catino.c @ 221:9f2e0c34fe33
ftmdump (C1xx factory data reverse eng) tool written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 17 Nov 2017 19:58:07 +0000 |
parents | 18fa570685de |
children |
rev | line source |
---|---|
49
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include <stdio.h> |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include <stdlib.h> |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 #include <string.h> |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 #include <strings.h> |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include "types.h" |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include "struct.h" |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 extern char *imgfile; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 extern struct inode_info inode[]; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 extern int last_inode; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 extern int journal_start_ino; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 u8 * |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 find_end_of_chunk(ino) |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 struct inode_info *ch = inode + ino; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 u8 *p; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 int i; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 p = ch->dataptr + ch->len; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 for (i = 1; i <= 16; i++) { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 if (!p[-i]) |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 return(p - i); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 if (p[-1] != 0xFF) |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 break; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 fprintf(stderr, |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 "chunk starting at %x (inode #%x): no valid termination found\n", |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 ch->offset, ino); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 exit(1); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 dump_cont_chain(start) |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 int ino; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 struct inode_info *inf; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 u8 *endp; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 for (ino = start; ino; ino = inf->descend) { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 inf = inode + ino; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 if (inf->type != 0xF4) { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 fprintf(stderr, |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 "continuation chunk #%x does not have type F4\n", |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 ino); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 exit(1); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 endp = find_end_of_chunk(ino); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 write(1, inf->dataptr, endp - inf->dataptr); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 do_cat(ino) |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 struct inode_info *inf = inode + ino; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 u8 *endp; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 if (inf->type != 0xF1) { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 fprintf(stderr, "error: requested inode is not a file\n"); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 exit(1); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 endp = find_end_of_chunk(ino); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 if (endp > inf->byte_after_name) |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 write(1, inf->byte_after_name, endp - inf->byte_after_name); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 dump_cont_chain(inf->descend); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 main(argc, argv) |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 char **argv; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 int ino; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 char *strtoul_endp; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 if (argc != 3) { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 usage: fprintf(stderr, "usage: %s ffs-image inode\n", argv[0]); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 exit(1); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 imgfile = argv[1]; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 ino = strtoul(argv[2], &strtoul_endp, 16); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
79 if (!argv[2][0] || *strtoul_endp) |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 goto usage; |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 read_img_file(); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 read_inodes(); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 walk_tree(); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 check_object_names(); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 parse_journal(); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
86 check_object_names(); /* rerun for "undeleted" objects */ |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
87 if (ino < 1 || ino > last_inode) { |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
88 fprintf(stderr, "%s: bad inode number specified\n", argv[0]); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
89 exit(1); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
90 } |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
91 do_cat(ino); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
92 exit(0); |
18fa570685de
pirollback: catino implemented, works
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
93 } |