From 21d8d1813437f503c80ac5bbc0c0a68b15b9adec Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Fri, 30 Dec 2022 05:36:14 -0500 Subject: [PATCH] GP-1035: Python interpreter code completion now works prior to executing any python statements --- .../main/java/ghidra/python/GhidraPythonInterpreter.java | 2 +- .../Python/src/main/java/ghidra/python/PythonPlugin.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java b/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java index fd734d00ce..5584e61a86 100644 --- a/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java +++ b/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java @@ -332,7 +332,7 @@ public class GhidraPythonInterpreter extends InteractiveInterpreter { * * @param script The script whose class hierarchy is to be used for injection. */ - private void injectScriptHierarchy(PythonScript script) { + void injectScriptHierarchy(PythonScript script) { if (script == null) { return; diff --git a/Ghidra/Features/Python/src/main/java/ghidra/python/PythonPlugin.java b/Ghidra/Features/Python/src/main/java/ghidra/python/PythonPlugin.java index c0da0b8734..723fa34452 100644 --- a/Ghidra/Features/Python/src/main/java/ghidra/python/PythonPlugin.java +++ b/Ghidra/Features/Python/src/main/java/ghidra/python/PythonPlugin.java @@ -226,8 +226,14 @@ public class PythonPlugin extends ProgramPlugin // Setup the PythonScript describing the state of the interactive prompt. // This allows things like currentProgram and currentAddress to dynamically reflect - // what's happening in the listing. + // what's happening in the listing. Injecting the script hierarchy early here allows + // code completion to work before commands are entered. interactiveScript = new PythonScript(); + interactiveScript.set( + new GhidraState(tool, tool.getProject(), getCurrentProgram(), getProgramLocation(), + getProgramSelection(), getProgramHighlight()), + interactiveTaskMonitor, new PrintWriter(getConsole().getStdOut())); + interpreter.injectScriptHierarchy(interactiveScript); interactiveTaskMonitor = new PythonInteractiveTaskMonitor(console.getStdOut()); // Start the input thread that receives python commands to execute.