Skip to content

Commit 4496e51

Browse files
committed
GT-3334: Protected GhidraScript/FlatProgramAPI methods can now be called
from python (fixes NationalSecurityAgency#1250)
1 parent 7cd8246 commit 4496e51

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Ghidra/Features/Python/src/main/java/ghidra/python/GhidraPythonInterpreter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public static GhidraPythonInterpreter get() {
6969
// Setup python cache directory
7070
PythonUtils.setupPythonCacheDir(TaskMonitor.DUMMY);
7171

72+
// Enable protected java methods to be accessed from python sub-classes.
73+
// This is necessary to be able to call protected GhidraScript/FlatProgram API
74+
// methods from a python script.
75+
System.setProperty("python.security.respectJavaAccessibility", "false");
76+
7277
// Indicate that we've initialized the python environment, which should
7378
// only happen once.
7479
pythonInitialized = true;
@@ -343,11 +348,12 @@ private void injectScriptHierarchy(PythonScript script) {
343348
}
344349
}
345350

346-
// Add public methods only once. Ignore inner classes.
351+
// Add public and protected methods (only once). Ignore inner classes.
347352
if (!scriptMethodsInjected) {
348353
for (Method method : scriptClass.getDeclaredMethods()) {
349354
if (!method.getName().contains("$") &&
350-
Modifier.isPublic(method.getModifiers())) {
355+
(Modifier.isPublic(method.getModifiers()) ||
356+
Modifier.isProtected(method.getModifiers()))) {
351357
method.setAccessible(true);
352358
setMethod(script, method);
353359
}

0 commit comments

Comments
 (0)