31
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2024-06-13 10:22:21 +00:00

unify code lines displaying

This commit is contained in:
Denis Ryabov 2021-04-04 11:41:33 +03:00
parent f42ed7c300
commit 7b8532f372

View File

@ -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);
}
}