PageRenderTime 208ms CodeModel.GetById 41ms app.highlight 109ms RepoModel.GetById 51ms app.codeStats 1ms

/getid3/module.misc.iso.php

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