rlm@3: <?php
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | PHP version 5                                                        |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen                 |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | This source file is subject to version 2 of the GPL license,         |
rlm@3: // | that is bundled with this package in the file license.txt and is     |
rlm@3: // | available through the world-wide-web at the following url:           |
rlm@3: // | http://www.gnu.org/copyleft/gpl.html                                 |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | Authors: James Heinrich <infoØgetid3*org>                            |
rlm@3: // |          Allan Hansen <ahØartemis*dk>                                |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: // | module.archive.szip.php                                              |
rlm@3: // | module for analyzing SZIP compressed files                           |
rlm@3: // | dependencies: NONE                                                   |
rlm@3: // +----------------------------------------------------------------------+
rlm@3: //
rlm@3: // $Id: module.archive.szip.php,v 1.2 2006/11/02 10:48:00 ah Exp $
rlm@3: 
rlm@3:         
rlm@3:         
rlm@3: class getid3_szip extends getid3_handler
rlm@3: {
rlm@3: 
rlm@3:     public function Analyze() {
rlm@3:         
rlm@3:         $getid3 = $this->getid3;
rlm@3: 
rlm@3:         fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET);
rlm@3:         $szip_rkau = fread($getid3->fp, 6);
rlm@3:         
rlm@3:         // Magic bytes:  'SZ'."\x0A\x04"
rlm@3:             
rlm@3:         $getid3->info['fileformat']            = 'szip';
rlm@3: 
rlm@3:         $getid3->info['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($szip_rkau, 4, 1));
rlm@3:         $getid3->info['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($szip_rkau, 5, 1));
rlm@3: 
rlm@3:         while (!feof($getid3->fp)) {
rlm@3:             $next_block_id = fread($getid3->fp, 2);
rlm@3:             switch ($next_block_id) {
rlm@3:                 case 'SZ':
rlm@3:                     // Note that szip files can be concatenated, this has the same effect as
rlm@3:                     // concatenating the files. this also means that global header blocks
rlm@3:                     // might be present between directory/data blocks.
rlm@3:                     fseek($getid3->fp, 4, SEEK_CUR);
rlm@3:                     break;
rlm@3: 
rlm@3:                 case 'BH':
rlm@3:                     $bh_header_bytes  = getid3_lib::BigEndian2Int(fread($getid3->fp, 3));
rlm@3:                     $bh_header_data   = fread($getid3->fp, $bh_header_bytes);
rlm@3:                     $bh_header_offset = 0;
rlm@3:                     while (strpos($bh_header_data, "\x00", $bh_header_offset) > 0) {
rlm@3:                         //filename as \0 terminated string  (empty string indicates end)
rlm@3:                         //owner as \0 terminated string (empty is same as last file)
rlm@3:                         //group as \0 terminated string (empty is same as last file)
rlm@3:                         //3 byte filelength in this block
rlm@3:                         //2 byte access flags
rlm@3:                         //4 byte creation time (like in unix)
rlm@3:                         //4 byte modification time (like in unix)
rlm@3:                         //4 byte access time (like in unix)
rlm@3: 
rlm@3:                         $bh_data_array['filename'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "\x00"));
rlm@3:                         $bh_header_offset += (strlen($bh_data_array['filename']) + 1);
rlm@3: 
rlm@3:                         $bh_data_array['owner'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "\x00"));
rlm@3:                         $bh_header_offset += (strlen($bh_data_array['owner']) + 1);
rlm@3: 
rlm@3:                         $bh_data_array['group'] = substr($bh_header_data, $bh_header_offset, strcspn($bh_header_data, "\x00"));
rlm@3:                         $bh_header_offset += (strlen($bh_data_array['group']) + 1);
rlm@3: 
rlm@3:                         $bh_data_array['filelength'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 3));
rlm@3:                         $bh_header_offset += 3;
rlm@3: 
rlm@3:                         $bh_data_array['access_flags'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 2));
rlm@3:                         $bh_header_offset += 2;
rlm@3: 
rlm@3:                         $bh_data_array['creation_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4));
rlm@3:                         $bh_header_offset += 4;
rlm@3: 
rlm@3:                         $bh_data_array['modification_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4));
rlm@3:                         $bh_header_offset += 4;
rlm@3: 
rlm@3:                         $bh_data_array['access_time'] = getid3_lib::BigEndian2Int(substr($bh_header_data, $bh_header_offset, 4));
rlm@3:                         $bh_header_offset += 4;
rlm@3: 
rlm@3:                         $getid3->info['szip']['BH'][] = $bh_data_array;
rlm@3:                     }
rlm@3:                     break;
rlm@3: 
rlm@3:                 default:
rlm@3:                     break 2;
rlm@3:             }
rlm@3:         }
rlm@3: 
rlm@3:         return true;
rlm@3:     }
rlm@3: 
rlm@3: }
rlm@3: 
rlm@3: ?>