Image/ExifTool/MacOS.pm

filter: Statementstmt 33.7% 86 / 255 Branchbran 16.8% 26 / 154 Conditioncond 22.6% 12 / 53 MC/DCmcdc 6.4% 2 / 31 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 9 totaltotal 25.6% 132 / 514 CC 98 SCAR 60.6
CC
98
Cov
27%
SetMacOSTags
1056.0
ExtractMDItemTags
380.0
ExtractXAttrTags
306.0
CRAP 428.1
« Image/ExifTool/Validate.pm ↑ Summary Image/ExifTool/Trailer.pm »
1 #------------------------------------------------------------------------------
2 # File: MacOS.pm
3 #
4 # Description: Read/write MacOS system tags
5 #
6 # Revisions: 2017/03/01 - P. Harvey Created
7 # 2020/10/13 - PH Added ability to read MacOS "._" files
8 #------------------------------------------------------------------------------
9  
10 package Image::ExifTool::MacOS;
11 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 43 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 43 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 43 $VERSION = '1.15';
16  
17 sub MDItemLocalTime($);
18 sub ProcessATTR($$$);
19  
20 43 my %mdDateInfo = (
21 ValueConv => \&MDItemLocalTime,
22 PrintConv => '$self->ConvertDateTime($val)',
23 );
24  
25 43 my %delXAttr = (
26 XAttrQuarantine => 'com.apple.quarantine',
27 XAttrMDItemWhereFroms => 'com.apple.metadata:kMDItemWhereFroms',
28 );
29  
30 # Information decoded from Mac OS sidecar files
31 43 %Image::ExifTool::MacOS::Main = (
32 GROUPS => { 0 => 'File', 1 => 'MacOS' },
33 NOTES => q{
34 Note that on some filesystems, MacOS creates sidecar files with names that
35 begin with "._". ExifTool will read these files if specified, and extract
36 the information listed in the following table without the need for extra
37 options, but these files are not writable directly.
38 },
39 2 => {
40 Name => 'RSRC',
41 SubDirectory => { TagTable => 'Image::ExifTool::RSRC::Main' },
42 },
43 9 => {
44 Name => 'ATTR',
45 SubDirectory => {
46 TagTable => 'Image::ExifTool::MacOS::XAttr',
47 ProcessProc => \&ProcessATTR,
48 },
49 },
50 );
51  
52 # "mdls" tags (ref PH)
53 43 %Image::ExifTool::MacOS::MDItem = (
54 WRITE_PROC => \&Image::ExifTool::DummyWriteProc,
55 VARS => { ID_FMT => 'none' },
56 GROUPS => { 0 => 'File', 1 => 'MacOS', 2 => 'Other' },
57 NOTES => q{
58 MDItem tags are extracted using the "mdls" utility. They are extracted if
59 any "MDItem*" tag or the MacOS group is specifically requested, or by
60 setting the API L<MDItemTags|../ExifTool.html#MDItemTags> option to 1 or the API L<RequestAll|../ExifTool.html#RequestAll> option to 2 or
61 higher. Note that these tags do not necessarily reflect the current
62 metadata of a file -- it may take some time for the MacOS mdworker daemon to
63 index the file after a metadata change.
64 },
65 MDItemFinderComment => {
66 Writable => 1,
67 WritePseudo => 1,
68 Protected => 1, # (all writable pseudo tags must be protected)
69 },
70 MDItemFSLabel => {
71 Writable => 1,
72 WritePseudo => 1,
73 Protected => 1, # (all writable pseudo tags must be protected)
74 WriteCheck => '$val =~ /^[0-7]$/ ? undef : "Not an integer in the range 0-7"',
75 PrintConv => {
76 0 => '0 (none)',
77 1 => '1 (Gray)',
78 2 => '2 (Green)',
79 3 => '3 (Purple)',
80 4 => '4 (Blue)',
81 5 => '5 (Yellow)',
82 6 => '6 (Red)',
83 7 => '7 (Orange)',
84 },
85 },
86 MDItemFSCreationDate => {
87 Writable => 1,
88 WritePseudo => 1,
89 DelCheck => q{"Can't delete"},
90 Protected => 1, # (all writable pseudo tags must be protected)
91 Shift => 'Time', # (but not supported yet)
92 Notes => q{
93 file creation date. Requires "setfile" for writing. Note that when
94 reading, it may take a few seconds after writing a file before this value
95 reflects the change. However, L<FileCreateDate|Extra.html> is updated immediately
96 },
97 Groups => { 2 => 'Time' },
98 ValueConv => \&MDItemLocalTime,
99 ValueConvInv => '$val',
100 PrintConv => '$self->ConvertDateTime($val)',
101 PrintConvInv => '$self->InverseDateTime($val)',
102 },
103 MDItemAcquisitionMake => { Groups => { 2 => 'Camera' } },
104 MDItemAcquisitionModel => { Groups => { 2 => 'Camera' } },
105 MDItemAltitude => { Groups => { 2 => 'Location' } },
106 MDItemAperture => { Groups => { 2 => 'Camera' } },
107 MDItemAudioBitRate => { Groups => { 2 => 'Audio' } },
108 MDItemAudioChannelCount => { Groups => { 2 => 'Audio' } },
109 MDItemAuthors => { Groups => { 2 => 'Author' } },
110 MDItemBitsPerSample => { Groups => { 2 => 'Image' } },
111 MDItemCity => { Groups => { 2 => 'Location' } },
112 MDItemCodecs => { },
113 MDItemColorSpace => { Groups => { 2 => 'Image' } },
114 MDItemComment => { },
115 MDItemContentCreationDate => { Groups => { 2 => 'Time' }, %mdDateInfo },
116 MDItemContentCreationDateRanking => { Groups => { 2 => 'Time' }, %mdDateInfo },
117 MDItemContentModificationDate => { Groups => { 2 => 'Time' }, %mdDateInfo },
118 MDItemContentType => { },
119 MDItemContentTypeTree => { },
120 MDItemContributors => { },
121 MDItemCopyright => { Groups => { 2 => 'Author' } },
122 MDItemCountry => { Groups => { 2 => 'Location' } },
123 MDItemCreator => { Groups => { 2 => 'Document' } },
124 MDItemDateAdded => { Groups => { 2 => 'Time' }, %mdDateInfo },
125 MDItemDescription => { },
126 MDItemDisplayName => { },
127 MDItemDownloadedDate => { Groups => { 2 => 'Time' }, %mdDateInfo },
128 MDItemDurationSeconds => { PrintConv => 'ConvertDuration($val)' },
129 MDItemEncodingApplications => { },
130 MDItemEXIFGPSVersion => { Groups => { 2 => 'Location' }, Description => 'MD Item EXIF GPS Version' },
131 MDItemEXIFVersion => { },
132 MDItemExposureMode => { Groups => { 2 => 'Camera' } },
133 MDItemExposureProgram => { Groups => { 2 => 'Camera' } },
134 MDItemExposureTimeSeconds => { Groups => { 2 => 'Camera' } },
135 MDItemFlashOnOff => { Groups => { 2 => 'Camera' } },
136 MDItemFNumber => { Groups => { 2 => 'Camera' } },
137 MDItemFocalLength => { Groups => { 2 => 'Camera' } },
138 MDItemFSContentChangeDate => { Groups => { 2 => 'Time' }, %mdDateInfo },
139 MDItemFSCreatorCode => { Groups => { 2 => 'Author' } },
140 MDItemFSFinderFlags => { },
141 MDItemFSHasCustomIcon => { },
142 MDItemFSInvisible => { },
143 MDItemFSIsExtensionHidden => { },
144 MDItemFSIsStationery => { },
145 MDItemFSName => { },
146 MDItemFSNodeCount => { },
147 MDItemFSOwnerGroupID => { },
148 MDItemFSOwnerUserID => { },
149 MDItemFSSize => { },
150 MDItemFSTypeCode => { },
151 MDItemGPSDateStamp => { Groups => { 2 => 'Time' } },
152 MDItemGPSStatus => { Groups => { 2 => 'Location' } },
153 MDItemGPSTrack => { Groups => { 2 => 'Location' } },
154 MDItemHasAlphaChannel => { Groups => { 2 => 'Image' } },
155 MDItemImageDirection => { Groups => { 2 => 'Location' } },
156 MDItemInterestingDateRanking => { Groups => { 2 => 'Time' }, %mdDateInfo },
157 MDItemISOSpeed => { Groups => { 2 => 'Camera' } },
158 MDItemKeywords => { },
159 MDItemKind => { },
160 MDItemLastUsedDate => { Groups => { 2 => 'Time' }, %mdDateInfo },
161 MDItemLastUsedDate_Ranking => { },
162 MDItemLatitude => { Groups => { 2 => 'Location' } },
163 MDItemLensModel => { },
164 MDItemLogicalSize => { },
165 MDItemLongitude => { Groups => { 2 => 'Location' } },
166 MDItemMediaTypes => { },
167 MDItemNumberOfPages => { },
168 MDItemOrientation => { Groups => { 2 => 'Image' } },
169 MDItemOriginApplicationIdentifier => { },
170 MDItemOriginMessageID => { },
171 MDItemOriginSenderDisplayName => { },
172 MDItemOriginSenderHandle => { },
173 MDItemOriginSubject => { },
174 MDItemPageHeight => { Groups => { 2 => 'Image' } },
175 MDItemPageWidth => { Groups => { 2 => 'Image' } },
176 MDItemPhysicalSize => { Groups => { 2 => 'Image' } },
177 MDItemPixelCount => { Groups => { 2 => 'Image' } },
178 MDItemPixelHeight => { Groups => { 2 => 'Image' } },
179 MDItemPixelWidth => { Groups => { 2 => 'Image' } },
180 MDItemProfileName => { Groups => { 2 => 'Image' } },
181 MDItemRedEyeOnOff => { Groups => { 2 => 'Camera' } },
182 MDItemResolutionHeightDPI => { Groups => { 2 => 'Image' } },
183 MDItemResolutionWidthDPI => { Groups => { 2 => 'Image' } },
184 MDItemSecurityMethod => { },
185 MDItemSpeed => { Groups => { 2 => 'Location' } },
186 MDItemStateOrProvince => { Groups => { 2 => 'Location' } },
187 MDItemStreamable => { },
188 MDItemTimestamp => { Groups => { 2 => 'Time' } }, # (time only)
189 MDItemTitle => { },
190 MDItemTotalBitRate => { },
191 MDItemUseCount => { },
192 MDItemUsedDates => { Groups => { 2 => 'Time' }, %mdDateInfo },
193 MDItemUserDownloadedDate => { Groups => { 2 => 'Time' }, %mdDateInfo },
194 MDItemUserDownloadedUserHandle=> { },
195 MDItemUserSharedReceivedDate => { },
196 MDItemUserSharedReceivedRecipient => { },
197 MDItemUserSharedReceivedRecipientHandle => { },
198 MDItemUserSharedReceivedSender=> { },
199 MDItemUserSharedReceivedSenderHandle => { },
200 MDItemUserSharedReceivedTransport => { },
201 MDItemUserTags => {
202 List => 1,
203 Writable => 1,
204 WritePseudo => 1,
205 Protected => 1, # (all writable pseudo tags must be protected)
206 Notes => q{
207 requires "tag" utility for writing -- install with "brew install tag". Note
208 that user tags may not contain a comma, and that duplicate user tags will
209 not be written
210 },
211 },
212 MDItemVersion => { },
213 MDItemVideoBitRate => { Groups => { 2 => 'Video' } },
214 MDItemWhereFroms => { },
215 MDItemWhiteBalance => { Groups => { 2 => 'Image' } },
216 # tags used by Apple Mail on .emlx files
217 com_apple_mail_dateReceived => { Name => 'AppleMailDateReceived', Groups => { 2 => 'Time' }, %mdDateInfo },
218 com_apple_mail_dateSent => { Name => 'AppleMailDateSent', Groups => { 2 => 'Time' }, %mdDateInfo },
219 com_apple_mail_flagged => { Name => 'AppleMailFlagged' },
220 com_apple_mail_messageID => { Name => 'AppleMailMessageID' },
221 com_apple_mail_priority => { Name => 'AppleMailPriority' },
222 com_apple_mail_read => { Name => 'AppleMailRead' },
223 com_apple_mail_repliedTo => { Name => 'AppleMailRepliedTo' },
224 com_apple_mail_isRemoteAttachment => { Name => 'AppleMailIsRemoteAttachment' },
225 MDItemAccountHandles => { },
226 MDItemAccountIdentifier => { },
227 MDItemAuthorEmailAddresses => { },
228 MDItemBundleIdentifier => { },
229 MDItemContentCreationDate_Ranking=>{Groups=> { 2 => 'Time' }, %mdDateInfo },
230 MDItemDateAdded_Ranking => { Groups => { 2 => 'Time' }, %mdDateInfo },
231 MDItemEmailConversationID => { },
232 MDItemIdentifier => { },
233 MDItemInterestingDate_Ranking => { Groups => { 2 => 'Time' }, %mdDateInfo },
234 MDItemIsApplicationManaged => { },
235 MDItemIsExistingThread => { },
236 MDItemIsLikelyJunk => { },
237 MDItemMailboxes => { },
238 MDItemMailDateReceived_Ranking=> { Groups => { 2 => 'Time' }, %mdDateInfo },
239 MDItemPrimaryRecipientEmailAddresses => { },
240 MDItemRecipients => { },
241 MDItemSubject => { },
242 );
243  
244 # "xattr" tags
245 43 %Image::ExifTool::MacOS::XAttr = (
246 WRITE_PROC => \&Image::ExifTool::DummyWriteProc,
247 GROUPS => { 0 => 'File', 1 => 'MacOS', 2 => 'Other' },
248 VARS => { ID_FMT => 'none' }, # (id's are too long)
249 NOTES => q{
250 XAttr tags are extracted using the "xattr" utility. They are extracted if
251 any "XAttr*" tag or the MacOS group is specifically requested, or by setting
252 the API L<XAttrTags|../ExifTool.html#XAttrTags> option to 1 or the API L<RequestAll|../ExifTool.html#RequestAll> option to 2 or higher.
253 And they are extracted by default from MacOS "._" files when reading
254 these files directly.
255 },
256 'com.apple.FinderInfo' => {
257 Name => 'XAttrFinderInfo',
258 ConvertBinary => 1,
259 # ref https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-9A581/Finder.h
260 ValueConv => q{
261 my @a = unpack('a4a4n3x10nx2N', $$val);
262 tr/\0//d, $_="'${_}'" foreach @a[0,1];
263 return "@a";
264 },
265 PrintConv => q{
266 $val =~ s/^('.*?') ('.*?') //s or return $val;
267 my ($type, $creator) = ($1, $2);
268 my ($flags, $y, $x, $exFlags, $putAway) = split ' ', $val;
269 my $label = ($flags >> 1) & 0x07;
270 my $flags = DecodeBits((($exFlags<<16) | $flags) & 0xfff1, {
271 0 => 'OnDesk',
272 6 => 'Shared',
273 7 => 'HasNoInits',
274 8 => 'Inited',
275 10 => 'CustomIcon',
276 11 => 'Stationery',
277 12 => 'NameLocked',
278 13 => 'HasBundle',
279 14 => 'Invisible',
280 15 => 'Alias',
281 # extended flags
282 22 => 'HasRoutingInfo',
283 23 => 'ObjectBusy',
284 24 => 'CustomBadge',
285 31 => 'ExtendedFlagsValid',
286 });
287 my $str = "Type=$type Creator=$creator Flags=$flags Label=$label Pos=($x,$y)";
288 $str .= " Putaway=$putAway" if $putAway;
289 return $str;
290 },
291 },
292 'com.apple.quarantine' => {
293 Name => 'XAttrQuarantine',
294 Writable => 1,
295 WritePseudo => 1,
296 WriteCheck => '"May only delete this tag"',
297 Protected => 1,
298 Notes => q{
299 quarantine information for files downloaded from the internet. May only be
300 deleted when writing
301 },
302 # ($a[1] is the time when the quarantine tag was set)
303 PrintConv => q{
304 my @a = split /;/, $val;
305 $a[0] = 'Flags=' . $a[0];
306 $a[1] = 'set at ' . ConvertUnixTime(hex $a[1]);
307 $a[2] = 'by ' . $a[2];
308 return join ' ', @a;
309 },
310 PrintConvInv => '$val',
311 },
312 'com.apple.metadata:com_apple_mail_dateReceived' => {
313 Name => 'XAttrAppleMailDateReceived',
314 Groups => { 2 => 'Time' },
315 },
316 'com.apple.metadata:com_apple_mail_dateSent' => {
317 Name => 'XAttrAppleMailDateSent',
318 Groups => { 2 => 'Time' },
319 },
320 'com.apple.metadata:com_apple_mail_isRemoteAttachment' => {
321 Name => 'XAttrAppleMailIsRemoteAttachment',
322 },
323 'com.apple.metadata:kMDItemDownloadedDate' => {
324 Name => 'XAttrMDItemDownloadedDate',
325 Groups => { 2 => 'Time' },
326 },
327 'com.apple.metadata:kMDItemFinderComment' => { Name => 'XAttrMDItemFinderComment' },
328 'com.apple.metadata:kMDItemWhereFroms' => {
329 Name => 'XAttrMDItemWhereFroms',
330 Writable => 1,
331 WritePseudo => 1,
332 WriteCheck => '"May only delete this tag"',
333 Protected => 1,
334 Notes => q{
335 information about where the file came from. May only be deleted when
336 writing
337 },
338 },
339 'com.apple.metadata:kMDLabel' => { Name => 'XAttrMDLabel', Binary => 1 },
340 'com.apple.ResourceFork' => { Name => 'XAttrResourceFork', Binary => 1 },
341 'com.apple.lastuseddate#PS' => {
342 Name => 'XAttrLastUsedDate',
343 Groups => { 2 => 'Time' },
344 # (first 4 bytes are date/time. Not sure what remaining 12 bytes are for)
345 RawConv => 'ConvertUnixTime(unpack("V",$$val))',
346 PrintConv => '$self->ConvertDateTime($val)',
347 },
348 );
349  
350 #------------------------------------------------------------------------------
351 # Convert OS MDItem time string to standard EXIF-formatted local time
352 # Inputs: 0) time string (eg. "2017-02-21 17:21:43 +0000")
353 # Returns: EXIF-formatted local time string with timezone
354 sub MDItemLocalTime($)
355 0 ▶{
Subroutine MDItemLocalTime: not called CC=3 SCAR=24.8
Pod undocumented
356 0 my $val = shift;
357 0 $val =~ tr/-/:/;
358 0 $val =~ s/ ?([-+]\d{2}):?(\d{2})/$1:$2/;
359 # convert from UTC to local time
360 0 ▶ if ($val =~ /\+00:00$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /\+00:00$/) 0 0 0
361 0 my $time = Image::ExifTool::GetUnixTime($val);
362 0 ▶ $val = Image::ExifTool::ConvertUnixTime($time, 1) if $time;
Branch: 1 branch
BranchTrueFalseTotal
if $time 0 0 0
363 }
364 0 return $val;
365 }
366  
367 #------------------------------------------------------------------------------
368 # Call system command, redirecting all I/O to /dev/null
369 # Inputs: system arguments
370 # Returns: system return code
371 sub System
372 0 ▶{
Subroutine System: not called CC=1 SCAR=6.9
Pod undocumented
373 0 my ($oldout, $olderr);
374 0 open($oldout, ">&STDOUT");
375 0 open($olderr, ">&STDERR");
376 0 open(STDOUT, '>', '/dev/null');
377 0 open(STDERR, '>', '/dev/null');
378 0 my $result = system(@_);
379 0 open(STDOUT, ">&", $oldout);
380 0 open(STDERR, ">&", $olderr);
381 0 return $result;
382 }
383  
384 #------------------------------------------------------------------------------
385 # Set MacOS MDItem and XAttr tags from new tag values
386 # Inputs: 0) ExifTool ref, 1) file name, 2) list of tags to set
387 # Returns: 1=something was set OK, 0=didn't try, -1=error (and warning set)
388 # Notes: There may be errors even if 1 is returned
389 sub SetMacOSTags($$$)
390 0 ▶{
Subroutine SetMacOSTags: not called CC=32 SCAR=69.6
Pod undocumented
391 0 my ($et, $file, $setTags) = @_;
392 0 my $result = 0;
393 0 my $tag;
394  
395 0 foreach $tag (@$setTags) {
396 0 my ($nvHash, $attr, @cmd, $err, $silentErr);
397 0 my $val = $et->GetNewValue($tag, \$nvHash);
398 0 ▶ next unless $nvHash;
Branch: 1 branch
BranchTrueFalseTotal
unless $nvHash 0 0 0
399 0 my $overwrite = $et->IsOverwriting($nvHash);
400 0 ▶ unless ($$nvHash{TagInfo}{List}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($nvHash->{"TagInfo"}{"List"}) 0 0 0
401 0 ▶ next unless $overwrite;
Branch: 1 branch
BranchTrueFalseTotal
unless $overwrite 0 0 0
402 0 ▶ if ($overwrite < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overwrite < 0) 0 0 0
403 0 ▶ my $operation = $$nvHash{Shift} ? 'Shifting' : 'Conditional replacement';
Branch: 1 branch
BranchTrueFalseTotal
$nvHash->{'Shift'} ? : 0 0 0
404 0 $et->Warn("$operation of MacOS $tag not yet supported");
405 0 next;
406 }
407 }
408 0 ▶ if ($tag eq 'MDItemFSCreationDate' or $tag eq 'FileCreateDate') {
Branch: 3 branches
BranchTrueFalseTotal
if ($tag eq 'MDItemFSCreationDate' or $tag eq 'FileCreateDate') { } 0 0 0
elsif ($tag eq 'MDItemUserTags') { } 0 0 0
elsif ($delXAttr{$tag}) { } 0 0 0
Condition0%0/3
$tag eq "MDItemFSCreationDate" or $tag eq "FileCreateDate"
l!l&&r!l&&!r
000
MC/DC0%0/2
$tag eq "MDItemFSCreationDate" or $tag eq "FileCreateDate"
$tag eq "MDItemFSCreationDate" $tag eq "FileCreateDate"
Truth table0%0/3
A or B
A= $tag eq "MDItemFSCreationDate"B= $tag eq "FileCreateDate"
ABresult
1X1
011
000
409 # convert to local time if value has a time zone
410 0 ▶ if ($val =~ /[-+Z]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /[-+Z]/) 0 0 0
411 0 my $time = Image::ExifTool::GetUnixTime($val, 1);
412 0 ▶ $val = Image::ExifTool::ConvertUnixTime($time, 1) if $time;
Branch: 1 branch
BranchTrueFalseTotal
if $time 0 0 0
413 0 $val =~ s/[-+].*//; # remove time zone
414 }
415 0 $val =~ s{(\d{4}):(\d{2}):(\d{2})}{$2/$3/$1}; # reformat for setfile
416 0 push @cmd, '/usr/bin/setfile', '-d', $val, $file;
417 } elsif ($tag eq 'MDItemUserTags') {
418 # (tested with "tag" version 0.9.0)
419 0 my @vals = $et->GetNewValue($nvHash);
420 0 ▶ if ($overwrite < 0 and @{$$nvHash{DelValue}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overwrite < 0 and @{$nvHash->{"DelValue"};}) 0 0 0
Condition0%0/3
$overwrite < 0 and @{$nvHash->{"DelValue"};}
!ll&&!rl&&r
000
MC/DC0%0/2
$overwrite < 0 and @{$nvHash->{"DelValue"};}
$overwrite < 0 @{$nvHash->{"DelValue"};}
Truth table0%0/3
A and B
A= $overwrite < 0B= @{$nvHash->{"DelValue"};}
ABresult
0X0
100
111
421 # delete specified tags
422 0 my @dels = @{$$nvHash{DelValue}};
423 0 my $del = join ',', @dels;
424 0 $err = System('/usr/local/bin/tag', '-r', $del, $file);
425 0 ▶ unless ($err) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($err) 0 0 0
426 0 $et->VerboseValue("- $tag", $del);
427 0 $result = 1;
428 0 ▶ undef $err if @vals; # more to do if there are tags to add
Branch: 1 branch
BranchTrueFalseTotal
if @vals 0 0 0
429 }
430 }
431 0 ▶ unless (defined $err) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $err) 0 0 0
432 # add new tags, or overwrite or delete existing tags
433 0 ▶ my $opt = $overwrite > 0 ? '-s' : '-a';
Branch: 1 branch
BranchTrueFalseTotal
$overwrite > 0 ? : 0 0 0
434 0 ▶ $val = @vals ? join(',', @vals) : '';
Branch: 1 branch
BranchTrueFalseTotal
@vals ? : 0 0 0
435 0 push @cmd, '/usr/local/bin/tag', $opt, $val, $file;
436 0 ▶ $et->VPrint(1," - $tag = (all)\n") if $overwrite > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $overwrite > 0 0 0 0
437 0 ▶ undef $val if $val eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $val eq "" 0 0 0
438 }
439 } elsif ($delXAttr{$tag}) {
440 0 push @cmd, '/usr/bin/xattr', '-d', $delXAttr{$tag}, $file;
441 0 $silentErr = 256; # (will get this error if attribute doesn't exist)
442 } else {
443 0 my ($f, $v);
444 0 ($f = $file) =~ s/([\\"])/\\$1/g; # escape backslashes and quotes for AppleScript
445 0 ▶ if ($tag eq 'MDItemFinderComment') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'MDItemFinderComment') { } 0 0 0
446 # (write finder comment using osascript instead of xattr
447 # because it is more work to construct the necessary bplist)
448 0 ▶ $val = '' unless defined $val; # set to empty string instead of deleting
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
449 0 $v = $et->Encode($val, 'UTF8');
450 0 $v =~ s/([\\"])/\\$1/g;
451 0 $attr = 'comment';
452 } else { # $tag eq 'MDItemFSLabel'
453 0 ▶ $v = $val ? 8 - $val : 0; # convert from label to label index (0 for no label)
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 0 0 0
454 0 $attr = 'label index';
455 }
456 0 push @cmd, '/usr/bin/osascript', '-e', qq(set fp to POSIX file "$f" as alias),
457 '-e', qq(tell application "Finder" to set $attr of file fp to "$v");
458 }
459 0 ▶ $err = System(@cmd) if @cmd;
Branch: 1 branch
BranchTrueFalseTotal
if @cmd 0 0 0
460 0 ▶ if (not $err) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $err) { } 0 0 0
elsif (not $silentErr or $err != $silentErr) { } 0 0 0
461 0 ▶ $et->VerboseValue("+ $tag", $val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
462 0 $result = 1;
463 ▶ } elsif (not $silentErr or $err != $silentErr) {
Condition0%0/3
not $silentErr or $err != $silentErr
l!l&&r!l&&!r
000
MC/DC0%0/2
not $silentErr or $err != $silentErr
not $silentErr $err != $silentErr
Truth table0%0/3
not(A) or B
A= not $silentErrB= $err != $silentErr
ABresult
1X1
011
000
464 0 ▶ my $cmd = $cmd[0] || 'tag';
Condition0%0/2
$cmd[0] || 'tag'
l!l
00
MC/DC0%0/1
$cmd[0] || 'tag'
$cmd[0]
Truth table0%0/2
A
A= $cmd[0]
Aresult
11
00
465 0 $cmd =~ s(.*/)();
466 0 $et->Warn(qq{Error $err running "$cmd" to set $tag});
467 0 ▶ $result = -1 unless $result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
468 }
469 }
470 0 return $result;
471 }
472  
473 #------------------------------------------------------------------------------
474 # Extract MacOS metadata item tags
475 # Inputs: 0) ExifTool object ref, 1) file name
476 sub ExtractMDItemTags($$)
477 0 ▶{
Subroutine ExtractMDItemTags: not called CC=19 SCAR=59.4
Pod undocumented
478 0 local $_;
479 0 my ($et, $file) = @_;
480 0 my ($fn, $tag, $val, $tmp);
481  
482 0 ($fn = $file) =~ s/([`"\$\\])/\\$1/g; # escape necessary characters
483 0 $et->VPrint(0, '(running mdls)');
484 0 my @mdls = `/usr/bin/mdls "$fn" 2> /dev/null`; # get MacOS metadata
485 0 ▶ if ($? or not @mdls) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? or not @mdls) 0 0 0
Condition0%0/3
$? or not @mdls
l!l&&r!l&&!r
000
MC/DC0%0/2
$? or not @mdls
$? not @mdls
Truth table0%0/3
A or not(B)
A= $?B= not @mdls
ABresult
1X1
011
000
486 0 $et->Warn('Error running "mdls" to extract MDItem tags');
487 0 return;
488 }
489 0 my $tagTablePtr = GetTagTable('Image::ExifTool::MacOS::MDItem');
490 0 $$et{INDENT} .= '| ';
491 0 $et->VerboseDir('MDItem');
492 0 foreach (@mdls) {
493 0 chomp;
494 0 ▶ if (ref $val ne 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val ne 'ARRAY') { } 0 0 0
elsif ($_ eq ')') { } 0 0 0
495 0 ▶ s/^k?(\w+)\s*= // or next;
Branch: 1 branch
BranchTrueFalseTotal
s/^k?(\w+)\s*= // or next 0 0 0
496 0 $tag = $1;
497 0 ▶ $_ eq '(' and $val = [ ], next; # (start of a list)
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "(" and $val = [], next 0 0 0
498 0 ▶ $_ = '' if $_ eq '(null)';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "(null)" 0 0 0
499 0 ▶ s/^"// and s/"$//; # remove quotes if they exist
Branch: 1 branch
BranchTrueFalseTotal
s/^"// and s/"$// 0 0 0
500 0 $val = $_;
501 } elsif ($_ eq ')') { # (end of a list)
502 0 $_ = $$val[0];
503 0 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 0 0
504 } else {
505 # add item to list
506 0 s/^ //; # remove leading spaces
507 0 s/,$//; # remove trailing comma
508 0 ▶ $_ = '' if $_ eq '(null)';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "(null)" 0 0 0
509 0 ▶ s/^"// and s/"$//; # remove quotes if they exist
Branch: 1 branch
BranchTrueFalseTotal
s/^"// and s/"$// 0 0 0
510 0 s/\\"/"/g; # un-escape quotes
511 0 s/\\\\/\\/g; # un-escape backslashes
512 0 $_ = $et->Decode($_, 'UTF8');
513 0 push @$val, $_;
514 0 next;
515 }
516 # add to Extra tags if not done already
517 0 ▶ unless ($$tagTablePtr{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagTablePtr->{$tag}) 0 0 0
518 # check for a date/time format
519 0 my %tagInfo;
520 0 ▶ %tagInfo = (
Branch: 1 branch
BranchTrueFalseTotal
if /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/ 0 0 0
521 Groups => { 2 => 'Time' },
522 ValueConv => \&MDItemLocalTime,
523 PrintConv => '$self->ConvertDateTime($val)',
524 ) if /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/;
525 # change tags like "com_apple_mail_xxx" to "AppleMailXxx"
526 0 ($tmp = $tag) =~ s/^com_//; # remove leading "com_"
527 0 $tmp =~ s/_([a-z])/\u$1/g; # use CamelCase
528 0 $tagInfo{Name} = Image::ExifTool::MakeTagName($tmp);
529 0 ▶ $tagInfo{List} = 1 if ref $val eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val eq "ARRAY" 0 0 0
530 0 ▶ $tagInfo{Groups}{2} = 'Audio' if $tag =~ /Audio/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /Audio/ 0 0 0
531 0 ▶ $tagInfo{Groups}{2} = 'Author' if $tag =~ /(Copyright|Author)/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /(Copyright|Author)/ 0 0 0
532 0 $et->VPrint(0, " [adding $tag]\n");
533 0 AddTagToTable($tagTablePtr, $tag, \%tagInfo);
534 }
535 0 ▶ $val = $et->Decode($val, 'UTF8') unless ref $val;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $val 0 0 0
536 0 $et->HandleTag($tagTablePtr, $tag, $val);
537 0 undef $val;
538 }
539 0 $$et{INDENT} =~ s/\| $//;
540 }
541  
542 #------------------------------------------------------------------------------
543 # Read MacOS XAttr value
544 # Inputs: 0) ExifTool object ref, 1) file name
545 sub ReadXAttrValue($$$$)
546 8 ▶{
Subroutine ReadXAttrValue: called CC=11 SCAR=24.3
Pod undocumented
547 8 my ($et, $tagTablePtr, $tag, $val) = @_;
548 # add to our table if necessary
549 8 ▶ unless ($$tagTablePtr{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagTablePtr->{$tag}) 2 6 8
550 2 my $name;
551 # generate tag name from attribute name
552 2 ▶ if ($tag =~ /^com\.apple\.(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^com\.apple\.(.*)$/) { } 1 1 2
553 1 ($name = $1) =~ s/^metadata:_?k//;
554 1 $name =~ s/^metadata:(com_)?//;
555 } else {
556 1 $name = $tag;
557 }
558 2 $name =~ s/[.:_]([a-z])/\U$1/g;
559 2 $name = 'XAttr' . ucfirst $name;
560 2 my %tagInfo = ( Name => $name );
561 2 ▶ $tagInfo{Groups} = { 2 => 'Time' } if $tag=~/Date$/;
Branch: 1 branch
BranchTrueFalseTotal
if $tag =~ /Date$/ 0 2 2
562 2 $et->VPrint(0, " [adding $tag]\n");
563 2 AddTagToTable($tagTablePtr, $tag, \%tagInfo);
564 }
565 8 ▶ if ($val =~ /^bplist0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^bplist0/) 4 4 8
566 4 my %dirInfo = ( DataPt => \$val );
567 4 require Image::ExifTool::PLIST;
568 4 ▶ if (Image::ExifTool::PLIST::ProcessBinaryPLIST($et, \%dirInfo, $tagTablePtr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (Image::ExifTool::PLIST::ProcessBinaryPLIST($et, \%dirInfo, $tagTablePtr)) { } 4 0 4
569 4 ▶ return undef if ref $dirInfo{Value} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $dirInfo{"Value"} eq "HASH" 0 4 4
570 $val = $dirInfo{Value}
571 4 } else {
572 0 $et->Warn("Error decoding $$tagTablePtr{$tag}{Name}");
573 0 return undef;
574 }
575 }
576 8 ▶ if (not ref $val and ($val =~ /\0/ or length($val) > 200) or $tag eq 'XAttrMDLabel') {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $val and $val =~ /\0/ || length $val > 200 or $tag eq "XAttrMDLabel") 1 7 8
Condition77%7/9
not ref $val and $val =~ /\0/ || length $val > 200 or $tag eq "XAttrMDLabel"
l!l&&r!l&&!r
107
not ref $val and $val =~ /\0/ || length $val > 200
!ll&&!rl&&r
341
$val =~ /\0/ or length $val > 200
l!l&&r!l&&!r
104
MC/DC50%2/4
not ref $val and $val =~ /\0/ || length $val > 200 or $tag eq "XAttrMDLabel"
not ref $val $val =~ /\0/ length $val > 200 $tag eq "XAttrMDLabel"
Truth table50%3/6
not(A) and B or C or D
A= not ref $valB= $val =~ /\0/C= length $val > 200D= $tag eq "XAttrMDLabel"
ABCDresult
11XX1
101X1
0XX11
10011
0XX00
10000
577 1 my $buff = $val;
578 1 $val = \$buff;
579 }
580 8 return $val;
581 }
582  
583 #------------------------------------------------------------------------------
584 # Read MacOS extended attribute tags using 'xattr' utility
585 # Inputs: 0) ExifTool object ref, 1) file name
586 sub ExtractXAttrTags($$)
587 0 ▶{
Subroutine ExtractXAttrTags: not called CC=17 SCAR=57.2
Pod undocumented
588 0 local $_;
589 0 my ($et, $file) = @_;
590 0 my ($fn, $tag, $val, $warn);
591  
592 0 ($fn = $file) =~ s/([`"\$\\])/\\$1/g; # escape necessary characters
593 0 $et->VPrint(0, '(running xattr)');
594 0 my @xattr = `/usr/bin/xattr -lx "$fn" 2> /dev/null`; # get MacOS extended attributes
595 0 ▶ if ($? or not @xattr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? or not @xattr) 0 0 0
Condition0%0/3
$? or not @xattr
l!l&&r!l&&!r
000
MC/DC0%0/2
$? or not @xattr
$? not @xattr
Truth table0%0/3
A or not(B)
A= $?B= not @xattr
ABresult
1X1
011
000
596 0 ▶ $? and $et->Warn('Error running "xattr" to extract XAttr tags');
Branch: 1 branch
BranchTrueFalseTotal
$? and $et->Warn("Error running \"xattr\" to extract XAttr tags") 0 0 0
597 0 return;
598 }
599 0 my $tagTablePtr = GetTagTable('Image::ExifTool::MacOS::XAttr');
600 0 $$et{INDENT} .= '| ';
601 0 $et->VerboseDir('XAttr');
602 0 push @xattr, ''; # (for a list terminator)
603 0 foreach (@xattr) {
604 0 chomp;
605 0 ▶ if (s/^[\dA-Fa-f]{8}//) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^[\dA-Fa-f]{8}//) { } 0 0 0
elsif ($tag and defined $val) { } 0 0 0
606 0 ▶ $tag or $warn = 1, next;
Branch: 1 branch
BranchTrueFalseTotal
$tag or $warn = 1, next 0 0 0
607 0 s/\|.*//;
608 0 tr/ //d;
609 0 ▶ (/[^\dA-Fa-f]/ or length($_) & 1) and $warn = 2, next;
Branch: 1 branch
BranchTrueFalseTotal
/[^\dA-Fa-f]/ || length $_ & 1 and $warn = 2, next 0 0 0
Condition0%0/3
/[^\dA-Fa-f]/ or length $_ & 1
l!l&&r!l&&!r
000
MC/DC0%0/2
/[^\dA-Fa-f]/ or length $_ & 1
/[^\dA-Fa-f]/ length $_ & 1
Truth table0%0/3
A or B
A= /[^\dA-Fa-f]/B= length $_ & 1
ABresult
1X1
011
000
610 0 ▶ $val = '' unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
611 0 $val .= pack('H*', $_);
612 0 next;
613 ▶ } elsif ($tag and defined $val) {
Condition0%0/3
$tag and defined $val
!ll&&!rl&&r
000
MC/DC0%0/2
$tag and defined $val
$tag defined $val
Truth table0%0/3
A and B
A= $tagB= defined $val
ABresult
0X0
100
111
614 0 $val = ReadXAttrValue($et, $tagTablePtr, $tag, $val);
615 0 ▶ $et->HandleTag($tagTablePtr, $tag, $val) if defined $val;
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 0 0 0
616 0 undef $tag;
617 0 undef $val;
618 }
619 0 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
620 0 ▶ s/:$// or $warn = 3, next; # attribute name must have trailing ":"
Branch: 1 branch
BranchTrueFalseTotal
s/:$// or $warn = 3, next 0 0 0
621 0 ▶ defined $val and $warn = 4, undef $val;
Branch: 1 branch
BranchTrueFalseTotal
defined $val and $warn = 4, undef $val 0 0 0
622 # remove random ID after kMDLabel in tag ID
623 0 ($tag = $_) =~ s/^com.apple.metadata:kMDLabel_.*/com.apple.metadata:kMDLabel/s;
624 }
625 0 ▶ $warn and $et->Warn(qq{Error $warn parsing "xattr" output});
Branch: 1 branch
BranchTrueFalseTotal
$warn and $et->Warn(qq[Error $warn parsing "xattr" output]) 0 0 0
626 0 $$et{INDENT} =~ s/\| $//;
627 }
628  
629 #------------------------------------------------------------------------------
630 # Extract MacOS file creation date/time
631 # Inputs: 0) ExifTool object ref, 1) file name
632 sub GetFileCreateDate($$)
633 0 ▶{
Subroutine GetFileCreateDate: not called CC=4 SCAR=30.0
Pod undocumented
634 0 local $_;
635 0 my ($et, $file) = @_;
636 0 my ($fn, $tag, $val, $tmp);
637  
638 0 ($fn = $file) =~ s/([`"\$\\])/\\$1/g; # escape necessary characters
639 0 $et->VPrint(0, '(running stat)');
640 0 my $time = `/usr/bin/stat -f '%SB' -t '%Y:%m:%d %H:%M:%S%z' "$fn" 2> /dev/null`;
641 0 ▶ if ($? or not $time or $time !~ s/([-+]\d{2})(\d{2})\s*$/$1:$2/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? or not $time or not $time =~ s/([-+]\d{2})(\d{2})\s*$/$1:$2/) 0 0 0
Condition0%0/6
$? or not $time or not $time =~ s/([-+]\d{2})(\d{2})\s*$/$1:$2/
l!l&&r!l&&!r
000
$? or not $time
l!l&&r!l&&!r
000
MC/DC0%0/3
$? or not $time or not $time =~ s/([-+]\d{2})(\d{2})\s*$/$1:$2/
$? not $time not $time =~ s/([-+]\d{2})(\d{2})\s*$/$1:$2/
Truth table0%0/4
A or not(B) or not(C)
A= $?B= not $timeC= not $time =~ s/([-+]\d{2})(\d{2})\s*$/$1:$2/
ABCresult
1XX1
01X1
0011
0000
642 0 $et->Warn('Error running "stat" to extract FileCreateDate');
643 0 return;
644 }
645 0 $$et{SET_GROUP1} = 'MacOS';
646 0 $et->FoundTag(FileCreateDate => $time);
647 0 delete $$et{SET_GROUP1};
648 }
649  
650 #------------------------------------------------------------------------------
651 # Read ATTR metadata from "._" file
652 # Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) tag table ref
653 # Return: 1 on success
654 # (ref https://www.swiftforensics.com/2018/11/the-dot-underscore-file-format.html)
655 sub ProcessATTR($$$)
656 1 ▶{
Subroutine ProcessATTR: called CC=10 SCAR=24.4
Pod undocumented
657 1 my ($et, $dirInfo, $tagTablePtr) = @_;
658 1 my $dataPt = $$dirInfo{DataPt};
659 1 my $dataPos = $$dirInfo{DataPos};
660 1 my $dataLen = length $$dataPt;
661  
662 1 ▶ $dataLen >= 58 and $$dataPt =~ /^.{34}ATTR/s or $et->Warn('Invalid ATTR header'), return 0;
Branch: 1 branch
BranchTrueFalseTotal
$dataLen >= 58 and $$dataPt =~ /^.{34}ATTR/s or $et->Warn("Invalid ATTR header"), (return 0) 1 0 1
Condition33%1/3
$dataLen >= 58 and $$dataPt =~ /^.{34}ATTR/s
!ll&&!rl&&r
001
MC/DC0%0/2
$dataLen >= 58 and $$dataPt =~ /^.{34}ATTR/s
$dataLen >= 58 $$dataPt =~ /^.{34}ATTR/s
Truth table33%1/3
A and B
A= $dataLen >= 58B= $$dataPt =~ /^.{34}ATTR/s
ABresult
0X0
100
111
663 1 my $entries = Get32u($dataPt, 66);
664 1 $et->VerboseDir('ATTR', $entries);
665 # (Note: The RAF is not in $dirInfo because it would break RSRC reading --
666 # the RSCR block uses relative offsets, while the ATTR block uses absolute! grrr!)
667 1 my $raf = $$et{RAF};
668 1 my $pos = 70; # first entry is after ATTR header
669 1 my $i;
670 1 ▶ for ($i=0; $i<$entries; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $entries) 8 1 9
671 8 ▶ $pos + 12 > $dataLen and $et->Warn('Truncated ATTR entry'), last;
Branch: 1 branch
BranchTrueFalseTotal
$pos + 12 > $dataLen and $et->Warn("Truncated ATTR entry"), last 0 8 8
672 8 my $off = Get32u($dataPt, $pos);
673 8 my $len = Get32u($dataPt, $pos + 4);
674 8 my $n = Get8u($dataPt, $pos + 10); # number of characters in tag name
675 8 ▶ $pos + 11 + $n > $dataLen and $et->Warn('Truncated ATTR name'), last;
Branch: 1 branch
BranchTrueFalseTotal
$pos + 11 + $n > $dataLen and $et->Warn("Truncated ATTR name"), last 0 8 8
676 8 $off -= $dataPos; # convert to relative offset (grrr!)
677 8 ▶ $off < 0 or $off > $dataLen and $et->Warn('Invalid ATTR offset'), last;
Branch: 1 branch
BranchTrueFalseTotal
$off < 0 or $off > $dataLen and $et->Warn("Invalid ATTR offset"), last 0 8 8
Condition33%2/6
$off < 0 || $off > $dataLen && ($et->Warn('Invalid ATTR offset'), last)
l!l&&r!l&&!r
080
$off > $dataLen and $et->Warn("Invalid ATTR offset"), last
!ll&&!rl&&r
800
MC/DC0%0/3
$off < 0 || $off > $dataLen && ($et->Warn('Invalid ATTR offset'), last)
$off < 0 $off > $dataLen $et->Warn("Invalid ATTR offset"), last
Truth table0%0/4
A || B and C
A= $off < 0B= $off > $dataLenC= $et->Warn("Invalid ATTR offset"), last
ABCresult
1XX1
0111
00X0
0100
678 8 my $tag = substr($$dataPt, $pos + 11, $n);
679 8 $tag =~ s/\0+$//; # remove null terminator
680 # remove random ID after kMDLabel in tag ID
681 8 $tag =~ s/^com.apple.metadata:kMDLabel_.*/com.apple.metadata:kMDLabel/s;
682 8 ▶ $off + $len > $dataLen and $et->Warn('Truncated ATTR value'), last;
Branch: 1 branch
BranchTrueFalseTotal
$off + $len > $dataLen and $et->Warn("Truncated ATTR value"), last 0 8 8
683 8 my $val = ReadXAttrValue($et, $tagTablePtr, $tag, substr($$dataPt, $off, $len));
684 8 ▶ $et->HandleTag($tagTablePtr, $tag, $val,
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 8 0 8
685 DataPt => $dataPt,
686 DataPos => $dataPos,
687 Start => $off,
688 Size => $len,
689 ) if defined $val;
690 8 $pos += (11 + $n + 3) & -4; # step to next entry (on even 4-byte boundary)
691 }
692 1 return 1;
693 }
694  
695 #------------------------------------------------------------------------------
696 # Read information from a MacOS "._" sidecar file
697 # Inputs: 0) ExifTool ref, 1) dirInfo ref
698 # Returns: 1 on success, 0 if this wasn't a valid "._" file
699 # (ref https://www.swiftforensics.com/2018/11/the-dot-underscore-file-format.html)
700 sub ProcessMacOS($$)
701 1 ▶{
Subroutine ProcessMacOS: called CC=9 SCAR=23.0
Pod undocumented
702 1 my ($et, $dirInfo) = @_;
703 1 my $raf = $$dirInfo{RAF};
704 1 my ($hdr, $buff, $i);
705  
706 1 ▶ return 0 unless $raf->Read($hdr, 26) == 26 and $hdr =~ /^\0\x05\x16\x07\0(.)\0\0Mac OS X /s;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($hdr, 26) == 26 and $hdr =~ /^\0\x05\x16\x07\0(.)\0\0Mac OS X /s 0 1 1
Condition33%1/3
$raf->Read($hdr, 26) == 26 and $hdr =~ /^\0\x05\x16\x07\0(.)\0\0Mac OS X /s
!ll&&!rl&&r
001
MC/DC0%0/2
$raf->Read($hdr, 26) == 26 and $hdr =~ /^\0\x05\x16\x07\0(.)\0\0Mac OS X /s
$raf->Read($hdr, 26) == 26 $hdr =~ /^\0\x05\x16\x07\0(.)\0\0Mac OS X /s
Truth table33%1/3
A and B
A= $raf->Read($hdr, 26) == 26B= $hdr =~ /^\0\x05\x16\x07\0(.)\0\0Mac OS X /s
ABresult
0X0
100
111
707 1 my $ver = ord $1;
708 # (extension may be anything, so just echo back the incoming file extension if it exists)
709 1 $et->SetFileType(undef, undef, $$et{FILE_EXT});
710 1 ▶ $ver == 2 or $et->Warn("Unsupported file version $ver"), return 1;
Branch: 1 branch
BranchTrueFalseTotal
$ver == 2 or $et->Warn("Unsupported file version $ver"), (return 1) 1 0 1
711 1 SetByteOrder('MM');
712 1 my $tagTablePtr = GetTagTable('Image::ExifTool::MacOS::Main');
713 1 my $entries = Get16u(\$hdr, 0x18);
714 1 $et->VerboseDir('MacOS', $entries);
715 1 ▶ $raf->Read($hdr, $entries * 12) == $entries * 12 or $et->Warn('Truncated header'), return 1;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($hdr, $entries * 12) == $entries * 12 or $et->Warn("Truncated header"), (return 1) 1 0 1
716 1 ▶ for ($i=0; $i<$entries; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $entries) 2 1 3
717 2 my $pos = $i * 12;
718 2 my $tag = Get32u(\$hdr, $pos);
719 2 my $off = Get32u(\$hdr, $pos + 4);
720 2 my $len = Get32u(\$hdr, $pos + 8);
721 2 ▶ $len > 100000000 and $et->Warn('Record size too large'), last;
Branch: 1 branch
BranchTrueFalseTotal
$len > 100000000 and $et->Warn("Record size too large"), last 0 2 2
722 2 ▶ $raf->Seek($off,0) and $raf->Read($buff,$len) == $len or $et->Warn('Truncated record'), last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Seek($off, 0) and $raf->Read($buff, $len) == $len or $et->Warn("Truncated record"), last 2 0 2
Condition33%1/3
$raf->Seek($off, 0) and $raf->Read($buff, $len) == $len
!ll&&!rl&&r
002
MC/DC0%0/2
$raf->Seek($off, 0) and $raf->Read($buff, $len) == $len
$raf->Seek($off, 0) $raf->Read($buff, $len) == $len
Truth table33%1/3
A and B
A= $raf->Seek($off, 0)B= $raf->Read($buff, $len) == $len
ABresult
0X0
100
111
723 2 $et->HandleTag($tagTablePtr, $tag, undef, DataPt => \$buff, DataPos => $off, Index => $i);
724 }
725 1 return 1;
726 }
727  
728 43 1; # end
729  
730 __END__
« Image/ExifTool/Validate.pm ↑ Summary Image/ExifTool/Trailer.pm »