11from binaryninja import log_error , log_info
2- from PySide6 .QtWidgets import (QDockWidget , QVBoxLayout , QHBoxLayout ,
3- QPushButton , QLabel , QCheckBox , QWidget , QTabWidget , QPlainTextEdit )
4- from PySide6 .QtCore import Qt
5- from PySide6 .QtGui import QPixmap
6- from PySide6 .QtWidgets import QWidget
2+ from PySide6 .QtWidgets import QVBoxLayout , QCheckBox , QWidget , QTabWidget , QPlainTextEdit
73from PySide6 .QtCore import QCoreApplication
8- from PySide6 .QtWidgets import QMessageBox
9- from PySide6 .QtWidgets import QProgressBar
10- from revengai .utils import create_progress_dialog
11- from .c_highlighter import CHighlighter
12- from revengai .utils .data_thread import DataThread
13- from revengai .utils import get_function_by_addr
14- from revengai .utils .periodic_check import PeriodicChecker
15- import os
4+ from revengai .utils import create_progress_dialog , get_function_by_addr
5+ from revengai .utils .c_highlighter import CHighlighter
166
177class AIDecompilerDialog (QWidget ):
188 def __init__ (self , config , ai_decompiler , bv , func ):
199 super ().__init__ ()
2010 self .config = config
2111 self .ai_decompiler = ai_decompiler
12+ self .ai_decompiler .dialog = self
2213 self .bv = bv
2314 self .func = func
2415 self .tabs = QTabWidget ()
2516 self .number_of_clicks = 0
26- self .init_ui (bv , func )
17+ self .initial_setup_done = False
18+ self .init_ui ()
2719
28- def init_ui (self , bv , func ):
20+ def init_ui (self ):
2921 self .setWindowTitle ("RevEng.AI: AI Decompiler" )
3022 layout = QVBoxLayout ()
3123 self .setLayout (layout )
3224 layout .addWidget (self .tabs )
33- self .pre_tab_setup (bv , func )
25+ self .address_tracking_checkbox = QCheckBox ("Address Tracking" )
26+ self .address_tracking_checkbox .setChecked (True )
27+ layout .addWidget (self .address_tracking_checkbox )
28+ self .address_tracking_checkbox .stateChanged .connect (self .toggle_address_tracking )
3429 self .tabs .tabCloseRequested .connect (self .close_tab )
3530
31+ def showEvent (self , event ):
32+ super ().showEvent (event )
33+ if not self .initial_setup_done :
34+ self .initial_setup_done = True
35+ QCoreApplication .processEvents ()
36+ self .pre_tab_setup (self .bv , self .func )
37+
38+ def toggle_address_tracking (self , state ):
39+ log_info (f"RevEng.AI | Address tracking checkbox state changed to { state } " )
40+ if state == 2 :
41+ log_info (f"RevEng.AI | Starting address tracking" )
42+ self .ai_decompiler .start_address_tracking ()
43+ else :
44+ log_info (f"RevEng.AI | Stopping address tracking" )
45+ self .ai_decompiler .stop_address_tracking ()
46+
3647 def pre_tab_setup (self , bv , func ):
37- function = get_function_by_addr (bv , func )
38- tab_name = str (f"0x{ function .start :x} " )
39- log_info (f"RevEng.AI | Given address 0x{ func :x} is function: { function .name } at 0x{ function .start :x} " )
40- for i in range (self .tabs .count ()):
41- if self .tabs .tabText (i ) == tab_name :
42- log_info (f"RevEng.AI | Tab { tab_name } already exists, switching to it." )
43- return
44-
45- log_info (f"RevEng.AI | Adding tab { tab_name } " )
46- tab = QWidget ()
47- layout = QVBoxLayout ()
48+ try :
49+ progress_dialog = create_progress_dialog (self , "RevEng.AI" , "Setting up AI Decompiler..." )
50+ progress_dialog .show ()
51+ QCoreApplication .processEvents ()
4852
49- editor = QPlainTextEdit ()
50- editor .setPlainText ("Starting AI Decompiler..." )
51- editor .setReadOnly (True )
53+ function = get_function_by_addr (bv , func )
54+ tab_name = str (f"0x{ function .start :x} " )
55+ log_info (f"RevEng.AI | Given address 0x{ func :x} is function: { function .name } at 0x{ function .start :x} " )
56+ for i in range (self .tabs .count ()):
57+ if self .tabs .tabText (i ) == tab_name :
58+ log_info (f"RevEng.AI | Tab { tab_name } already exists, switching to it." )
59+ self .tabs .setCurrentIndex (i )
60+ progress_dialog .close ()
61+ return
62+
63+ log_info (f"RevEng.AI | Adding tab { tab_name } " )
64+ tab = QWidget ()
65+ layout = QVBoxLayout ()
5266
53- #CHighlighter(editor.document())
54- editor .show ()
55- layout .addWidget (editor )
56- tab .setLayout (layout )
57-
58- index = self .tabs .addTab (tab , tab_name )
59- self .tabs .setCurrentIndex (index )
67+ editor = QPlainTextEdit ()
68+ editor .setPlainText ("Starting AI Decompiler..." )
69+ editor .setReadOnly (True )
6070
61- if self . tabs . count () > 1 :
62- self . tabs . setTabsClosable ( True )
71+ editor . show ()
72+ QCoreApplication . processEvents ( )
6373
64- options = {
65- "editor" : editor ,
66- "tab_name" : tab_name ,
67- "function" : function ,
68- "callback" : self .edit_editor
69- }
70- self .ai_decompiler .start_ai_decompiler (self .bv , options )
74+ layout .addWidget (editor )
75+ tab .setLayout (layout )
76+
77+ index = self .tabs .addTab (tab , tab_name )
78+ self .tabs .setCurrentIndex (index )
79+
80+ if self .tabs .count () > 1 :
81+ self .tabs .setTabsClosable (True )
82+
83+ options = {
84+ "editor" : editor ,
85+ "tab_name" : tab_name ,
86+ "function" : function ,
87+ "callback" : self .edit_editor
88+ }
89+
90+ self .ai_decompiler .start_ai_decompiler (self .bv , options )
91+ progress_dialog .close ()
92+ except Exception as e :
93+ if 'progress_dialog' in locals ():
94+ progress_dialog .close ()
95+ log_error (f"RevEng.AI | Error during pre_tab_setup: { str (e )} " )
7196
7297 def close_tab (self , index ):
7398 log_info (f"RevEng.AI | Closing tab { index } of { self .tabs .count ()} tabs" )
7499
75- # Stop AI decompiler for this tab if it's running
76100 try :
77101 self .ai_decompiler .stop_ai_decompiler ()
78102 except Exception as e :
@@ -83,10 +107,9 @@ def close_tab(self, index):
83107 self .tabs .setTabsClosable (False )
84108
85109 def closeEvent (self , event ):
86- """Handle dialog close event"""
87110 try :
88- # Stop any running AI decompiler
89111 if hasattr (self , 'ai_decompiler' ):
112+ log_info (f"RevEng.AI | Stopping AI decompiler" )
90113 self .ai_decompiler .stop_ai_decompiler ()
91114 except Exception as e :
92115 log_error (f"RevEng.AI | Error during cleanup: { str (e )} " )
0 commit comments