Package rubydragon
Class GhidraInterpreter
java.lang.Object
rubydragon.GhidraInterpreter
- All Implemented Interfaces:
ghidra.util.Disposable
- Direct Known Subclasses:
JShellGhidraInterpreter
,ScriptableGhidraInterpreter
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
autoImportClasses
(PrintWriter output, PrintWriter errOut) Imports all of the classes listed in the auto import list by calling importClass for each one.abstract void
dispose()
Cleans up all resources for this interpreter.abstract List<ghidra.app.plugin.core.console.CodeCompletion>
getCompletions
(String cmd) Get a list of completions for the given command prefix.The default name for the current address variable.The default name for the current FlatProgramAPI variable.The default name for the current highlight variable.The default name for the current location variable.The default name for the current program variable.The default name for the current selection variable.abstract DragonPlugin
The DragonPlugin that this interpreter is attached to.abstract String
Get the version of this interpreter.abstract void
importClass
(String packageName, String className) Imports a given class into the interpreter.abstract void
Initializes the internal interpreter used for interactive sessions.void
initInteractiveInterpreterWithProgress
(PrintWriter output, PrintWriter errOut) Initializes an interactive interpreter, measuring time and printing progress along the way.abstract void
setErrWriter
(PrintWriter errOut) Sets the error output stream for this interpreter.abstract void
setInput
(InputStream input) Sets the input stream for this interpreter.abstract void
setOutWriter
(PrintWriter output) Sets the output stream for this interpreter.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.abstract void
setVariable
(String name, Object value) Adds or updates the variable with the given name to the given value in the interpreter.abstract void
Starts an interactive session with the current input/output/error streams.void
updateAddress
(ghidra.program.model.address.Address address) Updates the current address in the interpreter.void
updateHighlight
(ghidra.program.util.ProgramSelection sel) Updates the highlighted selection pointed to by the current_highlight variable.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.void
updateProgram
(ghidra.program.model.listing.Program program) Updates the current program in current program to the one provided.void
updateSelection
(ghidra.program.util.ProgramSelection sel) Updates the selection pointed to by the current selection variable.
-
Constructor Details
-
GhidraInterpreter
public GhidraInterpreter()
-
-
Method Details
-
autoImportClasses
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 interfaceghidra.util.Disposable
-
getCompletions
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
The default name for the current address variable.- Returns:
- The default name for the current address variable.
- Since:
- 3.1.0
-
getCurrentAPIName
The default name for the current FlatProgramAPI variable.- Returns:
- The default name for the current API variable.
- Since:
- 3.1.0
-
getCurrentHighlightName
The default name for the current highlight variable.- Returns:
- The default name for the current highlight variable.
- Since:
- 3.1.0
-
getCurrentLocationName
The default name for the current location variable.- Returns:
- The default name for the current location variable.
- Since:
- 3.1.0
-
getCurrentProgramName
The default name for the current program variable.- Returns:
- The default name for the current program variable.
- Since:
- 3.1.0
-
getCurrentSelectionName
The default name for the current selection variable.- Returns:
- The default name for the current selection variable.
- Since:
- 3.1.0
-
getParentPlugin
The DragonPlugin that this interpreter is attached to.- Returns:
- The owning plugin of this interpreter.
- Since:
- 3.1.0
-
getVersion
Get the version of this interpreter.- Returns:
- A string with the language and version of the interpreter.
- Since:
- 3.1.0
-
importClass
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
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
Sets the error output stream for this interpreter.- Parameters:
errOut
- The new error output stream to use for the interpreter.
-
setInput
Sets the input stream for this interpreter.- Parameters:
input
- The new input stream to use for the interpreter.
-
setOutWriter
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
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.
-