Created
June 13, 2012 04:03
-
-
Save putnamhill/2921806 to your computer and use it in GitHub Desktop.
This script prints the version of adobe director used to create a file. Now detects director file versions 6, 7, 8, 8.5 (or 9.0), 10.1, 11.5.0r593, 11.5.8.612, and 12.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use constant IFFTYPES => qw( RIFX XFIR ); | |
use constant DIRTYPES => qw( MV93 39VM MC95 ); | |
use constant { | |
INT_SIZE => 4, | |
VERSION_OFFSET => 40 | |
}; | |
use Getopt::Long; | |
#use diagnostics; | |
BEGIN { | |
my $help; | |
GetOptions( | |
'help' => \$help, | |
'h' => \$help | |
); | |
if (defined $help) { | |
print <<'EOT'; | |
Usage: dir-vers.pl [options] file1 file2 ... | |
Print the version of director used to create a file. | |
If no files are passed on the command line, files are read from stdin (tip: feed with find). | |
Anything that is not a regular file is ignored. | |
Options: | |
-h, --help print this message | |
EOT | |
exit; | |
} | |
%version_table=( | |
'04c7' => '6.0', | |
'057e' => '7.0', | |
'0640' => '8.0', | |
'073a' => '8.5 or 9.0', | |
'0744' => '10.1', | |
'0782' => '11.5.0r593', | |
'0783' => '11.5.8.612', | |
'079f' => '12' | |
); | |
} | |
if ($#ARGV > -1) { | |
while ($#ARGV > -1) { # process every file on the command line | |
print_version($ARGV[0]); | |
shift; | |
} | |
} else { | |
while (<>) { # read from standard in if there's nothing on the command line | |
chomp; | |
print_version($_); | |
} | |
} | |
sub print_version{ | |
my ($path) = @_; | |
my $type; | |
my $len_buf; | |
my $len; | |
my $format_str; | |
my $properties_chunk_type; | |
(! -f $path) && return; # skip anything that's not a regular file | |
if (-r $path) { | |
open(FILE, '<', $path) or die "Can't open $path: $!"; | |
binmode(FILE); | |
read FILE, $type, INT_SIZE; | |
if (! grep(/$type/, IFFTYPES)) { | |
print STDERR "Does not appear to be an IFF file: $path ... skipping\n"; | |
return; | |
} | |
if ($type eq 'RIFX') { | |
$format_str = 'N'; # read big-endian 32 bit unsigned integers | |
$properties_chunk_type = 'DRCF'; | |
} else { | |
$format_str = 'V'; # read little-endian 32 bit unsigned integers | |
$properties_chunk_type = 'FCRD'; | |
} | |
seek FILE, INT_SIZE, 1; | |
read FILE, $type, INT_SIZE; | |
# one more sanity check: see if we recognize the second type string | |
if (! grep(/$type/, DIRTYPES)) { | |
print STDERR "Does not appear to be a director file: $path ... skipping\n"; | |
return; | |
} | |
read FILE, $type, INT_SIZE; | |
while (!($type eq $properties_chunk_type || eof(FILE))) { | |
read FILE, $len_buf, INT_SIZE; | |
$len = unpack($format_str, $len_buf); | |
seek FILE, $len, 1; | |
read FILE, $type, INT_SIZE; | |
} | |
if ($type eq $properties_chunk_type) { | |
seek FILE, VERSION_OFFSET, 1; | |
my $raw_hex_version; | |
read FILE, $raw_hex_version, 2; | |
my $str_hex_version = unpack('H*', $raw_hex_version); | |
if (defined($version_table{$str_hex_version})) { | |
print "$path\t0x$str_hex_version\t$version_table{$str_hex_version}\n"; | |
} else { | |
print STDERR "Could not lookup the version $str_hex_version of director file: $path ... skipping\n"; | |
} | |
} else { | |
print STDERR "Could not find the version of director file: $path ... skipping\n"; | |
} | |
} else { | |
print STDERR "Can't read file: $path ... skipping\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment