Short argument names

This commit is contained in:
Gabor Gyorvari
2018-09-05 19:56:43 +02:00
parent f9647806c8
commit a6360c56a0
2 changed files with 11 additions and 10 deletions

View File

@@ -30,8 +30,8 @@ Usage: php scan.php -d <directory>
-s --no-stop Continue scanning file after first hit -s --no-stop Continue scanning file after first hit
-p --pattern Show Patterns next to the file name -p --pattern Show Patterns next to the file name
-t --time Show time of last file change -t --time Show time of last file change
--line-number Display matching pattern line number in file -L --line-number Display matching pattern line number in file
--output-format Custom defined output format -o --output-format Custom defined output format
``` ```
Ignore argument could be used multiple times and accept glob style matching ex.: "`cache*`", "`??-cache.php`" or "`/cache`" etc. Ignore argument could be used multiple times and accept glob style matching ex.: "`cache*`", "`??-cache.php`" or "`/cache`" etc.

View File

@@ -182,7 +182,7 @@ class MalwareScanner
private function parseArgs() private function parseArgs()
{ {
$options = getopt( $options = getopt(
'd:e:i:abmcxlhkwnspt', 'd:e:i:o:abmcxlhkwnsptL',
array( array(
'directory:', 'directory:',
'extension:', 'extension:',
@@ -267,13 +267,12 @@ class MalwareScanner
if (isset($options['time']) || isset($options['t'])) { if (isset($options['time']) || isset($options['t'])) {
$this->setFlagTime(true); $this->setFlagTime(true);
} }
if (isset($options['line-number'])) { if (isset($options['line-number']) || isset($options['L'])) {
$this->setFlagLineNumber(true); $this->setFlagLineNumber(true);
} }
if (isset($options['output-format'])) { if (isset($options['output-format']) || isset($options['o'])) {
$this->setOutputFormat( $tmp = isset($options['output-format']) ? $options['output-format'] : $options['o'];
is_array($options['output-format']) ? $options['output-format'] : array ($options['output-format']) $this->setOutputFormat(is_array($tmp) ? $tmp : array($tmp));
);
} }
} }
@@ -571,7 +570,7 @@ class MalwareScanner
} }
if (!$found) { if (!$found) {
$this->printPath($found, $path, $toSearch, $comment, $hash, -1); $this->printPath($found, $path, $toSearch, $comment, $hash, 0);
return false; return false;
} }
@@ -628,7 +627,7 @@ class MalwareScanner
if ($hash === '') { if ($hash === '') {
$hash = md5($fileContent); $hash = md5($fileContent);
} }
$lineNumber = 1; $lineNumber = 0;
if ($this->flagLineNumber) { if ($this->flagLineNumber) {
if ($pos = strrpos(substr($fileContent, 0, $position), "\n")) { if ($pos = strrpos(substr($fileContent, 0, $position), "\n")) {
$lineNumber = substr_count(substr($fileContent, 0, $pos + 1), "\n") + 1; $lineNumber = substr_count(substr($fileContent, 0, $pos + 1), "\n") + 1;
@@ -663,6 +662,8 @@ class MalwareScanner
echo ' -s --no-stop Continue scanning file after first hit' . PHP_EOL; echo ' -s --no-stop Continue scanning file after first hit' . PHP_EOL;
echo ' -p --pattern Show Patterns next to the file name' . PHP_EOL; echo ' -p --pattern Show Patterns next to the file name' . PHP_EOL;
echo ' -t --time Show time of last file change' . PHP_EOL; echo ' -t --time Show time of last file change' . PHP_EOL;
echo ' -L --line-number Display matching pattern line number in file' . PHP_EOL;
echo ' -o --output-format Custom defined output format' . PHP_EOL;
} }
} }