Ghidra is a software reverse engineering (SRE) framework
GP-5031 PR #7070 followup, invert '.' dot logic, use ext for txt, jpg
dev747368cdf309cfc750
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/fileinfo/FileAttributeType.java b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/fileinfo/FileAttributeType.javaindex f112d7496c..7464dfb954 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/fileinfo/FileAttributeType.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/formats/gfilesystem/fileinfo/FileAttributeType.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -56,7 +56,7 @@ public enum FileAttributeType {SYMLINK_DEST_ATTR("Symbolic link destination", MISC_INFO, String.class),COMMENT_ATTR("Comment", MISC_INFO, String.class),- FILENAME_EXT_OVERRIDE("Extension override", MISC_INFO, String.class),+ FILENAME_EXT_OVERRIDE("Extension override", MISC_INFO, String.class), // no leading '.'UNKNOWN_ATTRIBUTE("Other attribute", ADDITIONAL_INFO, Object.class);@@ -64,7 +64,7 @@ public enum FileAttributeType {private final FileAttributeTypeGroup group;private final Class<?> valueType;- private FileAttributeType(String displayName, FileAttributeTypeGroup group,+ FileAttributeType(String displayName, FileAttributeTypeGroup group,Class<?> valueType) {this.displayName = displayName;this.group = group;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterUtilities.java b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterUtilities.javaindex b4d60c9ac1..12e8dc4adb 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterUtilities.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterUtilities.java@@ -59,16 +59,13 @@ public class ImporterUtilities {/*** File extension filter for well known 'loadable' files for GhidraFileChoosers.- *- * TODO: will be refactored to use file_extension_icon.xml file info.*/public static final GhidraFileFilter LOADABLE_FILES_FILTER = ExtensionFileFilter.forExtensions(- "Loadable files", "exe", "dll", "obj", "drv", "bin", "hex", "o", "a", "so", "class", "lib");+ "Loadable files", "exe", "dll", "obj", "drv", "bin", "hex", "o", "a", "so", "class", "lib",+ "dylib");/*** File extension filter for well known 'container' files for GhidraFileChoosers.- *- * TODO: will be refactored to use file_extension_icon.xml file info.*/public static final GhidraFileFilter CONTAINER_FILES_FILTER =ExtensionFileFilter.forExtensions("Container files", "zip", "tar", "tgz", "jar", "gz",diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBComponentProvider.javaindex e4a74757dd..c2cb043236 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBComponentProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBComponentProvider.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -194,16 +194,16 @@ public class FSBComponentProvider extends ComponentProviderAdapterString ext = node.getFilenameExtOverride();if (ext != null && !ext.isEmpty()) {- if (!ext.startsWith(".")) {- Msg.error(this, "Extension override '" + ext + "' does not begin with a dot");+ if (ext.startsWith(".")) {+ Msg.error(this,+ "Extension override '" + ext + "' should not begin with a dot");} else {- filename += ext;+ filename += "." + ext;}}Icon icon = fsbIcons.getIcon(filename, overlays);setIcon(icon);-}});}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBFileNode.java b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBFileNode.javaindex 17391b73ec..16092d4927 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBFileNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBFileNode.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -88,6 +88,13 @@ public class FSBFileNode extends FSBNode {return filenameExtOverride;}+ @Override+ public String getFileExtension() {+ return filenameExtOverride != null && !filenameExtOverride.isEmpty()+ ? filenameExtOverride+ : super.getFileExtension();+ }+@Overridepublic int hashCode() {return file.hashCode();diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBNode.java b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBNode.javaindex 77394ccffe..1ef3d60012 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/FSBNode.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -22,6 +22,8 @@ import java.util.stream.Collectors;import javax.swing.Icon;import javax.swing.tree.TreePath;+import org.apache.commons.io.FilenameUtils;+import docking.widgets.tree.GTreeNode;import docking.widgets.tree.GTreeSlowLoadingNode;import ghidra.formats.gfilesystem.*;@@ -65,6 +67,15 @@ public abstract class FSBNode extends GTreeSlowLoadingNode {return getFSRL().getName();}+ /**+ * Returns the extension of this node's name, or "" if none+ *+ * @return extension of this node's name, or "" if none+ */+ public String getFileExtension() {+ return FilenameUtils.getExtension(getName());+ }+public FSBRootNode getFSBRootNode() {GTreeNode node = getParent();while (node != null) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/filehandlers/ImageFSBFileHandler.java b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/filehandlers/ImageFSBFileHandler.javaindex 0dc29075f2..ce11503015 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/filehandlers/ImageFSBFileHandler.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/filehandlers/ImageFSBFileHandler.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -22,8 +22,6 @@ import java.util.Set;import javax.swing.*;-import org.apache.commons.io.FilenameUtils;-import docking.action.DockingAction;import docking.action.builder.ActionBuilder;import docking.widgets.label.GIconLabel;@@ -48,9 +46,7 @@ public class ImageFSBFileHandler implements FSBFileHandler {@Overridepublic boolean fileDefaultAction(FSBFileNode fileNode) {- FSRL fsrl = fileNode.getFSRL();- String extension = FilenameUtils.getExtension(fsrl.getName().toLowerCase());- if (COMMON_IMAGE_EXTENSIONS.contains(extension)) {+ if (COMMON_IMAGE_EXTENSIONS.contains(fileNode.getFileExtension().toLowerCase())) {FSBComponentProvider fsbComponent = context.fsbComponent();fsbComponent.runTask(monitor -> doViewAsImage(fileNode.getFSRL(),fsbComponent.getComponent(), monitor));diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/filehandlers/TextFSBFileHandler.java b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/filehandlers/TextFSBFileHandler.javaindex 329a8255ac..163faffa9d 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/filehandlers/TextFSBFileHandler.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugins/fsbrowser/filehandlers/TextFSBFileHandler.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -46,7 +46,7 @@ public class TextFSBFileHandler implements FSBFileHandler {@Overridepublic boolean fileDefaultAction(FSBFileNode fileNode) {- if (fileNode.getName().toLowerCase().endsWith(".txt")) {+ if (fileNode.getFileExtension().equalsIgnoreCase("txt")) {FSBComponentProvider fsbComponent = context.fsbComponent();fsbComponent.runTask(monitor -> doViewAsText(fileNode.getFSRL(), fsbComponent.getComponent(), monitor));