Image/ExifTool/PLIST.pm

filter: Statementstmt 80.7% 185 / 229 Branchbran 62.5% 110 / 176 Conditioncond 54.6% 47 / 86 MC/DCmcdc 23.5% 12 / 51 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 5 totaltotal 65.1% 363 / 557 CC 120 SCAR 48.6
CC
120
Cov
70%
ExtractObject
246.4
FoundTag
38.7
ProcessPLIST
25.5
CRAP 129.6
« Image/ExifTool/PCAP.pm ↑ Summary Image/ExifTool/BMP.pm »
1 #------------------------------------------------------------------------------
2 # File: PLIST.pm
3 #
4 # Description: Read Apple PLIST information
5 #
6 # Revisions: 2013-02-01 - P. Harvey Created
7 #
8 # References: 1) http://www.apple.com/DTDs/PropertyList-1.0.dtd
9 # 2) http://opensource.apple.com/source/CF/CF-550/CFBinaryPList.c
10 #
11 # Notes: - Sony MODD files also use XML PLIST format, but with a few quirks
12 #
13 # - Decodes both the binary and XML-based PLIST formats
14 #------------------------------------------------------------------------------
15  
16 package Image::ExifTool::PLIST;
17  
18 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶use Image::ExifTool::XMP;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶use Image::ExifTool::GPS;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 9 $VERSION = '1.17';
25  
26 sub ExtractObject($$;$);
27 sub Get24u($$);
28  
29 # access routines to read various-sized integer/real values (add 0x100 to size for reals)
30 9 my %readProc = (
31 1 => \&Get8u,
32 2 => \&Get16u,
33 3 => \&Get24u,
34 4 => \&Get32u,
35 8 => \&Get64u,
36 0x104 => \&GetFloat,
37 0x108 => \&GetDouble,
38 );
39  
40 # recognize different types of PLIST files based on certain tags
41 9 my %plistType = (
42 adjustmentBaseVersion => 'AAE',
43 );
44  
45 # PLIST tags (generated on-the-fly for most tags)
46 9 %Image::ExifTool::PLIST::Main = (
47 PROCESS_PROC => \&ProcessPLIST,
48 GROUPS => { 0 => 'PLIST', 1 => 'XML', 2 => 'Document' },
49 VARS => { LONG_TAGS => 18 },
50 NOTES => q{
51 Apple Property List tags. ExifTool reads both XML and binary-format PLIST
52 files, and will extract any existing tags even if they aren't listed below.
53 These tags belong to the family 0 "PLIST" group, but family 1 group may be
54 either "XML" or "PLIST" depending on whether the format is XML or binary.
55 },
56 #
57 # tags found in PLIST information of QuickTime iTunesInfo iTunMOVI atom (ref PH)
58 #
59 'cast//name' => { Name => 'Cast', List => 1 },
60 'directors//name' => { Name => 'Directors', List => 1 },
61 'producers//name' => { Name => 'Producers', List => 1 },
62 'screenwriters//name' => { Name => 'Screenwriters', List => 1 },
63 'codirectors//name' => { Name => 'Codirectors', List => 1 }, # (NC)
64 'studio//name' => { Name => 'Studio', List => 1 }, # (NC)
65 #
66 # tags found in MODD files (ref PH)
67 #
68 'MetaDataList//DateTimeOriginal' => {
69 Name => 'DateTimeOriginal',
70 Description => 'Date/Time Original',
71 Groups => { 2 => 'Time' },
72 # Sony uses a "real" here -- number of days since Dec 31, 1899
73 ValueConv => 'IsFloat($val) ? ConvertUnixTime(($val - 25569) * 24 * 3600) : $val',
74 PrintConv => '$self->ConvertDateTime($val)',
75 },
76 'MetaDataList//Duration' => {
77 Name => 'Duration',
78 Groups => { 2 => 'Video' },
79 PrintConv => 'ConvertDuration($val)',
80 },
81 'MetaDataList//Geolocation/Latitude' => {
82 Name => 'GPSLatitude',
83 Groups => { 2 => 'Location' },
84 PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "N")',
85 },
86 'MetaDataList//Geolocation/Longitude' => {
87 Name => 'GPSLongitude',
88 Groups => { 2 => 'Location' },
89 PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "E")',
90 },
91 'MetaDataList//Geolocation/MapDatum' => {
92 Name => 'GPSMapDatum',
93 Groups => { 2 => 'Location' },
94 },
95 # slow motion stuff found in AAE files
96 'slowMotion/regions/timeRange/start/flags' => {
97 Name => 'SlowMotionRegionsStartTimeFlags',
98 PrintConv => { BITMASK => {
99 0 => 'Valid',
100 1 => 'Has been rounded',
101 2 => 'Positive infinity',
102 3 => 'Negative infinity',
103 4 => 'Indefinite',
104 }},
105 },
106 'slowMotion/regions/timeRange/start/value' => 'SlowMotionRegionsStartTimeValue',
107 'slowMotion/regions/timeRange/start/timescale' => 'SlowMotionRegionsStartTimeScale',
108 'slowMotion/regions/timeRange/start/epoch' => 'SlowMotionRegionsStartTimeEpoch',
109 'slowMotion/regions/timeRange/duration/flags' => {
110 Name => 'SlowMotionRegionsDurationFlags',
111 PrintConv => { BITMASK => {
112 0 => 'Valid',
113 1 => 'Has been rounded',
114 2 => 'Positive infinity',
115 3 => 'Negative infinity',
116 4 => 'Indefinite',
117 }},
118 },
119 'slowMotion/regions/timeRange/duration/value' => 'SlowMotionRegionsDurationValue',
120 'slowMotion/regions/timeRange/duration/timescale' => 'SlowMotionRegionsDurationTimeScale',
121 'slowMotion/regions/timeRange/duration/epoch' => 'SlowMotionRegionsDurationEpoch',
122 'slowMotion/regions' => 'SlowMotionRegions',
123 'slowMotion/rate' => 'SlowMotionRate',
124 # buried deep in live photo .mov file
125 'LivePhotoMetadataSetupDataVersion' => { },
126 'SystemVersion/ProductBuildVersion' => 'ProductBuildVersion',
127 'SystemVersion/ProductName' => 'ProductName',
128 'SystemVersion/ProductVersion' => 'ProductVersion',
129 'FrameworkVersions/CoreMotion' => 'CoreMotionVersion',
130 'FrameworkVersions/CMCaptureCore' => 'CMCaptureCoreVersion',
131 'FrameworkVersions/H16ISPServices' => 'H16ISPServicesVersion',
132 'FrameworkVersions/CoreMedia' => 'CoreMediaVersion',
133 XMLFileType => {
134 # recognize MODD files by their content
135 RawConv => q{
136 if ($val eq 'ModdXML' and $$self{FILE_TYPE} eq 'XMP') {
137 $self->OverrideFileType('MODD');
138 }
139 return $val;
140 },
141 },
142 adjustmentData => { # AAE file
143 Name => 'AdjustmentData',
144 CompressedPLIST => 1,
145 SubDirectory => { TagTable => 'Image::ExifTool::PLIST::Main' },
146 },
147 );
148  
149 #------------------------------------------------------------------------------
150 # We found a PLIST XML property name/value
151 # Inputs: 0) ExifTool object ref, 1) tag table ref
152 # 2) reference to array of XML property names (last is current property)
153 # 3) property value, 4) attribute hash ref (not used here)
154 # Returns: 1 if valid tag was found
155 sub FoundTag($$$$;$)
156 37 ▶{
Subroutine FoundTag: called CC=27 SCAR=36.6
Pod undocumented
157 37 my ($et, $tagTablePtr, $props, $val, $attrs) = @_;
158 37 ▶ return 0 unless @$props;
Branch: 1 branch
BranchTrueFalseTotal
unless @$props 0 37 37
159 37 my $verbose = $et->Options('Verbose');
160 37 ▶ my $keys = $$et{PListKeys} || ( $$et{PListKeys} = [] );
Condition100%2/2
$et->{'PListKeys'} || ($et->{'PListKeys'} = [])
l!l
352
MC/DC100%1/1
$et->{'PListKeys'} || ($et->{'PListKeys'} = [])
$et->{'PListKeys'}
Truth table100%2/2
A
A= $et->{'PListKeys'}
Aresult
11
00
161  
162 37 my $prop = $$props[-1];
163 37 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 37 37
164 0 $et->VPrint(0, $$et{INDENT}, '[', join('/',@$props), ' = ',
165 $et->Printable($val), "]\n");
166 }
167 # un-escape XML character entities
168 37 $val = Image::ExifTool::XMP::UnescapeXML($val);
169  
170 # handle the various PLIST properties
171 37 ▶ if ($prop eq 'data') {
Branch: 3 branches
BranchTrueFalseTotal
if ($prop eq 'data') { } 2 35 37
elsif ($prop eq 'date') { } 2 33 35
elsif ($prop eq 'true' or $prop eq 'false') { } 1 32 33
172 2 ▶ if ($val =~ /^[0-9a-f]+$/ and not length($val) & 0x01) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^[0-9a-f]+$/ and not length $val & 1) { } 0 2 2
Condition33%1/3
$val =~ /^[0-9a-f]+$/ and not length $val & 1
!ll&&!rl&&r
200
MC/DC0%0/2
$val =~ /^[0-9a-f]+$/ and not length $val & 1
$val =~ /^[0-9a-f]+$/ not length $val & 1
Truth table33%1/3
A and not(B)
A= $val =~ /^[0-9a-f]+$/B= not length $val & 1
ABresult
0X0
100
111
173 # MODD files use ASCII-hex encoded "data"...
174 0 my $buff = pack('H*', $val);
175 0 $val = \$buff;
176 } else {
177 # ...but the PLIST DTD specifies Base64 encoding
178 2 $val = Image::ExifTool::XMP::DecodeBase64($val);
179 }
180 } elsif ($prop eq 'date') {
181 2 $val = Image::ExifTool::XMP::ConvertXMPDate($val);
182 ▶ } elsif ($prop eq 'true' or $prop eq 'false') {
Condition66%2/3
$prop eq "true" or $prop eq "false"
l!l&&r!l&&!r
1032
MC/DC50%1/2
$prop eq "true" or $prop eq "false"
$prop eq "true" $prop eq "false"
Truth table66%2/3
A or B
A= $prop eq "true"B= $prop eq "false"
ABresult
1X1
011
000
183 1 $val = ucfirst $prop;
184 } else {
185 # convert from UTF8 to ExifTool Charset
186 32 $val = $et->Decode($val, 'UTF8');
187 32 ▶ if ($prop eq 'key') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop eq "key") 17 15 32
188 17 ▶ if (@$props <= 3) { # top-level key should be plist/dict/key
Branch: 1 branch
BranchTrueFalseTotal
if (@$props <= 3) { } 15 2 17
189 15 @$keys = ( $val );
190 } else {
191 # save key names to be used in tag name
192 2 ▶ push @$keys, '' while @$keys < @$props - 3;
Branch: 1 branch
BranchTrueFalseTotal
@$keys < @$props - 3 and do { push @$keys, "" } 0 2 2
193 2 ▶ pop @$keys while @$keys > @$props - 2;
Branch: 1 branch
BranchTrueFalseTotal
@$keys > @$props - 2 and do { pop @$keys } 0 2 2
194 2 $$keys[@$props - 3] = $val;
195 }
196 17 return 0;
197 }
198 }
199  
200 20 ▶ return 0 unless @$keys; # can't store value if no associated key
Branch: 1 branch
BranchTrueFalseTotal
unless @$keys 2 18 20
201  
202 18 my $tag = join '/', @$keys; # generate tag ID from 'key' values
203 18 my $tagInfo = $$tagTablePtr{$tag};
204 18 ▶ unless ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo) 15 3 18
205 15 ▶ $et->VPrint(0, $$et{INDENT}, "[adding $tag]\n") if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 15 15
206 # generate tag name from ID
207 15 my $name = $tag;
208 15 $name =~ s{^MetaDataList//}{}; # shorten long MODD metadata tag names
209 15 $name =~ s{//name$}{}; # remove unnecessary MODD "name" property
210 15 $name =~ s/([^A-Za-z])([a-z])/$1\u$2/g; # capitalize words
211 15 $name =~ tr/-_a-zA-Z0-9//dc; # remove illegal characters
212 15 $tagInfo = { Name => ucfirst($name), List => 1 };
213 15 ▶ if ($prop eq 'date') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prop eq "date") 2 13 15
214 2 $$tagInfo{Groups}{2} = 'Time';
215 2 $$tagInfo{PrintConv} = '$self->ConvertDateTime($val)';
216 }
217 15 AddTagToTable($tagTablePtr, $tag, $tagInfo);
218 }
219 # allow list-behaviour only for consecutive tags with the same ID
220 18 ▶ if ($$et{LastPListTag} and $$et{LastPListTag} ne $tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"LastPListTag"} and $et->{"LastPListTag"} ne $tagInfo) 14 4 18
Condition100%3/3
$et->{"LastPListTag"} and $et->{"LastPListTag"} ne $tagInfo
!ll&&!rl&&r
2214
MC/DC100%2/2
$et->{"LastPListTag"} and $et->{"LastPListTag"} ne $tagInfo
$et->{"LastPListTag"} $et->{"LastPListTag"} ne $tagInfo
Truth table100%3/3
A and B
A= $et->{"LastPListTag"}B= $et->{"LastPListTag"} ne $tagInfo
ABresult
0X0
100
111
221 14 delete $$et{LIST_TAGS}{$$et{LastPListTag}};
222 }
223 18 $$et{LastPListTag} = $tagInfo;
224 # override file type if applicable
225 18 ▶ $et->OverrideFileType($plistType{$tag}) if $plistType{$tag} and $$et{FILE_TYPE} eq 'XMP';
Branch: 1 branch
BranchTrueFalseTotal
if $plistType{$tag} and $et->{"FILE_TYPE"} eq "XMP" 0 18 18
Condition66%2/3
$plistType{$tag} and $et->{"FILE_TYPE"} eq "XMP"
!ll&&!rl&&r
1710
MC/DC0%0/2
$plistType{$tag} and $et->{"FILE_TYPE"} eq "XMP"
$plistType{$tag} $et->{"FILE_TYPE"} eq "XMP"
Truth table66%2/3
A and B
A= $plistType{$tag}B= $et->{"FILE_TYPE"} eq "XMP"
ABresult
0X0
100
111
226 # handle compressed PLIST/JSON data
227 18 my $proc;
228 18 ▶ if ($$tagInfo{CompressedPLIST} and ref $val eq 'SCALAR' and $$val !~ /^bplist00/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{"CompressedPLIST"} and ref $val eq "SCALAR" and not $$val =~ /^bplist00/) 0 18 18
Condition66%4/6
$tagInfo->{"CompressedPLIST"} and ref $val eq "SCALAR" and not $$val =~ /^bplist00/
!ll&&!rl&&r
1710
$tagInfo->{"CompressedPLIST"} and ref $val eq "SCALAR"
!ll&&!rl&&r
1701
MC/DC0%0/3
$tagInfo->{"CompressedPLIST"} and ref $val eq "SCALAR" and not $$val =~ /^bplist00/
$tagInfo->{"CompressedPLIST"} ref $val eq "SCALAR" not $$val =~ /^bplist00/
Truth table50%2/4
A and B and not(C)
A= $tagInfo->{"CompressedPLIST"}B= ref $val eq "SCALAR"C= not $$val =~ /^bplist00/
ABCresult
0XX0
10X0
1100
1111
229 0 ▶ if (eval { require IO::Uncompress::RawInflate }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require IO::Uncompress::RawInflate } }) { } 0 0 0
230 0 my $inflated;
231 0 ▶ if (IO::Uncompress::RawInflate::rawinflate($val => \$inflated)) {
Branch: 1 branch
BranchTrueFalseTotal
if (IO::Uncompress::RawInflate::rawinflate($val, \$inflated)) { } 0 0 0
232 0 $val = \$inflated;
233 } else {
234 0 $et->Warn("Error inflating PLIST::$$tagInfo{Name}");
235 }
236 } else {
237 0 $et->Warn('Install IO::Uncompress to decode compressed PLIST data');
238 }
239 }
240 # save the tag
241 18 $et->HandleTag($tagTablePtr, $tag, $val, ProcessProc => $proc);
242  
243 18 return 1;
244 }
245  
246 #------------------------------------------------------------------------------
247 # Get big-endian 24-bit integer
248 # Inputs: 0) data ref, 1) offset
249 # Returns: integer value
250 sub Get24u($$)
251 0 ▶{
Subroutine Get24u: not called CC=1 SCAR=6.9
Pod undocumented
252 0 my ($dataPt, $off) = @_;
253 0 return unpack 'N', "\0" . substr($$dataPt, $off, 3);
254 }
255  
256 #------------------------------------------------------------------------------
257 # Extract object from binary PLIST file at the current file position (ref 2)
258 # Inputs: 0) ExifTool ref, 1) PLIST info ref, 2) parent tag ID (undef for top)
259 # Returns: the object, or undef on error
260 sub ExtractObject($$;$)
261 81 ▶{
Subroutine ExtractObject: called CC=60 SCAR=55.1
Pod undocumented
262 81 my ($et, $plistInfo, $parent) = @_;
263 81 my $raf = $$plistInfo{RAF};
264 81 my ($buff, $val);
265  
266 81 ▶ $raf->Read($buff, 1) == 1 or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 1) == 1 or return undef 81 0 81
267 81 my $type = ord($buff) >> 4;
268 81 my $size = ord($buff) & 0x0f;
269 81 ▶ if ($type == 0) { # null/bool/fill
Branch: 3 branches
BranchTrueFalseTotal
if ($type == 0) { } 1 80 81
elsif ($type == 1 or $type == 2 or $type == 3) { } 23 57 80
elsif ($type == 8) { } 0 57 57
270 1 $val = { 0x00=>'<null>', 0x08=>'True', 0x09=>'False', 0x0f=>'<fill>' }->{$size};
271 ▶ } elsif ($type == 1 or $type == 2 or $type == 3) { # int, float or date
Condition100%6/6
$type == 1 or $type == 2 or $type == 3
l!l&&r!l&&!r
20357
$type == 1 or $type == 2
l!l&&r!l&&!r
18260
MC/DC100%3/3
$type == 1 or $type == 2 or $type == 3
$type == 1 $type == 2 $type == 3
Truth table100%4/4
A or B or C
A= $type == 1B= $type == 2C= $type == 3
ABCresult
1XX1
01X1
0011
0000
272 23 $size = 1 << $size;
273 23 ▶ my $proc = ($type == 1 ? $readProc{$size} : $readProc{$size + 0x100}) or return undef;
Branch: 2 branches
BranchTrueFalseTotal
my $proc = $type == 1 ? $readProc{$size} : $readProc{$size + 256} or return undef 23 0 23
$type == 1 ? : 18 5 23
274 23 ▶ $val = &$proc(\$buff, 0) if $raf->Read($buff, $size) == $size;
Branch: 1 branch
BranchTrueFalseTotal
if $raf->Read($buff, $size) == $size 23 0 23
275 23 ▶ if ($type == 3 and defined $val) { # date
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 3 and defined $val) 3 20 23
Condition66%2/3
$type == 3 and defined $val
!ll&&!rl&&r
2003
MC/DC50%1/2
$type == 3 and defined $val
$type == 3 defined $val
Truth table66%2/3
A and B
A= $type == 3B= defined $val
ABresult
0X0
100
111
276 # dates are referenced to Jan 1, 2001 (11323 days from Unix time zero)
277 3 $val = Image::ExifTool::ConvertUnixTime($val + 11323 * 24 * 3600, 1);
278 3 $$plistInfo{DateFormat} = 1;
279 }
280 } elsif ($type == 8) { # UID
281 0 ++$size;
282 0 ▶ $raf->Read($buff, $size) == $size or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $size) == $size or return undef 0 0 0
283 0 my $proc = $readProc{$size};
284 0 ▶ if ($proc) {
Branch: 2 branches
BranchTrueFalseTotal
if ($proc) { } 0 0 0
elsif ($size == 16) { } 0 0 0
285 0 $val = &$proc(\$buff, 0);
286 } elsif ($size == 16) {
287 0 require Image::ExifTool::ASF;
288 0 $val = Image::ExifTool::ASF::GetGUID($buff);
289 } else {
290 0 $val = "0x" . unpack 'H*', $buff;
291 }
292 } else {
293 # $size is the size of the remaining types
294 57 ▶ if ($size == 0x0f) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size == 15) 5 52 57
295 # size is stored in extra integer object
296 5 $size = ExtractObject($et, $plistInfo);
297 5 ▶ return undef unless defined $size and $size =~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size and $size =~ /^\d+$/ 0 5 5
Condition33%1/3
defined $size and $size =~ /^\d+$/
!ll&&!rl&&r
005
MC/DC0%0/2
defined $size and $size =~ /^\d+$/
defined $size $size =~ /^\d+$/
Truth table33%1/3
A and B
A= defined $sizeB= $size =~ /^\d+$/
ABresult
0X0
100
111
298 }
299 57 ▶ if ($type == 4) { # data
Branch: 4 branches
BranchTrueFalseTotal
if ($type == 4) { } 2 55 57
elsif ($type == 5) { } 40 15 55
elsif ($type == 6) { } 1 14 15
elsif ($type == 10 or $type == 12 or $type == 13) { } 14 0 14
300 2 ▶ if ($size < 1000000 or $et->Options('Binary')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size < 1000000 or $et->Options('Binary')) { } 2 0 2
Condition33%1/3
$size < 1000000 or $et->Options("Binary")
l!l&&r!l&&!r
200
MC/DC0%0/2
$size < 1000000 or $et->Options("Binary")
$size < 1000000 $et->Options("Binary")
Truth table33%1/3
A or B
A= $size < 1000000B= $et->Options("Binary")
ABresult
1X1
011
000
301 2 ▶ $raf->Read($buff, $size) == $size or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $size) == $size or return undef 2 0 2
302 } else {
303 0 $buff = "Binary data $size bytes";
304 }
305 2 $val = \$buff; # (return reference for binary data)
306 } elsif ($type == 5) { # ASCII string
307 40 ▶ $raf->Read($val, $size) == $size or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($val, $size) == $size or return undef 40 0 40
308 } elsif ($type == 6) { # UCS-2BE string
309 1 $size *= 2;
310 1 ▶ $raf->Read($buff, $size) == $size or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $size) == $size or return undef 1 0 1
311 1 $val = $et->Decode($buff, 'UTF16'); # (might as well support surrogates too)
312 ▶ } elsif ($type == 10 or $type == 12 or $type == 13) { # array, set or dict
Condition66%4/6
$type == 10 or $type == 12 or $type == 13
l!l&&r!l&&!r
590
$type == 10 or $type == 12
l!l&&r!l&&!r
509
MC/DC0%0/3
$type == 10 or $type == 12 or $type == 13
$type == 10 $type == 12 $type == 13
Truth table50%2/4
A or B or C
A= $type == 10B= $type == 12C= $type == 13
ABCresult
1XX1
01X1
0011
0000
313 # the remaining types store a list of references
314 14 my $refSize = $$plistInfo{RefSize};
315 14 my $refProc = $$plistInfo{RefProc};
316 14 ▶ my $num = $type == 13 ? $size * 2 : $size;
Branch: 1 branch
BranchTrueFalseTotal
$type == 13 ? : 9 5 14
317 14 my $len = $num * $refSize;
318 14 ▶ $raf->Read($buff, $len) == $len or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $len) == $len or return undef 14 0 14
319 14 my $table = $$plistInfo{Table};
320 14 my ($i, $ref, @refs, @array);
321 14 ▶ for ($i=0; $i<$num; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 68 14 82
322 68 my $ref = &$refProc(\$buff, $i * $refSize);
323 68 ▶ return 0 if $ref >= @$table;
Branch: 1 branch
BranchTrueFalseTotal
if $ref >= @$table 0 68 68
324 68 push @refs, $ref;
325 }
326 14 ▶ if ($type == 13) { # dict
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 13) { } 9 5 14
327 # prevent infinite recursion
328 9 ▶ if (defined $parent and length $parent > 1000) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent and length $parent > 1000) 0 9 9
Condition66%2/3
defined $parent and length $parent > 1000
!ll&&!rl&&r
360
MC/DC0%0/2
defined $parent and length $parent > 1000
defined $parent length $parent > 1000
Truth table66%2/3
A and B
A= defined $parentB= length $parent > 1000
ABresult
0X0
100
111
329 0 $et->Warn('Possible deep recursion while parsing PLIST');
330 0 return undef;
331 }
332 9 my $tagTablePtr = $$plistInfo{TagTablePtr};
333 9 my $verbose = $et->Options('Verbose');
334 9 $val = { }; # initialize return dictionary (will stay empty if tags are saved)
335 9 ▶ for ($i=0; $i<$size; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 29 9 38
336 # get the entry key
337 29 ▶ $raf->Seek($$table[$refs[$i]], 0) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($$table[$refs[$i]], 0) or return undef 29 0 29
338 29 my $key = ExtractObject($et, $plistInfo);
339 29 ▶ next unless defined $key and length $key; # silently ignore bad dict entries
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and length $key 0 29 29
Condition33%1/3
defined $key and length $key
!ll&&!rl&&r
0029
MC/DC0%0/2
defined $key and length $key
defined $key length $key
Truth table33%1/3
A and B
A= defined $keyB= length $key
ABresult
0X0
100
111
340 # get the entry value
341 29 ▶ $raf->Seek($$table[$refs[$i+$size]], 0) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($$table[$refs[$i + $size]], 0) or return undef 29 0 29
342 # generate an ID for this tag
343 29 ▶ my $tag = defined $parent ? "$parent/$key" : $key;
Branch: 1 branch
BranchTrueFalseTotal
defined $parent ? : 15 14 29
344 29 undef $$plistInfo{DateFormat};
345 29 my $obj = ExtractObject($et, $plistInfo, $tag);
346 29 ▶ next if not defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 29 29
347 29 ▶ unless ($tagTablePtr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagTablePtr) 0 29 29
348 # make sure this is a valid structure field name
349 0 ▶ if (not defined $key or $key !~ /^[-_a-zA-Z0-9]+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $key && $key =~ /^[-_a-zA-Z0-9]+$/) { } 0 0 0
elsif (not $key =~ /^[_a-zA-Z]/) { } 0 0 0
Condition0%0/3
defined $key && $key =~ /^[-_a-zA-Z0-9]+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $key && $key =~ /^[-_a-zA-Z0-9]+$/
defined $key $key =~ /^[-_a-zA-Z0-9]+$/
Truth table0%0/3
A && B
A= defined $keyB= $key =~ /^[-_a-zA-Z0-9]+$/
ABresult
0X0
100
111
350 0 $key = "Tag$i"; # (generate fake tag name if it had illegal characters)
351 } elsif ($key !~ /^[_a-zA-Z]/) {
352 0 $key = "_$key"; # (must begin with alpha or underline)
353 }
354 0 ▶ $$val{$key} = $obj if defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj 0 0 0
355 0 next;
356 }
357 29 ▶ next if ref($obj) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $obj eq "HASH" 5 24 29
358 24 my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
359 24 ▶ unless ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagInfo) 0 24 24
360 0 ▶ $et->VPrint(0, $$et{INDENT}, "[adding $tag]\n") if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 0 0
361 0 my $name = $tag;
362 0 $name =~ s/([^A-Za-z])([a-z])/$1\u$2/g; # capitalize words
363 0 $name =~ tr/-_a-zA-Z0-9//dc; # remove illegal characters
364 0 ▶ $name = 'Tag'.ucfirst($name) if length($name) < 2 or $name =~ /^[-0-9]/;
Branch: 1 branch
BranchTrueFalseTotal
if length $name < 2 or $name =~ /^[-0-9]/ 0 0 0
Condition0%0/3
length $name < 2 or $name =~ /^[-0-9]/
l!l&&r!l&&!r
000
MC/DC0%0/2
length $name < 2 or $name =~ /^[-0-9]/
length $name < 2 $name =~ /^[-0-9]/
Truth table0%0/3
A or B
A= length $name < 2B= $name =~ /^[-0-9]/
ABresult
1X1
011
000
365 0 $tagInfo = { Name => ucfirst($name), List => 1 };
366 0 ▶ if ($$plistInfo{DateFormat}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plistInfo->{"DateFormat"}) 0 0 0
367 0 $$tagInfo{Groups}{2} = 'Time';
368 0 $$tagInfo{PrintConv} = '$self->ConvertDateTime($val)';
369 }
370 0 AddTagToTable($tagTablePtr, $tag, $tagInfo);
371 }
372 # allow list-behaviour only for consecutive tags with the same ID
373 24 ▶ if ($$et{LastPListTag} and $$et{LastPListTag} ne $tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"LastPListTag"} and $et->{"LastPListTag"} ne $tagInfo) 22 2 24
Condition66%2/3
$et->{"LastPListTag"} and $et->{"LastPListTag"} ne $tagInfo
!ll&&!rl&&r
2022
MC/DC50%1/2
$et->{"LastPListTag"} and $et->{"LastPListTag"} ne $tagInfo
$et->{"LastPListTag"} $et->{"LastPListTag"} ne $tagInfo
Truth table66%2/3
A and B
A= $et->{"LastPListTag"}B= $et->{"LastPListTag"} ne $tagInfo
ABresult
0X0
100
111
374 22 delete $$et{LIST_TAGS}{$$et{LastPListTag}};
375 }
376 24 $$et{LastPListTag} = $tagInfo;
377 24 $et->HandleTag($tagTablePtr, $tag, $obj);
378 }
379 } else {
380 # extract the referenced objects
381 5 foreach $ref (@refs) {
382 10 ▶ $raf->Seek($$table[$ref], 0) or return undef; # seek to this object
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($table->[$ref], 0) or return undef 10 0 10
383 10 $val = ExtractObject($et, $plistInfo, $parent);
384 10 ▶ next unless defined $val and ref $val ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and ref $val ne "HASH" 1 9 10
Condition66%2/3
defined $val and ref $val ne "HASH"
!ll&&!rl&&r
019
MC/DC50%1/2
defined $val and ref $val ne "HASH"
defined $val ref $val ne "HASH"
Truth table66%2/3
A and B
A= defined $valB= ref $val ne "HASH"
ABresult
0X0
100
111
385 9 push @array, $val;
386 }
387 5 $val = \@array;
388 }
389 }
390 }
391 81 return $val;
392 }
393  
394 #------------------------------------------------------------------------------
395 # Process binary PLIST data (ref 2)
396 # Inputs: 0) ExifTool object ref, 1) DirInfo ref, 2) tag table ref
397 # Returns: 1 on success (and returns plist value as $$dirInfo{Value})
398 sub ProcessBinaryPLIST($$;$)
399 8 ▶{
Subroutine ProcessBinaryPLIST: called CC=19 SCAR=31.5
Pod undocumented
400 8 my ($et, $dirInfo, $tagTablePtr) = @_;
401 8 my ($i, $buff, @table);
402 8 my $dataPt = $$dirInfo{DataPt};
403  
404 8 ▶ $et->VerboseDir('Binary PLIST') unless $$dirInfo{NoVerboseDir};
Branch: 1 branch
BranchTrueFalseTotal
unless $dirInfo->{"NoVerboseDir"} 7 1 8
405 8 SetByteOrder('MM');
406  
407 8 ▶ if ($dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataPt) 7 1 8
408 7 my $start = $$dirInfo{DirStart};
409 7 ▶ if ($start or ($$dirInfo{DirLen} and $$dirInfo{DirLen} != length $$dataPt)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start or $dirInfo->{'DirLen'} and $dirInfo->{'DirLen'} != length $$dataPt) { } 1 6 7
Condition50%3/6
$start or $dirInfo->{"DirLen"} and $dirInfo->{"DirLen"} != length $$dataPt
l!l&&r!l&&!r
106
$dirInfo->{"DirLen"} and $dirInfo->{"DirLen"} != length $$dataPt
!ll&&!rl&&r
600
MC/DC33%1/3
$start or $dirInfo->{"DirLen"} and $dirInfo->{"DirLen"} != length $$dataPt
$start $dirInfo->{"DirLen"} $dirInfo->{"DirLen"} != length $$dataPt
Truth table50%2/4
A or B and C
A= $startB= $dirInfo->{"DirLen"}C= $dirInfo->{"DirLen"} != length $$dataPt
ABCresult
1XX1
0111
00X0
0100
410 1 ▶ my $buf2 = substr($$dataPt, $start || 0, $$dirInfo{DirLen});
Condition50%1/2
$start || 0
l!l
10
MC/DC0%0/1
$start || 0
$start
Truth table50%1/2
A
A= $start
Aresult
11
00
411 1 $$dirInfo{RAF} = File::RandomAccess->new(\$buf2);
412 } else {
413 6 $$dirInfo{RAF} = File::RandomAccess->new($dataPt);
414 }
415 7 ▶ my $strt = $$dirInfo{DirStart} || 0;
Condition100%2/2
$dirInfo->{'DirStart'} || 0
l!l
16
MC/DC100%1/1
$dirInfo->{'DirStart'} || 0
$dirInfo->{'DirStart'}
Truth table100%2/2
A
A= $dirInfo->{'DirStart'}
Aresult
11
00
416 }
417 # read and parse the trailer
418 8 ▶ my $raf = $$dirInfo{RAF} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $raf = $dirInfo->{"RAF"} or return 0 8 0 8
419 8 ▶ $raf->Seek(-32,2) and $raf->Read($buff,32)==32 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek(-32, 2) and $raf->Read($buff, 32) == 32 or return 0 8 0 8
Condition33%1/3
$raf->Seek(-32, 2) and $raf->Read($buff, 32) == 32
!ll&&!rl&&r
008
MC/DC0%0/2
$raf->Seek(-32, 2) and $raf->Read($buff, 32) == 32
$raf->Seek(-32, 2) $raf->Read($buff, 32) == 32
Truth table33%1/3
A and B
A= $raf->Seek(-32, 2)B= $raf->Read($buff, 32) == 32
ABresult
0X0
100
111
420 8 my $intSize = Get8u(\$buff, 6);
421 8 my $refSize = Get8u(\$buff, 7);
422 8 my $numObj = Get64u(\$buff, 8);
423 8 my $topObj = Get64u(\$buff, 16);
424 8 my $tableOff = Get64u(\$buff, 24);
425  
426 8 ▶ return 0 if $topObj >= $numObj;
Branch: 1 branch
BranchTrueFalseTotal
if $topObj >= $numObj 0 8 8
427 8 ▶ my $intProc = $readProc{$intSize} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $intProc = $readProc{$intSize} or return 0 8 0 8
428 8 ▶ my $refProc = $readProc{$refSize} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $refProc = $readProc{$refSize} or return 0 8 0 8
429  
430 # read and parse the offset table
431 8 my $tableSize = $intSize * $numObj;
432 8 ▶ $raf->Seek($tableOff, 0) and $raf->Read($buff, $tableSize) == $tableSize or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($tableOff, 0) and $raf->Read($buff, $tableSize) == $tableSize or return 0 8 0 8
Condition33%1/3
$raf->Seek($tableOff, 0) and $raf->Read($buff, $tableSize) == $tableSize
!ll&&!rl&&r
008
MC/DC0%0/2
$raf->Seek($tableOff, 0) and $raf->Read($buff, $tableSize) == $tableSize
$raf->Seek($tableOff, 0) $raf->Read($buff, $tableSize) == $tableSize
Truth table33%1/3
A and B
A= $raf->Seek($tableOff, 0)B= $raf->Read($buff, $tableSize) == $tableSize
ABresult
0X0
100
111
433 8 ▶ for ($i=0; $i<$numObj; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numObj) 69 8 77
434 69 push @table, &$intProc(\$buff, $i * $intSize);
435 }
436 8 my %plistInfo = (
437 RAF => $raf,
438 RefSize => $refSize,
439 RefProc => $refProc,
440 Table => \@table,
441 TagTablePtr => $tagTablePtr,
442 );
443 # position file pointer at the top object, and extract it
444 8 ▶ $raf->Seek($table[$topObj], 0) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($table[$topObj], 0) or return 0 8 0 8
445 8 $$dirInfo{Value} = ExtractObject($et, \%plistInfo);
446 8 ▶ return defined $$dirInfo{Value} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $dirInfo->{'Value'} ? : 8 0 8
447 }
448  
449 #------------------------------------------------------------------------------
450 # Extract information from a PLIST file (binary, XML or JSON format)
451 # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
452 # Returns: 1 on success, 0 if this wasn't valid PLIST
453 sub ProcessPLIST($$;$)
454 7 ▶{
Subroutine ProcessPLIST: called CC=17 SCAR=32.4
Pod undocumented
455 7 my ($et, $dirInfo, $tagTablePtr) = @_;
456 7 my $dataPt = $$dirInfo{DataPt};
457 7 ▶ my $start = $$dirInfo{DirStart} || 0;
Condition50%1/2
$dirInfo->{'DirStart'} || 0
l!l
07
MC/DC0%0/1
$dirInfo->{'DirStart'} || 0
$dirInfo->{'DirStart'}
Truth table50%1/2
A
A= $dirInfo->{'DirStart'}
Aresult
11
00
458 7 my ($result, $notXML);
459  
460 7 ▶ if ($dataPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dataPt) 1 6 7
461 1 pos($$dataPt) = $start;
462 1 ▶ $notXML = 1 unless $$dataPt =~ /\G</g;
Branch: 1 branch
BranchTrueFalseTotal
unless $$dataPt =~ /\G</g 1 0 1
463 }
464 7 ▶ unless ($notXML) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($notXML) 6 1 7
465 # process XML PLIST data using the XMP module
466 6 $$dirInfo{XMPParseOpts}{FoundProc} = \&FoundTag;
467 6 $result = Image::ExifTool::XMP::ProcessXMP($et, $dirInfo, $tagTablePtr);
468 6 delete $$dirInfo{XMPParseOpts};
469 6 ▶ return $result if $result;
Branch: 1 branch
BranchTrueFalseTotal
if $result 2 4 6
470 }
471 5 my $buff;
472 5 my $raf = $$dirInfo{RAF};
473 5 ▶ if ($raf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf) { } 4 1 5
474 4 ▶ $raf->Seek(0,0) and $raf->Read($buff, 64) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek(0, 0) and $raf->Read($buff, 64) or return 0 4 0 4
Condition33%1/3
$raf->Seek(0, 0) and $raf->Read($buff, 64)
!ll&&!rl&&r
004
MC/DC0%0/2
$raf->Seek(0, 0) and $raf->Read($buff, 64)
$raf->Seek(0, 0) $raf->Read($buff, 64)
Truth table33%1/3
A and B
A= $raf->Seek(0, 0)B= $raf->Read($buff, 64)
ABresult
0X0
100
111
475 4 $dataPt = \$buff;
476 } else {
477 1 ▶ return 0 unless $dataPt;
Branch: 1 branch
BranchTrueFalseTotal
unless $dataPt 0 1 1
478 }
479 5 pos($$dataPt) = $start;
480 5 ▶ if ($$dataPt =~ /\Gbplist0/) { # binary PLIST
Branch: 3 branches
BranchTrueFalseTotal
if ($$dataPt =~ /\Gbplist0/) { } 2 3 5
elsif ($$dataPt =~ /^\{"/) { } 0 3 3
elsif ($et->{'FILE_EXT'} and $et->{'FILE_EXT'} eq 'PLIST' and $$dataPt =~ /^\xfe\xff\x00/) { } 0 6 6
481 # binary PLIST file
482 2 my $tagTablePtr = GetTagTable('Image::ExifTool::PLIST::Main');
483 2 $et->SetFileType('PLIST', 'application/x-plist');
484 2 $$et{SET_GROUP1} = 'PLIST';
485 2 ▶ unless (ProcessBinaryPLIST($et, $dirInfo, $tagTablePtr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&ProcessBinaryPLIST($et, $dirInfo, $tagTablePtr)) 0 2 2
486 0 $et->Error('Error reading binary PLIST file');
487 }
488 2 delete $$et{SET_GROUP1};
489 2 $result = 1;
490 } elsif ($$dataPt =~ /^\{"/) { # JSON PLIST
491 0 ▶ $raf and $raf->Seek(0);
Branch: 1 branch
BranchTrueFalseTotal
$raf and $raf->Seek(0) 0 0 0
492 0 require Image::ExifTool::JSON;
493 0 $result = Image::ExifTool::JSON::ProcessJSON($et, $dirInfo);
494 ▶ } elsif ($$et{FILE_EXT} and $$et{FILE_EXT} eq 'PLIST' and
Condition33%2/6
$et->{"FILE_EXT"} and $et->{"FILE_EXT"} eq "PLIST" and $$dataPt =~ /^\xfe\xff\x00/
!ll&&!rl&&r
300
$et->{"FILE_EXT"} and $et->{"FILE_EXT"} eq "PLIST"
!ll&&!rl&&r
300
MC/DC0%0/3
$et->{"FILE_EXT"} and $et->{"FILE_EXT"} eq "PLIST" and $$dataPt =~ /^\xfe\xff\x00/
$et->{"FILE_EXT"} $et->{"FILE_EXT"} eq "PLIST" $$dataPt =~ /^\xfe\xff\x00/
Truth table25%1/4
A and B and C
A= $et->{"FILE_EXT"}B= $et->{"FILE_EXT"} eq "PLIST"C= $$dataPt =~ /^\xfe\xff\x00/
ABCresult
0XX0
10X0
1100
1111
495 $$dataPt =~ /^\xfe\xff\x00/)
496 {
497 # (have seen very old PLIST files encoded as UCS-2BE with leading BOM)
498 0 $et->Error('Old PLIST format currently not supported');
499 0 $result = 1;
500 }
501 5 return $result;
502 }
503  
504 9 1; # end
505  
506 __END__
« Image/ExifTool/PCAP.pm ↑ Summary Image/ExifTool/BMP.pm »