From c13b6357c0c3698987e2b57e80414a832fa4039e Mon Sep 17 00:00:00 2001 From: Burhan Rajgara Date: Wed, 14 Aug 2024 16:28:52 -0700 Subject: [PATCH] added a popup when waiting for patch to complete --- .../decompiler_specific/ghidra/interface.py | 13 +-- .../src/patcherex2/decompiler_plugins/ui.py | 97 ++++++++++++++----- 2 files changed, 80 insertions(+), 30 deletions(-) diff --git a/decompiler-plugins/src/patcherex2/decompiler_plugins/decompiler_specific/ghidra/interface.py b/decompiler-plugins/src/patcherex2/decompiler_plugins/decompiler_specific/ghidra/interface.py index b77215f..ff197d4 100644 --- a/decompiler-plugins/src/patcherex2/decompiler_plugins/decompiler_specific/ghidra/interface.py +++ b/decompiler-plugins/src/patcherex2/decompiler_plugins/decompiler_specific/ghidra/interface.py @@ -22,12 +22,6 @@ def __init__(self): ) self.controller = Patcherex2Controller(self._interface) self.control_panel = ControlPanel(self.controller) - self.controller.deci.gui_register_ctx_menu( - "PatchAddress", - "Create a patch at this address", - lambda *x, **y: self.control_panel.add_patch, - category="Patcherex2", - ) self._init_widgets() def _init_widgets(self): @@ -44,4 +38,11 @@ def start_ghidra_remote_ui(): cp_window.show() + cp_window.controller.deci.gui_register_ctx_menu( + "PatchAddress", + "Create a patch at this address", + lambda *x, **y: cp_window.control_panel.add_patch, + category="Patcherex2", + ) + app.exec_() diff --git a/decompiler-plugins/src/patcherex2/decompiler_plugins/ui.py b/decompiler-plugins/src/patcherex2/decompiler_plugins/ui.py index efe430f..b8bf661 100644 --- a/decompiler-plugins/src/patcherex2/decompiler_plugins/ui.py +++ b/decompiler-plugins/src/patcherex2/decompiler_plugins/ui.py @@ -2,29 +2,27 @@ import re import select # noqa: F401 -from libbs.ui.qt_objects import ( - QAbstractItemView, - QCheckBox, - QComboBox, - QDialog, - QDialogButtonBox, - QGridLayout, - QGroupBox, - QHBoxLayout, - QHeaderView, - QLabel, - QLineEdit, - QMessageBox, - QPushButton, - Qt, - QTableWidget, - QVBoxLayout, - QWidget, -) -from libbs.ui.utils import QThread -from libbs.ui.version import ui_version - import patcherex2 + +# from libbs.ui.qt_objects import ( +# QAbstractItemView, +# QCheckBox, +# QComboBox, +# QDialog, +# QDialogButtonBox, +# QGridLayout, +# QGroupBox, +# QHBoxLayout, +# QHeaderView, +# QLabel, +# QLineEdit, +# QMessageBox, +# QPushButton, +# QTableWidget, +# QVBoxLayout, +# QWidget, +# ) +from libbs.ui.version import ui_version from patcherex2 import * from .controller import Patcherex2Controller, UIPatch @@ -32,10 +30,51 @@ if ui_version == "PySide6": from PySide6.QtGui import QFont - from PySide6.QtWidgets import QTextEdit + from PySide6.QtWidgets import ( + QAbstractItemView, + QApplication, + QCheckBox, + QComboBox, + QDialog, + QDialogButtonBox, + QGridLayout, + QGroupBox, + QHBoxLayout, + QHeaderView, + QLabel, + QLineEdit, + QMessageBox, + QProgressDialog, + QPushButton, + QTableWidget, + QTextEdit, + QVBoxLayout, + QWidget, + ) else: from PyQt5.QtGui import QFont - from PyQt5.QtWidgets import QTextEdit + from PyQt5.QtWidgets import ( + QAbstractItemView, + QApplication, + QCheckBox, + QComboBox, + QDialog, + QDialogButtonBox, + QFont, + QGridLayout, + QGroupBox, + QHBoxLayout, + QHeaderView, + QLabel, + QLineEdit, + QMessageBox, + QProgressDialog, + QPushButton, + QTableWidget, + QTextEdit, + QVBoxLayout, + QWidget, + ) import logging @@ -385,6 +424,14 @@ def reload_from_script(self): self.add_patch_list_row(patch_name, args) def patch_binary(self): + progressdialog = QProgressDialog() + progressdialog.setRange(0, 0) + progressdialog.setWindowTitle("Patching...") + progressdialog.setLabelText("Patching...") + progressdialog.setCancelButton(None) + progressdialog.show() + QApplication.processEvents() + try: binary_path = self.controller.deci.binary_path script = self.script_editor.toPlainText() @@ -393,8 +440,10 @@ def patch_binary(self): except Exception as e: logging.getLogger("patcherex2").error("Failed to patch binary", exc_info=1) + progressdialog.hide() QMessageBox.critical(None, "Error", f"Failed to patch binary: {e}") return + progressdialog.hide() QMessageBox.information(None, "Success", "Binary patched!") self.controller.patched_patches = self.controller.patches.copy() dialog = LoadBinaryDialog()