Skip to content

Commit

Permalink
v0.2.2
Browse files Browse the repository at this point in the history
Changelog excerpt:

- Improved signature file optimisation to reduce signature file footprint
  and to filter out some more possibly problematic signatures.
  • Loading branch information
Maikuolan committed Oct 23, 2018
1 parent c45d82b commit bb02041
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Versioning guidelines for SemVer can be found at: http://www.semver.org/

(none)

=== Version/Release 0.2.2 ===
PATCH RELEASE.

- [2018.10.23; Sub-minor code change; Maikuolan]: Improved signature file
optimisation to reduce signature file footprint and to filter out some more
possibly problematic signatures.

Caleb M (Maikuolan),
October 23, 2018.

=== Version/Release 0.2.1 ===
PATCH RELEASE.

Expand Down
38 changes: 31 additions & 7 deletions sigtool.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* SigTool v0.2.1 (last modified: 2018.10.20).
* SigTool v0.2.2 (last modified: 2018.10.23).
* Generates signatures for phpMussel using main.cvd and daily.cvd from ClamAV.
*
* Package location: GitHub <https://github.com/phpMussel/SigTool>.
Expand All @@ -16,10 +16,10 @@
class SigTool
{
/** Script version. */
public $Ver = '0.2.1';
public $Ver = '0.2.2';

/** Last modified date. */
public $Modified = '2018.10.20';
public $Modified = '2018.10.23';

/** Script user agent. */
public $UA = 'SigTool v%s (https://github.com/phpMussel/SigTool)';
Expand Down Expand Up @@ -378,7 +378,7 @@ public function shorthand(&$Data) {
'~^[^\:\n]+\:[^\n]+[\[\]][^\n]*$~m',

/** PCRE trips over capture groups at this range sometimes. Let's play it safe and ditch the affected signatures. */
'~^.*\{-?(?:\d{4,})\}.*$\n~m',
'~^.*\{(?:-?\d{4,}|\d{4,}-)\}.*$\n~m',

/** Not needed in the final generated signature files. */
'~^.*This ClamAV version has reached End of Life.*$\n~im'
Expand Down Expand Up @@ -886,12 +886,15 @@ public function fixPath($Path) {
}
}

/** Normalise to lower-case. */
$SigHex = strtolower($SigHex);

/** Assign to the appropriate signature file (regex). */
if (preg_match('/[^a-f\d*]/i', $SigHex)) {

/** Convert from ClamAV's pattern syntax to PCRE syntax. */
$SigHex = preg_replace([
'~^.*\{-?(?:\d{4,})\}.*$~',
'~^.*\{(?:-?\d{4,}|\d{4,}-)\}.*$~',
'~\{(\d+)-(?:\d{4,})?\}~',
'~\{(\d+)-(\d+)\}~',
'~\{-(\d+)\}~',
Expand Down Expand Up @@ -946,13 +949,13 @@ public function fixPath($Path) {
} else {
$Replacement = $InnerCharCount === 10 ? $Char . '[\da]' : $Char . '[\da-' . $FinalLast . ']';
}
$SigHex = str_replace($Replacer, $Replacement, $SigHex);
$SigHex = str_ireplace($Replacer, $Replacement, $SigHex);
}
}

/** Upper-lower case stuff, and further simplification. */
foreach ($CharRange as $Char) {
$SigHex = str_replace([
$SigHex = str_ireplace([
'(4' . $Char . '|6' . $Char . ')',
'(6' . $Char . '|4' . $Char . ')',
'(5' . $Char . '|7' . $Char . ')',
Expand All @@ -973,6 +976,27 @@ public function fixPath($Path) {
], $SigHex);
}

/** Reduce footprint. */
foreach ($CharRange as $Char) {
$Matches = [];
$Lengths = [];
if (preg_match_all('~' . $Char . '{16,}~', $SigHex, $Matches) !== false && isset($Matches[0])) {
foreach ($Matches[0] as $Match) {
$Lengths[] = strlen($Match);
}
rsort($Lengths);
}
foreach ($Lengths as $Length) {
$SigHex = preg_replace_callback(
'~(?P<_before>[^' . $Char . '])' . $Char . '{' . $Length . '}(?P<_after>[^' . $Char . '])~',
function ($Matches) use ($Char, $Length) {
return $Matches['_before'] . $Char . '{' . $Length . '}' . $Matches['_after'];
},
$SigHex
);
}
}

/** Newly formatted signature line. */
$ThisLine = $SigName . ':' . $SigHex . $StartStop . "\n";

Expand Down

0 comments on commit bb02041

Please sign in to comment.