ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GetId3\Module\Archive\Zip Class Reference

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //. More...

+ Inheritance diagram for GetId3\Module\Archive\Zip:
+ Collaboration diagram for GetId3\Module\Archive\Zip:

Public Member Functions

 analyze ()
 
 getZIPHeaderFilepointerTopDown ()
 
 getZIPentriesFilepointer ()
 
 ZIPparseLocalFileHeader ()
 
 ZIPparseCentralDirectory ()
 
 ZIPparseEndOfCentralDirectory ()
 
- Public Member Functions inherited from GetId3\Handler\BaseHandler
 __construct (GetId3Core $getid3, $call_module=null)
 
 analyze ()
 Analyze from file pointer. More...
 
 AnalyzeString (&$string)
 Analyze from string instead. More...
 
 saveAttachment (&$ThisFileInfoIndex, $filename, $offset, $length)
 

Static Public Member Functions

static ZIPparseGeneralPurposeFlags ($flagbytes, $compressionmethod)
 
static ZIPversionOSLookup ($index)
 array $ZIPversionOSLookup More...
 
static ZIPcompressionMethodLookup ($index)
 array $ZIPcompressionMethodLookup More...
 
static DOStime2UNIXtime ($DOSdate, $DOStime)
 

Additional Inherited Members

- Protected Member Functions inherited from GetId3\Handler\BaseHandler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
- Protected Attributes inherited from GetId3\Handler\BaseHandler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //.

module for analyzing pkZip files

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g http://www.getid3.org

Definition at line 29 of file Zip.php.

Member Function Documentation

◆ analyze()

GetId3\Module\Archive\Zip::analyze ( )
Returns
boolean

Definition at line 35 of file Zip.php.

References $info, array, GetId3\Lib\Helper\array_merge_clobber(), GetId3\Lib\Helper\CreateDeepArray(), GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Module\Archive\Zip\getZIPentriesFilepointer(), GetId3\Lib\Helper\intValueSupported(), GetId3\Module\Archive\Zip\ZIPparseCentralDirectory(), and GetId3\Module\Archive\Zip\ZIPparseEndOfCentralDirectory().

36  {
37  $info = &$this->getid3->info;
38 
39  $info['fileformat'] = 'zip';
40  $info['zip']['encoding'] = 'ISO-8859-1';
41  $info['zip']['files'] = array();
42 
43  $info['zip']['compressed_size'] = 0;
44  $info['zip']['uncompressed_size'] = 0;
45  $info['zip']['entries_count'] = 0;
46 
47  if (!Helper::intValueSupported($info['filesize'])) {
48  $info['error'][] = 'File is larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB, not supported by PHP';
49 
50  return false;
51  } else {
52  $EOCDsearchData = '';
53  $EOCDsearchCounter = 0;
54  while ($EOCDsearchCounter++ < 512) {
55 
56  fseek($this->getid3->fp, -128 * $EOCDsearchCounter, SEEK_END);
57  $EOCDsearchData = fread($this->getid3->fp, 128) . $EOCDsearchData;
58 
59  if (strstr($EOCDsearchData, 'PK' . "\x05\x06")) {
60 
61  $EOCDposition = strpos($EOCDsearchData, 'PK' . "\x05\x06");
62  fseek($this->getid3->fp,
63  (-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
64  $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory();
65 
66  fseek($this->getid3->fp,
67  $info['zip']['end_central_directory']['directory_offset'],
68  SEEK_SET);
69  $info['zip']['entries_count'] = 0;
70  while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
71  $info['zip']['central_directory'][] = $centraldirectoryentry;
72  $info['zip']['entries_count']++;
73  $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
74  $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
75 
76  if ($centraldirectoryentry['uncompressed_size'] > 0) {
77  $info['zip']['files'] = Helper::array_merge_clobber($info['zip']['files'],
78  Helper::CreateDeepArray($centraldirectoryentry['filename'],
79  '/',
80  $centraldirectoryentry['uncompressed_size']));
81  }
82  }
83 
84  if ($info['zip']['entries_count'] == 0) {
85  $info['error'][] = 'No Central Directory entries found (truncated file?)';
86 
87  return false;
88  }
89 
90  if (!empty($info['zip']['end_central_directory']['comment'])) {
91  $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
92  }
93 
94  if (isset($info['zip']['central_directory'][0]['compression_method'])) {
95  $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method'];
96  }
97  if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) {
98  $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed'];
99  }
100  if (isset($info['zip']['compression_method']) && ($info['zip']['compression_method'] == 'store') && !isset($info['zip']['compression_speed'])) {
101  $info['zip']['compression_speed'] = 'store';
102  }
103 
104  return true;
105  }
106  }
107  }
108 
109  if ($this->getZIPentriesFilepointer()) {
110 
111  // central directory couldn't be found and/or parsed
112  // scan through actual file data entries, recover as much as possible from probable trucated file
113  if ($info['zip']['compressed_size'] > ($info['filesize'] - 46 - 22)) {
114  $info['error'][] = 'Warning: Truncated file! - Total compressed file sizes (' . $info['zip']['compressed_size'] . ' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures (' . ($info['filesize'] - 46 - 22) . ' bytes)';
115  }
116  $info['error'][] = 'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete';
117  foreach ($info['zip']['entries'] as $key => $valuearray) {
118  $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size'];
119  }
120 
121  return true;
122  } else {
123 
124  unset($info['zip']);
125  $info['fileformat'] = '';
126  $info['error'][] = 'Cannot find End Of Central Directory (truncated file?)';
127 
128  return false;
129  }
130  }
static CreateDeepArray($ArrayPath, $Separator, $Value)
Definition: Helper.php:726
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
Create styles array
The data for the language used.
static array_merge_clobber($array1, $array2)
Definition: Helper.php:561
static intValueSupported($num)
null $hasINT64
Definition: Helper.php:130
+ Here is the call graph for this function:

