diff --git a/README.md b/README.md index 35be287..1f4207b 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ Usage: php scan.php -d -s --no-stop Continue scanning file after first hit -p --pattern Show Patterns next to the file name -t --time Show time of last file change - --line-number Display matching pattern line number in file - --output-format Custom defined output format + -L --line-number Display matching pattern line number in file + -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. diff --git a/scan.php b/scan.php index 9a912e8..6656ceb 100644 --- a/scan.php +++ b/scan.php @@ -182,7 +182,7 @@ class MalwareScanner private function parseArgs() { $options = getopt( - 'd:e:i:abmcxlhkwnspt', + 'd:e:i:o:abmcxlhkwnsptL', array( 'directory:', 'extension:', @@ -267,13 +267,12 @@ class MalwareScanner if (isset($options['time']) || isset($options['t'])) { $this->setFlagTime(true); } - if (isset($options['line-number'])) { + if (isset($options['line-number']) || isset($options['L'])) { $this->setFlagLineNumber(true); } - if (isset($options['output-format'])) { - $this->setOutputFormat( - is_array($options['output-format']) ? $options['output-format'] : array ($options['output-format']) - ); + if (isset($options['output-format']) || isset($options['o'])) { + $tmp = isset($options['output-format']) ? $options['output-format'] : $options['o']; + $this->setOutputFormat(is_array($tmp) ? $tmp : array($tmp)); } } @@ -571,7 +570,7 @@ class MalwareScanner } if (!$found) { - $this->printPath($found, $path, $toSearch, $comment, $hash, -1); + $this->printPath($found, $path, $toSearch, $comment, $hash, 0); return false; } @@ -628,7 +627,7 @@ class MalwareScanner if ($hash === '') { $hash = md5($fileContent); } - $lineNumber = 1; + $lineNumber = 0; if ($this->flagLineNumber) { if ($pos = strrpos(substr($fileContent, 0, $position), "\n")) { $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 ' -p --pattern Show Patterns next to the file name' . 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; } }