module.misc.iso.php 25 KB

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