diff --git a/capa/features/common.py b/capa/features/common.py index 67c9ed0d..a939f16e 100644 --- a/capa/features/common.py +++ b/capa/features/common.py @@ -11,7 +11,7 @@ import abc import codecs import logging import collections -from typing import TYPE_CHECKING, Set, Dict, List, Union, Optional, Sequence +from typing import TYPE_CHECKING, Set, Dict, List, Union, Optional if TYPE_CHECKING: # circular import, otherwise @@ -279,12 +279,12 @@ class Regex(String): flags |= re.IGNORECASE try: self.re = re.compile(pat, flags) - except re.error: + except re.error as exc: if value.endswith("/i"): value = value[: -len("i")] raise ValueError( "invalid regular expression: %s it should use Python syntax, try it at https://pythex.org" % value - ) + ) from exc def evaluate(self, ctx, short_circuit=True): capa.perf.counters["evaluate.feature"] += 1 diff --git a/capa/features/insn.py b/capa/features/insn.py index 50dd6133..7d01b7c6 100644 --- a/capa/features/insn.py +++ b/capa/features/insn.py @@ -72,6 +72,7 @@ class Offset(Feature): super(Offset, self).__init__(value, description=description) def get_value_str(self): + assert isinstance(self.value, int) return hex(self.value) diff --git a/capa/main.py b/capa/main.py index 373172b2..e9a2b728 100644 --- a/capa/main.py +++ b/capa/main.py @@ -461,6 +461,7 @@ def get_workspace(path, format_, sigpaths): # lazy import enables us to not require viv if user wants SMDA, for example. import viv_utils + import viv_utils.flirt logger.debug("generating vivisect workspace for: %s", path) # TODO should not be auto at this point, anymore @@ -1143,9 +1144,7 @@ def main(argv=None): def ida_main(): - import capa.rules import capa.ida.helpers - import capa.render.default import capa.features.extractors.ida.extractor logging.basicConfig(level=logging.INFO) @@ -1166,7 +1165,7 @@ def ida_main(): rules_path = os.path.join(get_default_root(), "rules") logger.debug("rule path: %s", rules_path) - rules = get_rules(rules_path) + rules = get_rules([rules_path]) rules = capa.rules.RuleSet(rules) meta = capa.ida.helpers.collect_metadata([rules_path]) diff --git a/capa/optimizer.py b/capa/optimizer.py index 0408bf07..997abd6c 100644 --- a/capa/optimizer.py +++ b/capa/optimizer.py @@ -47,7 +47,7 @@ def optimize_statement(statement): if isinstance(statement, (ceng.And, ceng.Or, ceng.Some)): # has .children - statement.children = sorted(statement.children, key=lambda n: get_node_cost(n)) + statement.children = sorted(statement.children, key=get_node_cost) return elif isinstance(statement, (ceng.Not, ceng.Range)): # has .child diff --git a/scripts/show-features.py b/scripts/show-features.py index f07dcf75..00c1eb05 100644 --- a/scripts/show-features.py +++ b/scripts/show-features.py @@ -79,6 +79,7 @@ import capa.exceptions import capa.render.verbose as v import capa.features.common import capa.features.freeze +import capa.features.address import capa.features.extractors.base_extractor from capa.helpers import log_unsupported_runtime_error @@ -108,7 +109,7 @@ def main(argv=None): try: sig_paths = capa.main.get_signatures(args.signatures) - except (IOError) as e: + except IOError as e: logger.error("%s", str(e)) return -1 diff --git a/setup.cfg b/setup.cfg index 5e0292f4..87eef850 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,3 +19,10 @@ test = pytest ignore = E203, E302, E402, E501, E712, E722, E731, W291, W503 max-line-length = 180 statistics = True + + +[pylint.FORMAT] +max-line-length = 180 + +[pylint] +disable = missing-docstring,invalid-name,import-outside-toplevel,redefined-outer-name,consider-using-f-string \ No newline at end of file