3 # AppleSingle/AppleDouble dump
5 # (c) 2009 by HAT <hat@fa2.so-net.ne.jp>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
18 open(INFILE, "<$ARGV[0]");
20 binmode(INFILE); # for DOS/Win
24 # Magic Number -----------------------------------------------
26 $rc = read(INFILE,$buf,4);
27 $val = unpack("N", $buf );
28 printf("Magic Num. : %08X", $val);
29 if ( $val == 0x00051600 ) {
30 printf(" : AppleSingle");
32 elsif ( $val == 0x00051607 ) {
33 printf(" : AppleDouble");
36 printf(" : Unknown" );
40 # Version Number ---------------------------------------------
42 $rc = read(INFILE,$buf,4);
43 $val = unpack("N", $buf );
44 printf("Ver. Num. : %08X", $val);
45 if ( $val == 0x00010000 ) {
46 printf(" : Version 1");
48 elsif ( $val == 0x00020000 ) {
49 printf(" : Version 2");
52 printf(" : Unknown" );
56 # v1:Home file system / v2:Filler ----------------------------
58 $rc = read(INFILE,$buf,16);
60 hexdump($buf, 16, 16, " ");
62 # Number of entities -----------------------------------------
64 $rc = read(INFILE,$buf,2);
65 $entnum = unpack("n", $buf );
66 printf("Num. of ent: %04X ", $entnum);
67 printf(" : %d", $entnum);
70 # data -------------------------------------------------------
72 for ( $num = 0 ; $num < $entnum ; $num++) {
74 seek(INFILE, ($num * 12 + 26), 0);
76 # Entry ---------------------------------------------------
78 $rc = read(INFILE,$buf,4);
79 $entid = unpack("N", $buf );
80 printf("\nEntry ID : %08X", $entid);
81 if ( $entid == 1 ) { printf(" : Data Fork"); }
82 elsif ( $entid == 2 ) { printf(" : Resource Fork"); }
83 elsif ( $entid == 3 ) { printf(" : Real Name"); }
84 elsif ( $entid == 4 ) { printf(" : Comment"); }
85 elsif ( $entid == 5 ) { printf(" : Icon, B&W"); }
86 elsif ( $entid == 6 ) { printf(" : Icon Color"); }
87 elsif ( $entid == 7 ) { printf(" : File Info"); }
88 elsif ( $entid == 8 ) { printf(" : File Dates Info"); }
89 elsif ( $entid == 9 ) { printf(" : Finder Info"); }
90 elsif ( $entid == 10 ) { printf(" : Macintosh File Info"); }
91 elsif ( $entid == 11 ) { printf(" : ProDOS File Info"); }
92 elsif ( $entid == 12 ) { printf(" : MS-DOS File Info"); }
93 elsif ( $entid == 13 ) { printf(" : Short Name"); }
94 elsif ( $entid == 14 ) { printf(" : AFP File Info"); }
95 elsif ( $entid == 15 ) { printf(" : Directory ID"); }
96 elsif ( $entid == 0x8053567E ) { printf(" : CNID (Netatalk Extended)"); }
97 elsif ( $entid == 0x8053594E ) { printf(" : DB stamp (Netatalk Extended)"); }
98 elsif ( $entid == 0x80444556 ) { printf(" : dev (Netatalk Extended)"); }
99 elsif ( $entid == 0x80494E4F ) { printf(" : inode (Netatalk Extended)"); }
100 else { printf(" : Unknown"); }
103 # Offset -------------------------------------------------
105 $rc = read(INFILE,$buf,4);
106 $ofst = unpack("N", $buf );
107 printf("Offset : %08X", $ofst);
108 printf(" : %d ", $ofst);
110 # Length -------------------------------------------------
112 $rc = read(INFILE,$buf,4);
113 $len = unpack("N", $buf );
114 printf("\nLength : %08X", $len);
115 printf(" : %d", $len);
120 # if ( $entid == 1 ) { ; } # Data Fork
121 # if ( $entid == 2 ) { ; } # Resource Fork
122 # if ( $entid == 3 ) { ; } # Real Name
123 # if ( $entid == 4 ) { ; } # Comment
124 # if ( $entid == 5 ) { ; } # Icon, B&W
125 # if ( $entid == 6 ) { ; } # Icon Color
126 # if ( $entid == 7 ) { ; } # File Info
127 if ( $entid == 8 ) { filedatesdump($ofst,$len); }
128 elsif ( $entid == 9 ) { finderinfodump($ofst,$len); }
129 # if ( $entid == 10 ) { ; } # Macintosh File Info
130 # if ( $entid == 11 ) { ; } # ProDOS File Info
131 # if ( $entid == 12 ) { ; } # MS-DOS File Info
132 # if ( $entid == 13 ) { ; } # Short Name
133 # if ( $entid == 14 ) { ; } # AFP File Info
134 # if ( $entid == 15 ) { ; } # Directory ID
135 # if ( $entid == 0x8053567E ) { ; } # CNID (Netatalk Extended)
136 # if ( $entid == 0x8053594E ) { ; } # DB stamp (Netatalk Extended)
137 # if ( $entid == 0x80444556 ) { ; } # dev (Netatalk Extended)
138 # if ( $entid == 0x80494E4F ) { ; } # inode (Netatalk Extended)
140 # Dump ---------------------------------------------------
142 seek(INFILE, $ofst, 0);
144 for ( $line = 0 ; $line < $quo ; $line++) {
145 $rc = read(INFILE, $buf, 16);
146 printf ( "%08X :", $addrs);
147 hexdump($buf, 16, 16, " ");
148 $addrs = $addrs + 0x10;
151 $rc = read(INFILE, $buf, $rem);
152 printf ( "%08X :", $addrs);
153 hexdump($buf, $rem, 16, " ");
160 #sub -----------------------------------------------------------
163 my ($ofst, $len) = @_;
168 @datetype =('create ', 'modify ', 'backup ', 'access ');
170 seek(INFILE, $ofst, 0);
172 for ( $i = 0 ; $i < 4 ; $i++) {
173 $rc = read(INFILE,$buf,4);
174 $datedata = unpack("N", $buf );
175 if ($datedata < 0x80000000) {
176 $datestr = gmtime( $datedata + 946684800)
178 .localtime( $datedata + 946684800)
180 } elsif ($datedata == 0x80000000) {
181 $datestr = "Unknown or Initial";
183 $datestr = gmtime( $datedata - 3348282496)
185 .localtime( $datedata - 3348282496)
188 printf ("%s : %08X : %s\n",$datetype[$i], $datedata, $datestr);
193 my ($ofst, $len) = @_;
195 seek(INFILE, $ofst, 0);
197 $rc = read(INFILE,$buf,4);
199 hexdump($buf, 4, 4, "");
201 $rc = read(INFILE,$buf,4);
203 hexdump($buf, 4, 4, "");
205 $rc = read(INFILE,$buf,2);
206 $flags = unpack("n", $buf );
207 printf ("isAlias : %d\n", ($flags >> 15) & 1);
208 printf ("Invisible : %d\n", ($flags >> 14) & 1);
209 printf ("hasBundle : %d\n", ($flags >> 13) & 1);
210 printf ("nameLocked : %d\n", ($flags >> 12) & 1);
211 printf ("Stationery : %d\n", ($flags >> 11) & 1);
212 printf ("CustomIcon : %d\n", ($flags >> 10) & 1);
213 printf ("Reserved : %d\n", ($flags >> 9) & 1);
214 printf ("Inited : %d\n", ($flags >> 8) & 1);
215 printf ("NoINITS : %d\n", ($flags >> 7) & 1);
216 printf ("Shared : %d\n", ($flags >> 6) & 1);
217 printf ("SwitchLaunc: %d\n", ($flags >> 5) & 1);
218 printf ("colorReserv: %d\n", ($flags >> 4) & 1);
219 printf ("color : %d%d%d\n", ($flags >> 3) & 1,
222 printf ("isOnDesk : %d\n", ($flags >> 0) & 1);
224 $rc = read(INFILE,$buf,4);
226 hexdump($buf, 4, 4, "");
228 $rc = read(INFILE,$buf,2);
230 hexdump($buf, 2, 4, "");
232 $rc = read(INFILE,$buf,2);
234 hexdump($buf, 2, 4, "");
236 $rc = read(INFILE,$buf,2);
238 hexdump($buf, 2, 4, "");
239 $rc = read(INFILE,$buf,2);
241 hexdump($buf, 2, 4, "");
242 $rc = read(INFILE,$buf,2);
244 hexdump($buf, 2, 4, "");
246 $rc = read(INFILE,$buf,1);
248 hexdump($buf, 1, 4, "");
250 $rc = read(INFILE,$buf,1);
252 hexdump($buf, 1, 4, "");
254 $rc = read(INFILE,$buf,2);
256 hexdump($buf, 2, 4, "");
258 $rc = read(INFILE,$buf,4);
260 hexdump($buf, 4, 4, "");
269 my ($eaofst, $ealen);
271 $rc = read(INFILE,$buf,2);
273 hexdump($buf, 2, 4, "");
275 $rc = read(INFILE,$buf,4);
277 hexdump($buf, 4, 4, "");
279 $rc = read(INFILE,$buf,4);
280 print "debug_tag : ";
281 hexdump($buf, 4, 4, "");
283 $rc = read(INFILE,$buf,4);
284 print "total_size : ";
285 hexdump($buf, 4, 4, "");
287 $rc = read(INFILE,$buf,4);
288 print "data_start : ";
289 hexdump($buf, 4, 4, "");
291 $rc = read(INFILE,$buf,4);
292 print "data_length: ";
293 hexdump($buf, 4, 4, "");
295 $rc = read(INFILE,$buf,4);
296 print "reserved[2]: ";
297 hexdump($buf, 4, 4, "");
299 $rc = read(INFILE,$buf,4);
300 print "reserved[1]: ";
301 hexdump($buf, 4, 4, "");
303 $rc = read(INFILE,$buf,4);
304 print "reserved[0]: ";
305 hexdump($buf, 4, 4, "");
307 $rc = read(INFILE,$buf,2);
309 hexdump($buf, 2, 4, "");
311 $rc = read(INFILE,$buf,2);
312 print "num_attrs : ";
313 hexdump($buf, 2, 4, "");
318 my ($buf, $len, $col, $delimit) = @_;
324 for ( $i=0 ; $i < $len ; $i++ ) {
325 $val = substr($buf, $i, 1);
327 $hexstr .= sprintf("%s%02X", $delimit, $ascval);
329 if (($ascval < 32) || ( $ascval > 126 )) {
334 for ( ; $i < $col ; $i++) {
335 $hexstr .= " ".$delimit;
339 printf("%s : %s", $hexstr,$ascstr);
344 sub htonl { unpack("N",pack("L",shift)) }
345 sub htons { unpack("n",pack("S",shift)) }
346 sub ntohl { unpack("L",pack("N",shift)) }
347 sub ntohs { unpack("S",pack("n",shift)) }