Skip to content

Commit f16c67c

Browse files
committed
finishing process binary feature
1 parent cb277a5 commit f16c67c

21 files changed

Lines changed: 230 additions & 456 deletions

.gitignore

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Virtual Environment
24+
venv/
25+
ENV/
26+
env/
27+
.env/
28+
29+
# IDE
30+
.idea/
31+
.vscode/
32+
*.swp
33+
*.swo
34+
35+
# Binary Ninja specific
36+
*.bndb
37+
*.bndb.bak
38+
patchers/
39+
*.patch
40+
41+
# Logs and databases
42+
*.log
43+
*.sqlite
44+
45+
# OS specific
46+
.DS_Store
47+
.DS_Store?
48+
._*
49+
.Spotlight-V100
50+
.Trashes
51+
ehthumbs.db
52+
Thumbs.db

features/configuration/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from binaryninja import PluginCommand, log_info
22
from .config import Config
33
from .config_dialog import ConfigDialog
4-
from ..base_auth_feature import BaseAuthFeature
4+
from revengai_bn.utils import BaseAuthFeature
55

66
class ConfigurationFeature():
77
def __init__(self):

features/configuration/config.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ def _load_config(self):
3838
"description" : "Configuration Status"}')
3939
settings.register_setting("revengai.binary_id",
4040
'{"title" : "Binary ID",\
41-
"type" : "string",\
42-
"default" : "",\
41+
"type" : "number",\
42+
"default" : 0,\
4343
"description" : "Current Binary ID"}')
4444
settings.register_setting("revengai.analysis_id",
4545
'{"title" : "Analysis ID",\
46-
"type" : "string",\
47-
"default" : "",\
46+
"type" : "number",\
47+
"default" : 0,\
4848
"description" : "Current Analysis ID"}')
4949

5050
self.host = settings.get_string("revengai.host", None)
@@ -71,11 +71,14 @@ def save_config(self) -> bool:
7171
settings.set_string("revengai.host", self.host)
7272
settings.set_string("revengai.api_key", self.api_key)
7373
settings.set_string("revengai.is_configured", self.is_configured)
74-
74+
7575
return True
7676

7777
except Exception as e:
7878
log_info(f"RevEng.AI | Failed to save API key: {str(e)}")
79+
self.is_configured = "False"
80+
settings = Settings()
81+
settings.set_string("revengai.is_configured", self.is_configured)
7982
return False
8083

8184

@@ -86,14 +89,14 @@ def clear_config(self):
8689
self.is_configured = False
8790
self.save_config()
8891

89-
def set_binary_id(self, binary_id: str):
92+
def set_binary_id(self, binary_id: int):
9093
"""Set the binary ID and store it in settings."""
9194
self.binary_id = binary_id
9295
settings = Settings()
9396
settings.set_integer("revengai.binary_id", self.binary_id)
9497
return
9598

96-
def set_analysis_id(self, analysis_id: str):
99+
def set_analysis_id(self, analysis_id: int):
97100
"""Set the analysis ID and store it in settings."""
98101
self.analysis_id = analysis_id
99102
settings = Settings()

features/configuration/config_dialog.py

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from PySide6.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel,
2-
QLineEdit, QPushButton, QMessageBox, QProgressDialog, QProgressBar)
2+
QLineEdit, QPushButton, QMessageBox)
33
from PySide6.QtCore import Qt
44
from PySide6.QtGui import QPixmap
55
from binaryninja import log_info, log_error, log_warn
66
import os
77
from .config_save_thread import ConfigSaveThread
8+
from revengai_bn.utils import create_progress_dialog
89

910
class ConfigDialog(QDialog):
1011
def __init__(self, config):
@@ -14,6 +15,7 @@ def __init__(self, config):
1415
self.progress = None
1516
self.init_ui()
1617

18+
1719
def init_ui(self):
1820
self.setWindowTitle("RevEng.AI Configuration Wizard")
1921
self.setMinimumWidth(500)
@@ -95,6 +97,7 @@ def init_ui(self):
9597
layout.addLayout(button_layout)
9698

9799
self.setLayout(layout)
100+
98101

99102
def save_config(self):
100103
api_key = self.api_key_input.text().strip()
@@ -119,36 +122,15 @@ def save_config(self):
119122
QMessageBox.Ok
120123
)
121124
return
122-
123-
# Create and show progress dialog
124-
self.progress = QProgressDialog("Testing API key...", None, 0, 0, self)
125-
self.progress.setWindowTitle("RevEng.AI Configuration")
126-
self.progress.setWindowModality(Qt.WindowModal)
127-
self.progress.setCancelButton(None)
128-
self.progress.setMinimumWidth(400)
129-
self.progress.setMinimumHeight(100)
130-
self.progress.findChild(QProgressBar).setMinimumWidth(250)
131-
self.progress.findChild(QProgressBar).setMinimumHeight(20)
132-
self.progress.setStyleSheet("""
133-
QProgressBar {
134-
border: 1px solid #cccccc;
135-
border-radius: 4px;
136-
text-align: center;
137-
background-color: #f0f0f0;
138-
min-width: 250px;
139-
min-height: 20px;
140-
}
141-
QProgressBar::chunk {
142-
background-color: #007bff;
143-
border-radius: 3px;
144-
}
145-
""")
125+
126+
self.progress = create_progress_dialog(self, "RevEng.AI Configuration", "Testing API key...")
146127

