Completed
Push — vendor/getid3 ( 49c253...dfd0b4 )
by Pauli
02:49
created

getid3_hpk::Analyze()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 65
rs 8.7636
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/////////////////////////////////////////////////////////////////
4
/// getID3() by James Heinrich <[email protected]>               //
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.hpk.php                                      //
12
// module for analyzing HPK files                              //
13
// dependencies: NONE                                          //
14
//                                                            ///
15
/////////////////////////////////////////////////////////////////
16
17
if (!defined('GETID3_INCLUDEPATH')) { // prevent path-exposing attacks that access modules directly on public webservers
18
	exit;
19
}
20
21
class getid3_hpk extends getid3_handler
22
{
23
	/**
24
	 * @return bool
25
	 */
26
	public function Analyze() {
27
		$info = &$this->getid3->info;
28
29
		$info['fileformat'] = 'hpk';
30
31
		$this->fseek($info['avdataoffset']);
32
		$HPKheader = $this->fread(36);
33
34
		if (substr($HPKheader, 0, 4) == 'BPUL') {
35
36
			$info['hpk']['header']['signature']                    =                              substr($HPKheader,  0, 4);
37
			$info['hpk']['header']['data_offset']                  = getid3_lib::LittleEndian2Int(substr($HPKheader,  4, 4));
38
			$info['hpk']['header']['fragments_per_file']           = getid3_lib::LittleEndian2Int(substr($HPKheader,  8, 4));
39
			//$info['hpk']['header']['unknown1']                     = getid3_lib::LittleEndian2Int(substr($HPKheader, 12, 4));
40
			$info['hpk']['header']['fragments_residual_offset']    = getid3_lib::LittleEndian2Int(substr($HPKheader, 16, 4));
41
			$info['hpk']['header']['fragments_residual_count']     = getid3_lib::LittleEndian2Int(substr($HPKheader, 20, 4));
42
			//$info['hpk']['header']['unknown2']                     = getid3_lib::LittleEndian2Int(substr($HPKheader, 24, 4));
43
			$info['hpk']['header']['fragmented_filesystem_offset'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 28, 4));
44
			$info['hpk']['header']['fragmented_filesystem_length'] = getid3_lib::LittleEndian2Int(substr($HPKheader, 32, 4));
45
46
			$info['hpk']['header']['filesystem_entries'] = $info['hpk']['header']['fragmented_filesystem_length'] / ($info['hpk']['header']['fragments_per_file'] * 8);
47
			$this->fseek($info['hpk']['header']['fragmented_filesystem_offset']);
48
			for ($i = 0; $i < $info['hpk']['header']['filesystem_entries']; $i++) {
49
				$offset = getid3_lib::LittleEndian2Int($this->fread(4));
0 ignored issues
show
Security Bug introduced by
It seems like $this->fread(4) targeting getid3_handler::fread() can also be of type false; however, getid3_lib::LittleEndian2Int() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
50
				$length = getid3_lib::LittleEndian2Int($this->fread(4));
0 ignored issues
show
Security Bug introduced by
It seems like $this->fread(4) targeting getid3_handler::fread() can also be of type false; however, getid3_lib::LittleEndian2Int() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
51
				$info['hpk']['filesystem'][$i] = array('offset' => $offset, 'length' => $length);
52
			}
53
54
$this->error('HPK parsing incomplete (and mostly broken) in this version of getID3() ['.$this->getid3->version().']');
55
56
/*
57
			$filename = '';
58
			$dirs = array();
59
			foreach ($info['hpk']['filesystem'] as $key => $filesystemdata) {
60
				$this->fseek($filesystemdata['offset']);
61
				$first4 = $this->fread(4);
62
				if (($first4 == 'LZ4 ') || ($first4 == 'ZLIB')) {
63
					// actual data, ignore
64
					$info['hpk']['toc'][$key] = array(
65
						'filename' => ltrim(implode('/', $dirs).'/'.$filename, '/'),
66
						'offset'   => $filesystemdata['offset'],
67
						'length'   => $filesystemdata['length'],
68
					);
69
					$filename = '';
70
					$dirs = array();
71
				} else {
72
					$fragment_index = getid3_lib::LittleEndian2Int($first4);
73
					$fragment_type  = getid3_lib::LittleEndian2Int($this->fread(4)); // file = 0, directory = 1
74
					$name_length    = getid3_lib::LittleEndian2Int($this->fread(2));
75
					if ($fragment_type == 1) {
76
						$dirs[]   = $this->fread($name_length);
77
					} else {
78
						$filename = $this->fread($name_length);
79
					}
80
				}
81
			}
82
*/
83
84
		} else {
85
			$this->error('Expecting "BPUL" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($HPKheader, 0, 4)).'"');
86
			return false;
87
		}
88
89
		return true;
90
	}
91
92
}
93