module.misc.iso.php 26 KB

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