mirror of
https://github.com/mandiant/capa.git
synced 2025-12-23 15:37:37 -08:00
@@ -161,7 +161,7 @@ class Regex(String):
|
|||||||
|
|
||||||
|
|
||||||
class StringFactory(object):
|
class StringFactory(object):
|
||||||
def __new__(self, value, description):
|
def __new__(self, value, description=None):
|
||||||
if value.startswith("/") and (value.endswith("/") or value.endswith("/i")):
|
if value.startswith("/") and (value.endswith("/") or value.endswith("/i")):
|
||||||
return Regex(value, description=description)
|
return Regex(value, description=description)
|
||||||
return String(value, description=description)
|
return String(value, description=description)
|
||||||
|
|||||||
@@ -162,6 +162,23 @@ def test_rule_yaml_count_range():
|
|||||||
assert r.evaluate({Number(100): {1, 2, 3}}) == False
|
assert r.evaluate({Number(100): {1, 2, 3}}) == False
|
||||||
|
|
||||||
|
|
||||||
|
def test_rule_yaml_count_string():
|
||||||
|
rule = textwrap.dedent(
|
||||||
|
"""
|
||||||
|
rule:
|
||||||
|
meta:
|
||||||
|
name: test rule
|
||||||
|
features:
|
||||||
|
- count(string(foo)): 2
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
r = capa.rules.Rule.from_yaml(rule)
|
||||||
|
assert r.evaluate({String("foo"): {}}) == False
|
||||||
|
assert r.evaluate({String("foo"): {1}}) == False
|
||||||
|
assert r.evaluate({String("foo"): {1, 2}}) == True
|
||||||
|
assert r.evaluate({String("foo"): {1, 2, 3}}) == False
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_rule_feature():
|
def test_invalid_rule_feature():
|
||||||
with pytest.raises(capa.rules.InvalidRule):
|
with pytest.raises(capa.rules.InvalidRule):
|
||||||
capa.rules.Rule.from_yaml(
|
capa.rules.Rule.from_yaml(
|
||||||
|
|||||||
Reference in New Issue
Block a user