-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path__init__.py
More file actions
109 lines (87 loc) · 3.54 KB
/
__init__.py
File metadata and controls
109 lines (87 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""
Shellcode IDE plugin entrypoint for Binary Ninja.
Registers a UI action and opens a PySide2 window that provides:
- Hex/bytes and Assembly editors
- Assemble/Disassemble actions via BN API (when available)
- Basic byte statistics and multi-format export preview
Note: This plugin is designed to run inside Binary Ninja where the Python
environment includes PySide2 and the `binaryninja` API. When imported outside
BN, the module will not auto-run; you can still import and instantiate the
window for UI development if PySide2 is available.
"""
from __future__ import annotations
import sys
from typing import Optional
def _in_binary_ninja() -> bool:
try:
import binaryninja # noqa: F401
return True
except Exception:
return False
def _register_bn_actions():
"""Register UI actions and a Tools menu entry in Binary Ninja.
This avoids hard dependency at import-time when developing outside BN.
"""
try:
import binaryninja as bn
# PluginCommand is no longer used for opening the window to avoid a disabled Plugins item
from binaryninjaui import UIAction, Menu, UIActionHandler
except Exception:
# Not running in BN UI, nothing to register
return
def open_window(_context):
from .ui.main_window import ShellcodeIDEWindow
# Create and show a top-level window. BN bundles the Qt app instance.
win = ShellcodeIDEWindow(parent=None, bn_api=bn)
win.show()
# Validator to keep the action always enabled regardless of context
def always_enabled(_context) -> bool:
return True
# Register a global UI action so it appears in the Command Palette
action_name = "Shellcode IDE"
UIAction.registerAction(action_name)
# Bind using a UIAction wrapper; BN expects a UIAction instance, not a raw function
UIActionHandler.globalActions().bindAction(action_name, UIAction(open_window, always_enabled))
# Add the action to the Plugins menu so it is always clickable
try:
# Preferred: add under Plugins -> Shellcode IDE
Menu.mainMenu("Plugins").addAction(action_name, action_name)
except Exception:
try:
# Fallback signatures for older BN builds
Menu.mainMenu("Plugins").addAction(action_name)
except Exception:
try:
# Last-resort path notation
Menu().addAction(f"Plugins\\{action_name}", action_name)
except Exception:
pass
# Do not add under Tools per user request; Plugins menu entry above is sufficient
def launch_standalone():
"""Launch the Shellcode IDE in standalone mode if PySide2 is available.
This is primarily for UI development outside of Binary Ninja.
"""
# Try PySide2 then PySide6 for standalone
app_mod = None
try:
from PySide2.QtWidgets import QApplication # type: ignore
app_mod = "PySide2"
except Exception:
try:
from PySide6.QtWidgets import QApplication # type: ignore
app_mod = "PySide6"
except Exception as exc:
print("[Shellcode IDE] PySide2/PySide6 is required for standalone launch:", exc)
sys.exit(1)
from .ui.main_window import ShellcodeIDEWindow
app = QApplication.instance() or QApplication(sys.argv)
win = ShellcodeIDEWindow(parent=None, bn_api=None)
win.show()
try:
rc = app.exec()
except Exception:
rc = app.exec_()
sys.exit(rc)
# Register with BN when imported inside its runtime
if _in_binary_ninja():
_register_bn_actions()