Image/ExifTool/ZIP.pm

filter: Statementstmt 63.7% 213 / 334 Branchbran 37.6% 70 / 186 Conditioncond 26.6% 25 / 94 MC/DCmcdc 3.6% 2 / 55 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 7 totaltotal 46.5% 320 / 688 CC 129 SCAR 64.2
CC
129
Cov
50%
ProcessZIP
968.5
ProcessRAR
366.2
ProcessGZIP
17.9
CRAP 611.5
« Image/ExifTool/FlashPix.pm ↑ Summary Image/ExifTool/XMP.pm »
1 #------------------------------------------------------------------------------
2 # File: ZIP.pm
3 #
4 # Description: Read ZIP archive meta information
5 #
6 # Revisions: 10/28/2007 - P. Harvey Created
7 #
8 # References: 1) http://www.pkware.com/documents/casestudies/APPNOTE.TXT
9 # 2) http://www.cpanforum.com/threads/9046
10 # 3) http://www.gzip.org/zlib/rfc-gzip.html
11 # 4) http://DataCompression.info/ArchiveFormats/RAR202.txt
12 # 5) https://jira.atlassian.com/browse/CONF-21706
13 # 6) http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/indesign/cs55-docs/IDML/idml-specification.pdf
14 # 7) https://www.rarlab.com/technote.htm
15 #------------------------------------------------------------------------------
16  
17 package Image::ExifTool::ZIP;
18  
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use vars qw($VERSION $warnString);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 $VERSION = '1.32';
24  
25 0 ▶sub WarnProc($) { $warnString = $_[0]; }
Subroutine WarnProc: not called CC=1 SCAR=6.9
Pod undocumented
26  
27 # file types for recognized Open Document "mimetype" values
28 1 my %openDocType = (
29 'application/vnd.oasis.opendocument.database' => 'ODB', #5
30 'application/vnd.oasis.opendocument.chart' => 'ODC', #5
31 'application/vnd.oasis.opendocument.formula' => 'ODF', #5
32 'application/vnd.oasis.opendocument.graphics' => 'ODG', #5
33 'application/vnd.oasis.opendocument.image' => 'ODI', #5
34 'application/vnd.oasis.opendocument.presentation' => 'ODP',
35 'application/vnd.oasis.opendocument.spreadsheet' => 'ODS',
36 'application/vnd.oasis.opendocument.text' => 'ODT',
37 'application/vnd.adobe.indesign-idml-package' => 'IDML', #6 (not open doc)
38 'application/epub+zip' => 'EPUB', #PH (not open doc)
39 );
40  
41 # iWork file types based on names of files found in the zip archive
42 1 my %iWorkFile = (
43 'Index/Slide.iwa' => 'KEY',
44 'Index/Tables/DataList.iwa' => 'NUMBERS',
45 );
46  
47 1 my %iWorkType = (
48 NUMBERS => 'NUMBERS',
49 PAGES => 'PAGES',
50 KEY => 'KEY',
51 KTH => 'KTH',
52 NMBTEMPLATE => 'NMBTEMPLATE',
53 );
54  
55 # ZIP metadata blocks
56 %Image::ExifTool::ZIP::Main = (
57 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
58 GROUPS => { 2 => 'Other' },
59 FORMAT => 'int16u',
60 NOTES => q{
61 The following tags are extracted from ZIP archives. ExifTool also extracts
62 additional meta information from compressed documents inside some ZIP-based
63 files such Office Open XML (DOCX, PPTX and XLSX), Open Document (ODB, ODC,
64 ODF, ODG, ODI, ODP, ODS and ODT), iWork (KEY, PAGES, NUMBERS), Capture One
65 Enhanced Image Package (EIP), Adobe InDesign Markup Language (IDML),
66 Electronic Publication (EPUB), and Sketch design files (SKETCH). The
67 ExifTool family 3 groups may be used to organize ZIP tags by embedded
68 document number (ie. the exiftool C<-g3> option).
69 },
70 2 => 'ZipRequiredVersion',
71 3 => {
72 Name => 'ZipBitFlag',
73 PrintConv => '$val ? sprintf("0x%.4x",$val) : $val',
74 },
75 4 => {
76 Name => 'ZipCompression',
77 PrintConv => {
78 0 => 'None',
79 1 => 'Shrunk',
80 2 => 'Reduced with compression factor 1',
81 3 => 'Reduced with compression factor 2',
82 4 => 'Reduced with compression factor 3',
83 5 => 'Reduced with compression factor 4',
84 6 => 'Imploded',
85 7 => 'Tokenized',
86 8 => 'Deflated',
87 9 => 'Enhanced Deflate using Deflate64(tm)',
88 10 => 'Imploded (old IBM TERSE)',
89 12 => 'BZIP2',
90 14 => 'LZMA (EFS)',
91 18 => 'IBM TERSE (new)',
92 19 => 'IBM LZ77 z Architecture (PFS)',
93 96 => 'JPEG recompressed', #2
94 97 => 'WavPack compressed', #2
95 98 => 'PPMd version I, Rev 1',
96 },
97 },
98 5 => {
99 Name => 'ZipModifyDate',
100 Format => 'int32u',
101 Groups => { 2 => 'Time' },
102 28 ▶ ValueConv => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
103 28 my $val = shift;
104 28 return sprintf('%.4d:%.2d:%.2d %.2d:%.2d:%.2d',
105 ($val >> 25) + 1980, # year
106 ($val >> 21) & 0x0f, # month
107 ($val >> 16) & 0x1f, # day
108 ($val >> 11) & 0x1f, # hour
109 ($val >> 5) & 0x3f, # minute
110 ($val & 0x1f) * 2 # second
111 );
112 },
113 1 PrintConv => '$self->ConvertDateTime($val)',
114 },
115 7 => { Name => 'ZipCRC', Format => 'int32u', PrintConv => 'sprintf("0x%.8x",$val)' },
116 9 => { Name => 'ZipCompressedSize', Format => 'int32u' },
117 11 => { Name => 'ZipUncompressedSize', Format => 'int32u' },
118 13 => {
119 Name => 'ZipFileNameLength',
120 # don't store a tag -- just extract the value for use with ZipFileName
121 Hidden => 1,
122 RawConv => '$$self{ZipFileNameLength} = $val; undef',
123 },
124 # 14 => 'ZipExtraFieldLength',
125 15 => {
126 Name => 'ZipFileName',
127 Format => 'string[$$self{ZipFileNameLength}]',
128 },
129 _com => 'ZipFileComment',
130 );
131  
132 # GNU ZIP tags (ref 3)
133 1 %Image::ExifTool::ZIP::GZIP = (
134 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
135 GROUPS => { 2 => 'Other' },
136 NOTES => q{
137 These tags are extracted from GZIP (GNU ZIP) archives, but currently only
138 for the first file in the archive.
139 },
140 2 => {
141 Name => 'Compression',
142 PrintConv => {
143 8 => 'Deflated',
144 },
145 },
146 3 => {
147 Name => 'Flags',
148 PrintConv => { BITMASK => {
149 0 => 'Text',
150 1 => 'CRC16',
151 2 => 'ExtraFields',
152 3 => 'FileName',
153 4 => 'Comment',
154 }},
155 },
156 4 => {
157 Name => 'ModifyDate',
158 Format => 'int32u',
159 Groups => { 2 => 'Time' },
160 ValueConv => 'ConvertUnixTime($val,1)',
161 PrintConv => '$self->ConvertDateTime($val)',
162 },
163 8 => {
164 Name => 'ExtraFlags',
165 PrintConv => {
166 0 => '(none)',
167 2 => 'Maximum Compression',
168 4 => 'Fastest Algorithm',
169 },
170 },
171 9 => {
172 Name => 'OperatingSystem',
173 PrintConv => {
174 0 => 'FAT filesystem (MS-DOS, OS/2, NT/Win32)',
175 1 => 'Amiga',
176 2 => 'VMS (or OpenVMS)',
177 3 => 'Unix',
178 4 => 'VM/CMS',
179 5 => 'Atari TOS',
180 6 => 'HPFS filesystem (OS/2, NT)',
181 7 => 'Macintosh',
182 8 => 'Z-System',
183 9 => 'CP/M',
184 10 => 'TOPS-20',
185 11 => 'NTFS filesystem (NT)',
186 12 => 'QDOS',
187 13 => 'Acorn RISCOS',
188 255 => 'unknown',
189 },
190 },
191 10 => 'ArchivedFileName',
192 11 => 'Comment',
193 );
194  
195 # RAR v4 tags (ref 4)
196 %Image::ExifTool::ZIP::RAR = (
197 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
198 GROUPS => { 2 => 'Other' },
199 NOTES => 'These tags are extracted from RAR archive files.',
200 0 => {
201 Name => 'CompressedSize',
202 Format => 'int32u',
203 },
204 4 => {
205 Name => 'UncompressedSize',
206 Format => 'int32u',
207 },
208 8 => {
209 Name => 'OperatingSystem',
210 PrintConv => {
211 0 => 'MS-DOS',
212 1 => 'OS/2',
213 2 => 'Win32',
214 3 => 'Unix',
215 },
216 },
217 13 => {
218 Name => 'ModifyDate',
219 Format => 'int32u',
220 Groups => { 2 => 'Time' },
221 0 ▶ ValueConv => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
222 0 my $val = shift;
223 0 return sprintf('%.4d:%.2d:%.2d %.2d:%.2d:%.2d',
224 ($val >> 25) + 1980, # year
225 ($val >> 21) & 0x0f, # month
226 ($val >> 16) & 0x1f, # day
227 ($val >> 11) & 0x1f, # hour
228 ($val >> 5) & 0x3f, # minute
229 ($val & 0x1f) * 2 # second
230 );
231 },
232 1 PrintConv => '$self->ConvertDateTime($val)',
233 },
234 18 => {
235 Name => 'PackingMethod',
236 PrintHex => 1,
237 PrintConv => {
238 0x30 => 'Stored',
239 0x31 => 'Fastest',
240 0x32 => 'Fast',
241 0x33 => 'Normal',
242 0x34 => 'Good Compression',
243 0x35 => 'Best Compression',
244 },
245 },
246 19 => {
247 Name => 'FileNameLength',
248 Format => 'int16u',
249 Hidden => 1,
250 RawConv => '$$self{FileNameLength} = $val; undef',
251 },
252 25 => {
253 Name => 'ArchivedFileName',
254 Format => 'string[$$self{FileNameLength}]',
255 },
256 );
257  
258 # RAR v5 tags (ref 7, github#203)
259 1 %Image::ExifTool::ZIP::RAR5 = (
260 GROUPS => { 2 => 'Other' },
261 VARS => { ID_FMT => 'none' },
262 NOTES => 'These tags are extracted from RAR v5 and 7z archive files.',
263 FileVersion => { },
264 CompressedSize => { },
265 ModifyDate => {
266 Groups => { 2 => 'Time' },
267 ValueConv => 'ConvertUnixTime($val,1)',
268 PrintConv => '$self->ConvertDateTime($val)',
269 },
270 UncompressedSize => { },
271 OperatingSystem => {
272 PrintConv => { 0 => 'Win32', 1 => 'Unix' },
273 },
274 ArchivedFileName => { },
275 );
276  
277 #------------------------------------------------------------------------------
278 # Read unsigned LEB (Little Endian Base) from file
279 # Inputs: 0) RAF ref
280 # Returns: integer value
281 sub ReadULEB($)
282 15 ▶{
Subroutine ReadULEB: called CC=3 SCAR=11.0
Pod undocumented
283 15 my $raf = shift;
284 15 my ($i, $buff);
285 15 my $rtnVal = 0;
286 15 for ($i=0; ; ++$i) {
287 18 ▶ $raf->Read($buff, 1) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 1) or last 17 1 18
288 17 my $num = ord($buff);
289 17 $rtnVal += ($num & 0x7f) << ($i * 7);
290 17 ▶ $num & 0x80 or last;
Branch: 1 branch
BranchTrueFalseTotal
$num & 128 or last 3 14 17
291 }
292 15 return $rtnVal;
293 }
294  
295 #------------------------------------------------------------------------------
296 # Extract information from a RAR file
297 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
298 # Returns: 1 on success, 0 if this wasn't a valid RAR file
299 sub ProcessRAR($$)
300 1 ▶{
Subroutine ProcessRAR: called CC=40 SCAR=59.0
Pod undocumented
301 1 my ($et, $dirInfo) = @_;
302 1 my $raf = $$dirInfo{RAF};
303 1 my ($flags, $buff);
304 1 my $docNum = 0;
305  
306 1 ▶ return 0 unless $raf->Read($buff, 7) and $buff =~ "Rar!\x1a\x07[\0\x01]";
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 7) and $buff =~ /Rar!\032\007[\000\001]/ 0 1 1
Condition33%1/3
$raf->Read($buff, 7) and $buff =~ /Rar!\032\007[\000\001]/
!ll&&!rl&&r
001
MC/DC0%0/2
$raf->Read($buff, 7) and $buff =~ /Rar!\032\007[\000\001]/
$raf->Read($buff, 7) $buff =~ /Rar!\032\007[\000\001]/
Truth table33%1/3
A and B
A= $raf->Read($buff, 7)B= $buff =~ /Rar!\032\007[\000\001]/
ABresult
0X0
100
111
307  
308 1 ▶ if ($buff eq "Rar!\x1a\x07\0") { # RARv4 (ref 4)
Branch: 1 branch
BranchTrueFalseTotal
if ($buff eq "Rar!\cZ\a\000") { } 0 1 1
309  
310 0 $et->SetFileType();
311 0 SetByteOrder('II');
312 0 my $tagTablePtr = GetTagTable('Image::ExifTool::ZIP::RAR5');
313 0 $et->HandleTag($tagTablePtr, 'FileVersion', 'RAR v4');
314 0 $tagTablePtr = GetTagTable('Image::ExifTool::ZIP::RAR');
315  
316 0 for (;;) {
317 # read block header
318 0 ▶ $raf->Read($buff, 7) == 7 or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 7) == 7 or last 0 0 0
319 0 my ($type, $flags, $size) = unpack('xxCvv', $buff);
320 0 $size -= 7;
321 0 ▶ if ($flags & 0x8000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 32768) 0 0 0
322 0 ▶ $raf->Read($buff, 4) == 4 or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 4) == 4 or last 0 0 0
323 0 $size += unpack('V',$buff) - 4;
324 }
325 0 ▶ last if $size < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $size < 0 0 0 0
326 0 ▶ next unless $size; # ignore blocks with no data
Branch: 1 branch
BranchTrueFalseTotal
unless $size 0 0 0
327 # don't try to read very large blocks unless LargeFileSupport is enabled
328 0 ▶ if ($size >= 0x80000000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size >= 2147483648) 0 0 0
329 0 ▶ if (not $et->Options('LargeFileSupport')) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $et->Options('LargeFileSupport')) { } 0 0 0
elsif ($et->Options('LargeFileSupport') eq '2') { } 0 0 0
330 0 $et->Warn('Large block encountered. Aborting.');
331 0 last;
332 } elsif ($et->Options('LargeFileSupport') eq '2') {
333 0 $et->Warn('Processing large block (LargeFileSupport is 2)');
334 }
335 }
336 # process the block
337 0 ▶ if ($type == 0x74) { # file block
Branch: 2 branches
BranchTrueFalseTotal
if ($type == 116) { } 0 0 0
elsif ($type == 117 and $size > 6) { } 0 0 0
338 # read maximum 4 KB from a file block
339 0 ▶ my $n = $size > 4096 ? 4096 : $size;
Branch: 1 branch
BranchTrueFalseTotal
$size > 4096 ? : 0 0 0
340 0 ▶ $raf->Read($buff, $n) == $n or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $n) == $n or last 0 0 0
341 # add compressed size to start of data so we can extract it with the other tags
342 0 $buff = pack('V',$size) . $buff;
343 0 $$et{DOC_NUM} = ++$docNum;
344 0 $et->ProcessDirectory({ DataPt => \$buff }, $tagTablePtr);
345 0 $size -= $n;
346 ▶ } elsif ($type == 0x75 and $size > 6) { # comment block
Condition0%0/3
$type == 117 and $size > 6
!ll&&!rl&&r
000
MC/DC0%0/2
$type == 117 and $size > 6
$type == 117 $size > 6
Truth table0%0/3
A and B
A= $type == 117B= $size > 6
ABresult
0X0
100
111
347 0 ▶ $raf->Read($buff, $size) == $size or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $size) == $size or last 0 0 0
348 # save comment, only if "Stored" (this is untested)
349 0 ▶ if (Get8u(\$buff, 3) == 0x30) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Get8u(\$buff, 3) == 48) 0 0 0
350 0 $et->FoundTag('Comment', substr($buff, 6));
351 }
352 0 next;
353 }
354 # seek to the start of the next block
355 0 ▶ $raf->Seek($size, 1) or last if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 0 0 0
Condition0%0/5
$size && ($raf->Seek($size, 1) || (last))
!ll&&!rl&&r
000
$raf->Seek($size, 1) or last
l!l
00
MC/DC0%0/2
$size && ($raf->Seek($size, 1) || (last))
$size $raf->Seek($size, 1)
Truth table0%0/3
A && B
A= $sizeB= $raf->Seek($size, 1)
ABresult
0X0
100
111
356 }
357  
358 } else { # RARv5 (ref 7, github#203)
359  
360 1 ▶ return 0 unless $raf->Read($buff, 1) and $buff eq "\0";
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 1) and $buff eq "\0" 0 1 1
Condition33%1/3
$raf->Read($buff, 1) and $buff eq "\0"
!ll&&!rl&&r
001
MC/DC0%0/2
$raf->Read($buff, 1) and $buff eq "\0"
$raf->Read($buff, 1) $buff eq "\0"
Truth table33%1/3
A and B
A= $raf->Read($buff, 1)B= $buff eq "\0"
ABresult
0X0
100
111
361 1 $et->SetFileType();
362 1 my $tagTablePtr = GetTagTable('Image::ExifTool::ZIP::RAR5');
363 1 $et->HandleTag($tagTablePtr, 'FileVersion', 'RAR v5');
364 1 $$et{INDENT} .= '| ';
365  
366 # loop through header blocks
367 1 for (;;) {
368 4 $raf->Seek(4, 1); # skip header CRC
369 4 my $headSize = ReadULEB($raf);
370 4 ▶ last if $headSize == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $headSize == 0 1 3 4
371 # read the header and create new RAF object for reading it
372 3 my $header;
373 3 ▶ $raf->Read($header, $headSize) == $headSize or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($header, $headSize) == $headSize or last 3 0 3
374 3 my $rafHdr = File::RandomAccess->new(\$header);
375 3 my $headType = ReadULEB($rafHdr); # get header type
376  
377 3 ▶ if ($headType == 4) { # encryption block
Branch: 1 branch
BranchTrueFalseTotal
if ($headType == 4) 0 3 3
378 0 $et->Warn("File is encrypted.", 0);
379 0 last;
380 }
381 # skip over all headers except file or service header
382 3 ▶ next unless $headType == 2 or $headType == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless $headType == 2 or $headType == 3 2 1 3
Condition66%2/3
$headType == 2 or $headType == 3
l!l&&r!l&&!r
102
MC/DC50%1/2
$headType == 2 or $headType == 3
$headType == 2 $headType == 3
Truth table66%2/3
A or B
A= $headType == 2B= $headType == 3
ABresult
1X1
011
000
383 1 ▶ $et->VerboseDir('RAR5 file', undef, $headSize) if $headType == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $headType == 2 1 0 1
384  
385 1 my $headFlag = ReadULEB($rafHdr);
386 1 ReadULEB($rafHdr); # skip extraSize
387 1 my $dataSize;
388 1 ▶ if ($headFlag & 0x0002) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headFlag & 2) { } 1 0 1
389 1 $dataSize = ReadULEB($rafHdr); # compressed data size
390 1 ▶ if ($headType == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($headType == 2) { } 1 0 1
391 1 $et->HandleTag($tagTablePtr, 'CompressedSize', $dataSize);
392 } else {
393 0 $raf->Seek($dataSize, 1); # skip service data section
394 0 next;
395 }
396 } else {
397 0 ▶ next if $headType == 3; # all done with service header
Branch: 1 branch
BranchTrueFalseTotal
if $headType == 3 0 0 0
398 0 $dataSize = 0;
399 }
400 1 my $fileFlag = ReadULEB($rafHdr);
401 1 my $uncompressedSize = ReadULEB($rafHdr);
402 1 ▶ $et->HandleTag($tagTablePtr, 'UncompressedSize', $uncompressedSize) unless $fileFlag & 0x0008;
Branch: 1 branch
BranchTrueFalseTotal
unless $fileFlag & 8 1 0 1
403 1 ReadULEB($rafHdr); # skip file attributes
404 1 ▶ if ($fileFlag & 0x0002) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fileFlag & 2) 0 1 1
405 0 ▶ $rafHdr->Read($buff, 4) == 4 or last;
Branch: 1 branch
BranchTrueFalseTotal
$rafHdr->Read($buff, 4) == 4 or last 0 0 0
406 # (untested)
407 0 $et->HandleTag($tagTablePtr, 'ModifyDate', unpack('V', $buff));
408 }
409 1 ▶ $rafHdr->Seek(4, 1) if $fileFlag & 0x0004; # skip CRC if present
Branch: 1 branch
BranchTrueFalseTotal
if $fileFlag & 4 1 0 1
410  
411 1 ReadULEB($rafHdr); # skip compressionInfo
412  
413 # get operating system
414 1 my $os = ReadULEB($rafHdr);
415 1 $et->HandleTag($tagTablePtr, 'OperatingSystem', $os);
416  
417 # get filename
418 1 ▶ $rafHdr->Read($buff, 1) == 1 or last;
Branch: 1 branch
BranchTrueFalseTotal
$rafHdr->Read($buff, 1) == 1 or last 1 0 1
419 1 my $nameLen = ord($buff);
420 1 ▶ $rafHdr->Read($buff, $nameLen) == $nameLen or last;
Branch: 1 branch
BranchTrueFalseTotal
$rafHdr->Read($buff, $nameLen) == $nameLen or last 1 0 1
421 1 $buff =~ s/\0+$//; # remove trailing nulls (if any)
422 1 $et->HandleTag($tagTablePtr, 'ArchivedFileName', $buff);
423  
424 1 $$et{DOC_NUM} = ++$docNum;
425  
426 1 $raf->Seek($dataSize, 1); # skip data section
427 }
428 1 $$et{INDENT} = substr($$et{INDENT}, 0, -2);
429 }
430  
431 1 $$et{DOC_NUM} = 0;
432 1 ▶ if ($docNum > 1 and not $et->Options('Duplicates')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($docNum > 1 and not $et->Options("Duplicates")) 0 1 1
Condition33%1/3
$docNum > 1 and not $et->Options("Duplicates")
!ll&&!rl&&r
100
MC/DC0%0/2
$docNum > 1 and not $et->Options("Duplicates")
$docNum > 1 not $et->Options("Duplicates")
Truth table33%1/3
A and not(B)
A= $docNum > 1B= not $et->Options("Duplicates")
ABresult
0X0
100
111
433 0 $et->Warn("Use the Duplicates option to extract tags for all $docNum files", 1);
434 }
435  
436 1 return 1;
437 }
438  
439 #------------------------------------------------------------------------------
440 # Extract information from a GNU ZIP file (ref 3)
441 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
442 # Returns: 1 on success, 0 if this wasn't a valid GZIP file
443 sub ProcessGZIP($$)
444 1 ▶{
Subroutine ProcessGZIP: called CC=13 SCAR=28.9
Pod undocumented
445 1 my ($et, $dirInfo) = @_;
446 1 my $raf = $$dirInfo{RAF};
447 1 my ($flags, $buff);
448  
449 1 ▶ return 0 unless $raf->Read($buff, 10) and $buff =~ /^\x1f\x8b\x08/;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 10) and $buff =~ /^\x1f\x8b\x08/ 0 1 1
Condition33%1/3
$raf->Read($buff, 10) and $buff =~ /^\x1f\x8b\x08/
!ll&&!rl&&r
001
MC/DC0%0/2
$raf->Read($buff, 10) and $buff =~ /^\x1f\x8b\x08/
$raf->Read($buff, 10) $buff =~ /^\x1f\x8b\x08/
Truth table33%1/3
A and B
A= $raf->Read($buff, 10)B= $buff =~ /^\x1f\x8b\x08/
ABresult
0X0
100
111
450  
451 1 $et->SetFileType();
452 1 SetByteOrder('II');
453  
454 1 my $tagTablePtr = GetTagTable('Image::ExifTool::ZIP::GZIP');
455 1 $et->HandleTag($tagTablePtr, 2, Get8u(\$buff, 2));
456 1 $et->HandleTag($tagTablePtr, 3, $flags = Get8u(\$buff, 3));
457 1 $et->HandleTag($tagTablePtr, 4, Get32u(\$buff, 4));
458 1 $et->HandleTag($tagTablePtr, 8, Get8u(\$buff, 8));
459 1 $et->HandleTag($tagTablePtr, 9, Get8u(\$buff, 9));
460  
461 # extract file name and comment if they exist
462 1 ▶ if ($flags & 0x18) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 24) 1 0 1
463 1 ▶ if ($flags & 0x04) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 4) 0 1 1
464 # skip extra field
465 0 ▶ $raf->Read($buff, 2) == 2 or return 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 2) == 2 or return 1 0 0 0
466 0 my $len = Get16u(\$buff, 0);
467 0 ▶ $raf->Read($buff, $len) == $len or return 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, $len) == $len or return 1 0 0 0
468 }
469 1 ▶ $raf->Read($buff, 4096) or return 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 4096) or return 1 1 0 1
470 1 my $pos = 0;
471 1 my $tagID;
472 # loop for ArchivedFileName (10) and Comment (11) tags
473 1 foreach $tagID (10, 11) {
474 2 ▶ my $mask = $tagID == 10 ? 0x08 : 0x10;
Branch: 1 branch
BranchTrueFalseTotal
$tagID == 10 ? : 1 1 2
475 2 ▶ next unless $flags & $mask;
Branch: 1 branch
BranchTrueFalseTotal
unless $flags & $mask 0 2 2
476 2 ▶ my $end = $buff =~ /\0/g ? pos($buff) - 1 : length($buff);
Branch: 1 branch
BranchTrueFalseTotal
$buff =~ /\0/g ? : 2 0 2
477 # (the doc specifies the string should be ISO 8859-1,
478 # but in OS X it seems to be UTF-8, so don't translate
479 # it because I could just as easily screw it up)
480 2 my $str = substr($buff, $pos, $end - $pos);
481 2 $et->HandleTag($tagTablePtr, $tagID, $str);
482 2 ▶ last if $end >= length $buff;
Branch: 1 branch
BranchTrueFalseTotal
if $end >= length $buff 0 2 2
483 2 $pos = $end + 1;
484 }
485 }
486 1 return 1;
487 }
488  
489 #------------------------------------------------------------------------------
490 # Call HandleTags for attributes of an Archive::Zip member
491 # Inputs: 0) ExifTool object ref, 1) member ref, 2) optional tag table ref
492 sub HandleMember($$;$)
493 28 ▶{
Subroutine HandleMember: called CC=4 SCAR=14.0
Pod undocumented
494 28 my ($et, $member, $tagTablePtr) = @_;
495 28 ▶ $tagTablePtr or $tagTablePtr = GetTagTable('Image::ExifTool::ZIP::Main');
Branch: 1 branch
BranchTrueFalseTotal
$tagTablePtr or $tagTablePtr = &GetTagTable("Image::ExifTool::ZIP::Main") 1 27 28
496 28 $et->HandleTag($tagTablePtr, 2, $member->versionNeededToExtract());
497 28 $et->HandleTag($tagTablePtr, 3, $member->bitFlag());
498 28 $et->HandleTag($tagTablePtr, 4, $member->compressionMethod());
499 28 $et->HandleTag($tagTablePtr, 5, $member->lastModFileDateTime());
500 28 $et->HandleTag($tagTablePtr, 7, $member->crc32());
501 28 $et->HandleTag($tagTablePtr, 9, $member->compressedSize());
502 28 $et->HandleTag($tagTablePtr, 11, $member->uncompressedSize());
503 28 $et->HandleTag($tagTablePtr, 15, $member->fileName());
504 28 my $com = $member->fileComment();
505 28 ▶ $et->HandleTag($tagTablePtr, '_com', $com) if defined $com and length $com;
Branch: 1 branch
BranchTrueFalseTotal
if defined $com and length $com 0 28 28
Condition33%1/3
defined $com and length $com
!ll&&!rl&&r
0280
MC/DC0%0/2
defined $com and length $com
defined $com length $com
Truth table33%1/3
A and B
A= defined $comB= length $com
ABresult
0X0
100
111
506 }
507  
508 #------------------------------------------------------------------------------
509 # Extract file from ZIP archive
510 # Inputs: 0) ExifTool ref, 1) Zip object ref, 2) file name
511 # Returns: zip member or undef it it didn't exist
512 sub ExtractFile($$$)
513 10 ▶{
Subroutine ExtractFile: called CC=1 SCAR=0.0
Pod undocumented
514 10 my ($et, $zip, $file) = @_;
515 10 my $result = $zip->memberNamed($file);
516 10 $et->VPrint(1, " (Extracting '${file}' from zip archive)\n");
517 10 return $result;
518 }
519  
520 #------------------------------------------------------------------------------
521 # Extract information from a ZIP file
522 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
523 # Returns: 1 on success, 0 if this wasn't a valid ZIP file
524 sub ProcessZIP($$)
525 5 ▶{
Subroutine ProcessZIP: called CC=73 SCAR=68.8
Pod undocumented
526 5 my ($et, $dirInfo) = @_;
527 5 my $raf = $$dirInfo{RAF};
528 5 my ($buff, $buf2, $zip);
529  
530 5 ▶ return 0 unless $raf->Read($buff, 30) == 30 and $buff =~ /^PK\x03\x04/;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 30) == 30 and $buff =~ /^PK\x03\x04/ 0 5 5
Condition33%1/3
$raf->Read($buff, 30) == 30 and $buff =~ /^PK\x03\x04/
!ll&&!rl&&r
005
MC/DC0%0/2
$raf->Read($buff, 30) == 30 and $buff =~ /^PK\x03\x04/
$raf->Read($buff, 30) == 30 $buff =~ /^PK\x03\x04/
Truth table33%1/3
A and B
A= $raf->Read($buff, 30) == 30B= $buff =~ /^PK\x03\x04/
ABresult
0X0
100
111
531  
532 5 my $tagTablePtr = GetTagTable('Image::ExifTool::ZIP::Main');
533 5 my $docNum = 0;
534  
535 # use Archive::Zip if available
536 5 for (;;) {
537 5 ▶ unless (eval { require Archive::Zip } and eval { require IO::File }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Archive::Zip } } and eval { do { require IO::File } }) 0 5 5
Condition33%1/3
eval { do { require Archive::Zip } } and eval { do { require IO::File } }
!ll&&!rl&&r
005
MC/DC0%0/2
eval { do { require Archive::Zip } } and eval { do { require IO::File } }
eval { do { require Archive::Zip } } eval { do { require IO::File } }
Truth table33%1/3
A and B
A= eval { do { require Archive::Zip } }B= eval { do { require IO::File } }
ABresult
0X0
100
111
538 0 ▶ if ($$et{FILE_EXT} and $$et{FILE_EXT} ne 'ZIP') {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"FILE_EXT"} and $et->{"FILE_EXT"} ne "ZIP") 0 0 0
Condition0%0/3
$et->{"FILE_EXT"} and $et->{"FILE_EXT"} ne "ZIP"
!ll&&!rl&&r
000
MC/DC0%0/2
$et->{"FILE_EXT"} and $et->{"FILE_EXT"} ne "ZIP"
$et->{"FILE_EXT"} $et->{"FILE_EXT"} ne "ZIP"
Truth table0%0/3
A and B
A= $et->{"FILE_EXT"}B= $et->{"FILE_EXT"} ne "ZIP"
ABresult
0X0
100
111
539 0 $et->Warn("Install Archive::Zip to decode compressed ZIP information");
540 }
541 0 last;
542 }
543 # Archive::Zip requires a seekable IO::File object
544 5 my $fh;
545 5 ▶ if ($raf->{TESTED} >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($raf->{'TESTED'} >= 0) { } 5 0 5
elsif (eval { do { require IO::String } }) { } 0 0 0
546 5 ▶ unless (eval { require IO::File }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require IO::File } }) 0 5 5
547 # (this shouldn't happen because IO::File is a prerequisite of Archive::Zip)
548 0 $et->Warn("Install IO::File to decode compressed ZIP information");
549 0 last;
550 }
551 5 $raf->Seek(0,0);
552 5 $fh = $raf->{FILE_PT};
553 5 bless $fh, 'IO::File'; # Archive::Zip expects an IO::File object
554 0 } elsif (eval { require IO::String }) {
555 # read the whole file into memory (what else can I do?)
556 0 $raf->Slurp();
557 0 $fh = IO::String->new(${$raf->{BUFF_PT}});
558 } else {
559 0 ▶ my $type = $raf->{FILE_PT} ? 'pipe or socket' : 'scalar reference';
Branch: 1 branch
BranchTrueFalseTotal
$raf->{'FILE_PT'} ? : 0 0 0
560 0 $et->Warn("Install IO::String to decode compressed ZIP information from a $type");
561 0 last;
562 }
563 5 $et->VPrint(1, " --- using Archive::Zip ---\n");
564 5 $zip = Archive::Zip->new;
565 # catch all warnings! (Archive::Zip is bad for this)
566 5 local $SIG{'__WARN__'} = \&WarnProc;
567 5 my $status = $zip->readFromFileHandle($fh);
568 0 ▶ if ($status eq '4' and $raf->{TESTED} >= 0 and eval { require IO::String } and
Branch: 1 branch
BranchTrueFalseTotal
if ($status eq 4 and $raf->{"TESTED"} >= 0 and eval { do { require IO::String } } and $raf->Seek(0, 2) and $raf->Tell < 100000000) 0 5 5
Condition33%4/12
$status eq 4 and $raf->{"TESTED"} >= 0 and eval { do { require IO::String } } and $raf->Seek(0, 2) and $raf->Tell < 100000000
!ll&&!rl&&r
500
$status eq 4 and $raf->{"TESTED"} >= 0 and eval { do { require IO::String } } and $raf->Seek(0, 2)
!ll&&!rl&&r
500
$status eq 4 and $raf->{"TESTED"} >= 0 and eval { do { require IO::String } }
!ll&&!rl&&r
500
$status eq 4 and $raf->{"TESTED"} >= 0
!ll&&!rl&&r
500
MC/DC0%0/5
$status eq 4 and $raf->{"TESTED"} >= 0 and eval { do { require IO::String } } and $raf->Seek(0, 2) and $raf->Tell < 100000000
$status eq 4 $raf->{"TESTED"} >= 0 eval { do { require IO::String } } $raf->Seek(0, 2) $raf->Tell < 100000000
Truth table16%1/6
A and B and C and D and E
A= $status eq 4B= $raf->{"TESTED"} >= 0C= eval { do { require IO::String } }D= $raf->Seek(0, 2)E= $raf->Tell < 100000000
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
569 $raf->Seek(0,2) and $raf->Tell() < 100000000)
570 {
571 # try again, reading it ourself this time in an attempt to avoid
572 # a failed test with Perl 5.6.2 GNU/Linux 2.6.32-5-686 i686-linux-64int-ld
573 0 $raf->Seek(0,0);
574 0 $raf->Slurp();
575 0 $fh = IO::String->new(${$raf->{BUFF_PT}});
576 0 $zip = Archive::Zip->new;
577 0 $status = $zip->readFromFileHandle($fh);
578 }
579 5 ▶ if ($status) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) 0 5 5
580 0 undef $zip;
581 0 my %err = ( 1=>'Stream end error', 3=>'Format error', 4=>'IO error' );
582 0 ▶ my $err = $err{$status} || "Error $status";
Condition0%0/2
$err{$status} || "Error $status"
l!l
00
MC/DC0%0/1
$err{$status} || "Error $status"
$err{$status}
Truth table0%0/2
A
A= $err{$status}
Aresult
11
00
583 0 $et->Warn("$err reading ZIP file");
584 0 last;
585 }
586 # extract zip file comment
587 5 my $comment = $zip->zipfileComment();
588 5 ▶ $et->FoundTag(Comment => $comment) if defined $comment and length $comment;
Branch: 1 branch
BranchTrueFalseTotal
if defined $comment and length $comment 0 5 5
Condition33%1/3
defined $comment and length $comment
!ll&&!rl&&r
050
MC/DC0%0/2
defined $comment and length $comment
defined $comment length $comment
Truth table33%1/3
A and B
A= defined $commentB= length $comment
ABresult
0X0
100
111
589  
590 5 $$dirInfo{ZIP} = $zip;
591  
592 # check for an Office Open file (DOCX, etc)
593 # --> read '[Content_Types].xml' to determine the file type
594 5 my ($mime, @members);
595 5 my $cType = ExtractFile($et, $zip, '[Content_Types].xml');
596 5 ▶ if ($cType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cType) 1 4 5
597 1 ($buff, $status) = $zip->contents($cType);
598 1 ▶ if (not $status and (
Branch: 1 branch
BranchTrueFalseTotal
if (not $status and $buff =~ m[\sPartName\s*=\s*['"](?:/ppt/presentation.xml|/word/document.xml|/xl/workbook.xml)['"][^>]*\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1] || $buff =~ /<Override[^>]*\sPartName[^<]+\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/ || $buff =~ /ContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/) 1 0 1
Condition33%3/9
not $status and $buff =~ m[\sPartName\s*=\s*['"](?:/ppt/presentation.xml|/word/document.xml|/xl/workbook.xml)['"][^>]*\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1] || $buff =~ /<Override[^>]*\sPartName[^<]+\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/ || $buff =~ /ContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/
!ll&&!rl&&r
001
$buff =~ m[\sPartName\s*=\s*['"](?:/ppt/presentation.xml|/word/document.xml|/xl/workbook.xml)['"][^>]*\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1] or $buff =~ /<Override[^>]*\sPartName[^<]+\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/ or $buff =~ /ContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/
l!l&&r!l&&!r
100
$buff =~ m[\sPartName\s*=\s*['"](?:/ppt/presentation.xml|/word/document.xml|/xl/workbook.xml)['"][^>]*\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1] or $buff =~ /<Override[^>]*\sPartName[^<]+\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/
l!l&&r!l&&!r
100
MC/DC0%0/4
not $status and $buff =~ m[\sPartName\s*=\s*['"](?:/ppt/presentation.xml|/word/document.xml|/xl/workbook.xml)['"][^>]*\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1] || $buff =~ /<Override[^>]*\sPartName[^<]+\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/ || $buff =~ /ContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/
not $status $buff =~ m[\sPartName\s*=\s*['"](?:/ppt/presentation.xml|/word/document.xml|/xl/workbook.xml)['"][^>]*\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1] $buff =~ /<Override[^>]*\sPartName[^<]+\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/ $buff =~ /ContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/
Truth table20%1/5
not(A) and B or C or D
A= not $statusB= $buff =~ m[\sPartName\s*=\s*['"](?:/ppt/presentation.xml|/word/document.xml|/xl/workbook.xml)['"][^>]*\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1]C= $buff =~ /<Override[^>]*\sPartName[^<]+\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/D= $buff =~ /ContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
599 # first look for the main document with the expected name
600 $buff =~ m{\sPartName\s*=\s*['"](?:/ppt/presentation.xml|/word/document.xml|/xl/workbook.xml)['"][^>]*\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1} or
601 # then look for the main part
602 $buff =~ /<Override[^>]*\sPartName[^<]+\sContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/ or
603 # and if all else fails, use the default main
604 $buff =~ /ContentType\s*=\s*(['"])([^"']+)\.main(\+xml)?\1/))
605 {
606 1 $mime = $2;
607 }
608 }
609 # check for docProps if we couldn't find a MIME type
610 5 ▶ $mime or @members = $zip->membersMatching('^docProps/.*\.(xml|XML)$');
Branch: 1 branch
BranchTrueFalseTotal
$mime or @members = $zip->membersMatching("^docProps/.*\\.(xml|XML)\$") 1 4 5
611 5 ▶ if ($mime or @members) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mime or @members) 1 4 5
Condition66%2/3
$mime or @members
l!l&&r!l&&!r
104
MC/DC50%1/2
$mime or @members
$mime @members
Truth table66%2/3
A or B
A= $mimeB= @members
ABresult
1X1
011
000
612 1 $$dirInfo{MIME} = $mime;
613 1 require Image::ExifTool::OOXML;
614 1 Image::ExifTool::OOXML::ProcessDOCX($et, $dirInfo);
615 1 delete $$dirInfo{MIME};
616 1 last;
617 }
618  
619 # check for an EIP file
620 4 @members = $zip->membersMatching('^CaptureOne/.*\.(cos|COS)$');
621 4 ▶ if (@members) {
Branch: 1 branch
BranchTrueFalseTotal
if (@members) 1 3 4
622 1 require Image::ExifTool::CaptureOne;
623 1 Image::ExifTool::CaptureOne::ProcessEIP($et, $dirInfo);
624 1 last;
625 }
626  
627 # check for an iWork file
628 3 @members = $zip->membersMatching('(?i)^(index\.(xml|apxl)|QuickLook/Thumbnail\.jpg|[^/]+\.(pages|numbers|key)/Index.(zip|xml|apxl))$');
629 3 ▶ if (@members) {
Branch: 1 branch
BranchTrueFalseTotal
if (@members) 1 2 3
630 1 require Image::ExifTool::iWork;
631 1 Image::ExifTool::iWork::Process_iWork($et, $dirInfo);
632 1 last;
633 }
634  
635 # check for an Open Document, IDML or EPUB file
636 2 my $mType = ExtractFile($et, $zip, 'mimetype');
637 2 ▶ if ($mType) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mType) 1 1 2
638 1 ($mime, $status) = $zip->contents($mType);
639 1 ▶ if (not $status and $mime =~ /([\x21-\xfe]+)/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $status and $mime =~ /([\x21-\xfe]+)/s) 1 0 1
Condition33%1/3
not $status and $mime =~ /([\x21-\xfe]+)/s
!ll&&!rl&&r
001
MC/DC0%0/2
not $status and $mime =~ /([\x21-\xfe]+)/s
not $status $mime =~ /([\x21-\xfe]+)/s
Truth table33%1/3
not(A) and B
A= not $statusB= $mime =~ /([\x21-\xfe]+)/s
ABresult
0X0
100
111
640 # clean up MIME type just in case (note that MIME is case insensitive)
641 1 $mime = lc $1;
642 1 ▶ $et->SetFileType($openDocType{$mime} || 'ZIP', $mime);
Condition50%1/2
$openDocType{$mime} || 'ZIP'
l!l
10
MC/DC0%0/1
$openDocType{$mime} || 'ZIP'
$openDocType{$mime}
Truth table50%1/2
A
A= $openDocType{$mime}
Aresult
11
00
643 1 ▶ $et->Warn("Unrecognized MIMEType $mime") unless $openDocType{$mime};
Branch: 1 branch
BranchTrueFalseTotal
unless $openDocType{$mime} 0 1 1
644 # extract Open Document metadata from "meta.xml"
645 1 my $meta = ExtractFile($et, $zip, 'meta.xml');
646 # IDML files have metadata in a different place (ref 6)
647 1 ▶ $meta or $meta = ExtractFile($et, $zip, 'META-INF/metadata.xml');
Branch: 1 branch
BranchTrueFalseTotal
$meta or $meta = &ExtractFile($et, $zip, "META-INF/metadata.xml") 1 0 1
648 1 ▶ if ($meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta) 1 0 1
649 1 ($buff, $status) = $zip->contents($meta);
650 1 ▶ unless ($status) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($status) 1 0 1
651 1 my %dirInfo = (
652 DirName => 'XML',
653 DataPt => \$buff,
654 DirLen => length $buff,
655 DataLen => length $buff,
656 );
657 # (avoid structure warnings when copying from XML)
658 1 my $oldWarn = $$et{NO_STRUCT_WARN};
659 1 $$et{NO_STRUCT_WARN} = 1;
660 1 $et->ProcessDirectory(\%dirInfo, GetTagTable('Image::ExifTool::XMP::Main'));
661 1 $$et{NO_STRUCT_WARN} = $oldWarn;
662 }
663 }
664 # process rootfile of EPUB container if applicable
665 1 for (;;) {
666 1 ▶ last if $meta and $mime ne 'application/epub+zip';
Branch: 1 branch
BranchTrueFalseTotal
if $meta and $mime ne "application/epub+zip" 1 0 1
Condition33%1/3
$meta and $mime ne "application/epub+zip"
!ll&&!rl&&r
001
MC/DC0%0/2
$meta and $mime ne "application/epub+zip"
$meta $mime ne "application/epub+zip"
Truth table33%1/3
A and B
A= $metaB= $mime ne "application/epub+zip"
ABresult
0X0
100
111
667 0 my $container = ExtractFile($et, $zip, 'META-INF/container.xml');
668 0 ($buff, $status) = $zip->contents($container);
669 0 ▶ last if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 0 0 0
670 0 ▶ $buff =~ /<rootfile\s+[^>]*?\bfull-path=(['"])(.*?)\1/s or last;
Branch: 1 branch
BranchTrueFalseTotal
$buff =~ /<rootfile\s+[^>]*?\bfull-path=(['"])(.*?)\1/s or last 0 0 0
671 # load the rootfile data (OPF extension; contains XML metadata)
672 0 ▶ my $meta2 = $zip->memberNamed($2) or last;
Branch: 1 branch
BranchTrueFalseTotal
my $meta2 = $zip->memberNamed($2) or last 0 0 0
673 0 $meta = $meta2;
674 0 ($buff, $status) = $zip->contents($meta);
675 0 ▶ last if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 0 0 0
676 # use opf:event to generate more meaningful tag names for dc:date
677 0 ▶ while ($buff =~ s{<dc:date opf:event="(\w+)">([^<]+)</dc:date>}{<dc:${1}Date>$2</dc:${1}Date>}s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ s[<dc:date opf:event="(\w+)">([^<]+)</dc:date>][<dc:$1Date>$2</dc:$1Date>]s) 0 0 0
678 0 my $dcTable = GetTagTable('Image::ExifTool::XMP::dc');
679 0 my $tag = "${1}Date";
680 AddTagToTable($dcTable, $tag, {
681 Name => ucfirst $tag,
682 Groups => { 2 => 'Time' },
683 List => 'Seq',
684 %Image::ExifTool::XMP::dateTimeInfo
685 0 ▶ }) unless $$dcTable{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless $dcTable->{$tag} 0 0 0
686 }
687 0 my %dirInfo = (
688 DataPt => \$buff,
689 DirLen => length $buff,
690 DataLen => length $buff,
691 IgnoreProp => { 'package' => 1, metadata => 1 },
692 );
693 # (avoid structure warnings when copying from XML)
694 0 my $oldWarn = $$et{NO_STRUCT_WARN};
695 0 $$et{NO_STRUCT_WARN} = 1;
696 0 $et->ProcessDirectory(\%dirInfo, GetTagTable('Image::ExifTool::XMP::XML'));
697 0 $$et{NO_STRUCT_WARN} = $oldWarn;
698 0 last;
699 }
700 1 ▶ if ($openDocType{$mime} or $meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($openDocType{$mime} or $meta) 1 0 1
Condition33%1/3
$openDocType{$mime} or $meta
l!l&&r!l&&!r
100
MC/DC0%0/2
$openDocType{$mime} or $meta
$openDocType{$mime} $meta
Truth table33%1/3
A or B
A= $openDocType{$mime}B= $meta
ABresult
1X1
011
000
701 # extract preview image(s) from "Thumbnails" directory if they exist
702 1 my $type;
703 1 my %tag = ( jpg => 'PreviewImage', png => 'PreviewPNG' );
704 1 foreach $type ('jpg', 'png') {
705 2 my $thumb = ExtractFile($et, $zip, "Thumbnails/thumbnail.$type");
706 2 ▶ next unless $thumb;
Branch: 1 branch
BranchTrueFalseTotal
unless $thumb 1 1 2
707 1 ($buff, $status) = $zip->contents($thumb);
708 1 ▶ $et->FoundTag($tag{$type}, $buff) unless $status;
Branch: 1 branch
BranchTrueFalseTotal
unless $status 1 0 1
709 }
710 1 last; # all done since we recognized the MIME type or found metadata
711 }
712 # continue on to list ZIP contents...
713 }
714 }
715  
716 # otherwise just extract general ZIP information
717 1 $et->SetFileType();
718 1 @members = $zip->members();
719 1 my ($member, $iWorkType);
720 # special files to extract
721 1 my %extract = (
722 'meta.json' => 1,
723 'previews/preview.png' => 'PreviewPNG',
724 'preview.jpg' => 'PreviewImage', # (iWork 2013 files)
725 'preview-web.jpg' => 'OtherImage', # (iWork 2013 files)
726 'preview-micro.jpg' => 'ThumbnailImage', # (iWork 2013 files)
727 'QuickLook/Thumbnail.jpg' => 'ThumbnailImage', # (iWork 2009 files)
728 'QuickLook/Preview.pdf' => 'PreviewPDF', # (iWork 2009 files)
729 );
730 1 foreach $member (@members) {
731 1 $$et{DOC_NUM} = ++$docNum;
732 1 HandleMember($et, $member, $tagTablePtr);
733 1 my $file = $member->fileName();
734 # extract things from Sketch files
735 1 ▶ if ($extract{$file}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($extract{$file}) { } 0 1 1
elsif ($file eq 'Index/Document.iwa' and not $iWorkType) { } 0 1 1
elsif ($iWorkFile{$file}) { } 0 1 1
736 0 ($buff, $status) = $zip->contents($member);
737 0 ▶ $status and $et->Warn("Error extracting $file"), next;
Branch: 1 branch
BranchTrueFalseTotal
$status and $et->Warn("Error extracting $file"), next 0 0 0
738 0 ▶ if ($file eq 'meta.json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file eq 'meta.json') { } 0 0 0
739 0 $et->ExtractInfo(\$buff, { ReEntry => 1 });
740 0 ▶ if ($$et{VALUE}{App} and $$et{VALUE}{App} =~ /sketch/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"VALUE"}{"App"} and $et->{"VALUE"}{"App"} =~ /sketch/i) 0 0 0
Condition0%0/3
$et->{"VALUE"}{"App"} and $et->{"VALUE"}{"App"} =~ /sketch/i
!ll&&!rl&&r
000
MC/DC0%0/2
$et->{"VALUE"}{"App"} and $et->{"VALUE"}{"App"} =~ /sketch/i
$et->{"VALUE"}{"App"} $et->{"VALUE"}{"App"} =~ /sketch/i
Truth table0%0/3
A and B
A= $et->{"VALUE"}{"App"}B= $et->{"VALUE"}{"App"} =~ /sketch/i
ABresult
0X0
100
111
741 0 $et->OverrideFileType('SKETCH');
742 }
743 } else {
744 0 $et->FoundTag($extract{$file} => $buff);
745 }
746 ▶ } elsif ($file eq 'Index/Document.iwa' and not $iWorkType) {
Condition33%1/3
$file eq "Index/Document.iwa" and not $iWorkType
!ll&&!rl&&r
100
MC/DC0%0/2
$file eq "Index/Document.iwa" and not $iWorkType
$file eq "Index/Document.iwa" not $iWorkType
Truth table33%1/3
A and not(B)
A= $file eq "Index/Document.iwa"B= not $iWorkType
ABresult
0X0
100
111
747 0 ▶ my $type = $iWorkType{$$et{FILE_EXT} || ''};
Condition0%0/2
$et->{'FILE_EXT'} || ''
l!l
00
MC/DC0%0/1
$et->{'FILE_EXT'} || ''
$et->{'FILE_EXT'}
Truth table0%0/2
A
A= $et->{'FILE_EXT'}
Aresult
11
00
748 0 ▶ $iWorkType = $type || 'PAGES';
Condition0%0/2
$type || 'PAGES'
l!l
00
MC/DC0%0/1
$type || 'PAGES'
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
749 } elsif ($iWorkFile{$file}) {
750 0 $iWorkType = $iWorkFile{$file};
751 }
752 }
753 1 ▶ $et->OverrideFileType($iWorkType) if $iWorkType;
Branch: 1 branch
BranchTrueFalseTotal
if $iWorkType 0 1 1
754 1 last;
755 }
756 # all done if we processed this using Archive::Zip
757 5 ▶ if ($zip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip) 5 0 5
758 5 delete $$dirInfo{ZIP};
759 5 delete $$et{DOC_NUM};
760 5 ▶ if ($docNum > 1 and not $et->Options('Duplicates')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($docNum > 1 and not $et->Options("Duplicates")) 0 5 5
Condition33%1/3
$docNum > 1 and not $et->Options("Duplicates")
!ll&&!rl&&r
500
MC/DC0%0/2
$docNum > 1 and not $et->Options("Duplicates")
$docNum > 1 not $et->Options("Duplicates")
Truth table33%1/3
A and not(B)
A= $docNum > 1B= not $et->Options("Duplicates")
ABresult
0X0
100
111
761 0 $et->Warn("Use the Duplicates option to extract tags for all $docNum files", 1);
762 }
763 5 return 1;
764 }
765 #
766 # process the ZIP file by hand (funny, but this seems easier than using Archive::Zip)
767 #
768 0 $et->VPrint(1, " -- processing as binary data --\n");
769 0 $raf->Seek(30, 0);
770 0 $et->SetFileType();
771 0 SetByteOrder('II');
772  
773 # A. Local file header:
774 # local file header signature 0) 4 bytes (0x04034b50)
775 # version needed to extract 4) 2 bytes
776 # general purpose bit flag 6) 2 bytes
777 # compression method 8) 2 bytes
778 # last mod file time 10) 2 bytes
779 # last mod file date 12) 2 bytes
780 # crc-32 14) 4 bytes
781 # compressed size 18) 4 bytes
782 # uncompressed size 22) 4 bytes
783 # file name length 26) 2 bytes
784 # extra field length 28) 2 bytes
785 0 for (;;) {
786 0 my $len = Get16u(\$buff, 26) + Get16u(\$buff, 28);
787 0 ▶ $raf->Read($buf2, $len) == $len or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buf2, $len) == $len or last 0 0 0
788  
789 0 $$et{DOC_NUM} = ++$docNum;
790 0 $buff .= $buf2;
791 0 my %dirInfo = (
792 DataPt => \$buff,
793 DataPos => $raf->Tell() - 30 - $len,
794 DataLen => 30 + $len,
795 DirStart => 0,
796 DirLen => 30 + $len,
797 MixedTags => 1, # (to ignore FileComment tag)
798 );
799 0 $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
800 0 my $flags = Get16u(\$buff, 6);
801 0 ▶ if ($flags & 0x08) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 8) 0 0 0
802 # we don't yet support skipping stream mode data
803 # (when this happens, the CRC, compressed size and uncompressed
804 # sizes are set to 0 in the header. Instead, they are stored
805 # after the compressed data with an optional header of 0x08074b50)
806 0 $et->Warn('Stream mode data encountered, file list may be incomplete');
807 0 last;
808 }
809 0 $len = Get32u(\$buff, 18); # file data length
810 0 ▶ $raf->Seek($len, 1) or last; # skip file data
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($len, 1) or last 0 0 0
811 0 ▶ $raf->Read($buff, 30) == 30 and $buff =~ /^PK\x03\x04/ or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 30) == 30 and $buff =~ /^PK\x03\x04/ or last 0 0 0
Condition0%0/3
$raf->Read($buff, 30) == 30 and $buff =~ /^PK\x03\x04/
!ll&&!rl&&r
000
MC/DC0%0/2
$raf->Read($buff, 30) == 30 and $buff =~ /^PK\x03\x04/
$raf->Read($buff, 30) == 30 $buff =~ /^PK\x03\x04/
Truth table0%0/3
A and B
A= $raf->Read($buff, 30) == 30B= $buff =~ /^PK\x03\x04/
ABresult
0X0
100
111
812 }
813 0 delete $$et{DOC_NUM};
814 0 ▶ if ($docNum > 1 and not $et->Options('Duplicates')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($docNum > 1 and not $et->Options("Duplicates")) 0 0 0
Condition0%0/3
$docNum > 1 and not $et->Options("Duplicates")
!ll&&!rl&&r
000
MC/DC0%0/2
$docNum > 1 and not $et->Options("Duplicates")
$docNum > 1 not $et->Options("Duplicates")
Truth table0%0/3
A and not(B)
A= $docNum > 1B= not $et->Options("Duplicates")
ABresult
0X0
100
111
815 0 $et->Warn("Use the Duplicates option to extract tags for all $docNum files", 1);
816 }
817 0 return 1;
818 }
819  
820 1 1; # end
821  
822 __END__
« Image/ExifTool/FlashPix.pm ↑ Summary Image/ExifTool/XMP.pm »