File indexing completed on 2024-05-12 17:25:55

0001 <?php
0002 /////////////////////////////////////////////////////////////////
0003 /// getID3() by James Heinrich <info@getid3.org>               //
0004 //  available at http://getid3.sourceforge.net                 //
0005 //            or http://www.getid3.org                         //
0006 //          also https://github.com/JamesHeinrich/getID3       //
0007 /////////////////////////////////////////////////////////////////
0008 // See readme.txt for more details                             //
0009 /////////////////////////////////////////////////////////////////
0010 //                                                             //
0011 // module.archive.szip.php                                     //
0012 // module for analyzing SZIP compressed files                  //
0013 // dependencies: NONE                                          //
0014 //                                                            ///
0015 /////////////////////////////////////////////////////////////////
0016 
0017 
0018 class getid3_szip extends getid3_handler
0019 {
0020 
0021   public function Analyze() {
0022     $info = &$this->getid3->info;
0023 
0024     $this->fseek($info['avdataoffset']);
0025     $SZIPHeader = $this->fread(6);
0026     if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") {
0027       $info['error'][] = 'Expecting "53 5A 0A 04" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($SZIPHeader, 0, 4)).'"';
0028       return false;
0029     }
0030     $info['fileformat']            = 'szip';
0031     $info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1));
0032     $info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1));
0033 $info['error'][] = 'SZIP parsing not enabled in this version of getID3() ['.$this->getid3->version().']';
0034 return false;
0035 
0036     while (!$this->feof()) {
0037       $NextBlockID = $this->fread(2);
0038       switch ($NextBlockID) {
0039         case 'SZ':
0040           // Note that szip files can be concatenated, this has the same effect as
0041           // concatenating the files. this also means that global header blocks
0042           // might be present between directory/data blocks.
0043           $this->fseek(4, SEEK_CUR);
0044           break;
0045 
0046         case 'BH':
0047           $BHheaderbytes  = getid3_lib::BigEndian2Int($this->fread(3));
0048           $BHheaderdata   = $this->fread($BHheaderbytes);
0049           $BHheaderoffset = 0;
0050           while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) {
0051             //filename as \0 terminated string  (empty string indicates end)
0052             //owner as \0 terminated string (empty is same as last file)
0053             //group as \0 terminated string (empty is same as last file)
0054             //3 byte filelength in this block
0055             //2 byte access flags
0056             //4 byte creation time (like in unix)
0057             //4 byte modification time (like in unix)
0058             //4 byte access time (like in unix)
0059 
0060             $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
0061             $BHheaderoffset += (strlen($BHdataArray['filename']) + 1);
0062 
0063             $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
0064             $BHheaderoffset += (strlen($BHdataArray['owner']) + 1);
0065 
0066             $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
0067             $BHheaderoffset += (strlen($BHdataArray['group']) + 1);
0068 
0069             $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3));
0070             $BHheaderoffset += 3;
0071 
0072             $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2));
0073             $BHheaderoffset += 2;
0074 
0075             $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
0076             $BHheaderoffset += 4;
0077 
0078             $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
0079             $BHheaderoffset += 4;
0080 
0081             $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
0082             $BHheaderoffset += 4;
0083 
0084             $info['szip']['BH'][] = $BHdataArray;
0085           }
0086           break;
0087 
0088         default:
0089           break 2;
0090       }
0091     }
0092 
0093     return true;
0094 
0095   }
0096 
0097 }