ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
getid3_zip Class Reference

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

+ Inheritance diagram for getid3_zip:
+ Collaboration diagram for getid3_zip:

Public Member Functions

 getid3_zip (&$fd, &$ThisFileInfo)
 
 getZIPHeaderFilepointerTopDown (&$fd, &$ThisFileInfo)
 
 getZIPentriesFilepointer (&$fd, &$ThisFileInfo)
 
 ZIPparseLocalFileHeader (&$fd)
 
 ZIPparseCentralDirectory (&$fd)
 
 ZIPparseEndOfCentralDirectory (&$fd)
 
 ZIPparseGeneralPurposeFlags ($flagbytes, $compressionmethod)
 
 ZIPversionOSLookup ($index)
 
 ZIPcompressionMethodLookup ($index)
 
 DOStime2UNIXtime ($DOSdate, $DOStime)
 
 Analyze ()
 
 getZIPHeaderFilepointerTopDown ()
 
 getZIPentriesFilepointer ()
 
 ZIPparseLocalFileHeader ()
 
 ZIPparseCentralDirectory ()
 
 ZIPparseEndOfCentralDirectory ()
 
- Public Member Functions inherited from getid3_handler
 __construct (getID3 $getid3, $call_module=null)
 
 Analyze ()
 
 AnalyzeString ($string)
 
 setStringMode ($string)
 
 saveAttachment ($name, $offset, $length, $image_mime=null)
 

Static Public Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from getid3_handler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
 notice ($text)
 
- Protected Attributes inherited from getid3_handler
 $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 //

Definition at line 17 of file module.archive.zip.php.

Member Function Documentation

◆ Analyze()

getid3_zip::Analyze ( )

Reimplemented from getid3_handler.

Definition at line 21 of file module.archive.zip.php.

21 {
22 $info = &$this->getid3->info;
23
24 $info['fileformat'] = 'zip';
25 $info['zip']['encoding'] = 'ISO-8859-1';
26 $info['zip']['files'] = array();
27
28 $info['zip']['compressed_size'] = 0;
29 $info['zip']['uncompressed_size'] = 0;
30 $info['zip']['entries_count'] = 0;
31
32 if (!getid3_lib::intValueSupported($info['filesize'])) {
33 $info['error'][] = 'File is larger than '.round(PHP_INT_MAX / 1073741824).'GB, not supported by PHP';
34 return false;
35 } else {
36 $EOCDsearchData = '';
37 $EOCDsearchCounter = 0;
38 while ($EOCDsearchCounter++ < 512) {
39
40 $this->fseek(-128 * $EOCDsearchCounter, SEEK_END);
41 $EOCDsearchData = $this->fread(128).$EOCDsearchData;
42
43 if (strstr($EOCDsearchData, 'PK'."\x05\x06")) {
44
45 $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06");
46 $this->fseek((-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
47 $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory();
48
49 $this->fseek($info['zip']['end_central_directory']['directory_offset']);
50 $info['zip']['entries_count'] = 0;
51 while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) {
52 $info['zip']['central_directory'][] = $centraldirectoryentry;
53 $info['zip']['entries_count']++;
54 $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
55 $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
56
57 //if ($centraldirectoryentry['uncompressed_size'] > 0) { zero-byte files are valid
58 if (!empty($centraldirectoryentry['filename'])) {
59 $info['zip']['files'] = getid3_lib::array_merge_clobber($info['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size']));
60 }
61 }
62
63 if ($info['zip']['entries_count'] == 0) {
64 $info['error'][] = 'No Central Directory entries found (truncated file?)';
65 return false;
66 }
67
68 if (!empty($info['zip']['end_central_directory']['comment'])) {
69 $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment'];
70 }
71
72 if (isset($info['zip']['central_directory'][0]['compression_method'])) {
73 $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method'];
74 }
75 if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) {
76 $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed'];
77 }
78 if (isset($info['zip']['compression_method']) && ($info['zip']['compression_method'] == 'store') && !isset($info['zip']['compression_speed'])) {
79 $info['zip']['compression_speed'] = 'store';
80 }
81
82 // secondary check - we (should) already have all the info we NEED from the Central Directory above, but scanning each
83 // Local File Header entry will
84 foreach ($info['zip']['central_directory'] as $central_directory_entry) {
85 $this->fseek($central_directory_entry['entry_offset']);
86 if ($fileentry = $this->ZIPparseLocalFileHeader()) {
87 $info['zip']['entries'][] = $fileentry;
88 } else {
89 $info['warning'][] = 'Error parsing Local File Header at offset '.$central_directory_entry['entry_offset'];
90 }
91 }
92
93 if (!empty($info['zip']['files']['[Content_Types].xml']) &&
94 !empty($info['zip']['files']['_rels']['.rels']) &&
95 !empty($info['zip']['files']['docProps']['app.xml']) &&
96 !empty($info['zip']['files']['docProps']['core.xml'])) {
97 // http://technet.microsoft.com/en-us/library/cc179224.aspx
98 $info['fileformat'] = 'zip.msoffice';
99 if (!empty($ThisFileInfo['zip']['files']['ppt'])) {
100 $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
101 } elseif (!empty($ThisFileInfo['zip']['files']['xl'])) {
102 $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
103 } elseif (!empty($ThisFileInfo['zip']['files']['word'])) {
104 $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
105 }
106 }
107
108 return true;
109 }
110 }
111 }
112
113 if (!$this->getZIPentriesFilepointer()) {
114 unset($info['zip']);
115 $info['fileformat'] = '';
116 $info['error'][] = 'Cannot find End Of Central Directory (truncated file?)';
117 return false;
118 }
119
120 // central directory couldn't be found and/or parsed
121 // scan through actual file data entries, recover as much as possible from probable trucated file
122 if ($info['zip']['compressed_size'] > ($info['filesize'] - 46 - 22)) {
123 $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)';
124 }
125 $info['error'][] = 'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete';
126 foreach ($info['zip']['entries'] as $key => $valuearray) {
127 $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size'];
128 }
129 return true;
130 }
fseek($bytes, $whence=SEEK_SET)
Definition: getid3.php:1697
fread($bytes)
Definition: getid3.php:1685
CreateDeepArray($ArrayPath, $Separator, $Value)
Definition: getid3.lib.php:465
static intValueSupported($num)
Definition: getid3.lib.php:80
array_merge_clobber($array1, $array2)
Definition: getid3.lib.php:358
$info
Definition: example_052.php:80

