diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatus.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatus.java index 9772c00a61..320c39c833 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatus.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatus.java @@ -74,7 +74,7 @@ public class BundleStatus implements Comparable { busy = b; } - public boolean getBusy() { + public boolean isBusy() { return busy; } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java index 81e6e35818..89ee83dd0d 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java @@ -37,7 +37,6 @@ import ghidra.app.services.ConsoleService; import ghidra.framework.plugintool.ComponentProviderAdapter; import ghidra.framework.plugintool.PluginTool; import ghidra.framework.preferences.Preferences; -import ghidra.util.Msg; import ghidra.util.exception.CancelledException; import ghidra.util.filechooser.GhidraFileChooserModel; import ghidra.util.filechooser.GhidraFileFilter; @@ -48,7 +47,7 @@ import resources.ResourceManager; * component for managing OSGi bundle status */ public class BundleStatusComponentProvider extends ComponentProviderAdapter { - static String preferenceForLastSelectedBundle = "LastGhidraScriptBundle"; + static String preferenceForLastSelectedBundle = "LastGhidraBundle"; private JPanel panel; private LessFreneticGTable bundleStatusTable; @@ -144,7 +143,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { public Component getTableCellRendererComponent(GTableCellRenderingData data) { BundleStatus status = (BundleStatus) data.getRowObject(); Component x = super.getTableCellRendererComponent(data); - if (status.getBusy()) { + if (status.isBusy()) { cb.setVisible(false); cb.setEnabled(false); setHorizontalAlignment(SwingConstants.CENTER); @@ -196,10 +195,10 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { DockingAction action; // - action = new DockingAction("ActivateBundle", this.getName()) { + action = new DockingAction("ActivateBundles", this.getName()) { @Override public void actionPerformed(ActionContext context) { - doActivateBundle(); + doActivateBundles(); } @Override @@ -207,7 +206,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { return bundleStatusTable.getSelectedRows().length > 0; } }; - action.setPopupMenuData(new MenuData(new String[] { "Activate bundles(s)" }, + action.setPopupMenuData(new MenuData(new String[] { "Activate bundle(s)" }, ResourceManager.loadImage("images/media-playback-start.png"), BUNDLE_GROUP)); action.setToolBarData(new ToolBarData( ResourceManager.loadImage("images/media-playback-start.png"), BUNDLE_GROUP)); @@ -216,10 +215,10 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { getTool().addLocalAction(this, action); // - action = new DockingAction("DeactivateBundle", this.getName()) { + action = new DockingAction("DeactivateBundles", this.getName()) { @Override public void actionPerformed(ActionContext context) { - doDeactivateBundle(); + doDeactivateBundles(); } @Override @@ -227,7 +226,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { return bundleStatusTable.getSelectedRows().length > 0; } }; - action.setPopupMenuData(new MenuData(new String[] { "Deactivate bundles(s)" }, + action.setPopupMenuData(new MenuData(new String[] { "Deactivate bundle(s)" }, ResourceManager.loadImage("images/media-playback-stop.png"), BUNDLE_GROUP)); action.setToolBarData(new ToolBarData( ResourceManager.loadImage("images/media-playback-stop.png"), BUNDLE_GROUP)); @@ -236,7 +235,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { getTool().addLocalAction(this, action); // - action = new DockingAction("CleanBundle", this.getName()) { + action = new DockingAction("CleanBundles", this.getName()) { @Override public void actionPerformed(ActionContext context) { doClean(); @@ -257,7 +256,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { getTool().addLocalAction(this, action); // - action = new DockingAction("AddBundle", this.getName()) { + action = new DockingAction("AddBundles", this.getName()) { @Override public void actionPerformed(ActionContext context) { showAddBundlesFileChooser(); @@ -269,7 +268,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { } }; - action.setPopupMenuData(new MenuData(new String[] { "Add bundle" }, + action.setPopupMenuData(new MenuData(new String[] { "Add bundle(s)" }, ResourceManager.loadImage("images/Plus.png"), BUNDLE_LIST_GROUP)); action.setToolBarData( new ToolBarData(ResourceManager.loadImage("images/Plus.png"), BUNDLE_LIST_GROUP)); @@ -279,7 +278,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { getTool().addLocalAction(this, action); // - action = new DockingAction("RemoveBundle", this.getName()) { + action = new DockingAction("RemoveBundles", this.getName()) { @Override public void actionPerformed(ActionContext context) { doRemoveBundles(); @@ -296,7 +295,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { action.setToolBarData(new ToolBarData(ResourceManager.loadImage("images/edit-delete.png"), BUNDLE_LIST_GROUP)); - action.setDescription("Remove selected bundles"); + action.setDescription("Remove selected bundle(s) from the list"); action.setEnabled(true); getTool().addLocalAction(this, action); } @@ -340,7 +339,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { fileChooser = new GhidraFileChooser(panel); fileChooser.setMultiSelectionEnabled(true); fileChooser.setFileSelectionMode(GhidraFileChooserMode.FILES_AND_DIRECTORIES); - fileChooser.setTitle("Select Script Bundle(s)"); + fileChooser.setTitle("Select Bundle(s)"); // fileChooser.setApproveButtonToolTipText(title); if (filter != null) { fileChooser.addFileFilter(new GhidraFileFilter() { @@ -381,7 +380,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { } } - protected void doActivateBundle() { + protected void doActivateBundles() { ConsoleService console = getTool().getService(ConsoleService.class); int[] selectedModelRows = getSelectedModelRows(); @@ -425,6 +424,9 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { } for (GhidraBundle gb : l) { + if (monitor.isCancelled()) { + break; + } try { gb.build(console.getStdErr()); bundleHost.activateSynchronously(gb.getBundleLoc()); @@ -436,12 +438,17 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { monitor.incrementProgress(1); } } - if (monitor.isCancelled()) { - for (BundleStatus bs : statuses) { + boolean anybusy = false; + for (BundleStatus bs : statuses) { + if (bs.isBusy()) { + anybusy = true; bs.setBusy(false); } + } + if (anybusy) { notifyTableDataChanged(); } + long endTime = System.nanoTime(); console.getStdOut().printf("%d/%d bundles activated in %3.2f seconds.\n", total_activated, total, (endTime - startTime) / 1e9); @@ -451,7 +458,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { }, getComponent(), 1000); } - protected void doDeactivateBundle() { + protected void doDeactivateBundles() { ConsoleService console = getTool().getService(ConsoleService.class); int[] selectedModelRows = getSelectedModelRows(); @@ -507,12 +514,6 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter { } catch (Exception e) { e.printStackTrace(console.getStdErr()); - status.setActive(!activate); - String message = e.getMessage(); - if (message == null) { - message = ""; - } - Msg.showError(this, getComponent(), "bundle activation failed", message); } finally { status.setBusy(false); 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.java index de7875c075..67202972ae 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 @@ -27,7 +27,6 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.Stream; import javax.tools.*; import javax.tools.JavaFileObject.Kind; @@ -655,18 +654,6 @@ public class GhidraSourceBundle extends GhidraBundle { // no manifest, so create one with bndtools Analyzer analyzer = new Analyzer(); analyzer.setJar(new Jar(bindir.toFile())); // give bnd the contents - Stream bjars = Files.list(BundleHost.getCompiledBundlesDir()).filter( - f -> f.toString().endsWith(".jar")).map(f -> { - try { - return new Jar(f.toFile()); - } - catch (IOException e1) { - e1.printStackTrace(writer); - return null; - } - }); - - analyzer.addClasspath(bjars.collect(Collectors.toUnmodifiableList())); analyzer.setProperty("Bundle-SymbolicName", BundleHost.getSymbolicNameFromSourceDir(srcdir)); analyzer.setProperty("Bundle-Version", "1.0"); 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.java index 461877518c..33fb48b025 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 @@ -103,41 +103,6 @@ public class GhidraScriptUtil { scriptNameToFilesMap.clear(); } - /** - * Uses the given name to find a matching script. This method only works because of the - * limitation that all script names in Ghidra must be unique. If the given name has multiple - * script matches, then a warning will be logged. - * - * @param name The name for which to find a script - * @return The ScriptInfo that has the given name - */ - public static ScriptInfo findScriptByName(String name) { - List matchingFiles = scriptNameToFilesMap.get(name); - if (matchingFiles != null && !matchingFiles.isEmpty()) { - ScriptInfo info = scriptFileToInfoMap.get(matchingFiles.get(0)); - if (matchingFiles.size() > 1) { - Msg.warn(GhidraScriptUtil.class, "Found duplicate scripts for name: " + name + - ". Binding to script: " + info.getSourceFile()); - } - return info; - } - - ResourceFile file = findScriptFileInPaths(_bundleHost.getBundlePaths(), name); - if (file == null) { - return null; - } - - return getExistingScriptInfo(file); // this will cache the created info - } - - public static List getAllScripts() { - List scriptList = new ArrayList<>(); - for (ResourceFile dirPath : _bundleHost.getBundlePaths()) { - updateAvailableScriptFilesForDirectory(scriptList, dirPath); - } - return scriptList; - } - /** * Returns a list of the current script directories. * @return a list of the current script directories @@ -470,23 +435,6 @@ public class GhidraScriptUtil { return new ResourceFile(parentDirctory, className); } - /** Returns true if the given filename exists in any of the given directories */ - private static ResourceFile findScriptFileInPaths(Collection scriptDirectories, - String filename) { - - String validatedName = fixupName(filename); - - for (ResourceFile resourceFile : scriptDirectories) { - if (resourceFile.isDirectory()) { - ResourceFile file = new ResourceFile(resourceFile, validatedName); - if (file.exists()) { - return file; - } - } - } - return null; - } - /** * Fixup name issues, such as package parts in the name and inner class names. *

@@ -509,20 +457,51 @@ public class GhidraScriptUtil { return path + ".java"; } - private static void updateAvailableScriptFilesForDirectory(List scriptAccumulator, - ResourceFile directory) { - ResourceFile[] files = directory.listFiles(); - if (files == null) { - return; - } + /** Returns true if the given filename exists in any of the given directories */ + private static ResourceFile findScriptFileInPaths(Collection scriptDirectories, + String filename) { - for (ResourceFile scriptFile : files) { - if (scriptFile.isFile() && hasScriptProvider(scriptFile)) { - scriptAccumulator.add(scriptFile); + String validatedName = fixupName(filename); + + for (ResourceFile resourceFile : scriptDirectories) { + if (resourceFile.isDirectory()) { + ResourceFile file = new ResourceFile(resourceFile, validatedName); + if (file.exists()) { + return file; + } } } + return null; } + /** + * Uses the given name to find a matching script. This method only works because of the + * limitation that all script names in Ghidra must be unique. If the given name has multiple + * script matches, then a warning will be logged. + * + * @param name The name for which to find a script + * @return The ScriptInfo that has the given name + */ + public static ScriptInfo findScriptByName(String name) { + List matchingFiles = scriptNameToFilesMap.get(name); + if (matchingFiles != null && !matchingFiles.isEmpty()) { + ScriptInfo info = scriptFileToInfoMap.get(matchingFiles.get(0)); + if (matchingFiles.size() > 1) { + Msg.warn(GhidraScriptUtil.class, "Found duplicate scripts for name: " + name + + ". Binding to script: " + info.getSourceFile()); + } + return info; + } + + ResourceFile file = findScriptFileInPaths(_bundleHost.getBundlePaths(), name); + if (file == null) { + return null; + } + + return getExistingScriptInfo(file); // this will cache the created info + } + + /* only used by GhidraScriptAnalyzerAdapter */ /** * Runs the specified script with the specified state * @@ -533,6 +512,7 @@ public class GhidraScriptUtil { * @param monitor the task monitor * @return whether the script successfully completed running */ + @Deprecated public static boolean runScript(GhidraState scriptState, GhidraScript script, PrintWriter writer, Object originator, TaskMonitor monitor) { @@ -557,4 +537,31 @@ public class GhidraScriptUtil { return true; } + @Deprecated + private static void updateAvailableScriptFilesForDirectory(List scriptAccumulator, + ResourceFile directory) { + ResourceFile[] files = directory.listFiles(); + if (files == null) { + return; + } + + for (ResourceFile scriptFile : files) { + if (scriptFile.isFile() && hasScriptProvider(scriptFile)) { + scriptAccumulator.add(scriptFile); + } + } + } + + /* + * used only by RecipeEditorDialog + */ + @Deprecated + public static List getAllScripts() { + List scriptList = new ArrayList<>(); + for (ResourceFile dirPath : _bundleHost.getBundlePaths()) { + updateAvailableScriptFilesForDirectory(scriptList, dirPath); + } + return scriptList; + } + }