Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-2847 protecting against non-available icons on theme export.

ghidragon78474c7f974a
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/options/editor/IconPropertyEditor.java b/Ghidra/Framework/Docking/src/main/java/docking/options/editor/IconPropertyEditor.java
index 684abc50cf..d04d76393c 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/options/editor/IconPropertyEditor.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/options/editor/IconPropertyEditor.java
@@ -102,12 +102,46 @@ public class IconPropertyEditor extends PropertyEditorSupport {
}
private void updateDropDownDataModel(Icon icon) {
- Set<Icon> icons = ResourceManager.getLoadedUrlIcons();
+ Set<Icon> icons = getCoreIcons();
icons.add(icon);
dataModel.setData(new ArrayList<>(icons));
dropDown.setSelectedValue(icon);
}
+ /**
+ * Returns all icons loaded by core Ghidra modules. For this use, we only want to use
+ * icons that are part of a standard distribution because if they are exported, they may
+ * not be available on import. Non-core icons can be used by picking them from the file
+ * system.
+ * @Return all icons loaded by core Ghidra modules
+ */
+ private Set<Icon> getCoreIcons() {
+ Set<Icon> loadedIcons = ResourceManager.getLoadedIcons();
+ Set<Icon> filtered = new HashSet<>();
+ for (Icon icon : loadedIcons) {
+ if (isCoreIcon(icon)) {
+ filtered.add(icon);
+ }
+ }
+ return filtered;
+ }
+
+ private boolean isCoreIcon(Icon icon) {
+ if (icon instanceof UrlImageIcon urlIcon) {
+ String path = urlIcon.getUrl().getPath();
+ if (path.contains("Ghidra/Framework")) {
+ return true;
+ }
+ if (path.contains("Ghidra/Features")) {
+ return true;
+ }
+ if (path.contains("Ghidra/Debug")) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void build() {
setLayout(new BorderLayout());
add(buildTopPanel(), BorderLayout.NORTH);
diff --git a/Ghidra/Framework/Gui/src/main/java/resources/ResourceManager.java b/Ghidra/Framework/Gui/src/main/java/resources/ResourceManager.java
index 424a7add97..8ce414c26c 100644
--- a/Ghidra/Framework/Gui/src/main/java/resources/ResourceManager.java
+++ b/Ghidra/Framework/Gui/src/main/java/resources/ResourceManager.java
@@ -552,15 +552,12 @@ public class ResourceManager {
return icon == null ? new UnresolvedIcon(iconPath, DEFAULT_ICON) : icon;
}
- public static Set<Icon> getLoadedUrlIcons() {
- Set<Icon> icons = new HashSet<>();
- for (Icon icon : iconMap.values()) {
- if (icon instanceof UrlImageIcon) {
- icons.add(icon);
- }
- }
-
- return icons;
+ /**
+ * Returns a list of all loaded icons.
+ * @return a list of all loaded icons
+ */
+ public static Set<Icon> getLoadedIcons() {
+ return new HashSet<>(iconMap.values());
}
private static UrlImageIcon doLoadIcon(String path) {
@@ -654,8 +651,7 @@ public class ResourceManager {
if (url != null) {
return new UrlImageIcon(BOMB, url);
}
- Msg.error(ResourceManager.class,
- "Could not find default icon: " + BOMB);
+ Msg.error(ResourceManager.class, "Could not find default icon: " + BOMB);
return getImageIcon(new ColorIcon3D(Color.RED, 16, 16));
}