Package rubydragon.jshell
Class JShellGhidraInterpreter
java.lang.Object
rubydragon.GhidraInterpreter
rubydragon.jshell.JShellGhidraInterpreter
- All Implemented Interfaces:
ghidra.util.Disposable
A Java interpreter for Ghidra, based on JShell.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionJShellGhidraInterpreter
(ghidra.app.plugin.core.interpreter.InterpreterConsole console, DragonPlugin parentPlugin) Creates a new interpreter, and ties the streams for the provided console to the new interpreter.JShellGhidraInterpreter
(InputStream in, OutputStream out, OutputStream err, DragonPlugin parentPlugin) Creates a new interpreter, and ties the given streams to the new interpreter. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 Java this JShell supports.void
importClass
(String packageName, String className) Imports a given class into the interpreter.void
Creates a new JShell interpreter, and declares the internal variables.void
Interrupts this interpreter.void
reset()
Resets this interpreter.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 interpreter.void
Starts an interactive session with the current input/output/error streams.void
updateAddress
(ghidra.program.model.address.Address address) Updates the current address pointed to by the "currentAddress" binding in the interpreter.void
updateHighlight
(ghidra.program.util.ProgramSelection sel) Updates the highlighted selection pointed to by the "currentHighlight" variable.void
updateLocation
(ghidra.program.util.ProgramLocation loc) Updates the location in the "currentLocation" variable as well as the address in the "ghidra/current-address" variable.void
updateProgram
(ghidra.program.model.listing.Program program) Updates the program pointed to by the "currentProgram" binding.void
updateSelection
(ghidra.program.util.ProgramSelection sel) Updates the selection pointed to by the "currentSelection" binding.Methods inherited from class rubydragon.GhidraInterpreter
autoImportClasses, getCurrentAddressName, getCurrentAPIName, getCurrentHighlightName, getCurrentLocationName, getCurrentProgramName, getCurrentSelectionName, initInteractiveInterpreterWithProgress, setStreams
-
Field Details
-
counter
-
variables
-
-
Constructor Details
-
JShellGhidraInterpreter
public JShellGhidraInterpreter(InputStream in, OutputStream out, OutputStream err, DragonPlugin parentPlugin) 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.parentPlugin
- The DragonPlugin instance owning this interpreter.
-
JShellGhidraInterpreter
public JShellGhidraInterpreter(ghidra.app.plugin.core.interpreter.InterpreterConsole console, DragonPlugin parentPlugin) 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
-
initInteractiveInterpreter
public void initInteractiveInterpreter()Creates a new JShell interpreter, and declares the internal variables.- 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.- 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 Java this JShell supports.- Specified by:
getVersion
in classGhidraInterpreter
- Returns:
- A string with the version of the interpreter.
- Since:
- 3.1.0
-
importClass
Imports a given class into the interpreter.- 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
-
interrupt
public void interrupt()Interrupts this interpreter. -
reset
public void reset()Resets this interpreter. -
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 interpreter.- 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
-
updateAddress
public void updateAddress(ghidra.program.model.address.Address address) Updates the current address pointed to by the "currentAddress" binding in the interpreter.- Overrides:
updateAddress
in classGhidraInterpreter
- 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 "currentHighlight" variable.- Overrides:
updateHighlight
in classGhidraInterpreter
- Parameters:
sel
- The new highlighted selection.
-
updateLocation
public void updateLocation(ghidra.program.util.ProgramLocation loc) Updates the location in the "currentLocation" variable as well as the address in the "ghidra/current-address" variable.- Overrides:
updateLocation
in classGhidraInterpreter
- Parameters:
loc
- The new location in the program.
-
updateProgram
public void updateProgram(ghidra.program.model.listing.Program program) Updates the program pointed to by the "currentProgram" binding.- Overrides:
updateProgram
in classGhidraInterpreter
- Parameters:
program
- The new current program.
-
updateSelection
public void updateSelection(ghidra.program.util.ProgramSelection sel) Updates the selection pointed to by the "currentSelection" binding.- Overrides:
updateSelection
in classGhidraInterpreter
- Parameters:
sel
- The new selection.
-