7cb8719d2d82d53e4abd82a88fa32cf90282153d
3 /////////////////////////////////////////////////////////////////
4 /// getID3() by James Heinrich <info@getid3.org> //
5 // available at https://github.com/JamesHeinrich/getID3 //
6 // or https://www.getid3.org //
7 // or http://getid3.sourceforge.net //
8 // see readme.txt for more details //
9 /////////////////////////////////////////////////////////////////
11 // module.archive.zip.php //
12 // module for analyzing pkZip files //
13 // dependencies: NONE //
15 /////////////////////////////////////////////////////////////////
18 class getid3_zip
extends getid3_handler
23 public function Analyze() {
24 $info = &$this->getid3
->info
;
26 $info['fileformat'] = 'zip';
27 $info['zip']['encoding'] = 'ISO-8859-1';
28 $info['zip']['files'] = array();
30 $info['zip']['compressed_size'] = 0;
31 $info['zip']['uncompressed_size'] = 0;
32 $info['zip']['entries_count'] = 0;
34 if (!getid3_lib
::intValueSupported($info['filesize'])) {
35 $this->error('File is larger than '.round(PHP_INT_MAX
/ 1073741824).'GB, not supported by PHP');
39 $EOCDsearchCounter = 0;
40 while ($EOCDsearchCounter++
< 512) {
42 $this->fseek(-128 * $EOCDsearchCounter, SEEK_END
);
43 $EOCDsearchData = $this->fread(128).$EOCDsearchData;
45 if (strstr($EOCDsearchData, 'PK'."\x05\x06")) {
47 $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06");
48 $this->fseek((-128 * $EOCDsearchCounter) +
$EOCDposition, SEEK_END
);
49 $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory();
51 $this->fseek($info['zip']['end_central_directory']['directory_offset']);
52 $info['zip']['entries_count'] = 0;
53 while ($centraldirectoryentry = $this->ZIPparseCentralDirectory()) {
54 $info['zip']['central_directory'][] = $centraldirectoryentry;
55 $info['zip']['entries_count']++
;
56 $info['zip']['compressed_size'] +
= $centraldirectoryentry['compressed_size'];
57 $info['zip']['uncompressed_size'] +
= $centraldirectoryentry['uncompressed_size'];
59 //if ($centraldirectoryentry['uncompressed_size'] > 0) { zero-byte files are valid
60 if (!empty($centraldirectoryentry['filename'])) {
61 $info['zip']['files'] = getid3_lib
::array_merge_clobber($info['zip']['files'], getid3_lib
::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size']));
65 if ($info['zip']['entries_count'] == 0) {
66 $this->error('No Central Directory entries found (truncated file?)');
70 if (!empty($info['zip']['end_central_directory']['comment'])) {
71 $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
74 if (isset($info['zip']['central_directory'][0]['compression_method'])) {
75 $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method'];
77 if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) {
78 $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed'];
80 if (isset($info['zip']['compression_method']) && ($info['zip']['compression_method'] == 'store') && !isset($info['zip']['compression_speed'])) {
81 $info['zip']['compression_speed'] = 'store';
84 // secondary check - we (should) already have all the info we NEED from the Central Directory above, but scanning each
85 // Local File Header entry will
86 foreach ($info['zip']['central_directory'] as $central_directory_entry) {
87 $this->fseek($central_directory_entry['entry_offset']);
88 if ($fileentry = $this->ZIPparseLocalFileHeader()) {
89 $info['zip']['entries'][] = $fileentry;
91 $this->warning('Error parsing Local File Header at offset '.$central_directory_entry['entry_offset']);
95 if (!empty($info['zip']['files']['[Content_Types].xml']) &&
96 !empty($info['zip']['files']['_rels']['.rels']) &&
97 !empty($info['zip']['files']['docProps']['app.xml']) &&
98 !empty($info['zip']['files']['docProps']['core.xml'])) {
99 // http://technet.microsoft.com/en-us/library/cc179224.aspx
100 $info['fileformat'] = 'zip.msoffice';
101 if (!empty($ThisFileInfo['zip']['files']['ppt'])) {
102 $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
103 } elseif (!empty($ThisFileInfo['zip']['files']['xl'])) {
104 $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
105 } elseif (!empty($ThisFileInfo['zip']['files']['word'])) {
106 $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
115 if (!$this->getZIPentriesFilepointer()) {
117 $info['fileformat'] = '';
118 $this->error('Cannot find End Of Central Directory (truncated file?)');
122 // central directory couldn't be found and/or parsed
123 // scan through actual file data entries, recover as much as possible from probable trucated file
124 if ($info['zip']['compressed_size'] > ($info['filesize'] - 46 - 22)) {
125 $this->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)');
127 $this->error('Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete');
128 foreach ($info['zip']['entries'] as $key => $valuearray) {
129 $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size'];
137 public function getZIPHeaderFilepointerTopDown() {
138 $info = &$this->getid3
->info
;
140 $info['fileformat'] = 'zip';
142 $info['zip']['compressed_size'] = 0;
143 $info['zip']['uncompressed_size'] = 0;
144 $info['zip']['entries_count'] = 0;
146 rewind($this->getid3
->fp
);
147 while ($fileentry = $this->ZIPparseLocalFileHeader()) {
148 $info['zip']['entries'][] = $fileentry;
149 $info['zip']['entries_count']++
;
151 if ($info['zip']['entries_count'] == 0) {
152 $this->error('No Local File Header entries found');
156 $info['zip']['entries_count'] = 0;
157 while ($centraldirectoryentry = $this->ZIPparseCentralDirectory()) {
158 $info['zip']['central_directory'][] = $centraldirectoryentry;
159 $info['zip']['entries_count']++
;
160 $info['zip']['compressed_size'] +
= $centraldirectoryentry['compressed_size'];
161 $info['zip']['uncompressed_size'] +
= $centraldirectoryentry['uncompressed_size'];
163 if ($info['zip']['entries_count'] == 0) {
164 $this->error('No Central Directory entries found (truncated file?)');
168 if ($EOCD = $this->ZIPparseEndOfCentralDirectory()) {
169 $info['zip']['end_central_directory'] = $EOCD;
171 $this->error('No End Of Central Directory entry found (truncated file?)');
175 if (!empty($info['zip']['end_central_directory']['comment'])) {
176 $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
185 public function getZIPentriesFilepointer() {
186 $info = &$this->getid3
->info
;
188 $info['zip']['compressed_size'] = 0;
189 $info['zip']['uncompressed_size'] = 0;
190 $info['zip']['entries_count'] = 0;
192 rewind($this->getid3
->fp
);
193 while ($fileentry = $this->ZIPparseLocalFileHeader()) {
194 $info['zip']['entries'][] = $fileentry;
195 $info['zip']['entries_count']++
;
196 $info['zip']['compressed_size'] +
= $fileentry['compressed_size'];
197 $info['zip']['uncompressed_size'] +
= $fileentry['uncompressed_size'];
199 if ($info['zip']['entries_count'] == 0) {
200 $this->error('No Local File Header entries found');
208 * @return array|false
210 public function ZIPparseLocalFileHeader() {
211 $LocalFileHeader['offset'] = $this->ftell();
213 $ZIPlocalFileHeader = $this->fread(30);
215 $LocalFileHeader['raw']['signature'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4));
216 if ($LocalFileHeader['raw']['signature'] != 0x04034B50) { // "PK\x03\x04"
217 // invalid Local File Header Signature
218 $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly
221 $LocalFileHeader['raw']['extract_version'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2));
222 $LocalFileHeader['raw']['general_flags'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2));
223 $LocalFileHeader['raw']['compression_method'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2));
224 $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2));
225 $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2));
226 $LocalFileHeader['raw']['crc_32'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4));
227 $LocalFileHeader['raw']['compressed_size'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4));
228 $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4));
229 $LocalFileHeader['raw']['filename_length'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2));
230 $LocalFileHeader['raw']['extra_field_length'] = getid3_lib
::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2));
232 $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10);
233 $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8);
234 $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']);
235 $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size'];
236 $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size'];
237 $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']);
238 $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']);
240 $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] +
$LocalFileHeader['raw']['extra_field_length'];
241 if ($FilenameExtrafieldLength > 0) {
242 $ZIPlocalFileHeader .= $this->fread($FilenameExtrafieldLength);
244 if ($LocalFileHeader['raw']['filename_length'] > 0) {
245 $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']);
247 if ($LocalFileHeader['raw']['extra_field_length'] > 0) {
248 $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 +
$LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']);
252 if ($LocalFileHeader['compressed_size'] == 0) {
253 // *Could* be a zero-byte file
254 // But could also be a file written on the fly that didn't know compressed filesize beforehand.
255 // Correct compressed filesize should be in the data_descriptor located after this file data, and also in Central Directory (at end of zip file)
256 if (!empty($this->getid3
->info
['zip']['central_directory'])) {
257 foreach ($this->getid3
->info
['zip']['central_directory'] as $central_directory_entry) {
258 if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) {
259 if ($central_directory_entry['compressed_size'] > 0) {
260 // overwrite local zero value (but not ['raw']'compressed_size']) so that seeking for data_descriptor (and next file entry) works correctly
261 $LocalFileHeader['compressed_size'] = $central_directory_entry['compressed_size'];
269 $LocalFileHeader['data_offset'] = $this->ftell();
270 $this->fseek($LocalFileHeader['compressed_size'], SEEK_CUR
); // this should (but may not) match value in $LocalFileHeader['raw']['compressed_size'] -- $LocalFileHeader['compressed_size'] could have been overwritten above with value from Central Directory
272 if ($LocalFileHeader['flags']['data_descriptor_used']) {
273 $DataDescriptor = $this->fread(16);
274 $LocalFileHeader['data_descriptor']['signature'] = getid3_lib
::LittleEndian2Int(substr($DataDescriptor, 0, 4));
275 if ($LocalFileHeader['data_descriptor']['signature'] != 0x08074B50) { // "PK\x07\x08"
276 $this->getid3
->warning('invalid Local File Header Data Descriptor Signature at offset '.($this->ftell() - 16).' - expecting 08 07 4B 50, found '.getid3_lib
::PrintHexBytes($LocalFileHeader['data_descriptor']['signature']));
277 $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly
280 $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib
::LittleEndian2Int(substr($DataDescriptor, 4, 4));
281 $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib
::LittleEndian2Int(substr($DataDescriptor, 8, 4));
282 $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib
::LittleEndian2Int(substr($DataDescriptor, 12, 4));
283 if (!$LocalFileHeader['raw']['compressed_size'] && $LocalFileHeader['data_descriptor']['compressed_size']) {
284 foreach ($this->getid3
->info
['zip']['central_directory'] as $central_directory_entry) {
285 if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) {
286 if ($LocalFileHeader['data_descriptor']['compressed_size'] == $central_directory_entry['compressed_size']) {
287 // $LocalFileHeader['compressed_size'] already set from Central Directory
289 $this->warning('conflicting compressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['compressed_size'].') vs Central Directory ('.$central_directory_entry['compressed_size'].') for file at offset '.$LocalFileHeader['offset']);
292 if ($LocalFileHeader['data_descriptor']['uncompressed_size'] == $central_directory_entry['uncompressed_size']) {
293 $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['data_descriptor']['uncompressed_size'];
295 $this->warning('conflicting uncompressed_size from data_descriptor ('.$LocalFileHeader['data_descriptor']['uncompressed_size'].') vs Central Directory ('.$central_directory_entry['uncompressed_size'].') for file at offset '.$LocalFileHeader['offset']);
302 return $LocalFileHeader;
306 * @return array|false
308 public function ZIPparseCentralDirectory() {
309 $CentralDirectory['offset'] = $this->ftell();
311 $ZIPcentralDirectory = $this->fread(46);
313 $CentralDirectory['raw']['signature'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4));
314 if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
315 // invalid Central Directory Signature
316 $this->fseek($CentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly
319 $CentralDirectory['raw']['create_version'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2));
320 $CentralDirectory['raw']['extract_version'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2));
321 $CentralDirectory['raw']['general_flags'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2));
322 $CentralDirectory['raw']['compression_method'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2));
323 $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2));
324 $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2));
325 $CentralDirectory['raw']['crc_32'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4));
326 $CentralDirectory['raw']['compressed_size'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4));
327 $CentralDirectory['raw']['uncompressed_size'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4));
328 $CentralDirectory['raw']['filename_length'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2));
329 $CentralDirectory['raw']['extra_field_length'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2));
330 $CentralDirectory['raw']['file_comment_length'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2));
331 $CentralDirectory['raw']['disk_number_start'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2));
332 $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2));
333 $CentralDirectory['raw']['external_file_attrib'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4));
334 $CentralDirectory['raw']['local_header_offset'] = getid3_lib
::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4));
336 $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset'];
337 $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10);
338 $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10);
339 $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8);
340 $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']);
341 $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size'];
342 $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size'];
343 $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']);
344 $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']);
346 $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] +
$CentralDirectory['raw']['extra_field_length'] +
$CentralDirectory['raw']['file_comment_length'];
347 if ($FilenameExtrafieldCommentLength > 0) {
348 $FilenameExtrafieldComment = $this->fread($FilenameExtrafieldCommentLength);
350 if ($CentralDirectory['raw']['filename_length'] > 0) {
351 $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']);
353 if ($CentralDirectory['raw']['extra_field_length'] > 0) {
354 $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']);
356 if ($CentralDirectory['raw']['file_comment_length'] > 0) {
357 $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] +
$CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']);
361 return $CentralDirectory;
365 * @return array|false
367 public function ZIPparseEndOfCentralDirectory() {
368 $EndOfCentralDirectory['offset'] = $this->ftell();
370 $ZIPendOfCentralDirectory = $this->fread(22);
372 $EndOfCentralDirectory['signature'] = getid3_lib
::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
373 if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
374 // invalid End Of Central Directory Signature
375 $this->fseek($EndOfCentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly
378 $EndOfCentralDirectory['disk_number_current'] = getid3_lib
::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2));
379 $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib
::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2));
380 $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib
::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2));
381 $EndOfCentralDirectory['directory_entries_total'] = getid3_lib
::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2));
382 $EndOfCentralDirectory['directory_size'] = getid3_lib
::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4));
383 $EndOfCentralDirectory['directory_offset'] = getid3_lib
::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4));
384 $EndOfCentralDirectory['comment_length'] = getid3_lib
::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2));
386 if ($EndOfCentralDirectory['comment_length'] > 0) {
387 $EndOfCentralDirectory['comment'] = $this->fread($EndOfCentralDirectory['comment_length']);
390 return $EndOfCentralDirectory;
394 * @param int $flagbytes
395 * @param int $compressionmethod
399 public static function ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod) {
400 // https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip-printable.html
401 $ParsedFlags = array();
402 $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001);
403 // 0x0002 -- see below
404 // 0x0004 -- see below
405 $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
406 $ParsedFlags['enhanced_deflation'] = (bool) ($flagbytes & 0x0010);
407 $ParsedFlags['compressed_patched_data'] = (bool) ($flagbytes & 0x0020);
408 $ParsedFlags['strong_encryption'] = (bool) ($flagbytes & 0x0040);
413 $ParsedFlags['language_encoding'] = (bool) ($flagbytes & 0x0800);
415 $ParsedFlags['mask_header_values'] = (bool) ($flagbytes & 0x2000);
419 switch ($compressionmethod) {
421 $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ?
8192 : 4096);
422 $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ?
3 : 2);
427 switch (($flagbytes & 0x0006) >> 1) {
429 $ParsedFlags['compression_speed'] = 'normal';
432 $ParsedFlags['compression_speed'] = 'maximum';
435 $ParsedFlags['compression_speed'] = 'fast';
438 $ParsedFlags['compression_speed'] = 'superfast';
452 public static function ZIPversionOSLookup($index) {
453 static $ZIPversionOSLookup = array(
454 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
460 6 => 'OS/2 H.P.F.S.',
464 10 => 'Windows NTFS',
469 15 => 'Alternate MVS',
473 19 => 'OS/X (Darwin)',
476 return (isset($ZIPversionOSLookup[$index]) ?
$ZIPversionOSLookup[$index] : '[unknown]');
484 public static function ZIPcompressionMethodLookup($index) {
485 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/ZIP.html
486 static $ZIPcompressionMethodLookup = array(
497 10 => 'Imploded (old IBM TERSE)',
498 11 => 'RESERVED[11]',
500 13 => 'RESERVED[13]',
502 15 => 'RESERVED[15]',
503 16 => 'RESERVED[16]',
504 17 => 'RESERVED[17]',
505 18 => 'IBM TERSE (new)',
506 19 => 'IBM LZ77 z Architecture (PFS)',
507 96 => 'JPEG recompressed',
508 97 => 'WavPack compressed',
509 98 => 'PPMd version I, Rev 1',
512 return (isset($ZIPcompressionMethodLookup[$index]) ?
$ZIPcompressionMethodLookup[$index] : '[unknown]');
516 * @param int $DOSdate
517 * @param int $DOStime
521 public static function DOStime2UNIXtime($DOSdate, $DOStime) {
523 // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
525 // 0-4 Day of the month (1-31)
526 // 5-8 Month (1 = January, 2 = February, and so on)
527 // 9-15 Year offset from 1980 (add 1980 to get actual year)
529 $UNIXday = ($DOSdate & 0x001F);
530 $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
531 $UNIXyear = (($DOSdate & 0xFE00) >> 9) +
1980;
534 // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
536 // 0-4 Second divided by 2
537 // 5-10 Minute (0-59)
538 // 11-15 Hour (0-23 on a 24-hour clock)
540 $UNIXsecond = ($DOStime & 0x001F) * 2;
541 $UNIXminute = (($DOStime & 0x07E0) >> 5);
542 $UNIXhour = (($DOStime & 0xF800) >> 11);
544 return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);