module.audio.mod.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /////////////////////////////////////////////////////////////////
  3. /// getID3() by James Heinrich <info@getid3.org> //
  4. // available at https://github.com/JamesHeinrich/getID3 //
  5. // or https://www.getid3.org //
  6. // or http://getid3.sourceforge.net //
  7. // see readme.txt for more details //
  8. /////////////////////////////////////////////////////////////////
  9. // //
  10. // module.audio.mod.php //
  11. // module for analyzing MOD Audio files //
  12. // dependencies: NONE //
  13. // ///
  14. /////////////////////////////////////////////////////////////////
  15. if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
  16. exit;
  17. }
  18. class getid3_mod extends getid3_handler
  19. {
  20. /**
  21. * @return bool
  22. */
  23. public function Analyze() {
  24. $info = &$this->getid3->info;
  25. $this->fseek($info['avdataoffset']);
  26. $fileheader = $this->fread(1088);
  27. if (preg_match('#^IMPM#', $fileheader)) {
  28. return $this->getITheaderFilepointer();
  29. } elseif (preg_match('#^Extended Module#', $fileheader)) {
  30. return $this->getXMheaderFilepointer();
  31. } elseif (preg_match('#^.{44}SCRM#', $fileheader)) {
  32. return $this->getS3MheaderFilepointer();
  33. } elseif (preg_match('#^.{1080}(M\\.K\\.|M!K!|FLT4|FLT8|[5-9]CHN|[1-3][0-9]CH)#', $fileheader)) {
  34. return $this->getMODheaderFilepointer();
  35. }
  36. $this->error('This is not a known type of MOD file');
  37. return false;
  38. }
  39. /**
  40. * @return bool
  41. */
  42. public function getMODheaderFilepointer() {
  43. $info = &$this->getid3->info;
  44. $this->fseek($info['avdataoffset'] + 1080);
  45. $FormatID = $this->fread(4);
  46. if (!preg_match('#^(M.K.|[5-9]CHN|[1-3][0-9]CH)$#', $FormatID)) {
  47. $this->error('This is not a known type of MOD file');
  48. return false;
  49. }
  50. $info['fileformat'] = 'mod';
  51. $this->error('MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']');
  52. return false;
  53. }
  54. /**
  55. * @return bool
  56. */
  57. public function getXMheaderFilepointer() {
  58. $info = &$this->getid3->info;
  59. $this->fseek($info['avdataoffset']);
  60. $FormatID = $this->fread(15);
  61. if (!preg_match('#^Extended Module$#', $FormatID)) {
  62. $this->error('This is not a known type of XM-MOD file');
  63. return false;
  64. }
  65. $info['fileformat'] = 'xm';
  66. $this->error('XM-MOD parsing not enabled in this version of getID3() ['.$this->getid3->version().']');
  67. return false;
  68. }
  69. /**
  70. * @return bool
  71. */
  72. public function getS3MheaderFilepointer() {
  73. $info = &$this->getid3->info;
  74. $this->fseek($info['avdataoffset'] + 44);
  75. $FormatID = $this->fread(4);
  76. if (!preg_match('#^SCRM$#', $FormatID)) {
  77. $this->error('This is not a ScreamTracker MOD file');
  78. return false;
  79. }
  80. $info['fileformat'] = 's3m';
  81. $this->error('ScreamTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']');
  82. return false;
  83. }
  84. /**
  85. * @return bool
  86. */
  87. public function getITheaderFilepointer() {
  88. $info = &$this->getid3->info;
  89. $this->fseek($info['avdataoffset']);
  90. $FormatID = $this->fread(4);
  91. if (!preg_match('#^IMPM$#', $FormatID)) {
  92. $this->error('This is not an ImpulseTracker MOD file');
  93. return false;
  94. }
  95. $info['fileformat'] = 'it';
  96. $this->error('ImpulseTracker parsing not enabled in this version of getID3() ['.$this->getid3->version().']');
  97. return false;
  98. }
  99. }