Package com.goatshriek.rubydragon.ruby
Class RubyGhidraInterpreter
java.lang.Object
com.goatshriek.rubydragon.GhidraInterpreter
com.goatshriek.rubydragon.ScriptableGhidraInterpreter
com.goatshriek.rubydragon.ruby.RubyGhidraInterpreter
- All Implemented Interfaces:
ghidra.util.Disposable
A Ruby interpreter for Ghidra, built using JRuby.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new Ruby interpreter.RubyGhidraInterpreter(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. -
Method Summary
Modifier and TypeMethodDescriptionvoidSets up method proxies at the top level to mirror $script or $current_api methods, as jython does.voiddispose()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 name for the current address variable.The name for the current FlatProgramAPI variable.The name for the current data variable.The name for the current function variable.The name for the current highlight variable.The name for the current data variable.The name for the current location variable.The name for the current program variable.The name for the current selection variable.The DragonPlugin that this interpreter is attached to.Get the version of Ruby this interpreter supports.voidimportClass(String packageName, String className) Imports a given class into the Ruby environment.voidCreates a new Ruby interpreter, sets up the automatic variables, and adds proxies into the namespace for the current Program methods.voidrunScript(ghidra.app.script.GhidraScript script, String[] scriptArguments, ghidra.app.script.GhidraState scriptState) Runs the given script with the arguments and state provided.voidsetErrWriter(PrintWriter errOut) Sets the error output stream for this interpreter.voidsetInput(InputStream input) Sets the input stream for this interpreter.voidsetOutWriter(PrintWriter output) Sets the output stream for this interpreter.voidsetVariable(String name, Object value) Adds or updates the variable with the given name to the given value in the scripting container.voidStarts an interactive session with the current input/output/error streams.voidupdateProgram(ghidra.program.model.listing.Program program) Updates the current program in "$current_program" to the one provided, as well as the "$current_api" variable holding a flat api instance.voidupdateState(ghidra.app.script.GhidraState scriptState) Updates a state with the $current_*.Methods inherited from class com.goatshriek.rubydragon.ScriptableGhidraInterpreter
loadStateMethods inherited from class com.goatshriek.rubydragon.GhidraInterpreter
autoImportClasses, initInteractiveInterpreterWithProgress, setStreams, updateAddress, updateHighlight, updateLocation, updateSelection
-
Constructor Details
-
RubyGhidraInterpreter
public RubyGhidraInterpreter()Creates a new Ruby interpreter. -
RubyGhidraInterpreter
public RubyGhidraInterpreter(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 plugin that manages this interpreter.
-
-
Method Details
-
createProxies
public void createProxies()Sets up method proxies at the top level to mirror $script or $current_api methods, as jython does. -
dispose
public void dispose()Should end the interpreter and release all resources. Currently does nothing.- Specified by:
disposein interfaceghidra.util.Disposable- Specified by:
disposein classGhidraInterpreter
-
getCompletions
Get a list of completions for the given command prefix. Currently not implemented, and will always return an empty list.- Specified by:
getCompletionsin classGhidraInterpreter- Parameters:
cmd- The beginning of a command to try to complete.- Returns:
- A list of possible code completions.
-
getCurrentAddressName
The name for the current address variable.- Overrides:
getCurrentAddressNamein classGhidraInterpreter- Returns:
- The name for the current address variable.
- Since:
- 3.1.0
-
getCurrentAPIName
The name for the current FlatProgramAPI variable.- Overrides:
getCurrentAPINamein classGhidraInterpreter- Returns:
- The name for the current API variable.
- Since:
- 3.1.0
-
getCurrentDataName
The name for the current data variable.- Overrides:
getCurrentDataNamein classGhidraInterpreter- Returns:
- The name for the current data variable.
- Since:
- 4.0.0
-
getCurrentFunctionName
The name for the current function variable.- Overrides:
getCurrentFunctionNamein classGhidraInterpreter- Returns:
- The name for the current function variable.
- Since:
- 4.0.0
-
getCurrentHighlightName
The name for the current highlight variable.- Overrides:
getCurrentHighlightNamein classGhidraInterpreter- Returns:
- The name for the current highlight variable.
- Since:
- 3.1.0
-
getCurrentInstructionName
The name for the current data variable.- Overrides:
getCurrentInstructionNamein classGhidraInterpreter- Returns:
- The name for the current data variable.
- Since:
- 4.0.0
-
getCurrentLocationName
The name for the current location variable.- Overrides:
getCurrentLocationNamein classGhidraInterpreter- Returns:
- The name for the current location variable.
- Since:
- 3.1.0
-
getCurrentProgramName
The name for the current program variable.- Overrides:
getCurrentProgramNamein classGhidraInterpreter- Returns:
- The name for the current program variable.
- Since:
- 3.1.0
-
getCurrentSelectionName
The name for the current selection variable.- Overrides:
getCurrentSelectionNamein classGhidraInterpreter- Returns:
- The name for the current selection variable.
- Since:
- 3.1.0
-
getParentPlugin
The DragonPlugin that this interpreter is attached to.- Specified by:
getParentPluginin classGhidraInterpreter- Returns:
- The owning plugin of this interpreter.
- Since:
- 3.1.0
-
getVersion
Get the version of Ruby this interpreter supports.- Specified by:
getVersionin classGhidraInterpreter- Returns:
- A string with the version of the interpreter.
- Since:
- 3.1.0
-
initInteractiveInterpreter
public void initInteractiveInterpreter()Creates a new Ruby interpreter, sets up the automatic variables, and adds proxies into the namespace for the current Program methods.- Specified by:
initInteractiveInterpreterin classGhidraInterpreter- Since:
- 3.1.0
-
importClass
Imports a given class into the Ruby environment.- Specified by:
importClassin classGhidraInterpreter- Parameters:
packageName- The name of the package the class is in.className- The name of the class to import.- 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.- Specified by:
runScriptin 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:
setErrWriterin classGhidraInterpreter- Parameters:
errOut- The new error output stream to use for the interpreter.
-
setInput
Sets the input stream for this interpreter.- Specified by:
setInputin classGhidraInterpreter- Parameters:
input- The new input stream to use for the interpreter.
-
setOutWriter
Sets the output stream for this interpreter.- Specified by:
setOutWriterin 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 scripting container.- Specified by:
setVariablein classGhidraInterpreter- Parameters:
name- The name of the variable to create or update.value- The value of the variable to add.
-
startInteractiveSession
public void startInteractiveSession()Starts an interactive session with the current input/output/error streams.- Specified by:
startInteractiveSessionin classGhidraInterpreter
-
updateProgram
public void updateProgram(ghidra.program.model.listing.Program program) Updates the current program in "$current_program" to the one provided, as well as the "$current_api" variable holding a flat api instance.- Overrides:
updateProgramin classGhidraInterpreter- Parameters:
program- The new current program.
-
updateState
public void updateState(ghidra.app.script.GhidraState scriptState) Updates a state with the $current_*. variables from the interpreter.- Specified by:
updateStatein classScriptableGhidraInterpreter- Parameters:
scriptState- The state to update.
-