Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3334: Protected GhidraScript/FlatProgramAPI methods can now be called from python (fixes #1250)

Ryan Kurtz4496e51b0be1
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 3d720cd85f..f6feac4f15 100644
--- a/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java
+++ b/Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java
@@ -69,6 +69,11 @@ public class GhidraPythonInterpreter extends InteractiveInterpreter {
// Setup python cache directory
PythonUtils.setupPythonCacheDir(TaskMonitor.DUMMY);
+ // Enable protected java methods to be accessed from python sub-classes.
+ // This is necessary to be able to call protected GhidraScript/FlatProgram API
+ // methods from a python script.
+ System.setProperty("python.security.respectJavaAccessibility", "false");
+
// Indicate that we've initialized the python environment, which should
// only happen once.
pythonInitialized = true;
@@ -343,11 +348,12 @@ public class GhidraPythonInterpreter extends InteractiveInterpreter {
}
}
- // Add public methods only once. Ignore inner classes.
+ // Add public and protected methods (only once). Ignore inner classes.
if (!scriptMethodsInjected) {
for (Method method : scriptClass.getDeclaredMethods()) {
if (!method.getName().contains("$") &&
- Modifier.isPublic(method.getModifiers())) {
+ (Modifier.isPublic(method.getModifiers()) ||
+ Modifier.isProtected(method.getModifiers()))) {
method.setAccessible(true);
setMethod(script, method);
}