References $info, getid3_lib\array_merge_clobber(), getid3_lib\CreateDeepArray(), getid3_handler\fread(), getid3_handler\fseek(), getZIPentriesFilepointer(), getid3_lib\intValueSupported(), ZIPparseCentralDirectory(), ZIPparseEndOfCentralDirectory(), and ZIPparseLocalFileHeader().

+ Here is the call graph for this function:

◆ DOStime2UNIXtime() [1/2]

getid3_zip::DOStime2UNIXtime (   $DOSdate,
  $DOStime 
)

Definition at line 386 of file module.archive.zip.php.

386 {
387 // wFatDate
388 // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
389 // Bits Contents
390 // 0-4 Day of the month (1-31)
391 // 5-8 Month (1 = January, 2 = February, and so on)
392 // 9-15 Year offset from 1980 (add 1980 to get actual year)
393
394 $UNIXday = ($DOSdate & 0x001F);
395 $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
396 $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
397
398 // wFatTime
399 // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
400 // Bits Contents
401 // 0-4 Second divided by 2
402 // 5-10 Minute (0-59)
403 // 11-15 Hour (0-23 on a 24-hour clock)
404
405 $UNIXsecond = ($DOStime & 0x001F) * 2;
406 $UNIXminute = (($DOStime & 0x07E0) >> 5);
407 $UNIXhour = (($DOStime & 0xF800) >> 11);
408
409 return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
410 }

Referenced by ZIPparseCentralDirectory(), and ZIPparseLocalFileHeader().

+ Here is the caller graph for this function:

◆ DOStime2UNIXtime() [2/2]

static getid3_zip::DOStime2UNIXtime (   $DOSdate,
  $DOStime 
)
static

Definition at line 487 of file module.archive.zip.php.

487 {
488 // wFatDate
489 // Specifies the MS-DOS date. The date is a packed 16-bit value with the following format:
490 // Bits Contents
491 // 0-4 Day of the month (1-31)
492 // 5-8 Month (1 = January, 2 = February, and so on)
493 // 9-15 Year offset from 1980 (add 1980 to get actual year)
494
495 $UNIXday = ($DOSdate & 0x001F);
496 $UNIXmonth = (($DOSdate & 0x01E0) >> 5);
497 $UNIXyear = (($DOSdate & 0xFE00) >> 9) + 1980;
498
499 // wFatTime
500 // Specifies the MS-DOS time. The time is a packed 16-bit value with the following format:
501 // Bits Contents
502 // 0-4 Second divided by 2
503 // 5-10 Minute (0-59)
504 // 11-15 Hour (0-23 on a 24-hour clock)
505
506 $UNIXsecond = ($DOStime & 0x001F) * 2;
507 $UNIXminute = (($DOStime & 0x07E0) >> 5);
508 $UNIXhour = (($DOStime & 0xF800) >> 11);
509
510 return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
511 }

◆ getid3_zip()

getid3_zip::getid3_zip ( $fd,
$ThisFileInfo 
)

Definition at line 20 of file module.archive.zip.php.

