Ghidra is a software reverse engineering (SRE) framework
GP-7066 - Added a section to the Configure Tool dialog to allow users to see all plugins that belong to an extension.
dragonmacherbb0e6c987a44
diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifestindex 6123bdc3c9..4bbc7a8048 100644--- a/Ghidra/Features/Base/certification.manifest+++ b/Ghidra/Features/Base/certification.manifest@@ -1072,6 +1072,7 @@ src/main/resources/images/typedef.png||GHIDRA||||END|src/main/resources/images/unknown.gif||GHIDRA||||END|src/main/resources/images/unlock.gif||GHIDRA||||END|src/main/resources/images/verticalSplit.png||GHIDRA||||END|+src/main/resources/images/view-process-users.32.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END|src/main/resources/images/view-sort-ascending.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END|src/main/resources/images/view-sort-descending.png||Oxygen Icons - LGPL 3.0|||Oxygen icon theme (dual license; LGPL or CC-SA-3.0)|END|src/main/resources/images/view_bottom.png||Nuvola Icons - LGPL 2.1|||Nuvola icon set|END|diff --git a/Ghidra/Features/Base/src/main/resources/images/view-process-users.32.png b/Ghidra/Features/Base/src/main/resources/images/view-process-users.32.pngnew file mode 100644index 0000000000..e64b14cfdfBinary files /dev/null and b/Ghidra/Features/Base/src/main/resources/images/view-process-users.32.png differdiff --git a/Ghidra/Framework/Project/data/project.theme.properties b/Ghidra/Framework/Project/data/project.theme.propertiesindex 5343f77f89..dc1683ef65 100644--- a/Ghidra/Framework/Project/data/project.theme.properties+++ b/Ghidra/Framework/Project/data/project.theme.properties@@ -85,6 +85,7 @@ icon.project.info.convert = wand.pngicon.extension.configure = plugin.pngicon.plugin.manager.default = plasma.png+icon.plugin.manager.extensions = view-process-users.32.pngfont.help.about = font.monospacedfont.keybindings.status = sansserif-plain-11diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginConfigurationModel.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginConfigurationModel.javaindex e14a3be562..0621c23696 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginConfigurationModel.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginConfigurationModel.java@@ -243,4 +243,16 @@ public class PluginConfigurationModel {public List<PluginDescription> getAllPluginDescriptions() {return pluginPackagingProvider.getPluginDescriptions();}++ public List<PluginDescription> getPluginDescriptionsForExtensions() {++ List<PluginDescription> results = new ArrayList<>();+ List<PluginDescription> descriptions = pluginPackagingProvider.getPluginDescriptions();+ for (PluginDescription description : descriptions) {+ if (description.isInExtension()) {+ results.add(description);+ }+ }+ return results;+ }}diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginInstallerTableModel.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginInstallerTableModel.javaindex e9f2ac7df2..2da0074757 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginInstallerTableModel.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginInstallerTableModel.java@@ -16,6 +16,8 @@package ghidra.framework.plugintool.dialog;import java.net.URL;+import java.nio.file.Path;+import java.nio.file.Paths;import java.util.List;import java.util.Map;import java.util.stream.Collectors;@@ -28,7 +30,10 @@ import docking.widgets.table.AbstractDynamicTableColumn;import docking.widgets.table.TableColumnDescriptor;import docking.widgets.table.threaded.ThreadedTableModel;import ghidra.docking.settings.Settings;-import ghidra.framework.plugintool.*;+import ghidra.framework.plugintool.Plugin;+import ghidra.framework.plugintool.PluginConfigurationModel;+import ghidra.framework.plugintool.PluginTool;+import ghidra.framework.plugintool.ServiceProvider;import ghidra.framework.plugintool.util.PluginDescription;import ghidra.framework.plugintool.util.PluginStatus;import ghidra.util.HTMLUtilities;@@ -303,11 +308,7 @@ class PluginInstallerTableModel@Overridepublic String getValue(PluginDescription rowObject, Settings settings,List<PluginDescription> data, ServiceProvider sp) throws IllegalArgumentException {- Class<? extends Plugin> clazz = rowObject.getPluginClass();- String name = clazz.getName();- String path = '/' + name.replace('.', '/') + ".class";- URL url = clazz.getResource(path);- return url.getFile();+ return rowObject.getSourceLocation();}}diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginManagerComponent.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginManagerComponent.javaindex 77d3112457..9aedc603b1 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginManagerComponent.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/dialog/PluginManagerComponent.java@@ -22,7 +22,6 @@ import java.util.List;import javax.accessibility.AccessibleContext;import javax.swing.*;-import docking.EmptyBorderToggleButton;import docking.widgets.GHyperlinkComponent;import docking.widgets.checkbox.GCheckBox;import docking.widgets.label.*;@@ -42,7 +41,7 @@ public class PluginManagerComponent extends JPanel implements Scrollable {private final PluginTool tool;private PluginConfigurationModel model;- private List<PluginPackageComponent> packageComponentList = new ArrayList<>();+ private List<PluginPackagePanel> packageComponentList = new ArrayList<>();PluginManagerComponent(PluginTool tool, PluginConfigurationModel model) {super(new VerticalLayout(2));@@ -54,14 +53,17 @@ public class PluginManagerComponent extends JPanel implements Scrollable {List<PluginPackage> pluginPackages = model.getPluginPackages();for (PluginPackage pluginPackage : pluginPackages) {- PluginPackageComponent comp = new PluginPackageComponent(pluginPackage);- packageComponentList.add(comp);- add(comp);+ PluginPackagePanel panel = new PluginPackagePanel(pluginPackage);+ packageComponentList.add(panel);+ add(panel);}++ ExtensionsPanel extensionsPanel = new ExtensionsPanel();+ add(extensionsPanel);}private void updateCheckboxes() {- for (PluginPackageComponent comp : packageComponentList) {+ for (PluginPackagePanel comp : packageComponentList) {comp.updateCheckBoxState();}}@@ -79,6 +81,13 @@ public class PluginManagerComponent extends JPanel implements Scrollable {tool.showDialog(pluginTableDialog);}+ void manageExtensions() {+ List<PluginDescription> descriptons = model.getPluginDescriptionsForExtensions();+ PluginInstallerDialog pluginInstallerDialog = new PluginInstallerDialog(+ "Configure Extension Plugins", tool, model, descriptons);+ tool.showDialog(pluginInstallerDialog);+ }+PluginConfigurationModel getModel() {return model;}@@ -102,32 +111,57 @@ public class PluginManagerComponent extends JPanel implements Scrollable {}boolean isAddAllCheckBoxEnabled(PluginPackage pluginPackage) {- for (PluginPackageComponent ppc : packageComponentList) {+ for (PluginPackagePanel ppc : packageComponentList) {if (ppc.pluginPackage.equals(pluginPackage)) {- return ppc.checkBox.isEnabled();+ return ppc.selectAllCheckBox.isEnabled();}}throw new AssertException("No checkbox found for " + pluginPackage);}+ @Override+ public Dimension getPreferredScrollableViewportSize() {+ return getPreferredSize();+ }++ @Override+ public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {+ return 50;+ }++ @Override+ public boolean getScrollableTracksViewportHeight() {+ return false;+ }++ @Override+ public boolean getScrollableTracksViewportWidth() {+ return true;+ }++ @Override+ public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {+ return 20;+ }//=================================================================================================// Inner Classes//=================================================================================================- private class PluginPackageComponent extends JPanel {- private Color BG = new GColor("color.bg");- private final PluginPackage pluginPackage;- private final GCheckBox checkBox;+ /** A panel that represents a group of plugins, typically all plugins in a PluginPackage */+ private abstract class GroupPanel extends JPanel {+ protected static final Color BG = new GColor("color.bg");+ protected GCheckBox selectAllCheckBox;- PluginPackageComponent(PluginPackage pluginPackage) {+ GroupPanel() {super(new BorderLayout());setBackground(BG);+ setBorder(BorderFactory.createLineBorder(Colors.BORDER));+ }- this.pluginPackage = pluginPackage;- this.checkBox =createCheckbox();+ protected void build() {+ this.selectAllCheckBox = createCheckBox();- initizalizeCheckBoxSection();initializeLabelSection();initializeDescriptionSection();@@ -135,43 +169,6 @@ public class PluginManagerComponent extends JPanel implements Scrollable {updateCheckBoxState();}- private GCheckBox createCheckbox() {- GCheckBox checkbox = new GCheckBox();- AccessibleContext ac = checkbox.getAccessibleContext();- ac.setAccessibleName(pluginPackage.getName() + " plugin package");- ac.setAccessibleDescription(pluginPackage.getDescription());- return checkbox;- }-- private void initizalizeCheckBoxSection() {- JPanel checkboxPanel = new JPanel(new HorizontalLayout(0));- checkboxPanel.setBackground(BG);-- checkBox.addActionListener(- e -> selectPluginPackage(pluginPackage, checkBox.isSelected()));- if (model.hasOnlyUnstablePlugins(pluginPackage)) {- checkBox.setEnabled(false);- }- checkBox.setBackground(BG);-- checkboxPanel.add(Box.createHorizontalStrut(10));- checkboxPanel.add(checkBox);- checkboxPanel.add(Box.createHorizontalStrut(10));-- Icon icon = pluginPackage.getIcon();- if (icon == null) {- icon = DEFAULT_ICON;- }- JLabel iconLabel = new GIconLabel(ResourceManager.getScaledIcon(icon, 32, 32, 32));- iconLabel.setBackground(BG);-- checkboxPanel.add(iconLabel);- checkboxPanel.add(Box.createHorizontalStrut(10));- checkboxPanel.setPreferredSize(new Dimension(84, 70));-- add(checkboxPanel, BorderLayout.WEST);- }-private void initializeLabelSection() {JPanel centerPanel = new JPanel(new GridBagLayout());GridBagConstraints gbc = new GridBagConstraints();@@ -183,7 +180,7 @@ public class PluginManagerComponent extends JPanel implements Scrollable {JPanel labelPanel = new JPanel(new VerticalLayout(3));labelPanel.setBackground(BG);- GLabel nameLabel = new GLabel(pluginPackage.getName());+ GLabel nameLabel = new GLabel(getGroupName());Gui.registerFont(nameLabel, "font.plugin.package.panel.name");nameLabel.setForeground(new GColor("color.fg.plugin.package.panel.name"));labelPanel.add(nameLabel);@@ -196,15 +193,23 @@ public class PluginManagerComponent extends JPanel implements Scrollable {add(centerPanel);}- private GHyperlinkComponent createConfigureHyperlink() {- GHyperlinkComponent configureHyperlink =- new GHyperlinkComponent();- configureHyperlink.addLink("Configure", "Configure Plugins", () -> {- managePlugins(PluginPackageComponent.this.pluginPackage);- });+ protected abstract String getGroupName();++ protected abstract String getGroupDescription();++ protected abstract Icon getGroupIcon();++ protected abstract void addLink(GHyperlinkComponent link);++ protected abstract GCheckBox createCheckBox();++ protected abstract void updateCheckBoxState();- configureHyperlink.setBackground(BG);- return configureHyperlink;+ private GHyperlinkComponent createConfigureHyperlink() {+ GHyperlinkComponent configureLink = new GHyperlinkComponent();+ addLink(configureLink);+ configureLink.setBackground(BG);+ return configureLink;}private String enchanceDescription(String text) {@@ -212,59 +217,156 @@ public class PluginManagerComponent extends JPanel implements Scrollable {}private void initializeDescriptionSection() {- String htmlDescription = enchanceDescription(pluginPackage.getDescription());+ String description = getGroupDescription();+ String htmlDescription = enchanceDescription(description);JLabel descriptionlabel = new GHtmlLabel(htmlDescription);descriptionlabel.setForeground(new GColor("color.fg.plugin.package.panel.description"));descriptionlabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));descriptionlabel.setVerticalAlignment(SwingConstants.TOP);- descriptionlabel.setToolTipText(- HTMLUtilities.toWrappedHTML(pluginPackage.getDescription(), 80));+ descriptionlabel.setToolTipText(HTMLUtilities.toWrappedHTML(description, 80));add(descriptionlabel, BorderLayout.EAST);}- void updateCheckBoxState() {- checkBox.setSelected(- model.getPackageState(pluginPackage) != PluginPackageState.NO_PLUGINS_LOADED);- }}- static class MyToggleButton extends EmptyBorderToggleButton {- public MyToggleButton(Icon icon) {- super(icon);++ private class ExtensionsPanel extends GroupPanel {++ private static final GIcon ICON = new GIcon("icon.plugin.manager.extensions");++ ExtensionsPanel() {+ build();}@Override- public void setIcon(Icon newIcon) {- Icon scaledIcon = ResourceManager.getScaledIcon(newIcon, 32, 32, 32);- doSetIcon(scaledIcon);+ protected String getGroupName() {+ return "Extensions";}- }- @Override- public Dimension getPreferredScrollableViewportSize() {- return getPreferredSize();- }+ @Override+ protected String getGroupDescription() {+ return "All plugins that belong to an Extension.";+ }- @Override- public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {- return 50;- }+ @Override+ protected Icon getGroupIcon() {+ return ICON;+ }- @Override- public boolean getScrollableTracksViewportHeight() {- return false;- }+ @Override+ protected void addLink(GHyperlinkComponent link) {+ link.addLink("Configure", "Configure Plugins", () -> {+ manageExtensions();+ });+ }++ @Override+ protected GCheckBox createCheckBox() {+ // not checkbox for this group; create a spacer for symmetry++ JPanel iconPanel = new JPanel(new HorizontalLayout(0));+ iconPanel.setBackground(BG);++ iconPanel.add(Box.createHorizontalStrut(40));++ Icon icon = getGroupIcon();+ JLabel iconLabel = new GIconLabel(ResourceManager.getScaledIcon(icon, 32, 32, 32));+ iconLabel.setBackground(BG);++ iconPanel.add(iconLabel);+ iconPanel.add(Box.createHorizontalStrut(10));+ iconPanel.setPreferredSize(new Dimension(84, 70));++ add(iconPanel, BorderLayout.WEST);++ return null;+ }++ @Override+ protected void updateCheckBoxState() {+ // no checkbox for this group+ }- @Override- public boolean getScrollableTracksViewportWidth() {- return true;}- @Override- public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {- return 20;+ private class PluginPackagePanel extends GroupPanel {++ private final PluginPackage pluginPackage;++ PluginPackagePanel(PluginPackage pluginPackage) {+ this.pluginPackage = pluginPackage;+ build();+ }++ @Override+ protected GCheckBox createCheckBox() {+ GCheckBox checkBox = new GCheckBox();+ AccessibleContext ac = checkBox.getAccessibleContext();+ ac.setAccessibleName(getGroupName() + " plugin package");+ ac.setAccessibleDescription(getGroupDescription());++ JPanel checkboxPanel = new JPanel(new HorizontalLayout(0));+ checkboxPanel.setBackground(BG);++ checkBox.addActionListener(+ e -> selectPluginPackage(pluginPackage, checkBox.isSelected()));+ if (model.hasOnlyUnstablePlugins(pluginPackage)) {+ checkBox.setEnabled(false);+ }+ checkBox.setBackground(BG);++ checkboxPanel.add(Box.createHorizontalStrut(10));+ checkboxPanel.add(checkBox);+ checkboxPanel.add(Box.createHorizontalStrut(10));++ Icon icon = getGroupIcon();+ if (icon == null) {+ icon = DEFAULT_ICON;+ }+ JLabel iconLabel = new GIconLabel(ResourceManager.getScaledIcon(icon, 32, 32, 32));+ iconLabel.setBackground(BG);++ checkboxPanel.add(iconLabel);+ checkboxPanel.add(Box.createHorizontalStrut(10));+ checkboxPanel.setPreferredSize(new Dimension(84, 70));++ add(checkboxPanel, BorderLayout.WEST);++ return checkBox;+ }++ @Override+ protected void updateCheckBoxState() {+ PluginPackageState state = model.getPackageState(pluginPackage);+ selectAllCheckBox.setSelected(state != PluginPackageState.NO_PLUGINS_LOADED);+ }++ @Override+ protected String getGroupName() {+ return pluginPackage.getName();+ }++ @Override+ protected Icon getGroupIcon() {+ return pluginPackage.getIcon();+ }++ @Override+ protected String getGroupDescription() {+ return pluginPackage.getDescription();+ }++ @Override+ protected void addLink(GHyperlinkComponent link) {+ link.addLink("Configure", "Configure Plugins", () -> {+ managePlugins(PluginPackagePanel.this.pluginPackage);+ });+ }++}+}diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/util/PluginDescription.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/util/PluginDescription.javaindex 3962a16f75..374a4e848b 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/util/PluginDescription.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/util/PluginDescription.java@@ -16,7 +16,8 @@package ghidra.framework.plugintool.util;import java.lang.reflect.Method;-import java.net.URL;+import java.net.*;+import java.nio.file.Path;import java.util.*;import generic.jar.ResourceFile;@@ -45,7 +46,7 @@ public class PluginDescription implements Comparable<PluginDescription> {* @return {@link PluginDescription}*/public static PluginDescription getPluginDescription(Class<? extends Plugin> c) {- // TODO: sync the hashmap?+ // Note: the cache is not synchronizedPluginDescription cachedPD =CACHE.computeIfAbsent(c, PluginDescription::createPluginDescription);return cachedPD;@@ -116,21 +117,39 @@ public class PluginDescription implements Comparable<PluginDescription> {* @return path to the source file*/public String getSourceLocation() {- String path = url.getFile();+ try {+ return convertToSourceLocation(url);+ } catch (URISyntaxException e) {+ Msg.error(this, "Unexpected bad url: " + url);+ return "<bad source location>";+ }+ }++ private static String convertToSourceLocation(URL url) throws URISyntaxException {++ URI uri;if ("jar".equals(url.getProtocol())) {- int i = path.indexOf('!');- if (i >= 0) {- path = path.substring(0, i);- }- String fileProtoPrefix = "file:";- if (path.startsWith(fileProtoPrefix)) {- path = path.substring(fileProtoPrefix.length() + 1);- }- return '/' + path;++ // strip off the jar protocol+ String file = url.getFile();+ uri = URI.create(file);}- String classpath = pluginClass.getName();- path = path.substring(0, path.length() - classpath.length() - DOTCLASS_EXT.length() - 1);- return '/' + path;+ else {+ uri = url.toURI();+ }++ String parent = Path.of(uri).getParent().toString();++ // Check for a file:/ path pointing to a class inside of a jar file+ String jarSeparator = ".jar!";+ int index = parent.indexOf(jarSeparator);+ if (index != -1) {+ // we want to return just the path to the jar file without the package path+ int bangIndex = index + jarSeparator.length() -1;+ parent = parent.substring(0, bangIndex);+ }++ return parent;}/**@@ -167,10 +186,19 @@ public class PluginDescription implements Comparable<PluginDescription> {* {@return true if this plugin is provided by an extension}*/public boolean isInExtension() {- String myPath = getSourceLocation();++ Path myPath = null;+ try {+ myPath = Path.of(url.toURI());+ }+ catch (URISyntaxException e) {+ Msg.error(this, "Invalid URL for PluginDescription: " + url, e);+ return false;+ }+ApplicationLayout layout = Application.getApplicationLayout();List<ResourceFile> extDirs = layout.getExtensionInstallationDirs();- return FileUtilities.startsWith(extDirs, myPath);+ return FileUtilities.startsWith(extDirs, myPath.toString());}/**