1<?php
2
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/////////////////////////////////////////////////////////////////
10//                                                             //
11// module.misc.iso.php                                         //
12// module for analyzing ISO files                              //
13// dependencies: NONE                                          //
14//                                                            ///
15/////////////////////////////////////////////////////////////////
16
17if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
18	exit;
19}
20
21class getid3_iso extends getid3_handler
22{
23	/**
24	 * @return bool
25	 */
26	public function Analyze() {
27		$info = &$this->getid3->info;
28
29		$info['fileformat'] = 'iso';
30
31		for ($i = 16; $i <= 19; $i++) {
32			$this->fseek(2048 * $i);
33			$ISOheader = $this->fread(2048);
34			if (substr($ISOheader, 1, 5) == 'CD001') {
35				switch (ord($ISOheader[0])) {
36					case 1:
37						$info['iso']['primary_volume_descriptor']['offset'] = 2048 * $i;
38						$this->ParsePrimaryVolumeDescriptor($ISOheader);
39						break;
40
41					case 2:
42						$info['iso']['supplementary_volume_descriptor']['offset'] = 2048 * $i;
43						$this->ParseSupplementaryVolumeDescriptor($ISOheader);
44						break;
45
46					default:
47						// skip
48						break;
49				}
50			}
51		}
52
53		$this->ParsePathTable();
54
55		$info['iso']['files'] = array();
56		foreach ($info['iso']['path_table']['directories'] as $directorynum => $directorydata) {
57			$info['iso']['directories'][$directorynum] = $this->ParseDirectoryRecord($directorydata);
58		}
59
60		return true;
61	}
62
63	/**
64	 * @param string $ISOheader
65	 *
66	 * @return bool
67	 */
68	public function ParsePrimaryVolumeDescriptor(&$ISOheader) {
69		// ISO integer values are stored *BOTH* Little-Endian AND Big-Endian format!!
70		// ie 12345 == 0x3039  is stored as $39 $30 $30 $39 in a 4-byte field
71
72		// shortcuts
73		$info = &$this->getid3->info;
74		$info['iso']['primary_volume_descriptor']['raw'] = array();
75		$thisfile_iso_primaryVD     = &$info['iso']['primary_volume_descriptor'];
76		$thisfile_iso_primaryVD_raw = &$thisfile_iso_primaryVD['raw'];
77
78		$thisfile_iso_primaryVD_raw['volume_descriptor_type']         = getid3_lib::LittleEndian2Int(substr($ISOheader,    0, 1));
79		$thisfile_iso_primaryVD_raw['standard_identifier']            =                  substr($ISOheader,    1, 5);
80		if ($thisfile_iso_primaryVD_raw['standard_identifier'] != 'CD001') {
81			$this->error('Expected "CD001" at offset ('.($thisfile_iso_primaryVD['offset'] + 1).'), found "'.$thisfile_iso_primaryVD_raw['standard_identifier'].'" instead');
82			unset($info['fileformat']);
83			unset($info['iso']);
84			return false;
85		}
86
87
88		$thisfile_iso_primaryVD_raw['volume_descriptor_version']     = getid3_lib::LittleEndian2Int(substr($ISOheader,    6, 1));
89		//$thisfile_iso_primaryVD_raw['unused_1']                      =                              substr($ISOheader,    7, 1);
90		$thisfile_iso_primaryVD_raw['system_identifier']             =                              substr($ISOheader,    8, 32);
91		$thisfile_iso_primaryVD_raw['volume_identifier']             =                              substr($ISOheader,   40, 32);
92		//$thisfile_iso_primaryVD_raw['unused_2']                      =                              substr($ISOheader,   72, 8);
93		$thisfile_iso_primaryVD_raw['volume_space_size']             = getid3_lib::LittleEndian2Int(substr($ISOheader,   80, 4));
94		//$thisfile_iso_primaryVD_raw['unused_3']                      =                              substr($ISOheader,   88, 32);
95		$thisfile_iso_primaryVD_raw['volume_set_size']               = getid3_lib::LittleEndian2Int(substr($ISOheader,  120, 2));
96		$thisfile_iso_primaryVD_raw['volume_sequence_number']        = getid3_lib::LittleEndian2Int(substr($ISOheader,  124, 2));
97		$thisfile_iso_primaryVD_raw['logical_block_size']            = getid3_lib::LittleEndian2Int(substr($ISOheader,  128, 2));
98		$thisfile_iso_primaryVD_raw['path_table_size']               = getid3_lib::LittleEndian2Int(substr($ISOheader,  132, 4));
99		$thisfile_iso_primaryVD_raw['path_table_l_location']         = getid3_lib::LittleEndian2Int(substr($ISOheader,  140, 2));
100		$thisfile_iso_primaryVD_raw['path_table_l_opt_location']     = getid3_lib::LittleEndian2Int(substr($ISOheader,  144, 2));
101		$thisfile_iso_primaryVD_raw['path_table_m_location']         = getid3_lib::LittleEndian2Int(substr($ISOheader,  148, 2));
102		$thisfile_iso_primaryVD_raw['path_table_m_opt_location']     = getid3_lib::LittleEndian2Int(substr($ISOheader,  152, 2));
103		$thisfile_iso_primaryVD_raw['root_directory_record']         =                              substr($ISOheader,  156, 34);
104		$thisfile_iso_primaryVD_raw['volume_set_identifier']         =                              substr($ISOheader,  190, 128);
105		$thisfile_iso_primaryVD_raw['publisher_identifier']          =                              substr($ISOheader,  318, 128);
106		$thisfile_iso_primaryVD_raw['data_preparer_identifier']      =                              substr($ISOheader,  446, 128);
107		$thisfile_iso_primaryVD_raw['application_identifier']        =                              substr($ISOheader,  574, 128);
108		$thisfile_iso_primaryVD_raw['copyright_file_identifier']     =                              substr($ISOheader,  702, 37);
109		$thisfile_iso_primaryVD_raw['abstract_file_identifier']      =                              substr($ISOheader,  739, 37);
110		$thisfile_iso_primaryVD_raw['bibliographic_file_identifier'] =                              substr($ISOheader,  776, 37);
111		$thisfile_iso_primaryVD_raw['volume_creation_date_time']     =                              substr($ISOheader,  813, 17);
112		$thisfile_iso_primaryVD_raw['volume_modification_date_time'] =                              substr($ISOheader,  830, 17);
113		$thisfile_iso_primaryVD_raw['volume_expiration_date_time']   =                              substr($ISOheader,  847, 17);
114		$thisfile_iso_primaryVD_raw['volume_effective_date_time']    =                              substr($ISOheader,  864, 17);
115		$thisfile_iso_primaryVD_raw['file_structure_version']        = getid3_lib::LittleEndian2Int(substr($ISOheader,  881, 1));
116		//$thisfile_iso_primaryVD_raw['unused_4']                      = getid3_lib::LittleEndian2Int(substr($ISOheader,  882, 1));
117		$thisfile_iso_primaryVD_raw['application_data']              =                              substr($ISOheader,  883, 512);
118		//$thisfile_iso_primaryVD_raw['unused_5']                      =                              substr($ISOheader, 1395, 653);
119
120		$thisfile_iso_primaryVD['system_identifier']             = trim($thisfile_iso_primaryVD_raw['system_identifier']);
121		$thisfile_iso_primaryVD['volume_identifier']             = trim($thisfile_iso_primaryVD_raw['volume_identifier']);
122		$thisfile_iso_primaryVD['volume_set_identifier']         = trim($thisfile_iso_primaryVD_raw['volume_set_identifier']);
123		$thisfile_iso_primaryVD['publisher_identifier']          = trim($thisfile_iso_primaryVD_raw['publisher_identifier']);
124		$thisfile_iso_primaryVD['data_preparer_identifier']      = trim($thisfile_iso_primaryVD_raw['data_preparer_identifier']);
125		$thisfile_iso_primaryVD['application_identifier']        = trim($thisfile_iso_primaryVD_raw['application_identifier']);
126		$thisfile_iso_primaryVD['copyright_file_identifier']     = trim($thisfile_iso_primaryVD_raw['copyright_file_identifier']);
127		$thisfile_iso_primaryVD['abstract_file_identifier']      = trim($thisfile_iso_primaryVD_raw['abstract_file_identifier']);
128		$thisfile_iso_primaryVD['bibliographic_file_identifier'] = trim($thisfile_iso_primaryVD_raw['bibliographic_file_identifier']);
129		$thisfile_iso_primaryVD['volume_creation_date_time']     = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_creation_date_time']);
130		$thisfile_iso_primaryVD['volume_modification_date_time'] = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_modification_date_time']);
131		$thisfile_iso_primaryVD['volume_expiration_date_time']   = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_expiration_date_time']);
132		$thisfile_iso_primaryVD['volume_effective_date_time']    = $this->ISOtimeText2UNIXtime($thisfile_iso_primaryVD_raw['volume_effective_date_time']);
133
134		if (($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048) > $info['filesize']) {
135			$this->error('Volume Space Size ('.($thisfile_iso_primaryVD_raw['volume_space_size'] * 2048).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)');
136		}
137
138		return true;
139	}
140
141	/**
142	 * @param string $ISOheader
143	 *
144	 * @return bool
145	 */
146	public function ParseSupplementaryVolumeDescriptor(&$ISOheader) {
147		// ISO integer values are stored Both-Endian format!!
148		// ie 12345 == 0x3039  is stored as $39 $30 $30 $39 in a 4-byte field
149
150		// shortcuts
151		$info = &$this->getid3->info;
152		$info['iso']['supplementary_volume_descriptor']['raw'] = array();
153		$thisfile_iso_supplementaryVD     = &$info['iso']['supplementary_volume_descriptor'];
154		$thisfile_iso_supplementaryVD_raw = &$thisfile_iso_supplementaryVD['raw'];
155
156		$thisfile_iso_supplementaryVD_raw['volume_descriptor_type'] = getid3_lib::LittleEndian2Int(substr($ISOheader,    0, 1));
157		$thisfile_iso_supplementaryVD_raw['standard_identifier']    =                  substr($ISOheader,    1, 5);
158		if ($thisfile_iso_supplementaryVD_raw['standard_identifier'] != 'CD001') {
159			$this->error('Expected "CD001" at offset ('.($thisfile_iso_supplementaryVD['offset'] + 1).'), found "'.$thisfile_iso_supplementaryVD_raw['standard_identifier'].'" instead');
160			unset($info['fileformat']);
161			unset($info['iso']);
162			return false;
163		}
164
165		$thisfile_iso_supplementaryVD_raw['volume_descriptor_version'] = getid3_lib::LittleEndian2Int(substr($ISOheader,    6, 1));
166		//$thisfile_iso_supplementaryVD_raw['unused_1']                  =                              substr($ISOheader,    7, 1);
167		$thisfile_iso_supplementaryVD_raw['system_identifier']         =                              substr($ISOheader,    8, 32);
168		$thisfile_iso_supplementaryVD_raw['volume_identifier']         =                              substr($ISOheader,   40, 32);
169		//$thisfile_iso_supplementaryVD_raw['unused_2']                  =                              substr($ISOheader,   72, 8);
170		$thisfile_iso_supplementaryVD_raw['volume_space_size']         = getid3_lib::LittleEndian2Int(substr($ISOheader,   80, 4));
171		if ($thisfile_iso_supplementaryVD_raw['volume_space_size'] == 0) {
172			// Supplementary Volume Descriptor not used
173			//unset($thisfile_iso_supplementaryVD);
174			//return false;
175		}
176
177		//$thisfile_iso_supplementaryVD_raw['unused_3']                       =                              substr($ISOheader,   88, 32);
178		$thisfile_iso_supplementaryVD_raw['volume_set_size']                = getid3_lib::LittleEndian2Int(substr($ISOheader,  120, 2));
179		$thisfile_iso_supplementaryVD_raw['volume_sequence_number']         = getid3_lib::LittleEndian2Int(substr($ISOheader,  124, 2));
180		$thisfile_iso_supplementaryVD_raw['logical_block_size']             = getid3_lib::LittleEndian2Int(substr($ISOheader,  128, 2));
181		$thisfile_iso_supplementaryVD_raw['path_table_size']                = getid3_lib::LittleEndian2Int(substr($ISOheader,  132, 4));
182		$thisfile_iso_supplementaryVD_raw['path_table_l_location']          = getid3_lib::LittleEndian2Int(substr($ISOheader,  140, 2));
183		$thisfile_iso_supplementaryVD_raw['path_table_l_opt_location']      = getid3_lib::LittleEndian2Int(substr($ISOheader,  144, 2));
184		$thisfile_iso_supplementaryVD_raw['path_table_m_location']          = getid3_lib::LittleEndian2Int(substr($ISOheader,  148, 2));
185		$thisfile_iso_supplementaryVD_raw['path_table_m_opt_location']      = getid3_lib::LittleEndian2Int(substr($ISOheader,  152, 2));
186		$thisfile_iso_supplementaryVD_raw['root_directory_record']          =                              substr($ISOheader,  156, 34);
187		$thisfile_iso_supplementaryVD_raw['volume_set_identifier']          =                              substr($ISOheader,  190, 128);
188		$thisfile_iso_supplementaryVD_raw['publisher_identifier']           =                              substr($ISOheader,  318, 128);
189		$thisfile_iso_supplementaryVD_raw['data_preparer_identifier']       =                              substr($ISOheader,  446, 128);
190		$thisfile_iso_supplementaryVD_raw['application_identifier']         =                              substr($ISOheader,  574, 128);
191		$thisfile_iso_supplementaryVD_raw['copyright_file_identifier']      =                              substr($ISOheader,  702, 37);
192		$thisfile_iso_supplementaryVD_raw['abstract_file_identifier']       =                              substr($ISOheader,  739, 37);
193		$thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier']  =                              substr($ISOheader,  776, 37);
194		$thisfile_iso_supplementaryVD_raw['volume_creation_date_time']      =                              substr($ISOheader,  813, 17);
195		$thisfile_iso_supplementaryVD_raw['volume_modification_date_time']  =                              substr($ISOheader,  830, 17);
196		$thisfile_iso_supplementaryVD_raw['volume_expiration_date_time']    =                              substr($ISOheader,  847, 17);
197		$thisfile_iso_supplementaryVD_raw['volume_effective_date_time']     =                              substr($ISOheader,  864, 17);
198		$thisfile_iso_supplementaryVD_raw['file_structure_version']         = getid3_lib::LittleEndian2Int(substr($ISOheader,  881, 1));
199		//$thisfile_iso_supplementaryVD_raw['unused_4']                       = getid3_lib::LittleEndian2Int(substr($ISOheader,  882, 1));
200		$thisfile_iso_supplementaryVD_raw['application_data']               =                              substr($ISOheader,  883, 512);
201		//$thisfile_iso_supplementaryVD_raw['unused_5']                       =                              substr($ISOheader, 1395, 653);
202
203		$thisfile_iso_supplementaryVD['system_identifier']              = trim($thisfile_iso_supplementaryVD_raw['system_identifier']);
204		$thisfile_iso_supplementaryVD['volume_identifier']              = trim($thisfile_iso_supplementaryVD_raw['volume_identifier']);
205		$thisfile_iso_supplementaryVD['volume_set_identifier']          = trim($thisfile_iso_supplementaryVD_raw['volume_set_identifier']);
206		$thisfile_iso_supplementaryVD['publisher_identifier']           = trim($thisfile_iso_supplementaryVD_raw['publisher_identifier']);
207		$thisfile_iso_supplementaryVD['data_preparer_identifier']       = trim($thisfile_iso_supplementaryVD_raw['data_preparer_identifier']);
208		$thisfile_iso_supplementaryVD['application_identifier']         = trim($thisfile_iso_supplementaryVD_raw['application_identifier']);
209		$thisfile_iso_supplementaryVD['copyright_file_identifier']      = trim($thisfile_iso_supplementaryVD_raw['copyright_file_identifier']);
210		$thisfile_iso_supplementaryVD['abstract_file_identifier']       = trim($thisfile_iso_supplementaryVD_raw['abstract_file_identifier']);
211		$thisfile_iso_supplementaryVD['bibliographic_file_identifier']  = trim($thisfile_iso_supplementaryVD_raw['bibliographic_file_identifier']);
212		$thisfile_iso_supplementaryVD['volume_creation_date_time']      = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_creation_date_time']);
213		$thisfile_iso_supplementaryVD['volume_modification_date_time']  = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_modification_date_time']);
214		$thisfile_iso_supplementaryVD['volume_expiration_date_time']    = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_expiration_date_time']);
215		$thisfile_iso_supplementaryVD['volume_effective_date_time']     = $this->ISOtimeText2UNIXtime($thisfile_iso_supplementaryVD_raw['volume_effective_date_time']);
216
217		if (($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']) > $info['filesize']) {
218			$this->error('Volume Space Size ('.($thisfile_iso_supplementaryVD_raw['volume_space_size'] * $thisfile_iso_supplementaryVD_raw['logical_block_size']).' bytes) is larger than the file size ('.$info['filesize'].' bytes) (truncated file?)');
219		}
220
221		return true;
222	}
223
224	/**
225	 * @return bool
226	 */
227	public function ParsePathTable() {
228		$info = &$this->getid3->info;
229		if (!isset($info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location']) && !isset($info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'])) {
230			return false;
231		}
232		if (isset($info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'])) {
233			$PathTableLocation = $info['iso']['supplementary_volume_descriptor']['raw']['path_table_l_location'];
234			$PathTableSize     = $info['iso']['supplementary_volume_descriptor']['raw']['path_table_size'];
235			$TextEncoding      = 'UTF-16BE'; // Big-Endian Unicode
236		} else {
237			$PathTableLocation = $info['iso']['primary_volume_descriptor']['raw']['path_table_l_location'];
238			$PathTableSize     = $info['iso']['primary_volume_descriptor']['raw']['path_table_size'];
239			$TextEncoding      = 'ISO-8859-1'; // Latin-1
240		}
241
242		if (($PathTableLocation * 2048) > $info['filesize']) {
243			$this->error('Path Table Location specifies an offset ('.($PathTableLocation * 2048).') beyond the end-of-file ('.$info['filesize'].')');
244			return false;
245		}
246
247		$info['iso']['path_table']['offset'] = $PathTableLocation * 2048;
248		$this->fseek($info['iso']['path_table']['offset']);
249		$info['iso']['path_table']['raw'] = $this->fread($PathTableSize);
250
251		$offset = 0;
252		$pathcounter = 1;
253		while ($offset < $PathTableSize) {
254			// shortcut
255			$info['iso']['path_table']['directories'][$pathcounter] = array();
256			$thisfile_iso_pathtable_directories_current = &$info['iso']['path_table']['directories'][$pathcounter];
257
258			$thisfile_iso_pathtable_directories_current['length']           = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 1));
259			$offset += 1;
260			$thisfile_iso_pathtable_directories_current['extended_length']  = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 1));
261			$offset += 1;
262			$thisfile_iso_pathtable_directories_current['location_logical'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 4));
263			$offset += 4;
264			$thisfile_iso_pathtable_directories_current['parent_directory'] = getid3_lib::LittleEndian2Int(substr($info['iso']['path_table']['raw'], $offset, 2));
265			$offset += 2;
266			$thisfile_iso_pathtable_directories_current['name']             =                  substr($info['iso']['path_table']['raw'], $offset, $thisfile_iso_pathtable_directories_current['length']);
267			$offset += $thisfile_iso_pathtable_directories_current['length'] + ($thisfile_iso_pathtable_directories_current['length'] % 2);
268
269			$thisfile_iso_pathtable_directories_current['name_ascii']       = getid3_lib::iconv_fallback($TextEncoding, $info['encoding'], $thisfile_iso_pathtable_directories_current['name']);
270
271			$thisfile_iso_pathtable_directories_current['location_bytes'] = $thisfile_iso_pathtable_directories_current['location_logical'] * 2048;
272			if ($pathcounter == 1) {
273				$thisfile_iso_pathtable_directories_current['full_path'] = '/';
274			} else {
275				$thisfile_iso_pathtable_directories_current['full_path'] = $info['iso']['path_table']['directories'][$thisfile_iso_pathtable_directories_current['parent_directory']]['full_path'].$thisfile_iso_pathtable_directories_current['name_ascii'].'/';
276			}
277			$FullPathArray[] = $thisfile_iso_pathtable_directories_current['full_path'];
278
279			$pathcounter++;
280		}
281
282		return true;
283	}
284
285	/**
286	 * @param array $directorydata
287	 *
288	 * @return array
289	 */
290	public function ParseDirectoryRecord($directorydata) {
291		$info = &$this->getid3->info;
292		if (isset($info['iso']['supplementary_volume_descriptor'])) {
293			$TextEncoding = 'UTF-16BE';   // Big-Endian Unicode
294		} else {
295			$TextEncoding = 'ISO-8859-1'; // Latin-1
296		}
297
298		$this->fseek($directorydata['location_bytes']);
299		$DirectoryRecordData = $this->fread(1);
300		$DirectoryRecord = array();
301
302		while (ord($DirectoryRecordData[0]) > 33) {
303
304			$DirectoryRecordData .= $this->fread(ord($DirectoryRecordData[0]) - 1);
305
306			$ThisDirectoryRecord = array();
307
308			$ThisDirectoryRecord['raw']['length']                    = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData,  0, 1));
309			$ThisDirectoryRecord['raw']['extended_attribute_length'] = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData,  1, 1));
310			$ThisDirectoryRecord['raw']['offset_logical']            = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData,  2, 4));
311			$ThisDirectoryRecord['raw']['filesize']                  = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 10, 4));
312			$ThisDirectoryRecord['raw']['recording_date_time']       =                  substr($DirectoryRecordData, 18, 7);
313			$ThisDirectoryRecord['raw']['file_flags']                = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 25, 1));
314			$ThisDirectoryRecord['raw']['file_unit_size']            = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 26, 1));
315			$ThisDirectoryRecord['raw']['interleave_gap_size']       = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 27, 1));
316			$ThisDirectoryRecord['raw']['volume_sequence_number']    = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 28, 2));
317			$ThisDirectoryRecord['raw']['file_identifier_length']    = getid3_lib::LittleEndian2Int(substr($DirectoryRecordData, 32, 1));
318			$ThisDirectoryRecord['raw']['file_identifier']           =                  substr($DirectoryRecordData, 33, $ThisDirectoryRecord['raw']['file_identifier_length']);
319
320			$ThisDirectoryRecord['file_identifier_ascii']            = getid3_lib::iconv_fallback($TextEncoding, $info['encoding'], $ThisDirectoryRecord['raw']['file_identifier']);
321
322			$ThisDirectoryRecord['filesize']                  = $ThisDirectoryRecord['raw']['filesize'];
323			$ThisDirectoryRecord['offset_bytes']              = $ThisDirectoryRecord['raw']['offset_logical'] * 2048;
324			$ThisDirectoryRecord['file_flags']['hidden']      = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x01);
325			$ThisDirectoryRecord['file_flags']['directory']   = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x02);
326			$ThisDirectoryRecord['file_flags']['associated']  = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x04);
327			$ThisDirectoryRecord['file_flags']['extended']    = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x08);
328			$ThisDirectoryRecord['file_flags']['permissions'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x10);
329			$ThisDirectoryRecord['file_flags']['multiple']    = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x80);
330			$ThisDirectoryRecord['recording_timestamp']       = $this->ISOtime2UNIXtime($ThisDirectoryRecord['raw']['recording_date_time']);
331
332			if ($ThisDirectoryRecord['file_flags']['directory']) {
333				$ThisDirectoryRecord['filename'] = $directorydata['full_path'];
334			} else {
335				$ThisDirectoryRecord['filename'] = $directorydata['full_path'].$this->ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']);
336				$info['iso']['files'] = getid3_lib::array_merge_clobber($info['iso']['files'], getid3_lib::CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize']));
337			}
338
339			$DirectoryRecord[] = $ThisDirectoryRecord;
340			$DirectoryRecordData = $this->fread(1);
341		}
342
343		return $DirectoryRecord;
344	}
345
346	/**
347	 * @param string $ISOfilename
348	 *
349	 * @return string
350	 */
351	public function ISOstripFilenameVersion($ISOfilename) {
352		// convert 'filename.ext;1' to 'filename.ext'
353		if (!strstr($ISOfilename, ';')) {
354			return $ISOfilename;
355		} else {
356			return substr($ISOfilename, 0, strpos($ISOfilename, ';'));
357		}
358	}
359
360	/**
361	 * @param string $ISOtime
362	 *
363	 * @return int|false
364	 */
365	public function ISOtimeText2UNIXtime($ISOtime) {
366
367		$UNIXyear   = (int) substr($ISOtime,  0, 4);
368		$UNIXmonth  = (int) substr($ISOtime,  4, 2);
369		$UNIXday    = (int) substr($ISOtime,  6, 2);
370		$UNIXhour   = (int) substr($ISOtime,  8, 2);
371		$UNIXminute = (int) substr($ISOtime, 10, 2);
372		$UNIXsecond = (int) substr($ISOtime, 12, 2);
373
374		if (!$UNIXyear) {
375			return false;
376		}
377		return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
378	}
379
380	/**
381	 * @param string $ISOtime
382	 *
383	 * @return int
384	 */
385	public function ISOtime2UNIXtime($ISOtime) {
386		// Represented by seven bytes:
387		// 1: Number of years since 1900
388		// 2: Month of the year from 1 to 12
389		// 3: Day of the Month from 1 to 31
390		// 4: Hour of the day from 0 to 23
391		// 5: Minute of the hour from 0 to 59
392		// 6: second of the minute from 0 to 59
393		// 7: Offset from Greenwich Mean Time in number of 15 minute intervals from -48 (West) to +52 (East)
394
395		$UNIXyear   = ord($ISOtime[0]) + 1900;
396		$UNIXmonth  = ord($ISOtime[1]);
397		$UNIXday    = ord($ISOtime[2]);
398		$UNIXhour   = ord($ISOtime[3]);
399		$UNIXminute = ord($ISOtime[4]);
400		$UNIXsecond = ord($ISOtime[5]);
401		$GMToffset  = $this->TwosCompliment2Decimal(ord($ISOtime[5]));
402
403		return gmmktime($UNIXhour, $UNIXminute, $UNIXsecond, $UNIXmonth, $UNIXday, $UNIXyear);
404	}
405
406	/**
407	 * @param int $BinaryValue
408	 *
409	 * @return int
410	 */
411	public function TwosCompliment2Decimal($BinaryValue) {
412		// http://sandbox.mc.edu/~bennet/cs110/tc/tctod.html
413		// First check if the number is negative or positive by looking at the sign bit.
414		// If it is positive, simply convert it to decimal.
415		// If it is negative, make it positive by inverting the bits and adding one.
416		// Then, convert the result to decimal.
417		// The negative of this number is the value of the original binary.
418
419		if ($BinaryValue & 0x80) {
420
421			// negative number
422			return (0 - ((~$BinaryValue & 0xFF) + 1));
423		} else {
424			// positive number
425			return $BinaryValue;
426		}
427	}
428
429
430}
431