|
2 | 2 | # @author mahaloz |
3 | 3 | # @category AI |
4 | 4 | # @menupath Tools.DAILA.Start DAILA Backend |
| 5 | +# @runtime PyGhidra |
5 | 6 |
|
6 | 7 |
|
7 | | -python_library_command = "dailalib -s ghidra" |
8 | | -shell_library_command = "daila -s ghidra" |
9 | 8 | def create_plugin(*args, **kwargs): |
10 | 9 | from dailalib import create_plugin as _create_plugin |
11 | 10 | return _create_plugin(*args, **kwargs) |
12 | 11 |
|
13 | | -# ============================================================================= |
14 | | -# LibBS generic plugin loader (don't touch) |
15 | | -# ============================================================================= |
16 | | - |
17 | | -import sys |
18 | | -# Python 2 has special requirements for Ghidra, which forces us to use a different entry point |
19 | | -# and scope for defining plugin entry points |
20 | | -if sys.version[0] == "2": |
21 | | - # Do Ghidra Py2 entry point |
22 | | - import subprocess |
23 | | - from libbs_vendored.ghidra_bridge_server import GhidraBridgeServer |
24 | | - from distutils.spawn import find_executable |
25 | | - cmd = shell_library_command.split(" ") |
26 | | - if not find_executable(cmd[0]): |
27 | | - # fallback to doing python style module call |
28 | | - python_end = ["-m"] + python_library_command.split(" ") |
29 | | - python_exec = "python" if find_executable("python") else "python3" |
30 | | - cmd = [python_exec] + python_end |
31 | | - |
32 | | - GhidraBridgeServer.run_server(background=True) |
33 | | - print("[+] Starting the backend now...") |
34 | | - try: |
35 | | - process = subprocess.Popen(cmd) |
36 | | - except Exception as e: |
37 | | - print("[!] Failed to run the backend command", cmd, "because", e) |
38 | | - |
39 | | - if process.poll() is not None: |
40 | | - raise RuntimeError( |
41 | | - "Failed to run the Python3 backed. It's likely Python3 is not in your Path inside Ghidra.") |
42 | | -else: |
43 | | - # Try plugin discovery for other decompilers |
44 | | - try: |
45 | | - import idaapi |
46 | | - has_ida = True |
47 | | - except ImportError: |
48 | | - has_ida = False |
49 | | - try: |
50 | | - import angrmanagement |
51 | | - has_angr = True |
52 | | - except ImportError: |
53 | | - has_angr = False |
54 | | - |
55 | | - if not has_ida and not has_angr: |
56 | | - create_plugin() |
57 | | - elif has_angr: |
58 | | - from angrmanagement.plugins import BasePlugin |
59 | | - class AngrBSPluginThunk(BasePlugin): |
60 | | - def __init__(self, workspace): |
61 | | - super().__init__(workspace) |
62 | | - globals()["workspace"] = workspace |
63 | | - self.plugin = create_plugin() |
64 | | - |
65 | | - def teardown(self): |
66 | | - pass |
| 12 | +try: |
| 13 | + import idaapi |
| 14 | + has_ida = True |
| 15 | +except ImportError: |
| 16 | + has_ida = False |
| 17 | +try: |
| 18 | + import angrmanagement |
| 19 | + has_angr = True |
| 20 | +except ImportError: |
| 21 | + has_angr = False |
| 22 | +try: |
| 23 | + import ghidra |
| 24 | + has_ghidra = True |
| 25 | +except ImportError: |
| 26 | + has_ghidra = False |
| 27 | +try: |
| 28 | + import binaryninja |
| 29 | + has_binja = True |
| 30 | +except ImportError: |
| 31 | + has_binja = False |
| 32 | + |
| 33 | + |
| 34 | +if has_ghidra or has_binja: |
| 35 | + create_plugin() |
| 36 | +elif has_angr: |
| 37 | + from angrmanagement.plugins import BasePlugin |
| 38 | + class AngrBSPluginThunk(BasePlugin): |
| 39 | + def __init__(self, workspace): |
| 40 | + super().__init__(workspace) |
| 41 | + globals()["workspace"] = workspace |
| 42 | + self.plugin = create_plugin() |
| 43 | + |
| 44 | + def teardown(self): |
| 45 | + pass |
| 46 | +elif has_ida: |
| 47 | + # IDA will call create_plugin automatically |
| 48 | + pass |
67 | 49 |
|
68 | 50 |
|
69 | 51 | def PLUGIN_ENTRY(*args, **kwargs): |
|
0 commit comments