Skip to content

Commit

Permalink
added a popup when waiting for patch to complete
Browse files Browse the repository at this point in the history
  • Loading branch information
burhanr13 committed Aug 14, 2024
1 parent bcc96d6 commit c13b635
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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_()
97 changes: 73 additions & 24 deletions decompiler-plugins/src/patcherex2/decompiler_plugins/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,79 @@
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
from .decompiler_specific.deci_extras import *

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

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit c13b635

Please sign in to comment.