[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / medias / lib / getid3 / module.archive.szip.php
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
17
18 class getid3_szip extends getid3_handler
19 {
20 /**
21 * @return bool
22 */
23 public function Analyze() {
24 $info = &$this->getid3->info;
25
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)).'"');
30 return false;
31 }
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().']');
36 return false;
37
38 while (!$this->feof()) {
39 $NextBlockID = $this->fread(2);
40 switch ($NextBlockID) {
41 case 'SZ':
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);
46 break;
47
48 case 'BH':
49 $BHheaderbytes = getid3_lib::BigEndian2Int($this->fread(3));
50 $BHheaderdata = $this->fread($BHheaderbytes);
51 $BHheaderoffset = 0;
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
57 //2 byte access flags
58 //4 byte creation time (like in unix)
59 //4 byte modification time (like in unix)
60 //4 byte access time (like in unix)
61
62 $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
63 $BHheaderoffset += (strlen($BHdataArray['filename']) + 1);
64
65 $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
66 $BHheaderoffset += (strlen($BHdataArray['owner']) + 1);
67
68 $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00"));
69 $BHheaderoffset += (strlen($BHdataArray['group']) + 1);
70
71 $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3));
72 $BHheaderoffset += 3;
73
74 $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2));
75 $BHheaderoffset += 2;
76
77 $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
78 $BHheaderoffset += 4;
79
80 $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
81 $BHheaderoffset += 4;
82
83 $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4));
84 $BHheaderoffset += 4;
85
86 $info['szip']['BH'][] = $BHdataArray;
87 }
88 break;
89
90 default:
91 break 2;
92 }
93 }
94
95 return true;
96
97 }
98
99 }