1 | <?php |
---|
2 | ///////////////////////////////////////////////////////////////// |
---|
3 | /// getID3() by James Heinrich <info@getid3.org> // |
---|
4 | // available at http://getid3.sourceforge.net // |
---|
5 | // or http://www.getid3.org // |
---|
6 | ///////////////////////////////////////////////////////////////// |
---|
7 | // See readme.txt for more details // |
---|
8 | ///////////////////////////////////////////////////////////////// |
---|
9 | // // |
---|
10 | // module.archive.szip.php // |
---|
11 | // module for analyzing SZIP compressed files // |
---|
12 | // dependencies: NONE // |
---|
13 | // /// |
---|
14 | ///////////////////////////////////////////////////////////////// |
---|
15 | |
---|
16 | |
---|
17 | class getid3_szip |
---|
18 | { |
---|
19 | |
---|
20 | function getid3_szip(&$fd, &$ThisFileInfo) { |
---|
21 | |
---|
22 | fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET); |
---|
23 | $SZIPHeader = fread($fd, 6); |
---|
24 | if (substr($SZIPHeader, 0, 4) != 'SZ'."\x0A\x04") { |
---|
25 | $ThisFileInfo['error'][] = 'Expecting "SZ[x0A][x04]" at offset '.$ThisFileInfo['avdataoffset'].', found "'.substr($SZIPHeader, 0, 4).'"'; |
---|
26 | return false; |
---|
27 | } |
---|
28 | |
---|
29 | $ThisFileInfo['fileformat'] = 'szip'; |
---|
30 | |
---|
31 | $ThisFileInfo['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1)); |
---|
32 | $ThisFileInfo['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1)); |
---|
33 | |
---|
34 | while (!feof($fd)) { |
---|
35 | $NextBlockID = fread($fd, 2); |
---|
36 | switch ($NextBlockID) { |
---|
37 | case 'SZ': |
---|
38 | // Note that szip files can be concatenated, this has the same effect as |
---|
39 | // concatenating the files. this also means that global header blocks |
---|
40 | // might be present between directory/data blocks. |
---|
41 | fseek($fd, 4, SEEK_CUR); |
---|
42 | break; |
---|
43 | |
---|
44 | case 'BH': |
---|
45 | $BHheaderbytes = getid3_lib::BigEndian2Int(fread($fd, 3)); |
---|
46 | $BHheaderdata = fread($fd, $BHheaderbytes); |
---|
47 | $BHheaderoffset = 0; |
---|
48 | while (strpos($BHheaderdata, "\x00", $BHheaderoffset) > 0) { |
---|
49 | //filename as \0 terminated string (empty string indicates end) |
---|
50 | //owner as \0 terminated string (empty is same as last file) |
---|
51 | //group as \0 terminated string (empty is same as last file) |
---|
52 | //3 byte filelength in this block |
---|
53 | //2 byte access flags |
---|
54 | //4 byte creation time (like in unix) |
---|
55 | //4 byte modification time (like in unix) |
---|
56 | //4 byte access time (like in unix) |
---|
57 | |
---|
58 | $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); |
---|
59 | $BHheaderoffset += (strlen($BHdataArray['filename']) + 1); |
---|
60 | |
---|
61 | $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); |
---|
62 | $BHheaderoffset += (strlen($BHdataArray['owner']) + 1); |
---|
63 | |
---|
64 | $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); |
---|
65 | $BHheaderoffset += (strlen($BHdataArray['group']) + 1); |
---|
66 | |
---|
67 | $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3)); |
---|
68 | $BHheaderoffset += 3; |
---|
69 | |
---|
70 | $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2)); |
---|
71 | $BHheaderoffset += 2; |
---|
72 | |
---|
73 | $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); |
---|
74 | $BHheaderoffset += 4; |
---|
75 | |
---|
76 | $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); |
---|
77 | $BHheaderoffset += 4; |
---|
78 | |
---|
79 | $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); |
---|
80 | $BHheaderoffset += 4; |
---|
81 | |
---|
82 | $ThisFileInfo['szip']['BH'][] = $BHdataArray; |
---|
83 | } |
---|
84 | break; |
---|
85 | |
---|
86 | default: |
---|
87 | break 2; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | return true; |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | } |
---|
96 | |
---|
97 | ?> |
---|