module.misc.iso.php 25 KB

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