mirror of
https://github.com/mandiant/capa.git
synced 2025-12-12 15:49:46 -08:00
engine: cleanup some lints
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
import copy
|
||||
import collections
|
||||
from typing import TYPE_CHECKING, Set, Dict, List, Tuple, Union, Mapping
|
||||
from typing import Set, Dict, List, Tuple, Union, Mapping
|
||||
|
||||
import capa.rules
|
||||
import capa.features.common
|
||||
@@ -62,7 +62,7 @@ class Statement:
|
||||
yield self.child
|
||||
|
||||
if hasattr(self, "children"):
|
||||
for child in self.children:
|
||||
for child in getattr(self, "children"):
|
||||
yield child
|
||||
|
||||
def replace_child(self, existing, new):
|
||||
@@ -71,9 +71,10 @@ class Statement:
|
||||
self.child = new
|
||||
|
||||
if hasattr(self, "children"):
|
||||
for i, child in enumerate(self.children):
|
||||
children = getattr(self, "children")
|
||||
for i, child in enumerate(children):
|
||||
if child is existing:
|
||||
self.children[i] = new
|
||||
children[i] = new
|
||||
|
||||
|
||||
class Result:
|
||||
@@ -235,9 +236,9 @@ def match(rules: List["capa.rules.Rule"], features: FeatureSet, va: int) -> Tupl
|
||||
va (int): location of the features
|
||||
|
||||
Returns:
|
||||
Tuple[FeatureSet, Dict[str, Tuple[int, Result]]]: two-tuple with entries:
|
||||
Tuple[FeatureSet, MatchResults]: two-tuple with entries:
|
||||
- set of features used for matching (which may be greater than argument, due to rule match features), and
|
||||
- mapping from rule name to (location of match, result object)
|
||||
- mapping from rule name to [(location of match, result object)]
|
||||
"""
|
||||
results = collections.defaultdict(list) # type: MatchResults
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ class Regex(String):
|
||||
matches = collections.defaultdict(list)
|
||||
|
||||
for feature, locations in ctx.items():
|
||||
if not isinstance(feature, (capa.features.common.String,)):
|
||||
if not isinstance(feature, (String,)):
|
||||
continue
|
||||
|
||||
if not isinstance(feature.value, str):
|
||||
@@ -243,7 +243,7 @@ class Bytes(Feature):
|
||||
|
||||
def evaluate(self, ctx):
|
||||
for feature, locations in ctx.items():
|
||||
if not isinstance(feature, (capa.features.common.Bytes,)):
|
||||
if not isinstance(feature, (Bytes,)):
|
||||
continue
|
||||
|
||||
if feature.value.startswith(self.value):
|
||||
|
||||
Reference in New Issue
Block a user