module.misc.iso.php 25 KB

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