mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-31 06:20:40 +08:00
GP-6754: Handle Jython not being installed better (message and headless
exit code)
This commit is contained in:
@@ -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.analysis.AutoAnalysisManager;
|
||||||
import ghidra.app.plugin.core.osgi.BundleHost;
|
import ghidra.app.plugin.core.osgi.BundleHost;
|
||||||
import ghidra.app.script.*;
|
import ghidra.app.script.*;
|
||||||
|
import ghidra.app.script.JythonStubScriptProvider.JythonStubException;
|
||||||
import ghidra.app.util.headless.HeadlessScript.HeadlessContinuationOption;
|
import ghidra.app.util.headless.HeadlessScript.HeadlessContinuationOption;
|
||||||
import ghidra.app.util.importer.ProgramLoader;
|
import ghidra.app.util.importer.ProgramLoader;
|
||||||
import ghidra.app.util.opinion.*;
|
import ghidra.app.util.opinion.*;
|
||||||
@@ -960,7 +961,13 @@ public class HeadlessAnalyzer {
|
|||||||
}
|
}
|
||||||
catch (Exception exc) {
|
catch (Exception exc) {
|
||||||
String logErrorMsg = "REPORT SCRIPT ERROR: " + scriptName + " : " + exc.getMessage();
|
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;
|
return retOption;
|
||||||
|
|||||||
Reference in New Issue
Block a user