Package ghidra.jython
Class GhidraJythonInterpreter
java.lang.Object
org.python.util.PythonInterpreter
org.python.util.InteractiveInterpreter
ghidra.jython.GhidraJythonInterpreter
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class GhidraJythonInterpreter
extends org.python.util.InteractiveInterpreter
A python interpreter meant for Ghidra's use. Each interpreter you get will have its own
variable space so they should not interfere with each other.
There is no longer a way to reset an interpreter...it was too complicated to get right.
Instead, you should cleanup()
your old interpreter and make a new one.
-
Field Summary
Fields inherited from class org.python.util.InteractiveInterpreter
buffer, filename
Fields inherited from class org.python.util.PythonInterpreter
cflags, systemState, threadLocals, useThreadLocalState
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
void
execFile
(ResourceFile file, JythonScript script) Execute a python file using this interpreter.static GhidraJythonInterpreter
get()
Gets a new GhidraPythonInterpreter instance.boolean
push
(String line, JythonScript script) Pushes (executes) a line of Python to the interpreter.Methods inherited from class org.python.util.InteractiveInterpreter
interrupt, resetbuffer, runcode, runsource, runsource, runsource, showexception, write
Methods inherited from class org.python.util.PythonInterpreter
close, compile, compile, compile, compile, eval, eval, exec, exec, execfile, execfile, execfile, get, get, getLocals, getSystemState, initialize, set, set, setErr, setErr, setErr, setIn, setIn, setIn, setLocals, setOut, setOut, setOut, setSystemState, threadLocalStateInterpreter
-
Method Details
-
get
Gets a new GhidraPythonInterpreter instance.- Returns:
- A new GhidraPythonInterpreter. Could be null if it failed to be created.
-
push
public boolean push(String line, JythonScript script) throws org.python.core.PyException, IllegalStateException Pushes (executes) a line of Python to the interpreter.- Parameters:
line
- the line of Python to push to the interpreterscript
- a PythonScript from which we load state (or null)- Returns:
- true if more input is needed before execution can occur
- Throws:
org.python.core.PyException
- if an unhandled exception occurred while executing the line of pythonIllegalStateException
- if this interpreter has been cleaned up.
-
execFile
Execute a python file using this interpreter.- Parameters:
file
- The python file to execute.script
- A PythonScript from which we load state (or null).- Throws:
IllegalStateException
- if this interpreter has been cleaned up.
-
cleanup
public void cleanup()- Overrides:
cleanup
in classorg.python.util.PythonInterpreter
-