Image/ExifTool/Protobuf.pm

filter: Statementstmt 80.5% 116 / 144 Branchbran 66.3% 77 / 116 Conditioncond 62.2% 33 / 53 MC/DCmcdc 31.2% 10 / 32 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 5 totaltotal 68.1% 244 / 358 CC 78 SCAR 52.9
CC
78
Cov
72%
ProcessProtobuf
274.4
ReadRecord
10.0
VarInt
6.0
CRAP 198.7
« Image/ExifTool/Nikon.pm ↑ Summary Image/ExifTool/AFCP.pm »
1 #------------------------------------------------------------------------------
2 # File: Protobuf.pm
3 #
4 # Description: Decode protocol buffer data
5 #
6 # Revisions: 2024-12-04 - P. Harvey Created
7 #
8 # Notes: Tag definitions for Protobuf tags support 'signed', 'unsigned',
9 # and 'int64s' formats for VARINT (type 0) values, 'int64u',
10 # 'int64s', 'rational64u', 'rational64s' and 'double' for I64
11 # (type 1), 'undef', 'string' and 'rational' for LEN (type 2),
12 # and 'int32u', 'int32s', 'rational32u', 'rational32s',
13 # 'fixed32u', 'fixed32s' and 'float' for I32 (type 5) values.
14 #
15 # References: 1) https://protobuf.dev/programming-guides/encoding/
16 #------------------------------------------------------------------------------
17  
18 package Image::ExifTool::Protobuf;
19  
20 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 12 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 12 $VERSION = '1.07';
25  
26 sub ProcessProtobuf($$$;$);
27  
28 # largest unsigned integer on this system (2^32 or 2^64 - 1)
29 12 my $intMax = ~0;
30  
31 # smallest unsigned integer that we interpret as int64s (0xffffffff00000000)
32 12 my $int64sMin = 18446744069414584320;
33  
34 #------------------------------------------------------------------------------
35 # Read bytes from dirInfo object
36 # Inputs: 0) dirInfo ref (with DataPt and Pos set), 1) number of bytes
37 # Returns: binary data or undef on error
38 sub GetBytes($$)
39 57578 ▶{
Subroutine GetBytes: called CC=2 SCAR=6.9
Pod undocumented
40 57578 my ($dirInfo, $n) = @_;
41 57578 my $dataPt = $$dirInfo{DataPt};
42 57578 my $pos = $$dirInfo{Pos};
43 57578 ▶ return undef if $pos + $n > length $$dataPt;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $n > length $$dataPt 81 57497 57578
44 57497 $$dirInfo{Pos} += $n;
45 57497 return substr($$dataPt, $pos, $n);
46 }
47  
48 #------------------------------------------------------------------------------
49 # Read variable-length integer
50 # Inputs: 0) dirInfo ref
51 # Returns: integer value
52 # - sets $$dirInfo{Bit0} according to bit 0 of returned value
53 # (necessary for cases where a signed integer exceeds $intMax)
54 sub VarInt($)
55 39576 ▶{
Subroutine VarInt: called CC=6 SCAR=17.9
Pod undocumented
56 39576 my $dirInfo = shift;
57 39576 my $buff = GetBytes($dirInfo, 1);
58 39576 ▶ return undef unless defined $buff;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buff 31 39545 39576
59 39545 my $val = ord($buff) & 0x7f;
60 39545 $$dirInfo{Bit0} = $val & 0x01;
61 39545 my $mult = 128;
62 39545 my $i = 0;
63 39545 for (;;) {
64 41222 ▶ last unless ord($buff) & 0x80;
Branch: 1 branch
BranchTrueFalseTotal
unless ord $buff & 128 32803 8419 41222
65 8419 $buff = GetBytes($dirInfo, 1);
66 8419 ▶ return undef unless defined $buff;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buff 0 8419 8419
67 8419 $val += (ord($buff) & 0x7f) * $mult;
68 8419 ▶ last unless ord($buff) & 0x80;
Branch: 1 branch
BranchTrueFalseTotal
unless ord $buff & 128 6741 1678 8419
69 1678 ▶ return undef if ++$i > 32; # set a reasonable limit
Branch: 1 branch
BranchTrueFalseTotal
if ++$i > 32 1 1677 1678
70 1677 $mult *= 128; # (Note: don't use integer bit shift to avoid integer overflow)
71 }
72 39544 return $val;
73 }
74  
75 #------------------------------------------------------------------------------
76 # Read protobuf record
77 # Inputs: 0) dirInfo ref
78 # Returns: 0) record payload (plus tag id and format type in list context) or undef on error
79 # Notes: Updates $$dirInfo{Pos} to start of next record, and sets $$dirInfo{Bit0}
80 # according to the least significant bit of type 0 (varInt) records
81 sub ReadRecord($)
82 22842 ▶{
Subroutine ReadRecord: called CC=10 SCAR=23.0
Pod undocumented
83 22842 my $dirInfo = shift;
84 22842 my $val = VarInt($dirInfo);
85 22842 ▶ return undef unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 6 22836 22842
86 22836 my $id = $val >> 3;
87 22836 my $type = $val & 0x07;
88 22836 my $buff;
89  
90 22836 ▶ if ($type == 0) { # varInt
Branch: 6 branches
BranchTrueFalseTotal
if ($type == 0) { } 12535 10301 22836
elsif ($type == 1) { } 380 9921 10301
elsif ($type == 2) { } 4153 5768 9921
elsif ($type == 3) { } 20 5748 5768
elsif ($type == 4) { } 74 5674 5748
elsif ($type == 5) { } 5547 127 5674
91 12535 $buff = VarInt($dirInfo);
92 } elsif ($type == 1) { # 64-bit number
93 380 $buff = GetBytes($dirInfo, 8);
94 } elsif ($type == 2) { # string, bytes or protobuf
95 4153 my $len = VarInt($dirInfo);
96 4153 ▶ if ($len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len) { } 3656 497 4153
97 3656 $buff = GetBytes($dirInfo, $len);
98 } else {
99 497 $buff = '';
100 }
101 } elsif ($type == 3) { # (deprecated start group)
102 20 $buff = '';
103 } elsif ($type == 4) { # (deprecated end group)
104 74 $buff = '';
105 } elsif ($type == 5) { # 32-bit number
106 5547 $buff = GetBytes($dirInfo, 4);
107 }
108 22836 ▶ return wantarray ? ($buff, $id, $type) : $buff;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 11129 11707 22836
109 }
110  
111 #------------------------------------------------------------------------------
112 # Check to see if this could be a protobuf object
113 # Inputs: 0) data reference
114 # Retursn: true if this looks like a protobuf
115 sub IsProtobuf($)
116 1745 ▶{
Subroutine IsProtobuf: called CC=3 SCAR=11.0
Pod undocumented
117 1745 my $pt = shift;
118 1745 my $dirInfo = { DataPt => $pt, Pos => 0 };
119 1745 for (;;) {
120 11713 ▶ return 0 unless defined ReadRecord($dirInfo);
Branch: 1 branch
BranchTrueFalseTotal
unless defined &ReadRecord($dirInfo) 207 11506 11713
121 11506 ▶ return 1 if $$dirInfo{Pos} == length $$pt;
Branch: 1 branch
BranchTrueFalseTotal
if $dirInfo->{"Pos"} == length $$pt 1538 9968 11506
122 }
123 }
124  
125 #------------------------------------------------------------------------------
126 # Process protobuf data (eg. DJI djmd timed data from Action4 videos) (ref 1)
127 # Inputs: 0) ExifTool ref, 1) dirInfo ref with DataPt, DataPos, DirName and Base,
128 # 2) tag table ptr, 3) prefix of parent protobuf ID's
129 # Returns: true on success
130 sub ProcessProtobuf($$$;$)
131 1539 ▶{
Subroutine ProcessProtobuf: called CC=61 SCAR=56.1
Pod undocumented
132 1539 my ($et, $dirInfo, $tagTbl, $prefix) = @_;
133 1539 my $dataPt = $$dirInfo{DataPt};
134 1539 my $dirName = $$dirInfo{DirName};
135 1539 ▶ my $dirStart = $$dirInfo{DirStart} || 0;
Condition50%1/2
$dirInfo->{'DirStart'} || 0
l!l
01539
MC/DC0%0/1
$dirInfo->{'DirStart'} || 0
$dirInfo->{'DirStart'}
Truth table50%1/2
A
A= $dirInfo->{'DirStart'}
Aresult
11
00
136 1539 ▶ my $dirLen = $$dirInfo{DirLen} || (length($$dataPt) - $dirStart);
Condition33%1/3
$dirInfo->{'DirLen'} || length($$dataPt) - $dirStart
l!l&&r!l&&!r
015390
MC/DC0%0/2
$dirInfo->{'DirLen'} || length($$dataPt) - $dirStart
$dirInfo->{'DirLen'} length($$dataPt) - $dirStart
Truth table33%1/3
A || B
A= $dirInfo->{'DirLen'}B= length($$dataPt) - $dirStart
ABresult
1X1
011
000
137 1539 my $dirEnd = $dirStart + $dirLen;
138 1539 ▶ my $dataPos = ($$dirInfo{Base} || 0) + ($$dirInfo{DataPos} || 0);
Condition75%3/4
$dirInfo->{'Base'} || 0
l!l
01539
$dirInfo->{'DataPos'} || 0
l!l
15381
MC/DC0%0/1
$dirInfo->{'Base'} || 0
$dirInfo->{'Base'}
MC/DC100%1/1
$dirInfo->{'DataPos'} || 0
$dirInfo->{'DataPos'}
Truth table50%1/2
A
A= $dirInfo->{'Base'}
Aresult
11
00
Truth table100%2/2
A
A= $dirInfo->{'DataPos'}
Aresult
11
00
139 1539 ▶ my $unknown = $et->Options('Unknown') || $et->Options('Verbose');
Condition33%1/3
$et->Options('Unknown') || $et->Options('Verbose')
l!l&&r!l&&!r
001539
MC/DC0%0/2
$et->Options('Unknown') || $et->Options('Verbose')
$et->Options('Unknown') $et->Options('Verbose')
Truth table33%1/3
A || B
A= $et->Options('Unknown')B= $et->Options('Verbose')
ABresult
1X1
011
000
140  
141 1539 ▶ $$dirInfo{Pos} = $$dirInfo{DirStart} || 0; # initialize buffer Pos
Condition50%1/2
$dirInfo->{'DirStart'} || 0
l!l
01539
MC/DC0%0/1
$dirInfo->{'DirStart'} || 0
$dirInfo->{'DirStart'}
Truth table50%1/2
A
A= $dirInfo->{'DirStart'}
Aresult
11
00
142 1539 $et->VerboseDir('Protobuf', undef, $dirLen);
143 1539 ▶ unless ($prefix) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($prefix) 1 1538 1539
144 1 $prefix = '';
145 1 ▶ $$et{ProtoPrefix}{$dirName} = '' unless defined $$et{ProtoPrefix}{$dirName};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $et->{"ProtoPrefix"}{$dirName} 1 0 1
146 1 SetByteOrder('II');
147 }
148 # prefix for unknown tags
149 1539 ▶ my $unkPre = $$tagTbl{TAG_PREFIX} ? $$tagTbl{TAG_PREFIX} . '_' : 'Protobuf ';
Branch: 1 branch
BranchTrueFalseTotal
$tagTbl->{'TAG_PREFIX'} ? : 1539 0 1539
150  
151 # loop through protobuf records
152 1539 for (;;) {
153 12668 my $pos = $$dirInfo{Pos};
154 12668 ▶ last if $pos >= $dirEnd;
Branch: 1 branch
BranchTrueFalseTotal
if $pos >= $dirEnd 1539 11129 12668
155 11129 my ($buff, $id, $type) = ReadRecord($dirInfo);
156 11129 ▶ defined $buff or $et->Warn('Protobuf format error'), last;
Branch: 1 branch
BranchTrueFalseTotal
defined $buff or $et->Warn("Protobuf format error"), last 11129 0 11129
157 11129 ▶ if ($type == 2 and $buff =~ /\.proto$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 2 and $buff =~ /\.proto$/) 0 11129 11129
Condition66%2/3
$type == 2 and $buff =~ /\.proto$/
!ll&&!rl&&r
906620630
MC/DC0%0/2
$type == 2 and $buff =~ /\.proto$/
$type == 2 $buff =~ /\.proto$/
Truth table66%2/3
A and B
A= $type == 2B= $buff =~ /\.proto$/
ABresult
0X0
100
111
158 # save protocol name separately for directory type
159 0 $$et{ProtoPrefix}{$dirName} = substr($buff, 0, -6) . '_';
160 0 $et->HandleTag($tagTbl, Protocol => $buff);
161 }
162 11129 my $tag = "$$et{ProtoPrefix}{$dirName}$prefix$id";
163 11129 my $tagInfo = $$tagTbl{$tag};
164 11129 ▶ if ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo) { } 1630 9499 11129
165 1630 ▶ next if $type != 2 and $$tagInfo{Unknown} and not $unknown;
Branch: 1 branch
BranchTrueFalseTotal
if $type != 2 and $tagInfo->{"Unknown"} and not $unknown 51 1579 1630
Condition83%5/6
$type != 2 and $tagInfo->{"Unknown"} and not $unknown
!ll&&!rl&&r
1579051
$type != 2 and $tagInfo->{"Unknown"}
!ll&&!rl&&r
1571851
MC/DC66%2/3
$type != 2 and $tagInfo->{"Unknown"} and not $unknown
$type != 2 $tagInfo->{"Unknown"} not $unknown
Truth table75%3/4
A and B and not(C)
A= $type != 2B= $tagInfo->{"Unknown"}C= not $unknown
ABCresult
0XX0
10X0
1100
1111
166 } else {
167 9499 ▶ next unless $type == 2 or $unknown;
Branch: 1 branch
BranchTrueFalseTotal
unless $type == 2 or $unknown 9007 492 9499
Condition66%2/3
$type == 2 or $unknown
l!l&&r!l&&!r
49209007
MC/DC50%1/2
$type == 2 or $unknown
$type == 2 $unknown
Truth table66%2/3
A or B
A= $type == 2B= $unknown
ABresult
1X1
011
000
168 492 $tagInfo = AddTagToTable($tagTbl, $tag, { Unknown => 1 });
169 }
170 # set IsProtobuf flag (only for Unknown tags) if necessary
171 2071 ▶ if ($type == 2 and $$tagInfo{Unknown}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 2 and $tagInfo->{"Unknown"}) 2027 44 2071
Condition100%3/3
$type == 2 and $tagInfo->{"Unknown"}
!ll&&!rl&&r
8362027
MC/DC100%2/2
$type == 2 and $tagInfo->{"Unknown"}
$type == 2 $tagInfo->{"Unknown"}
Truth table100%3/3
A and B
A= $type == 2B= $tagInfo->{"Unknown"}
ABresult
0X0
100
111
172 2027 ▶ if ($$tagInfo{IsProtobuf}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo->{'IsProtobuf'}) { } 1175 852 2027
elsif (not defined $tagInfo->{'IsProtobuf'} and $buff =~ /[^\x20-\x7e]/ and &IsProtobuf(\$buff)) { } 372 762 1134
173 1175 ▶ $$tagInfo{IsProtobuf} = 0 unless IsProtobuf(\$buff);
Branch: 1 branch
BranchTrueFalseTotal
unless &IsProtobuf(\$buff) 9 1166 1175
174 ▶ } elsif (not defined $$tagInfo{IsProtobuf} and $buff =~ /[^\x20-\x7e]/ and
Condition100%6/6
not defined $tagInfo->{"IsProtobuf"} and $buff =~ /[^\x20-\x7e]/ and &IsProtobuf(\$buff)
!ll&&!rl&&r
282198372
not defined $tagInfo->{"IsProtobuf"} and $buff =~ /[^\x20-\x7e]/
!ll&&!rl&&r
137145570
MC/DC100%3/3
not defined $tagInfo->{"IsProtobuf"} and $buff =~ /[^\x20-\x7e]/ and &IsProtobuf(\$buff)
not defined $tagInfo->{"IsProtobuf"} $buff =~ /[^\x20-\x7e]/ &IsProtobuf(\$buff)
Truth table100%4/4
not(A) and B and C
A= not defined $tagInfo->{"IsProtobuf"}B= $buff =~ /[^\x20-\x7e]/C= &IsProtobuf(\$buff)
ABCresult
0XX0
10X0
1100
1111
175 IsProtobuf(\$buff))
176 {
177 372 $$tagInfo{IsProtobuf} = 1;
178 }
179 2027 ▶ next unless $$tagInfo{IsProtobuf} or $unknown;
Branch: 1 branch
BranchTrueFalseTotal
unless $tagInfo->{"IsProtobuf"} or $unknown 489 1538 2027
Condition66%2/3
$tagInfo->{"IsProtobuf"} or $unknown
l!l&&r!l&&!r
15380489
MC/DC50%1/2
$tagInfo->{"IsProtobuf"} or $unknown
$tagInfo->{"IsProtobuf"} $unknown
Truth table66%2/3
A or B
A= $tagInfo->{"IsProtobuf"}B= $unknown
ABresult
1X1
011
000
180 }
181 # format binary payload into a useful value
182 1582 my $val;
183 1582 ▶ if ($$tagInfo{Format}) {
Branch: 5 branches
BranchTrueFalseTotal
if ($tagInfo->{'Format'}) { } 21 1561 1582
elsif ($type == 0) { } 0 1561 1561
elsif ($type == 1) { } 0 1561 1561
elsif ($type == 2) { } 1561 0 1561
elsif ($type == 5) { } 0 0 0
184 21 ▶ if ($type == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 0) { } 3 18 21
elsif ($type == 2 and $tagInfo->{'Format'} eq 'rational') { } 0 18 18
185 3 $val = $buff;
186 3 ▶ if ($$tagInfo{Format} eq 'signed') {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo->{'Format'} eq 'signed') { } 0 3 3
elsif ($tagInfo->{'Format'} eq 'int64s' and $val >= $int64sMin) { } 0 6 6
187 0 ▶ if ($val > $intMax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val > $intMax) { } 0 0 0
188 # use double math (15 decimal digits precision)
189 0 ▶ $val = $$dirInfo{Bit0} ? -int($val / 2) - 1 : $val / 2;
Branch: 1 branch
BranchTrueFalseTotal
$dirInfo->{'Bit0'} ? : 0 0 0
190 } else {
191 # use integer math
192 0 ▶ $val = ($val & 1) ? -($val >> 1)-1 : ($val >> 1);
Branch: 1 branch
BranchTrueFalseTotal
$val & 1 ? : 0 0 0
193 }
194 ▶ } elsif ($$tagInfo{Format} eq 'int64s' and $val >= $int64sMin) {
Condition33%1/3
$tagInfo->{"Format"} eq "int64s" and $val >= $int64sMin
!ll&&!rl&&r
300
MC/DC0%0/2
$tagInfo->{"Format"} eq "int64s" and $val >= $int64sMin
$tagInfo->{"Format"} eq "int64s" $val >= $int64sMin
Truth table33%1/3
A and B
A= $tagInfo->{"Format"} eq "int64s"B= $val >= $int64sMin
ABresult
0X0
100
111
195 # hack for DJI drones which store 64-bit signed integers improperly
196 # (just toss upper 32 bits which should be all 1's anyway)
197 # Note: do the two subtractions because $int64sMin + 4294967296
198 # is too large for a 64-bit integer
199 0 $val = $val - $int64sMin - 4294967296;
200 }
201 ▶ } elsif ($type == 2 and $$tagInfo{Format} eq 'rational') {
Condition66%2/3
$type == 2 and $tagInfo->{"Format"} eq "rational"
!ll&&!rl&&r
5130
MC/DC0%0/2
$type == 2 and $tagInfo->{"Format"} eq "rational"
$type == 2 $tagInfo->{"Format"} eq "rational"
Truth table66%2/3
A and B
A= $type == 2B= $tagInfo->{"Format"} eq "rational"
ABresult
0X0
100
111
202 0 my $dir = { DataPt => \$buff, Pos => 0 };
203 0 my $num = VarInt($dir);
204 0 my $den = VarInt($dir);
205 0 ▶ $val = (defined $num and $den) ? $num/$den : 'err';
Branch: 1 branch
BranchTrueFalseTotal
defined $num && $den ? : 0 0 0
Condition0%0/3
defined $num and $den
!ll&&!rl&&r
000
MC/DC0%0/2
defined $num and $den
defined $num $den
Truth table0%0/3
A and B
A= defined $numB= $den
ABresult
0X0
100
111
206 } else {
207 18 $val = ReadValue(\$buff, 0, $$tagInfo{Format}, undef, length($buff));
208 }
209 } elsif ($type == 0) { # varInt
210 0 $val = $buff;
211 0 my $hex = sprintf('%x', $val);
212 0 ▶ if ($val >= $int64sMin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val >= $int64sMin) { } 0 0 0
213 0 my $s64 = $val - $int64sMin - 4294967296;
214 0 $val .= " (0x$hex, int64s $s64)";
215 } else {
216 0 my $signed;
217 0 ▶ if ($val > $intMax) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val > $intMax) { } 0 0 0
218 0 ▶ $signed = $$dirInfo{Bit0} ? -int($val / 2) - 1 : $val / 2;
Branch: 1 branch
BranchTrueFalseTotal
$dirInfo->{'Bit0'} ? : 0 0 0
219 } else {
220 0 ▶ $signed = ($val & 1) ? -($val >> 1)-1 : ($val >> 1);
Branch: 1 branch
BranchTrueFalseTotal
$val & 1 ? : 0 0 0
221 }
222 0 $val .= " (0x$hex, signed $signed)";
223 }
224 } elsif ($type == 1) { # 64-bit number
225 0 $val = '0x' . unpack('H*', $buff) . ' (double ' . GetDouble(\$buff,0) . ')';
226 } elsif ($type == 2) { # string, bytes or protobuf
227 1561 ▶ if ($$tagInfo{SubDirectory}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tagInfo->{'SubDirectory'}) { } 0 1561 1561
elsif ($tagInfo->{'IsProtobuf'}) { } 1538 23 1561
228 # (fall through to process known SubDirectory)
229 } elsif ($$tagInfo{IsProtobuf}) {
230 # process Unknown protobuf directories
231 1538 $et->VPrint(1, "$$et{INDENT}${unkPre}$tag (" . length($buff) . " bytes) -->\n");
232 1538 my $addr = $dataPos + $$dirInfo{Pos} - length($buff);
233 1538 $et->VerboseDump(\$buff, Addr => $addr, Prefix => $$et{INDENT});
234 1538 my %subdir = ( DataPt => \$buff, DataPos => $addr, DirName => $dirName );
235 1538 $$et{INDENT} .= '| ';
236 1538 ProcessProtobuf($et, \%subdir, $tagTbl, "$prefix$id-");
237 1538 $$et{INDENT} = substr($$et{INDENT}, 0, -2);
238 1538 next;
239 } else {
240 # check for rational value (2 varInt values)
241 23 my $rat;
242 23 my %dir = ( DataPt => \$buff, Pos => 0 );
243 23 my $num = VarInt(\%dir);
244 23 ▶ if (defined $num) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $num) 23 0 23
245 23 my $denom = VarInt(\%dir);
246 23 ▶ $rat = " (rational $num/$denom)" if $denom and $dir{Pos} == length($buff);
Branch: 1 branch
BranchTrueFalseTotal
if $denom and $dir{"Pos"} == length $buff 0 23 23
Condition33%1/3
$denom and $dir{"Pos"} == length $buff
!ll&&!rl&&r
0230
MC/DC0%0/2
$denom and $dir{"Pos"} == length $buff
$denom $dir{"Pos"} == length $buff
Truth table33%1/3
A and B
A= $denomB= $dir{"Pos"} == length $buff
ABresult
0X0
100
111
247 }
248 23 ▶ if ($buff !~ /[^\r\n\t\x20-\x7e]/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $buff =~ /[^\r\n\t\x20-\x7e]/) { } 23 0 23
elsif (length($buff) % 4) { } 0 0 0
249 23 $val = $buff; # assume this is an ASCII string
250 } elsif (length($buff) % 4) {
251 0 $val = '0x' . unpack('H*', $buff);
252 } else {
253 0 my $n = length($buff) / 4;
254 # (do this instead of '(H8)*' because older Perl version didn't support this)
255 0 $val = '0x' . join(' ', unpack("(H8)$n", $buff)); # (group in 4-byte blocks)
256 }
257 23 ▶ $val .= $rat if $rat;
Branch: 1 branch
BranchTrueFalseTotal
if $rat 0 23 23
258 }
259 } elsif ($type == 5) { # 32-bit number
260 0 $val = '0x' . unpack('H*', $buff) . ' (int32u ' . Get32u(\$buff, 0);
261 0 ▶ $val .= ', int32s ' . Get32s(\$buff, 0) if ord(substr($buff,3,1)) & 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if ord substr($buff, 3, 1) & 128 0 0 0
262 0 $val .= ', float ' . GetFloat(\$buff, 0) . ')';
263 } else {
264 0 $val = $buff;
265 }
266 # get length of data in the record
267 44 ▶ my $start = $type == 0 ? $pos + 1 : $$dirInfo{Pos} - length $buff;
Branch: 1 branch
BranchTrueFalseTotal
$type == 0 ? : 3 41 44
268 $et->HandleTag($tagTbl, $tag, $val,
269 DataPt => $dataPt,
270 DataPos=> $dataPos,
271 Start => $start,
272 Size => $$dirInfo{Pos} - $start,
273 Extra => ", type=$type",
274 Format => $$tagInfo{Format},
275 44 );
276 }
277 # warn if we didn't finish exactly at the end of the buffer
278 1539 ▶ $et->Warn('Truncated protobuf data') unless $prefix or $$dirInfo{Pos} == $dirEnd;
Branch: 1 branch
BranchTrueFalseTotal
unless $prefix or $dirInfo->{"Pos"} == $dirEnd 0 1539 1539
Condition66%2/3
$prefix or $dirInfo->{"Pos"} == $dirEnd
l!l&&r!l&&!r
153810
MC/DC0%0/2
$prefix or $dirInfo->{"Pos"} == $dirEnd
$prefix $dirInfo->{"Pos"} == $dirEnd
Truth table66%2/3
A or B
A= $prefixB= $dirInfo->{"Pos"} == $dirEnd
ABresult
1X1
011
000
279 1539 return 1;
280 }
281  
282 __END__
« Image/ExifTool/Nikon.pm ↑ Summary Image/ExifTool/AFCP.pm »