diff --git a/.github/ruff.toml b/.github/ruff.toml index ea923692..c6a66b08 100644 --- a/.github/ruff.toml +++ b/.github/ruff.toml @@ -43,5 +43,11 @@ exclude = [ ] [per-file-ignores] -#"__init__.py" = ["E402"] -#"path/to/file.py" = ["E402"] +# until we address #1592 and move test fixtures into conftest.py +# then we need to ignore imports done to enable pytest fixtures. +# +# F401: `foo` imported but unused +# F811 Redefinition of unused `foo` +"tests/test_main.py" = ["F401", "F811"] +"tests/test_freeze.py" = ["F401", "F811"] +"tests/test_function_id.py" = ["F401", "F811"] diff --git a/capa/engine.py b/capa/engine.py index 4d9e0980..90a3308f 100644 --- a/capa/engine.py +++ b/capa/engine.py @@ -8,7 +8,7 @@ import copy import collections -from typing import TYPE_CHECKING, Set, Dict, List, Tuple, Union, Mapping, Iterable, Iterator, cast +from typing import TYPE_CHECKING, Set, Dict, List, Tuple, Union, Mapping, Iterable, Iterator import capa.perf import capa.features.common diff --git a/capa/features/extractors/binja/basicblock.py b/capa/features/extractors/binja/basicblock.py index e354669d..6649fc92 100644 --- a/capa/features/extractors/binja/basicblock.py +++ b/capa/features/extractors/binja/basicblock.py @@ -15,7 +15,6 @@ from binaryninja import Function, Settings from binaryninja import BasicBlock as BinjaBasicBlock from binaryninja import ( BinaryView, - DataBuffer, SymbolType, RegisterValueType, VariableSourceType, @@ -26,7 +25,7 @@ from binaryninja import ( ) from capa.features.common import Feature, Characteristic -from capa.features.address import Address, AbsoluteVirtualAddress +from capa.features.address import Address from capa.features.basicblock import BasicBlock from capa.features.extractors.helpers import MIN_STACKSTRING_LEN from capa.features.extractors.base_extractor import BBHandle, FunctionHandle diff --git a/capa/features/extractors/binja/file.py b/capa/features/extractors/binja/file.py index 9700a8c1..edc11ed4 100644 --- a/capa/features/extractors/binja/file.py +++ b/capa/features/extractors/binja/file.py @@ -10,7 +10,7 @@ import sys import struct from typing import Tuple, Iterator -from binaryninja import Symbol, Segment, BinaryView, SymbolType, SymbolBinding +from binaryninja import Segment, BinaryView, SymbolType, SymbolBinding import capa.features.extractors.common import capa.features.extractors.helpers diff --git a/capa/features/extractors/binja/function.py b/capa/features/extractors/binja/function.py index 96c58eea..981650b7 100644 --- a/capa/features/extractors/binja/function.py +++ b/capa/features/extractors/binja/function.py @@ -19,7 +19,6 @@ from capa.features.extractors.base_extractor import FunctionHandle def extract_function_calls_to(fh: FunctionHandle): """extract callers to a function""" func: Function = fh.inner - bv: BinaryView = func.view for caller in func.caller_sites: # Everything that is a code reference to the current function is considered a caller, which actually includes diff --git a/capa/features/extractors/binja/global_.py b/capa/features/extractors/binja/global_.py index f8ce7003..afcec4ad 100644 --- a/capa/features/extractors/binja/global_.py +++ b/capa/features/extractors/binja/global_.py @@ -1,10 +1,8 @@ import logging -import contextlib from typing import Tuple, Iterator from binaryninja import BinaryView -import capa.features.extractors.elf from capa.features.common import OS, OS_MACOS, ARCH_I386, ARCH_AMD64, OS_WINDOWS, Arch, Feature from capa.features.address import NO_ADDRESS, Address diff --git a/capa/features/extractors/binja/insn.py b/capa/features/extractors/binja/insn.py index fe5cd228..9f22beae 100644 --- a/capa/features/extractors/binja/insn.py +++ b/capa/features/extractors/binja/insn.py @@ -6,7 +6,7 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. import sys -from typing import Any, Dict, List, Tuple, Iterator, Optional +from typing import Any, List, Tuple, Iterator, Optional from binaryninja import Function from binaryninja import BasicBlock as BinjaBasicBlock @@ -18,12 +18,11 @@ from binaryninja import ( RegisterValueType, LowLevelILOperation, LowLevelILInstruction, - InstructionTextTokenType, ) import capa.features.extractors.helpers from capa.features.insn import API, MAX_STRUCTURE_SIZE, Number, Offset, Mnemonic, OperandNumber, OperandOffset -from capa.features.common import MAX_BYTES_FEATURE_SIZE, THUNK_CHAIN_DEPTH_DELTA, Bytes, String, Feature, Characteristic +from capa.features.common import MAX_BYTES_FEATURE_SIZE, Bytes, String, Feature, Characteristic from capa.features.address import Address, AbsoluteVirtualAddress from capa.features.extractors.binja.helpers import DisassemblyInstruction, visit_llil_exprs from capa.features.extractors.base_extractor import BBHandle, InsnHandle, FunctionHandle @@ -73,7 +72,6 @@ def extract_insn_api_features(fh: FunctionHandle, bbh: BBHandle, ih: InsnHandle) example: call dword [0x00473038] """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner bv: BinaryView = func.view @@ -128,12 +126,9 @@ def extract_insn_number_features( example: push 3136B0h ; dwControlCode """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner - bv: BinaryView = func.view results: List[Tuple[Any[Number, OperandNumber], Address]] = [] - address_size = func.view.arch.address_size * 8 def llil_checker(il: LowLevelILInstruction, parent: LowLevelILInstruction, index: int) -> bool: if il.operation == LowLevelILOperation.LLIL_LOAD: @@ -171,7 +166,6 @@ def extract_insn_bytes_features(fh: FunctionHandle, bbh: BBHandle, ih: InsnHandl example: push offset iid_004118d4_IShellLinkA ; riid """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner bv: BinaryView = func.view @@ -220,7 +214,6 @@ def extract_insn_string_features( example: push offset aAcr ; "ACR > " """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner bv: BinaryView = func.view @@ -278,7 +271,6 @@ def extract_insn_offset_features( example: .text:0040112F cmp [esi+4], ebx """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner results: List[Tuple[Any[Offset, OperandOffset], Address]] = [] @@ -364,7 +356,6 @@ def extract_insn_nzxor_characteristic_features( parse instruction non-zeroing XOR instruction ignore expected non-zeroing XORs, e.g. security cookies """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner results = [] @@ -414,7 +405,6 @@ def extract_insn_peb_access_characteristic_features( fs:[0x30] on x86, gs:[0x60] on x64 """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner results = [] @@ -456,7 +446,6 @@ def extract_insn_segment_access_features( fh: FunctionHandle, bbh: BBHandle, ih: InsnHandle ) -> Iterator[Tuple[Feature, Address]]: """parse instruction fs or gs access""" - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner results = [] @@ -485,7 +474,6 @@ def extract_insn_cross_section_cflow( fh: FunctionHandle, bbh: BBHandle, ih: InsnHandle ) -> Iterator[Tuple[Feature, Address]]: """inspect the instruction for a CALL or JMP that crosses section boundaries""" - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner bv: BinaryView = func.view @@ -509,7 +497,6 @@ def extract_function_calls_from(fh: FunctionHandle, bbh: BBHandle, ih: InsnHandl most relevant at the function scope, however, its most efficient to extract at the instruction scope """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner bv: BinaryView = func.view @@ -555,7 +542,6 @@ def extract_function_indirect_call_characteristic_features( most relevant at the function or basic block scope; however, its most efficient to extract at the instruction scope """ - insn: DisassemblyInstruction = ih.inner func: Function = fh.inner llil = func.get_llil_at(ih.address) diff --git a/capa/features/extractors/dnfile/insn.py b/capa/features/extractors/dnfile/insn.py index 431423a6..b70f39dc 100644 --- a/capa/features/extractors/dnfile/insn.py +++ b/capa/features/extractors/dnfile/insn.py @@ -9,7 +9,7 @@ from __future__ import annotations import logging -from typing import TYPE_CHECKING, Any, Dict, Tuple, Union, Iterator, Optional +from typing import TYPE_CHECKING, Tuple, Union, Iterator, Optional if TYPE_CHECKING: from capa.features.extractors.dnfile.extractor import DnFileFeatureExtractorCache diff --git a/capa/features/extractors/dnfile/types.py b/capa/features/extractors/dnfile/types.py index 822b5d67..5982a1fe 100644 --- a/capa/features/extractors/dnfile/types.py +++ b/capa/features/extractors/dnfile/types.py @@ -6,8 +6,7 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. -from enum import Enum -from typing import Union, Optional +from typing import Optional class DnType(object): diff --git a/capa/features/extractors/dotnetfile.py b/capa/features/extractors/dotnetfile.py index 7a1abb57..bf759419 100644 --- a/capa/features/extractors/dotnetfile.py +++ b/capa/features/extractors/dotnetfile.py @@ -1,5 +1,5 @@ import logging -from typing import Tuple, Iterator, cast +from typing import Tuple, Iterator import dnfile import pefile diff --git a/capa/features/extractors/viv/file.py b/capa/features/extractors/viv/file.py index a28045b3..0deee2c7 100644 --- a/capa/features/extractors/viv/file.py +++ b/capa/features/extractors/viv/file.py @@ -16,7 +16,7 @@ import capa.features.extractors.common import capa.features.extractors.helpers import capa.features.extractors.strings from capa.features.file import Export, Import, Section, FunctionName -from capa.features.common import String, Feature, Characteristic +from capa.features.common import Feature, Characteristic from capa.features.address import Address, FileOffsetAddress, AbsoluteVirtualAddress diff --git a/capa/features/extractors/viv/indirect_calls.py b/capa/features/extractors/viv/indirect_calls.py index f76c13f8..0855d56f 100644 --- a/capa/features/extractors/viv/indirect_calls.py +++ b/capa/features/extractors/viv/indirect_calls.py @@ -87,8 +87,8 @@ def find_definition(vw: VivWorkspace, va: int, reg: int) -> Tuple[int, Union[int raises: NotFoundError: when the definition cannot be found. """ - q = collections.deque() # type: Deque[int] - seen = set([]) # type: Set[int] + q: Deque[int] = collections.deque() + seen: Set[int] = set([]) q.extend(get_previous_instructions(vw, va)) while q: diff --git a/capa/features/extractors/viv/insn.py b/capa/features/extractors/viv/insn.py index d8d6edbe..27c65b5f 100644 --- a/capa/features/extractors/viv/insn.py +++ b/capa/features/extractors/viv/insn.py @@ -19,11 +19,10 @@ import envi.archs.amd64.disasm import capa.features.extractors.helpers import capa.features.extractors.viv.helpers -from capa.features.file import FunctionName from capa.features.insn import API, MAX_STRUCTURE_SIZE, Number, Offset, Mnemonic, OperandNumber, OperandOffset from capa.features.common import MAX_BYTES_FEATURE_SIZE, THUNK_CHAIN_DEPTH_DELTA, Bytes, String, Feature, Characteristic from capa.features.address import Address, AbsoluteVirtualAddress -from capa.features.extractors.elf import Shdr, SymTab +from capa.features.extractors.elf import SymTab from capa.features.extractors.base_extractor import BBHandle, InsnHandle, FunctionHandle from capa.features.extractors.viv.indirect_calls import NotFoundError, resolve_indirect_call diff --git a/capa/features/freeze/__init__.py b/capa/features/freeze/__init__.py index d0eb720c..38900578 100644 --- a/capa/features/freeze/__init__.py +++ b/capa/features/freeze/__init__.py @@ -12,7 +12,7 @@ See the License for the specific language governing permissions and limitations import zlib import logging from enum import Enum -from typing import Any, List, Tuple, Union +from typing import List, Tuple, Union from pydantic import Field, BaseModel diff --git a/capa/helpers.py b/capa/helpers.py index 38bd2d56..77534b50 100644 --- a/capa/helpers.py +++ b/capa/helpers.py @@ -9,6 +9,7 @@ import os import inspect import logging import contextlib +import importlib.util from typing import NoReturn import tqdm @@ -40,12 +41,7 @@ def get_file_taste(sample_path: str) -> bytes: def is_runtime_ida(): - try: - import idc - except ImportError: - return False - else: - return True + return importlib.util.find_spec("idc") is not None def assert_never(value) -> NoReturn: diff --git a/capa/ida/plugin/cache.py b/capa/ida/plugin/cache.py index 5226df9f..69a3a3d3 100644 --- a/capa/ida/plugin/cache.py +++ b/capa/ida/plugin/cache.py @@ -10,7 +10,7 @@ from __future__ import annotations import itertools import collections -from typing import Set, Dict, List, Tuple, Union, Optional +from typing import Set, Dict, Tuple, Union, Optional import capa.engine from capa.rules import Scope, RuleSet diff --git a/capa/ida/plugin/form.py b/capa/ida/plugin/form.py index 07fbe69f..b1319651 100644 --- a/capa/ida/plugin/form.py +++ b/capa/ida/plugin/form.py @@ -587,7 +587,7 @@ class CapaExplorerForm(idaapi.PluginForm): rules_message.setText("You must specify a directory containing capa rules before running analysis.") rules_message.setInformativeText( "Click 'Ok' to specify a local directory of rules or you can download and extract the official " - f"rules from the URL listed in the details." + "rules from the URL listed in the details." ) rules_message.setDetailedText(f"{CAPA_OFFICIAL_RULESET_URL}") rules_message.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) @@ -606,7 +606,7 @@ class CapaExplorerForm(idaapi.PluginForm): return False settings.user[CAPA_SETTINGS_RULE_PATH] = path - except UserCancelledError as e: + except UserCancelledError: capa.ida.helpers.inform_user_ida_ui("Analysis requires capa rules") logger.warning( "You must specify a directory containing capa rules before running analysis.%s", diff --git a/capa/main.py b/capa/main.py index cf8e3a63..b707fe9b 100644 --- a/capa/main.py +++ b/capa/main.py @@ -34,6 +34,7 @@ import capa.perf import capa.rules import capa.engine import capa.version +import capa.helpers import capa.render.json import capa.rules.cache import capa.render.default @@ -1339,17 +1340,8 @@ def ida_main(): print(capa.render.default.render(meta, rules, capabilities)) -def is_runtime_ida(): - try: - import idc - except ImportError: - return False - else: - return True - - if __name__ == "__main__": - if is_runtime_ida(): + if capa.helpers.is_runtime_ida(): ida_main() else: sys.exit(main()) diff --git a/capa/render/default.py b/capa/render/default.py index 15e2a5e8..1cd07c38 100644 --- a/capa/render/default.py +++ b/capa/render/default.py @@ -11,7 +11,6 @@ import collections import tabulate import capa.render.utils as rutils -import capa.features.freeze as frz import capa.render.result_document as rd import capa.features.freeze.features as frzf from capa.rules import RuleSet diff --git a/capa/render/proto/__init__.py b/capa/render/proto/__init__.py index 66a06c82..e895ae94 100644 --- a/capa/render/proto/__init__.py +++ b/capa/render/proto/__init__.py @@ -24,14 +24,10 @@ $ protoc.exe --python_out=. --mypy_out=. (e.g. capa/render/proto Alternatively, --pyi_out=. can be used to generate a Python Interface file that supports development """ -import sys -import json -import argparse import datetime from typing import Any, Dict, Union import google.protobuf.json_format -from google.protobuf.json_format import MessageToJson import capa.rules import capa.features.freeze as frz diff --git a/capa/render/result_document.py b/capa/render/result_document.py index 21957ddf..944365e6 100644 --- a/capa/render/result_document.py +++ b/capa/render/result_document.py @@ -7,7 +7,7 @@ # See the License for the specific language governing permissions and limitations under the License. import datetime import collections -from typing import Any, Dict, List, Tuple, Union, Optional +from typing import Dict, List, Tuple, Union, Optional from pydantic import Field, BaseModel diff --git a/scripts/cache-ruleset.py b/scripts/cache-ruleset.py index a2a49bdb..8c24497e 100644 --- a/scripts/cache-ruleset.py +++ b/scripts/cache-ruleset.py @@ -17,7 +17,6 @@ See the License for the specific language governing permissions and limitations """ import os import sys -import time import logging import argparse diff --git a/scripts/capa_as_library.py b/scripts/capa_as_library.py index 57657018..242e4e9c 100644 --- a/scripts/capa_as_library.py +++ b/scripts/capa_as_library.py @@ -2,7 +2,7 @@ import json import collections -from typing import Any, Dict +from typing import Any, Dict, Set import capa.main import capa.rules @@ -13,7 +13,6 @@ import capa.render.utils as rutils import capa.render.default import capa.render.result_document as rd import capa.features.freeze.features as frzf -from capa.engine import * from capa.features.common import OS_AUTO, FORMAT_AUTO diff --git a/scripts/lint.py b/scripts/lint.py index 8348cdea..ff2e8bd8 100644 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -43,7 +43,7 @@ import capa.engine import capa.helpers import capa.features.insn from capa.rules import Rule, RuleSet -from capa.features.common import OS_AUTO, FORMAT_PE, FORMAT_DOTNET, String, Feature, Substring +from capa.features.common import OS_AUTO, String, Feature, Substring from capa.render.result_document import RuleMetadata logger = logging.getLogger("lint") diff --git a/tests/fixtures.py b/tests/fixtures.py index 84e40209..21eae8f7 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -10,7 +10,6 @@ import os import os.path import binascii -import itertools import contextlib import collections from typing import Set, Dict diff --git a/tests/test_binja_features.py b/tests/test_binja_features.py index 04c8a49e..9bc5a995 100644 --- a/tests/test_binja_features.py +++ b/tests/test_binja_features.py @@ -5,10 +5,11 @@ # Unless required by applicable law or agreed to in writing, software distributed under the License # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. +import os import logging +import pytest import fixtures -from fixtures import * import capa.main @@ -22,7 +23,7 @@ try: try: binaryninja.load(source=b"\x90") - except RuntimeError as e: + except RuntimeError: logger.warning("Binary Ninja license is not valid, provide via $BN_LICENSE or license.dat") else: binja_present = True diff --git a/tests/test_dnfile_features.py b/tests/test_dnfile_features.py index 76540468..664b699b 100644 --- a/tests/test_dnfile_features.py +++ b/tests/test_dnfile_features.py @@ -6,9 +6,7 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. -import pytest import fixtures -from fixtures import * from fixtures import parametrize diff --git a/tests/test_dotnet_features.py b/tests/test_dotnet_features.py index 9980a730..5227c892 100644 --- a/tests/test_dotnet_features.py +++ b/tests/test_dotnet_features.py @@ -6,9 +6,7 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. -import pytest import fixtures -from fixtures import * from fixtures import parametrize diff --git a/tests/test_dotnetfile_features.py b/tests/test_dotnetfile_features.py index 28d63cdb..a4af0da0 100644 --- a/tests/test_dotnetfile_features.py +++ b/tests/test_dotnetfile_features.py @@ -8,9 +8,10 @@ import pytest import fixtures -from fixtures import * from fixtures import parametrize +import capa.features.file + @parametrize( "sample,scope,feature,expected", diff --git a/tests/test_engine.py b/tests/test_engine.py index c070edb8..a3e8efd0 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -6,9 +6,8 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. import capa.features.address -from capa.engine import * -from capa.features import * -from capa.features.insn import * +from capa.engine import And, Or, Not, Some, Range +from capa.features.insn import Number ADDR1 = capa.features.address.AbsoluteVirtualAddress(0x401001) ADDR2 = capa.features.address.AbsoluteVirtualAddress(0x401002) diff --git a/tests/test_freeze.py b/tests/test_freeze.py index 2c5f1920..8a31a03b 100644 --- a/tests/test_freeze.py +++ b/tests/test_freeze.py @@ -8,7 +8,8 @@ import textwrap from typing import List -from fixtures import * +import pytest +from fixtures import z9324d_extractor import capa.main import capa.rules @@ -20,7 +21,8 @@ import capa.features.freeze import capa.features.basicblock import capa.features.extractors.null import capa.features.extractors.base_extractor -from capa.features.address import AbsoluteVirtualAddress +from capa.features.extractors.base_extractor import FunctionHandle, BBHandle +from capa.features.address import AbsoluteVirtualAddress, Address EXTRACTOR = capa.features.extractors.null.NullFeatureExtractor( base_address=AbsoluteVirtualAddress(0x401000), diff --git a/tests/test_ida_features.py b/tests/test_ida_features.py index 99e7d5a1..e37258d3 100644 --- a/tests/test_ida_features.py +++ b/tests/test_ida_features.py @@ -55,7 +55,6 @@ import pytest try: sys.path.append(os.path.dirname(__file__)) import fixtures - from fixtures import * finally: sys.path.pop() @@ -104,7 +103,7 @@ def test_ida_features(): try: fixtures.do_test_feature_presence(get_ida_extractor, sample, scope, feature, expected) - except Exception as e: + except Exception: f = io.StringIO() traceback.print_exc(file=f) yield this_name, id, "fail", f.getvalue() @@ -130,7 +129,7 @@ def test_ida_feature_counts(): try: fixtures.do_test_feature_count(get_ida_extractor, sample, scope, feature, expected) - except Exception as e: + except Exception: f = io.StringIO() traceback.print_exc(file=f) yield this_name, id, "fail", f.getvalue() diff --git a/tests/test_main.py b/tests/test_main.py index d17e6e64..e76ee4ed 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -10,7 +10,6 @@ import json import textwrap import fixtures -from fixtures import * from fixtures import ( _692f_dotnetfile_extractor, _1c444_dotnetfile_extractor, @@ -22,7 +21,6 @@ import capa.main import capa.rules import capa.engine import capa.features -from capa.engine import * def test_main(z9324d_extractor): diff --git a/tests/test_match.py b/tests/test_match.py index fc3583f7..2810e599 100644 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -13,8 +13,7 @@ import capa.engine import capa.features.insn import capa.features.common from capa.rules import Scope -from capa.features.insn import * -from capa.features.common import * +from capa.features.common import MatchedRule, String, OS, OS_ANY, OS_WINDOWS def match(rules, features, va, scope=Scope.FUNCTION): diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py index d07ba330..40c008fa 100644 --- a/tests/test_optimizer.py +++ b/tests/test_optimizer.py @@ -8,15 +8,13 @@ import textwrap -import pytest - import capa.rules import capa.engine import capa.optimizer import capa.features.common from capa.engine import Or, And from capa.features.insn import Mnemonic -from capa.features.common import Arch, Bytes, Substring +from capa.features.common import Arch, Substring def test_optimizer_order(): diff --git a/tests/test_os_detection.py b/tests/test_os_detection.py index 585aada2..d7bdb55c 100644 --- a/tests/test_os_detection.py +++ b/tests/test_os_detection.py @@ -9,8 +9,7 @@ import io import zlib -import pytest -from fixtures import * +from fixtures import get_data_path_by_name import capa.features.extractors.elf diff --git a/tests/test_pefile_features.py b/tests/test_pefile_features.py index e0b735e8..6f4a59bf 100644 --- a/tests/test_pefile_features.py +++ b/tests/test_pefile_features.py @@ -7,7 +7,6 @@ # See the License for the specific language governing permissions and limitations under the License. import pytest import fixtures -from fixtures import * from fixtures import parametrize import capa.features.file diff --git a/tests/test_proto.py b/tests/test_proto.py index 64c950bc..06476c15 100644 --- a/tests/test_proto.py +++ b/tests/test_proto.py @@ -8,7 +8,7 @@ import copy from typing import Any -from fixtures import * +import pytest import capa.rules import capa.render diff --git a/tests/test_result_document.py b/tests/test_result_document.py index 5ae9af26..1a1b656f 100644 --- a/tests/test_result_document.py +++ b/tests/test_result_document.py @@ -9,7 +9,6 @@ import copy import pytest import fixtures -from fixtures import * import capa import capa.engine as ceng diff --git a/tests/test_rules.py b/tests/test_rules.py index 9f07f31d..69875508 100644 --- a/tests/test_rules.py +++ b/tests/test_rules.py @@ -344,7 +344,7 @@ def test_subscope_rules(): def test_duplicate_rules(): with pytest.raises(capa.rules.InvalidRule): - rules = capa.rules.RuleSet( + _ = capa.rules.RuleSet( [ capa.rules.Rule.from_yaml( textwrap.dedent( @@ -374,7 +374,7 @@ def test_duplicate_rules(): def test_missing_dependency(): with pytest.raises(capa.rules.InvalidRule): - rules = capa.rules.RuleSet( + _ = capa.rules.RuleSet( [ capa.rules.Rule.from_yaml( textwrap.dedent( @@ -393,7 +393,7 @@ def test_missing_dependency(): def test_invalid_rules(): with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -406,7 +406,7 @@ def test_invalid_rules(): ) with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -420,7 +420,7 @@ def test_invalid_rules(): # att&ck and mbc must be lists with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -433,7 +433,7 @@ def test_invalid_rules(): ) ) with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -497,7 +497,7 @@ def test_count_number_symbol(): def test_invalid_number(): with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -510,7 +510,7 @@ def test_invalid_number(): ) with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -523,7 +523,7 @@ def test_invalid_number(): ) with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -583,7 +583,7 @@ def test_count_offset_symbol(): def test_invalid_offset(): with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -596,7 +596,7 @@ def test_invalid_offset(): ) with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -609,7 +609,7 @@ def test_invalid_offset(): ) with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -624,7 +624,7 @@ def test_invalid_offset(): def test_invalid_string_values_int(): with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: @@ -637,7 +637,7 @@ def test_invalid_string_values_int(): ) with pytest.raises(capa.rules.InvalidRule): - r = capa.rules.Rule.from_yaml( + _ = capa.rules.Rule.from_yaml( textwrap.dedent( """ rule: diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 2d8fefac..3e673466 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -12,7 +12,6 @@ import textwrap import subprocess import pytest -from fixtures import * CD = os.path.dirname(__file__) diff --git a/tests/test_viv_features.py b/tests/test_viv_features.py index 58ce5ace..ca26f693 100644 --- a/tests/test_viv_features.py +++ b/tests/test_viv_features.py @@ -6,7 +6,6 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. import fixtures -from fixtures import * @fixtures.parametrize(