module.archive.szip.php 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.archive.szip.php //
  12. // module for analyzing SZIP compressed files //
  13. // dependencies: NONE //
  14. // ///
  15. /////////////////////////////////////////////////////////////////
  16. class getid3_szip extends getid3_handler
  17. {
  18. public function Analyze() {
  19. $info = &$this->getid3->info;
  20. $this->fseek($info['avdataoffset']);
  21. $SZIPHeader = $this->fread(6);
  22. if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") {
  23. $info['error'][] = 'Expecting "53 5A 0A 04" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($SZIPHeader, 0, 4)).'"';
  24. return false;
  25. }
  26. $info['fileformat'] = 'szip';
  27. $info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1));
  28. $info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1));
  29. $info['error'][] = 'SZIP parsing not enabled in this version of getID3() ['.$this->getid3->version().']';
  30. return false;
  31. while (!$this->feof()) {
  32. $NextBlockID = $this->fread(2);
  33. switch ($NextBlockID) {
  34. case 'SZ':
  35. // Note that szip files can be concatenated, this has the same effect as
  36. // concatenating the files. this also means that global header blocks
  37. // might be present between directory/data blocks.
  38. $this->fseek(4, SEEK_CUR);
  39. break;
  40. case 'BH':
  41. $BHheaderbytes = getid3_lib::BigEndian2Int($this->fread(3));
  42. $BHheaderdata = $this->fread($BHheaderbytes);
  43. $BHheaderoffset = 0;
  44. while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) {
  45. //filename as \0 terminated string (empty string indicates end)
  46. //owner as \0 terminated string (empty is same as last file)
  47. //group as \0 terminated string (empty is same as last file)
  48. //3 byte filelength in this block
  49. //2 byte access flags
  50. //4 byte creation time (like in unix)
  51. //4 byte modification time (like in unix)
  52. //4 byte access time (like in unix)
  53. $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
  54. $BHheaderoffset += (strlen($BHdataArray['filename']) + 1);
  55. $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
  56. $BHheaderoffset += (strlen($BHdataArray['owner']) + 1);
  57. $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
  58. $BHheaderoffset += (strlen($BHdataArray['group']) + 1);
  59. $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3));
  60. $BHheaderoffset += 3;
  61. $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2));
  62. $BHheaderoffset += 2;
  63. $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
  64. $BHheaderoffset += 4;
  65. $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
  66. $BHheaderoffset += 4;
  67. $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
  68. $BHheaderoffset += 4;
  69. $info['szip']['BH'][] = $BHdataArray;
  70. }
  71. break;
  72. default:
  73. break 2;
  74. }
  75. }
  76. return true;
  77. }
  78. }