diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 100c015361..707e26ad28 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -61,7 +61,7 @@ repos: - id: rm-unneeded-f-str - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.4 + rev: v0.8.3 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/angrmanagement/data/jobs/dependency_analysis.py b/angrmanagement/data/jobs/dependency_analysis.py index 4f22ae79d7..fd64d093bd 100644 --- a/angrmanagement/data/jobs/dependency_analysis.py +++ b/angrmanagement/data/jobs/dependency_analysis.py @@ -101,7 +101,7 @@ def _perform(self, ctx: JobContext, inst: Instance): for depth in range(min_depth, max_depth): base_progress: float = 30.0 + (depth - min_depth) * progress_chunk - ctx.set_progress(base_progress, text="Calculating reaching definitions... depth %d." % depth) + ctx.set_progress(base_progress, text=f"Calculating reaching definitions... depth {depth}.") # generate RDA observation points observation_points = set() for pred in inst.cfg.am_obj.get_predecessors(inst.cfg.am_obj.get_any_node(self.func_addr)): @@ -115,7 +115,7 @@ def _perform(self, ctx: JobContext, inst: Instance): ): ctx.set_progress( base_progress + idx / total * progress_chunk, - text="Computing transitive closures: %d/%d - depth %d" % (idx + 1, total, depth), + text=f"Computing transitive closures: {idx + 1}/{total} - depth {depth}", ) all_defs = set() diff --git a/angrmanagement/plugins/dep_viewer/sinks.py b/angrmanagement/plugins/dep_viewer/sinks.py index d4f213d204..c6cef29903 100644 --- a/angrmanagement/plugins/dep_viewer/sinks.py +++ b/angrmanagement/plugins/dep_viewer/sinks.py @@ -32,7 +32,7 @@ def __init__(self, lib: str | None, func_name: str, arg_idx, platforms: list[str self.platforms = platforms def __repr__(self) -> str: - return "" % (self.func_name, self.arg_idx) + return f"" class SinkManager: diff --git a/angrmanagement/plugins/plugin_manager.py b/angrmanagement/plugins/plugin_manager.py index a4b1c81172..e84bdf06dd 100644 --- a/angrmanagement/plugins/plugin_manager.py +++ b/angrmanagement/plugins/plugin_manager.py @@ -169,7 +169,7 @@ def _register_toolbar_actions(self, plugin_cls: type[BasePlugin], plugin: BasePl for idx, (icon, tooltip) in enumerate(plugin_cls.TOOLBAR_BUTTONS): action = ToolbarAction( icon, - "plugin %s toolbar %d" % (plugin_cls, idx), + f"plugin {plugin_cls} toolbar {idx}", tooltip, functools.partial(self._dispatch_single, plugin, BasePlugin.handle_click_toolbar, False, idx), ) diff --git a/angrmanagement/plugins/trace_viewer/trace_plugin.py b/angrmanagement/plugins/trace_viewer/trace_plugin.py index 270b811b0e..104715881e 100644 --- a/angrmanagement/plugins/trace_viewer/trace_plugin.py +++ b/angrmanagement/plugins/trace_viewer/trace_plugin.py @@ -303,7 +303,7 @@ def _open_bitmap_multi_trace(self, trace_path, base_addr): self.workspace._main_window, "Downloading failed", "angr management failed to retrieve the header of the file. " - "The HTTP request returned an unexpected status code %d." % ex.status_code, + f"The HTTP request returned an unexpected status code {ex.status_code}.", ) return None else: @@ -332,7 +332,7 @@ def _open_trace(self, trace_path, base_addr): self.workspace._main_window, "Downloading failed", "angr management failed to retrieve the header of the file. " - "The HTTP request returned an unexpected status code %d." % ex.status_code, + f"The HTTP request returned an unexpected status code {ex.status_code}.", ) trace = None else: diff --git a/angrmanagement/ui/dialogs/socket_config.py b/angrmanagement/ui/dialogs/socket_config.py index 9125eb2122..fd6251ba82 100644 --- a/angrmanagement/ui/dialogs/socket_config.py +++ b/angrmanagement/ui/dialogs/socket_config.py @@ -268,7 +268,7 @@ def _action_accepted_socket(self) -> None: current = self.currentIndex() if current.parent().isValid(): current = current.parent() - ident = "Accept, " + current.internalPointer().ident + (", %d" % (current.internalPointer().childCount() + 1)) + ident = f"Accept, {current.internalPointer().ident}, {current.internalPointer().childCount() + 1}" self.model().add_item(ident, current, "Accepted") def _action_add_package(self) -> None: diff --git a/angrmanagement/ui/widgets/qast_viewer.py b/angrmanagement/ui/widgets/qast_viewer.py index a9f6680d94..06a4b78142 100644 --- a/angrmanagement/ui/widgets/qast_viewer.py +++ b/angrmanagement/ui/widgets/qast_viewer.py @@ -203,7 +203,7 @@ def _build_strings(self) -> None: else: # claripy.AST if self._display_size: - self._size_label.setText("[%d]" % (len(ast) // 8)) # in bytes + self._size_label.setText(f"[{len(ast) // 8}]") # in bytes if not ast.symbolic: format = "%02x" if self._byte_format is None else self._byte_format self._ast_str = format % self._ast._model_concrete.value diff --git a/angrmanagement/ui/widgets/qblock_code.py b/angrmanagement/ui/widgets/qblock_code.py index ec677495e5..1a6ba3a432 100644 --- a/angrmanagement/ui/widgets/qblock_code.py +++ b/angrmanagement/ui/widgets/qblock_code.py @@ -399,7 +399,7 @@ def create_subobjs(self, obj: ailment.expression.Register) -> None: if obj.variable is not None and self.options.show_variables: self.add_variable(obj.variable) else: - s = f"{obj.reg_name}" if hasattr(obj, "reg_name") else "reg_%d<%d>" % (obj.reg_offset, obj.bits // 8) + s = f"{obj.reg_name}" if hasattr(obj, "reg_name") else f"reg_{obj.reg_offset}<{obj.bits // 8}>" self.add_text(s) def should_highlight(self) -> bool: @@ -441,7 +441,7 @@ class QAilConvertObj(QAilTextObj): """ def create_subobjs(self, obj: ailment.expression.Convert) -> None: - self.add_text("Conv(%d->%d, " % (obj.from_bits, obj.to_bits)) + self.add_text(f"Conv({obj.from_bits}->{obj.to_bits}, ") self.add_ailobj(obj.operand) self.add_text(")") @@ -546,7 +546,7 @@ class VexIRTmpWrapper: def __init__(self, tid: TmpVar, reg_name: str | None = None) -> None: self.tid = tid - self.reg_name = reg_name or ("t%d" % self.tid) + self.reg_name = reg_name or (f"t{self.tid}") def __str__(self) -> str: return self.reg_name diff --git a/angrmanagement/ui/widgets/qfunction_header.py b/angrmanagement/ui/widgets/qfunction_header.py index 5e311f3a45..4f24205eac 100644 --- a/angrmanagement/ui/widgets/qfunction_header.py +++ b/angrmanagement/ui/widgets/qfunction_header.py @@ -127,7 +127,7 @@ def _init_widgets(self) -> None: if self.prototype.arg_names and i < len(self.prototype.arg_names): arg_name = self.prototype.arg_names[i] else: - arg_name = "arg_%d" % i + arg_name = f"arg_{i}" proto_str += arg_name if i < len(self.prototype.args) - 1: diff --git a/angrmanagement/ui/widgets/qfunction_table.py b/angrmanagement/ui/widgets/qfunction_table.py index c1449dc6f6..9f5f154bdc 100644 --- a/angrmanagement/ui/widgets/qfunction_table.py +++ b/angrmanagement/ui/widgets/qfunction_table.py @@ -510,9 +510,9 @@ def update_displayed_function_count(self) -> None: self._status_label.setText("") return if cnt == len(self.function_manager): - self._status_label.setText("%d functions" % cnt) + self._status_label.setText(f"{cnt} functions") else: - self._status_label.setText("%d/%d functions" % (cnt, len(self.function_manager))) + self._status_label.setText(f"{cnt}/{len(self.function_manager)} functions") def filter_functions(self, text: str) -> None: self._table_view.filter(text) diff --git a/angrmanagement/ui/widgets/qoperand.py b/angrmanagement/ui/widgets/qoperand.py index 4b793801fa..8f8fa893c4 100644 --- a/angrmanagement/ui/widgets/qoperand.py +++ b/angrmanagement/ui/widgets/qoperand.py @@ -300,7 +300,7 @@ def _init_widgets(self) -> None: if "custom_values_str" not in formatting: formatting["custom_values_str"] = {} if variable_sort == "memory": - custom_value_str = variable_str if offset == 0 else "%s[%d]" % (variable_str, offset) + custom_value_str = f"{variable_str}" if offset == 0 else f"{variable_str}[{offset}]" else: custom_value_str = "" @@ -310,15 +310,15 @@ def _init_widgets(self) -> None: if self.infodock.induction_variable_analysis is not None: r = self.infodock.induction_variable_analysis.variables.get(variable.ident, None) if r is not None and r.expr.__class__.__name__ == "InductionExpr": - custom_value_str = "i*%d+%d" % (r.expr.stride, r.expr.init) + custom_value_str = f"i*{r.expr.stride}+{r.expr.init}" if ( r is not None and r.expr.__class__.__name__ == "Add" and r.expr.operands[0].__class__.__name__ == "InductionExpr" ): - custom_value_str = "i*%d+%d" % ( - r.expr.operands[0].stride, - r.expr.operands[0].init + r.expr.operands[1].value, + custom_value_str = ( + f"i*{r.expr.operands[0].stride}+" + "{r.expr.operands[0].init + r.expr.operands[1].value}" ) formatting["custom_values_str"][ident] = custom_value_str diff --git a/angrmanagement/ui/widgets/qsimulation_manager_viewer.py b/angrmanagement/ui/widgets/qsimulation_manager_viewer.py index 66d845affb..f00bfcc51a 100644 --- a/angrmanagement/ui/widgets/qsimulation_manager_viewer.py +++ b/angrmanagement/ui/widgets/qsimulation_manager_viewer.py @@ -40,7 +40,7 @@ def refresh(self) -> None: if self.stash_name == "errored" and getattr(state, "state", None): state = state.state self.addChild(StateTreeItem(state, self.simgr_viewer)) - self.setText(0, "%s (%d)" % (self.stash_name, len(self.states))) + self.setText(0, f"{self.stash_name} ({len(self.states)})") def handle_context_menu_event(self, event) -> None: menu = QMenu() diff --git a/angrmanagement/ui/widgets/qstate_table.py b/angrmanagement/ui/widgets/qstate_table.py index 5c504ecf1e..727a83c6a4 100644 --- a/angrmanagement/ui/widgets/qstate_table.py +++ b/angrmanagement/ui/widgets/qstate_table.py @@ -179,7 +179,7 @@ def _get_copied_state_name(self, current_name: str): ctr = int(ctr_str) + 1 if ctr_str else 1 current_name = m.group(1) - name = current_name + " copy %d" % ctr + name = f"{current_name} copy {ctr}" else: ctr = 0 name = current_name + " copy" @@ -188,5 +188,5 @@ def _get_copied_state_name(self, current_name: str): all_names = {s.gui_data.name for s in self.states} while name in all_names: ctr += 1 - name = current_name + " copy %d" % ctr + name = f"{current_name} copy {ctr}" return name diff --git a/angrmanagement/ui/widgets/qvextemps_viewer.py b/angrmanagement/ui/widgets/qvextemps_viewer.py index 303c152463..23a2763274 100644 --- a/angrmanagement/ui/widgets/qvextemps_viewer.py +++ b/angrmanagement/ui/widgets/qvextemps_viewer.py @@ -61,7 +61,7 @@ def _load_tmps(self) -> None: lbl_tmp_name = QLabel(self) lbl_tmp_name.setProperty("class", "reg_viewer_label") - lbl_tmp_name.setText("tmp_%d" % tmp_id) + lbl_tmp_name.setText(f"tmp_{tmp_id}") lbl_tmp_name.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed) sublayout.addWidget(lbl_tmp_name) diff --git a/angrmanagement/utils/edge.py b/angrmanagement/utils/edge.py index fb7d695ec6..2f7f4a30d7 100644 --- a/angrmanagement/utils/edge.py +++ b/angrmanagement/utils/edge.py @@ -61,4 +61,4 @@ def last_move(self): return 1 # NO_MOVE def __repr__(self) -> str: - return "" % (self.src, self.dst, len(self.coordinates)) + return f"" diff --git a/angrmanagement/utils/func.py b/angrmanagement/utils/func.py index 0f99c47d45..f613d5085e 100644 --- a/angrmanagement/utils/func.py +++ b/angrmanagement/utils/func.py @@ -45,7 +45,7 @@ def function_prototype_str(func: Function) -> str: if func.prototype.arg_names and i < len(func.prototype.arg_names): arg_name = func.prototype.arg_names[i] else: - arg_name = "arg_%d" % i + arg_name = f"arg_{i}" s += type_str + " " + arg_name diff --git a/angrmanagement/utils/graph.py b/angrmanagement/utils/graph.py index 809545d285..1459150975 100644 --- a/angrmanagement/utils/graph.py +++ b/angrmanagement/utils/graph.py @@ -304,11 +304,7 @@ def merge(self, other) -> None: self.out_branches[ins_addr][item.stmt_idx] = item def __repr__(self) -> str: - return "" % ( - self.addr, - len(self.cfg_nodes), - len(self.out_branches), - ) + return f"" def __hash__(self): return hash(("supercfgnode", self.addr))