Skip to content

Commit 650c359

Browse files
committed
fix: lib, upload and minor fixes
1 parent 02a20ad commit 650c359

14 files changed

Lines changed: 171 additions & 386 deletions

File tree

reai_toolkit/__init__.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22
import os
33
import sys
44
from binaryninja import log_info, log_error
5+
import importlib
6+
7+
def delete_module(module_name):
8+
to_delete = []
9+
for module in sys.modules:
10+
if module.startswith(module_name):
11+
to_delete.append(module)
12+
for module_to_delete in to_delete:
13+
log_info(f"RevEng.AI | Deleting module: {module_to_delete}")
14+
del sys.modules[module_to_delete]
15+
16+
def import_module(module_name):
17+
try:
18+
importlib.import_module(module_name)
19+
log_info(f"RevEng.AI | Imported module: {module_name}")
20+
except Exception as e:
21+
log_error(f"RevEng.AI | Error importing module: {e}")
522

6-
# Get the directory where this __init__.py file is located
723
try:
824
plugin_dir = os.path.dirname(os.path.abspath(__file__))
925
log_info(f"RevEng.AI | Using __file__ for plugin directory")
1026
except NameError:
11-
# If __file__ is not defined, try to get it from the module
1227
import reai_toolkit
1328
plugin_dir = os.path.dirname(os.path.abspath(reai_toolkit.__file__))
1429
log_info(f"RevEng.AI | Using module path for plugin directory")
@@ -19,26 +34,42 @@
1934
log_info(f"RevEng.AI | Vendor path: {vendor_path}")
2035
log_info(f"RevEng.AI | Vendor exists: {os.path.exists(vendor_path)}")
2136

22-
# Check if vendor directory exists and list its contents
2337
if os.path.exists(vendor_path):
24-
# Add vendor directory to the beginning of sys.path for priority
2538
if vendor_path not in sys.path:
2639
sys.path.insert(0, vendor_path)
2740
log_info(f"RevEng.AI | Added vendor directory to sys.path at position 0")
2841

29-
# Also use site.addsitedir to handle .pth files
3042
site.addsitedir(vendor_path)
3143

32-
# List some contents for verification
3344
try:
3445
contents = os.listdir(vendor_path)
3546
log_info(f"RevEng.AI | Vendor directory contains {len(contents)} items")
3647
log_info(f"RevEng.AI | Sample contents: {', '.join(contents[:5])}")
48+
49+
modules = ["urllib3", "certifi", "revengai"]
50+
51+
for module in modules:
52+
delete_module(module)
53+
import_module(module)
54+
55+
import certifi
56+
57+
os.environ["SSL_CERT_FILE"] = certifi.where()
58+
os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
59+
60+
modules.remove("revengai")
61+
sys.path.remove(vendor_path)
62+
63+
for module in modules:
64+
delete_module(module)
65+
import_module(module)
66+
67+
sys.path.insert(0, vendor_path)
68+
3769
except Exception as e:
3870
log_error(f"RevEng.AI | Error listing vendor contents: {e}")
3971
else:
4072
log_error(f"RevEng.AI | ERROR: Vendor directory not found at {vendor_path}")
41-
# List what's actually in the plugin directory
4273
try:
4374
plugin_contents = os.listdir(plugin_dir)
4475
log_info(f"RevEng.AI | Plugin directory contains: {', '.join(plugin_contents)}")

reai_toolkit/features/auto_unstrip/auto_unstrip.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from concurrent.futures import ThreadPoolExecutor, as_completed
99
from reai_toolkit.utils import rename_function as rename_function_util, apply_data_types as apply_data_types_util, get_function_by_addr as get_function_by_addr_util
1010
from revengai import AutoUnstripRequest
11+
from threading import Event
1112

1213
class AutoUnstrip:
1314
def __init__(self, config):
@@ -16,6 +17,15 @@ def __init__(self, config):
1617
self.base_addr = None
1718
self.path = None
1819
self.max_workers = 4
20+
self.cancelled = Event()
21+
22+
def cancel(self):
23+
log_info("RevEng.AI | Cancelling operation...")
24+
self.cancelled.set()
25+
26+
def clear_cancelled(self):
27+
log_info("RevEng.AI | Clearing cancelled event...")
28+
self.cancelled.clear()
1929

2030
def resolve_data_types(self, to_datatypes: List[Dict], id_to_addr: Dict[int, int], deci: DecompilerInterface, chunk_index: int) -> None:
2131
try:
@@ -89,6 +99,9 @@ def auto_unstrip(self, bv: BinaryView):
8999
matches = []
90100
results = []
91101

102+
if self.cancelled.is_set():
103+
return False, "Operation cancelled"
104+
92105
with revengai.ApiClient(self.config.api_config) as api_client:
93106
api_instance = revengai.FunctionsCoreApi(api_client)
94107
api_response = api_instance.auto_unstrip(analysis_id, auto_unstrip_request)
@@ -110,12 +123,18 @@ def auto_unstrip(self, bv: BinaryView):
110123
raise Exception(api_response.error)
111124
for match in matches:
112125
try:
126+
if self.cancelled.is_set():
127+
return False, "Operation cancelled"
128+
113129
function = get_function_by_addr_util(bv, match.function_vaddr)
114130
results.append({"virtual_address": match.function_vaddr, "current_name": function.name, "suggested_name": match.suggested_demangled_name})
115131
except Exception as e:
116132
log_error(f"RevEng.AI | Error getting function by address {match.function_vaddr}: {str(e)}")
117133
results.append({"virtual_address": match.function_vaddr, "current_name": "N/A", "suggested_name": match.suggested_demangled_name})
118134

135+
if self.cancelled.is_set():
136+
return False, "Operation cancelled"
137+
119138
return True, results
120139

121140
except Exception as e:

reai_toolkit/features/auto_unstrip/auto_unstrip_dialog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from binaryninja import log_error, log_info
33
from PySide6.QtGui import QPixmap
44
from PySide6.QtCore import Qt, QCoreApplication
5-
from reai_toolkit.utils import create_progress_dialog, DataThread
5+
from reai_toolkit.utils import create_progress_dialog, DataThread, create_cancellable_progress_dialog
66
from PySide6.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QCheckBox, QMessageBox, QTableWidget, QHeaderView, QAbstractItemView, QTableWidgetItem
77

88
class AutoUnstripDialog(QDialog):
@@ -118,11 +118,11 @@ def _on_rename_finished(self, success, message):
118118

119119

120120
def _auto_unstrip(self):
121-
self.progress = create_progress_dialog(self, "RevEng.AI Auto Unstrip", "Auto Unstripping binary...")
121+
self.progress = create_cancellable_progress_dialog(self, "RevEng.AI Auto Unstrip", "Auto Unstripping binary...", self.auto_unstrip.cancel)
122122
self.progress.show()
123123
QCoreApplication.processEvents()
124124

125-
self.auto_unstrip_thread = DataThread(self.auto_unstrip.auto_unstrip, self.bv)
125+
self.auto_unstrip_thread = DataThread(self.auto_unstrip.auto_unstrip, self.bv, callback_cancelled_reset = self.auto_unstrip.clear_cancelled)
126126
self.auto_unstrip_thread.finished.connect(self._on_auto_unstrip_finished)
127127
self.auto_unstrip_thread.start()
128128

reai_toolkit/features/auto_unstrip_old/__init__.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

reai_toolkit/features/auto_unstrip_old/auto_unstrip.py

Lines changed: 0 additions & 197 deletions
This file was deleted.

0 commit comments

Comments
 (0)