fix!: authors instead of author

This commit is contained in:
Moritz Raabe
2022-05-31 23:05:13 +02:00
parent 2f47fddda9
commit 1df60186f0
5 changed files with 34 additions and 19 deletions

View File

@@ -196,7 +196,8 @@ class CapaExplorerRulgenPreview(QtWidgets.QTextEdit):
" meta:", " meta:",
" name: <insert_name>", " name: <insert_name>",
" namespace: <insert_namespace>", " namespace: <insert_namespace>",
" author: %s" % author, " authors:",
" - %s" % author,
" scope: %s" % scope, " scope: %s" % scope,
" references: <insert_references>", " references: <insert_references>",
" examples:", " examples:",

View File

@@ -54,7 +54,7 @@ META_KEYS = (
"maec/malware-family", "maec/malware-family",
"maec/malware-category", "maec/malware-category",
"maec/malware-category-ov", "maec/malware-category-ov",
"author", "authors",
"description", "description",
"lib", "lib",
"scope", "scope",
@@ -1298,6 +1298,12 @@ class RuleSet:
logger.debug('using rule "%s" and dependencies, found tag in meta.%s: %s', rule.name, k, v) logger.debug('using rule "%s" and dependencies, found tag in meta.%s: %s', rule.name, k, v)
rules_filtered.update(set(capa.rules.get_rules_and_dependencies(rules, rule.name))) rules_filtered.update(set(capa.rules.get_rules_and_dependencies(rules, rule.name)))
break break
if isinstance(v, list):
for vv in v:
if tag in vv:
logger.debug('using rule "%s" and dependencies, found tag in meta.%s: %s', rule.name, k, vv)
rules_filtered.update(set(capa.rules.get_rules_and_dependencies(rules, rule.name)))
break
return RuleSet(list(rules_filtered)) return RuleSet(list(rules_filtered))
def match(self, scope: Scope, features: FeatureSet, va: int) -> Tuple[FeatureSet, ceng.MatchResults]: def match(self, scope: Scope, features: FeatureSet, va: int) -> Tuple[FeatureSet, ceng.MatchResults]:

View File

@@ -43,9 +43,8 @@ import capa.rules
import capa.engine import capa.engine
import capa.helpers import capa.helpers
import capa.features.insn import capa.features.insn
import capa.features.common
from capa.rules import Rule, RuleSet from capa.rules import Rule, RuleSet
from capa.features.common import Feature from capa.features.common import String, Feature, Substring
logger = logging.getLogger("lint") logger = logging.getLogger("lint")
@@ -168,12 +167,12 @@ class InvalidScope(Lint):
return rule.meta.get("scope") not in ("file", "function", "basic block", "instruction") return rule.meta.get("scope") not in ("file", "function", "basic block", "instruction")
class MissingAuthor(Lint): class MissingAuthors(Lint):
name = "missing author" name = "missing authors"
recommendation = "Add meta.author so that users know who to contact with questions" recommendation = "Add meta.authors so that users know who to contact with questions"
def check_rule(self, ctx: Context, rule: Rule): def check_rule(self, ctx: Context, rule: Rule):
return "author" not in rule.meta return "authors" not in rule.meta
class MissingExamples(Lint): class MissingExamples(Lint):
@@ -490,7 +489,7 @@ class FeatureStringTooShort(Lint):
def check_features(self, ctx: Context, features: List[Feature]): def check_features(self, ctx: Context, features: List[Feature]):
for feature in features: for feature in features:
if isinstance(feature, (capa.features.common.String, capa.features.common.Substring)): if isinstance(feature, (String, Substring)):
assert isinstance(feature.value, str) assert isinstance(feature.value, str)
if len(feature.value) < 4: if len(feature.value) < 4:
self.recommendation = self.recommendation.format(feature.value) self.recommendation = self.recommendation.format(feature.value)
@@ -697,7 +696,7 @@ def lint_scope(ctx: Context, rule: Rule):
META_LINTS = ( META_LINTS = (
MissingNamespace(), MissingNamespace(),
NamespaceDoesntMatchRulePath(), NamespaceDoesntMatchRulePath(),
MissingAuthor(), MissingAuthors(),
MissingExamples(), MissingExamples(),
MissingExampleOffset(), MissingExampleOffset(),
ExampleFileDNE(), ExampleFileDNE(),

View File

@@ -15,7 +15,8 @@ EXPECTED = textwrap.dedent(
rule: rule:
meta: meta:
name: test rule name: test rule
author: user@domain.com authors:
- user@domain.com
scope: function scope: function
examples: examples:
- foo1234 - foo1234
@@ -38,7 +39,8 @@ def test_rule_reformat_top_level_elements():
- number: 2 - number: 2
meta: meta:
name: test rule name: test rule
author: user@domain.com authors:
- user@domain.com
scope: function scope: function
examples: examples:
- foo1234 - foo1234
@@ -55,7 +57,8 @@ def test_rule_reformat_indentation():
rule: rule:
meta: meta:
name: test rule name: test rule
author: user@domain.com authors:
- user@domain.com
scope: function scope: function
examples: examples:
- foo1234 - foo1234
@@ -75,7 +78,8 @@ def test_rule_reformat_order():
""" """
rule: rule:
meta: meta:
author: user@domain.com authors:
- user@domain.com
examples: examples:
- foo1234 - foo1234
- bar5678 - bar5678
@@ -98,7 +102,8 @@ def test_rule_reformat_meta_update():
""" """
rule: rule:
meta: meta:
author: user@domain.com authors:
- user@domain.com
examples: examples:
- foo1234 - foo1234
- bar5678 - bar5678
@@ -124,7 +129,8 @@ def test_rule_reformat_string_description():
rule: rule:
meta: meta:
name: test rule name: test rule
author: user@domain.com authors:
- user@domain.com
scope: function scope: function
features: features:
- and: - and:

View File

@@ -42,7 +42,8 @@ def test_rule_yaml():
rule: rule:
meta: meta:
name: test rule name: test rule
author: user@domain.com authors:
- user@domain.com
scope: function scope: function
examples: examples:
- foo1234 - foo1234
@@ -724,7 +725,8 @@ def test_filter_rules():
rule: rule:
meta: meta:
name: rule 1 name: rule 1
author: joe authors:
- joe
features: features:
- api: CreateFile - api: CreateFile
""" """
@@ -803,7 +805,8 @@ def test_filter_rules_missing_dependency():
rule: rule:
meta: meta:
name: rule 1 name: rule 1
author: joe authors:
- joe
features: features:
- match: rule 2 - match: rule 2
""" """