From cd89f0e00f5d36b18116950803840be0111b3218 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Tue, 6 Jul 2021 10:47:24 -0400 Subject: [PATCH] GP-1099: Supporting the __file__ attribute in Jython scripts --- .../src/main/java/ghidra/python/GhidraPythonInterpreter.java | 3 +++ 1 file changed, 3 insertions(+) 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 e102543058..85053243ee 100644 --- a/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java +++ b/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java @@ -211,6 +211,9 @@ public class GhidraPythonInterpreter extends InteractiveInterpreter { Py.getThreadState().tracefunc = interruptTraceFunction; + // The Python import system sets the __file__ attribute to the file it's executing + setVariable("__file__", new PyString(file.getAbsolutePath())); + // If the remote python debugger is alive, initialize it by calling settrace() if (!SystemUtilities.isInDevelopmentMode() && !SystemUtilities.isInHeadlessMode()) { if (PyDevUtils.getPyDevSrcDir() != null) {