20 {
21
22 $ThisFileInfo['fileformat'] = 'zip';
23 $ThisFileInfo['zip']['encoding'] = 'ISO-8859-1';
24 $ThisFileInfo['zip']['files'] = array();
25
26 $ThisFileInfo['zip']['compressed_size'] = 0;
27 $ThisFileInfo['zip']['uncompressed_size'] = 0;
28 $ThisFileInfo['zip']['entries_count'] = 0;
29
30 $EOCDsearchData = '';
31 $EOCDsearchCounter = 0;
32 while ($EOCDsearchCounter++ < 512) {
33
34 fseek($fd, -128 * $EOCDsearchCounter, SEEK_END);
35 $EOCDsearchData = fread($fd, 128).$EOCDsearchData;
36
37 if (strstr($EOCDsearchData, 'PK'."\x05\x06")) {
38
39 $EOCDposition = strpos($EOCDsearchData, 'PK'."\x05\x06");
40 fseek($fd, (-128 * $EOCDsearchCounter) + $EOCDposition, SEEK_END);
41 $ThisFileInfo['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory($fd);
42
43 fseek($fd, $ThisFileInfo['zip']['end_central_directory']['directory_offset'], SEEK_SET);
44 $ThisFileInfo['zip']['entries_count'] = 0;
45 while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($fd)) {
46 $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry;
47 $ThisFileInfo['zip']['entries_count']++;
48 $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
49 $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
50
51 if ($centraldirectoryentry['uncompressed_size'] > 0) {
52 $ThisFileInfo['zip']['files'] = getid3_lib::array_merge_clobber($ThisFileInfo['zip']['files'], getid3_lib::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size']));
53 }
54 }
55
56 if ($ThisFileInfo['zip']['entries_count'] == 0) {
57 $ThisFileInfo['error'][] = 'No Central Directory entries found (truncated file?)';
58 return false;
59 }
60
61 if (!empty($ThisFileInfo['zip']['end_central_directory']['comment'])) {
62 $ThisFileInfo['zip']['comments']['comment'][] = $ThisFileInfo['zip']['end_central_directory']['comment'];
63 }
64
65 if (isset($ThisFileInfo['zip']['central_directory'][0]['compression_method'])) {
66 $ThisFileInfo['zip']['compression_method'] = $ThisFileInfo['zip']['central_directory'][0]['compression_method'];
67 }
68 if (isset($ThisFileInfo['zip']['central_directory'][0]['flags']['compression_speed'])) {
69 $ThisFileInfo['zip']['compression_speed'] = $ThisFileInfo['zip']['central_directory'][0]['flags']['compression_speed'];
70 }
71 if (isset($ThisFileInfo['zip']['compression_method']) && ($ThisFileInfo['zip']['compression_method'] == 'store') && !isset($ThisFileInfo['zip']['compression_speed'])) {
72 $ThisFileInfo['zip']['compression_speed'] = 'store';
73 }
74
75 return true;
76
77 }
78
79 }
80
81 if ($this->getZIPentriesFilepointer($fd, $ThisFileInfo)) {
82
83 // central directory couldn't be found and/or parsed
84 // scan through actual file data entries, recover as much as possible from probable trucated file
85 if ($ThisFileInfo['zip']['compressed_size'] > ($ThisFileInfo['filesize'] - 46 - 22)) {
86 $ThisFileInfo['error'][] = 'Warning: Truncated file! - Total compressed file sizes ('.$ThisFileInfo['zip']['compressed_size'].' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures ('.($ThisFileInfo['filesize'] - 46 - 22).' bytes)';
87 }
88 $ThisFileInfo['error'][] = 'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete';
89 foreach ($ThisFileInfo['zip']['entries'] as $key => $valuearray) {
90 $ThisFileInfo['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size'];
91 }
92 return true;
93
94 } else {
95
96 unset($ThisFileInfo['zip']);
97 $ThisFileInfo['fileformat'] = '';
98 $ThisFileInfo['error'][] = 'Cannot find End Of Central Directory (truncated file?)';
99 return false;
100
101 }
102 }

References getid3_lib\array_merge_clobber(), getid3_lib\CreateDeepArray(), getid3_handler\fread(), getid3_handler\fseek(), getZIPentriesFilepointer(), ZIPparseCentralDirectory(), and ZIPparseEndOfCentralDirectory().

+ Here is the call graph for this function:

◆ getZIPentriesFilepointer() [1/2]

getid3_zip::getZIPentriesFilepointer ( $fd,
$ThisFileInfo 
)

Definition at line 149 of file module.archive.zip.php.

149 {
150 $ThisFileInfo['zip']['compressed_size'] = 0;
151 $ThisFileInfo['zip']['uncompressed_size'] = 0;
152 $ThisFileInfo['zip']['entries_count'] = 0;
153
154 rewind($fd);
155 while ($fileentry = $this->ZIPparseLocalFileHeader($fd)) {
156 $ThisFileInfo['zip']['entries'][] = $fileentry;
157 $ThisFileInfo['zip']['entries_count']++;
158 $ThisFileInfo['zip']['compressed_size'] += $fileentry['compressed_size'];
159 $ThisFileInfo['zip']['uncompressed_size'] += $fileentry['uncompressed_size'];
160 }
161 if ($ThisFileInfo['zip']['entries_count'] == 0) {
162 $ThisFileInfo['error'][] = 'No Local File Header entries found';
163 return false;
164 }
165
166 return true;
167 }

References ZIPparseLocalFileHeader().

+ Here is the call graph for this function:

◆ getZIPentriesFilepointer() [2/2]

getid3_zip::getZIPentriesFilepointer ( )

Definition at line 179 of file module.archive.zip.php.

179 {
180 $info = &$this->getid3->info;
181
182 $info['zip']['compressed_size'] = 0;
183 $info['zip']['uncompressed_size'] = 0;
184 $info['zip']['entries_count'] = 0;
185
186 rewind($this->getid3->fp);
187 while ($fileentry = $this->ZIPparseLocalFileHeader()) {
188 $info['zip']['entries'][] = $fileentry;
189 $info['zip']['entries_count']++;
190 $info['zip']['compressed_size'] += $fileentry['compressed_size'];
191 $info['zip']['uncompressed_size'] += $fileentry['uncompressed_size'];
192 }
193 if ($info['zip']['entries_count'] == 0) {
194 $info['error'][] = 'No Local File Header entries found';
195 return false;
196 }
197
198 return true;
199 }

References $info, and ZIPparseLocalFileHeader().

Referenced by Analyze(), and getid3_zip().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getZIPHeaderFilepointerTopDown() [1/2]

getid3_zip::getZIPHeaderFilepointerTopDown ( $fd,
$ThisFileInfo 
)

Definition at line 105 of file module.archive.zip.php.

105 {
106 $ThisFileInfo['fileformat'] = 'zip';
107
108 $ThisFileInfo['zip']['compressed_size'] = 0;
109 $ThisFileInfo['zip']['uncompressed_size'] = 0;
110 $ThisFileInfo['zip']['entries_count'] = 0;
111
112 rewind($fd);
113 while ($fileentry = $this->ZIPparseLocalFileHeader($fd)) {
114 $ThisFileInfo['zip']['entries'][] = $fileentry;
115 $ThisFileInfo['zip']['entries_count']++;
116 }
117 if ($ThisFileInfo['zip']['entries_count'] == 0) {
118 $ThisFileInfo['error'][] = 'No Local File Header entries found';
119 return false;
120 }
121
122 $ThisFileInfo['zip']['entries_count'] = 0;
123 while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($fd)) {
124 $ThisFileInfo['zip']['central_directory'][] = $centraldirectoryentry;
125 $ThisFileInfo['zip']['entries_count']++;
126 $ThisFileInfo['zip']['compressed_size'] += $centraldirectoryentry['compressed_size'];
127 $ThisFileInfo['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size'];
128 }
129 if ($ThisFileInfo['zip']['entries_count'] == 0) {
130 $ThisFileInfo['error'][] = 'No Central Directory entries found (truncated file?)';
131 return false;
132 }
133
134 if ($EOCD = $this->ZIPparseEndOfCentralDirectory($fd)) {
135 $ThisFileInfo['zip']['end_central_directory'] = $EOCD;
136 } else {
137 $ThisFileInfo['error'][] = 'No End Of Central Directory entry found (truncated file?)';
138 return false;
139 }
140
141 if (!empty($ThisFileInfo['zip']['end_central_directory']['comment'])) {
142 $ThisFileInfo['zip']['comments']['comment'][] = $ThisFileInfo['zip']['end_central_directory']['comment'];
143 }
144
145 return true;
146 }

