module.misc.iso.php 26 KB

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