|
8 | 8 | * License: GNU/GPLv2
|
9 | 9 | * @see LICENSE.txt
|
10 | 10 | *
|
11 |
| - * This file: The scanner (last modified: 2023.09.23). |
| 11 | + * This file: The scanner (last modified: 2023.09.25). |
12 | 12 | */
|
13 | 13 |
|
14 | 14 | namespace phpMussel\Core;
|
@@ -619,6 +619,95 @@ public function destroyScanDebugArray(&$Arr): void
|
619 | 619 | $Arr = null;
|
620 | 620 | }
|
621 | 621 |
|
| 622 | + /** |
| 623 | + * Writes to $HashReference, and performs any other needed hit-related actions. |
| 624 | + * |
| 625 | + * @param string $Hash The hash of the item which had a positive hit. |
| 626 | + * @param int $Size The size of the item which had a positive hit. |
| 627 | + * @param string $Name The name of the item which had a positive hit. |
| 628 | + * @param string $Text A human-readable explanation of the hit. |
| 629 | + * @param int $Code The integer results of the scan. |
| 630 | + * @param int $Depth The current depth of the scan process. |
| 631 | + * @return void |
| 632 | + */ |
| 633 | + public function atHit(string $Hash, int $Size = -1, string $Name = '', string $Text = '', int $Code = 2, int $Depth = 0): void |
| 634 | + { |
| 635 | + /** Fallback for missing item hash. */ |
| 636 | + if ($Hash === '') { |
| 637 | + $Hash = $this->Loader->L10N->getString('response.Data not available'); |
| 638 | + } |
| 639 | + |
| 640 | + /** Fallback for missing item name. */ |
| 641 | + if ($Name === '') { |
| 642 | + $Name = $this->Loader->L10N->getString('response.Data not available'); |
| 643 | + } |
| 644 | + |
| 645 | + /** Ensure that $Text doesn't break lines and clean it up. */ |
| 646 | + $Text = preg_replace('~[\x00-\x1F]~', '', $Text); |
| 647 | + |
| 648 | + /** Generate hash reference and key for various arrays to be populated. */ |
| 649 | + $HashReference = sprintf('%s:%d:%s', $Hash, $Size, $Name); |
| 650 | + if (strpos($this->Loader->HashReference, $HashReference . "\n") === false) { |
| 651 | + $this->Loader->HashReference .= $HashReference . "\n"; |
| 652 | + } |
| 653 | + |
| 654 | + $TextLength = strlen($Text); |
| 655 | + |
| 656 | + /** Scan results as text. */ |
| 657 | + if ($TextLength && isset($this->Loader->ScanResultsText[$HashReference]) && strlen($this->Loader->ScanResultsText[$HashReference])) { |
| 658 | + $this->Loader->ScanResultsText[$HashReference] .= $this->Loader->L10N->getString('grammar_spacer') . $Text; |
| 659 | + } else { |
| 660 | + $this->Loader->ScanResultsText[$HashReference] = $Text; |
| 661 | + } |
| 662 | + |
| 663 | + /** Scan results as integers. */ |
| 664 | + if (empty($this->Loader->ScanResultsIntegers[$HashReference]) || $this->Loader->ScanResultsIntegers[$HashReference] !== 2) { |
| 665 | + $this->Loader->ScanResultsIntegers[$HashReference] = $Code; |
| 666 | + } |
| 667 | + |
| 668 | + /** Increment detections count. */ |
| 669 | + if ($Code !== 0 && $Code !== 1) { |
| 670 | + if (isset($this->Loader->InstanceCache['DetectionsCount'])) { |
| 671 | + $this->Loader->InstanceCache['DetectionsCount']++; |
| 672 | + } else { |
| 673 | + $this->Loader->InstanceCache['DetectionsCount'] = 1; |
| 674 | + } |
| 675 | + } |
| 676 | + |
| 677 | + /** Indenting to apply for the formatted scan results . */ |
| 678 | + $Indent = str_pad('→ ', ($Depth < 1 ? 4 : ($Depth * 3) + 4), '─', STR_PAD_LEFT); |
| 679 | + |
| 680 | + /** Fallback for missing text for formatted text. */ |
| 681 | + if ($TextLength === 0) { |
| 682 | + if ($Code === 0) { |
| 683 | + $Text = sprintf( |
| 684 | + $this->Loader->L10N->getString('grammar_exclamation_mark'), |
| 685 | + sprintf($this->Loader->L10N->getString('response.%s does not exist'), $Name) |
| 686 | + ); |
| 687 | + } elseif ($Code === 1) { |
| 688 | + $Text = $this->Loader->L10N->getString('response.No problems found'); |
| 689 | + } else { |
| 690 | + $Text = $this->Loader->L10N->getString('response.Data not available'); |
| 691 | + } |
| 692 | + } |
| 693 | + |
| 694 | + if ($this->CalledFrom === 'CLI') { |
| 695 | + if ($Code === 1) { |
| 696 | + $Text = "\033[0;92m" . $Text . "\033[0;33m"; |
| 697 | + } elseif ($Code === 2 || $Code < 0) { |
| 698 | + $Text = "\033[0;91m" . $Text . "\033[0;33m"; |
| 699 | + } else { |
| 700 | + $Text = "\033[0;90m" . $Text . "\033[0;33m"; |
| 701 | + } |
| 702 | + } |
| 703 | + |
| 704 | + /** Scan results as formatted text. */ |
| 705 | + $this->Loader->ScanResultsFormatted .= $Indent . $Text . "\n"; |
| 706 | + |
| 707 | + /** Update flags. */ |
| 708 | + $this->Loader->InstanceCache['CheckWasLast'] = false; |
| 709 | + } |
| 710 | + |
622 | 711 | /**
|
623 | 712 | * Responsible for recursing through any files given to it to be scanned, which
|
624 | 713 | * may be necessary for the case of archives and directories. It performs the
|
@@ -3931,93 +4020,4 @@ private function resetHeuristics(): void
|
3931 | 4020 | $this->HeuristicCount = 0;
|
3932 | 4021 | $this->HeuristicMode = false;
|
3933 | 4022 | }
|
3934 |
| - |
3935 |
| - /** |
3936 |
| - * Writes to $HashReference, and performs any other needed hit-related actions. |
3937 |
| - * |
3938 |
| - * @param string $Hash The hash of the item which had a positive hit. |
3939 |
| - * @param int $Size The size of the item which had a positive hit. |
3940 |
| - * @param string $Name The name of the item which had a positive hit. |
3941 |
| - * @param string $Text A human-readable explanation of the hit. |
3942 |
| - * @param int $Code The integer results of the scan. |
3943 |
| - * @param int $Depth The current depth of the scan process. |
3944 |
| - * @return void |
3945 |
| - */ |
3946 |
| - public function atHit(string $Hash, int $Size = -1, string $Name = '', string $Text = '', int $Code = 2, int $Depth = 0): void |
3947 |
| - { |
3948 |
| - /** Fallback for missing item hash. */ |
3949 |
| - if ($Hash === '') { |
3950 |
| - $Hash = $this->Loader->L10N->getString('response.Data not available'); |
3951 |
| - } |
3952 |
| - |
3953 |
| - /** Fallback for missing item name. */ |
3954 |
| - if ($Name === '') { |
3955 |
| - $Name = $this->Loader->L10N->getString('response.Data not available'); |
3956 |
| - } |
3957 |
| - |
3958 |
| - /** Ensure that $Text doesn't break lines and clean it up. */ |
3959 |
| - $Text = preg_replace('~[\x00-\x1F]~', '', $Text); |
3960 |
| - |
3961 |
| - /** Generate hash reference and key for various arrays to be populated. */ |
3962 |
| - $HashReference = sprintf('%s:%d:%s', $Hash, $Size, $Name); |
3963 |
| - if (strpos($this->Loader->HashReference, $HashReference . "\n") === false) { |
3964 |
| - $this->Loader->HashReference .= $HashReference . "\n"; |
3965 |
| - } |
3966 |
| - |
3967 |
| - $TextLength = strlen($Text); |
3968 |
| - |
3969 |
| - /** Scan results as text. */ |
3970 |
| - if ($TextLength && isset($this->Loader->ScanResultsText[$HashReference]) && strlen($this->Loader->ScanResultsText[$HashReference])) { |
3971 |
| - $this->Loader->ScanResultsText[$HashReference] .= $this->Loader->L10N->getString('grammar_spacer') . $Text; |
3972 |
| - } else { |
3973 |
| - $this->Loader->ScanResultsText[$HashReference] = $Text; |
3974 |
| - } |
3975 |
| - |
3976 |
| - /** Scan results as integers. */ |
3977 |
| - if (empty($this->Loader->ScanResultsIntegers[$HashReference]) || $this->Loader->ScanResultsIntegers[$HashReference] !== 2) { |
3978 |
| - $this->Loader->ScanResultsIntegers[$HashReference] = $Code; |
3979 |
| - } |
3980 |
| - |
3981 |
| - /** Increment detections count. */ |
3982 |
| - if ($Code !== 0 && $Code !== 1) { |
3983 |
| - if (isset($this->Loader->InstanceCache['DetectionsCount'])) { |
3984 |
| - $this->Loader->InstanceCache['DetectionsCount']++; |
3985 |
| - } else { |
3986 |
| - $this->Loader->InstanceCache['DetectionsCount'] = 1; |
3987 |
| - } |
3988 |
| - } |
3989 |
| - |
3990 |
| - /** Indenting to apply for the formatted scan results . */ |
3991 |
| - $Indent = str_pad('→ ', ($Depth < 1 ? 4 : ($Depth * 3) + 4), '─', STR_PAD_LEFT); |
3992 |
| - |
3993 |
| - /** Fallback for missing text for formatted text. */ |
3994 |
| - if ($TextLength === 0) { |
3995 |
| - if ($Code === 0) { |
3996 |
| - $Text = sprintf( |
3997 |
| - $this->Loader->L10N->getString('grammar_exclamation_mark'), |
3998 |
| - sprintf($this->Loader->L10N->getString('response.%s does not exist'), $Name) |
3999 |
| - ); |
4000 |
| - } elseif ($Code === 1) { |
4001 |
| - $Text = $this->Loader->L10N->getString('response.No problems found'); |
4002 |
| - } else { |
4003 |
| - $Text = $this->Loader->L10N->getString('response.Data not available'); |
4004 |
| - } |
4005 |
| - } |
4006 |
| - |
4007 |
| - if ($this->CalledFrom === 'CLI') { |
4008 |
| - if ($Code === 1) { |
4009 |
| - $Text = "\033[0;92m" . $Text . "\033[0;33m"; |
4010 |
| - } elseif ($Code === 2 || $Code < 0) { |
4011 |
| - $Text = "\033[0;91m" . $Text . "\033[0;33m"; |
4012 |
| - } else { |
4013 |
| - $Text = "\033[0;90m" . $Text . "\033[0;33m"; |
4014 |
| - } |
4015 |
| - } |
4016 |
| - |
4017 |
| - /** Scan results as formatted text. */ |
4018 |
| - $this->Loader->ScanResultsFormatted .= $Indent . $Text . "\n"; |
4019 |
| - |
4020 |
| - /** Update flags. */ |
4021 |
| - $this->Loader->InstanceCache['CheckWasLast'] = false; |
4022 |
| - } |
4023 | 4023 | }
|
0 commit comments