File: module.archive.7zip.php

package info (click to toggle)
php-getid3 1.9.23%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,032 kB
  • sloc: php: 34,712; makefile: 10
file content (52 lines) | stat: -rw-r--r-- 2,436 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

/////////////////////////////////////////////////////////////////
/// getID3() by James Heinrich <info@getid3.org>               //
//  available at https://github.com/JamesHeinrich/getID3       //
//            or https://www.getid3.org                        //
//            or http://getid3.sourceforge.net                 //
//  see readme.txt for more details                            //
/////////////////////////////////////////////////////////////////
//                                                             //
// module.archive.7zip.php                                     //
// module for analyzing 7zip files                             //
// dependencies: NONE                                          //
//                                                            ///
/////////////////////////////////////////////////////////////////

if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
	exit;
}

class getid3_7zip extends getid3_handler
{
	/**
	 * @return bool
	 */
	public function Analyze() {
		$info = &$this->getid3->info;

		$this->fseek($info['avdataoffset']);
		$z7header = $this->fread(32);

		// https://py7zr.readthedocs.io/en/latest/archive_format.html
		$info['7zip']['header']['magic'] = substr($z7header, 0, 6);
		if ($info['7zip']['header']['magic'] != '7z'."\xBC\xAF\x27\x1C") {
			$this->error('Invalid 7zip stream header magic (expecting 37 7A BC AF 27 1C, found '.getid3_lib::PrintHexBytes($info['7zip']['header']['magic']).') at offset '.$info['avdataoffset']);
			return false;
		}
		$info['fileformat'] = '7zip';

		$info['7zip']['header']['version_major']      = getid3_lib::LittleEndian2Int(substr($z7header,  6, 1)); // always 0x00 (?)
		$info['7zip']['header']['version_minor']      = getid3_lib::LittleEndian2Int(substr($z7header,  7, 1)); // always 0x04 (?)
		$info['7zip']['header']['start_header_crc']   = getid3_lib::LittleEndian2Int(substr($z7header,  8, 4));
		$info['7zip']['header']['next_header_offset'] = getid3_lib::LittleEndian2Int(substr($z7header, 12, 8));
		$info['7zip']['header']['next_header_size']   = getid3_lib::LittleEndian2Int(substr($z7header, 20, 8));
		$info['7zip']['header']['next_header_crc']    = getid3_lib::LittleEndian2Int(substr($z7header, 28, 4));

$this->error('7zip parsing not enabled in this version of getID3() ['.$this->getid3->version().']');
		return false;

	}

}