Ghidra is a software reverse engineering (SRE) framework
do not auto-create ScriptInfo objects, fix static allocatins in testing
Jason P. Leasure1735a11a769f
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.javaindex b7e889ba11..72959962c0 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleHost.java@@ -39,6 +39,7 @@ import ghidra.util.exception.CancelledException;import ghidra.util.task.*;public class BundleHost {+ protected static final boolean DUMP_TO_STDERR = false;// XXX ScriptProviders don't have any way to access services or other way to access system wide resourcesstatic private BundleHost _instance;@@ -302,7 +303,9 @@ public class BundleHost {@Overridepublic void frameworkEvent(FrameworkEvent event) {- System.err.printf("%s %s\n", event.getBundle(), event);+ if (DUMP_TO_STDERR) {+ System.err.printf("%s %s\n", event.getBundle(), event);+ }}});@@ -318,8 +321,10 @@ public class BundleHost {type = "unregistering";}- System.err.printf("%s %s from %s\n", event.getSource(), type,- event.getServiceReference().getBundle().getLocation());+ if (DUMP_TO_STDERR) {+ System.err.printf("%s %s from %s\n", event.getSource(), type,+ event.getServiceReference().getBundle().getLocation());+ }}});@@ -327,9 +332,11 @@ public class BundleHost {@Overridepublic void bundleChanged(BundleEvent event) {Bundle b = event.getBundle();- String n = b.getSymbolicName();- String l = b.getLocation();- System.err.printf("%s %s from %s\n", getEventTypeString(event), n, l);+ if (DUMP_TO_STDERR) {+ String n = b.getSymbolicName();+ String l = b.getLocation();+ System.err.printf("%s %s from %s\n", getEventTypeString(event), n, l);+ }switch (event.getType()) {case BundleEvent.STARTED:fireBundleActivationChange(b, true);@@ -418,7 +425,6 @@ public class BundleHost {FrameworkWiring fw = felix.adapt(FrameworkWiring.class);LinkedList<Bundle> dependents =new LinkedList<Bundle>(fw.getDependencyClosure(Collections.singleton(b)));- System.err.printf("%s has %d dependendts\n", b.getSymbolicName(), dependents.size());while (!dependents.isEmpty()) {b = dependents.pop();try {@@ -562,4 +568,10 @@ public class BundleHost {}}+ public void removeAllListeners() {+ synchronized (osgiListeners) {+ osgiListeners.clear();+ }+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusListener.javaindex 67eb3ee9af..3f06386abe 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusListener.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusListener.java@@ -16,6 +16,9 @@*/package ghidra.app.plugin.core.osgi;+/**+ * events thrown by BundleStatusModel component+ */public interface BundleStatusListener {/**diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.javaindex 08b615f863..3e490a8c10 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/GhidraSourceBundle.java@@ -146,15 +146,18 @@ public class GhidraSourceBundle implements GhidraBundle {/*** update buildReqs based on \@imports tag in java files from the default package+ ** @throws GhidraBundleException on failure to parse the \@imports tag*/private void updateRequirementsFromMetadata() throws GhidraBundleException {- // parse metadata from all Java source in sourceDirbuildReqs.clear();req2file.clear();for (ResourceFile rf : sourceDir.listFiles()) {if (rf.getName().endsWith(".java")) {+ // without GhidraScriptComponentProvider.updateAvailableScriptFilesForDirectory, or GhidraScriptComponentProvider.newScript+ // this might be the earliest need for ScriptInfo, so allow construction.+// NB: ScriptInfo will update field values if lastModified has changed since last time they were computedScriptInfo si = GhidraScriptUtil.getScriptInfo(rf);String imps = si.getImports();diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/OSGiListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/OSGiListener.javaindex b0e6783323..50546656d3 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/OSGiListener.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/OSGiListener.java@@ -2,6 +2,9 @@ package ghidra.app.plugin.core.osgi;import org.osgi.framework.Bundle;+/**+ * Listener for OSGi framework events.+ */public interface OSGiListener {default void bundleBuilt(GhidraBundle gb) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptActionManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptActionManager.javaindex 2f4e8644bd..b66abd913a 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptActionManager.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptActionManager.java@@ -129,8 +129,10 @@ class GhidraScriptActionManager {continue;}ResourceFile scriptFile = action.getScript();- ScriptInfo info = GhidraScriptUtil.getScriptInfo(scriptFile);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(scriptFile);if (info == null) {+ Msg.showError(this, provider.getComponent(), "Bad state?",+ "action associated with a script that has no info");continue;//bad state?}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptComponentProvider.javaindex 704281619d..8b90b7c867 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptComponentProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptComponentProvider.java@@ -240,6 +240,10 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {action.setKeyBindingData(new KeyBindingData(ks));}+ assert !GhidraScriptUtil.containsMetadata(+ renameFile) : "renamed script already has metadata";+ GhidraScriptUtil.getScriptInfo(renameFile);+tableModel.switchScript(script, renameFile);setSelectedScript(renameFile);}@@ -384,7 +388,13 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {new GhidraScriptEditorComponentProvider(plugin, this, newFile);editorMap.put(newFile, editor);+ // create the ScriptInfo object now, before the TableModelEvent handlers+ // attempt to use it.+ assert !GhidraScriptUtil.containsMetadata(newFile) : "new source already has metadata?";+ GhidraScriptUtil.getScriptInfo(newFile);+tableModel.insertScript(newFile);+int index = getScriptIndex(newFile);if (index >= 0) {@@ -542,6 +552,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {}// note: do this after the loop to prevent a flurry of table model update events+ // scriptinfo was created in updateAvailableScriptfilesForDirectorytableModel.insertScripts(scriptAccumulator);for (ResourceFile file : scriptsToRemove) {@@ -566,7 +577,12 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {// model.insertScript(element);scriptAccumulator.add(scriptFile);}- scriptRoot.insert(scriptFile);+ // new ScriptInfo objects are created on performRefresh, e.g. on startup. Other+ // refresh operations might have old infos.+ // assert !GhidraScriptUtil.containsMetadata(scriptFile): "info already exists for script during refresh";+ ScriptInfo info = GhidraScriptUtil.getScriptInfo(scriptFile);+ String[] categoryPath = info.getCategory();+ scriptRoot.insert(categoryPath);}scriptsToRemove.remove(scriptFile);}@@ -579,7 +595,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {for (ResourceFile script : scripts) {// First get the ScriptInfo object and refresh, which will ensure any// info data (ie: script icons) will be reloaded.- ScriptInfo info = GhidraScriptUtil.getScriptInfo(script);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(script);info.refresh();ScriptAction scriptAction = actionManager.get(script);@@ -693,6 +709,8 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {GhidraScriptEditorComponentProvider editor = editorMap.get(oldScript);editorMap.put(newScript, editor);editorMap.remove(oldScript);+ // create corresponding info before inserting in table+ GhidraScriptUtil.getScriptInfo(newScript);tableModel.insertScript(newScript);}@@ -761,7 +779,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {GhidraSourceBundle gsb = (GhidraSourceBundle) sb;for (ResourceFile sf : gsb.getNewSources()) {if (GhidraScriptUtil.containsMetadata(sf)) {- ScriptInfo info = GhidraScriptUtil.getScriptInfo(sf);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(sf);BuildFailure e = gsb.getErrors(sf);info.setCompileErrors(e != null);}@@ -906,11 +924,13 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {// the selected script has been changed, update the description panelupdateDescriptionPanel();- updateCategoryTree(script);++ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(script);+ updateCategoryTree(info.getCategory());}- private void updateCategoryTree(ResourceFile script) {- scriptRoot.insert(script);+ private void updateCategoryTree(String[] categoryPath) {+ scriptRoot.insert(categoryPath);trimUnusedTreeCategories();}@@ -922,7 +942,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {@Overridepublic List<String> transform(ResourceFile script) {- ScriptInfo info = GhidraScriptUtil.getScriptInfo(script);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(script);list.clear();list.add(info.getName());list.add(info.getDescription());@@ -953,20 +973,22 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {}private void updateDescriptionPanel() {- descriptionTextPane.setText("");+ String text = "Error! no script info!";ResourceFile script = getSelectedScript();- if (script == null) {- return;+ if (script != null) {+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(script);+ if (info != null) {+ text = info.getToolTipText();+ }}+ final String ftext = text;- ScriptInfo info = GhidraScriptUtil.getScriptInfo(script);- if (info != null) {- descriptionTextPane.setText(info.getToolTipText());-- // have to do an invokeLater here, since the DefaultCaret class runs in an invokeLater,- // which will overwrite our location setting- SwingUtilities.invokeLater(() -> descriptionTextPane.setCaretPosition(0));- }+ // have to do an invokeLater here, since the DefaultCaret class runs in an invokeLater,+ // which will overwrite our location setting+ SwingUtilities.invokeLater(() -> {+ descriptionTextPane.setText(ftext);+ descriptionTextPane.setCaretPosition(0);+ });}private int getModelRowForViewRow(int viewRow) {@@ -1137,9 +1159,6 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {@Overridepublic boolean acceptsRow(ResourceFile script) {ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(script);- if (info == null) {- return false;- }String[] category = getSelectedCategoryPath();if (category == null) { // root nodediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptTableModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptTableModel.javaindex f8d60858e2..e1c27dfcbd 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptTableModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/GhidraScriptTableModel.java@@ -238,7 +238,7 @@ class GhidraScriptTableModel extends GDynamicColumnTableModel<ResourceFile, ObjeJLabel label = (JLabel) super.getTableCellRendererComponent(data);ResourceFile file = (ResourceFile) data.getRowObject();- ScriptInfo info = GhidraScriptUtil.getScriptInfo(file);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(file);label.setText(null);label.setToolTipText(null);@@ -279,7 +279,7 @@ class GhidraScriptTableModel extends GDynamicColumnTableModel<ResourceFile, Obje@Overridepublic ImageIcon getValue(ResourceFile rowObject, Settings settings, Object data,ServiceProvider sp) throws IllegalArgumentException {- ScriptInfo info = GhidraScriptUtil.getScriptInfo(rowObject);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(rowObject);if (info.isCompileErrors() || info.isDuplicate()) {return ERROR_IMG;}@@ -329,7 +329,7 @@ class GhidraScriptTableModel extends GDynamicColumnTableModel<ResourceFile, Obje@Overridepublic String getValue(ResourceFile rowObject, Settings settings, Object data,ServiceProvider sp) throws IllegalArgumentException {- ScriptInfo info = GhidraScriptUtil.getScriptInfo(rowObject);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(rowObject);return info.getDescription();}@@ -401,7 +401,7 @@ class GhidraScriptTableModel extends GDynamicColumnTableModel<ResourceFile, Obje@Overridepublic KeyBindingsInfo getValue(ResourceFile rowObject, Settings settings, Object data,ServiceProvider sp) throws IllegalArgumentException {- ScriptInfo info = GhidraScriptUtil.getScriptInfo(rowObject);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(rowObject);KeyStroke actionKeyStroke = provider.getActionManager().getKeyBinding(rowObject);boolean isActionBinding = false;KeyStroke keyBinding = info.getKeyBinding();@@ -459,7 +459,7 @@ class GhidraScriptTableModel extends GDynamicColumnTableModel<ResourceFile, Obje@Overridepublic String getValue(ResourceFile rowObject, Settings settings, Object data,ServiceProvider sp) throws IllegalArgumentException {- ScriptInfo info = GhidraScriptUtil.getScriptInfo(rowObject);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(rowObject);return getCategoryString(info);}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/RootNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/RootNode.javaindex 0ec8713d25..55eec912c1 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/RootNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/RootNode.java@@ -20,10 +20,6 @@ import java.util.List;import javax.swing.Icon;import docking.widgets.tree.GTreeNode;-import docking.widgets.tree.GTreeNode;-import generic.jar.ResourceFile;-import ghidra.app.script.GhidraScriptUtil;-import ghidra.app.script.ScriptInfo;import resources.ResourceManager;class RootNode extends GTreeNode {@@ -49,9 +45,7 @@ class RootNode extends GTreeNode {return false;}- void insert(ResourceFile script) {- ScriptInfo info = GhidraScriptUtil.getScriptInfo(script);- String[] categoryPath = info.getCategory();+ void insert(String[] categoryPath) {GTreeNode parent = this;for (String categoryName : categoryPath) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/ScriptAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/ScriptAction.javaindex 1b5bb324ec..443933c57f 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/ScriptAction.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/script/ScriptAction.java@@ -90,7 +90,7 @@ class ScriptAction extends DockingAction {}// check to see if we have a fallback value- ScriptInfo info = GhidraScriptUtil.getScriptInfo(script);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(script);KeyStroke metadataKeyStroke = info.getKeyBinding();if (metadataKeyStroke == null) {// there is no fallback value; the current keybinding data is what we want@@ -105,7 +105,7 @@ class ScriptAction extends DockingAction {// we have a user defined keybinding if the keystroke for the action differs from// that which is defined in the metadata of the scriptKeyStroke actionKeyStroke = keyBindingData.getKeyBinding();- ScriptInfo info = GhidraScriptUtil.getScriptInfo(script);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(script);KeyStroke metadataKeyBinding = info.getKeyBinding();isUserDefinedKeyBinding = !SystemUtilities.isEqual(actionKeyStroke, metadataKeyBinding);}@@ -119,7 +119,7 @@ class ScriptAction extends DockingAction {}void refresh() {- ScriptInfo info = GhidraScriptUtil.getScriptInfo(script);+ ScriptInfo info = GhidraScriptUtil.getExistingScriptInfo(script);KeyStroke stroke = info.getKeyBinding();if (!isUserDefinedKeyBinding) {setKeyBindingData(new KeyBindingData(stroke));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 dace64a9c7..629530226a 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@@ -199,16 +199,6 @@ public class GhidraScriptUtil {return name.substring(0, pos);}- /**- * Returns true if a ScriptInfo object exists for- * the specified script file.- * @param scriptFile the script file- * @return true if a ScriptInfo object exists- */- public static boolean containsMetadata(ResourceFile scriptFile) {- return scriptFileToInfoMap.containsKey(scriptFile);- }-/*** Removes the ScriptInfo object for the specified file* @param scriptFile the script file@@ -242,7 +232,11 @@ public class GhidraScriptUtil {}/**- * Returns the script info object for the specified script file+ * Returns the script info object for the specified script file,+ * construct a new one if necessary.+ *+ * Only call this method if you expect to be creating ScriptInfo objects.+ * Prefer getExistingScriptInfo instead.** @param scriptFile the script file* @return the script info object for the specified script file@@ -266,11 +260,69 @@ public class GhidraScriptUtil {return info;}+ /**+ * Returns true if a ScriptInfo object exists for+ * the specified script file.+ * @param scriptFile the script file+ * @return true if a ScriptInfo object exists+ */+ public static boolean containsMetadata(ResourceFile scriptFile) {+ return scriptFileToInfoMap.containsKey(scriptFile);+ }++ public static ScriptInfo getExistingScriptInfo(ResourceFile script) {+ ScriptInfo info = scriptFileToInfoMap.get(script);+ if (info == null) {+ String s = (script.exists() ? "" : "non") + "existing script" + script.toString() ++ " is missing info we thought was there";+ System.err.println(s);+ Msg.showError(GhidraScriptUtil.class, null, "ScriptInfo lookup", s);+ }+ return info;+ }++ /**+ * Returns the existing script info for the given name. The script environment limits+ * scripts such that names are unique. If this method returns a non-null value, then the+ * name given name is taken.+ *+ * @param scriptName the name of the script for which to get a ScriptInfo+ * @return a ScriptInfo matching the given name; null if no script by that name is known to+ * the script manager+ */+ public static ScriptInfo getExistingScriptInfo(String scriptName) {+ List<ResourceFile> matchingFiles = scriptNameToFilesMap.get(scriptName);+ if (matchingFiles == null || matchingFiles.isEmpty()) {+ return null;+ }+ return scriptFileToInfoMap.get(matchingFiles.get(0));+ }++ /**+ * Looks through all of the current {@link ScriptInfo}s to see if one already exists with+ * the given name.+ * @param scriptName The name to check+ * @return true if the name is not taken by an existing {@link ScriptInfo}.+ */+ public static boolean alreadyExists(String scriptName) {+ return getExistingScriptInfo(scriptName) != null;+ }+private static void markAnyDuplicates(List<ResourceFile> files) {boolean isDuplicate = files.size() > 1;files.forEach(f -> scriptFileToInfoMap.get(f).setDuplicate(isDuplicate));}+ /**+ * Updates every known script's duplicate value.+ */+ public static void refreshDuplicates() {+ scriptNameToFilesMap.values().forEach(files -> {+ boolean isDuplicate = files.size() > 1;+ files.forEach(file -> scriptFileToInfoMap.get(file).setDuplicate(isDuplicate));+ });+ }+/*** Returns a list of all Ghidra script providers*@@ -421,7 +473,7 @@ public class GhidraScriptUtil {return null;}- return getScriptInfo(file); // this will cache the created info+ return getExistingScriptInfo(file); // this will cache the created info}private static void updateAvailableScriptFilesForDirectory(List<ResourceFile> scriptAccumulator,@@ -438,37 +490,6 @@ public class GhidraScriptUtil {}}- /**- * Looks through all of the current {@link ScriptInfo}s to see if one already exists with- * the given name.- * @param scriptName The name to check- * @return true if the name is not taken by an existing {@link ScriptInfo}.- */- public static boolean alreadyExists(String scriptName) {- return getExistingScriptInfo(scriptName) != null;- }-- /**- * Returns the existing script info for the given name. The script environment limits- * scripts such that names are unique. If this method returns a non-null value, then the- * name given name is taken.- *- * @param scriptName the name of the script for which to get a ScriptInfo- * @return a ScriptInfo matching the given name; null if no script by that name is known to- * the script manager- */- public static ScriptInfo getExistingScriptInfo(String scriptName) {- List<ResourceFile> matchingFiles = scriptNameToFilesMap.get(scriptName);- if (matchingFiles == null || matchingFiles.isEmpty()) {- return null;- }- return scriptFileToInfoMap.get(matchingFiles.get(0));- }-- public static ScriptInfo getExistingScriptInfo(ResourceFile script) {- return scriptFileToInfoMap.get(script);- }-/*** Runs the specified script with the specified state*@@ -503,14 +524,4 @@ public class GhidraScriptUtil {return true;}- /**- * Updates every known script's duplicate value.- */- public static void refreshDuplicates() {- scriptNameToFilesMap.values().forEach(files -> {- boolean isDuplicate = files.size() > 1;- files.forEach(file -> scriptFileToInfoMap.get(file).setDuplicate(isDuplicate));- });- }-}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.javaindex 01d77d2c6f..14301b4b6e 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/AbstractGhidraScriptMgrPluginTest.java@@ -47,7 +47,7 @@ import generic.jar.ResourceFile;import generic.test.TestUtils;import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;import ghidra.app.plugin.core.console.ConsoleComponentProvider;-import ghidra.app.plugin.core.osgi.BundleStatusProvider;+import ghidra.app.plugin.core.osgi.*;import ghidra.app.script.*;import ghidra.app.services.ConsoleService;import ghidra.framework.Application;@@ -60,7 +60,6 @@ import ghidra.util.*;import ghidra.util.datastruct.FixedSizeStack;import ghidra.util.exception.AssertException;import ghidra.util.exception.CancelledException;-import ghidra.util.table.GhidraTable;import ghidra.util.table.GhidraTableFilterPanel;import ghidra.util.task.*;import util.CollectionUtils;@@ -76,7 +75,7 @@ public abstract class AbstractGhidraScriptMgrPluginTestprotected ConsoleService console;protected Program program;- protected GhidraTable scriptTable;+ protected DraggableScriptTable scriptTable;protected JTextPane consoleTextPane;protected GhidraScriptEditorComponentProvider editor;protected JTextArea editorTextArea;@@ -87,7 +86,6 @@ public abstract class AbstractGhidraScriptMgrPluginTest@Beforepublic void setUp() throws Exception {-setErrorGUIEnabled(false);// change the eclipse port so that Eclipse doesn't try to edit the script when@@ -119,16 +117,20 @@ public abstract class AbstractGhidraScriptMgrPluginTest(JTextPane) findComponentByName(consoleProvider.getComponent(), "CONSOLE");assertNotNull(consoleTextPane);- scriptTable = (GhidraTable) findComponentByName(provider.getComponent(), "SCRIPT_TABLE");+ scriptTable =+ (DraggableScriptTable) findComponentByName(provider.getComponent(), "SCRIPT_TABLE");assertNotNull(scriptTable);- // this clears out the static map that accumulates values between tests- GhidraScriptUtil.clearMetadata();- runSwing(() -> provider.refresh());+ clearConsole();cleanupOldTestFiles();- clearConsole();+ // synchronize GhidraScriptUtil static metadata with GUI metadata+ runSwing(() -> provider.refresh());++ waitForSwing();++ System.err.printf("===== Starting %s ======\n", testName.getMethodName());}protected Program buildProgram() throws Exception {@@ -156,16 +158,17 @@ public abstract class AbstractGhidraScriptMgrPluginTest@Afterpublic void tearDown() throws Exception {-closeAllWindows();waitForSwing();- if (testScriptFile != null) {- testScriptFile.delete();+ if (testScriptFile != null && testScriptFile.exists()) {+ deleteFile(testScriptFile);+ testScriptFile = null;}-wipeUserScripts();+ BundleHost.getInstance().removeAllListeners();+env.dispose();}@@ -628,6 +631,15 @@ public abstract class AbstractGhidraScriptMgrPluginTestwaitForSwing();}+ protected void addScriptDirectory(ResourceFile scriptDir) {+ provider.enableScriptDirectory(scriptDir);++ @SuppressWarnings("unchecked")+ List<ResourceFile> scriptBundlePaths =+ (List<ResourceFile>) getInstanceField("scriptBundlePaths", GhidraScriptUtil.class);+ scriptBundlePaths.add(scriptDir);+ }+protected String runScript(String scriptName) throws Exception {clearConsole();@@ -973,6 +985,46 @@ public abstract class AbstractGhidraScriptMgrPluginTest}+ /**+ * rip out GUI listeners from bundle and OSGI components+ * use as follows:+ *+ * <pre>{@code+ * try (var rewire = unwireGUI()) {+ * // ... test code ...+ * }+ * }</pre>+ *+ * @return an undo closure which puts the listeners back in place+ */+ @SuppressWarnings("unchecked")+ protected AutoCloseable unwireGUI() {+ waitForSwing();+ BundleStatusProvider bundleStatusProvider =+ (BundleStatusProvider) TestUtils.getInstanceField("bundleStatusProvider", provider);+ BundleStatusModel bundleStatusModel = bundleStatusProvider.getModel();++ List<BundleStatusListener> bundleStatusListeners =+ (List<BundleStatusListener>) TestUtils.getInstanceField("bundleStatusListeners",+ bundleStatusModel);++ List<BundleStatusListener> storedBundleStatusListeners =+ new ArrayList<>(bundleStatusListeners);+ bundleStatusListeners.clear();++ List<OSGiListener> osgiListeners =+ (List<OSGiListener>) TestUtils.getInstanceField("osgiListeners",+ BundleHost.getInstance());+ ArrayList<OSGiListener> storedOsgiListeners = new ArrayList<>(osgiListeners);+ osgiListeners.clear();++ return () -> {+ waitForSwing();+ bundleStatusListeners.addAll(storedBundleStatusListeners);+ osgiListeners.addAll(storedOsgiListeners);+ };+ }+protected void cleanupOldTestFiles() throws IOException {// remove the compiled bundles directory so that any scripts we use will be recompiledwipe(BundleHost.getCompiledBundlesDir());@@ -983,6 +1035,7 @@ public abstract class AbstractGhidraScriptMgrPluginTestBundleStatusProvider bundleStatusProvider =(BundleStatusProvider) TestUtils.getInstanceField("bundleStatusProvider", provider);List<ResourceFile> paths = bundleStatusProvider.getModel().getEnabledPaths();+for (ResourceFile path : paths) {File file = path.getFile(false);File[] listFiles = file.listFiles();@@ -994,12 +1047,10 @@ public abstract class AbstractGhidraScriptMgrPluginTestString name = dirFile.getName();if (name.startsWith("NewScript") || name.startsWith("Temp") ||name.startsWith(myTestName)) {- dirFile.delete();+ deleteFile(new ResourceFile(dirFile));}}}-- refreshProvider();}protected void closeScriptProvider() {@@ -1211,7 +1262,6 @@ public abstract class AbstractGhidraScriptMgrPluginTest}protected String runScriptAndGetOutput(ResourceFile scriptFile) throws Exception {-GhidraScriptProvider scriptProvider = GhidraScriptUtil.getProvider(scriptFile);GhidraScript script =scriptProvider.getScriptInstance(scriptFile, new PrintWriter(System.err));diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin2Test.javaindex 893069bcdd..dde3b3e8aa 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin2Test.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin2Test.java@@ -56,17 +56,20 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTesString consoleText = getConsoleText();assertTrue("ConsoleText was \"" + consoleText + "\".",consoleText.indexOf("> Hello World") >= 0);+}@Testpublic void testScriptWithInnerClassAndLocalClass() throws Exception {- ResourceFile innerScriptFile = createInnerClassScript();+ try (var rewire = unwireGUI()) {+ ResourceFile innerScriptFile = createInnerClassScript();- String output = runScriptAndGetOutput(innerScriptFile);+ String output = runScriptAndGetOutput(innerScriptFile);- assertTrue("Inner class output not found", output.indexOf("I am an inner class") != -1);- assertTrue("External class output not found",- output.indexOf("I am an external class") != -1);+ assertTrue("Inner class output not found", output.indexOf("I am an inner class") != -1);+ assertTrue("External class output not found",+ output.indexOf("I am an external class") != -1);+ }}@Test@@ -75,47 +78,52 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTes// Test that if a user uses a parent class other than GhidraScript, that parent// class will get recompiled when it changes.//- ResourceFile parentScriptFile = createTempScriptFile("AbstractParentScript");+ try (var rewire = unwireGUI()) {++ ResourceFile parentScriptFile = createTempScriptFile("AbstractParentScript");- String v1Message = "Hello from version 1";- writeAbstractScriptContents(parentScriptFile, v1Message);+ String v1Message = "Hello from version 1";+ writeAbstractScriptContents(parentScriptFile, v1Message);- ResourceFile childScriptFile = createChildScript(parentScriptFile, null);+ ResourceFile childScriptFile = createChildScript(parentScriptFile, null);- String output = runScriptAndGetOutput(childScriptFile);+ String output = runScriptAndGetOutput(childScriptFile);- assertContainsText(v1Message, output);+ assertContainsText(v1Message, output);- // change the parent script- String v2Message = "Hello from version 2";- writeAbstractScriptContents(parentScriptFile, v2Message);+ // change the parent script+ String v2Message = "Hello from version 2";+ writeAbstractScriptContents(parentScriptFile, v2Message);- output = runScriptAndGetOutput(childScriptFile);+ output = runScriptAndGetOutput(childScriptFile);- assertContainsText(v2Message, output);+ assertContainsText(v2Message, output);+ }}@Testpublic void testScriptWithParentInPackageRecompile() throws Exception {+ try (var rewire = unwireGUI()) {- final String parentName = "ParentInPackageScript";- final String packageName = parentName + "Pkg";+ final String parentName = "ParentInPackageScript";+ final String packageName = parentName + "Pkg";- ResourceFile parentScriptFile = createTempScriptFile(parentName, packageName);- writePackageScriptContents(parentScriptFile, packageName);+ ResourceFile parentScriptFile = createTempScriptFile(parentName, packageName);+ writePackageScriptContents(parentScriptFile, packageName);- ResourceFile childScriptFile = createChildScript(parentScriptFile, packageName);+ ResourceFile childScriptFile = createChildScript(parentScriptFile, packageName);- String output = runScriptAndGetOutput(childScriptFile);- assertContainsText("0", output);- output = runScriptAndGetOutput(childScriptFile);- assertContainsText("1", output);+ String output = runScriptAndGetOutput(childScriptFile);+ assertContainsText("0", output);+ output = runScriptAndGetOutput(childScriptFile);+ assertContainsText("1", output);- // Change the parent script so it recompiles and resets its static state- Thread.sleep(1000); // Ensure our file write advances the last modified timestamp- writePackageScriptContents(parentScriptFile, packageName);- output = runScriptAndGetOutput(childScriptFile);- assertContainsText("0", output);+ // Change the parent script so it recompiles and resets its static state+ Thread.sleep(1000); // Ensure our file write advances the last modified timestamp+ writePackageScriptContents(parentScriptFile, packageName);+ output = runScriptAndGetOutput(childScriptFile);+ assertContainsText("0", output);+ }}@Test@@ -124,59 +132,61 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTes// Test that compiling a script to the user's script dir will use a bin dir for the// output.//+ try (var rewire = unwireGUI()) {++ // create a new dummy script+ File userScriptsDir = new File(GhidraScriptUtil.USER_SCRIPTS_DIR);+ String rawScriptName = testName.getMethodName();+ String scriptFilename = rawScriptName + ".java";+ File newScriptFile = new File(userScriptsDir, scriptFilename);+ if (newScriptFile.exists()) {+ assertTrue("Unable to delete script file for testing: " + newScriptFile,+ newScriptFile.delete());+ }- // create a new dummy script- File userScriptsDir = new File(GhidraScriptUtil.USER_SCRIPTS_DIR);- String rawScriptName = testName.getMethodName();- String scriptFilename = rawScriptName + ".java";- File newScriptFile = new File(userScriptsDir, scriptFilename);- if (newScriptFile.exists()) {- assertTrue("Unable to delete script file for testing: " + newScriptFile,- newScriptFile.delete());- }-- JavaScriptProvider scriptProvider = new JavaScriptProvider();- scriptProvider.createNewScript(new ResourceFile(newScriptFile), null);+ JavaScriptProvider scriptProvider = new JavaScriptProvider();+ scriptProvider.createNewScript(new ResourceFile(newScriptFile), null);- // remove all class files from the user script dir (none should ever be there)- FileFilter classFileFilter = file -> file.getName().endsWith(".class");- File[] userScriptDirFiles = userScriptsDir.listFiles(classFileFilter);- for (File file : userScriptDirFiles) {- file.delete();- }- userScriptDirFiles = userScriptsDir.listFiles(classFileFilter);- boolean isEmpty = userScriptDirFiles == null || userScriptDirFiles.length == 0;- assertTrue("Unable to delete class files from the user scripts directory", isEmpty);-- // remove all class files from the user script bin dir- File userScriptsBinDir =- GhidraSourceBundle.getBindirFromScriptFile(new ResourceFile(newScriptFile)).toFile();- File[] userScriptBinDirFiles;- if (userScriptsBinDir.exists()) {- userScriptBinDirFiles = userScriptsBinDir.listFiles(classFileFilter);- for (File file : userScriptBinDirFiles) {+ // remove all class files from the user script dir (none should ever be there)+ FileFilter classFileFilter = file -> file.getName().endsWith(".class");+ File[] userScriptDirFiles = userScriptsDir.listFiles(classFileFilter);+ for (File file : userScriptDirFiles) {file.delete();}- }- userScriptBinDirFiles = userScriptsDir.listFiles(classFileFilter);- isEmpty = userScriptBinDirFiles == null || userScriptBinDirFiles.length == 0;- assertTrue("Unable to delete class files from the bin directory", isEmpty);+ userScriptDirFiles = userScriptsDir.listFiles(classFileFilter);+ boolean isEmpty = userScriptDirFiles == null || userScriptDirFiles.length == 0;+ assertTrue("Unable to delete class files from the user scripts directory", isEmpty);++ // remove all class files from the user script bin dir+ File userScriptsBinDir = GhidraSourceBundle.getBindirFromScriptFile(+ new ResourceFile(newScriptFile)).toFile();+ File[] userScriptBinDirFiles;+ if (userScriptsBinDir.exists()) {+ userScriptBinDirFiles = userScriptsBinDir.listFiles(classFileFilter);+ for (File file : userScriptBinDirFiles) {+ file.delete();+ }+ }+ userScriptBinDirFiles = userScriptsDir.listFiles(classFileFilter);+ isEmpty = userScriptBinDirFiles == null || userScriptBinDirFiles.length == 0;+ assertTrue("Unable to delete class files from the bin directory", isEmpty);- // compile the script- ScriptTaskListener scriptID = env.runScript(newScriptFile);- waitForScriptCompletion(scriptID, 20000);+ // compile the script+ ScriptTaskListener scriptID = env.runScript(newScriptFile);+ waitForScriptCompletion(scriptID, 20000);- // make sure the class file is in the user dir's bin dir- assertTrue("bin dir was not created!", userScriptsBinDir.exists());- File classFile = new File(userScriptsBinDir, rawScriptName + ".class");- assertTrue("Class file was not compiled to the bin dir", classFile.exists());+ // make sure the class file is in the user dir's bin dir+ assertTrue("bin dir was not created!", userScriptsBinDir.exists());+ File classFile = new File(userScriptsBinDir, rawScriptName + ".class");+ assertTrue("Class file was not compiled to the bin dir", classFile.exists());- // make sure no other class files are in the user script dir- userScriptDirFiles = userScriptsDir.listFiles(classFileFilter);- isEmpty = userScriptDirFiles == null || userScriptDirFiles.length == 0;- assertTrue("Class files were written to the top level script directory", isEmpty);+ // make sure no other class files are in the user script dir+ userScriptDirFiles = userScriptsDir.listFiles(classFileFilter);+ isEmpty = userScriptDirFiles == null || userScriptDirFiles.length == 0;+ assertTrue("Class files were written to the top level script directory", isEmpty);- newScriptFile.delete();+ newScriptFile.delete();+ }}@Test@@ -185,23 +195,24 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTes// Tests that a system script will not get compiled to the source tree in which it lives,// but will instead get compiled to the user scripts directory//-- // find a system script- String scriptName = "HelloWorldScript.java";- ResourceFile systemScriptFile = findScript(scriptName);-- // compile the system script- ScriptTaskListener scriptID = env.runScript(systemScriptFile.getFile(false));- waitForScriptCompletion(scriptID, 20000);-- // verify that the generated class file is placed in the default scripting home/bin- File userScriptsBinDir =- GhidraSourceBundle.getBindirFromScriptFile(systemScriptFile).toFile();- String className = scriptName.replace(".java", ".class");- File expectedClassFile = new File(userScriptsBinDir, className);-- assertTrue("System script not compiled to the expected directory",- expectedClassFile.exists());+ try (var rewire = unwireGUI()) {+ // find a system script+ String scriptName = "HelloWorldScript.java";+ ResourceFile systemScriptFile = findScript(scriptName);++ // compile the system script+ ScriptTaskListener scriptID = env.runScript(systemScriptFile.getFile(false));+ waitForScriptCompletion(scriptID, 20000);++ // verify that the generated class file is placed in the default scripting home/bin+ File userScriptsBinDir =+ GhidraSourceBundle.getBindirFromScriptFile(systemScriptFile).toFile();+ String className = scriptName.replace(".java", ".class");+ File expectedClassFile = new File(userScriptsBinDir, className);++ assertTrue("System script not compiled to the expected directory",+ expectedClassFile.exists());+ }}@Test@@ -210,35 +221,43 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTes// Tests that we can create a user-defined scripts directory and that compiling a// script will put the output in the bin directory under the user settings directory.//-- // create a user-defined directory- File tempDir = new File(AbstractGTest.getTestDirectoryPath());- File tempScriptDir = new File(tempDir, "TestScriptDir");- FileUtilities.deleteDir(tempScriptDir);- tempScriptDir.mkdir();-- provider.enableScriptDirectory(new ResourceFile(tempScriptDir));-- // create a script file in that directory- String rawScriptName = testName.getMethodName();- String scriptFilename = rawScriptName + ".java";- File newScriptFile = new File(tempScriptDir, scriptFilename);-- JavaScriptProvider scriptProvider = new JavaScriptProvider();- scriptProvider.createNewScript(new ResourceFile(newScriptFile), null);-- // compile the script- ScriptTaskListener scriptID = env.runScript(newScriptFile);- waitForScriptCompletion(scriptID, 20000);-- // verify a bin dir was created and that the class file is in it- File binDir =- GhidraSourceBundle.getBindirFromScriptFile(new ResourceFile(newScriptFile)).toFile();- assertTrue("bin output dir not created", binDir.exists());-- File scriptClassFile = new File(binDir, rawScriptName + ".class");- assertTrue("Script not compiled to the user-defined script directory",- scriptClassFile.exists());+ try (var rewire = unwireGUI()) {++ // create a user-defined directory+ File tempDir = new File(AbstractGTest.getTestDirectoryPath());+ File tempScriptDir = new File(tempDir, "TestScriptDir");+ FileUtilities.deleteDir(tempScriptDir);+ tempScriptDir.mkdir();++ ResourceFile scriptDir = new ResourceFile(tempScriptDir);+ addScriptDirectory(scriptDir);+ try {+ // create a script file in that directory+ String rawScriptName = testName.getMethodName();+ String scriptFilename = rawScriptName + ".java";+ ResourceFile newScriptFile = new ResourceFile(scriptDir, scriptFilename);++ JavaScriptProvider scriptProvider = new JavaScriptProvider();+ scriptProvider.createNewScript(newScriptFile, null);++ // compile the script+ ScriptTaskListener scriptID = env.runScript(newScriptFile.getFile(false));+ waitForScriptCompletion(scriptID, 20000);++ // verify a bin dir was created and that the class file is in it+ File binDir = GhidraSourceBundle.getBindirFromScriptFile(newScriptFile).toFile();+ assertTrue("bin output dir not created", binDir.exists());++ File scriptClassFile = new File(binDir, rawScriptName + ".class");+ assertTrue("Script not compiled to the user-defined script directory",+ scriptClassFile.exists());++ deleteFile(newScriptFile);+ }+ finally {+ deleteFile(scriptDir);+ }+ }}@Test@@ -280,7 +299,7 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTesassertScriptManagerForgotAbout(oldScript);assertScriptManagerKnowsAbout(newScript);- newScript.delete();+ deleteFile(newScript);}@Test@@ -375,12 +394,13 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTesassertFileSaved(script, changedContents);assertFileInEditor(script);++ deleteFile(script);}@Testpublic void testSaveAsDoesNotAllowOverwriteExistingFileThatScriptManagerDoesNotYetKnowAbout()throws Exception {-//// In this scenario the script manager does not 'know' about the script in question// since we have created it 'behind the scenes'@@ -397,11 +417,13 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTes@Testpublic void testSaveAsDoesNotAllowUseOfExistingScriptName() throws Exception {ResourceFile existingScript = createTempScriptFile();+ System.err.printf("secret script: %s\n", existingScript.toString());refreshProvider();// alert manager to new scriptloadTempScriptIntoEditor();assertCannotPerformSaveAsByNameDueToDuplicate(existingScript.getName());+ deleteFile(existingScript);}@Test@@ -459,35 +481,37 @@ public class GhidraScriptMgrPlugin2Test extends AbstractGhidraScriptMgrPluginTes@Testpublic void testScriptInstancesAreNotReused() throws Exception {-//// Checks for the error where script fields accumulated state because script// instances were reused. Script instances should be recreated for each run.//-- ResourceFile script = createInstanceFieldScript();- String output = runScriptAndGetOutput(script);- assertContainsText("*1*", output);-- output = runScriptAndGetOutput(script);- assertContainsText("The field of the script still has state--the script was not recreated",- "*1*", output);+ try (var rewire = unwireGUI()) {+ ResourceFile script = createInstanceFieldScript();+ String output = runScriptAndGetOutput(script);+ assertContainsText("*1*", output);++ output = runScriptAndGetOutput(script);+ assertContainsText(+ "The field of the script still has state--the script was not recreated", "*1*",+ output);+ }}@Testpublic void testStaticVariableSupport() throws Exception {-//// If the script is not changed, do not reload, which allows for clients to use// static variables to maintain state.//-- ResourceFile script = createStaticFieldScript();- String output = runScriptAndGetOutput(script);- assertContainsText("*1*", output);-- output = runScriptAndGetOutput(script);- assertContainsText("The field of the script still has state--the script was not recreated",- "*2*", output);+ try (var rewire = unwireGUI()) {+ ResourceFile script = createStaticFieldScript();+ String output = runScriptAndGetOutput(script);+ assertContainsText("*1*", output);++ output = runScriptAndGetOutput(script);+ assertContainsText(+ "The field of the script still has state--the script was not recreated", "*2*",+ output);+ }}}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin3Test.javaindex c9bf8a7bd8..83cf5ef4d6 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin3Test.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/script/GhidraScriptMgrPlugin3Test.java@@ -161,7 +161,7 @@ public class GhidraScriptMgrPlugin3Test extends AbstractGhidraScriptMgrPluginTesassertEquals(rowCount + 1, getRowCount());- newScript.delete();+ deleteFile(newScript);}@Test@@ -184,7 +184,7 @@ public class GhidraScriptMgrPlugin3Test extends AbstractGhidraScriptMgrPluginTesassertCategoryInTree(newCategory);assertCategoryNotInTree(oldCategory);- newScript.delete();+ deleteFile(newScript);}@Test@@ -208,7 +208,7 @@ public class GhidraScriptMgrPlugin3Test extends AbstractGhidraScriptMgrPluginTesassertCategoryInTree(newCategory);assertCategoryNotInTree(oldCategory);- newScript.delete();+ deleteFile(newScript);}@Test@@ -394,6 +394,7 @@ public class GhidraScriptMgrPlugin3Test extends AbstractGhidraScriptMgrPluginTeschooseDiscaredEditorChanges();assertFalse("Editor not closed after discarding changes", editor.isVisible());+}@Test