module.archive.hpk.php 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.archive.hpk.php //
  11. // module for analyzing HPK 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_hpk extends getid3_handler
  19. {
  20. /**
  21. * @return bool
  22. */
  23. public function Analyze() {
  24. $info = &$this->getid3->info;
  25. $info['fileformat'] = 'hpk';
  26. $this->fseek($info['avdataoffset']);
  27. $HPKheader = $this->fread(36);
  28. if (substr($HPKheader, 0, 4) == 'BPUL') {
  29. $info['hpk']['header']['signature'] = substr($HPKheader, 0, 4);
  30. $info['hpk']['header']['data_offset'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 4, 4));
  31. $info['hpk']['header']['fragments_per_file'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 8, 4));
  32. //$info['hpk']['header']['unknown1'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 12, 4));
  33. $info['hpk']['header']['fragments_residual_offset'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 16, 4));
  34. $info['hpk']['header']['fragments_residual_count'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 20, 4));
  35. //$info['hpk']['header']['unknown2'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 24, 4));
  36. $info['hpk']['header']['fragmented_filesystem_offset'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 28, 4));
  37. $info['hpk']['header']['fragmented_filesystem_length'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 32, 4));
  38. $info['hpk']['header']['filesystem_entries'] = $info['hpk']['header']['fragmented_filesystem_length'] / ($info['hpk']['header']['fragments_per_file'] * 8);
  39. $this->fseek($info['hpk']['header']['fragmented_filesystem_offset']);
  40. for ($i = 0; $i < $info['hpk']['header']['filesystem_entries']; $i++) {
  41. $offset = getid3_lib::LittleEndian2Int($this->fread(4));
  42. $length = getid3_lib::LittleEndian2Int($this->fread(4));
  43. $info['hpk']['filesystem'][$i] = array('offset' => $offset, 'length' => $length);
  44. }
  45. $this->error('HPK parsing incomplete (and mostly broken) in this version of getID3() ['.$this->getid3->version().']');
  46. /*
  47. $filename = '';
  48. $dirs = array();
  49. foreach ($info['hpk']['filesystem'] as $key => $filesystemdata) {
  50. $this->fseek($filesystemdata['offset']);
  51. $first4 = $this->fread(4);
  52. if (($first4 == 'LZ4 ') || ($first4 == 'ZLIB')) {
  53. // actual data, ignore
  54. $info['hpk']['toc'][$key] = array(
  55. 'filename' => ltrim(implode('/', $dirs).'/'.$filename, '/'),
  56. 'offset' => $filesystemdata['offset'],
  57. 'length' => $filesystemdata['length'],
  58. );
  59. $filename = '';
  60. $dirs = array();
  61. } else {
  62. $fragment_index = getid3_lib::LittleEndian2Int($first4);
  63. $fragment_type = getid3_lib::LittleEndian2Int($this->fread(4)); // file = 0, directory = 1
  64. $name_length = getid3_lib::LittleEndian2Int($this->fread(2));
  65. if ($fragment_type == 1) {
  66. $dirs[] = $this->fread($name_length);
  67. } else {
  68. $filename = $this->fread($name_length);
  69. }
  70. }
  71. }
  72. */
  73. } else {
  74. $this->error('Expecting "BPUL" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($HPKheader, 0, 4)).'"');
  75. return false;
  76. }
  77. return true;
  78. }
  79. }