Image/ExifTool/7Z.pm

filter: Statementstmt 2.8% 15 / 526 Branchbran 0.5% 1 / 194 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 14.8% 4 / 27 Podpod 0.0% 0 / 24 totaltotal 2.8% 22 / 786 CC 109 SCAR 43.9
CC
109
Cov
2%
ReadFilesInfo
182.0
ReadSubstreamsInfo
156.0
Process7Z
145.2
CRAP 80.5
« Image/ExifTool/H264.pm ↑ Summary Image/ExifTool/FLIR.pm »
1 #------------------------------------------------------------------------------
2 # File: 7Z.pm
3 #
4 # Description: Read 7z archive meta information
5 #
6 # Revisions: 2023/04/28 - Amir Gooran (Cyberno)
7 # 2023-05-06 - PH Minor changes in ExifTool interfacing
8 #
9 # References: 1) https://py7zr.readthedocs.io/en/latest/archive_format.html
10 #------------------------------------------------------------------------------
11  
12 package Image::ExifTool::7Z;
13  
14 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 $VERSION = '1.01';
19  
20 0 ▶sub ReadUInt32 {
Subroutine ReadUInt32: not called CC=1 SCAR=6.9
Pod undocumented
21 0 my $buff;
22  
23 0 $_[0]->Read($buff, 4);
24 0 my ($output) = unpack('L', $buff);
25 0 return $output;
26 }
27  
28 0 ▶sub ReadUInt64 {
Subroutine ReadUInt64: not called CC=5 SCAR=34.0
Pod undocumented
29 0 my $buff;
30 my $output;
31  
32 0 $_[0]->Read($buff, 1);
33 0 my $b = ord($buff);
34 0 ▶ if($b == 255){ # read real uint64
Branch: 1 branch
BranchTrueFalseTotal
if ($b == 255) 0 0 0
35 0 $_[0]->Read($buff, 8);
36 0 my ($output) = unpack('Q', $buff);
37 0 return $output;
38 }
39 0 my @blen = (0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE);
40  
41 0 my $mask = 0x80;
42 0 my $vlen = 8;
43  
44 0 ▶ for (my $l = 0 ; $l < scalar(@blen) ; $l++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l < scalar @blen) 0 0 0
45 0 my $v = $blen[$l];
46 0 ▶ if($b <= $v){
Branch: 1 branch
BranchTrueFalseTotal
if ($b <= $v) 0 0 0
47 0 $vlen = $l;
48 0 last;
49 }
50 0 $mask >>= 1;
51 }
52 0 ▶ if($vlen == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($vlen == 0) 0 0 0
53 0 return $b & ($mask - 1);
54 }
55 0 $_[0]->Read($buff, $vlen);
56 0 $buff .= "\0\0\0\0\0\0\0\0";
57  
58 0 my $value = unpack('Q', $buff);
59 0 my $highpart = $b & ($mask - 1);
60 0 return $value + ($highpart << ($vlen * 8));
61 }
62  
63 0 ▶sub ReadRealUInt64 {
Subroutine ReadRealUInt64: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my $buff;
65  
66 0 $_[0]->Read($buff, 8);
67 0 my $value = unpack('Q', $buff);
68 0 return $value;
69 }
70  
71 0 ▶sub ReadBoolean {
Subroutine ReadBoolean: not called CC=5 SCAR=34.0
Pod undocumented
72 0 my $buff;
73 0 my $count = $_[1];
74 0 my $checkall = $_[2];
75 0 my @result = ();
76  
77 0 ▶ if($checkall){
Branch: 1 branch
BranchTrueFalseTotal
if ($checkall) 0 0 0
78 0 $_[0]->Read($buff, 1);
79 0 my $all_defined = ord($buff);
80 0 ▶ if($all_defined != 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($all_defined != 0) 0 0 0
81 0 @result = (1)x$count;
82 0 return @result;
83 }
84 }
85  
86 0 my $b = 0;
87 0 my $mask = 0;
88  
89 0 ▶ for (my $i = 0 ; $i < $count ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $count) 0 0 0
90 0 ▶ if($mask == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($mask == 0) 0 0 0
91 0 $_[0]->Read($buff, 1);
92 0 $b = ord($buff);
93 0 $mask = 0x80;
94 }
95 0 push(@result, ($b & $mask) != 0);
96 0 $mask >>= 1;
97 }
98 0 return @result;
99 }
100  
101 0 ▶sub ReadUTF16 {
Subroutine ReadUTF16: not called CC=3 SCAR=24.8
Pod undocumented
102 0 my $val = "";
103 0 my $ch;
104  
105 0 ▶ for(my $i=0; $i < 65536; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 65536) 0 0 0
106 0 $_[0]->Read($ch, 2);
107 0 ▶ if($ch eq "\0\0"){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\0\0") 0 0 0
108 0 last;
109 }
110 0 $val .= $ch;
111 }
112 0 return $val;
113 }
114  
115 0 ▶sub ReadPackInfo {
Subroutine ReadPackInfo: not called CC=7 SCAR=40.3
Pod undocumented
116 0 my $et = shift;
117  
118 0 my $buff;
119 0 my %out_packinfo = ();
120 0 $out_packinfo{"packsizes"} = ();
121  
122 0 $out_packinfo{"packpos"} = ReadUInt64($_[0]);
123 0 my $numstreams = ReadUInt64($_[0]);
124 0 $et->VPrint(0, "Number Of Streams: $numstreams\n");
125  
126 0 $_[0]->Read($buff, 1);
127 0 my $pid = ord($buff);
128  
129 0 my @packsizes;
130 0 ▶ if($pid == 9){ # size
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 9) 0 0 0
131 0 ▶ for (my $i = 0 ; $i < $numstreams ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numstreams) 0 0 0
132 0 push(@{ $out_packinfo{"packsizes"} }, ReadUInt64($_[0]));
133 }
134 0 $_[0]->Read($buff, 1);
135 0 $pid = ord($buff);
136 0 ▶ if($pid == 10){ # crc
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 10) 0 0 0
137 0 my @crcs;
138 0 my @digestdefined = ReadBoolean($_[0], $numstreams, 1);
139 0 foreach my $crcexist (@digestdefined) {
140 0 ▶ if($crcexist){
Branch: 1 branch
BranchTrueFalseTotal
if ($crcexist) 0 0 0
141 0 push(@crcs, ReadUInt32($_[0]));
142 }
143 }
144 0 $_[0]->Read($buff, 1);
145 0 $pid = ord($buff);
146 }
147 }
148 0 ▶ if($pid != 0) { # end id expected
Branch: 1 branch
BranchTrueFalseTotal
if ($pid != 0) 0 0 0
149 0 return 0;
150 }
151 0 return \%out_packinfo;
152 }
153  
154 0 ▶sub findInBinPair {
Subroutine findInBinPair: not called CC=3 SCAR=24.8
Pod undocumented
155 0 my @bindpairs = @{$_[0]};
156 0 my $index = $_[1];
157  
158 0 ▶ for (my $i = 0; $i < scalar(@bindpairs); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @bindpairs) 0 0 0
159 0 ▶ if($bindpairs[$i] == $index){
Branch: 1 branch
BranchTrueFalseTotal
if ($bindpairs[$i] == $index) 0 0 0
160 0 return $i;
161 }
162 }
163 0 return -1;
164 }
165  
166 0 ▶sub ReadFolder {
Subroutine ReadFolder: not called CC=10 SCAR=47.0
Pod undocumented
167 0 my $et = shift;
168 0 my $buff;
169 0 my $totalin = 0;
170 0 my $totalout = 0;
171 0 my %out_folder = ();
172 0 $out_folder{"packed_indices"} = ();
173 0 $out_folder{"bindpairs"} = ();
174 0 $out_folder{"coders"} = ();
175  
176 0 my $num_coders = ReadUInt64($_[0]);
177 0 $et->VPrint(0, "Number of coders: $num_coders\n");
178  
179 0 ▶ for (my $i = 0; $i < $num_coders; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num_coders) 0 0 0
180 0 my %c = ();
181 0 $_[0]->Read($buff, 1);
182 0 my $b = ord($buff);
183 0 my $methodsize = $b & 0xF;
184 0 my $iscomplex = ($b & 0x10) == 0x10;
185 0 my $hasattributes = ($b & 0x20) == 0x20;
186 0 ▶ if($methodsize > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($methodsize > 0) { } 0 0 0
187 0 $_[0]->Read($buff, $methodsize);
188 0 $c{"method"} = $buff;
189 }
190 else{
191 0 $c{"method"} = "\0";
192 }
193 0 ▶ if($iscomplex){
Branch: 1 branch
BranchTrueFalseTotal
if ($iscomplex) { } 0 0 0
194 0 $c{"numinstreams"} = ReadUInt64($_[0]);
195 0 $c{"numoutstreams"} = ReadUInt64($_[0]);
196 }
197 else{
198 0 $c{"numinstreams"} = 1;
199 0 $c{"numoutstreams"} = 1;
200 }
201 0 $totalin += $c{"numinstreams"};
202 0 $totalout += $c{"numoutstreams"};
203 0 ▶ if($hasattributes){
Branch: 1 branch
BranchTrueFalseTotal
if ($hasattributes) { } 0 0 0
204 0 my $proplen = ReadUInt64($_[0]);
205 0 $_[0]->Read($buff, $proplen);
206 0 $c{"properties"} = $buff;
207 }
208 else {
209 0 $c{"properties"} = undef;
210 }
211 0 $et->VPrint(0, "Reading coder $i\n");
212 0 push(@{ $out_folder{"coders"} }, \%c);
213 }
214 0 my $num_bindpairs = $totalout - 1;
215 0 ▶ for (my $i = 0; $i < $num_bindpairs; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num_bindpairs) 0 0 0
216 0 my @bond = (ReadUInt64($_[0]), ReadUInt64($_[0]));
217 0 push(@{ $out_folder{"bindpairs"} }, @bond);
218 }
219 0 my $num_packedstreams = $totalin - $num_bindpairs;
220 0 ▶ if($num_packedstreams == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($num_packedstreams == 1) { } 0 0 0
221 0 ▶ for (my $i = 0; $i < $totalin; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $totalin) 0 0 0
222 0 ▶ if(findInBinPair(\@{ $out_folder{"bindpairs"} }, $i) < 0){
Branch: 1 branch
BranchTrueFalseTotal
if (findInBinPair(\@{$out_folder{"bindpairs"};}, $i) < 0) 0 0 0
223 0 push(@{ $out_folder{"packed_indices"} }, $i);
224 }
225 }
226 }
227 else{
228 0 ▶ for (my $i = 0; $i < $num_packedstreams; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num_packedstreams) 0 0 0
229 0 push(@{ $out_folder{"packed_indices"} }, ReadUInt64($_[0]));
230 }
231 }
232  
233 0 return \%out_folder;
234 }
235  
236 0 ▶sub RetrieveCodersInfo{
Subroutine RetrieveCodersInfo: not called CC=10 SCAR=47.0
Pod undocumented
237 0 my $et = shift;
238 0 my $buff;
239 0 my @folders = @{ $_[1] };
240  
241 0 $_[0]->Read($buff, 1);
242 0 my $pid = ord($buff);
243  
244 0 ▶ if($pid != 0x0c){ # coders unpack size id expected
Branch: 1 branch
BranchTrueFalseTotal
if ($pid != 12) 0 0 0
245 0 return 0;
246 }
247 0 foreach my $folder (@folders) {
248 0 $folder->{"unpacksizes"} = ();
249 0 foreach my $c (@{ $folder->{"coders"} }) {
250 0 ▶ for (my $i = 0 ; $i < $c->{"numoutstreams"} ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $c->{"numoutstreams"}) 0 0 0
251 0 push(@{ $folder->{"unpacksizes" } }, ReadUInt64($_[0]));
252 }
253 }
254 }
255 0 $_[0]->Read($buff, 1);
256 0 $pid = ord($buff);
257  
258 0 ▶ if($pid == 0x0a){ #crc
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 10) 0 0 0
259 0 my $numfolders = scalar(@folders);
260 0 $et->VPrint(0, "Number of folders: $numfolders\n");
261 0 my @defined = ReadBoolean($_[0], $numfolders, 1);
262 0 my @crcs;
263 0 foreach my $crcexist (@defined) {
264 0 ▶ if($crcexist){
Branch: 1 branch
BranchTrueFalseTotal
if ($crcexist) 0 0 0
265 0 push(@crcs, ReadUInt32($_[0]));
266 }
267 }
268 0 ▶ for (my $i = 0 ; $i < $numfolders ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numfolders) 0 0 0
269 0 $folders[$i]->{"digestdefined"} = $defined[$i];
270 0 $folders[$i]->{"crc"} = $crcs[$i];
271 }
272 0 $_[0]->Read($buff, 1);
273 0 $pid = ord($buff);
274 }
275  
276 0 ▶ if($pid != 0x00){ # end id expected
Branch: 1 branch
BranchTrueFalseTotal
if ($pid != 0) 0 0 0
277 0 $et->VPrint(0, "Invalid PID: $pid\n");
278 0 return 0;
279 }
280 0 return 1;
281 }
282  
283 0 ▶sub ReadUnpackInfo {
Subroutine ReadUnpackInfo: not called CC=5 SCAR=34.0
Pod undocumented
284 0 my $et = shift;
285 0 my $buff;
286 0 my %out_unpackinfo = ();
287  
288 0 $_[0]->Read($buff, 1);
289 0 my $pid = ord($buff);
290  
291 0 ▶ if($pid != 0xb) { # folder id expected
Branch: 1 branch
BranchTrueFalseTotal
if ($pid != 11) 0 0 0
292 0 return 0;
293 }
294  
295 0 $out_unpackinfo{"numfolders"} = ReadUInt64($_[0]);
296 0 $out_unpackinfo{"folders"} = ();
297  
298 0 $_[0]->Read($buff, 1);
299 0 my $external = ord($buff);
300  
301 0 ▶ if($external == 0x00){
Branch: 1 branch
BranchTrueFalseTotal
if ($external == 0) 0 0 0
302 0 ▶ for (my $i = 0 ; $i < $out_unpackinfo{"numfolders"}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $out_unpackinfo{"numfolders"}) 0 0 0
303 0 $et->VPrint(0, "Reading folder $i\n");
304 0 my $folder = ReadFolder($et, $_[0]);
305 0 push(@{ $out_unpackinfo{"folders"} }, $folder);
306 }
307 }
308 0 ▶ return 0 unless RetrieveCodersInfo($et, $_[0], $out_unpackinfo{"folders"});
Branch: 1 branch
BranchTrueFalseTotal
unless RetrieveCodersInfo($et, $_[0], $out_unpackinfo{"folders"}) 0 0 0
309 0 return \%out_unpackinfo;
310 }
311  
312 0 ▶sub ReadSubstreamsInfo {
Subroutine ReadSubstreamsInfo: not called CC=12 SCAR=50.5
Pod undocumented
313 0 my $et = shift;
314 0 my $buff;
315 0 my %out_substreamsinfo = ();
316 0 $out_substreamsinfo{"num_unpackstreams_folders"} = ();
317  
318 0 my $numfolders = $_[1];
319 0 my $folders = $_[2];
320  
321 0 $_[0]->Read($buff, 1);
322 0 my $pid = ord($buff);
323 0 ▶ if($pid == 13){ # num unpack stream
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 13) { } 0 0 0
324 0 $et->VPrint(0, "Num unpack stream detected.\n");
325 0 ▶ for (my $i = 0 ; $i < $numfolders; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numfolders) 0 0 0
326 0 push(@{ $out_substreamsinfo{"num_unpackstreams_folders"} }, ReadUInt64($_[0]));
327 }
328 0 $_[0]->Read($buff, 1);
329 0 $pid = ord($buff);
330 }
331 else{
332 0 @{ $out_substreamsinfo{"num_unpackstreams_folders"} } = (1)x$numfolders;
333 }
334 0 ▶ if($pid == 9){ # size property
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 9) 0 0 0
335 0 $et->VPrint(0, "Size property detected.\n");
336 0 $out_substreamsinfo{"unpacksizes"} = ();
337 0 ▶ for(my $i=0; $i< scalar(@{ $out_substreamsinfo{"num_unpackstreams_folders"} }); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$out_substreamsinfo{"num_unpackstreams_folders"};}) 0 0 0
338 0 my $totalsize = 0;
339 0 ▶ for(my $j=1; $j < @{ $out_substreamsinfo{"num_unpackstreams_folders"} }[$i]; $j++){
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$out_substreamsinfo{"num_unpackstreams_folders"};}[$i]) 0 0 0
340 0 my $size = ReadUInt64($_[0]);
341 0 push(@{ $out_substreamsinfo{"unpacksizes"} }, $size);
342 0 $totalsize += $size;
343 }
344 # self.unpacksizes.append(folders[i].get_unpack_size() - totalsize)
345 }
346 0 $_[0]->Read($buff, 1);
347 0 $pid = ord($buff);
348 }
349 0 my $num_digests = 0;
350 0 my $num_digests_total = 0;
351 0 ▶ for (my $i = 0 ; $i < $numfolders; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numfolders) 0 0 0
352 0 my $numsubstreams = @{ $out_substreamsinfo{"num_unpackstreams_folders"} }[$i];
353 0 ▶ if($numsubstreams != 1 or not @{ $folders }[$i]->{"digestdefined"}){
Branch: 1 branch
BranchTrueFalseTotal
if ($numsubstreams != 1 or not @{$folders;}[$i]->{"digestdefined"}) 0 0 0
Condition0%0/3
$numsubstreams != 1 or not @{$folders;}[$i]->{"digestdefined"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$numsubstreams != 1 or not @{$folders;}[$i]->{"digestdefined"}
$numsubstreams != 1 not @{$folders;}[$i]->{"digestdefined"}
Truth table0%0/3
A or not(B)
A= $numsubstreams != 1B= not @{$folders;}[$i]->{"digestdefined"}
ABresult
1X1
011
000
354 0 $num_digests += $numsubstreams;
355 }
356 0 $num_digests_total += $numsubstreams;
357 }
358 0 $et->VPrint(0, "Num Digests Total: $num_digests_total\n");
359 0 ▶ if($pid == 10) { # crc property
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 10) 0 0 0
360 0 $et->VPrint(0, "CRC property detected.\n");
361 0 my @crcs;
362 0 my @defined = ReadBoolean($_[0], $num_digests, 1);
363 0 foreach my $crcexist (@defined) {
364 0 push(@crcs, ReadUInt32($_[0]));
365 }
366 0 $_[0]->Read($buff, 1);
367 0 $pid = ord($buff);
368 }
369 0 ▶ if($pid != 0x00){ # end id expected
Branch: 1 branch
BranchTrueFalseTotal
if ($pid != 0) 0 0 0
370 0 return 0;
371 }
372 0 return \%out_substreamsinfo;
373 }
374  
375 0 ▶sub ReadStreamsInfo {
Subroutine ReadStreamsInfo: not called CC=8 SCAR=42.8
Pod undocumented
376 0 my $et = shift;
377 0 my $buff;
378 my $unpackinfo;
379 0 my %out_streamsinfo = ();
380  
381 0 $_[0]->Read($buff, 1);
382 0 my $pid = ord($buff);
383 0 ▶ if($pid == 6){ # pack info
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 6) 0 0 0
384 0 my $packinfo = ReadPackInfo($et, $_[0]);
385 0 ▶ return 0 unless $packinfo;
Branch: 1 branch
BranchTrueFalseTotal
unless $packinfo 0 0 0
386 0 $out_streamsinfo{"packinfo"} = $packinfo;
387 0 $_[0]->Read($buff, 1);
388 0 $pid = ord($buff);
389 }
390 0 ▶ if($pid == 7) { # unpack info
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 7) 0 0 0
391 0 $et->VPrint(0, "Unpack info data detected.\n");
392 0 $unpackinfo = ReadUnpackInfo($et, $_[0]);
393 0 ▶ return 0 unless $unpackinfo;
Branch: 1 branch
BranchTrueFalseTotal
unless $unpackinfo 0 0 0
394 0 $out_streamsinfo{"unpackinfo"} = $unpackinfo;
395 0 $_[0]->Read($buff, 1);
396 0 $pid = ord($buff);
397 }
398 0 ▶ if($pid == 8){ # substreams info
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 8) 0 0 0
399 0 $et->VPrint(0, "Substreams info data detected.\n");
400 0 my $substreamsinfo = ReadSubstreamsInfo($et, $_[0], $unpackinfo->{"numfolders"}, $unpackinfo->{"folders"});
401 0 ▶ return 0 unless $substreamsinfo;
Branch: 1 branch
BranchTrueFalseTotal
unless $substreamsinfo 0 0 0
402 0 $out_streamsinfo{"substreamsinfo"} = $substreamsinfo;
403 0 $_[0]->Read($buff, 1);
404 0 $pid = ord($buff);
405 }
406 0 ▶ if($pid != 0x00){ # end id expected
Branch: 1 branch
BranchTrueFalseTotal
if ($pid != 0) 0 0 0
407 0 $et->VPrint(0, "Invalid PID: $pid\n");
408 0 return 0;
409 }
410 0 return \%out_streamsinfo;
411 }
412  
413 0 ▶sub IsNativeCoder {
Subroutine IsNativeCoder: not called CC=8 SCAR=42.8
Pod undocumented
414 0 my $coder = $_[0];
415  
416 0 ▶ if(ord(substr($coder->{"method"}, 0, 1)) == 3){
Branch: 2 branches
BranchTrueFalseTotal
if (ord substr($coder->{'method'}, 0, 1) == 3) { } 0 0 0
elsif (ord substr($coder->{'method'}, 0, 1) == 6) { } 0 0 0
417 0 ▶ if(ord(substr($coder->{"method"}, 1, 1)) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord substr($coder->{"method"}, 1, 1) == 1) 0 0 0
418 0 ▶ if(ord(substr($coder->{"method"}, 2, 1)) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord substr($coder->{"method"}, 2, 1) == 1) 0 0 0
419 0 return "LZMA";
420 }
421 }
422 }
423 elsif(ord(substr($coder->{"method"}, 0, 1)) == 6){
424 0 ▶ if(ord(substr($coder->{"method"}, 1, 1)) == 0xf1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord substr($coder->{"method"}, 1, 1) == 241) 0 0 0
425 0 ▶ if(ord(substr($coder->{"method"}, 2, 1)) == 7) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord substr($coder->{"method"}, 2, 1) == 7) 0 0 0
426 0 ▶ if(ord(substr($coder->{"method"}, 3, 1)) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord substr($coder->{"method"}, 3, 1) == 1) 0 0 0
427 0 return "7zAES";
428 }
429 }
430 }
431 }
432 }
433  
434 0 ▶sub GetDecompressor {
Subroutine GetDecompressor: not called CC=3 SCAR=24.8
Pod undocumented
435 0 my $et = shift;
436  
437 0 my $folder = $_[0];
438 0 my %out_decompressor = ();
439 0 $out_decompressor{"chain"} = ();
440 0 $out_decompressor{"input_size"} = $_[1];
441 0 $out_decompressor{"_unpacksizes"} = $folder->{"unpacksizes"};
442 0 @{ $out_decompressor{"_unpacked"} } = (0) x scalar(@{ $out_decompressor{"_unpacksizes"} });
443 0 $out_decompressor{"consumed"} = 0;
444 0 $out_decompressor{"block_size"} = 32768;
445 0 $out_decompressor{"_unused"} = [];
446  
447 0 foreach my $coder (@{ $folder->{"coders"} }) {
448 0 my $algorithm = IsNativeCoder($coder);
449 0 ▶ if($algorithm eq "7zAES") {
Branch: 1 branch
BranchTrueFalseTotal
if ($algorithm eq '7zAES') { } 0 0 0
450 0 $et->Warn("File is encrypted.", 0);
451 0 return 0;
452 }
453 else{
454 0 push(@{ $out_decompressor{"chain"} }, $algorithm);
455 }
456 }
457  
458 0 return \%out_decompressor;
459 }
460  
461 0 ▶sub ReadData {
Subroutine ReadData: not called CC=3 SCAR=24.8
Pod undocumented
462 0 my $et = shift;
463 0 my $decompressor = $_[1];
464 0 my $rest_size = $decompressor->{"input_size"} - $decompressor->{"consumed"};
465 0 my $unused_s = scalar(@{ $decompressor->{"_unused"} });
466 0 my $read_size = $rest_size - $unused_s;
467 0 my $data = "";
468 0 ▶ if($read_size > $decompressor->{"block_size"} - $unused_s){
Branch: 1 branch
BranchTrueFalseTotal
if ($read_size > $decompressor->{"block_size"} - $unused_s) 0 0 0
469 0 $read_size = $decompressor->{"block_size"} - $unused_s;
470 }
471 0 ▶ if($read_size > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($read_size > 0) 0 0 0
472 0 $decompressor->{"consumed"} += $_[0]->Read($data, $read_size);
473 0 $et->VPrint(0, "Compressed size: $read_size\n");
474 }
475 0 return $data;
476 }
477  
478 0 ▶sub Decompress_Internal {
Subroutine Decompress_Internal: not called CC=3 SCAR=24.8
Pod undocumented
479 0 my $data = "";
480 0 ▶ for(my $i=0; $i < scalar(@{ $_[0]->{"chain"} }); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$_[0]{"chain"};}) 0 0 0
481 0 ▶ if(@{ $_[0]->{"_unpacked"} }[$i] < @{ $_[0]->{"_unpacksizes"} }[$i]){
Branch: 1 branch
BranchTrueFalseTotal
if (@{$_[0]{"_unpacked"};}[$i] < @{$_[0]{"_unpacksizes"};}[$i]) 0 0 0
482 0 my %opts = ();
483 0 $opts{"Filter"} = Lzma::Filter::Lzma1();
484 0 my ($z, $status) = Compress::Raw::Lzma::RawDecoder->new( %opts );
485 0 $status = $z->code($_[1], $data);
486 0 @{ $_[0]->{"_unpacked"} }[$i] += length($data);
487 }
488 }
489 0 return $data;
490 }
491  
492 0 ▶sub Decompress {
Subroutine Decompress: not called CC=1 SCAR=6.9
Pod undocumented
493 0 my $et = shift;
494 0 my $max_length = $_[1];
495 0 my $data = ReadData($et, $_[0], $_[1]);
496 0 my $tmp = Decompress_Internal($_[1], $data);
497 0 return $tmp;
498 }
499  
500 0 ▶sub ReadName {
Subroutine ReadName: not called CC=2 SCAR=17.9
Pod undocumented
501 0 my $numfiles = $_[1];
502  
503 0 ▶ for(my $i=0; $i < $numfiles; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numfiles) 0 0 0
504 0 @{ $_[2] }[$i]->{"filename"} = ReadUTF16($_[0]);
505 }
506 }
507  
508 0 ▶sub ReadTimes {
Subroutine ReadTimes: not called CC=4 SCAR=30.0
Pod undocumented
509 0 my $et = shift;
510 0 my $external;
511 0 my $numfiles = $_[1];
512 0 my $name = $_[2];
513  
514 0 my @defined = ReadBoolean($_[0], $numfiles, 1);
515 0 $_[0]->Read($external, 1);
516 0 ▶ if(ord($external) != 0){
Branch: 1 branch
BranchTrueFalseTotal
if (ord $external != 0) 0 0 0
517 0 $et->Warn("Invalid or corrupted file. (ReadTimes)");
518 0 return 0;
519 }
520  
521 0 ▶ for(my $i=0; $i < $numfiles; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numfiles) 0 0 0
522 0 ▶ if($defined[$i]){
Branch: 1 branch
BranchTrueFalseTotal
if ($defined[$i]) { } 0 0 0
523 0 my $value = ReadRealUInt64($_[0]);
524 0 $value = $value / 10000000.0 - 11644473600;
525 0 @{ $_[3] }[$i]->{$name} = $value;
526 }
527 else{
528 0 @{ $_[3] }[$i]->{$name} = undef;
529 }
530 }
531 }
532  
533 0 ▶sub ReadAttributes {
Subroutine ReadAttributes: not called CC=3 SCAR=24.8
Pod undocumented
534 0 my $numfiles = $_[1];
535  
536 0 ▶ for(my $i=0; $i < $numfiles; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numfiles) 0 0 0
537 0 ▶ if($_[2][$i]){
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2][$i]) { } 0 0 0
538 0 my $value = ReadUInt32($_[0]);
539 0 @{ $_[3] }[$i]->{"attributes"} = $value >> 8;
540 }
541 else{
542 0 @{ $_[3] }[$i]->{"attributes"} = undef;
543 }
544 }
545 }
546  
547 0 ▶sub ReadFilesInfo {
Subroutine ReadFilesInfo: not called CC=13 SCAR=52.0
Pod undocumented
548 0 my $et = shift;
549 0 my $buff;
550  
551 0 my $numfiles = ReadUInt64($_[0]);
552 0 my @out_files = ();
553 0 ▶ for(my $i = 0; $i < $numfiles; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numfiles) 0 0 0
554 0 my %new_file = ();
555 0 $new_file{"emptystream"} = 0;
556 0 push(@out_files, \%new_file);
557 }
558 0 my $numemptystreams = 0;
559 0 $et->VPrint(0, "Number of files: $numfiles\n");
560 0 while(1){
561 0 $_[0]->Read($buff, 1);
562 0 my $prop = ord($buff);
563 0 ▶ if($prop == 0){ # end
Branch: 1 branch
BranchTrueFalseTotal
if ($prop == 0) 0 0 0
564 0 return \@out_files;
565 }
566 0 my $size = ReadUInt64($_[0]);
567 0 ▶ if($prop == 25) { # dummy
Branch: 1 branch
BranchTrueFalseTotal
if ($prop == 25) 0 0 0
568 0 $_[0]->Seek($size, 1);
569 0 next;
570 }
571 0 $_[0]->Read($buff, $size);
572 0 my $buffer = File::RandomAccess->new(\$buff);
573 0 ▶ if($prop == 14){ # empty stream
Branch: 5 branches
BranchTrueFalseTotal
if ($prop == 14) { } 0 0 0
elsif ($prop == 15) { } 0 0 0
elsif ($prop == 17) { } 0 0 0
elsif ($prop == 20) { } 0 0 0
elsif ($prop == 21) { } 0 0 0
574 0 my @isempty = ReadBoolean($buffer, $numfiles, 0);
575 0 my $numemptystreams = 0;
576 0 ▶ for(my $i = 0; $i < $numfiles; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numfiles) 0 0 0
577 0 ▶ if($isempty[$i] == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($isempty[$i] == 0) { } 0 0 0
578 0 $out_files[$i]->{"emptystream"} = 0;
579 }
580 else{
581 0 $out_files[$i]->{"emptystream"} = 1;
582 0 $numemptystreams++;
583 }
584 }
585 }
586 elsif($prop == 15) { # empty file
587  
588 }
589 elsif($prop == 17){ # name
590 0 $et->VPrint(0, "Name prop detected.\n");
591 0 my $external;
592 0 $buffer->Read($external, 1);
593 0 my $is_external = ord($external);
594 0 ▶ if($is_external == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($is_external == 0) 0 0 0
595 0 ReadName($buffer, $numfiles, \@out_files);
596 }
597 }
598 elsif($prop == 20){ # last write time
599 0 $et->VPrint(0, "Last write time detected.\n");
600 0 ReadTimes($et, $buffer, $numfiles, "lastwritetime", \@out_files);
601 }
602 elsif($prop == 21){ # attributes
603 0 $et->VPrint(0, "File attributes detected.\n");
604 0 my $external;
605 0 my @defined = ReadBoolean($buffer, $numfiles, 1);
606 0 $_[0]->Read($external, 1);
607 0 ▶ if(ord($external) == 0){
Branch: 1 branch
BranchTrueFalseTotal
if (ord $external == 0) { } 0 0 0
608 0 ReadAttributes($buffer, $numfiles, \@defined, \@out_files);
609 }
610 else{
611 0 my $dataindex = ReadUINT64($buffer);
612 #TODO: try to read external data
613 }
614 }
615 }
616 }
617  
618 0 ▶sub ExtractHeaderInfo {
Subroutine ExtractHeaderInfo: not called CC=5 SCAR=34.0
Pod undocumented
619 0 my $et = shift;
620 0 my $buff;
621 0 my %out_headerinfo = ();
622 0 $out_headerinfo{"files_info"} = ();
623 0 my $files_info;
624  
625 0 $_[0]->Read($buff, 1);
626 0 my $pid = ord($buff);
627  
628 0 ▶ if($pid == 0x04){
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 4) 0 0 0
629 0 my $mainstreams = ReadStreamsInfo($et, $_[0]);
630 0 ▶ if($mainstreams == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($mainstreams == 0) 0 0 0
631 0 $et->Warn("Invalid or corrupted file. (ExtractHeaderInfo)");
632 0 return 0;
633 }
634 0 $_[0]->Read($buff, 1);
635 0 $pid = ord($buff);
636 }
637 0 ▶ if($pid == 0x05){
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 5) 0 0 0
638 0 $et->VPrint(0, "File info pid reached.\n");
639 0 $files_info = ReadFilesInfo($et, $_[0]);
640 0 push(@{ $out_headerinfo{"files_info"} }, $files_info);
641 0 $_[0]->Read($buff, 1);
642 0 $pid = ord($buff);
643 }
644 0 ▶ if($pid != 0x00){ # end id expected
Branch: 1 branch
BranchTrueFalseTotal
if ($pid != 0) 0 0 0
645 0 $et->VPrint(0, "Invalid PID: $pid\n");
646 0 return 0;
647 }
648 0 return \%out_headerinfo;
649 }
650  
651 0 ▶sub DisplayFiles {
Subroutine DisplayFiles: not called CC=4 SCAR=30.0
Pod undocumented
652 0 my $et = shift;
653 0 my $docNum = 0;
654 0 my $tagTablePtr = GetTagTable('Image::ExifTool::ZIP::RAR5');
655  
656 0 foreach my $currentfile (@{ $_[0] }){
657 0 $$et{DOC_NUM} = ++$docNum;
658 0 $et->HandleTag($tagTablePtr, 'ModifyDate', $currentfile->{"lastwritetime"});
659 0 $et->HandleTag($tagTablePtr, 'ArchivedFileName', $currentfile->{"filename"});
660 }
661 0 delete $$et{DOC_NUM};
662 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
663 0 $et->Warn("Use the Duplicates option to extract tags for all $docNum files", 1);
664 }
665 }
666  
667 #------------------------------------------------------------------------------
668 # Extract information from a 7z file
669 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
670 # Returns: 1 on success, 0 if this wasn't a valid 7z file
671 sub Process7Z($$)
672 14 ▶{
Subroutine Process7Z: called CC=13 SCAR=49.8
Pod undocumented
673 14 my ($et, $dirInfo) = @_;
674 14 my $raf = $$dirInfo{RAF};
675 14 my ($flags, $buff);
676  
677 14 ▶ return 0 unless $raf->Read($buff, 6) and $buff eq "7z\xbc\xaf\x27\x1c";
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 6) and $buff eq "7z\274\257'\34" 14 0 14
Condition66%2/3
$raf->Read($buff, 6) and $buff eq "7z\274\257'\34"
!ll&&!rl&&r
3110
MC/DC0%0/2
$raf->Read($buff, 6) and $buff eq "7z\274\257'\34"
$raf->Read($buff, 6) $buff eq "7z\274\257'\34"
Truth table66%2/3
A and B
A= $raf->Read($buff, 6)B= $buff eq "7z\274\257'\34"
ABresult
0X0
100
111
678  
679 0 $et->SetFileType();
680  
681 0 $raf->Read($buff, 2);
682 0 my ($major_version, $minor_version) = unpack('cc', $buff);
683 0 my $tagTablePtr = GetTagTable('Image::ExifTool::ZIP::RAR5');
684 0 $et->HandleTag($tagTablePtr, 'FileVersion', sprintf('7z v%d.%.2d',$major_version,$minor_version));
685  
686 0 $raf->Seek(4, 1); # skip Start Header CRC
687  
688 0 $raf->Read($buff, 20);
689 0 my ($nextheaderoffset, $nextheadersize) = unpack('QQx', $buff);
690 0 $et->VPrint(0, "NextHeaderOffset: $nextheaderoffset, NextHeaderSize: $nextheadersize\n");
691  
692 0 $raf->Seek($nextheaderoffset, 1); # going to next header offset
693 0 $raf->Read($buff, 1);
694 0 my $pid = ord($buff);
695 0 ▶ if($pid == 1){ # normal header
Branch: 2 branches
BranchTrueFalseTotal
if ($pid == 1) { } 0 0 0
elsif ($pid == 23) { } 0 0 0
696 0 $et->VPrint(0,"Normal header detected. trying to decode\n");
697 0 my $headerinfo = ExtractHeaderInfo($et, $raf);
698 0 ▶ if($headerinfo == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($headerinfo == 0) 0 0 0
699 0 $et->Warn("Invalid or corrupted file.");
700 0 return 1;
701 }
702 0 DisplayFiles($et, @{ $headerinfo->{"files_info"} });
703 }
704 elsif($pid == 23){ # encoded header
705 0 ▶ unless (eval { require Compress::Raw::Lzma }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Compress::Raw::Lzma } }) 0 0 0
706 0 $et->Warn("Install Compress::Raw::Lzma to read encoded 7z information");
707 0 return 1;
708 }
709 0 $et->VPrint(0, "Encoded Header detected. trying to decode\n");
710 0 my $streamsinfo = ReadStreamsInfo($et, $raf);
711 0 ▶ if($streamsinfo == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($streamsinfo == 0) 0 0 0
712 0 $et->Warn("Invalid or corrupted file.");
713 0 return 1;
714 }
715 0 my $buffer2 = ();
716 0 foreach my $folder (@{ $streamsinfo->{"unpackinfo"}->{"folders"} }) {
717 0 my @uncompressed = @{ $folder->{"unpacksizes"} };
718 0 my $compressed_size = $streamsinfo->{"packinfo"}->{"packsizes"}[0];
719 0 my $uncompressed_size = @uncompressed[scalar(@uncompressed) - 1];
720 0 my $decomporessor = GetDecompressor($et, $folder, $compressed_size);
721 0 ▶ if($decomporessor == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($decomporessor == 0) 0 0 0
722 0 $et->Warn("Invalid or corrupted file.");
723 0 return 1;
724 }
725  
726 0 my $src_start = 32;
727 0 $src_start += $streamsinfo->{"packinfo"}->{"packpos"};
728 0 $raf->Seek($src_start, 0);
729 0 my $remaining = $uncompressed_size;
730 0 my $folder_data = "";
731 0 ▶ while($remaining > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($remaining > 0) 0 0 0
732 0 $folder_data .= Decompress($et, $raf, $decomporessor, $remaining);
733 0 $remaining = $uncompressed_size - length($folder_data);
734 }
735 0 $buffer2 = File::RandomAccess->new(\$folder_data);
736 }
737 0 $buffer2->Seek(0, 0);
738 0 $buffer2->Read($buff, 1);
739 0 $pid = ord($buff);
740 0 ▶ if($pid != 0x01){ # header field expected
Branch: 1 branch
BranchTrueFalseTotal
if ($pid != 1) 0 0 0
741 0 return 0;
742 }
743 0 my $headerinfo = ExtractHeaderInfo($et, $buffer2);
744 0 ▶ if($headerinfo == 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($headerinfo == 0) 0 0 0
745 0 $et->Warn("Invalid or corrupted file.");
746 0 return 1;
747 }
748 0 DisplayFiles($et, @{ $headerinfo->{"files_info"} });
749 }else{ # Unknown header
750 0 return 0;
751 }
752  
753 0 return 1;
754 }
755  
756 6 1; # end
757  
758 __END__
« Image/ExifTool/H264.pm ↑ Summary Image/ExifTool/FLIR.pm »