Skip to content

Commit bb02041

Browse files
committed
v0.2.2
Changelog excerpt: - Improved signature file optimisation to reduce signature file footprint and to filter out some more possibly problematic signatures.
1 parent c45d82b commit bb02041

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

Changelog.txt

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ Versioning guidelines for SemVer can be found at: http://www.semver.org/
99

1010
(none)
1111

12+
=== Version/Release 0.2.2 ===
13+
PATCH RELEASE.
14+
15+
- [2018.10.23; Sub-minor code change; Maikuolan]: Improved signature file
16+
optimisation to reduce signature file footprint and to filter out some more
17+
possibly problematic signatures.
18+
19+
Caleb M (Maikuolan),
20+
October 23, 2018.
21+
1222
=== Version/Release 0.2.1 ===
1323
PATCH RELEASE.
1424

sigtool.php

+31-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* SigTool v0.2.1 (last modified: 2018.10.20).
3+
* SigTool v0.2.2 (last modified: 2018.10.23).
44
* Generates signatures for phpMussel using main.cvd and daily.cvd from ClamAV.
55
*
66
* Package location: GitHub <https://github.com/phpMussel/SigTool>.
@@ -16,10 +16,10 @@
1616
class SigTool
1717
{
1818
/** Script version. */
19-
public $Ver = '0.2.1';
19+
public $Ver = '0.2.2';
2020

2121
/** Last modified date. */
22-
public $Modified = '2018.10.20';
22+
public $Modified = '2018.10.23';
2323

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

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

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

889+
/** Normalise to lower-case. */
890+
$SigHex = strtolower($SigHex);
891+
889892
/** Assign to the appropriate signature file (regex). */
890893
if (preg_match('/[^a-f\d*]/i', $SigHex)) {
891894

892895
/** Convert from ClamAV's pattern syntax to PCRE syntax. */
893896
$SigHex = preg_replace([
894-
'~^.*\{-?(?:\d{4,})\}.*$~',
897+
'~^.*\{(?:-?\d{4,}|\d{4,}-)\}.*$~',
895898
'~\{(\d+)-(?:\d{4,})?\}~',
896899
'~\{(\d+)-(\d+)\}~',
897900
'~\{-(\d+)\}~',
@@ -946,13 +949,13 @@ public function fixPath($Path) {
946949
} else {
947950
$Replacement = $InnerCharCount === 10 ? $Char . '[\da]' : $Char . '[\da-' . $FinalLast . ']';
948951
}
949-
$SigHex = str_replace($Replacer, $Replacement, $SigHex);
952+
$SigHex = str_ireplace($Replacer, $Replacement, $SigHex);
950953
}
951954
}
952955

953956
/** Upper-lower case stuff, and further simplification. */
954957
foreach ($CharRange as $Char) {
955-
$SigHex = str_replace([
958+
$SigHex = str_ireplace([
956959
'(4' . $Char . '|6' . $Char . ')',
957960
'(6' . $Char . '|4' . $Char . ')',
958961
'(5' . $Char . '|7' . $Char . ')',
@@ -973,6 +976,27 @@ public function fixPath($Path) {
973976
], $SigHex);
974977
}
975978

979+
/** Reduce footprint. */
980+
foreach ($CharRange as $Char) {
981+
$Matches = [];
982+
$Lengths = [];
983+
if (preg_match_all('~' . $Char . '{16,}~', $SigHex, $Matches) !== false && isset($Matches[0])) {
984+
foreach ($Matches[0] as $Match) {
985+
$Lengths[] = strlen($Match);
986+
}
987+
rsort($Lengths);
988+
}
989+
foreach ($Lengths as $Length) {
990+
$SigHex = preg_replace_callback(
991+
'~(?P<_before>[^' . $Char . '])' . $Char . '{' . $Length . '}(?P<_after>[^' . $Char . '])~',
992+
function ($Matches) use ($Char, $Length) {
993+
return $Matches['_before'] . $Char . '{' . $Length . '}' . $Matches['_after'];
994+
},
995+
$SigHex
996+
);
997+
}
998+
}
999+
9761000
/** Newly formatted signature line. */
9771001
$ThisLine = $SigName . ':' . $SigHex . $StartStop . "\n";
9781002

0 commit comments

Comments
 (0)