| 1 | package Finnigan::Decoder; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010000; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings FATAL => qw( all ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = 0.0206; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Encode qw//; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw/confess/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 2024 | ▶ | sub read { | ||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 12 | 2024 | my ($class, $stream, $fields, $any_arg) = @_; | |||||||||||||||||||||||||||||||
| 13 | 2024 | my $self = {size => 0}; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 2024 | bless $self, $class; | |||||||||||||||||||||||||||||||
| 16 | 2024 | $self->decode($stream, $fields, $any_arg); | |||||||||||||||||||||||||||||||
| 17 | 2024 | return $self; | |||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 28 | ▶ | sub iterate_object { | ||||||||||||||||||||||||||||||
|
Subroutine
iterate_object: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 21 | 28 | my ($self, $stream, $count, $name, $class, $any_arg) = @_; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 28 | my $addr = tell $stream; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 28 | my $current_element_number = keys(%{$self->{data}}) + 1; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 28 | ▶ | confess qq(key "$name" already exists) if $self->{data}->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 28 | my $size = 0; | |||||||||||||||||||||||||||||||
| 30 | 28 | foreach my $i ( 1 .. $count ) { | |||||||||||||||||||||||||||||||
| 31 | 1791 | my $value = $class->decode($stream, $any_arg); | |||||||||||||||||||||||||||||||
| 32 | 1791 | $size += $value->{size}; | |||||||||||||||||||||||||||||||
| 33 | 1791 | push @{$self->{data}->{$name}->{value}}, $value; | |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 28 | $self->{data}->{$name}->{seq} = $current_element_number; | |||||||||||||||||||||||||||||||
| 37 | $self->{data}->{$name}->{addr} = $addr, | ||||||||||||||||||||||||||||||||
| 38 | $self->{data}->{$name}->{size} = $size, | ||||||||||||||||||||||||||||||||
| 39 | $self->{data}->{$name}->{type} = "$class\[\]", | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 28 | $self->{size} += $size; | |||||||||||||||||||||||||||||||
| 42 | 28 | $self->{current_element_number}++; | |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 28 | return $self; | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 584 | ▶ | sub iterate_scalar { | ||||||||||||||||||||||||||||||
|
Subroutine
iterate_scalar: called CC=12 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 48 | 584 | my ($self, $stream, $count, $name, $desc) = @_; | |||||||||||||||||||||||||||||||
| 49 | 584 | my ($template, $type) = @$desc; | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 584 | my $addr = my $current_addr = tell $stream; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 584 | my $current_element_number = keys(%{$self->{data}}) + 1; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 584 | ▶ | confess qq(key "$name" already exists) if $self->{data}->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 584 | my $size = 0; | |||||||||||||||||||||||||||||||
| 58 | 584 | my ($rec, $nbytes); | |||||||||||||||||||||||||||||||
| 59 | 584 | my ($i, $bytes_to_read); | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 584 | ▶ | if ( $template eq 'varstr' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | if ( $type eq 'PascalStringWin32' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | for ($i = 1; $i <= $count; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | # read the prefix counter into $nchars | ||||||||||||||||||||||||||||||||
| 65 | 2 | my $bytes_to_read = 4; | |||||||||||||||||||||||||||||||
| 66 | 2 | $nbytes = CORE::read $stream, $rec, $bytes_to_read; | |||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | $nbytes == $bytes_to_read | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | or die "could not read all $bytes_to_read bytes of the prefix counter in $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 69 | 2 | my $nchars = unpack "V", $rec; | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | # read the 2-byte characters | ||||||||||||||||||||||||||||||||
| 72 | 2 | $bytes_to_read = 2*$nchars; | |||||||||||||||||||||||||||||||
| 73 | 2 | $nbytes = CORE::read $stream, $rec, $bytes_to_read; | |||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | $nbytes == $bytes_to_read | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | or die "could not read all $nchars 2-byte characters of $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 76 | 2 | $nbytes += 4; # total string length | |||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 2 | $size += $nbytes; | |||||||||||||||||||||||||||||||
| 79 | 2 | $current_addr += $nbytes; | |||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 2 | push @{$self->{data}->{$name}->{value}}, Encode::decode('UTF-16LE', (pack "C*", unpack "U0C*", $rec)); | |||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | else { | ||||||||||||||||||||||||||||||||
| 85 | 0 | confess "unknown varstr type $type"; | |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||||||
| 89 | 583 | my $template_length = length(pack($template,())); | |||||||||||||||||||||||||||||||
| 90 | 583 | ▶ | if ( substr($template, 0, 3) eq 'U0C' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | 0 | foreach $i ( 1 .. $count ) { | |||||||||||||||||||||||||||||||
| 92 | 0 | $nbytes = CORE::read $stream, $rec, $template_length; | |||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $nbytes == $template_length | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 94 | or die "could not read all $template_length bytes of $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 0 | $size += $nbytes; | |||||||||||||||||||||||||||||||
| 97 | 0 | $current_addr += $nbytes; | |||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 0 | push @{$self->{data}->{$name}->{value}}, pack ( "C*", unpack $template, $rec ); | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||
| 103 | 583 | foreach $i ( 1 .. $count ) { | |||||||||||||||||||||||||||||||
| 104 | 4243 | $nbytes = CORE::read $stream, $rec, $template_length; | |||||||||||||||||||||||||||||||
| 105 | 4243 | ▶ | $nbytes == $template_length | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 106 | or die "could not read all $template_length bytes of $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 4243 | $size += $nbytes; | |||||||||||||||||||||||||||||||
| 109 | 4243 | $current_addr += $nbytes; | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 4243 | push @{$self->{data}->{$name}->{value}}, unpack ( $template, $rec ); | |||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | 584 | $self->{data}->{$name}->{seq} = $current_element_number; | |||||||||||||||||||||||||||||||
| 117 | $self->{data}->{$name}->{addr} = $addr, | ||||||||||||||||||||||||||||||||
| 118 | $self->{data}->{$name}->{size} = $size, | ||||||||||||||||||||||||||||||||
| 119 | $self->{data}->{$name}->{type} = $type, | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 584 | $self->{size} += $size; | |||||||||||||||||||||||||||||||
| 122 | 584 | $self->{current_element_number}++; | |||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 584 | return $self; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 2114 | ▶ | sub decode { | ||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=20 SCAR=30.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 128 | 2114 | my ($self, $stream, $fields, $any_arg) = @_; | |||||||||||||||||||||||||||||||
| 129 | 2114 | my ( $rec, $nbytes ); | |||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | 2114 | my $current_addr = tell $stream; | |||||||||||||||||||||||||||||||
| 132 | 2114 | ▶ | $self->{addr} ||= $current_addr; # assign the address only if called | ||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->{"addr"} ||= $current_addr
MC/DC100%2/2
$self->{"addr"} ||= $current_addr
$self->{"addr"}
$current_addr
Truth table100%3/3
A ||= B
A= $self->{"addr"}B= $current_addr
| |||||||||||||||||||||||||||||||||
| 133 | # the first time (because decoding | ||||||||||||||||||||||||||||||||
| 134 | # can be done in multiple chunks) | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 2114 | my $current_element_number = keys %{$self->{data}}; | |||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||
| 138 | 2114 | my $value; | |||||||||||||||||||||||||||||||
| 139 | 2114 | foreach my $i ( 0 .. @$fields/2 - 1 ) { | |||||||||||||||||||||||||||||||
| 140 | 14793 | my $name = $fields->[2*$i]; | |||||||||||||||||||||||||||||||
| 141 | 14793 | ▶ | unless ( $fields->[2*$i+1] ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | # it is a spacer in the human-readable generic record | ||||||||||||||||||||||||||||||||
| 143 | 536 | $self->{data}->{$name} = { | |||||||||||||||||||||||||||||||
| 144 | seq => $current_element_number + $i, | ||||||||||||||||||||||||||||||||
| 145 | addr => $current_addr, | ||||||||||||||||||||||||||||||||
| 146 | size => 0, | ||||||||||||||||||||||||||||||||
| 147 | type => 'spacer', | ||||||||||||||||||||||||||||||||
| 148 | value => '', | ||||||||||||||||||||||||||||||||
| 149 | }; | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 536 | $self->{current_element_number} = $i; | |||||||||||||||||||||||||||||||
| 152 | 536 | next; | |||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | 14257 | my ($template, $type) = @{$fields->[2*$i+1]}; | |||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | 14257 | ▶ | confess qq(key "$name" already exists) if $self->{data}->{$name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | 14257 | ▶ | if ( $template eq 'object' ) { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 160 | 93 | $value = $type->decode($stream, $any_arg); | |||||||||||||||||||||||||||||||
| 161 | 93 | $nbytes = $value->{size}; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | elsif ( $template eq 'varstr' ) { | ||||||||||||||||||||||||||||||||
| 164 | 655 | ▶ | if ( $type eq 'PascalStringWin32' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 165 | # read the prefix counter into $nchars | ||||||||||||||||||||||||||||||||
| 166 | 655 | my $bytes_to_read = 4; | |||||||||||||||||||||||||||||||
| 167 | 655 | $nbytes = CORE::read $stream, $rec, $bytes_to_read; | |||||||||||||||||||||||||||||||
| 168 | 655 | ▶ | $nbytes == $bytes_to_read | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 169 | or die "could not read all $bytes_to_read bytes of the prefix counter in $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 170 | 655 | my $nchars = unpack "V", $rec; | |||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | # read the 2-byte characters | ||||||||||||||||||||||||||||||||
| 173 | 655 | $bytes_to_read = 2*$nchars; | |||||||||||||||||||||||||||||||
| 174 | 655 | $nbytes = CORE::read $stream, $rec, $bytes_to_read; | |||||||||||||||||||||||||||||||
| 175 | 655 | ▶ | $nbytes == $bytes_to_read | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 176 | or die "could not read all $nchars 2-byte characters of $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 177 | 655 | $rec =~ s/\xb0/\*/; # remove the degree sign | |||||||||||||||||||||||||||||||
| 178 | #print(STDERR (ord > 127 ? sprintf("<%02X>", ord) : $_)) for(split //, $rec); print STDERR "\n"; | ||||||||||||||||||||||||||||||||
| 179 | 655 | $value = Encode::decode('UTF-16LE', (pack "C*", unpack "U0C*", $rec)); | |||||||||||||||||||||||||||||||
| 180 | 655 | $nbytes += 4; | |||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||
| 182 | else { | ||||||||||||||||||||||||||||||||
| 183 | 0 | confess "unknown varstr type $type"; | |||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | elsif ( $template eq 'string' ) { | ||||||||||||||||||||||||||||||||
| 187 | 208 | ▶ | if ( substr($type, 0, 6) eq 'ASCIIZ' ) { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 188 | 66 | (undef, my $bytes_to_read) = split ":", $type; | |||||||||||||||||||||||||||||||
| 189 | 66 | $nbytes = CORE::read $stream, $rec, $bytes_to_read; | |||||||||||||||||||||||||||||||
| 190 | 66 | ▶ | $nbytes == $bytes_to_read | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 191 | or die "could not read all $bytes_to_read bytes of the string in $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 192 | 66 | $value = unpack "Z*", $rec; | |||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | elsif ( substr($type, 0, 9) eq 'UTF-16-LE' ) { | ||||||||||||||||||||||||||||||||
| 195 | 142 | (undef, my $bytes_to_read) = split ":", $type; | |||||||||||||||||||||||||||||||
| 196 | 142 | $nbytes = CORE::read $stream, $rec, $bytes_to_read; | |||||||||||||||||||||||||||||||
| 197 | 142 | ▶ | $nbytes == $bytes_to_read | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 198 | or die "could not read all $bytes_to_read bytes of the string in $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 199 | 142 | ($value) = split /\0/, Encode::decode('UTF-16LE', (pack "C*", unpack "U0C*", $rec)); # decode and truncate at 0 | |||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||
| 201 | elsif ( substr($type, 0, 9) eq 'UTF-16-BE' ) { | ||||||||||||||||||||||||||||||||
| 202 | 0 | confess "UTF-16-BE not implemented"; | |||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||
| 204 | else { | ||||||||||||||||||||||||||||||||
| 205 | 0 | confess "unknown string type"; | |||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||
| 208 | elsif ( $template eq 'windows_time' ) { | ||||||||||||||||||||||||||||||||
| 209 | 14 | my $bytes_to_read = 8; | |||||||||||||||||||||||||||||||
| 210 | 14 | $nbytes = CORE::read $stream, $rec, $bytes_to_read; | |||||||||||||||||||||||||||||||
| 211 | 14 | ▶ | $nbytes == $bytes_to_read | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 212 | or die "could not read all $bytes_to_read bytes of $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 213 | 14 | my ($w1, $w2) = unpack "VV", $rec; | |||||||||||||||||||||||||||||||
| 214 | 14 | $value = scalar gmtime (($w2 * 4294967296 + $w1) / 10000000 - 11644473600); # Windows timestamp is 100s of ns since Jan 1 1601 | |||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||
| 216 | else { | ||||||||||||||||||||||||||||||||
| 217 | 13287 | my $bytes_to_read = length(pack($template,())); | |||||||||||||||||||||||||||||||
| 218 | 13287 | $nbytes = CORE::read $stream, $rec, $bytes_to_read; | |||||||||||||||||||||||||||||||
| 219 | 13287 | ▶ | $nbytes == $bytes_to_read | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 220 | or die "could not read all $bytes_to_read bytes of $name at $current_addr"; | ||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | 13287 | ▶ | if ( substr($template, 0, 3) eq 'U0C' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 223 | 29 | $value = pack "C*", unpack $template, $rec; | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | else { | ||||||||||||||||||||||||||||||||
| 226 | 13258 | $value = unpack $template, $rec; | |||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | 14257 | $self->{data}->{$name} = { | |||||||||||||||||||||||||||||||
| 231 | seq => $current_element_number + $i, | ||||||||||||||||||||||||||||||||
| 232 | addr => $current_addr, | ||||||||||||||||||||||||||||||||
| 233 | size => $nbytes, | ||||||||||||||||||||||||||||||||
| 234 | type => $type, | ||||||||||||||||||||||||||||||||
| 235 | value => $value, | ||||||||||||||||||||||||||||||||
| 236 | }; | ||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | 14257 | $current_addr = tell $stream; | |||||||||||||||||||||||||||||||
| 239 | 14257 | $self->{size} += $nbytes; | |||||||||||||||||||||||||||||||
| 240 | 14257 | $self->{current_element_number} = $i; | |||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 2114 | return $self; | |||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | 10 | ▶ | sub size { | ||||||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 247 | 10 | shift->{size}; | |||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | 12 | ▶ | sub data { | ||||||||||||||||||||||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 251 | 12 | shift->{data}; | |||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub addr { | ||||||||||||||||||||||||||||||
|
Subroutine
addr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 255 | 0 | shift->{addr}; | |||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub item { | ||||||||||||||||||||||||||||||
|
Subroutine
item: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 259 | 0 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||
| 260 | 0 | $self->{data}->{$key}; | |||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | sub values { | ||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 264 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 265 | 0 | return {map { $_ => $self->{data}->{$_}->{value} } keys %{$self->{data}}}; | |||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub dump { | ||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=30 SCAR=68.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 269 | 0 | my ( $self, %arg ) = @_; | |||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | 0 | my $addr = $self->{addr}; | |||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $arg{header}++ unless exists $arg{header}; # print the header by default | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||
| 275 | my @keys = sort { | ||||||||||||||||||||||||||||||||
| 276 | $self->data->{$a}->{seq} <=> $self->data->{$b}->{seq} | ||||||||||||||||||||||||||||||||
| 277 | 0 | } keys %{$self->{data}}; | |||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ( $arg{filter} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 280 | 0 | my %filter = map {$_ => 1} @{$arg{filter}}; | |||||||||||||||||||||||||||||||
| 281 | 0 | @keys = grep {$filter{$_}} @keys; | |||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if ($arg{style} and $arg{style} eq 'html') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$arg{"style"} and $arg{"style"} eq "html"
MC/DC0%0/2
$arg{"style"} and $arg{"style"} eq "html"
$arg{"style"}
$arg{"style"} eq "html"
Truth table0%0/3
A and B
A= $arg{"style"}B= $arg{"style"} eq "html"
| |||||||||||||||||||||||||||||||||
| 285 | 0 | say "<table>"; | |||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | say " <tr> <td>offset</td> <td>size</td> <td>type</td> <td>key</td> <td>value</td> </tr>" if $arg{header}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 287 | 0 | foreach my $key ( @keys ) { | |||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my $offset = $arg{relative} ? $self->item($key)->{addr} - $addr : $self->item($key)->{addr}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 289 | 0 | my $value = $self->item($key)->{value}; | |||||||||||||||||||||||||||||||
| 290 | 0 | my $type = $self->item($key)->{type}; | |||||||||||||||||||||||||||||||
| 291 | 0 | $type =~ s/^Finnigan:://; | |||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 293 | 0 | $value = join ", ", map {"$_"} @$value; | |||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if ( $type eq 'RawBytes' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 296 | 0 | my $len = length($value); | |||||||||||||||||||||||||||||||
| 297 | 0 | my @list = unpack('C*', substr($value, 0, 16)); | |||||||||||||||||||||||||||||||
| 298 | 0 | $_ = sprintf "%2.2x", $_ for @list; | |||||||||||||||||||||||||||||||
| 299 | 0 | $value = join(" ", @list); | |||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | $value .= " ..." if $len > 16; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||
| 302 | say " <tr>" | ||||||||||||||||||||||||||||||||
| 303 | . " <td>" . $offset . "</td>" | ||||||||||||||||||||||||||||||||
| 304 | 0 | . " <td>" . $self->item($key)->{size} . "</td>" | |||||||||||||||||||||||||||||||
| 305 | . " <td>" . $type . "</td>" | ||||||||||||||||||||||||||||||||
| 306 | . " <td>" . $key . "</td>" | ||||||||||||||||||||||||||||||||
| 307 | . " <td>$value</td>" | ||||||||||||||||||||||||||||||||
| 308 | . " </tr>" | ||||||||||||||||||||||||||||||||
| 309 | ; | ||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||
| 311 | 0 | say "</table>"; | |||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||
| 313 | ▶ | elsif ($arg{style} and $arg{style} eq 'wiki') { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$arg{"style"} and $arg{"style"} eq "wiki"
MC/DC0%0/2
$arg{"style"} and $arg{"style"} eq "wiki"
$arg{"style"}
$arg{"style"} eq "wiki"
Truth table0%0/3
A and B
A= $arg{"style"}B= $arg{"style"} eq "wiki"
| |||||||||||||||||||||||||||||||||
| 314 | 0 | ▶ | say "|| " . join(" || ", qw/offset size type key value/) . " ||" if $arg{header}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 315 | 0 | foreach my $key ( @keys ) { | |||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | my $offset = $arg{relative} ? $self->item($key)->{addr} - $addr : $self->item($key)->{addr}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 317 | 0 | my $value = $self->item($key)->{value}; | |||||||||||||||||||||||||||||||
| 318 | 0 | my $type = $self->item($key)->{type}; | |||||||||||||||||||||||||||||||
| 319 | 0 | $type =~ s/^Finnigan:://; | |||||||||||||||||||||||||||||||
| 320 | 0 | $type =~ s/\[\]/\`[]\`/; | |||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if ($self->item($key)->{type} eq 'UTF16LE' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->item($key)->{"type"} eq "UTF16LE" and substr($value, 0, 2) eq "\0\0"
MC/DC0%0/2
$self->item($key)->{"type"} eq "UTF16LE" and substr($value, 0, 2) eq "\0\0"
$self->item($key)->{"type"} eq "UTF16LE"
substr($value, 0, 2) eq "\0\0"
Truth table0%0/3
A and B
A= $self->item($key)->{"type"} eq "UTF16LE"B= substr($value, 0, 2) eq "\0\0"
| |||||||||||||||||||||||||||||||||
| 322 | and substr($value, 0, 2) eq "\x00\x00") { | ||||||||||||||||||||||||||||||||
| 323 | 0 | $value =~ s/\x00/00 /g; | |||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | if (length($value) > 20) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 325 | 0 | $value = substr($value, 0, 30) . "..."; | |||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 329 | 0 | $value = join ", ", map {"$_"} @$value; | |||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ( $type eq 'RawBytes' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 332 | 0 | my $len = length($value); | |||||||||||||||||||||||||||||||
| 333 | 0 | my @list = unpack('C*', substr($value, 0, 16)); | |||||||||||||||||||||||||||||||
| 334 | 0 | $_ = sprintf "%2.2x", $_ for @list; | |||||||||||||||||||||||||||||||
| 335 | 0 | $value = join(" ", @list); | |||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | $value .= " ..." if $len > 16; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||
| 338 | say "|| " . join(" || ", | ||||||||||||||||||||||||||||||||
| 339 | $offset, | ||||||||||||||||||||||||||||||||
| 340 | $self->item($key)->{size}, | ||||||||||||||||||||||||||||||||
| 341 | 0 | $type, | |||||||||||||||||||||||||||||||
| 342 | "\`$key\`", | ||||||||||||||||||||||||||||||||
| 343 | "\`$value\`" | ||||||||||||||||||||||||||||||||
| 344 | ). " ||"; | ||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||
| 348 | 0 | foreach my $key ( @keys ) { | |||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | my $offset = $arg{relative} ? $self->item($key)->{addr} - $addr : $self->item($key)->{addr}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 350 | 0 | my $value = $self->item($key)->{value}; | |||||||||||||||||||||||||||||||
| 351 | 0 | my $type = $self->item($key)->{type}; | |||||||||||||||||||||||||||||||
| 352 | 0 | $type =~ s/^Finnigan:://; | |||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 354 | 0 | $value = join ", ", map {"$_"} @$value; | |||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if ( $type eq 'RawBytes' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 357 | 0 | my $len = length($value); | |||||||||||||||||||||||||||||||
| 358 | 0 | my @list = unpack('C*', substr($value, 0, 16)); | |||||||||||||||||||||||||||||||
| 359 | 0 | $_ = sprintf "%2.2x", $_ for @list; | |||||||||||||||||||||||||||||||
| 360 | 0 | $value = join(" ", @list); | |||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | $value .= " ..." if $len > 16; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||
| 363 | say join("\t", | ||||||||||||||||||||||||||||||||
| 364 | $offset, | ||||||||||||||||||||||||||||||||
| 365 | $self->item($key)->{size}, | ||||||||||||||||||||||||||||||||
| 366 | 0 | $type, | |||||||||||||||||||||||||||||||
| 367 | $key, | ||||||||||||||||||||||||||||||||
| 368 | "$value" | ||||||||||||||||||||||||||||||||
| 369 | ); | ||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | sub purge_unused_data { | ||||||||||||||||||||||||||||||
|
Subroutine
purge_unused_data: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 375 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||
| 376 | 0 | delete $self->{current_element_number}; | |||||||||||||||||||||||||||||||
| 377 | 0 | delete $self->{addr}; | |||||||||||||||||||||||||||||||
| 378 | 0 | delete $self->{size}; | |||||||||||||||||||||||||||||||
| 379 | 0 | foreach my $key (keys %{$self->{data}}) { | |||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | if ( substr($key, 0, 4) eq 'unkn' ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 381 | 0 | delete $self->{data}->{$key}; | |||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||
| 383 | else { | ||||||||||||||||||||||||||||||||
| 384 | 0 | delete $self->{data}->{$key}->{type}; | |||||||||||||||||||||||||||||||
| 385 | 0 | delete $self->{data}->{$key}->{addr}; | |||||||||||||||||||||||||||||||
| 386 | 0 | delete $self->{data}->{$key}->{seq}; | |||||||||||||||||||||||||||||||
| 387 | 0 | delete $self->{data}->{$key}->{size}; | |||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||
| 390 | 0 | return $self; | |||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||
| 393 | 2 | 1; | |||||||||||||||||||||||||||||||
| 394 | __END__ | ||||||||||||||||||||||||||||||||