◆ DOStime2UNIXtime()

static GetId3\Module\Archive\Zip::DOStime2UNIXtime (   $DOSdate,
  $DOStime 
)
static
Parameters
type$DOSdate
type$DOStime
Returns
type

Definition at line 570 of file Zip.php.

Referenced by GetId3\Module\Archive\Zip\ZIPparseCentralDirectory(), and GetId3\Module\Archive\Zip\ZIPparseLocalFileHeader().

571  {
572  // wFatDate
573  // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
574  // Bits Contents
575  // 0-4 Day of the month (1-31)
576  // 5-8 Month (1 = January, 2 = February, and so on)
577  // 9-15 Year offset from 1980 (add 1980 to get actual year)
578 
579  $UNIXday = ($DOSdate & 0x001F);
580  $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
581  $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
582 
583  // wFatTime
584  // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
585  // Bits Contents
586  // 0-4 Second divided by 2
587  // 5-10 Minute (0-59)
588  // 11-15 Hour (0-23 on a 24-hour clock)
589 
590  $UNIXsecond = ($DOStime & 0x001F) * 2;
591  $UNIXminute = (($DOStime & 0x07E0) >> 5);
592  $UNIXhour = (($DOStime & 0xF800) >> 11);
593 
594  return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth,
595  $UNIXday, $UNIXyear);
596  }
+ Here is the caller graph for this function:

◆ getZIPentriesFilepointer()

GetId3\Module\Archive\Zip::getZIPentriesFilepointer ( )
Returns
boolean

Definition at line 189 of file Zip.php.

References $info, and GetId3\Module\Archive\Zip\ZIPparseLocalFileHeader().

Referenced by GetId3\Module\Archive\Zip\analyze().

190  {
191  $info = &$this->getid3->info;
192 
193  $info['zip']['compressed_size'] = 0;
194  $info['zip']['uncompressed_size'] = 0;
195  $info['zip']['entries_count'] = 0;
196 
197  rewind($this->getid3->fp);
198  while ($fileentry = $this->ZIPparseLocalFileHeader()) {
199  $info['zip']['entries'][] = $fileentry;
200  $info['zip']['entries_count']++;
201  $info['zip']['compressed_size'] += $fileentry['compressed_size'];
202  $info['zip']['uncompressed_size'] += $fileentry['uncompressed_size'];
203  }
204  if ($info['zip']['entries_count'] == 0) {
205  $info['error'][] = 'No Local File Header entries found';
206 
207  return false;
208  }
209 
210  return true;
211  }
$info
Definition: example_052.php:80
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getZIPHeaderFilepointerTopDown()