References ZIPparseCentralDirectory(), ZIPparseEndOfCentralDirectory(), and ZIPparseLocalFileHeader().

+ Here is the call graph for this function:

◆ getZIPHeaderFilepointerTopDown() [2/2]

getid3_zip::getZIPHeaderFilepointerTopDown ( )

Definition at line 133 of file module.archive.zip.php.

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

References $info, ZIPparseCentralDirectory(), ZIPparseEndOfCentralDirectory(), and ZIPparseLocalFileHeader().

+ Here is the call graph for this function:

◆ ZIPcompressionMethodLookup() [1/2]

getid3_zip::ZIPcompressionMethodLookup (   $index)

Definition at line 368 of file module.archive.zip.php.

368 {
369 static $ZIPcompressionMethodLookup = array(
370 0 => 'store',
371 1 => 'shrink',
372 2 => 'reduce-1',
373 3 => 'reduce-2',
374 4 => 'reduce-3',
375 5 => 'reduce-4',
376 6 => 'implode',
377 7 => 'tokenize',
378 8 => 'deflate',
379 9 => 'deflate64',
380 10 => 'PKWARE Date Compression Library Imploding'
381 );
382
383 return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]');
384 }

Referenced by ZIPparseCentralDirectory(), and ZIPparseLocalFileHeader().

+ Here is the caller graph for this function:

◆ ZIPcompressionMethodLookup() [2/2]

static getid3_zip::ZIPcompressionMethodLookup (   $index)
static

Definition at line 456 of file module.archive.zip.php.

456 {
457 // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/ZIP.html
458 static $ZIPcompressionMethodLookup = array(
459 0 => 'store',
460 1 => 'shrink',
461 2 => 'reduce-1',
462 3 => 'reduce-2',
463 4 => 'reduce-3',
464 5 => 'reduce-4',
465 6 => 'implode',
466 7 => 'tokenize',
467 8 => 'deflate',
468 9 => 'deflate64',
469 10 => 'Imploded (old IBM TERSE)',
470 11 => 'RESERVED[11]',
471 12 => 'BZIP2',
472 13 => 'RESERVED[13]',
473 14 => 'LZMA (EFS)',
474 15 => 'RESERVED[15]',
475 16 => 'RESERVED[16]',
476 17 => 'RESERVED[17]',
477 18 => 'IBM TERSE (new)',
478 19 => 'IBM LZ77 z Architecture (PFS)',
479 96 => 'JPEG recompressed',
480 97 => 'WavPack compressed',
481 98 => 'PPMd version I, Rev 1',
482 );
483
484 return (isset($ZIPcompressionMethodLookup[$index]) ? $ZIPcompressionMethodLookup[$index] : '[unknown]');
485 }

◆ ZIPparseCentralDirectory() [1/2]

getid3_zip::ZIPparseCentralDirectory ( $fd)

Definition at line 227 of file module.archive.zip.php.

