- Timestamp:
- 2021-02-26T19:39:51+13:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cpan/Image/ExifTool/RSRC.pm
r24107 r34921 15 15 use Image::ExifTool qw(:DataAccess :Utils); 16 16 17 $VERSION = '1.02'; 17 $VERSION = '1.09'; 18 19 sub ProcessRSRC($$); 18 20 19 21 # Information decoded from Mac OS resources 20 22 %Image::ExifTool::RSRC::Main = ( 21 23 GROUPS => { 2 => 'Document' }, 24 PROCESS_PROC => \&ProcessRSRC, 22 25 NOTES => q{ 23 Tags extracted from Mac OS resource files and DFONT files. These tags may 24 also be extracted from the resource fork of any file in OS X, either by 25 adding "/rsrc" to the filename to process the resource fork alone, or by 26 using the ExtractEmbedded (-ee) option to process the resource fork as a 27 sub-document of the main file. 26 Tags extracted from Mac OS resource files, DFONT files and "._" sidecar 27 files. These tags may also be extracted from the resource fork of any file 28 in OS X, either by adding "/..namedfork/rsrc" to the filename to process the 29 resource fork alone, or by using the L<ExtractEmbedded|../ExifTool.html#ExtractEmbedded> (-ee) option to process 30 the resource fork as a sub-document of the main file. When writing, 31 ExifTool preserves the Mac OS resource fork by default, but it may deleted 32 with C<-rsrc:all=> on the command line. 28 33 }, 29 34 '8BIM' => { … … 34 39 Name => 'Font', 35 40 SubDirectory => { TagTable => 'Image::ExifTool::Font::Name' }, 41 }, 42 # my samples of postscript-type DFONT files have a POST resource 43 # with ID 0x1f5 and the same format as a PostScript file 44 'POST_0x01f5' => { 45 Name => 'PostscriptFont', 46 SubDirectory => { TagTable => 'Image::ExifTool::PostScript::Main' }, 36 47 }, 37 48 'usro_0x0000' => 'OpenWithApplication', … … 55 66 sub ProcessRSRC($$) 56 67 { 57 my ($e xifTool, $dirInfo) = @_;68 my ($et, $dirInfo) = @_; 58 69 my $raf = $$dirInfo{RAF}; 59 70 my ($hdr, $map, $buff, $i, $j); 71 72 # allow access with data reference 73 $raf or $raf = new File::RandomAccess($$dirInfo{DataPt}); 60 74 61 75 # attempt to validate the format as thoroughly as practical … … 74 88 my $typeOff = Get16u(\$map, 24); 75 89 my $nameOff = Get16u(\$map, 26); 76 my $numTypes = Get16u(\$map, 28);90 my $numTypes = (Get16u(\$map, 28) + 1) & 0xffff; 77 91 78 92 # validate offsets in the resource map 79 93 return 0 if $typeOff < 28 or $nameOff < 30; 80 94 81 $e xifTool->SetFileType('RSRC') unless $$exifTool{IN_RESOURCE};82 my $verbose = $e xifTool->Options('Verbose');95 $et->SetFileType('RSRC') unless $$et{IN_RESOURCE}; 96 my $verbose = $et->Options('Verbose'); 83 97 my $tagTablePtr = GetTagTable('Image::ExifTool::RSRC::Main'); 98 $et->VerboseDir('RSRC', $numTypes); 84 99 85 100 # parse resource type list 86 for ($i=0; $i< =$numTypes; ++$i) {101 for ($i=0; $i<$numTypes; ++$i) { 87 102 my $off = $typeOff + 2 + 8 * $i; # offset of entry in type list 88 103 last if $off + 8 > $mapLen; … … 109 124 if ($tagInfo or $verbose) { 110 125 unless ($raf->Seek($resOff, 0) and $raf->Read($buff, 4) == 4 and 111 ($valLen = unpack('N', $buff)) < 10 24000 and # arbitrary size limit126 ($valLen = unpack('N', $buff)) < 100000000 and # arbitrary size limit (100MB) 112 127 $raf->Read($val, $valLen) == $valLen) 113 128 { 114 $e xifTool->Warn("Error reading $resType resource");129 $et->Warn("Error reading $resType resource"); 115 130 next; 116 131 } … … 120 135 $resName = '' unless $raf->Seek($resNameOff, 0) and $raf->Read($buff, 1) and 121 136 ($nameLen = ord $buff) != 0 and $raf->Read($resName, $nameLen) == $nameLen; 122 $exifTool->VPrint(0,sprintf("$resType resource ID 0x%.4x (offset 0x%.4x, $valLen bytes, name='$resName'):\n", $id, $resOff)); 123 $exifTool->VerboseDump(\$val); 137 $et->VPrint(0,sprintf("%s resource ID 0x%.4x (offset 0x%.4x, $valLen bytes, name='%s'):\n", 138 $resType, $id, $resOff, $resName)); 139 $et->VerboseDump(\$val); 124 140 } 125 141 next unless $tagInfo; … … 133 149 next if $p + $vlen > $valLen; 134 150 my $tagTablePtr = GetTagTable('Image::ExifTool::RSRC::Main'); 135 $val = $e xifTool->Decode(substr($val, $p, $vlen), 'MacRoman');151 $val = $et->Decode(substr($val, $p, $vlen), 'MacRoman'); 136 152 } elsif ($resType eq 'sfnt') { 137 153 # parse the OTF font block … … 139 155 $$dirInfo{Base} = $resOff + 4; 140 156 require Image::ExifTool::Font; 141 unless (Image::ExifTool::Font::ProcessOTF($e xifTool, $dirInfo)) {142 $e xifTool->Warn('Unrecognized sfnt resource format');157 unless (Image::ExifTool::Font::ProcessOTF($et, $dirInfo)) { 158 $et->Warn('Unrecognized sfnt resource format'); 143 159 } 144 $exifTool->OverrideFileType('DFONT'); 160 # assume this is a DFONT file unless processing the rsrc fork 161 $et->OverrideFileType('DFONT') unless $$et{DOC_NUM}; 145 162 next; 146 163 } elsif ($resType eq '8BIM') { 147 164 my $ttPtr = GetTagTable('Image::ExifTool::Photoshop::Main'); 148 $e xifTool->HandleTag($ttPtr, $id, $val,165 $et->HandleTag($ttPtr, $id, $val, 149 166 DataPt => \$val, 150 167 DataPos => $resOff + 4, … … 177 194 } 178 195 $val = \@vals; 196 } elsif ($resType eq 'POST') { 197 # assume this is a DFONT file unless processing the rsrc fork 198 $et->OverrideFileType('DFONT') unless $$et{DOC_NUM}; 199 $val = substr $val, 2; 179 200 } elsif ($resType ne 'TEXT') { 180 201 next; 181 202 } 182 $e xifTool->HandleTag($tagTablePtr, $tag, $val);203 $et->HandleTag($tagTablePtr, $tag, $val); 183 204 } 184 205 } … … 205 226 =head1 AUTHOR 206 227 207 Copyright 2003-20 11, Phil Harvey (phil at owl.phy.queensu.ca)228 Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com) 208 229 209 230 This library is free software; you can redistribute it and/or modify it
Note:
See TracChangeset
for help on using the changeset viewer.