GetId3\Module\Archive\Zip::getZIPHeaderFilepointerTopDown ( )
Returns
boolean

Definition at line 136 of file Zip.php.

References $info, GetId3\Module\Archive\Zip\ZIPparseCentralDirectory(), GetId3\Module\Archive\Zip\ZIPparseEndOfCentralDirectory(), and GetId3\Module\Archive\Zip\ZIPparseLocalFileHeader().

137  {
138  $info = &$this->getid3->info;
139 
140  $info['fileformat'] = 'zip';
141 
142  $info['zip']['compressed_size'] = 0;
143  $info['zip']['uncompressed_size'] = 0;
144  $info['zip']['entries_count'] = 0;
145 
146  rewind($this->getid3->fp);
147  while ($fileentry = $this->ZIPparseLocalFileHeader()) {
148  $info['zip']['entries'][] = $fileentry;
149  $info['zip']['entries_count']++;
150  }
151  if ($info['zip']['entries_count'] == 0) {
152  $info['error'][] = 'No Local File Header entries found';
153 
154  return false;
155  }
156 
157  $info['zip']['entries_count'] = 0;
158  while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
159  $info['zip']['central_directory'][] = $centraldirectoryentry;
160  $info['zip']['entries_count']++;
161  $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
162  $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
163  }
164  if ($info['zip']['entries_count'] == 0) {
165  $info['error'][] = 'No Central Directory entries found (truncated file?)';
166 
167  return false;
168  }
169 
170  if ($EOCD = $this->ZIPparseEndOfCentralDirectory()) {
171  $info['zip']['end_central_directory'] = $EOCD;
172  } else {
173  $info['error'][] = 'No End Of Central Directory entry found (truncated file?)';
174 
175  return false;
176  }
177 
178  if (!empty($info['zip']['end_central_directory']['comment'])) {
179  $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
180  }
181 
182  return true;
183  }
$info
Definition: example_052.php:80
+ Here is the call graph for this function:

◆ ZIPcompressionMethodLookup()

static GetId3\Module\Archive\Zip::ZIPcompressionMethodLookup (   $index)
static

array $ZIPcompressionMethodLookup

Parameters
type$index
Returns
type

Definition at line 545 of file Zip.php.

References array.

Referenced by GetId3\Module\Archive\Zip\ZIPparseCentralDirectory(), and GetId3\Module\Archive\Zip\ZIPparseLocalFileHeader().

546  {
547  static $ZIPcompressionMethodLookup = array(
548  0 => 'store',
549  1 => 'shrink',
550  2 => 'reduce-1',
551  3 => 'reduce-2',
552  4 => 'reduce-3',
553  5 => 'reduce-4',
554  6 => 'implode',
555  7 => 'tokenize',
556  8 => 'deflate',
557  9 => 'deflate64',
558  10 => 'PKWARE Date Compression Library Imploding'
559  );
560 
561  return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]');
562  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ ZIPparseCentralDirectory()

GetId3\Module\Archive\Zip::ZIPparseCentralDirectory ( )
Returns
boolean

Definition at line 315 of file Zip.php.

References GetId3\Module\Archive\Zip\DOStime2UNIXtime(), GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Handler\BaseHandler\ftell(), GetId3\Lib\Helper\LittleEndian2Int(), GetId3\Module\Archive\Zip\ZIPcompressionMethodLookup(), GetId3\Module\Archive\Zip\ZIPparseGeneralPurposeFlags(), and GetId3\Module\Archive\Zip\ZIPversionOSLookup().

Referenced by GetId3\Module\Archive\Zip\analyze(), and GetId3\Module\Archive\Zip\getZIPHeaderFilepointerTopDown().

