Ghidra is a software reverse engineering (SRE) framework
GP-5415: Python scripts that do not declare a @runtime metadata comment now default to PyGhidra instead of Jython. (Closes #7856)
Ryan Kurtz6f0cb9a77ceb
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptUtil.java b/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptUtil.javaindex 180b024e29..cdf3da72b0 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptUtil.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScriptUtil.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -30,7 +30,7 @@ import ghidra.app.plugin.core.script.GhidraScriptMgrPlugin;import ghidra.app.util.headless.HeadlessAnalyzer;import ghidra.framework.Application;import ghidra.util.Msg;-import ghidra.util.classfinder.ClassSearcher;+import ghidra.util.classfinder.*;import utilities.util.FileUtilities;/**@@ -276,18 +276,18 @@ public class GhidraScriptUtil {}/**- * Returns a list of all supported Ghidra script providers+ * Returns a list of all supported Ghidra script providers.+ * <p>+ * NOTE: The list is {@link ExtensionPointProperties#priority() priority-sorted}** @return a list of all supported Ghidra script providers+ * @apiNote this method is synchronized so that two threads do not try to create the list when+ * null*/- // Note: this method is synchronized so that two threads do not try to create the list when nullpublic static synchronized List<GhidraScriptProvider> getProviders() {if (providers == null) {- providers = ClassSearcher.getInstances(GhidraScriptProvider.class)- .stream()- .filter(p -> !(p instanceof UnsupportedScriptProvider))- .sorted()- .toList();+ providers = ClassSearcher.getInstances(GhidraScriptProvider.class,+ new ClassExclusionFilter(UnsupportedScriptProvider.class));}return providers;}diff --git a/Ghidra/Features/Jython/src/main/java/ghidra/jython/JythonScriptProvider.java b/Ghidra/Features/Jython/src/main/java/ghidra/jython/JythonScriptProvider.javaindex c91041bd4b..71b408e7e5 100644--- a/Ghidra/Features/Jython/src/main/java/ghidra/jython/JythonScriptProvider.java+++ b/Ghidra/Features/Jython/src/main/java/ghidra/jython/JythonScriptProvider.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -19,12 +19,10 @@ import java.io.PrintWriter;import generic.jar.ResourceFile;import ghidra.app.script.*;-import ghidra.util.classfinder.ExtensionPointProperties;/*** A {@link GhidraScriptProvider} used to run Jython scripts*/-@ExtensionPointProperties(priority = 1000) // Enforce high priority so Jython is the default Python providerpublic class JythonScriptProvider extends AbstractPythonScriptProvider {@Overridediff --git a/Ghidra/Features/PyGhidra/src/main/java/ghidra/pyghidra/PyGhidraScriptProvider.java b/Ghidra/Features/PyGhidra/src/main/java/ghidra/pyghidra/PyGhidraScriptProvider.javaindex 382c287c1e..a60feb90a3 100644--- a/Ghidra/Features/PyGhidra/src/main/java/ghidra/pyghidra/PyGhidraScriptProvider.java+++ b/Ghidra/Features/PyGhidra/src/main/java/ghidra/pyghidra/PyGhidraScriptProvider.java@@ -29,12 +29,14 @@ import ghidra.program.util.ProgramLocation;import ghidra.program.util.ProgramSelection;import ghidra.pyghidra.PythonFieldExposer.ExposedFields;import ghidra.util.SystemUtilities;+import ghidra.util.classfinder.ExtensionPointProperties;import ghidra.util.exception.AssertException;import ghidra.util.task.TaskMonitor;/*** {@link GhidraScript} provider for native python3 scripts*/+@ExtensionPointProperties(priority = 1000) // Enforce high priority so PyGhidra is the default Python providerpublic final class PyGhidraScriptProvider extends AbstractPythonScriptProvider {private static Consumer<GhidraScript> scriptRunner = null;@@ -102,7 +104,7 @@ public final class PyGhidraScriptProvider extends AbstractPythonScriptProvider {}/**- * Helper inner class that can create a {@link MethodHandles.Lookup}+ * Helper inner class that can create a {@link java.lang.invoke.MethodHandles.Lookup}* that can access the protected fields of the {@link GhidraScript}*/private static class ExposedField extends PythonFieldExposer.ExposedField {@@ -136,7 +138,7 @@ public final class PyGhidraScriptProvider extends AbstractPythonScriptProvider {}/**- * Helper inner class that can create a {@link MethodHandles.Lookup}+ * Helper inner class that can create a {@link java.lang.invoke.MethodHandles.Lookup}* that can access the protected fields of the {@link GhidraScript}*/private static class ExposedField extends PythonFieldExposer.ExposedField {