mirror of
https://github.com/mandiant/capa.git
synced 2026-02-04 19:12:01 -08:00
add yaml representer for the Scope class, as well as other bugfixes
This commit is contained in:
@@ -59,6 +59,9 @@ class NullStaticFeatureExtractor(StaticFeatureExtractor):
|
||||
def get_base_address(self):
|
||||
return self.base_address
|
||||
|
||||
def get_sample_hashes(self) -> SampleHashes:
|
||||
return self.sample_hashes
|
||||
|
||||
def extract_global_features(self):
|
||||
for feature in self.global_features:
|
||||
yield feature, NO_ADDRESS
|
||||
@@ -121,6 +124,9 @@ class NullDynamicFeatureExtractor(DynamicFeatureExtractor):
|
||||
for feature in self.global_features:
|
||||
yield feature, NO_ADDRESS
|
||||
|
||||
def get_sample_hashes(self) -> SampleHashes:
|
||||
return self.sample_hashes
|
||||
|
||||
def extract_file_features(self):
|
||||
for address, feature in self.file_features:
|
||||
yield feature, address
|
||||
|
||||
@@ -86,6 +86,10 @@ class Scope(str, Enum):
|
||||
# not used to validate rules.
|
||||
GLOBAL = "global"
|
||||
|
||||
@classmethod
|
||||
def to_yaml(cls, representer, node):
|
||||
return representer.represent_str(f"{node.value}")
|
||||
|
||||
|
||||
# these literals are used to check if the flavor
|
||||
# of a rule is correct.
|
||||
@@ -979,6 +983,7 @@ class Rule:
|
||||
|
||||
# we use the ruamel.yaml parser because it supports roundtripping of documents with comments.
|
||||
y = ruamel.yaml.YAML(typ="rt")
|
||||
y.register_class(Scope)
|
||||
|
||||
# use block mode, not inline json-like mode
|
||||
y.default_flow_style = False
|
||||
|
||||
@@ -263,7 +263,6 @@ def assert_round_trip(rd: rdoc.ResultDocument):
|
||||
pytest.param("a076114_rd"),
|
||||
pytest.param("pma0101_rd"),
|
||||
pytest.param("dotnet_1c444e_rd"),
|
||||
pytest.param(""),
|
||||
],
|
||||
)
|
||||
def test_round_trip(request, rd_file):
|
||||
|
||||
Reference in New Issue
Block a user