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