From a68cee1c00deea579553729cf66469383bd9827c Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Wed, 10 Jun 2026 15:55:00 -0400 Subject: [PATCH] GP-6616: Imported non-Programs (i.e., Trace) now try to be opened in the tool that was used to import them --- .../plugin/importer/ImporterUtilities.java | 78 +++++++------------ 1 file changed, 29 insertions(+), 49 deletions(-) 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.java index b6cb02bb28..03db3a8ea6 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 @@ -16,7 +16,6 @@ package ghidra.plugin.importer; import java.awt.Window; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.*; @@ -447,75 +446,56 @@ public class ImporterUtilities { } } - private static void doPostImportProcessing(PluginTool pluginTool, + private static Set doPostImportProcessing(PluginTool pluginTool, ProgramManager programManager, LoadResults loadResults, String importMessages, TaskMonitor monitor) throws CancelledException { - // Optionally echo loader message log to application.log - if (!Loader.loggingDisabled && !importMessages.isEmpty()) { - Msg.info(ImporterUtilities.class, "Import info:\n" + importMessages); - } - - int openFailures = 0; - boolean isFirstFile = true; - DomainFile firstDomainFile = null; - + boolean firstFile = true; Set importedFilesSet = new HashSet<>(); for (Loaded loaded : loadResults) { monitor.checkCancelled(); - - DomainFile savedDomainFile = null; - try { - savedDomainFile = loaded.getSavedDomainFile(); - if (firstDomainFile == null) { - firstDomainFile = savedDomainFile; - } - if (savedDomainFile != null) { - importedFilesSet.add(savedDomainFile); - } - } - catch (FileNotFoundException e) { - // ignore - domain object was not saved - } - Object consumer = new Object(); DomainObject obj = loaded.getDomainObject(consumer); - boolean opened = false; + DomainFile df = obj.getDomainFile(); try { - if (obj instanceof Program && programManager != null) { - int openState = isFirstFile - ? ProgramManager.OPEN_CURRENT - : ProgramManager.OPEN_VISIBLE; - programManager.openProgram((Program) obj, openState); - opened = true; + if (obj instanceof Program) { + if (programManager != null) { + int openState = firstFile + ? ProgramManager.OPEN_CURRENT + : ProgramManager.OPEN_VISIBLE; + programManager.openProgram((Program) obj, openState); + } } - else if (savedDomainFile != null) { - // Attempt to open in tool if it will accept it (e.g., DBTrace from GZT file) - opened = pluginTool.acceptDomainFiles(new DomainFile[] { savedDomainFile }); + else { + // We imported a non-Program (i.e., a Trace or similar). + // Try to open it in the current tool (if not FrontEndTool). + if (!(pluginTool instanceof FrontEndTool)) { + boolean success = pluginTool.acceptDomainFiles(new DomainFile[] { df }); + if (!success) { + importMessages = "Saved " + df + + ", but failed to open it in the current tool.\n" + importMessages; + } + } } - if (isFirstFile) { + if (firstFile) { // currently we only show results for the imported program, not any libraries displayResults(pluginTool, obj, importMessages); + + // Optionally echo loader message log to application.log + if (!Loader.loggingDisabled && !importMessages.isEmpty()) { + Msg.info(ImporterUtilities.class, "Additional info:\n" + importMessages); + } } + firstFile = false; + importedFilesSet.add(df); } finally { obj.release(consumer); } - if (!opened) { - ++openFailures; - } - isFirstFile = false; } selectFiles(importedFilesSet); - - if (openFailures != 0 && pluginTool != AppInfo.getFrontEndTool()) { - // Indicate imports which failed to open in tool - Msg.showInfo(ImporterUtilities.class, null, "Import Notice", - "Unable to open " + openFailures + - " file(s) within current tool after successful import.\n" + - "See selected files in project window."); - } + return importedFilesSet; } private static void selectFiles(Set importedFilesSet) {