[3318] | 1 | <?php |
---|
[3544] | 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 | ///////////////////////////////////////////////////////////////// |
---|
[3318] | 15 | |
---|
[3544] | 16 | |
---|
| 17 | class getid3_szip |
---|
[3318] | 18 | { |
---|
| 19 | |
---|
[3544] | 20 | function getid3_szip(&$fd, &$ThisFileInfo) { |
---|
[3318] | 21 | |
---|
[3544] | 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 | } |
---|
[3318] | 28 | |
---|
[3544] | 29 | $ThisFileInfo['fileformat'] = 'szip'; |
---|
[3318] | 30 | |
---|
[3544] | 31 | $ThisFileInfo['szip']['major_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 4, 1)); |
---|
| 32 | $ThisFileInfo['szip']['minor_version'] = getid3_lib::BigEndian2Int(substr($SZIPHeader, 5, 1)); |
---|
[3318] | 33 | |
---|
[3544] | 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; |
---|
[3318] | 43 | |
---|
[3544] | 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) |
---|
[3318] | 57 | |
---|
[3544] | 58 | $BHdataArray['filename'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); |
---|
| 59 | $BHheaderoffset += (strlen($BHdataArray['filename']) + 1); |
---|
[3318] | 60 | |
---|
[3544] | 61 | $BHdataArray['owner'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); |
---|
| 62 | $BHheaderoffset += (strlen($BHdataArray['owner']) + 1); |
---|
[3318] | 63 | |
---|
[3544] | 64 | $BHdataArray['group'] = substr($BHheaderdata, $BHheaderoffset, strcspn($BHheaderdata, "\x00")); |
---|
| 65 | $BHheaderoffset += (strlen($BHdataArray['group']) + 1); |
---|
[3318] | 66 | |
---|
[3544] | 67 | $BHdataArray['filelength'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 3)); |
---|
| 68 | $BHheaderoffset += 3; |
---|
[3318] | 69 | |
---|
[3544] | 70 | $BHdataArray['access_flags'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 2)); |
---|
| 71 | $BHheaderoffset += 2; |
---|
[3318] | 72 | |
---|
[3544] | 73 | $BHdataArray['creation_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); |
---|
| 74 | $BHheaderoffset += 4; |
---|
[3318] | 75 | |
---|
[3544] | 76 | $BHdataArray['modification_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); |
---|
| 77 | $BHheaderoffset += 4; |
---|
[3318] | 78 | |
---|
[3544] | 79 | $BHdataArray['access_time'] = getid3_lib::BigEndian2Int(substr($BHheaderdata, $BHheaderoffset, 4)); |
---|
| 80 | $BHheaderoffset += 4; |
---|
[3318] | 81 | |
---|
[3544] | 82 | $ThisFileInfo['szip']['BH'][] = $BHdataArray; |
---|
| 83 | } |
---|
| 84 | break; |
---|
[3318] | 85 | |
---|
[3544] | 86 | default: |
---|
| 87 | break 2; |
---|
| 88 | } |
---|
| 89 | } |
---|
[3318] | 90 | |
---|
[3544] | 91 | return true; |
---|
| 92 | |
---|
| 93 | } |
---|
| 94 | |
---|
[3318] | 95 | } |
---|
| 96 | |
---|
| 97 | ?> |
---|