Package rubydragon.groovy
Class GroovyGhidraInterpreter
java.lang.Object
rubydragon.GhidraInterpreter
rubydragon.ScriptableGhidraInterpreter
rubydragon.groovy.GroovyGhidraInterpreter
- All Implemented Interfaces:
ghidra.util.Disposable
A Groovy interpreter for Ghidra.
-
Constructor Summary
ConstructorDescriptionCreates a new Groovy interpreter.GroovyGhidraInterpreter
(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.GroovyGhidraInterpreter
(InputStream in, OutputStream out, OutputStream err, DragonPlugin plugin) Creates a new interpreter, and ties the given streams to the new interpreter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
autoImportClasses
(PrintWriter output, PrintWriter errOut) Does nothing, as automatic imports are handled in initInteractiveInterpreter more efficiently.void
dispose()
Should end the interpreter and release all resources.List<ghidra.app.plugin.core.console.CodeCompletion>
getCompletions
(String cmd) Get a list of completions for the given command prefix.The DragonPlugin that this interpreter is attached to.Get the version of Groovy this interpreter supports.void
importClass
(String packageName, String className) Does nothing, as automatic imports are handled in initInteractiveInterpreter more efficiently.void
Creates a new Groovy interpreter for interactive sessions.void
loadState
(ghidra.app.script.GhidraState state) Loads a provided GhidraState into the script interpreter.void
reset()
Resets this interpreter.void
runScript
(ghidra.app.script.GhidraScript script, String[] scriptArguments, ghidra.app.script.GhidraState scriptState) Runs the given script with the arguments and state provided.void
setErrWriter
(PrintWriter errOut) Sets the error output stream for this interpreter.void
setInput
(InputStream input) Sets the input stream for this interpreter.void
setOutWriter
(PrintWriter output) Sets the output stream for this interpreter.void
setVariable
(String name, Object value) Adds or updates the variable with the given name to the given value in the current engine.void
Starts an interactive session with the current input/output/error streams.void
updateState
(ghidra.app.script.GhidraState scriptState) Updates a state with the current selection/location/etc.Methods inherited from class rubydragon.GhidraInterpreter
getCurrentAddressName, getCurrentAPIName, getCurrentHighlightName, getCurrentLocationName, getCurrentProgramName, getCurrentSelectionName, initInteractiveInterpreterWithProgress, setStreams, updateAddress, updateHighlight, updateLocation, updateProgram, updateSelection
-
Constructor Details
-
GroovyGhidraInterpreter
public GroovyGhidraInterpreter()Creates a new Groovy interpreter. -
GroovyGhidraInterpreter
public GroovyGhidraInterpreter(InputStream in, OutputStream out, OutputStream err, DragonPlugin plugin) Creates a new interpreter, and ties the given streams to the new interpreter.- Parameters:
in
- The input stream to use for the interpeter.out
- The output stream to use for the interpreter.err
- The error stream to use for the interpreter.
-
GroovyGhidraInterpreter
public GroovyGhidraInterpreter(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.plugin
- The DragonPlugin instance owning this interpreter.
-
-
Method Details
-
autoImportClasses
Does nothing, as automatic imports are handled in initInteractiveInterpreter more efficiently. This function is overridden so that the default implementation is not used.- Overrides:
autoImportClasses
in classGhidraInterpreter
- Parameters:
output
- An output writer to write progress to.errOut
- An output writer for errors to be written to.- Since:
- 3.1.0
-
initInteractiveInterpreter
public void initInteractiveInterpreter()Creates a new Groovy interpreter for interactive sessions.- Specified by:
initInteractiveInterpreter
in classGhidraInterpreter
- Since:
- 3.1.0
-
dispose
public void dispose()Should end the interpreter and release all resources.- Specified by:
dispose
in interfaceghidra.util.Disposable
- Specified by:
dispose
in classGhidraInterpreter
-
getCompletions
Get a list of completions for the given command prefix. Currently not implemented, and will always return an empty list.- Specified by:
getCompletions
in classGhidraInterpreter
- Parameters:
cmd
- The beginning of a command to try to complete.- Returns:
- A list of possible code completions.
-
getParentPlugin
The DragonPlugin that this interpreter is attached to.- Specified by:
getParentPlugin
in classGhidraInterpreter
- Returns:
- The owning plugin of this interpreter.
- Since:
- 3.1.0
-
getVersion
Get the version of Groovy this interpreter supports.- Specified by:
getVersion
in classGhidraInterpreter
- Returns:
- A string with the version of the interpreter.
- Since:
- 3.1.0
-
importClass
Does nothing, as automatic imports are handled in initInteractiveInterpreter more efficiently. This function is overridden so that the default implementation is not used.- Specified by:
importClass
in classGhidraInterpreter
- Parameters:
packageName
- The name of the package the class is in.className
- The name of the class to import.- Since:
- 3.1.0
-
loadState
public void loadState(ghidra.app.script.GhidraState state) Loads a provided GhidraState into the script interpreter.- Overrides:
loadState
in classScriptableGhidraInterpreter
- Parameters:
state
- The state to load.
-
reset
public void reset()Resets this interpreter. -
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.- Specified by:
runScript
in classScriptableGhidraInterpreter
- 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 existIOException
- if the script could not be readFileNotFoundException
- if the script file wasn't found
-
setErrWriter
Sets the error output stream for this interpreter.- Specified by:
setErrWriter
in classGhidraInterpreter
- Parameters:
errOut
- The new error output stream to use for the interpreter.
-
setInput
Sets the input stream for this interpreter.- Specified by:
setInput
in classGhidraInterpreter
- Parameters:
input
- The new input stream to use for the interpreter.
-
setOutWriter
Sets the output stream for this interpreter.- Specified by:
setOutWriter
in classGhidraInterpreter
- Parameters:
output
- The new output stream to use for the interpreter.
-
setVariable
Adds or updates the variable with the given name to the given value in the current engine.- Specified by:
setVariable
in classGhidraInterpreter
- 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 classGhidraInterpreter
-
updateState
public void updateState(ghidra.app.script.GhidraState scriptState) Updates a state with the current selection/location/etc. variables from the script interpreter.- Specified by:
updateState
in classScriptableGhidraInterpreter
- Parameters:
scriptState
- The state to update.
-