GT-3334: Protected GhidraScript/FlatProgramAPI methods can now be called

from python (fixes #1250)
This commit is contained in:
Ryan Kurtz 2019-11-18 12:18:20 -05:00
parent 7cd82462e9
commit 4496e51b0b

View File

@ -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);
}