public function Analyze() { $info =& $this->getid3->info; $info['fileformat'] = 'rar'; if ($this->option_use_rar_extension === true) { if (function_exists('rar_open')) { if ($rp = rar_open($info['filenamepath'])) { $info['rar']['files'] = array(); $entries = rar_list($rp); foreach ($entries as $entry) { $info['rar']['files'] = Utils::array_merge_clobber($info['rar']['files'], Utils::CreateDeepArray($entry->getName(), '/', $entry->getUnpackedSize())); } rar_close($rp); return true; } else { $info['error'][] = 'failed to rar_open(' . $info['filename'] . ')'; } } else { $info['error'][] = 'RAR support does not appear to be available in this PHP installation'; } } else { $info['error'][] = 'PHP-RAR processing has been disabled (set ' . get_class($this) . '->option_use_rar_extension=true to enable)'; } return false; }
public function Analyze() { $info =& $this->getid3->info; $info['fileformat'] = 'zip'; $info['zip']['encoding'] = 'ISO-8859-1'; $info['zip']['files'] = array(); $info['zip']['compressed_size'] = 0; $info['zip']['uncompressed_size'] = 0; $info['zip']['entries_count'] = 0; if (!Utils::intValueSupported($info['filesize'])) { $info['error'][] = 'File is larger than ' . round(PHP_INT_MAX / 1073741824) . 'GB, not supported by PHP'; return false; } else { $EOCDsearchData = ''; $EOCDsearchCounter = 0; while ($EOCDsearchCounter++ < 512) { $this->fseek(-128 * $EOCDsearchCounter, SEEK_END); $EOCDsearchData = $this->fread(128) . $EOCDsearchData; if (strstr($EOCDsearchData, 'PK' . "")) { $EOCDposition = strpos($EOCDsearchData, 'PK' . ""); $this->fseek(-128 * $EOCDsearchCounter + $EOCDposition, SEEK_END); $info['zip']['end_central_directory'] = $this->ZIPparseEndOfCentralDirectory(); $this->fseek($info['zip']['end_central_directory']['directory_offset']); $info['zip']['entries_count'] = 0; while ($centraldirectoryentry = $this->ZIPparseCentralDirectory($this->getid3->fp)) { $info['zip']['central_directory'][] = $centraldirectoryentry; $info['zip']['entries_count']++; $info['zip']['compressed_size'] += $centraldirectoryentry['compressed_size']; $info['zip']['uncompressed_size'] += $centraldirectoryentry['uncompressed_size']; //if ($centraldirectoryentry['uncompressed_size'] > 0) { zero-byte files are valid if (!empty($centraldirectoryentry['filename'])) { $info['zip']['files'] = Utils::array_merge_clobber($info['zip']['files'], Utils::CreateDeepArray($centraldirectoryentry['filename'], '/', $centraldirectoryentry['uncompressed_size'])); } } if ($info['zip']['entries_count'] == 0) { $info['error'][] = 'No Central Directory entries found (truncated file?)'; return false; } if (!empty($info['zip']['end_central_directory']['comment'])) { $info['zip']['comments']['comment'][] = $info['zip']['end_central_directory']['comment']; } if (isset($info['zip']['central_directory'][0]['compression_method'])) { $info['zip']['compression_method'] = $info['zip']['central_directory'][0]['compression_method']; } if (isset($info['zip']['central_directory'][0]['flags']['compression_speed'])) { $info['zip']['compression_speed'] = $info['zip']['central_directory'][0]['flags']['compression_speed']; } if (isset($info['zip']['compression_method']) && $info['zip']['compression_method'] == 'store' && !isset($info['zip']['compression_speed'])) { $info['zip']['compression_speed'] = 'store'; } // secondary check - we (should) already have all the info we NEED from the Central Directory above, but scanning each // Local File Header entry will foreach ($info['zip']['central_directory'] as $central_directory_entry) { $this->fseek($central_directory_entry['entry_offset']); if ($fileentry = $this->ZIPparseLocalFileHeader()) { $info['zip']['entries'][] = $fileentry; } else { $info['warning'][] = 'Error parsing Local File Header at offset ' . $central_directory_entry['entry_offset']; } } if (!empty($info['zip']['files']['[Content_Types].xml']) && !empty($info['zip']['files']['_rels']['.rels']) && !empty($info['zip']['files']['docProps']['app.xml']) && !empty($info['zip']['files']['docProps']['core.xml'])) { // http://technet.microsoft.com/en-us/library/cc179224.aspx $info['fileformat'] = 'zip.msoffice'; if (!empty($ThisFileInfo['zip']['files']['ppt'])) { $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; } elseif (!empty($ThisFileInfo['zip']['files']['xl'])) { $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; } elseif (!empty($ThisFileInfo['zip']['files']['word'])) { $info['mime_type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; } } return true; } } } if (!$this->getZIPentriesFilepointer()) { unset($info['zip']); $info['fileformat'] = ''; $info['error'][] = 'Cannot find End Of Central Directory (truncated file?)'; return false; } // central directory couldn't be found and/or parsed // scan through actual file data entries, recover as much as possible from probable trucated file if ($info['zip']['compressed_size'] > $info['filesize'] - 46 - 22) { $info['error'][] = 'Warning: Truncated file! - Total compressed file sizes (' . $info['zip']['compressed_size'] . ' bytes) is greater than filesize minus Central Directory and End Of Central Directory structures (' . ($info['filesize'] - 46 - 22) . ' bytes)'; } $info['error'][] = 'Cannot find End Of Central Directory - returned list of files in [zip][entries] array may not be complete'; foreach ($info['zip']['entries'] as $key => $valuearray) { $info['zip']['files'][$valuearray['filename']] = $valuearray['uncompressed_size']; } return true; }
public function ParseDirectoryRecord($directorydata) { $info =& $this->getid3->info; if (isset($info['iso']['supplementary_volume_descriptor'])) { $TextEncoding = 'UTF-16BE'; // Big-Endian Unicode } else { $TextEncoding = 'ISO-8859-1'; // Latin-1 } $this->fseek($directorydata['location_bytes']); $DirectoryRecordData = $this->fread(1); while (ord($DirectoryRecordData[0]) > 33) { $DirectoryRecordData .= $this->fread(ord($DirectoryRecordData[0]) - 1); $ThisDirectoryRecord['raw']['length'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 0, 1)); $ThisDirectoryRecord['raw']['extended_attribute_length'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 1, 1)); $ThisDirectoryRecord['raw']['offset_logical'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 2, 4)); $ThisDirectoryRecord['raw']['filesize'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 10, 4)); $ThisDirectoryRecord['raw']['recording_date_time'] = substr($DirectoryRecordData, 18, 7); $ThisDirectoryRecord['raw']['file_flags'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 25, 1)); $ThisDirectoryRecord['raw']['file_unit_size'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 26, 1)); $ThisDirectoryRecord['raw']['interleave_gap_size'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 27, 1)); $ThisDirectoryRecord['raw']['volume_sequence_number'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 28, 2)); $ThisDirectoryRecord['raw']['file_identifier_length'] = Utils::LittleEndian2Int(substr($DirectoryRecordData, 32, 1)); $ThisDirectoryRecord['raw']['file_identifier'] = substr($DirectoryRecordData, 33, $ThisDirectoryRecord['raw']['file_identifier_length']); $ThisDirectoryRecord['file_identifier_ascii'] = Utils::iconv_fallback($TextEncoding, $info['encoding'], $ThisDirectoryRecord['raw']['file_identifier']); $ThisDirectoryRecord['filesize'] = $ThisDirectoryRecord['raw']['filesize']; $ThisDirectoryRecord['offset_bytes'] = $ThisDirectoryRecord['raw']['offset_logical'] * 2048; $ThisDirectoryRecord['file_flags']['hidden'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x1); $ThisDirectoryRecord['file_flags']['directory'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x2); $ThisDirectoryRecord['file_flags']['associated'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x4); $ThisDirectoryRecord['file_flags']['extended'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x8); $ThisDirectoryRecord['file_flags']['permissions'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x10); $ThisDirectoryRecord['file_flags']['multiple'] = (bool) ($ThisDirectoryRecord['raw']['file_flags'] & 0x80); $ThisDirectoryRecord['recording_timestamp'] = $this->ISOtime2UNIXtime($ThisDirectoryRecord['raw']['recording_date_time']); if ($ThisDirectoryRecord['file_flags']['directory']) { $ThisDirectoryRecord['filename'] = $directorydata['full_path']; } else { $ThisDirectoryRecord['filename'] = $directorydata['full_path'] . $this->ISOstripFilenameVersion($ThisDirectoryRecord['file_identifier_ascii']); $info['iso']['files'] = Utils::array_merge_clobber($info['iso']['files'], Utils::CreateDeepArray($ThisDirectoryRecord['filename'], '/', $ThisDirectoryRecord['filesize'])); } $DirectoryRecord[] = $ThisDirectoryRecord; $DirectoryRecordData = $this->fread(1); } return $DirectoryRecord; }
public function Analyze() { $info =& $this->getid3->info; $info['fileformat'] = 'tar'; $info['tar']['files'] = array(); $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155prefix'; $null_512k = str_repeat("", 512); // end-of-file marker $this->fseek(0); while (!feof($this->getid3->fp)) { $buffer = $this->fread(512); if (strlen($buffer) < 512) { break; } // check the block $checksum = 0; for ($i = 0; $i < 148; $i++) { $checksum += ord($buffer[$i]); } for ($i = 148; $i < 156; $i++) { $checksum += ord(' '); } for ($i = 156; $i < 512; $i++) { $checksum += ord($buffer[$i]); } $attr = unpack($unpack_header, $buffer); $name = isset($attr['fname']) ? trim($attr['fname']) : ''; $mode = octdec(isset($attr['mode']) ? trim($attr['mode']) : ''); $uid = octdec(isset($attr['uid']) ? trim($attr['uid']) : ''); $gid = octdec(isset($attr['gid']) ? trim($attr['gid']) : ''); $size = octdec(isset($attr['size']) ? trim($attr['size']) : ''); $mtime = octdec(isset($attr['mtime']) ? trim($attr['mtime']) : ''); $chksum = octdec(isset($attr['chksum']) ? trim($attr['chksum']) : ''); $typflag = isset($attr['typflag']) ? trim($attr['typflag']) : ''; $lnkname = isset($attr['lnkname']) ? trim($attr['lnkname']) : ''; $magic = isset($attr['magic']) ? trim($attr['magic']) : ''; $ver = isset($attr['ver']) ? trim($attr['ver']) : ''; $uname = isset($attr['uname']) ? trim($attr['uname']) : ''; $gname = isset($attr['gname']) ? trim($attr['gname']) : ''; $devmaj = octdec(isset($attr['devmaj']) ? trim($attr['devmaj']) : ''); $devmin = octdec(isset($attr['devmin']) ? trim($attr['devmin']) : ''); $prefix = isset($attr['prefix']) ? trim($attr['prefix']) : ''; if ($checksum == 256 && $chksum == 0) { // EOF Found break; } if ($prefix) { $name = $prefix . '/' . $name; } if (preg_match('#/$#', $name) && !$name) { $typeflag = 5; } if ($buffer == $null_512k) { // it's the end of the tar-file... break; } // Read to the next chunk $this->fseek($size, SEEK_CUR); $diff = $size % 512; if ($diff != 0) { // Padding, throw away $this->fseek(512 - $diff, SEEK_CUR); } // Protect against tar-files with garbage at the end if ($name == '') { break; } $info['tar']['file_details'][$name] = array('name' => $name, 'mode_raw' => $mode, 'mode' => self::display_perms($mode), 'uid' => $uid, 'gid' => $gid, 'size' => $size, 'mtime' => $mtime, 'chksum' => $chksum, 'typeflag' => self::get_flag_type($typflag), 'linkname' => $lnkname, 'magic' => $magic, 'version' => $ver, 'uname' => $uname, 'gname' => $gname, 'devmajor' => $devmaj, 'devminor' => $devmin); $info['tar']['files'] = Utils::array_merge_clobber($info['tar']['files'], Utils::CreateDeepArray($info['tar']['file_details'][$name]['name'], '/', $size)); } return true; }