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 Link icon

    Fields inherited from class org.python.util.InteractiveInterpreter Link icon

    buffer, filename

    Fields inherited from class org.python.util.PythonInterpreter Link icon

    cflags, systemState, threadLocals, useThreadLocalState
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
     
    void
    Execute a python file using this interpreter.
    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 Link icon

    interrupt, resetbuffer, runcode, runsource, runsource, runsource, showexception, write

    Methods inherited from class org.python.util.PythonInterpreter Link icon

    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

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details Link icon

    • get Link icon

      public static GhidraJythonInterpreter get()
      Gets a new GhidraPythonInterpreter instance.
      Returns:
      A new GhidraPythonInterpreter. Could be null if it failed to be created.
    • push Link icon

      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 interpreter
      script - 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 python
      IllegalStateException - if this interpreter has been cleaned up.
    • execFile Link icon

      public void execFile(ResourceFile file, JythonScript script) throws 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:
      IllegalStateException - if this interpreter has been cleaned up.
    • cleanup Link icon

      public void cleanup()
      Overrides:
      cleanup in class org.python.util.PythonInterpreter