This commit is contained in:
Willi Ballenthin
2023-11-06 09:50:59 +00:00
parent f7c72cd1c3
commit eb12ec43f0
2 changed files with 30 additions and 3 deletions

View File

@@ -312,7 +312,7 @@ def render_node(ostream, layout: rd.Layout, rule: rd.RuleMatches, match: rd.Matc
if isinstance(node, rd.StatementNode):
render_statement(ostream, layout, match, node.statement, indent=indent)
elif isinstance(node, rd.FeatureNode):
render_feature(ostream, layout, match, rule, node.feature, indent=indent)
render_feature(ostream, layout, rule, match, node.feature, indent=indent)
else:
raise RuntimeError("unexpected node type: " + str(node))
@@ -357,7 +357,7 @@ def render_match(ostream, layout: rd.Layout, rule: rd.RuleMatches, match: rd.Mat
else:
raise RuntimeError("unexpected mode: " + mode)
render_node(ostream, layout, match, rule, match.node, indent=indent)
render_node(ostream, layout, rule, match, match.node, indent=indent)
for child in match.children:
render_match(ostream, layout, rule, child, indent=indent + 1, mode=child_mode)

View File

@@ -160,6 +160,33 @@ def test_render_vverbose_feature(feature, expected):
layout = capa.render.result_document.StaticLayout(functions=())
capa.render.vverbose.render_feature(ostream, layout, matches, feature, indent=0)
src = textwrap.dedent(
"""
rule:
meta:
name: test rule
authors:
- user@domain.com
scopes:
static: function
dynamic: process
examples:
- foo1234
- bar5678
features:
- and:
- number: 1
- number: 2
"""
)
rule = capa.rules.Rule.from_yaml(src)
rm = capa.render.result_document.RuleMatches(
meta=rule.meta,
source=src,
matches=(),
)
capa.render.vverbose.render_feature(ostream, layout, rm, matches, feature, indent=0)
assert ostream.getvalue().strip() == expected