Package rubydragon

Class GhidraInterpreter

java.lang.Object
rubydragon.GhidraInterpreter
All Implemented Interfaces:
ghidra.util.Disposable
Direct Known Subclasses:
JShellGhidraInterpreter, ScriptableGhidraInterpreter

public abstract class GhidraInterpreter extends Object implements ghidra.util.Disposable
An interpreter that users can use interactively. This class provides a common base that all interpreters should implement in order to fit in to the overall system. It provides a common wrapper around the language-specific internals of a given language environment. Interpreters that also support scripts should inherit from ScriptableGhidraInterpreter instead.
  • Constructor Details

    • GhidraInterpreter

      public GhidraInterpreter()
  • Method Details

    • autoImportClasses

      public void autoImportClasses(PrintWriter output, PrintWriter errOut)
      Imports all of the classes listed in the auto import list by calling importClass for each one.
      Parameters:
      output - An output writer to write progress to.
      errOut - An output writer for errors to be written to.
      Since:
      3.1.0
    • dispose

      public abstract void dispose()
      Cleans up all resources for this interpreter.
      Specified by:
      dispose in interface ghidra.util.Disposable
    • getCompletions

      public abstract List<ghidra.app.plugin.core.console.CodeCompletion> getCompletions(String cmd)
      Get a list of completions for the given command prefix.
      Parameters:
      cmd - The command to try to complete.
      Returns:
      A list of possible code completions.
    • getCurrentAddressName

      public String getCurrentAddressName()
      The default name for the current address variable.
      Returns:
      The default name for the current address variable.
      Since:
      3.1.0
    • getCurrentAPIName

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

      public String getCurrentHighlightName()
      The default name for the current highlight variable.
      Returns:
      The default name for the current highlight variable.
      Since:
      3.1.0
    • getCurrentLocationName

      public String getCurrentLocationName()
      The default name for the current location variable.
      Returns:
      The default name for the current location variable.
      Since:
      3.1.0
    • getCurrentProgramName

      public String getCurrentProgramName()
      The default name for the current program variable.
      Returns:
      The default name for the current program variable.
      Since:
      3.1.0
    • getCurrentSelectionName

      public String getCurrentSelectionName()
      The default name for the current selection variable.
      Returns:
      The default name for the current selection variable.
      Since:
      3.1.0
    • getParentPlugin

      public abstract DragonPlugin getParentPlugin()
      The DragonPlugin that this interpreter is attached to.
      Returns:
      The owning plugin of this interpreter.
      Since:
      3.1.0
    • getVersion

      public abstract String getVersion()
      Get the version of this interpreter.
      Returns:
      A string with the language and version of the interpreter.
      Since:
      3.1.0
    • importClass

      public abstract void importClass(String packageName, String className)
      Imports a given class into the interpreter.
      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 abstract void initInteractiveInterpreter()
      Initializes the internal interpreter used for interactive sessions. This method is intended to be the actual creation of the interpreter, which is expected to be a slow operation.
      Since:
      3.1.0
    • initInteractiveInterpreterWithProgress

      public void initInteractiveInterpreterWithProgress(PrintWriter output, PrintWriter errOut)
      Initializes an interactive interpreter, measuring time and printing progress along the way. This function will first call initInteractiveInterpreter, followed by autoImportClasses. Subclasses can use this method to set up interactive sessions, as long as they have implemented initInteractiveInterpreter and importClass. If more control is needed over the auto-import process, then the autoImportClasses method can be overridden to customize this functionality. Assuming the correction methods are implemented, then this method can be called during startInteractiveSession, for example in a new thread dedicated to the interpreter.
      Parameters:
      output - An output writer to write progress to.
      errOut - An output writer for errors to be written to.
      Since:
      3.1.0
    • setErrWriter

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

      public abstract void setInput(InputStream input)
      Sets the input stream for this interpreter.
      Parameters:
      input - The new input stream to use for the interpreter.
    • setOutWriter

      public abstract void setOutWriter(PrintWriter output)
      Sets the output stream for this interpreter.
      Parameters:
      output - The new output stream to use for the interpreter.
    • setStreams

      public void setStreams(ghidra.app.plugin.core.interpreter.InterpreterConsole console)
      Sets the input, output, and error streams for this interpreter to those of the provided console.
      Parameters:
      console - The console to tie the interpreter streams to.
    • setVariable

      public abstract void setVariable(String name, Object value)
      Adds or updates the variable with the given name to the given value in the interpreter.
      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 abstract void startInteractiveSession()
      Starts an interactive session with the current input/output/error streams.
    • updateAddress

      public void updateAddress(ghidra.program.model.address.Address address)
      Updates the current address in the interpreter.
      Parameters:
      address - The new current address in the program.
    • updateHighlight

      public void updateHighlight(ghidra.program.util.ProgramSelection sel)
      Updates the highlighted selection pointed to by the current_highlight variable.
      Parameters:
      sel - The new highlighted selection.
    • updateLocation

      public void updateLocation(ghidra.program.util.ProgramLocation loc)
      Updates the location in the current location variable as well as the address in the current address variable.
      Parameters:
      loc - The new location in the program.
    • updateProgram

      public void updateProgram(ghidra.program.model.listing.Program program)
      Updates the current program in current program to the one provided.
      Parameters:
      program - The new current program.
    • updateSelection

      public void updateSelection(ghidra.program.util.ProgramSelection sel)
      Updates the selection pointed to by the current selection variable.
      Parameters:
      sel - The new selection.