mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
GP-5415: Python scripts that do not declare a @runtime metadata comment
now default to PyGhidra instead of Jython. (Closes #7856)
This commit is contained in:
parent
b7602e9d41
commit
6f0cb9a77c
3 changed files with 16 additions and 16 deletions
|
@ -4,9 +4,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* 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.app.util.headless.HeadlessAnalyzer;
|
||||||
import ghidra.framework.Application;
|
import ghidra.framework.Application;
|
||||||
import ghidra.util.Msg;
|
import ghidra.util.Msg;
|
||||||
import ghidra.util.classfinder.ClassSearcher;
|
import ghidra.util.classfinder.*;
|
||||||
import utilities.util.FileUtilities;
|
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
|
* @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 null
|
|
||||||
public static synchronized List<GhidraScriptProvider> getProviders() {
|
public static synchronized List<GhidraScriptProvider> getProviders() {
|
||||||
if (providers == null) {
|
if (providers == null) {
|
||||||
providers = ClassSearcher.getInstances(GhidraScriptProvider.class)
|
providers = ClassSearcher.getInstances(GhidraScriptProvider.class,
|
||||||
.stream()
|
new ClassExclusionFilter(UnsupportedScriptProvider.class));
|
||||||
.filter(p -> !(p instanceof UnsupportedScriptProvider))
|
|
||||||
.sorted()
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
return providers;
|
return providers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -19,12 +19,10 @@ import java.io.PrintWriter;
|
||||||
|
|
||||||
import generic.jar.ResourceFile;
|
import generic.jar.ResourceFile;
|
||||||
import ghidra.app.script.*;
|
import ghidra.app.script.*;
|
||||||
import ghidra.util.classfinder.ExtensionPointProperties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link GhidraScriptProvider} used to run Jython scripts
|
* A {@link GhidraScriptProvider} used to run Jython scripts
|
||||||
*/
|
*/
|
||||||
@ExtensionPointProperties(priority = 1000) // Enforce high priority so Jython is the default Python provider
|
|
||||||
public class JythonScriptProvider extends AbstractPythonScriptProvider {
|
public class JythonScriptProvider extends AbstractPythonScriptProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,12 +29,14 @@ import ghidra.program.util.ProgramLocation;
|
||||||
import ghidra.program.util.ProgramSelection;
|
import ghidra.program.util.ProgramSelection;
|
||||||
import ghidra.pyghidra.PythonFieldExposer.ExposedFields;
|
import ghidra.pyghidra.PythonFieldExposer.ExposedFields;
|
||||||
import ghidra.util.SystemUtilities;
|
import ghidra.util.SystemUtilities;
|
||||||
|
import ghidra.util.classfinder.ExtensionPointProperties;
|
||||||
import ghidra.util.exception.AssertException;
|
import ghidra.util.exception.AssertException;
|
||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link GhidraScript} provider for native python3 scripts
|
* {@link GhidraScript} provider for native python3 scripts
|
||||||
*/
|
*/
|
||||||
|
@ExtensionPointProperties(priority = 1000) // Enforce high priority so PyGhidra is the default Python provider
|
||||||
public final class PyGhidraScriptProvider extends AbstractPythonScriptProvider {
|
public final class PyGhidraScriptProvider extends AbstractPythonScriptProvider {
|
||||||
|
|
||||||
private static Consumer<GhidraScript> scriptRunner = null;
|
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}
|
* that can access the protected fields of the {@link GhidraScript}
|
||||||
*/
|
*/
|
||||||
private static class ExposedField extends PythonFieldExposer.ExposedField {
|
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}
|
* that can access the protected fields of the {@link GhidraScript}
|
||||||
*/
|
*/
|
||||||
private static class ExposedField extends PythonFieldExposer.ExposedField {
|
private static class ExposedField extends PythonFieldExposer.ExposedField {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue