protected function doScan(Scanner $scanner) { $start_state = $scanner->getState(); if (empty($this->parsers)) { return true; } $parser = $this->parsers[0]; $count = 0; while (true) { if ($this->max > 0 && $count <= $this->max) { return true; } if (!$parser->trigger($scanner)) { if ($this->min == 0 || $count >= $this->min) { return true; } else { $scanner->setState($start_state); return false; } } if (!$parser->scan($scanner)) { if ($this->min == 0 || $count >= $this->min) { return true; } else { $scanner->setState($start_state); } } $count++; } return true; }
protected function doScan(Scanner $scanner) { $start_state = $scanner->getState(); foreach ($this->parsers as $parser) { if (!($parser->trigger($scanner) && ($scan = $parser->scan($scanner)))) { $scanner->setState($start_state); return false; } } return true; }
protected function doScan(Scanner $scanner) { $type = $scanner->tokenType(); $start_state = null; foreach ($this->parsers as $parser) { $start_state = $scanner->getState(); if ($type == $parser->trigger($scanner) && $parser->scan($scanner)) { return true; } } $scanner->setState($start_state); return false; }
/** * check $path for updates * * @param string $path */ public function checkUpdate($path) { $cachedEntry = $this->cache->get($path); if ($this->storage->hasUpdated($path, $cachedEntry['mtime'])) { if ($this->storage->is_dir($path)) { $this->scanner->scan($path, Scanner::SCAN_SHALLOW); } else { $this->scanner->scanFile($path); } if ($cachedEntry['mimetype'] === 'httpd/unix-directory') { $this->cleanFolder($path); } $this->cache->correctFolderSize($path); } }
/** * */ public static function updateFile($params) { $path = $params['path']; if (!$path) { return; } //fix a bug where there were multiply '/' in front of the path, it should only be one while ($path[0] == '/') { $path = substr($path, 1); } $path = '/' . $path; $collection = new Collection(\OCP\User::getUser()); $scanner = new Scanner($collection); $scanner->scanFile($path); }
/** * Returns metadata from the shared storage, but * with permissions from the source storage. * * @param string $path path of the file for which to retrieve metadata * * @return array an array of metadata of the file */ protected function getData($path) { $data = parent::getData($path); $sourcePath = $this->storage->getSourcePath($path); list($sourceStorage, $internalPath) = \OC\Files\Filesystem::resolvePath($sourcePath); $data['permissions'] = $sourceStorage->getPermissions($internalPath); return $data; }
protected function doScan(Scanner $scanner) { $quotechar = $scanner->tokenType(); $ret = false; $string = ""; while ($token = $scanner->nextToken()) { if ($token == $quotechar) { $ret = true; break; } $string .= $scanner->token(); } if ($string && !$this->discard) { $scanner->getContext()->pushResult($string); } return $ret; }
/** * Update the cache for changes to $path * * @param string $path * @param array $cachedData */ public function update($path, $cachedData) { if ($this->storage->is_dir($path)) { $this->scanner->scan($path, Scanner::SCAN_SHALLOW); } else { $this->scanner->scanFile($path); } if ($cachedData['mimetype'] === 'httpd/unix-directory') { $this->cleanFolder($path); } $this->cache->correctFolderSize($path); }
/** * Function to test scanning of files. */ public function testScanning() { //start the scan. $errors = Scanner::scanDir(__DIR__ . "/../../../framework/control/"); //print the results. echo "\nNormal Display: \n--------------------------\n"; Scanner::displayErrors($errors, "Use of blacklisted keywords found!"); echo "\n\n\n"; echo "\nGCC Style Display: \n--------------------------\n"; Scanner::displayGCCStyleOutput($errors, "Use of blacklisted keywords found!"); echo "\n"; //You can see the results in your screen. }
/** * check $path for updates * * @param string $path * @return boolean|array true if path was updated, otherwise the cached data is returned */ public function checkUpdate($path) { if ($this->watchPolicy === self::CHECK_ALWAYS or $this->watchPolicy === self::CHECK_ONCE and array_search($path, $this->checkedPaths) === false) { $cachedEntry = $this->cache->get($path); $this->checkedPaths[] = $path; if ($this->storage->hasUpdated($path, $cachedEntry['storage_mtime'])) { if ($this->storage->is_dir($path)) { $this->scanner->scan($path, Scanner::SCAN_SHALLOW); } else { $this->scanner->scanFile($path); } if ($cachedEntry['mimetype'] === 'httpd/unix-directory') { $this->cleanFolder($path); } $this->cache->correctFolderSize($path); return true; } return $cachedEntry; } else { return false; } }
/** * Parses a character separated list of instructions or null if the * sequence is not valid * * @param callable $fn Parsing instruction function * @param array $args Arguments that will be passed to the function * @param string $char Separator * * @return array * * @throws Exception */ protected function charSeparatedListOf($fn, $args = array(), $char = ",") { $list = array(); $valid = true; while ($param = call_user_func_array(array($this, $fn), $args)) { $list[] = $param; $valid = true; if (!$this->scanner->consume($char)) { break; } else { $valid = false; } } if (!$valid) { return $this->error(); } return $list; }
/** * Update the cache for $path * * @param string $path * @param int $time */ public function update($path, $time = null) { if (Scanner::isPartialFile($path)) { return; } /** * @var \OC\Files\Storage\Storage $storage * @var string $internalPath */ list($storage, $internalPath) = $this->view->resolvePath($path); if ($storage) { $this->propagator->addChange($path); $cache = $storage->getCache($internalPath); $scanner = $storage->getScanner($internalPath); $data = $scanner->scan($internalPath, Scanner::SCAN_SHALLOW); $this->correctParentStorageMtime($storage, $internalPath); $cache->correctFolderSize($internalPath, $data); $this->propagator->propagateChanges($time); } }
/** * [type] $name [= default] * * @return array * @throws Exception */ public function parse_args() { $token = $this->scanner->next(); if ($token['code'] === T_RPARENTHESIS) { // No arguments $this->scanner->back(); return []; } $arg = ['type' => 'mixed', 'name' => NULL, 'value' => [FALSE, NULL]]; if ($token['code'] === T_ARRAY || $token['code'] === T_STRING) { // type $arg['type'] = $token['value']; $token = $this->scanner->next(); } if ($token['code'] === T_VARIABLE) { $arg['name'] = $token['value']; $token = $this->scanner->next(); } if ($token['code'] === T_ASSIGN) { $token = $this->scanner->next(); $arg['value'] = [TRUE, $token['value']]; if ($token['value'] == '[') { // TODO: allow initialization with non-empty arrays $this->check(T_ARRAY_CLOSE); } $token = $this->scanner->next(); } if ($token['code'] === T_RPARENTHESIS) { $this->scanner->back(); if (is_null($arg['name'])) { return []; } return [$arg]; } elseif ($token['code'] == T_COMMA) { return array_merge([$arg], $this->parse_args()); } }
if ($key != 'files' && $key != 'dirs') { $f2s = $key . '/' . $val; if (substr($f2s, -3) == 'php') { $output .= 'File: ' . $f2s . PHP_EOL; } } } } } else { $info = new SplFileInfo($o2s); $perms = substr(sprintf('%o', $info->getPerms()), -4); $owner = $info->getOwner(); $group = $info->getGroup(); $type = $info->getType(); $size = $info->getSize(); $scanner = new Scanner($o2s, $eol, $htmlMode, $scannerOptions); $scanner->scanFile("all", $patternData, $stringData); if (count($scanner->found)) { foreach ($scanner->found as $l) { $found .= $l; } } else { $found = ''; } //make human readable size $size = $scanner->size_readable($size); } } else { $ainfo = "The file/folder {$bS}{$o2s}{$bE} does not exist"; } //translate . to path if o2s eq .
/** * sign: '!' sign | '+' sign | '-' sign | index */ private static function parseSign(Scanner $scanner) { switch ($scanner->tokenType()) { case '!': $scanner->nextToken(); $result = new NotExpression(self::parseSign($scanner)); break; case '+': $scanner->nextToken(); $result = self::parseSign($scanner); break; case '-': $scanner->nextToken(); $result = new MinusExpression(self::parseSign($scanner)); break; default: $result = self::parseIndex($scanner); } return $result; }
function iterate(Scanner $scanner) { foreach ($this->tokens as $token) { $scanner->accept($token); } }
function trigger(Scanner $scanner) { return $scanner->token() == $this->char; }
<?php include_once 'config/config.php'; include_once 'includes/Scanner.php'; if (!empty($argv[1])) { $project_id = intval($argv[1]); $scanner = new Scanner($project_id); $scanner->performScan(); }
/** * @param string $source * @param string $target */ public function rename($source, $target) { if (Scanner::isPartialFile($source) or Scanner::isPartialFile($target)) { return; } /** * @var \OC\Files\Storage\Storage $sourceStorage * @var \OC\Files\Storage\Storage $targetStorage * @var string $sourceInternalPath * @var string $targetInternalPath */ list($sourceStorage, $sourceInternalPath) = $this->view->resolvePath($source); // if it's a moved mountpoint we dont need to do anything if ($sourceInternalPath === '') { return; } list($targetStorage, $targetInternalPath) = $this->view->resolvePath($target); if ($sourceStorage && $targetStorage) { if ($sourceStorage === $targetStorage) { $cache = $sourceStorage->getCache($sourceInternalPath); $cache->move($sourceInternalPath, $targetInternalPath); if (pathinfo($sourceInternalPath, PATHINFO_EXTENSION) !== pathinfo($targetInternalPath, PATHINFO_EXTENSION)) { // handle mime type change $mimeType = $sourceStorage->getMimeType($targetInternalPath); $fileId = $cache->getId($targetInternalPath); $cache->update($fileId, array('mimetype' => $mimeType)); } $cache->correctFolderSize($sourceInternalPath); $cache->correctFolderSize($targetInternalPath); $this->correctParentStorageMtime($sourceStorage, $sourceInternalPath); $this->correctParentStorageMtime($targetStorage, $targetInternalPath); $this->propagator->addChange($source); $this->propagator->addChange($target); } else { $this->remove($source); $this->update($target); } $this->propagator->propagateChanges(); } }
} $char = substr($this->in, $this->pos, 1); $this->pos++; return $char; } public function getPos() { return $this->pos; } public function pushBackChar() { $this->pos--; } public function string() { return $this->in; } } /** * Demo */ $context = new Context(); $user_in = "\$input equals '4' or \$input equals 'four'"; $reader = new StringReader($user_in); $scanner = new Scanner($reader, $context); while ($scanner->nextToken() != Scanner::EOF) { // var_dump($scanner->token(), $scanner->char_no(), $scanner->getTypeString()); print $scanner->token(); print "\t{$scanner->char_no()}"; print "\t{$scanner->getTypeString()}\n"; }
<?php namespace CyberLine\phUPnP; require 'src/Scanner.php'; try { $scanner = new Scanner(); $scanner->setTimeout(1); print json_encode($scanner); } catch (\Exception $e) { print 'Exception: ' . $e->getMessage() . PHP_EOL; }
/** * Function to display error in GCC style. * @param Array $errors * @param String $customErrorMessage */ public static function displayGCCStyleOutput($errors) { require_once __DIR__ . '/../libs/core/functions.php'; foreach ($errors as $listoferrors) { foreach ($listoferrors['result'] as $individualErrors) { if (count($individualErrors) == 0) { continue; } $file = $listoferrors['file']; $line = $individualErrors["LINE"]; $content = $individualErrors["CONTENT"]; $errorType = $individualErrors["ERROR"]; $errorMessage = Scanner::getErrorMessage($errorType); $errorNature = $individualErrors["TYPE"]; echof("?:?:?:?:\t?\n?\n\n", $errorNature, $file, $line, $errorType, $content, $errorMessage); } } }
$o2s = $arga[1]; } } } parseArguments(); //get the object's info if (!file_exists($o2s)) { echo "The file/folder {$o2s} does not exist!\n"; exit(-1); } //init scanner if (is_dir($o2s)) { $scanner = new Scanner($scannerOptions); $scanner->getDirContents($o2s, true); } else { $scanner = new Scanner($scannerOptions); $scanner->addFileToScan($o2s); } //add steps include_once 'lib/step_simplestring.php'; $scanner->addStep(new StepSimplestring($scanner, $log)); include_once 'lib/step_simplepattern.php'; $scanner->addStep(new StepSimplepattern($scanner, $log)); include_once 'lib/step_preg.php'; $scanner->addStep(new StepPreg($scanner, $log)); include_once 'lib/step_wp.php'; $scanner->addStep(new StepWP($scanner, $log)); include_once 'lib/step_comments.php'; $scanner->addStep(new StepComments($scanner, $log)); //run scan $filenum = count($scanner->files);
function handleMatch(Parser $parser, Scanner $scanner) { $varname = $scanner->getContext()->popResult(); $scanner->getContext()->pushResult(new VariableHandler($varname)); }
$scan_functions = array_merge($F_XSS, $F_HTTP_HEADER); $F_USERINPUT = array(); $V_USERINPUT = array($_POST['varname']); $F_SECURING_XSS = array(); $_POST['vector'] = 'client'; $overall_time = 0; $timeleft = 0; $file_amount = count($files); for ($fit = 0; $fit < $file_amount; $fit++) { // for scanning display $thisfile_start = microtime(TRUE); $file_scanning = $files[$fit]; echo $fit . '|' . $file_amount . '|' . $file_scanning . '|' . $timeleft . '|' . "\n"; @ob_flush(); flush(); $scan = new Scanner($file_scanning, $scan_functions, array(), array()); $scan->parse(); $overall_time += microtime(TRUE) - $thisfile_start; // timeleft = average_time_per_file * file_amount_left $timeleft = round($overall_time / ($fit + 1) * ($file_amount - $fit + 1), 2); } echo "STATS_DONE.\n"; @ob_flush(); flush(); } $elapsed = microtime(TRUE) - $start; ################################ RESULT ################################# $treestyle = $_POST['treestyle']; function checkLeak($tree, $line, $varname) { if ($tree->children) {
protected function push(Scanner $scanner) { $context = $scanner->getContext(); $context->pushResult($scanner->token()); }
function trigger(Scanner $scanner) { if ($scanner->tokenType() != Scanner::WORD) { return false; } if (is_null($this->word)) { return true; } return $this->word == $scanner->token(); }
/** * Analisa uma expressão dentro de parênteses * @param Scanner $input ponteiro para a Classe que conte a expressão e funcionalidade para iteração * @return null|TreeNode <b>null</b> se não tiver nada dentro do parênteses ou a árvore com a expressão * @throws Exception */ private function parenthesesAnalyzer(&$input) { $parentheses = $input->getParanthesesExpression(); /** * Advance the size of the inside expression plus '(' and ')' */ $treeNode = null; if ($parentheses['expression'] != null) { $parenthesesScanner = new Scanner($parentheses['expression']); $treeNode = $this->parser($parenthesesScanner); } return $treeNode; }
* * For copyright and license information, please see the LICENSE.md * Installing the system or redistributions of files must retain the above copyright notice. * * @link http://mobicms.net mobiCMS Project * @copyright Copyright (C) mobiCMS Community * @license LICENSE.md (see attached file) */ defined('MOBICMS') or die('Error: restricted access'); define('ROOT_DIR', '.'); $form = new Mobicms\Form\Form(['action' => App::request()->getUri()]); $form->infoMessages = false; $form->title(_m('Anti-Spyware'))->element('radio', 'mode', ['checked' => 1, 'items' => ['1' => _m('Scan to the appropriate distribution'), '2' => _m('Snapshot scan'), '3' => _m('Make snapshot')]])->divider()->element('submit', 'submit', ['value' => _s('Run'), 'class' => 'btn btn-primary'])->html('<a class="btn btn-link" href="../">' . _s('Back') . '</a>'); if ($form->process() === true) { require_once dirname(__DIR__) . '/classes/Scanner.php'; $scanner = new Scanner(); switch ($form->output['mode']) { case 1: // Сканируем на соответствие дистрибутиву $scanner->scan(); if (count($scanner->modifiedFiles) || count($scanner->missingFiles) || count($scanner->newFiles)) { App::view()->modifiedFiles = $scanner->modifiedFiles; App::view()->missingFiles = $scanner->missingFiles; App::view()->extraFiles = $scanner->newFiles; App::view()->errormsg = _m('Distributive inconsistency!'); } else { App::view()->ok = _m('List of files corresponds to the distributive'); } break; case 2: // Сканируем на соответствие ранее созданному снимку
/** * Parse M source code to PHP * @param string $source M language source code */ public function parse($source) { $this->iterator = Scanner::scan($source); $this->parseBlock(FALSE); return $this; }