GP-6754: Handle Jython not being installed better (message and headless

exit code)
This commit is contained in:
Ryan Kurtz
2026-04-28 13:59:53 -04:00
parent 2ab7bc3f03
commit bdabab040e
2 changed files with 72 additions and 1 deletions
@@ -0,0 +1,64 @@
/* ###
* IP: GHIDRA
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.app.script;
import java.io.PrintWriter;
import generic.jar.ResourceFile;
import ghidra.util.classfinder.ExtensionPointProperties;
/**
* A stub {@link GhidraScriptProvider} used to give feedback to a user trying to run a Jython
* script when the Jython Extension is not installed.
* <p>
* Uses a sub-{@link ExtensionPointProperties#DEFAULT_PRIORITY default} priority so the Jython
* Extension can get prioritized over this if it's installed.
*/
@ExtensionPointProperties(priority = ExtensionPointProperties.DEFAULT_PRIORITY - 1)
public class JythonStubScriptProvider extends AbstractPythonScriptProvider {
@Override
public String getDescription() {
return "Jython";
}
@Override
public String getRuntimeEnvironmentName() {
return "Jython";
}
@Override
public GhidraScript getScriptInstance(ResourceFile sourceFile, PrintWriter writer)
throws JythonStubException {
throw new JythonStubException();
}
/**
* A special type of {@link GhidraScriptLoadException} used to indicate that the Jython
* Extension is not installed.
*/
public static class JythonStubException extends GhidraScriptLoadException {
/**
* Construct an new {@link JythonStubException}
*/
public JythonStubException() {
super("Jython script failed. " +
"In order to use Jython based scripts, you must install the Jython Ghidra " +
"Extension, or (recommended) port your script to PyGhidra or Java.");
}
}
}
@@ -30,6 +30,7 @@ import ghidra.GhidraJarApplicationLayout;
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.app.plugin.core.osgi.BundleHost;
import ghidra.app.script.*;
import ghidra.app.script.JythonStubScriptProvider.JythonStubException;
import ghidra.app.util.headless.HeadlessScript.HeadlessContinuationOption;
import ghidra.app.util.importer.ProgramLoader;
import ghidra.app.util.opinion.*;
@@ -960,7 +961,13 @@ public class HeadlessAnalyzer {
}
catch (Exception exc) {
String logErrorMsg = "REPORT SCRIPT ERROR: " + scriptName + " : " + exc.getMessage();
Msg.error(this, logErrorMsg, exc);
if (exc instanceof JythonStubException) {
Msg.error(this, logErrorMsg);
System.exit(1);
}
else {
Msg.error(this, logErrorMsg, exc);
}
}
return retOption;