227 {
228 $CentralDirectory['offset'] = ftell($fd);
229
230 $ZIPcentralDirectory = fread($fd, 46);
231
232 $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4));
233 if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
234 // invalid Central Directory Signature
235 fseek($fd, $CentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
236 return false;
237 }
238 $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2));
239 $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2));
240 $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2));
241 $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2));
242 $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2));
243 $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2));
244 $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4));
245 $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4));
246 $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4));
247 $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2));
248 $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2));
249 $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2));
250 $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2));
251 $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2));
252 $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4));
253 $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4));
254
255 $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset'];
256 $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10);
257 $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10);
258 $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8);
259 $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']);
260 $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size'];
261 $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size'];
262 $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']);
263 $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']);
264
265 $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length'];
266 if ($FilenameExtrafieldCommentLength > 0) {
267 $FilenameExtrafieldComment = fread($fd, $FilenameExtrafieldCommentLength);
268
269 if ($CentralDirectory['raw']['filename_length'] > 0) {
270 $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']);
271 }
272 if ($CentralDirectory['raw']['extra_field_length'] > 0) {
273 $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']);
274 }
275 if ($CentralDirectory['raw']['file_comment_length'] > 0) {
276 $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']);
277 }
278 }
279
280 return $CentralDirectory;
281 }
LittleEndian2Int($byteword, $signed=false)
Definition: getid3.lib.php:266
ZIPparseGeneralPurposeFlags($flagbytes, $compressionmethod)
ZIPversionOSLookup($index)
ZIPcompressionMethodLookup($index)
DOStime2UNIXtime($DOSdate, $DOStime)

References DOStime2UNIXtime(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), ZIPcompressionMethodLookup(), ZIPparseGeneralPurposeFlags(), and ZIPversionOSLookup().

+ Here is the call graph for this function:

◆ ZIPparseCentralDirectory() [2/2]

getid3_zip::ZIPparseCentralDirectory ( )

Definition at line 298 of file module.archive.zip.php.

298 {
299 $CentralDirectory['offset'] = $this->ftell();
300
301 $ZIPcentralDirectory = $this->fread(46);
302
303 $CentralDirectory['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 0, 4));
304 if ($CentralDirectory['raw']['signature'] != 0x02014B50) {
305 // invalid Central Directory Signature
306 $this->fseek($CentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly
307 return false;
308 }
309 $CentralDirectory['raw']['create_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 4, 2));
310 $CentralDirectory['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 6, 2));
311 $CentralDirectory['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 8, 2));
312 $CentralDirectory['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 10, 2));
313 $CentralDirectory['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 12, 2));
314 $CentralDirectory['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 14, 2));
315 $CentralDirectory['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 16, 4));
316 $CentralDirectory['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 20, 4));
317 $CentralDirectory['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 24, 4));
318 $CentralDirectory['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 28, 2));
319 $CentralDirectory['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 30, 2));
320 $CentralDirectory['raw']['file_comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 32, 2));
321 $CentralDirectory['raw']['disk_number_start'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 34, 2));
322 $CentralDirectory['raw']['internal_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 36, 2));
323 $CentralDirectory['raw']['external_file_attrib'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 38, 4));
324 $CentralDirectory['raw']['local_header_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPcentralDirectory, 42, 4));
325
326 $CentralDirectory['entry_offset'] = $CentralDirectory['raw']['local_header_offset'];
327 $CentralDirectory['create_version'] = sprintf('%1.1f', $CentralDirectory['raw']['create_version'] / 10);
328 $CentralDirectory['extract_version'] = sprintf('%1.1f', $CentralDirectory['raw']['extract_version'] / 10);
329 $CentralDirectory['host_os'] = $this->ZIPversionOSLookup(($CentralDirectory['raw']['extract_version'] & 0xFF00) >> 8);
330 $CentralDirectory['compression_method'] = $this->ZIPcompressionMethodLookup($CentralDirectory['raw']['compression_method']);
331 $CentralDirectory['compressed_size'] = $CentralDirectory['raw']['compressed_size'];
332 $CentralDirectory['uncompressed_size'] = $CentralDirectory['raw']['uncompressed_size'];
333 $CentralDirectory['flags'] = $this->ZIPparseGeneralPurposeFlags($CentralDirectory['raw']['general_flags'], $CentralDirectory['raw']['compression_method']);
334 $CentralDirectory['last_modified_timestamp'] = $this->DOStime2UNIXtime($CentralDirectory['raw']['last_mod_file_date'], $CentralDirectory['raw']['last_mod_file_time']);
335
336 $FilenameExtrafieldCommentLength = $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'] + $CentralDirectory['raw']['file_comment_length'];
337 if ($FilenameExtrafieldCommentLength > 0) {
338 $FilenameExtrafieldComment = $this->fread($FilenameExtrafieldCommentLength);
339
340 if ($CentralDirectory['raw']['filename_length'] > 0) {
341 $CentralDirectory['filename'] = substr($FilenameExtrafieldComment, 0, $CentralDirectory['raw']['filename_length']);
342 }
343 if ($CentralDirectory['raw']['extra_field_length'] > 0) {
344 $CentralDirectory['raw']['extra_field_data'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'], $CentralDirectory['raw']['extra_field_length']);
345 }
346 if ($CentralDirectory['raw']['file_comment_length'] > 0) {
347 $CentralDirectory['file_comment'] = substr($FilenameExtrafieldComment, $CentralDirectory['raw']['filename_length'] + $CentralDirectory['raw']['extra_field_length'], $CentralDirectory['raw']['file_comment_length']);
348 }
349 }
350
351 return $CentralDirectory;
352 }

References DOStime2UNIXtime(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), ZIPcompressionMethodLookup(), ZIPparseGeneralPurposeFlags(), and ZIPversionOSLookup().

Referenced by Analyze(), getid3_zip(), and getZIPHeaderFilepointerTopDown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPparseEndOfCentralDirectory() [1/2]

getid3_zip::ZIPparseEndOfCentralDirectory ( $fd)

Definition at line 283 of file module.archive.zip.php.

283 {
284 $EndOfCentralDirectory['offset'] = ftell($fd);
285
286 $ZIPendOfCentralDirectory = fread($fd, 22);
287
288 $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
289 if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
290 // invalid End Of Central Directory Signature
291 fseek($fd, $EndOfCentralDirectory['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
292 return false;
293 }
294 $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2));
295 $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2));
296 $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2));
297 $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2));
298 $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4));
299 $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4));
300 $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2));
301
302 if ($EndOfCentralDirectory['comment_length'] > 0) {
303 $EndOfCentralDirectory['comment'] = fread($fd, $EndOfCentralDirectory['comment_length']);
304 }
305
306 return $EndOfCentralDirectory;
307 }

References getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), and getid3_lib\LittleEndian2Int().

+ Here is the call graph for this function:

◆ ZIPparseEndOfCentralDirectory() [2/2]

getid3_zip::ZIPparseEndOfCentralDirectory ( )

Definition at line 354 of file module.archive.zip.php.

354 {
355 $EndOfCentralDirectory['offset'] = $this->ftell();
356
357 $ZIPendOfCentralDirectory = $this->fread(22);
358
359 $EndOfCentralDirectory['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 0, 4));
360 if ($EndOfCentralDirectory['signature'] != 0x06054B50) {
361 // invalid End Of Central Directory Signature
362 $this->fseek($EndOfCentralDirectory['offset']); // seek back to where filepointer originally was so it can be handled properly
363 return false;
364 }
365 $EndOfCentralDirectory['disk_number_current'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 4, 2));
366 $EndOfCentralDirectory['disk_number_start_directory'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 6, 2));
367 $EndOfCentralDirectory['directory_entries_this_disk'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 8, 2));
368 $EndOfCentralDirectory['directory_entries_total'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 10, 2));
369 $EndOfCentralDirectory['directory_size'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 12, 4));
370 $EndOfCentralDirectory['directory_offset'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 16, 4));
371 $EndOfCentralDirectory['comment_length'] = getid3_lib::LittleEndian2Int(substr($ZIPendOfCentralDirectory, 20, 2));
372
373 if ($EndOfCentralDirectory['comment_length'] > 0) {
374 $EndOfCentralDirectory['comment'] = $this->fread($EndOfCentralDirectory['comment_length']);
375 }
376
377 return $EndOfCentralDirectory;
378 }

References getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), and getid3_lib\LittleEndian2Int().

Referenced by Analyze(), getid3_zip(), and getZIPHeaderFilepointerTopDown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPparseGeneralPurposeFlags() [1/2]

getid3_zip::ZIPparseGeneralPurposeFlags (   $flagbytes,
  $compressionmethod 
)

Definition at line 310 of file module.archive.zip.php.

310 {
311 $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001);
312
313 switch ($compressionmethod) {
314 case 6:
315 $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096);
316 $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2);
317 break;
318
319 case 8:
320 case 9:
321 switch (($flagbytes & 0x0006) >> 1) {
322 case 0:
323 $ParsedFlags['compression_speed'] = 'normal';
324 break;
325 case 1:
326 $ParsedFlags['compression_speed'] = 'maximum';
327 break;
328 case 2:
329 $ParsedFlags['compression_speed'] = 'fast';
330 break;
331 case 3:
332 $ParsedFlags['compression_speed'] = 'superfast';
333 break;
334 }
335 break;
336 }
337 $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
338
339 return $ParsedFlags;
340 }

Referenced by ZIPparseCentralDirectory(), and ZIPparseLocalFileHeader().

+ Here is the caller graph for this function:

◆ ZIPparseGeneralPurposeFlags() [2/2]

static getid3_zip::ZIPparseGeneralPurposeFlags (   $flagbytes,
  $compressionmethod 
)
static

Definition at line 381 of file module.archive.zip.php.

381 {
382 // https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip-printable.html
383 $ParsedFlags['encrypted'] = (bool) ($flagbytes & 0x0001);
384 // 0x0002 -- see below
385 // 0x0004 -- see below
386 $ParsedFlags['data_descriptor_used'] = (bool) ($flagbytes & 0x0008);
387 $ParsedFlags['enhanced_deflation'] = (bool) ($flagbytes & 0x0010);
388 $ParsedFlags['compressed_patched_data'] = (bool) ($flagbytes & 0x0020);
389 $ParsedFlags['strong_encryption'] = (bool) ($flagbytes & 0x0040);
390 // 0x0080 - unused
391 // 0x0100 - unused
392 // 0x0200 - unused
393 // 0x0400 - unused
394 $ParsedFlags['language_encoding'] = (bool) ($flagbytes & 0x0800);
395 // 0x1000 - reserved
396 $ParsedFlags['mask_header_values'] = (bool) ($flagbytes & 0x2000);
397 // 0x4000 - reserved
398 // 0x8000 - reserved
399
400 switch ($compressionmethod) {
401 case 6:
402 $ParsedFlags['dictionary_size'] = (($flagbytes & 0x0002) ? 8192 : 4096);
403 $ParsedFlags['shannon_fano_trees'] = (($flagbytes & 0x0004) ? 3 : 2);
404 break;
405
406 case 8:
407 case 9:
408 switch (($flagbytes & 0x0006) >> 1) {
409 case 0:
410 $ParsedFlags['compression_speed'] = 'normal';
411 break;
412 case 1:
413 $ParsedFlags['compression_speed'] = 'maximum';
414 break;
415 case 2:
416 $ParsedFlags['compression_speed'] = 'fast';
417 break;
418 case 3:
419 $ParsedFlags['compression_speed'] = 'superfast';
420 break;
421 }
422 break;
423 }
424
425 return $ParsedFlags;
426 }

