Skip to content

Commit

Permalink
Partial headless functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Flipout50 authored and mahaloz committed Dec 6, 2023
1 parent 58a9634 commit 8e1526f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 11 additions & 0 deletions libbs/decompilers/ghidra/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 8e1526f

Please sign in to comment.