diff --git a/.github/flake8.ini b/.github/flake8.ini index f949f801..6426764f 100644 --- a/.github/flake8.ini +++ b/.github/flake8.ini @@ -10,6 +10,8 @@ extend-ignore = F811, # E501 line too long (prefer black) E501, + # E701 multiple statements on one line (colon) (prefer black, see https://github.com/psf/black/issues/4173) + E701, # B010 Do not call setattr with a constant attribute value B010, # G200 Logging statement uses exception in arguments diff --git a/capa/features/address.py b/capa/features/address.py index 800cefcd..0edf4cec 100644 --- a/capa/features/address.py +++ b/capa/features/address.py @@ -10,8 +10,7 @@ import abc class Address(abc.ABC): @abc.abstractmethod - def __eq__(self, other): - ... + def __eq__(self, other): ... @abc.abstractmethod def __lt__(self, other): diff --git a/capa/features/freeze/__init__.py b/capa/features/freeze/__init__.py index 2dac7f48..258ba07a 100644 --- a/capa/features/freeze/__init__.py +++ b/capa/features/freeze/__init__.py @@ -9,6 +9,7 @@ Unless required by applicable law or agreed to in writing, software distributed 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 json import zlib import logging diff --git a/capa/ida/plugin/form.py b/capa/ida/plugin/form.py index dcc1ca46..f6219186 100644 --- a/capa/ida/plugin/form.py +++ b/capa/ida/plugin/form.py @@ -932,9 +932,9 @@ class CapaExplorerForm(idaapi.PluginForm): update_wait_box("verifying cached results") try: - results: Optional[ - capa.render.result_document.ResultDocument - ] = capa.ida.helpers.load_and_verify_cached_results() + results: Optional[capa.render.result_document.ResultDocument] = ( + capa.ida.helpers.load_and_verify_cached_results() + ) except Exception as e: capa.ida.helpers.inform_user_ida_ui("Failed to verify cached results, reanalyzing program") logger.exception("Failed to verify cached results (error: %s)", e) diff --git a/capa/ida/plugin/view.py b/capa/ida/plugin/view.py index 0225e453..bbb8287a 100644 --- a/capa/ida/plugin/view.py +++ b/capa/ida/plugin/view.py @@ -200,9 +200,11 @@ class CapaExplorerRulegenPreview(QtWidgets.QTextEdit): " references:", " - ", " examples:", - f" - {capa.ida.helpers.get_file_md5().upper()}:{hex(ea)}" - if ea - else f" - {capa.ida.helpers.get_file_md5().upper()}", + ( + f" - {capa.ida.helpers.get_file_md5().upper()}:{hex(ea)}" + if ea + else f" - {capa.ida.helpers.get_file_md5().upper()}" + ), " features:", ] self.setText("\n".join(metadata_default)) diff --git a/capa/loader.py b/capa/loader.py index 4c0f3d4f..a8ffccf0 100644 --- a/capa/loader.py +++ b/capa/loader.py @@ -482,7 +482,7 @@ def compute_dynamic_layout( ) for t in threads if t in matched_threads - ) # this object is open to extension in the future, + ), # this object is open to extension in the future, # such as with the function name, etc. ) for p, threads in threads_by_process.items() @@ -524,7 +524,7 @@ def compute_static_layout(rules: RuleSet, extractor: StaticFeatureExtractor, cap address=frz.Address.from_capa(f), matched_basic_blocks=tuple( rdoc.BasicBlockLayout(address=frz.Address.from_capa(bb)) for bb in bbs if bb in matched_bbs - ) # this object is open to extension in the future, + ), # this object is open to extension in the future, # such as with the function name, etc. ) for f, bbs in bbs_by_function.items() diff --git a/capa/render/result_document.py b/capa/render/result_document.py index 2ef85185..ce95245e 100644 --- a/capa/render/result_document.py +++ b/capa/render/result_document.py @@ -160,8 +160,7 @@ class CompoundStatementType: OPTIONAL = "optional" -class StatementModel(FrozenModel): - ... +class StatementModel(FrozenModel): ... class CompoundStatement(StatementModel): @@ -650,9 +649,9 @@ class ResultDocument(FrozenModel): return ResultDocument(meta=meta, rules=rule_matches) def to_capa(self) -> Tuple[Metadata, Dict]: - capabilities: Dict[ - str, List[Tuple[capa.features.address.Address, capa.features.common.Result]] - ] = collections.defaultdict(list) + capabilities: Dict[str, List[Tuple[capa.features.address.Address, capa.features.common.Result]]] = ( + collections.defaultdict(list) + ) # this doesn't quite work because we don't have the rule source for rules that aren't matched. rules_by_name = { diff --git a/capa/render/verbose.py b/capa/render/verbose.py index f6f566de..44024acf 100644 --- a/capa/render/verbose.py +++ b/capa/render/verbose.py @@ -22,6 +22,7 @@ Unless required by applicable law or agreed to in writing, software distributed 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 typing import cast import tabulate diff --git a/pyproject.toml b/pyproject.toml index 62ed5ef7..08dc8270 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,7 +79,7 @@ dev = [ "flake8-use-pathlib==0.3.0", "flake8-copyright==0.2.4", "ruff==0.1.14", - "black==23.12.1", + "black==24.1.1", "isort==5.13.2", "mypy==1.8.0", "psutil==5.9.2", diff --git a/scripts/cache-ruleset.py b/scripts/cache-ruleset.py index 0e364622..8a10cf50 100644 --- a/scripts/cache-ruleset.py +++ b/scripts/cache-ruleset.py @@ -15,6 +15,7 @@ Unless required by applicable law or agreed to in writing, software distributed 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 import logging import argparse diff --git a/scripts/capafmt.py b/scripts/capafmt.py index de4171ea..be46b2ad 100644 --- a/scripts/capafmt.py +++ b/scripts/capafmt.py @@ -14,6 +14,7 @@ Unless required by applicable law or agreed to in writing, software distributed 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 import logging import argparse diff --git a/scripts/import-to-ida.py b/scripts/import-to-ida.py index e52a029d..3c653304 100644 --- a/scripts/import-to-ida.py +++ b/scripts/import-to-ida.py @@ -28,6 +28,7 @@ Unless required by applicable law or agreed to in writing, software distributed 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 logging import binascii from pathlib import Path diff --git a/scripts/lint.py b/scripts/lint.py index 93440395..49ff70e6 100644 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -13,6 +13,7 @@ Unless required by applicable law or agreed to in writing, software distributed 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 gc import os import re