mirror of
https://github.com/mandiant/capa.git
synced 2025-12-22 15:16:22 -08:00
adding support for string features with special characters e.g. '\n'
This commit is contained in:
@@ -125,6 +125,10 @@ class String(Feature):
|
|||||||
def __init__(self, value, description=None):
|
def __init__(self, value, description=None):
|
||||||
super(String, self).__init__(value, description=description)
|
super(String, self).__init__(value, description=description)
|
||||||
|
|
||||||
|
def get_value_str(self):
|
||||||
|
""" """
|
||||||
|
return repr(self.value).strip("'")
|
||||||
|
|
||||||
|
|
||||||
class Regex(String):
|
class Regex(String):
|
||||||
def __init__(self, value, description=None):
|
def __init__(self, value, description=None):
|
||||||
@@ -194,7 +198,7 @@ class StringFactory(object):
|
|||||||
def __new__(self, value, description=None):
|
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(str(codecs.decode(value, "unicode_escape")), description=description)
|
||||||
|
|
||||||
|
|
||||||
class Bytes(Feature):
|
class Bytes(Feature):
|
||||||
|
|||||||
@@ -681,6 +681,24 @@ def test_explicit_string_values_int():
|
|||||||
assert (String("0x123") in children) == True
|
assert (String("0x123") in children) == True
|
||||||
|
|
||||||
|
|
||||||
|
def test_string_values_special_characters():
|
||||||
|
rule = textwrap.dedent(
|
||||||
|
"""
|
||||||
|
rule:
|
||||||
|
meta:
|
||||||
|
name: test rule
|
||||||
|
features:
|
||||||
|
- or:
|
||||||
|
- string: hello\\r\\nworld
|
||||||
|
- string: some\\path
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
r = capa.rules.Rule.from_yaml(rule)
|
||||||
|
children = list(r.statement.get_children())
|
||||||
|
assert (String("hello\r\nworld") in children) == True
|
||||||
|
assert (String("some\\path") in children) == True
|
||||||
|
|
||||||
|
|
||||||
def test_regex_values_always_string():
|
def test_regex_values_always_string():
|
||||||
rules = [
|
rules = [
|
||||||
capa.rules.Rule.from_yaml(
|
capa.rules.Rule.from_yaml(
|
||||||
|
|||||||
Reference in New Issue
Block a user