mirror of
https://github.com/scr34m/php-malware-scanner.git
synced 2026-06-16 12:30:35 +00:00
Cleaned up pattern whitespace and comment handling
checking for comments and whitespace lines in pattern files should only be done once when the patterns are loaded. Added this code to the loadPatterns() function and removed it from the 3 scan loops.
This commit is contained in:
26
scan.php
26
scan.php
@@ -164,6 +164,14 @@ class MalwareScanner
|
||||
$list = array();
|
||||
if (is_readable($file)) {
|
||||
foreach (file($file) as $pattern) {
|
||||
//Check if the line is only whitespace and skips.
|
||||
if (strlen(trim($pattern)) == 0) {
|
||||
continue;
|
||||
}
|
||||
//Check if first char in pattern is a '#' which indicates a comment and skips.
|
||||
if ($pattern[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
$list[] = trim($pattern);
|
||||
}
|
||||
}
|
||||
@@ -183,12 +191,6 @@ class MalwareScanner
|
||||
array_push($this->patterns_raw, "googleBot", "htaccess");
|
||||
}
|
||||
foreach ($this->patterns_raw as $toSearch) {
|
||||
if (!$toSearch) {
|
||||
continue;
|
||||
}
|
||||
if ($toSearch[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
if (strpos($fileContent, $toSearch) !== FALSE){
|
||||
$found = true;
|
||||
if ($hash === ''){
|
||||
@@ -203,12 +205,6 @@ class MalwareScanner
|
||||
|
||||
if (!$found || $this->verbose) {
|
||||
foreach ($this->patterns_iraw as $toSearch) {
|
||||
if (!$toSearch) {
|
||||
continue;
|
||||
}
|
||||
if ($toSearch[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
if (stripos($fileContent, $toSearch) !== FALSE){
|
||||
$found = true;
|
||||
if ($hash === ''){
|
||||
@@ -224,12 +220,6 @@ class MalwareScanner
|
||||
|
||||
if (!$found || $this->verbose) {
|
||||
foreach ($this->patterns_re as $toSearch) {
|
||||
if (!$toSearch) {
|
||||
continue;
|
||||
}
|
||||
if ($toSearch[0] === '#') {
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/' . $toSearch . '/im', $fileContent)) {
|
||||
$found = true;
|
||||
if ($hash === ''){
|
||||
|
||||
Reference in New Issue
Block a user