Class ClojureGhidraInterpreter

All Implemented Interfaces:
ghidra.util.Disposable

public class ClojureGhidraInterpreter extends ScriptableGhidraInterpreter
A Clojure interpreter for Ghidra.
  • Constructor Details

    • ClojureGhidraInterpreter

      public ClojureGhidraInterpreter()
      Creates a new Clojure interpreter.
    • ClojureGhidraInterpreter

      public ClojureGhidraInterpreter(ghidra.app.plugin.core.interpreter.InterpreterConsole console, DragonPlugin plugin)
      Creates a new interpreter, and ties the streams for the provided console to the new interpreter.
      Parameters:
      console - The console to bind to the interpreter streams.
      parentPlugin - The DragonPlugin instance owning this interpreter.
  • Method Details

    • dispose

      public void dispose()
      Should end the interpreter and release all resources. Currently does nothing. Unfortunately, Clojure kills the entire process when the interactive session is ended. Since this kills Ghidra completely rather than just disabling the plugin, we elect to do nothing here and wait for a restart to kill this thread. This is also the reason that the console is not destroyed in ClojureDragonPlugin.dispose().
      Specified by:
      dispose in interface ghidra.util.Disposable
      Specified by:
      dispose in class GhidraInterpreter
    • getCompletions

      public List<ghidra.app.plugin.core.console.CodeCompletion> getCompletions(String cmd)
      Get a list of completions for the given command prefix. Currently not implemented, and will always return an empty list.
      Specified by:
      getCompletions in class GhidraInterpreter
      Parameters:
      cmd - The beginning of a command to try to complete.
      Returns:
      A list of possible code completions.
    • getCurrentAddressName

      public String getCurrentAddressName()
      The name for the current address variable.
      Overrides:
      getCurrentAddressName in class GhidraInterpreter
      Returns:
      The name for the current address variable.
      Since:
      3.1.0
    • getCurrentAPIName

      public String getCurrentAPIName()
      The name for the current FlatProgramAPI variable.
      Overrides:
      getCurrentAPIName in class GhidraInterpreter
      Returns:
      The name for the current API variable.
      Since:
      3.1.0
    • getCurrentHighlightName

      public String getCurrentHighlightName()
      The name for the current highlight variable.
      Overrides:
      getCurrentHighlightName in class GhidraInterpreter
      Returns:
      The name for the current highlight variable.
      Since:
      3.1.0
    • getCurrentLocationName

      public String getCurrentLocationName()
      The name for the current location variable.
      Overrides:
      getCurrentLocationName in class GhidraInterpreter
      Returns:
      The name for the current location variable.
      Since:
      3.1.0
    • getCurrentProgramName

      public String getCurrentProgramName()
      The name for the current program variable.
      Overrides:
      getCurrentProgramName in class GhidraInterpreter
      Returns:
      The name for the current program variable.
      Since:
      3.1.0
    • getCurrentSelectionName

      public String getCurrentSelectionName()
      The name for the current selection variable.
      Overrides:
      getCurrentSelectionName in class GhidraInterpreter
      Returns:
      The name for the current selection variable.
      Since:
      3.1.0
    • getParentPlugin

      public DragonPlugin getParentPlugin()
      The DragonPlugin that this interpreter is attached to.
      Specified by:
      getParentPlugin in class GhidraInterpreter
      Returns:
      The owning plugin of this interpreter.
      Since:
      3.1.0
    • getVersion

      public String getVersion()
      Get the version of Clojure this interpreter supports.
      Specified by:
      getVersion in class GhidraInterpreter
      Returns:
      A string with the version of the interpreter.
      Since:
      3.1.0
    • importClass

      public void importClass(String packageName, String className)
      Imports a given class into the interpreter.
      Specified by:
      importClass in class GhidraInterpreter
      Parameters:
      packageName - The name of the package the class is in.
      className - The name of the class to import.
      Since:
      3.1.0
    • initInteractiveInterpreter

      public void initInteractiveInterpreter()
      Sets up the Clojure environment, and auto loads classes if enabled.
      Specified by:
      initInteractiveInterpreter in class GhidraInterpreter
      Since:
      3.1.0
    • runScript

      public void runScript(ghidra.app.script.GhidraScript script, String[] scriptArguments, ghidra.app.script.GhidraState scriptState) throws IllegalArgumentException, FileNotFoundException, IOException
      Runs the given script with the arguments and state provided. The provided state is loaded into the interpreter at the beginning of execution, and the values of the globals are then exported back into the state after it completes. If the script cannot be found but the script is not running in headless mode, the user will be prompted to ignore the error, which will cause the function to simply continue instead of throwing an IllegalArgumentException. Public and protected fields and public methods are bound into the ghidra namespace before the script itself is run. A "ghidra/script" binding is also created, bound to this ClojureScript instance (via "this").
      Specified by:
      runScript in class ScriptableGhidraInterpreter
      Parameters:
      script - The script to run.
      scriptArguments - The arguments to pass to the script.
      scriptState - The script to load before the script runs, and update after the script finishes.
      Throws:
      IllegalArgumentException - if the script does not exist
      IOException - if the script could not be read
      FileNotFoundException - if the script file wasn't found
    • setErrWriter

      public void setErrWriter(PrintWriter errOut)
      Sets the error output stream for this interpreter.
      Specified by:
      setErrWriter in class GhidraInterpreter
      Parameters:
      errOut - The new error output stream to use for the interpreter.
    • setInput

      public void setInput(InputStream input)
      Sets the input stream for this interpreter.
      Specified by:
      setInput in class GhidraInterpreter
      Parameters:
      input - The new input stream to use for the interpreter.
    • setOutWriter

      public void setOutWriter(PrintWriter output)
      Sets the output stream for this interpreter.
      Specified by:
      setOutWriter in class GhidraInterpreter
      Parameters:
      output - The new output stream to use for the interpreter.
    • setVariable

      public void setVariable(String name, Object value)
      Adds or updates the variable with the given name to the given value in the scripting container.
      Specified by:
      setVariable in class GhidraInterpreter
      Parameters:
      name - The name of the variable to create or update.
      value - The value of the variable to add.
      Since:
      3.1.0
    • startInteractiveSession

      public void startInteractiveSession()
      Starts an interactive session with the current input/output/error streams.
      Specified by:
      startInteractiveSession in class GhidraInterpreter
    • updateState

      public void updateState(ghidra.app.script.GhidraState scriptState)
      Updates a state with the current selection/location/etc. variables from the interpreter.
      Specified by:
      updateState in class ScriptableGhidraInterpreter
      Parameters:
      scriptState - The state to update.