◆ ZIPparseLocalFileHeader() [1/2]

getid3_zip::ZIPparseLocalFileHeader ( $fd)

Definition at line 170 of file module.archive.zip.php.

170 {
171 $LocalFileHeader['offset'] = ftell($fd);
172
173 $ZIPlocalFileHeader = fread($fd, 30);
174
175 $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4));
176 if ($LocalFileHeader['raw']['signature'] != 0x04034B50) {
177 // invalid Local File Header Signature
178 fseek($fd, $LocalFileHeader['offset'], SEEK_SET); // seek back to where filepointer originally was so it can be handled properly
179 return false;
180 }
181 $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2));
182 $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2));
183 $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2));
184 $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2));
185 $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2));
186 $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4));
187 $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4));
188 $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4));
189 $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2));
190 $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2));
191
192 $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10);
193 $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8);
194 $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']);
195 $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size'];
196 $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size'];
197 $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']);
198 $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']);
199
200 $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length'];
201 if ($FilenameExtrafieldLength > 0) {
202 $ZIPlocalFileHeader .= fread($fd, $FilenameExtrafieldLength);
203
204 if ($LocalFileHeader['raw']['filename_length'] > 0) {
205 $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']);
206 }
207 if ($LocalFileHeader['raw']['extra_field_length'] > 0) {
208 $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']);
209 }
210 }
211
212 $LocalFileHeader['data_offset'] = ftell($fd);
213 //$LocalFileHeader['compressed_data'] = fread($fd, $LocalFileHeader['raw']['compressed_size']);
214 fseek($fd, $LocalFileHeader['raw']['compressed_size'], SEEK_CUR);
215
216 if ($LocalFileHeader['flags']['data_descriptor_used']) {
217 $DataDescriptor = fread($fd, 12);
218 $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4));
219 $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4));
220 $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4));
221 }
222
223 return $LocalFileHeader;
224 }

References DOStime2UNIXtime(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), ZIPcompressionMethodLookup(), ZIPparseGeneralPurposeFlags(), and ZIPversionOSLookup().

+ Here is the call graph for this function:

◆ ZIPparseLocalFileHeader() [2/2]

getid3_zip::ZIPparseLocalFileHeader ( )

Definition at line 202 of file module.archive.zip.php.

202 {
203 $LocalFileHeader['offset'] = $this->ftell();
204
205 $ZIPlocalFileHeader = $this->fread(30);
206
207 $LocalFileHeader['raw']['signature'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 0, 4));
208 if ($LocalFileHeader['raw']['signature'] != 0x04034B50) { // "PK\x03\x04"
209 // invalid Local File Header Signature
210 $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly
211 return false;
212 }
213 $LocalFileHeader['raw']['extract_version'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 4, 2));
214 $LocalFileHeader['raw']['general_flags'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 6, 2));
215 $LocalFileHeader['raw']['compression_method'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 8, 2));
216 $LocalFileHeader['raw']['last_mod_file_time'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 10, 2));
217 $LocalFileHeader['raw']['last_mod_file_date'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 12, 2));
218 $LocalFileHeader['raw']['crc_32'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 14, 4));
219 $LocalFileHeader['raw']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 18, 4));
220 $LocalFileHeader['raw']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 22, 4));
221 $LocalFileHeader['raw']['filename_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 26, 2));
222 $LocalFileHeader['raw']['extra_field_length'] = getid3_lib::LittleEndian2Int(substr($ZIPlocalFileHeader, 28, 2));
223
224 $LocalFileHeader['extract_version'] = sprintf('%1.1f', $LocalFileHeader['raw']['extract_version'] / 10);
225 $LocalFileHeader['host_os'] = $this->ZIPversionOSLookup(($LocalFileHeader['raw']['extract_version'] & 0xFF00) >> 8);
226 $LocalFileHeader['compression_method'] = $this->ZIPcompressionMethodLookup($LocalFileHeader['raw']['compression_method']);
227 $LocalFileHeader['compressed_size'] = $LocalFileHeader['raw']['compressed_size'];
228 $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['raw']['uncompressed_size'];
229 $LocalFileHeader['flags'] = $this->ZIPparseGeneralPurposeFlags($LocalFileHeader['raw']['general_flags'], $LocalFileHeader['raw']['compression_method']);
230 $LocalFileHeader['last_modified_timestamp'] = $this->DOStime2UNIXtime($LocalFileHeader['raw']['last_mod_file_date'], $LocalFileHeader['raw']['last_mod_file_time']);
231
232 $FilenameExtrafieldLength = $LocalFileHeader['raw']['filename_length'] + $LocalFileHeader['raw']['extra_field_length'];
233 if ($FilenameExtrafieldLength > 0) {
234 $ZIPlocalFileHeader .= $this->fread($FilenameExtrafieldLength);
235
236 if ($LocalFileHeader['raw']['filename_length'] > 0) {
237 $LocalFileHeader['filename'] = substr($ZIPlocalFileHeader, 30, $LocalFileHeader['raw']['filename_length']);
238 }
239 if ($LocalFileHeader['raw']['extra_field_length'] > 0) {
240 $LocalFileHeader['raw']['extra_field_data'] = substr($ZIPlocalFileHeader, 30 + $LocalFileHeader['raw']['filename_length'], $LocalFileHeader['raw']['extra_field_length']);
241 }
242 }
243
244 if ($LocalFileHeader['compressed_size'] == 0) {
245 // *Could* be a zero-byte file
246 // But could also be a file written on the fly that didn't know compressed filesize beforehand.
247 // Correct compressed filesize should be in the data_descriptor located after this file data, and also in Central Directory (at end of zip file)
248 if (!empty($this->getid3->info['zip']['central_directory'])) {
249 foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) {
250 if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) {
251 if ($central_directory_entry['compressed_size'] > 0) {
252 // overwrite local zero value (but not ['raw']'compressed_size']) so that seeking for data_descriptor (and next file entry) works correctly
253 $LocalFileHeader['compressed_size'] = $central_directory_entry['compressed_size'];
254 }
255 break;
256 }
257 }
258 }
259
260 }
261 $LocalFileHeader['data_offset'] = $this->ftell();
262 $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
263
264 if ($LocalFileHeader['flags']['data_descriptor_used']) {
265 $DataDescriptor = $this->fread(16);
266 $LocalFileHeader['data_descriptor']['signature'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 0, 4));
267 if ($LocalFileHeader['data_descriptor']['signature'] != 0x08074B50) { // "PK\x07\x08"
268 $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']);
269 $this->fseek($LocalFileHeader['offset']); // seek back to where filepointer originally was so it can be handled properly
270 return false;
271 }
272 $LocalFileHeader['data_descriptor']['crc_32'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 4, 4));
273 $LocalFileHeader['data_descriptor']['compressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 8, 4));
274 $LocalFileHeader['data_descriptor']['uncompressed_size'] = getid3_lib::LittleEndian2Int(substr($DataDescriptor, 12, 4));
275 if (!$LocalFileHeader['raw']['compressed_size'] && $LocalFileHeader['data_descriptor']['compressed_size']) {
276 foreach ($this->getid3->info['zip']['central_directory'] as $central_directory_entry) {
277 if ($central_directory_entry['entry_offset'] == $LocalFileHeader['offset']) {
278 if ($LocalFileHeader['data_descriptor']['compressed_size'] == $central_directory_entry['compressed_size']) {
279 // $LocalFileHeader['compressed_size'] already set from Central Directory
280 } else {
281 $this->getid3->info['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'];
282 }
283
284 if ($LocalFileHeader['data_descriptor']['uncompressed_size'] == $central_directory_entry['uncompressed_size']) {
285 $LocalFileHeader['uncompressed_size'] = $LocalFileHeader['data_descriptor']['uncompressed_size'];
286 } else {
287 $this->getid3->info['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'];
288 }
289 break;
290 }
291 }
292 }
293 }
294 return $LocalFileHeader;
295 }
PrintHexBytes($string, $hex=true, $spaces=true, $htmlsafe=true)
Definition: getid3.lib.php:17