316  {
317  $CentralDirectory['offset'] = ftell($this->getid3->fp);
318 
319  $ZIPcentralDirectory = fread($this->getid3->fp, 46);
320 
321  $CentralDirectory['raw']['signature'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
322  0,
323  4));
324  if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
325  // invalid Central Directory Signature
326  fseek($this->getid3->fp, $CentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
327 
328  return false;
329  }
330  $CentralDirectory['raw']['create_version'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
331  4,
332  2));
333  $CentralDirectory['raw']['extract_version'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
334  6,
335  2));
336  $CentralDirectory['raw']['general_flags'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
337  8,
338  2));
339  $CentralDirectory['raw']['compression_method'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
340  10,
341  2));
342  $CentralDirectory['raw']['last_mod_file_time'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
343  12,
344  2));
345  $CentralDirectory['raw']['last_mod_file_date'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
346  14,
347  2));
348  $CentralDirectory['raw']['crc_32'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
349  16,
350  4));
351  $CentralDirectory['raw']['compressed_size'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
352  20,
353  4));
354  $CentralDirectory['raw']['uncompressed_size'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
355  24,
356  4));
357  $CentralDirectory['raw']['filename_length'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
358  28,
359  2));
360  $CentralDirectory['raw']['extra_field_length'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
361  30,
362  2));
363  $CentralDirectory['raw']['file_comment_length'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
364  32,
365  2));
366  $CentralDirectory['raw']['disk_number_start'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
367  34,
368  2));
369  $CentralDirectory['raw']['internal_file_attrib'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
370  36,
371  2));
372  $CentralDirectory['raw']['external_file_attrib'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
373  38,
374  4));
375  $CentralDirectory['raw']['local_header_offset'] = Helper::LittleEndian2Int(substr($ZIPcentralDirectory,
376  42,
377  4));
378 
379  $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset'];
380  $CentralDirectory['create_version'] = sprintf('%1.1f',
381  $CentralDirectory['raw']['create_version'] / 10);
382  $CentralDirectory['extract_version'] = sprintf('%1.1f',
383  $CentralDirectory['raw']['extract_version'] / 10);
384  $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8);
385  $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']);
386  $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size'];
387  $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size'];
388  $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'],
389  $CentralDirectory['raw']['compression_method']);
390  $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'],
391  $CentralDirectory['raw']['last_mod_file_time']);
392 
393  $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length'];
394  if ($FilenameExtrafieldCommentLength > 0) {
395  $FilenameExtrafieldComment = fread($this->getid3->fp,
396  $FilenameExtrafieldCommentLength);
397 
398  if ($CentralDirectory['raw']['filename_length'] > 0) {
399  $CentralDirectory['filename'] = substr($FilenameExtrafieldComment,
400  0,
401  $CentralDirectory['raw']['filename_length']);
402  }
403  if ($CentralDirectory['raw']['extra_field_length'] > 0) {
404  $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment,
405  $CentralDirectory['raw']['filename_length'],
406  $CentralDirectory['raw']['extra_field_length']);
407  }
408  if ($CentralDirectory['raw']['file_comment_length'] > 0) {
409  $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment,
410  $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'],
411  $CentralDirectory['raw']['file_comment_length']);
412  }
413  }
414 
415  return $CentralDirectory;
416  }
static DOStime2UNIXtime($DOSdate, $DOStime)
Definition: Zip.php:570
fseek($bytes, $whence=SEEK_SET)
static ZIPversionOSLookup($index)
array $ZIPversionOSLookup
Definition: Zip.php:513
static LittleEndian2Int($byteword, $signed=false)
Definition: Helper.php:413
static ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod)
Definition: Zip.php:473
static ZIPcompressionMethodLookup($index)
array $ZIPcompressionMethodLookup
Definition: Zip.php:545
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPparseEndOfCentralDirectory()

GetId3\Module\Archive\Zip::ZIPparseEndOfCentralDirectory ( )
Returns
boolean

Definition at line 422 of file Zip.php.

References GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Handler\BaseHandler\ftell(), and GetId3\Lib\Helper\LittleEndian2Int().

Referenced by GetId3\Module\Archive\Zip\analyze(), and GetId3\Module\Archive\Zip\getZIPHeaderFilepointerTopDown().

