1<?php 2 3///////////////////////////////////////////////////////////////// 4/// getID3() by James Heinrich <info@getid3.org> // 5// available at https://github.com/JamesHeinrich/getID3 // 6// or https://www.getid3.org // 7// or http://getid3.sourceforge.net // 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 17if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers 18 exit; 19} 20 21class getid3_szip extends getid3_handler 22{ 23 /** 24 * @return bool 25 */ 26 public function Analyze() { 27 $info = &$this->getid3->info; 28 29 $this->fseek($info['avdataoffset']); 30 $SZIPHeader = $this->fread(6); 31 if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") { 32 $this->error('Expecting "53 5A 0A 04" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($SZIPHeader, 0, 4)).'"'); 33 return false; 34 } 35 $info['fileformat'] = 'szip'; 36 $info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1)); 37 $info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1)); 38 $this->error('SZIP parsing not enabled in this version of getID3() ['.$this->getid3->version().']'); 39 return false; 40 41 while (!$this->feof()) { 42 $NextBlockID = $this->fread(2); 43 switch ($NextBlockID) { 44 case 'SZ': 45 // Note that szip files can be concatenated, this has the same effect as 46 // concatenating the files. this also means that global header blocks 47 // might be present between directory/data blocks. 48 $this->fseek(4, SEEK_CUR); 49 break; 50 51 case 'BH': 52 $BHheaderbytes = getid3_lib::BigEndian2Int($this->fread(3)); 53 $BHheaderdata = $this->fread($BHheaderbytes); 54 $BHheaderoffset = 0; 55 while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) { 56 //filename as \0 terminated string (empty string indicates end) 57 //owner as \0 terminated string (empty is same as last file) 58 //group as \0 terminated string (empty is same as last file) 59 //3 byte filelength in this block 60 //2 byte access flags 61 //4 byte creation time (like in unix) 62 //4 byte modification time (like in unix) 63 //4 byte access time (like in unix) 64 65 $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); 66 $BHheaderoffset += (strlen($BHdataArray['filename']) + 1); 67 68 $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); 69 $BHheaderoffset += (strlen($BHdataArray['owner']) + 1); 70 71 $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); 72 $BHheaderoffset += (strlen($BHdataArray['group']) + 1); 73 74 $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3)); 75 $BHheaderoffset += 3; 76 77 $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2)); 78 $BHheaderoffset += 2; 79 80 $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); 81 $BHheaderoffset += 4; 82 83 $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); 84 $BHheaderoffset += 4; 85 86 $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); 87 $BHheaderoffset += 4; 88 89 $info['szip']['BH'][] = $BHdataArray; 90 } 91 break; 92 93 default: 94 break 2; 95 } 96 } 97 98 return true; 99 100 } 101 102} 103