Here's something I saved that was orginally posted at racesimcentral a few years ago.
Code:
#!/usr/bin/perl -w
#
use strict;
use Compress::Zlib;
my $file = shift;
my $file_size = -s $file;
my $number_of_files;
my $address = 0;
open MAS, $file;
binmode(MAS);
print "header:", unpack("A11", &get_field( ($address + 0),11)), "\n";
print "Number Of Files: ", unpack("L1", &get_field( ($address+16),4)), "\n";
$number_of_files = unpack("L1", &get_field( ($address+16),4));
print "Length Files Data: ", unpack("L1", &get_field( ($address+20),4)), "\n";
my $file_data_size = unpack("L1", &get_field( ($address+20),4));
print "***************************************\n";
#This is where the file headers start in GTR/GTL MAS File.
my $next = 24;
my $file_offset = $file_size - $file_data_size;
my $file_count = 0;
while (($file_count < $number_of_files) && ($number_of_files > 0) )
{
($next, my $typeid, my $offset, my $dfsize, my $cfsize, my $fname) = &get_file_header($next);
$file_count++;
&get_file( $fname, ($offset+$file_offset), $cfsize);
}
close MAS;
exit(0);
sub get_field()
{
my $address = $_[0];
my $size = $_[1];
my $tmp;
seek(MAS,$address,0);
read(MAS,$tmp,$size);
return ($tmp);
}
sub get_file_header()
{
my $address = $_[0];
my @file;
$file[0] = unpack("L1", &get_field( ($address),4)); #File Type ID
$file[1] = unpack("L1", &get_field( ($address+4),4)); #File Offset
$file[2] = unpack("L1", &get_field( ($address+8),4)); #Decompressed File Size
$file[3] = unpack("L1", &get_field( ($address+12),4)); #Compressed File Size
$file[4] = unpack("A240", &get_field( ($address+16),240)); #File Name
return ((256+$address), @file);
}
sub print_file_headers()
{
my $address = $_[0];
print "Files Type ID: ", unpack("L1", &get_field( ($address),4)), "\n";
print "File Offset: ", unpack("L1", &get_field( ($address+4),4)), "\n";
print "Decompressed File Size: ", unpack("L1", &get_field( ($address+8),4)), "\n";
print "Compressed File Size: ", unpack("L1", &get_field( ($address+12),4)), "\n";
my $compressed_file_size = unpack("L1", &get_field( ($address+12),4));
print "File Name: ", unpack("A240", &get_field( ($address+16),240)), "\n";
print "***************************************\n";
return (256+$address);
}
sub get_file()
{
my $file_name = $_[0];
my $offset = $_[1];
my $csize = $_[2];
my $exit_code = 1;
my $file = &get_field( $offset, $csize);
my $output = uncompress($file);
if (defined $output)
{
open FILE, ">$file_name";
binmode(FILE);
print FILE $output;
print FILE $file;
close FILE;
print "$file_name\n";
}
else
{
print "uncompress Failed\n";
}
return ($exit_code);
}