147128
self.save_thread = ConfigSaveThread(self.config, api_key, host)
148129
self.save_thread.finished.connect(self._on_save_finished)
149130
self.save_thread.start()
150131

151132
self.progress.show()
133+
152134

153135
def _on_save_finished(self, success, error_message):
154136
self.progress.close()

features/upload/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from binaryninja import PluginCommand, log_info, BinaryView
22
from .upload import BinaryUploader
33
from .upload_dialog import UploadDialog
4-
from ..base_auth_feature import BaseAuthFeature
4+
from revengai_bn.utils import BaseAuthFeature
55

66
class UploadFeature(BaseAuthFeature):
77
def __init__(self, config=None):

features/upload/upload.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from binaryninja import BinaryView, log_info, log_error, log_debug, SymbolType, BinaryViewType
22
from reait.api import RE_models, RE_upload, RE_analysis_lookup, RE_analyse
3+
from revengai_bn.utils import PeriodicChecker
34
import json
45

56
class BinaryUploader:
@@ -45,7 +46,12 @@ def get_models(self, bv: BinaryView):
4546

4647
def upload_binary(self, bv: BinaryView, options: dict):
4748
try:
49+
4850
log_info(f"RevEng.AI | Uploading binary {bv.file.filename}.")
51+
log_info(f"RevEng.AI | File size: {bv.parent_view.length} bytes")
52+
if bv.parent_view.length > 10 * 1024 ** 2:
53+
log_error(f"RevEng.AI | File size is too large. Please upload a file smaller than 10MB.")
54+
return False
4955

5056
upload = RE_upload(bv.file.filename).json()
5157

@@ -57,47 +63,46 @@ def upload_binary(self, bv: BinaryView, options: dict):
5763

5864
sha_256_hash = upload["sha_256_hash"]
5965
log_info(f"RevEng.AI | SHA-256 hash: {sha_256_hash}")
60-
61-
# Convert symbols to a list of dictionaries with hex strings
62-
symbols = []
63-
log_info(f"RevEng.AI | Image Base: {bv.image_base:x}")
64-
for key, value in bv.symbols.items():
65-
if value[0].type == SymbolType.FunctionSymbol:
66-
func = bv.get_function_at(value[0].address)
67-
symbols.append({
66+
67+
symbols = {
68+
"base_addr": bv.image_base,
69+
"functions": []
70+
}
71+
72+
for func in bv.functions:
73+
symbols["functions"].append({
6874
"name": func.name,
69-
"start": func.start,
70-
"end": func.start + func.total_bytes,
71-
})
72-
log_info(f"RevEng.AI | Name: {key} | Start: {func.start:x} | End: {func.start + func.total_bytes:x} | Size: {func.total_bytes}")
73-
74-
# Log all analysis parameters
75-
log_info("RevEng.AI | Analysis parameters:")
76-
log_info(f"RevEng.AI | - File path: {bv.file.filename}")
77-
log_info(f"RevEng.AI | - Binary scope: {'PRIVATE' if options['is_private'] else 'PUBLIC'}")
78-
log_info(f"RevEng.AI | - Debug info path: {options.get('debug_info', None)}")
79-
log_info(f"RevEng.AI | - Model name: {options['model']}")
80-
log_info(f"RevEng.AI | - Tags: {options.get('tags', [])}")
81-
log_info(f"RevEng.AI | - Number of symbols: {len(symbols)}")
82-
75+
"start_addr": func.start,
76+
"end_addr": func.start + func.total_bytes,
77+
})
78+
8379
analysis = RE_analyse(
8480
fpath=bv.file.filename,
8581
binary_scope= "PRIVATE" if options["is_private"] else "PUBLIC",
8682
model_name=options["model"],
8783
tags=options["tags"],
88-
symbols=symbols
84+
debug_fpath=options["debug_info"],
85+
symbols=symbols,
86+
skip_scraping=True,
87+
skip_sbom=True,
88+
skip_capabilities=True,
89+
advanced_analysis=False
8990
).json()
9091

9192
log_info(f"RevEng.AI | Analysis response: {analysis}")
9293

93-
binary_id = analysis["binary_id"]
94-
analysis_info = RE_analysis_lookup(str(binary_id)).json()
94+
analysis_info = RE_analysis_lookup(str(analysis["binary_id"])).json()
9595

96-
log_info(f"RevEng.AI | Analysis info: {analysis_info}")
96+
log_info(f"RevEng.AI | Binary ID: {analysis['binary_id']}")
97+
log_info(f"RevEng.AI | Analysis ID: {analysis_info['analysis_id']}")
9798

