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 /////////////////////////////////////////////////////////////////
11 // module.archive.szip.php //
12 // module for analyzing SZIP compressed files //
13 // dependencies: NONE //
15 /////////////////////////////////////////////////////////////////
18 class getid3_szip
extends getid3_handler
23 public function Analyze() {
24 $info = &$this->getid3
->info
;
26 $this->fseek($info['avdataoffset']);
27 $SZIPHeader = $this->fread(6);
28 if (substr($SZIPHeader, 0, 4) != "SZ\x0A\x04") {
29 $this->error('Expecting "53 5A 0A 04" at offset '.$info['avdataoffset'].', found "'.getid3_lib
::PrintHexBytes(substr($SZIPHeader, 0, 4)).'"');
32 $info['fileformat'] = 'szip';
33 $info['szip']['major_version'] = getid3_lib
::BigEndian2Int(substr($SZIPHeader, 4, 1));
34 $info['szip']['minor_version'] = getid3_lib
::BigEndian2Int(substr($SZIPHeader, 5, 1));
35 $this->error('SZIP parsing not enabled in this version of getID3() ['.$this->getid3
->version().']');
38 while (!$this->feof()) {
39 $NextBlockID = $this->fread(2);
40 switch ($NextBlockID) {
42 // Note that szip files can be concatenated, this has the same effect as
43 // concatenating the files. this also means that global header blocks
44 // might be present between directory/data blocks.
45 $this->fseek(4, SEEK_CUR
);
49 $BHheaderbytes = getid3_lib
::BigEndian2Int($this->fread(3));
50 $BHheaderdata = $this->fread($BHheaderbytes);
52 while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) {
53 //filename as \0 terminated string (empty string indicates end)
54 //owner as \0 terminated string (empty is same as last file)
55 //group as \0 terminated string (empty is same as last file)
56 //3 byte filelength in this block
58 //4 byte creation time (like in unix)
59 //4 byte modification time (like in unix)
60 //4 byte access time (like in unix)
62 $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
63 $BHheaderoffset +
= (strlen($BHdataArray['filename']) +
1);
65 $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
66 $BHheaderoffset +
= (strlen($BHdataArray['owner']) +
1);
68 $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
69 $BHheaderoffset +
= (strlen($BHdataArray['group']) +
1);
71 $BHdataArray['filelength'] = getid3_lib
::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3));
74 $BHdataArray['access_flags'] = getid3_lib
::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2));
77 $BHdataArray['creation_time'] = getid3_lib
::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
80 $BHdataArray['modification_time'] = getid3_lib
::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
83 $BHdataArray['access_time'] = getid3_lib
::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
86 $info['szip']['BH'][] = $BHdataArray;