-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtemplate_plugin_entry.py
63 lines (54 loc) · 2.2 KB
/
template_plugin_entry.py
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
# REPLACE_ME: with the description of the plugin you want displayed in Ghidra, and update below items
# @author YourNameHere
# @category YourCategoryHere
# @menupath Tools.MyPlugin.Replace me with short desc shown in Tools>MyPlugin menu
# REPLACE_ME: replace the command to run your plugin from Ghidra Python2 side
plugin_command = "my_library_name --run"
def create_plugin(*args, **kwargs):
# REPLACE_ME this import with an import of your plugin's create_plugin function
from my_library_name import create_plugin as _create_plugin
return _create_plugin(*args, **kwargs)
# =============================================================================
# LibBS generic plugin loader (don't touch things below this)
# =============================================================================
import sys
# Python 2 has special requirements for Ghidra, which forces us to use a different entry point
# and scope for defining plugin entry points
if sys.version[0] == "2":
# Do Ghidra Py2 entry point
import subprocess
from libbs_vendored.ghidra_bridge_server import GhidraBridgeServer
GhidraBridgeServer.run_server(background=True)
process = subprocess.Popen(plugin_command.split(" "))
if process.poll() is not None:
raise RuntimeError(
"Failed to run the Python3 backed. It's likely Python3 (and its scripts) is not in your Path inside Ghidra."
)
else:
# Try plugin discovery for other decompilers
try:
import idaapi
has_ida = True
except ImportError:
has_ida = False
try:
import angrmanagement
has_angr = True
except ImportError:
has_angr = False
if not has_ida and not has_angr:
create_plugin()
elif has_angr:
from angrmanagement.plugins import BasePlugin
class AngrBSPluginThunk(BasePlugin):
def __init__(self, workspace):
super().__init__(workspace)
globals()["workspace"] = workspace
self.plugin = create_plugin()
def teardown(self):
pass
def PLUGIN_ENTRY(*args, **kwargs):
"""
This is the entry point for IDA to load the plugin.
"""
return create_plugin(*args, **kwargs)