423  {
424  $EndOfCentralDirectory['offset'] = ftell($this->getid3->fp);
425 
426  $ZIPendOfCentralDirectory = fread($this->getid3->fp, 22);
427 
428  $EndOfCentralDirectory['signature'] = Helper::LittleEndian2Int(substr($ZIPendOfCentralDirectory,
429  0,
430  4));
431  if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
432  // invalid End Of Central Directory Signature
433  fseek($this->getid3->fp, $EndOfCentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
434 
435  return false;
436  }
437  $EndOfCentralDirectory['disk_number_current'] = Helper::LittleEndian2Int(substr($ZIPendOfCentralDirectory,
438  4,
439  2));
440  $EndOfCentralDirectory['disk_number_start_directory'] = Helper::LittleEndian2Int(substr($ZIPendOfCentralDirectory,
441  6,
442  2));
443  $EndOfCentralDirectory['directory_entries_this_disk'] = Helper::LittleEndian2Int(substr($ZIPendOfCentralDirectory,
444  8,
445  2));
446  $EndOfCentralDirectory['directory_entries_total'] = Helper::LittleEndian2Int(substr($ZIPendOfCentralDirectory,
447  10,
448  2));
449  $EndOfCentralDirectory['directory_size'] = Helper::LittleEndian2Int(substr($ZIPendOfCentralDirectory,
450  12,
451  4));
452  $EndOfCentralDirectory['directory_offset'] = Helper::LittleEndian2Int(substr($ZIPendOfCentralDirectory,
453  16,
454  4));
455  $EndOfCentralDirectory['comment_length'] = Helper::LittleEndian2Int(substr($ZIPendOfCentralDirectory,
456  20,
457  2));
458 
459  if ($EndOfCentralDirectory['comment_length'] > 0) {
460  $EndOfCentralDirectory['comment'] = fread($this->getid3->fp,
461  $EndOfCentralDirectory['comment_length']);
462  }
463 
464  return $EndOfCentralDirectory;
465  }
fseek($bytes, $whence=SEEK_SET)
static LittleEndian2Int($byteword, $signed=false)
Definition: Helper.php:413
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPparseGeneralPurposeFlags()

static GetId3\Module\Archive\Zip::ZIPparseGeneralPurposeFlags (   $flagbytes,
  $compressionmethod 
)
static
Parameters
type$flagbytes
type$compressionmethod
Returns
type

Definition at line 473 of file Zip.php.

Referenced by GetId3\Module\Archive\Zip\ZIPparseCentralDirectory(), and GetId3\Module\Archive\Zip\ZIPparseLocalFileHeader().

475  {
476  $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001);
477 
478  switch ($compressionmethod) {
479  case 6:
480  $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096);
481  $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2);
482  break;
483 
484  case 8:
485  case 9:
486  switch (($flagbytes & 0x0006) >> 1) {
487  case 0:
488  $ParsedFlags['compression_speed'] = 'normal';
489  break;
490  case 1:
491  $ParsedFlags['compression_speed'] = 'maximum';
492  break;
493  case 2:
494  $ParsedFlags['compression_speed'] = 'fast';
495  break;
496  case 3:
497  $ParsedFlags['compression_speed'] = 'superfast';
498  break;
499  }
500  break;
501  }
502  $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
503 
504  return $ParsedFlags;
505  }
+ Here is the caller graph for this function:

◆ ZIPparseLocalFileHeader()

GetId3\Module\Archive\Zip::ZIPparseLocalFileHeader ( )
Returns
boolean

Definition at line 217 of file Zip.php.

References GetId3\Module\Archive\Zip\DOStime2UNIXtime(), GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Handler\BaseHandler\ftell(), GetId3\Lib\Helper\LittleEndian2Int(), GetId3\Module\Archive\Zip\ZIPcompressionMethodLookup(), GetId3\Module\Archive\Zip\ZIPparseGeneralPurposeFlags(), and GetId3\Module\Archive\Zip\ZIPversionOSLookup().

Referenced by GetId3\Module\Archive\Zip\getZIPentriesFilepointer(), and GetId3\Module\Archive\Zip\getZIPHeaderFilepointerTopDown().

