From 7b8532f3727d0a2e9ab62a5e0d438d364b7e6115 Mon Sep 17 00:00:00 2001 From: Denis Ryabov Date: Sun, 4 Apr 2021 11:41:33 +0300 Subject: [PATCH] unify code lines displaying --- .../com_jedchecker/libraries/rules/jamss.php | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/administrator/components/com_jedchecker/libraries/rules/jamss.php b/administrator/components/com_jedchecker/libraries/rules/jamss.php index 8648d9e..0f88d92 100644 --- a/administrator/components/com_jedchecker/libraries/rules/jamss.php +++ b/administrator/components/com_jedchecker/libraries/rules/jamss.php @@ -339,18 +339,34 @@ class JedcheckerRulesJamss extends JEDcheckerRule { $count++; + foreach ($all_results as $match) + { + // Output the line of malware code, but sanitize it before + // The offset is in $match[1] + $offset = $match[1]; + // Note: negative 3rd argument is used for right-to-left search + $start = strrpos($content, "\n", -(strlen($content) - $offset)); + + if ($start === false) + { + $start = 0; + } + + $end = strpos($content, "\n", $offset); + + if ($end === false) + { + $end = strlen($content); + } + + $first_code = substr($content, $start, min($end - $start, 200)); + $first_line = $this->calculate_line_number($offset, $content); + break; + } + if (is_array($pattern)) { // Then it has some additional comments - foreach ($all_results as $match) - { - // Output the line of malware code, but sanitize it before - // The offset is in $match[1] - $first_code = substr($content, $match[1], 200); - $first_line = $this->calculate_line_number($match[1], $content); - break; - } - $this->jamssWarning( $path, JText::_('COM_JEDCHECKER_ERROR_JAMSS_PATTERN') . "#$pattern[2] - $pattern[1]", @@ -362,16 +378,6 @@ class JedcheckerRulesJamss extends JEDcheckerRule else { // It's a string, no comments available - $first_content = ""; - - foreach ($all_results as $match) - { - // Output the line of malware code, but sanitize it before - $first_code = substr($content, $match[1], 200); - $first_line = $this->calculate_line_number($match[1], $content); - break; - } - $this->jamssWarning( $path, JText::_('COM_JEDCHECKER_ERROR_JAMSS_STRING') . $pattern, @@ -423,7 +429,6 @@ class JedcheckerRulesJamss extends JEDcheckerRule private function jamssWarning($path, $title, $info, $code, $line) { $info = !empty($info)?sprintf($this->params->get('info'), htmlentities($info, ENT_QUOTES)):""; - $code = !empty($code)?sprintf($this->params->get('code'), htmlentities($code, ENT_QUOTES)):""; - $this->report->addWarning($path, $info . $code . $title, $line); + $this->report->addWarning($path, $info . $title, $line, $code); } }