Skip to content

Commit

Permalink
Search for shell command first
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed Jan 15, 2024
1 parent 1f6015d commit 0ce480b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dailalib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.2.5"
__version__ = "2.2.6"

from .api import AIAPI, OpenAIAPI
from libbs.api import DecompilerInterface
Expand Down
25 changes: 8 additions & 17 deletions dailalib/daila_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
# @menupath Tools.DAILA.Start DAILA Backend


# replace this with the command to run your plugin remotely
library_command = "dailalib -s ghidra"
# replace this imporate with an import of your plugin's create_plugin function
python_library_command = "dailalib -s ghidra"
shell_library_command = "daila -s ghidra"
def create_plugin(*args, **kwargs):
from dailalib import create_plugin as _create_plugin
return _create_plugin(*args, **kwargs)
Expand All @@ -22,22 +21,14 @@ def create_plugin(*args, **kwargs):
# Do Ghidra Py2 entry point
import subprocess
from libbs_vendored.ghidra_bridge_server import GhidraBridgeServer
full_command = "python3 -m " + library_command
from distutils.spawn import find_executable
cmd = shell_library_command.split(" ") if shell_library_command else python_library_command.split(" ")
if not find_executable(cmd[0]):
# fallback to doing a python command
cmd = python_library_command.split(" ")

GhidraBridgeServer.run_server(background=True)

failed_py3 = False
try:
process = subprocess.Popen(full_command.split(" "))
failed_py3 = process.poll() is not None
except:
failed_py3 = True

if failed_py3:
print("python3 command failed. Trying python...")
full_command = full_command.replace("python3", "python")
process = subprocess.Popen(full_command.split(" "))

process = subprocess.Popen(cmd)
if process.poll() is not None:
raise RuntimeError(
"Failed to run the Python3 backed. It's likely Python3 is not in your Path inside Ghidra.")
Expand Down

0 comments on commit 0ce480b

Please sign in to comment.