11using System . Collections . Generic ;
22using AuthenticodeLint . Rules ;
3+ using System ;
4+ using System . Linq ;
35
46namespace AuthenticodeLint
57{
@@ -14,20 +16,12 @@ static CheckEngine()
1416
1517 public IReadOnlyList < IAuthenticodeRule > GetRules ( )
1618 {
17- return new List < IAuthenticodeRule >
18- {
19- new Sha1PrimarySignatureRule ( ) ,
20- new Sha2SignatureExistsRule ( ) ,
21- new NoWeakFileDigestAlgorithmsRule ( ) ,
22- new TimestampedRule ( ) ,
23- new PublisherInformationPresentRule ( ) ,
24- new PublisherInformationUrlHttpsRule ( ) ,
25- new SigningCertificateDigestAlgorithmRule ( ) ,
26- new TrustedSignatureRule ( ) ,
27- new WinCertificatePaddingRule ( ) ,
28- new NoUnknownUnsignedAttibuteRule ( ) ,
29- new NoUnknownCertificatesRule ( )
30- } ;
19+ return ( from type in typeof ( IAuthenticodeRule ) . Assembly . GetExportedTypes ( )
20+ where typeof ( IAuthenticodeRule ) . IsAssignableFrom ( type ) && type . GetConstructor ( Type . EmptyTypes ) != null
21+ let instance = ( IAuthenticodeRule ) Activator . CreateInstance ( type )
22+ orderby instance . RuleId
23+ select instance
24+ ) . ToList ( ) ;
3125 }
3226
3327 public RuleEngineResult RunAllRules ( string file , Graph < Signature > signatures , List < IRuleResultCollector > collectors , CheckConfiguration configuration )
@@ -52,9 +46,17 @@ public RuleEngineResult RunAllRules(string file, Graph<Signature> signatures, Li
5246 {
5347 result = RuleResult . Skip ;
5448 }
49+ else if ( rule is IAuthenticodeFileRule )
50+ {
51+ result = ( ( IAuthenticodeFileRule ) rule ) . Validate ( file , verboseWriter , configuration ) ;
52+ }
53+ else if ( rule is IAuthenticodeSignatureRule )
54+ {
55+ result = ( ( IAuthenticodeSignatureRule ) rule ) . Validate ( signatures , verboseWriter , configuration ) ;
56+ }
5557 else
5658 {
57- result = rule . Validate ( signatures , verboseWriter , configuration , file ) ;
59+ throw new NotSupportedException ( "Rule type is not supported." ) ;
5860 }
5961 }
6062 if ( result != RuleResult . Pass )
0 commit comments