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:
nichogenius
2017-08-18 07:31:33 -06:00
committed by GitHub
parent 1909eb0781
commit 44aafb0972

View File

@@ -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 === ''){