98-
self.config.set_binary_id(binary_id)
99+
self.config.set_binary_id(analysis["binary_id"])
99100
self.config.set_analysis_id(analysis_info["analysis_id"])
100-
101+
102+
# Start periodic status checking
103+
checker = PeriodicChecker()
104+
checker.start_checking(bv, analysis["binary_id"])
105+
101106
return True
102107

103108
except Exception as e:

features/upload/upload_dialog.py

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from PySide6.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QLabel,
22
QComboBox, QPushButton, QRadioButton, QButtonGroup,
3-
QLineEdit, QGroupBox, QFileDialog, QProgressDialog, QMessageBox)
4-
from PySide6.QtCore import Qt
3+
QLineEdit, QGroupBox, QFileDialog, QMessageBox)
4+
from PySide6.QtCore import Qt, QCoreApplication
55
from binaryninja import log_info, log_error, log_warn
66
from .model_load_thread import ModelLoadThread
77
from .upload_binary_thread import UploadBinaryThread
8+
from revengai_bn.utils import create_progress_dialog
9+
import time
810

911
class UploadDialog(QDialog):
1012
def __init__(self, config, uploader, bv):
@@ -15,10 +17,8 @@ def __init__(self, config, uploader, bv):
1517
self.model_thread = None
1618
self.upload_thread = None
1719
self.progress = None
18-
self.load_models()
1920
self.init_ui()
2021

21-
2222
def init_ui(self):
2323
self.setWindowTitle("RevEng.AI: Process Binary")
2424
self.setMinimumWidth(500)
@@ -81,37 +81,25 @@ def init_ui(self):
8181
layout.addLayout(button_layout)
8282

8383
self.setLayout(layout)
84+
85+
# Show and process the dialog first
86+
self.show()
87+
QCoreApplication.processEvents()
88+
89+
# Now start loading models
90+
self.load_models()
8491

8592
def load_models(self):
8693
"""Start loading models in background"""
87-
# Create and show progress dialog
88-
self.progress = QProgressDialog("Loading available models...", None, 0, 0, self)
89-
self.progress.setWindowTitle("RevEng.AI")
90-
self.progress.setWindowModality(Qt.WindowModal)
91-
self.progress.setCancelButton(None)
92-
self.progress.setMinimumWidth(400)
93-
self.progress.setMinimumHeight(100)
94-
self.progress.setStyleSheet("""
95-
QProgressBar {
96-
border: 1px solid #cccccc;
97-
border-radius: 4px;
98-
text-align: center;
99-
background-color: #f0f0f0;
100-
min-width: 250px;
101-
min-height: 20px;
102-
}
103-
QProgressBar::chunk {
104-
background-color: #007bff;
105-
border-radius: 3px;
106-
}
107-
""")
94+
self.progress = create_progress_dialog(self, "RevEng.AI", "Loading available models...")
10895

10996
self.model_thread = ModelLoadThread(self.uploader, self.bv)
11097
self.model_thread.finished.connect(self._on_models_loaded)
11198
self.model_thread.error.connect(self._on_model_load_error)
11299
self.model_thread.start()
113-
100+
114101
self.progress.show()
102+
QCoreApplication.processEvents()
115103

116104
def _on_models_loaded(self, models):
117105
"""Handle successful model loading"""
@@ -144,34 +132,16 @@ def upload_binary(self):
144132
)
145133
return
146134

147-
# Create and show progress dialog
148-
self.progress = QProgressDialog("Uploading binary to RevEng.AI...", None, 0, 0, self)
149-
self.progress.setWindowTitle("RevEng.AI Upload")
150-
self.progress.setWindowModality(Qt.WindowModal)
151-
self.progress.setCancelButton(None)
152-
self.progress.setMinimumWidth(400)
153-
self.progress.setMinimumHeight(100)
154-
self.progress.setStyleSheet("""
155-
QProgressBar {
156-
border: 1px solid #cccccc;
157-
border-radius: 4px;
158-
text-align: center;
159-
background-color: #f0f0f0;
160-
min-width: 250px;
161-
min-height: 20px;
162-
}
163-
QProgressBar::chunk {
164-
background-color: #007bff;
165-
border-radius: 3px;
166-
}
167-
""")
135+
# Create and show progress dialog using utility function
136+
self.progress = create_progress_dialog(self, "RevEng.AI Upload", "Uploading binary to RevEng.AI...")
168137

169138
# Create and start upload thread
170139
self.upload_thread = UploadBinaryThread(self.uploader, self.bv, self.get_upload_options())
171140
self.upload_thread.finished.connect(self._on_upload_finished)
172141
self.upload_thread.start()
173142

174143
self.progress.show()
144+
QCoreApplication.processEvents()
175145

176146
def _on_upload_finished(self, success, error_message):
177147
"""Handle upload completion"""

0 commit comments

Comments
 (0)