218  {
219  $LocalFileHeader['offset'] = ftell($this->getid3->fp);
220 
221  $ZIPlocalFileHeader = fread($this->getid3->fp, 30);
222 
223  $LocalFileHeader['raw']['signature'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
224  0,
225  4));
226  if ($LocalFileHeader['raw']['signature'] != 0x04034B50) {
227  // invalid Local File Header Signature
228  fseek($this->getid3->fp, $LocalFileHeader['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
229 
230  return false;
231  }
232  $LocalFileHeader['raw']['extract_version'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
233  4,
234  2));
235  $LocalFileHeader['raw']['general_flags'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
236  6,
237  2));
238  $LocalFileHeader['raw']['compression_method'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
239  8,
240  2));
241  $LocalFileHeader['raw']['last_mod_file_time'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
242  10,
243  2));
244  $LocalFileHeader['raw']['last_mod_file_date'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
245  12,
246  2));
247  $LocalFileHeader['raw']['crc_32'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
248  14,
249  4));
250  $LocalFileHeader['raw']['compressed_size'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
251  18,
252  4));
253  $LocalFileHeader['raw']['uncompressed_size'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
254  22,
255  4));
256  $LocalFileHeader['raw']['filename_length'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
257  26,
258  2));
259  $LocalFileHeader['raw']['extra_field_length'] = Helper::LittleEndian2Int(substr($ZIPlocalFileHeader,
260  28,
261  2));
262 
263  $LocalFileHeader['extract_version'] = sprintf('%1.1f',
264  $LocalFileHeader['raw']['extract_version'] / 10);
265  $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8);
266  $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']);
267  $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size'];
268  $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size'];
269  $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'],
270  $LocalFileHeader['raw']['compression_method']);
271  $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'],
272  $LocalFileHeader['raw']['last_mod_file_time']);
273 
274  $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length'];
275  if ($FilenameExtrafieldLength > 0) {
276  $ZIPlocalFileHeader .= fread($this->getid3->fp,
277  $FilenameExtrafieldLength);
278 
279  if ($LocalFileHeader['raw']['filename_length'] > 0) {
280  $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30,
281  $LocalFileHeader['raw']['filename_length']);
282  }
283  if ($LocalFileHeader['raw']['extra_field_length'] > 0) {
284  $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader,
285  30 + $LocalFileHeader['raw']['filename_length'],
286  $LocalFileHeader['raw']['extra_field_length']);
287  }
288  }
289 
290  $LocalFileHeader['data_offset'] = ftell($this->getid3->fp);
291  //$LocalFileHeader['compressed_data'] = fread($this->getid3->fp, $LocalFileHeader['raw']['compressed_size']);
292  fseek($this->getid3->fp, $LocalFileHeader['raw']['compressed_size'],
293  SEEK_CUR);
294 
295  if ($LocalFileHeader['flags']['data_descriptor_used']) {
296  $DataDescriptor = fread($this->getid3->fp, 12);
297  $LocalFileHeader['data_descriptor']['crc_32'] = Helper::LittleEndian2Int(substr($DataDescriptor,
298  0,
299  4));
300  $LocalFileHeader['data_descriptor']['compressed_size'] = Helper::LittleEndian2Int(substr($DataDescriptor,
301  4,
302  4));
303  $LocalFileHeader['data_descriptor']['uncompressed_size'] = Helper::LittleEndian2Int(substr($DataDescriptor,
304  8,
305  4));
306  }
307 
308  return $LocalFileHeader;
309  }
static DOStime2UNIXtime($DOSdate, $DOStime)
Definition: Zip.php:570
fseek($bytes, $whence=SEEK_SET)
static ZIPversionOSLookup($index)
array $ZIPversionOSLookup
Definition: Zip.php:513
static LittleEndian2Int($byteword, $signed=false)
Definition: Helper.php:413
static ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod)
Definition: Zip.php:473
static ZIPcompressionMethodLookup($index)
array $ZIPcompressionMethodLookup
Definition: Zip.php:545
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPversionOSLookup()

static GetId3\Module\Archive\Zip::ZIPversionOSLookup (   $index)
static

array $ZIPversionOSLookup

Parameters
type$index
Returns
type

Definition at line 513 of file Zip.php.

References array.

Referenced by GetId3\Module\Archive\Zip\ZIPparseCentralDirectory(), and GetId3\Module\Archive\Zip\ZIPparseLocalFileHeader().

514  {
515  static $ZIPversionOSLookup = array(
516  0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
517  1 => 'Amiga',
518  2 => 'OpenVMS',
519  3 => 'Unix',
520  4 => 'VM/CMS',
521  5 => 'Atari ST',
522  6 => 'OS/2 H.P.F.S.',
523  7 => 'Macintosh',
524  8 => 'Z-System',
525  9 => 'CP/M',
526  10 => 'Windows NTFS',
527  11 => 'MVS',
528  12 => 'VSE',
529  13 => 'Acorn Risc',
530  14 => 'VFAT',
531  15 => 'Alternate MVS',
532  16 => 'BeOS',
533  17 => 'Tandem'
534  );
535 
536  return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]');
537  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: