Ghidra is a software reverse engineering (SRE) framework
GP-4805 persist Batch Import dialog checkbox state
dev747368a759c6e81fd4
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterPlugin.javaindex 9deb1e2224..b2746c7263 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugin/importer/ImporterPlugin.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.@@ -20,7 +20,8 @@ import java.awt.event.KeyEvent;import java.io.File;import java.io.IOException;import java.nio.CharBuffer;-import java.util.*;+import java.util.ArrayList;+import java.util.List;import docking.ActionContext;import docking.action.*;@@ -91,6 +92,7 @@ public class ImporterPlugin extends Pluginprivate GhidraFileChooser chooser;private FrontEndService frontEndService;private DockingAction batchImportAction;+ private FileSystemService fsService;public ImporterPlugin(PluginTool tool) {super(tool);@@ -163,22 +165,11 @@ public class ImporterPlugin extends Pluginreturn;}- BatchImportDialog.showAndImport(tool, null, files2FSRLs(files), destFolder,+ List<FSRL> fsrls = files.stream().map(f -> fsService().getLocalFSRL(f)).toList();+ BatchImportDialog.showAndImport(tool, null, fsrls, destFolder,getTool().getService(ProgramManager.class));}- private List<FSRL> files2FSRLs(List<File> files) {- if (files == null) {- return Collections.emptyList();- }-- List<FSRL> result = new ArrayList<>(files.size());- for (File f : files) {- result.add(FileSystemService.getInstance().getLocalFSRL(f));- }- return result;- }-@Overridepublic void importFile(DomainFolder folder, File file) {@@ -190,7 +181,7 @@ public class ImporterPlugin extends Pluginreturn;}- FSRL fsrl = FileSystemService.getInstance().getLocalFSRL(file);+ FSRL fsrl = fsService().getLocalFSRL(file);ProgramManager manager = tool.getService(ProgramManager.class);ImporterUtilities.showImportDialog(tool, manager, fsrl, folder, null);}@@ -480,7 +471,7 @@ public class ImporterPlugin extends PluginProgramManager manager = tool.getService(ProgramManager.class);Program program = manager.getCurrentProgram();- FSRL fsrl = FileSystemService.getInstance().getLocalFSRL(file);+ FSRL fsrl = fsService().getLocalFSRL(file);TaskLauncher.launchModal("Show Add To Program Dialog", monitor -> {ImporterUtilities.showAddToProgramDialog(fsrl, program, tool, monitor);});@@ -501,12 +492,11 @@ public class ImporterPlugin extends Plugintry {Memory memory = program.getMemory();- FileSystemService fsService = FileSystemService.getInstance();// create a tmp ByteProvider that contains the bytes from the selected regionFileCacheEntry tmpFile;try (FileCacheEntryBuilder tmpFileBuilder =- fsService.createTempFile(range.getLength())) {+ fsService().createTempFile(range.getLength())) {byte[] bytes = new byte[(int) range.getLength()];memory.getBytes(range.getMinAddress(), bytes);tmpFileBuilder.write(bytes);@@ -517,7 +507,7 @@ public class ImporterPlugin extends PluginString rangeName =block.getName() + "[" + range.getMinAddress() + "," + range.getMaxAddress() + "]";ByteProvider bp =- fsService.getNamedTempFile(tmpFile, program.getName() + " " + rangeName);+ fsService().getNamedTempFile(tmpFile, program.getName() + " " + rangeName);LoaderMap loaderMap = LoaderService.getAllSupportedLoadSpecs(bp);ImporterDialog importerDialog = new ImporterDialog(tool,@@ -531,4 +521,12 @@ public class ImporterPlugin extends PluginMsg.showError(this, null, "Memory Access Error Occurred", e.getMessage(), e);}}++ private FileSystemService fsService() {+ // use a delayed initialization so we don't force the FileSystemService to initialize+ if (fsService == null) {+ fsService = FileSystemService.getInstance();+ }+ return fsService;+ }}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 e6850a5554..5be8d74b19 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@@ -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.@@ -217,7 +217,7 @@ public class ImporterUtilities {programManager, monitor);}else if (choice == 2) {- BatchImportDialog.showAndImport(tool, null, Arrays.asList(fullFsrl), destinationFolder,+ BatchImportDialog.showAndImport(tool, null, List.of(fullFsrl), destinationFolder,programManager);}else if (choice == 3) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/plugins/importer/batch/BatchImportDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/plugins/importer/batch/BatchImportDialog.javaindex 658720af75..13c0882a17 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/plugins/importer/batch/BatchImportDialog.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/plugins/importer/batch/BatchImportDialog.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.@@ -42,8 +42,10 @@ import generic.theme.GThemeDefaults.Colors.Messages;import ghidra.app.services.ProgramManager;import ghidra.formats.gfilesystem.FSRL;import ghidra.formats.gfilesystem.FileSystemService;+import ghidra.framework.main.AppInfo;import ghidra.framework.model.DomainFolder;import ghidra.framework.plugintool.PluginTool;+import ghidra.framework.preferences.Preferences;import ghidra.plugin.importer.ImporterUtilities;import ghidra.plugins.importer.batch.BatchGroup.BatchLoadConfig;import ghidra.plugins.importer.tasks.ImportBatchTask;@@ -53,6 +55,8 @@ import ghidra.util.task.TaskLauncher;public class BatchImportDialog extends DialogComponentProvider {+ private static final String PREF_STRIPCONTAINER = "BATCHIMPORT.STRIPCONTAINER";+ private static final String PREF_STRIPLEADING = "BATCHIMPORT.STRIPLEADING";private static final String LAST_IMPORT_DIR = "LastBatchImportDir";/**@@ -71,10 +75,8 @@ public class BatchImportDialog extends DialogComponentProvider {*/public static void showAndImport(PluginTool tool, BatchInfo batchInfo, List<FSRL> initialFiles,DomainFolder defaultFolder, ProgramManager programManager) {- BatchImportDialog dialog = new BatchImportDialog(batchInfo, defaultFolder);- dialog.setProgramManager(programManager);+ BatchImportDialog dialog = new BatchImportDialog(batchInfo, defaultFolder, programManager);SystemUtilities.runSwingLater(() -> {- dialog.build();if (initialFiles != null && !initialFiles.isEmpty()) {dialog.addSources(initialFiles);}@@ -88,8 +90,8 @@ public class BatchImportDialog extends DialogComponentProvider {private BatchInfo batchInfo;private DomainFolder destinationFolder;private ProgramManager programManager;- private boolean stripLeading = true;- private boolean stripContainer = false;+ private boolean stripLeading = getBooleanPref(PREF_STRIPLEADING, true);+ private boolean stripContainer = getBooleanPref(PREF_STRIPCONTAINER, false);private boolean openAfterImporting = false;private BatchImportTableModel tableModel;@@ -100,17 +102,22 @@ public class BatchImportDialog extends DialogComponentProvider {private SourcesListModel sourceListModel;- private BatchImportDialog(BatchInfo batchInfo, DomainFolder defaultFolder) {+ private BatchImportDialog(BatchInfo batchInfo, DomainFolder defaultFolder,+ ProgramManager programManager) {super("Batch Import", true);this.batchInfo = (batchInfo != null) ? batchInfo : new BatchInfo();this.destinationFolder = defaultFolder != null ? defaultFolder- : ghidra.framework.main.AppInfo.getActiveProject().getProjectData().getRootFolder();+ : AppInfo.getActiveProject().getProjectData().getRootFolder();+ this.programManager = programManager;+setHelpLocation(new HelpLocation("ImporterPlugin", "Batch_Import_Dialog"));// a reasonable size that is long enough to show path information and table columns with// a height that has enough room to show table rows and import sourcessetPreferredSize(900, 600);++ build();}private void build() {@@ -417,9 +424,7 @@ public class BatchImportDialog extends DialogComponentProvider {private boolean addSources(List<FSRL> filesToAdd) {- List<FSRL> updatedFiles = filesToAdd.stream()- .map(FSRL::convertRootToContainer)- .collect(Collectors.toList());+ List<FSRL> updatedFiles = filesToAdd.stream().map(FSRL::convertRootToContainer).toList();List<FSRL> badFiles = batchInfo.addFiles(updatedFiles);if (!badFiles.isEmpty()) {@@ -589,10 +594,12 @@ public class BatchImportDialog extends DialogComponentProvider {private void setStripLeading(boolean stripLeading) {this.stripLeading = stripLeading;+ setBooleanPref(PREF_STRIPLEADING, stripLeading);}private void setStripContainer(boolean stripContainer) {this.stripContainer = stripContainer;+ setBooleanPref(PREF_STRIPCONTAINER, stripContainer);}private void setMaxDepth(int newMaxDepth) {@@ -604,7 +611,12 @@ public class BatchImportDialog extends DialogComponentProvider {refreshData();}- private void setProgramManager(ProgramManager programManager) {- this.programManager = programManager;+ private static boolean getBooleanPref(String name, boolean defaultValue) {+ return Boolean+ .parseBoolean(Preferences.getProperty(name, Boolean.toString(defaultValue), true));+ }++ private static void setBooleanPref(String name, boolean value) {+ Preferences.setProperty(name, Boolean.toString(value));}}