1
1
<?php
2
2
/**
3
- * SigTool v0.2.1 (last modified: 2018.10.20 ).
3
+ * SigTool v0.2.2 (last modified: 2018.10.23 ).
4
4
* Generates signatures for phpMussel using main.cvd and daily.cvd from ClamAV.
5
5
*
6
6
* Package location: GitHub <https://github.com/phpMussel/SigTool>.
16
16
class SigTool
17
17
{
18
18
/** Script version. */
19
- public $ Ver = '0.2.1 ' ;
19
+ public $ Ver = '0.2.2 ' ;
20
20
21
21
/** Last modified date. */
22
- public $ Modified = '2018.10.20 ' ;
22
+ public $ Modified = '2018.10.23 ' ;
23
23
24
24
/** Script user agent. */
25
25
public $ UA = 'SigTool v%s (https://github.com/phpMussel/SigTool) ' ;
@@ -378,7 +378,7 @@ public function shorthand(&$Data) {
378
378
'~^[^\:\n]+\:[^\n]+[\[\]][^\n]*$~m ' ,
379
379
380
380
/** 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 ' ,
382
382
383
383
/** Not needed in the final generated signature files. */
384
384
'~^.*This ClamAV version has reached End of Life.*$\n~im '
@@ -886,12 +886,15 @@ public function fixPath($Path) {
886
886
}
887
887
}
888
888
889
+ /** Normalise to lower-case. */
890
+ $ SigHex = strtolower ($ SigHex );
891
+
889
892
/** Assign to the appropriate signature file (regex). */
890
893
if (preg_match ('/[^a-f\d*]/i ' , $ SigHex )) {
891
894
892
895
/** Convert from ClamAV's pattern syntax to PCRE syntax. */
893
896
$ SigHex = preg_replace ([
894
- '~^.*\{-? (?:\d{4,})\}.*$~ ' ,
897
+ '~^.*\{(?:-? \d{4,}|\d{4,}- )\}.*$~ ' ,
895
898
'~\{(\d+)-(?:\d{4,})?\}~ ' ,
896
899
'~\{(\d+)-(\d+)\}~ ' ,
897
900
'~\{-(\d+)\}~ ' ,
@@ -946,13 +949,13 @@ public function fixPath($Path) {
946
949
} else {
947
950
$ Replacement = $ InnerCharCount === 10 ? $ Char . '[\da] ' : $ Char . '[\da- ' . $ FinalLast . '] ' ;
948
951
}
949
- $ SigHex = str_replace ($ Replacer , $ Replacement , $ SigHex );
952
+ $ SigHex = str_ireplace ($ Replacer , $ Replacement , $ SigHex );
950
953
}
951
954
}
952
955
953
956
/** Upper-lower case stuff, and further simplification. */
954
957
foreach ($ CharRange as $ Char ) {
955
- $ SigHex = str_replace ([
958
+ $ SigHex = str_ireplace ([
956
959
'(4 ' . $ Char . '|6 ' . $ Char . ') ' ,
957
960
'(6 ' . $ Char . '|4 ' . $ Char . ') ' ,
958
961
'(5 ' . $ Char . '|7 ' . $ Char . ') ' ,
@@ -973,6 +976,27 @@ public function fixPath($Path) {
973
976
], $ SigHex );
974
977
}
975
978
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
+
976
1000
/** Newly formatted signature line. */
977
1001
$ ThisLine = $ SigName . ': ' . $ SigHex . $ StartStop . "\n" ;
978
1002
0 commit comments