References DOStime2UNIXtime(), getid3_handler\fread(), getid3_handler\fseek(), getid3_handler\ftell(), getid3_lib\LittleEndian2Int(), getid3_lib\PrintHexBytes(), ZIPcompressionMethodLookup(), ZIPparseGeneralPurposeFlags(), and ZIPversionOSLookup().

Referenced by Analyze(), getZIPentriesFilepointer(), and getZIPHeaderFilepointerTopDown().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ZIPversionOSLookup() [1/2]

getid3_zip::ZIPversionOSLookup (   $index)

Definition at line 343 of file module.archive.zip.php.

343 {
344 static $ZIPversionOSLookup = array(
345 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
346 1 => 'Amiga',
347 2 => 'OpenVMS',
348 3 => 'Unix',
349 4 => 'VM/CMS',
350 5 => 'Atari ST',
351 6 => 'OS/2 H.P.F.S.',
352 7 => 'Macintosh',
353 8 => 'Z-System',
354 9 => 'CP/M',
355 10 => 'Windows NTFS',
356 11 => 'MVS',
357 12 => 'VSE',
358 13 => 'Acorn Risc',
359 14 => 'VFAT',
360 15 => 'Alternate MVS',
361 16 => 'BeOS',
362 17 => 'Tandem'
363 );
364
365 return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]');
366 }

Referenced by ZIPparseCentralDirectory(), and ZIPparseLocalFileHeader().

+ Here is the caller graph for this function:

◆ ZIPversionOSLookup() [2/2]

static getid3_zip::ZIPversionOSLookup (   $index)
static

Definition at line 429 of file module.archive.zip.php.

429 {
430 static $ZIPversionOSLookup = array(
431 0 => 'MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)',
432 1 => 'Amiga',
433 2 => 'OpenVMS',
434 3 => 'Unix',
435 4 => 'VM/CMS',
436 5 => 'Atari ST',
437 6 => 'OS/2 H.P.F.S.',
438 7 => 'Macintosh',
439 8 => 'Z-System',
440 9 => 'CP/M',
441 10 => 'Windows NTFS',
442 11 => 'MVS',
443 12 => 'VSE',
444 13 => 'Acorn Risc',
445 14 => 'VFAT',
446 15 => 'Alternate MVS',
447 16 => 'BeOS',
448 17 => 'Tandem',
449 18 => 'OS/400',
450 19 => 'OS/X (Darwin)',
451 );
452
453 return (isset($ZIPversionOSLookup[$index]) ? $ZIPversionOSLookup[$index] : '[unknown]');
454 }

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