Package ghidra.python

Class 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.

    • 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

      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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 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
        java.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 class org.python.util.PythonInterpreter