Commit ed4d0c56 authored by Gary Allen Vollink's avatar Gary Allen Vollink
Browse files

Minor overhaul...

mapitem has been reduced to only needed bits.
Many comments about mapped and mapitem updated.
Output now prints subtitle for Boma SubTypes with subtitles.
Attempted fix for UTF-16 using Encode::decode()
parent 34c635c5
......@@ -3,6 +3,7 @@ use Crypt::Cipher;
use Compress::Zlib;
use Time::Local;
use POSIX;
use Encode ();
use strict;
# Common
......@@ -307,12 +308,21 @@ $map->{'boma_0011'} = {
};
$map->{'boma_0012'} = {
'subtitle' => q{Year-Seq?},
'subtitle' => q{Episode Comment},
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Year-Seq?} ],
36 => [ q{wstring}, 0, q{Episode Comment} ],
};
$map->{'boma_0016'} = {
'subtitle' => q{Episode Synopsis},
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Episode Synopsis} ],
};
$map->{'boma_0017'} = {
......@@ -324,6 +334,23 @@ $map->{'boma_0017'} = {
32 => [ 4, q{Play Count} ],
};
$map->{'boma_0018'} = {
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Series Title} ],
};
$map->{'boma_0019'} = {
'subtitle' => q{Series Episode Number},
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Episode Number} ],
};
$map->{'boma_001B'} = {
'subtitle' => q{Album Artist},
0 => [ q{string}, 4, q{Section Type} ],
......@@ -333,6 +360,15 @@ $map->{'boma_001B'} = {
36 => [ q{wstring}, 0, q{Album Artist} ],
};
$map->{'boma_001C'} = {
'subtitle' => q{Series (unknown info)},
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Series (unknown info)} ],
};
$map->{'boma_001D'} = {
'subtitle' => q{Unknown XML},
0 => [ q{string}, 4, q{Section Type} ],
......@@ -413,6 +449,15 @@ $map->{'boma_002E'} = {
36 => [ q{wstring}, 0, q{Copyright} ],
};
$map->{'boma_0033'} = {
'subtitle' => q{Series Synopsis},
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Series Synopsis} ],
};
$map->{'boma_0034'} = {
'subtitle' => q{Flavor String},
0 => [ q{string}, 4, q{Section Type} ],
......@@ -549,6 +594,15 @@ $map->{'boma_012E'} = {
36 => [ q{wstring}, 0, q{iama Album Artist (2)} ],
};
$map->{'boma_012F'} = {
'subtitle' => q{Series Title},
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Series Title} ],
};
$map->{'boma_0190'} = {
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
......@@ -596,7 +650,7 @@ $map->{'boma_01FC'} = {
12 => [ q{subtype}, 4, q{boma SubType} ],
20 => [ q{string}, 4, q{SubSection Type} ], # [book]
24 => [ 4, q{SubSection Length} ],
28 => [ q{book}, 0, q{Book Strings} ],
28 => [ q{book}, 0, q{1FC Book Strings} ],
};
$map->{'boma_01FD'} = {
......@@ -606,7 +660,25 @@ $map->{'boma_01FD'} = {
12 => [ q{subtype}, 4, q{boma SubType} ],
20 => [ q{string}, 4, q{SubSection Type} ], # [book]
24 => [ 4, q{SubSection Length} ],
28 => [ q{book}, 0, q{Book Strings} ],
28 => [ q{book}, 0, q{1FD Book Strings} ],
};
$map->{'boma_01F4'} = {
'subtitle' => q{WString Hex Output},
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Unknown 64x4 WString Value} ],
};
$map->{'boma_01FE'} = {
'subtitle' => q{WString Hex Output},
0 => [ q{string}, 4, q{Section Type} ],
8 => [ q{offset}, 4, q{Section Length} ],
12 => [ q{subtype}, 4, q{boma SubType} ],
24 => [ 4, q{String Length} ],
36 => [ q{wstring}, 0, q{Unknown 64x4 WString Value} ],
};
$map->{'boma_01FF'} = {
......@@ -1938,7 +2010,8 @@ sub readInput
printf $dfh ("Actual file size %08x (%u)\n", $fsize, $fsize);
}
}
# 92 => [ 4, q{Max Crypt Size} ],
# 84 => [ 4, q{Max Crypt Size} ], hfma
# 92 => [ 4, q{Max Crypt Size} ], hdfm
elsif ( $title eq q{Max Crypt Size} ) {
$max_crypt_size = unpack($endian, $input);
printf $dfh "%08x (% 3u) : %s Max Crypt Size = %u\n"
......@@ -1947,8 +2020,8 @@ sub readInput
, $max_crypt_size;
}
elsif ( $title && length($title) ) {
#printf $dfh "%08x (% 3u) %s: %s\n"
# , $tell, $tell, $title, avHexdump($input, 4, $endian);
# The ONLY place mapitem is used, as it works
# with distinct items.
mapitem( \$hmap, $signature, $buffer, 0, $tell, $len);
}
else {
......@@ -2612,7 +2685,6 @@ sub substr_char
return $out;
}
sub substr_wchar
{
my $buffer = shift;
......@@ -2620,38 +2692,24 @@ sub substr_wchar
my $len = shift;
my $out = q{};
my $test = undef;
my $cx = 0;
while ( $cx < $len ) {
$test = substr($buffer, ($start+$cx), 2);
# This hasn't been tested on N style, but seems right.
if ( "V" == $endian ) {
# Little v, 2 bytes
$test = unpack("v", $test);
}
else {
# Little n, 2 bytes
$test = unpack("n", $test);
}
if ( $cx + 1 == $len ) {
$test = substr($buffer, ($start+$cx), 1);
$test = unpack("C", $test);
}
$out .= chr($test);
$cx += 2;
}
my $test = substr($buffer, $start, $len);
if ( "V" == $endian ) {
$out = Encode::decode('UTF-16le', $test);
} else {
$out = Encode::decode('UTF-16be', $test);
}
return $out;
}
#############################################################################
# mapped
# mapped()
#
# This function should replace all individual section checks... eventually.
##
# TODO:
# boma special cases should be handled here, too.
# This function walks through a complete section, sometimes remembering
# facts from other parts of the same section.
#
# Section memory is necessary for some sections (any that need string length).
##
sub mapped($$$\$)
{
......@@ -2701,12 +2759,6 @@ CX: while ( $cx < $os_end ) {
# Currently string types break becasue they don't "remember" the
# length parameter.
if ( $title && length($title) ) {
# my ($s, $a, $t) = mapitem( \$ismap, $type, $buffer, $current_loc, $cx, $len );
# $os_end = larger( $os_end, $s );
# $oa_end = larger( $oa_end, $a );
# $type = $t;
# }
# elsif ( 0 ) {
if ( q{string} eq $dtype ) {
if ( q{Section Type} eq $title ) {
$type = $input;
......@@ -2789,10 +2841,14 @@ CX: while ( $cx < $os_end ) {
} # End elsif ( q{offset} ... )
elsif ( q{subtype} eq $dtype ) {
my $ststr = "$type SubType";
my $subt = q{};
$input = getNumeric($input, $len);
my $maptest = sprintf "%s_%04X", $type, $input;
if ( exists($map->{$maptest}) ) {
$ismap = $map->{$maptest};
if ( exists( $ismap->{'subtitle'} ) ) {
$subt = sprintf( ' "%s"', $ismap->{'subtitle'} );
}
}
elsif ( q{msdh} eq $type ) {
# iTunes itl
......@@ -2823,15 +2879,16 @@ CX: while ( $cx < $os_end ) {
# msdh doesn't need SubType Maps
} # elsif ( q{msdh} eq $type )
else {
$subt = q{(Not SubMapped)};
if ( !exists $INFO{boma_no_sub}->{$input} ) {
$INFO{boma_no_sub}->{$input} = 1;
printf STDERR "\t\tNo SubType Map %s_%04X\n"
, $type, $input;
}
}
printf $dfh "%08x (% 3u) : %s: 0x%04X (%u)\n"
printf $dfh "%08x (% 3u) : %s: 0x%04X (%u) %s\n"
, $current_loc+$cx, $cx,
, $ststr, $input, $input;
, $ststr, $input, $input, $subt;
} # End elsif ( q{subtype} ... )
elsif ( q{strtype} eq $dtype ) {
$input = getNumeric($input, $len);
......@@ -2948,6 +3005,14 @@ CX: while ( $cx < $os_end ) {
return $current_loc + $os_end;
}
#############################################################################
# mapitem()
#
# This function is ONLY used during the mapping of the Envelope Header.
# mapped() is used anywhere else.
#
# mapitem() is able to work within a section that hasn't been fully read in.
##
sub mapitem
{
my $ismap_ptr = shift;
......@@ -3048,126 +3113,6 @@ sub mapitem
, $title
, $offset, $offset, $current_loc + $offset;
} # End elsif ( q{offset} ... )
elsif ( q{subtype} eq $dtype ) {
my $ststr = "$type SubType";
$input = getNumeric($input, $len);
my $maptest = sprintf "%s_%04X", $type, $input;
if ( exists($map->{$maptest}) ) {
$ismap = $map->{$maptest};
$$ismap_ptr = $map->{$maptest};
if ( exists( $ismap->{'subtitle'} ) ) {
$ststr .= sprintf( ' "%s"', $ismap->{'subtitle'} );
}
}
elsif ( q{msdh} eq $type ) {
# iTunes itl
if ( 0x0003 == $input ) {
my $slen = $oa_end - $os_end;
$ismap->{$os_end} = [
$slen,
q{msdh SubType 3 Unknown Block},
];
#printf $dfh "\t\t%s->{%u} = [ %u, q{unknown}];\n"
# , '$ismap', $os_end, $slen;
$os_end = $oa_end;
}
if ( 0x0004 == $input ) {
my $slen = $oa_end - $os_end;
$ismap->{$os_end} = [ q{string}, $slen, q{Library Location}];
#printf $dfh "\t\t%s->{%u} = [q{string}, %u, q{Library Location}];\n"
# , '$ismap', $os_end, $slen;
$os_end = $oa_end;
}
elsif ( 0x0013 == $input ) {
my $slen = $oa_end - $os_end;
$ismap->{$os_end} = [ q{string}, $slen, q{xml}];
#printf $dfh "\t\t%s->{%u} = [q{string}, %u, q{xml}];\n"
# , '$ismap', $os_end, $slen;
$os_end = $oa_end;
}
# msdh doesn't need SubType Maps
} # elsif ( q{msdh} eq $type )
else {
if ( !exists $INFO{boma_no_sub}->{$input} ) {
$INFO{boma_no_sub}->{$input} = 1;
printf STDERR "\t\tNo SubType Map %s_%04X\n"
, $type, $input;
}
}
printf $dfh "%08x (% 3u) : %s: 0x%04X (%u)\n"
, $current_loc+$cx, $cx,
, $ststr, $input, $input;
} # End elsif ( q{subtype} ... )
elsif ( q{strtype} eq $dtype ) {
$input = getNumeric($input, $len);
$chartype =
($input==0?"URI":
($input==1?"wide":
($input==2?"escURI":
($input==3?"narrow":
"unknown"
)
)
)
);
printf $dfh "%08x (% 3u) : %s: (%u) %s\n"
, $current_loc+$cx, $cx,
, $title, $input, $chartype;
} # End elsif ( q{strtype} ... )
elsif ( q{typestr} eq $dtype ) {
if ( q{wide} eq $chartype ) {
$input = substr_wchar($buffer, $current_loc+$cx, $len);
}
else {
$input = substr_char($buffer, $current_loc+$cx, $len);
}
printf $dfh "%08x (% 3u) : %s: [%s]\n"
, $current_loc+$cx, $cx,
, $title, $input;
} # End elsif ( q{typestr} ... )
elsif ( q{book} eq $dtype ) {
my $stringnext = 0;
my $prev_bit32 = 0;
my $pprev_bit32 = 0;
my $next_len = 0;
my $test = q{};
while ( $cx < $os_end ) {
if ( $stringnext ) {
$test = substr($buffer, $current_loc+$cx, $next_len);
my $string = unpack("Z[$next_len]", $test);
# Path Components to song file
# "Macintosh HD" (the name of hard drive that stores the song)."
# APFS Volume Group: ########-####-####-####-############
printf $dfh ("%08x (% 3u) %04X STRING [%d]: [%s]\n",
$current_loc+$cx, $cx, $stringnext, $next_len,
printable_str($string,0,$next_len));
$cx = $cx + $next_len
+ (($next_len % 4)?( 4 - ( $next_len % 4 ) ):0);
$stringnext = 0;
} # End if ( $stringnext )
else {
$test = substr($buffer, $current_loc+$cx, 4);
my $bit32 = unpack($endian, $test);
if ( 0x0901 == $bit32 ) {
$stringnext = $bit32;
$next_len = $prev_bit32;
}
elsif ( 0x0201 == $bit32 && 0x501 == $pprev_bit32 ) {
$stringnext = $bit32;
$next_len = $prev_bit32 - 1;
}
elsif ( 0x0101 == $bit32 ) {
$stringnext = $bit32;
$next_len = $prev_bit32;
}
$pprev_bit32 = $prev_bit32;
$prev_bit32 = $bit32;
printf $dfh "%08x (% 3u) %s\n"
, $current_loc+$cx, $cx, avHexdump($test, 4);
$cx += 4;
} # End else // if ( $stringnext )
} # End while ( $cx < $os_end )
} # End elsif ( q{book} ... )
else {
if ( 16 >= $len ) {
my $signed = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment