Package ghidra.python
Class GhidraPythonInterpreter
- java.lang.Object
-
- org.python.util.PythonInterpreter
-
- org.python.util.InteractiveInterpreter
-
- ghidra.python.GhidraPythonInterpreter
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class GhidraPythonInterpreter 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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanup()
void
execFile(ResourceFile file, PythonScript script)
Execute a python file using this interpreter.static GhidraPythonInterpreter
get()
Gets a new GhidraPythonInterpreter instance.boolean
push(java.lang.String line, PythonScript 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 Detail
-
get
public static GhidraPythonInterpreter get()
Gets a new GhidraPythonInterpreter instance.- Returns:
- A new GhidraPythonInterpreter. Could be null if it failed to be created.
-
push
public boolean push(java.lang.String line, PythonScript script) throws org.python.core.PyException, java.lang.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 pythonjava.lang.IllegalStateException
- if this interpreter has been cleaned up.
-
execFile
public void execFile(ResourceFile file, PythonScript script) throws java.lang.IllegalStateException
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:
java.lang.IllegalStateException
- if this interpreter has been cleaned up.
-
cleanup
public void cleanup()
- Overrides:
cleanup
in classorg.python.util.PythonInterpreter
-
-