diff --git a/libbs/decompilers/ghidra/interface.py b/libbs/decompilers/ghidra/interface.py index f9bd99ae..7cf35021 100644 --- a/libbs/decompilers/ghidra/interface.py +++ b/libbs/decompilers/ghidra/interface.py @@ -2,6 +2,7 @@ from pathlib import Path from typing import Optional, Dict, List, Tuple import logging +import subprocess from functools import wraps from libbs.api import DecompilerInterface @@ -45,6 +46,16 @@ def __init__(self, loop_on_plugin=True, **kwargs): self.base_addr = None self.loop_on_plugin = loop_on_plugin + # connect to the remote bridge, assumes Ghidra is already running! + if self.headless: + #TODO: Generalize this for all users + subprocess.Popen(["/home/flipout/.local/bin/ghidra_10.4_PUBLIC/support/analyzeHeadless", + "/home/flipout/", "ci", + "-import", "/home/flipout/Downloads/fauxware", + "-scriptPath", "/home/flipout/ghidra_scripts/", + "-postScript", "ghidra_bridge_server.py"]) + if not self.connect_ghidra_bridge(): + raise Exception("Failed to connect to remote Ghidra Bridge. Did you start it first?") # # Controller API diff --git a/tests/tests.py b/tests/tests.py index c19e27d3..2e1a15dc 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -5,16 +5,16 @@ class TestHeadlessInterfaces(unittest.TestCase): def test_ghidra_interface(self): - # TODO: Make deci headless - deci = DecompilerInterface.discover_interface(force_decompiler="ghidra") + deci = DecompilerInterface.discover_interface(force_decompiler="ghidra", headless=True) main = deci.functions[0x400664] main.name = "main" deci.functions[0x400664] = main - assert(deci.functions[0x400664].name == "main") + assert deci.functions[0x400664].name == "main" main.stack_vars[-24].name = "input" deci.functions[0x400664] = main - assert(deci.functions[0x400664].stack_vars[-24].name == "input") + #TODO: Fix stack variables + assert deci.functions[0x400664].stack_vars[-24].name == "input" main.args[3].name = "key" deci.functions[0x400664] = main - assert(main.args[3].name == "key") + assert main.args[3].name == "key" print("under development")