/** * Check if the data is a ZIP / RAR file, extract files, get file info. * * @param string $compressedData * * @return bool */ protected function _processCompressedData(&$compressedData) { $this->_compressedFilesChecked++; // Give the data to archive info so it can check if it's a rar. if ($this->_archiveInfo->setData($compressedData, true) === false) { $this->_debug('Data is probably not RAR or ZIP.' . PHP_EOL); return false; } // Check if there's an error. if ($this->_archiveInfo->error !== '') { $this->_debug('ArchiveInfo Error: ' . $this->_archiveInfo->error); return false; } // Get a summary of the compressed file. $dataSummary = $this->_archiveInfo->getSummary(true); // Check if the compressed file is encrypted. if (!empty($this->_archiveInfo->isEncrypted) || isset($dataSummary['is_encrypted']) && $dataSummary['is_encrypted'] != 0) { $this->_debug('ArchiveInfo: Compressed file has a password.'); $this->_releaseHasPassword = true; $this->_passwordStatus[] = Releases::PASSWD_RAR; return false; } switch ($dataSummary['main_type']) { case \ArchiveInfo::TYPE_RAR: if ($this->_echoCLI) { $this->_echo('r', 'primaryOver', false); } if ($this->_extractUsingRarInfo === false && $this->_unrarPath !== false) { $fileName = $this->tmpPath . uniqid() . '.rar'; file_put_contents($fileName, $compressedData); Misc::runCmd($this->_killString . $this->_unrarPath . '" e -ai -ep -c- -id -inul -kb -or -p- -r -y "' . $fileName . '" "' . $this->tmpPath . 'unrar/"'); unlink($fileName); } break; case \ArchiveInfo::TYPE_ZIP: if ($this->_echoCLI) { $this->_echo('z', 'primaryOver', false); } if ($this->_extractUsingRarInfo === false && $this->_7zipPath !== false) { $fileName = $this->tmpPath . uniqid() . '.zip'; file_put_contents($fileName, $compressedData); Misc::runCmd($this->_killString . $this->_7zipPath . '" x "' . $fileName . '" -bd -y -o"' . $this->tmpPath . 'unzip/"'); unlink($fileName); } break; default: return false; } return $this->_processCompressedFileList(); }
/** * Work out if a release is passworded */ public function processReleasePasswords($fetchedBinary, $tmpPath, $unrarPath, $checkpasswordedrar) { $passStatus = Releases::PASSWD_NONE; $potentiallypasswordedfileregex = "/\\.(ace|cab|tar|gz|url)\$/i"; $definetlypasswordedfileregex = "/password\\.url/i"; $rar = new ArchiveInfo(); $filecount = 0; $rarfile = $tmpPath . 'rarfile.rar'; file_put_contents($rarfile, $fetchedBinary); if ($rar->open($rarfile)) { $rarsummary = $rar->getSummary(true, false); if (isset($rarsummary["is_encrypted"]) && $rarsummary["is_encrypted"] != 0 || !empty($rar->isEncrypted)) { $passStatus = Releases::PASSWD_RAR; } else { $files = $rar->getArchiveFileList(); if ($files !== false) { foreach ($files as $file) { if (isset($file['pass']) && isset($file["name"])) { $filecount++; // // individual file rar passworded // if ($file['pass'] == true || preg_match($definetlypasswordedfileregex, $file["name"])) { $passStatus = Releases::PASSWD_RAR; } elseif (preg_match($potentiallypasswordedfileregex, $file["name"]) && $passStatus != Releases::PASSWD_RAR) { $passStatus = Releases::PASSWD_POTENTIAL; } } } } // // Deep Checking // if ($checkpasswordedrar == 2) { $israr = $this->isRar($rarfile); for ($i = 0; $i < sizeof($israr); $i++) { if (preg_match('/\\\\/', $israr[$i])) { $israr[$i] = ltrim(strrchr($israr[$i], "\\"), "\\"); } } $execstring = '"' . $unrarPath . '" e -ai -ep -c- -id -r -kb -p- -y -inul "' . $rarfile . '" "' . $tmpPath . '"'; $output = Utility::runCmd($execstring, false, true); // delete the rar @unlink($rarfile); // ok, now we have all the files extracted from the rar into the tempdir and // the rar file deleted, now to loop through the files and recursively unrar // if any of those are rars, we don't trust their names and we test every file // for the rar header for ($i = 0; $i < sizeof($israr); $i++) { // even though its in the rar filelist there may not have been enough data // to extract this file so dont attempt to read the file if it doesnt exist if (!file_exists($tmpPath . $israr[$i])) { continue; } $tmp = $this->isRar($tmpPath . $israr[$i]); if (is_array($tmp)) { for ($x = 0; $x < sizeof($tmp); $x++) { if (preg_match('/\\\\/', $tmp[$x])) { $tmp[$x] = ltrim(strrchr($tmp[$x], "\\"), "\\"); } $israr[] = $tmp[$x]; } $execstring = '"' . $unrarPath . '" e -ai -ep -c- -id -r -kb -p- -y -inul "' . $tmpPath . $israr[$i] . '" "' . $tmpPath . '"'; $output2 = Utility::runCmd($execstring, false, true); @unlink($tmpPath . $israr[$i]); } else { if ($tmp == 1 || $tmp == 2) { $passStatus = Releases::PASSWD_RAR; @unlink($tmpPath . $israr[$i]); } } unset($tmp); } } } } @unlink($rarfile); unset($fetchedBinary); return $passStatus; }