Ghidra is a software reverse engineering (SRE) framework
GP-5899 FidPlugin startup speed
dev747368f53671b43d05
diff --git a/Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/db/FidFileManager.java b/Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/db/FidFileManager.javaindex 4c8d54bece..f731a3b4f1 100644--- a/Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/db/FidFileManager.java+++ b/Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/db/FidFileManager.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.@@ -114,6 +114,21 @@ public class FidFileManager {return files;}+ public boolean hasFidFiles() {+ loadFidFiles();+ return !fidFiles.isEmpty();+ }++ public boolean hasUserFidFiles() {+ loadFidFiles();+ for (FidFile fidFile : fidFiles) {+ if (!fidFile.isInstalled()) {+ return true;+ }+ }+ return false;+ }+/*** Returns a list of all the user added (non installation) Fid files. This will* be files containing packed databases.diff --git a/Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/FidPlugin.java b/Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/FidPlugin.javaindex 930c6141ab..67ce059209 100644--- a/Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/FidPlugin.java+++ b/Ghidra/Features/FunctionID/src/main/java/ghidra/feature/fid/plugin/FidPlugin.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.@@ -19,13 +19,10 @@ import java.io.File;import java.io.IOException;import java.util.List;-import javax.swing.SwingUtilities;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;-import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;+import docking.action.builder.ActionBuilder;import docking.tool.ToolConstants;import docking.widgets.filechooser.GhidraFileChooser;import docking.widgets.filechooser.GhidraFileChooserMode;@@ -67,23 +64,13 @@ public class FidPlugin extends ProgramPlugin implements ChangeListener {private FidService service;private FidFileManager fidFileManager;- private DockingAction chooseAction;- private DockingAction createAction;- private DockingAction attachAction;- private DockingAction detachAction;- private DockingAction populateAction;-public FidPlugin(PluginTool tool) {super(tool);}@Overridepublic void stateChanged(ChangeEvent e) {- SwingUtilities.invokeLater(() -> updateActions());- }-- private void updateActions() {- enableActions();+ tool.contextChanged(null); // update fid action enablement}@Override@@ -93,7 +80,6 @@ public class FidPlugin extends ProgramPlugin implements ChangeListener {fidFileManager.addChangeListener(this);service = new FidService();createStandardActions();- enableActions();}@Override@@ -107,80 +93,54 @@ public class FidPlugin extends ProgramPlugin implements ChangeListener {* FID databases would want to use.*/private void createStandardActions() {- DockingAction action;-- action = new DockingAction("Choose Active FidDbs", getName()) {- @Override- public void actionPerformed(ActionContext context) {- chooseActiveFidDbs();- }- };- action.setMenuBarData(new MenuData(- new String[] { ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Choose active FidDbs..." },- null, MENU_GROUP_1, MenuData.NO_MNEMONIC, "1"));- action.setDescription("Select which FidDbs are used during Fid Search");- action.setHelpLocation(new HelpLocation(FID_HELP, "chooseactivemenu"));- tool.addAction(action);- chooseAction = action;-- action = new DockingAction("Create new empty FidDb", getName()) {- @Override- public void actionPerformed(ActionContext context) {- createFidDb();- }- };- action.setMenuBarData(- new MenuData(new String[] { ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME,- "Create new empty FidDb..." }, null, MENU_GROUP_1, MenuData.NO_MNEMONIC, "2"));- action.setDescription("Create a new, empty FidDb file in your file system");- action.setHelpLocation(new HelpLocation(FID_HELP, "createemptyfid"));- tool.addAction(action);- createAction = action;-- action = new DockingAction("Attach existing FidDb", getName()) {- @Override- public void actionPerformed(ActionContext context) {- attachFidDb();- }- };- action.setMenuBarData(new MenuData(- new String[] { ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Attach existing FidDb..." },- null, MENU_GROUP_1, MenuData.NO_MNEMONIC, "3"));- action.setDescription("Attach an existing FidDb file from your file system");- action.setHelpLocation(new HelpLocation(FID_HELP, "attachfid"));- tool.addAction(action);- attachAction = action;-- action = new DockingAction("Detach attached FidDb", getName()) {- @Override- public void actionPerformed(ActionContext context) {- removeFidFile();- }- };- action.setMenuBarData(new MenuData(- new String[] { ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Detach attached FidDb..." },- null, MENU_GROUP_1, MenuData.NO_MNEMONIC, "4"));- action.setDescription("Detach an already attached FidDb");- action.setHelpLocation(new HelpLocation(FID_HELP, "detachfid"));- tool.addAction(action);- detachAction = action;-- action = new DockingAction("Populate FidDb from programs", getName()) {- @Override- public void actionPerformed(ActionContext context) {- PopulateFidDialog populateFidDialog = new PopulateFidDialog(tool, service);- tool.showDialog(populateFidDialog);- }- };- action.setMenuBarData(new MenuData(- new String[] { ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME,- "Populate FidDb from programs..." },- null, MENU_GROUP_1, MenuData.NO_MNEMONIC, "5"));- action.setDescription("Populate an existing FidDb with all programs under a domain folder");- action.setHelpLocation(new HelpLocation(FID_HELP, "populatedialog"));- tool.addAction(action);- populateAction = action;-+ new ActionBuilder("Choose Active FidDbs", getName())+ .enabledWhen(ac -> fidFileManager.hasFidFiles())+ .onAction(ac -> chooseActiveFidDbs())+ .menuPath(ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Choose active FidDbs...")+ .menuGroup(MENU_GROUP_1, "1")+ .description("Select which FidDbs are used during Fid Search")+ .helpLocation(new HelpLocation(FID_HELP, "chooseactivemenu"))+ .buildAndInstall(tool);++ new ActionBuilder("Create new empty FidDb", getName())+ .enabledWhen(ac -> true)+ .onAction(ac -> createFidDb())+ .menuPath(ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Create new empty FidDb...")+ .menuGroup(MENU_GROUP_1, "2")+ .description("Create a new, empty FidDb file in your file system")+ .helpLocation(new HelpLocation(FID_HELP, "createemptyfid"))+ .buildAndInstall(tool);++ new ActionBuilder("Attach existing FidDb", getName())+ .enabledWhen(ac -> true)+ .onAction(ac -> attachFidDb())+ .menuPath(ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Attach existing FidDb...")+ .menuGroup(MENU_GROUP_1, "3")+ .description("Attach an existing FidDb file from your file system")+ .helpLocation(new HelpLocation(FID_HELP, "attachfid"))+ .buildAndInstall(tool);++ new ActionBuilder("Detach attached FidDb", getName())+ .enabledWhen(ac -> fidFileManager.hasUserFidFiles())+ .onAction(ac -> removeFidFile())+ .menuPath(ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Detach attached FidDb...")+ .menuGroup(MENU_GROUP_1, "4")+ .description("Detach an already attached FidDb")+ .helpLocation(new HelpLocation(FID_HELP, "detachfid"))+ .buildAndInstall(tool);++ new ActionBuilder("Populate FidDb from programs", getName())+ .enabledWhen(ac -> fidFileManager.hasUserFidFiles())+ .onAction(ac -> {+ PopulateFidDialog populateFidDialog = new PopulateFidDialog(tool, service);+ tool.showDialog(populateFidDialog);+ })+ .menuPath(ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME,+ "Populate FidDb from programs...")+ .menuGroup(MENU_GROUP_1, "5")+ .description("Populate an existing FidDb with all programs under a domain folder")+ .helpLocation(new HelpLocation(FID_HELP, "populatedialog"))+ .buildAndInstall(tool);}/**@@ -243,19 +203,6 @@ public class FidPlugin extends ProgramPlugin implements ChangeListener {}}- /**- * Method to properly set action enablement based upon appropriate business logic.- */- private void enableActions() {- boolean atLeastOneFidDb = fidFileManager.getFidFiles().size() > 0;- boolean atLeastOneUserFidDb = fidFileManager.getUserAddedFiles().size() > 0;- chooseAction.setEnabled(atLeastOneFidDb);- createAction.setEnabled(true);- attachAction.setEnabled(true);- detachAction.setEnabled(atLeastOneUserFidDb);- populateAction.setEnabled(atLeastOneUserFidDb);- }-/*** Method to ask for a file (copied from GhidraScript).* @param title popup window title