Skip to content

Commit

Permalink
QDecompilationOptions: Add Preset combo box (#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson authored Oct 4, 2024
1 parent 67f5f6f commit 0478cff
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions angrmanagement/ui/widgets/qdecomp_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
from angr.analyses.decompiler.optimization_passes import get_optimization_passes
from angr.analyses.decompiler.peephole_optimizations import EXPR_OPTS, MULTI_STMT_OPTS, STMT_OPTS
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QComboBox, QLineEdit, QPushButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget
from PySide6.QtWidgets import (
QComboBox,
QHBoxLayout,
QLabel,
QLineEdit,
QPushButton,
QTreeWidget,
QTreeWidgetItem,
QVBoxLayout,
QWidget,
)

if TYPE_CHECKING:
from angrmanagement.data.instance import Instance
Expand Down Expand Up @@ -96,6 +106,7 @@ def __init__(self, code_view, instance: Instance) -> None:
self._peephole_opts = None

# widgets
self._preset_cmb: QComboBox
self._search_box: QLineEdit
self._treewidget: QTreeWidget
self._apply_btn: QPushButton
Expand Down Expand Up @@ -164,7 +175,7 @@ def get_default_options(self): # pylint: disable=no-self-use
def get_default_passes(self):
if self._instance is None or self._instance.project.am_none:
return []
default_preset = DECOMPILATION_PRESETS["default"]
default_preset = DECOMPILATION_PRESETS[self._preset_cmb.currentText()]
return default_preset.get_optimization_passes(
self._instance.project.arch, self._instance.project.simos.name
) + [x for x, de in self._code_view.workspace.plugins.optimization_passes() if de]
Expand All @@ -183,6 +194,20 @@ def get_all_peephole_opts(self): # pylint: disable=no-self-use
return MULTI_STMT_OPTS + STMT_OPTS + EXPR_OPTS

def _init_widgets(self) -> None:
preset_lyt = QHBoxLayout()
preset_lyt.setContentsMargins(3, 3, 3, 3)
preset_lyt.setSpacing(3)

preset_lyt.addWidget(QLabel("Preset:"))
self._preset_cmb = QComboBox()
presets = sorted([n for n in DECOMPILATION_PRESETS if n != "default"])
self._preset_cmb.addItems(presets)
self._preset_cmb.setCurrentIndex(
next(i for i, n in enumerate(presets) if DECOMPILATION_PRESETS[n] is DECOMPILATION_PRESETS["default"])
)
self._preset_cmb.activated.connect(lambda: self.reload(force=True))
preset_lyt.addWidget(self._preset_cmb, 1)

# search box
self._search_box = QLineEdit()
self._search_box.textChanged.connect(self._on_search_box_text_changed)
Expand All @@ -197,6 +222,7 @@ def _init_widgets(self) -> None:
self._apply_btn.clicked.connect(self._on_apply_pressed)

layout = QVBoxLayout()
layout.addLayout(preset_lyt)
layout.addWidget(self._search_box)
layout.addWidget(self._treewidget)
layout.addWidget(self._apply_btn)
Expand Down

0 comments on commit 0478cff

Please sign in to comment.