module.archive.szip.php 3.8 KB

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