Skip to content

Commit

Permalink
GT-3334: Protected GhidraScript/FlatProgramAPI methods can now be called
Browse files Browse the repository at this point in the history
from python (fixes #1250)
  • Loading branch information
ryanmkurtz committed Nov 18, 2019
1 parent 7cd8246 commit 4496e51
Showing 1 changed file with 8 additions and 2 deletions.
Expand Up @@ -69,6 +69,11 @@ public static GhidraPythonInterpreter get() {
// 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;
Expand Down Expand Up @@ -343,11 +348,12 @@ private void injectScriptHierarchy(PythonScript script) {
}
}

// 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);
}
Expand Down

0 comments on commit 4496e51

Please sign in to comment.