mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
Merge remote-tracking branch
'origin/GP-5899_dev747368_fidplugin_startup_speed' (#7887)
This commit is contained in:
commit
39c6a6db59
2 changed files with 65 additions and 103 deletions
|
@ -114,6 +114,21 @@ public class FidFileManager {
|
||||||
return files;
|
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
|
* Returns a list of all the user added (non installation) Fid files. This will
|
||||||
* be files containing packed databases.
|
* be files containing packed databases.
|
||||||
|
|
|
@ -19,13 +19,10 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
import docking.ActionContext;
|
import docking.action.builder.ActionBuilder;
|
||||||
import docking.action.DockingAction;
|
|
||||||
import docking.action.MenuData;
|
|
||||||
import docking.tool.ToolConstants;
|
import docking.tool.ToolConstants;
|
||||||
import docking.widgets.filechooser.GhidraFileChooser;
|
import docking.widgets.filechooser.GhidraFileChooser;
|
||||||
import docking.widgets.filechooser.GhidraFileChooserMode;
|
import docking.widgets.filechooser.GhidraFileChooserMode;
|
||||||
|
@ -67,23 +64,13 @@ public class FidPlugin extends ProgramPlugin implements ChangeListener {
|
||||||
private FidService service;
|
private FidService service;
|
||||||
private FidFileManager fidFileManager;
|
private FidFileManager fidFileManager;
|
||||||
|
|
||||||
private DockingAction chooseAction;
|
|
||||||
private DockingAction createAction;
|
|
||||||
private DockingAction attachAction;
|
|
||||||
private DockingAction detachAction;
|
|
||||||
private DockingAction populateAction;
|
|
||||||
|
|
||||||
public FidPlugin(PluginTool tool) {
|
public FidPlugin(PluginTool tool) {
|
||||||
super(tool);
|
super(tool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
SwingUtilities.invokeLater(() -> updateActions());
|
tool.contextChanged(null); // update fid action enablement
|
||||||
}
|
|
||||||
|
|
||||||
private void updateActions() {
|
|
||||||
enableActions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,7 +80,6 @@ public class FidPlugin extends ProgramPlugin implements ChangeListener {
|
||||||
fidFileManager.addChangeListener(this);
|
fidFileManager.addChangeListener(this);
|
||||||
service = new FidService();
|
service = new FidService();
|
||||||
createStandardActions();
|
createStandardActions();
|
||||||
enableActions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -107,80 +93,54 @@ public class FidPlugin extends ProgramPlugin implements ChangeListener {
|
||||||
* FID databases would want to use.
|
* FID databases would want to use.
|
||||||
*/
|
*/
|
||||||
private void createStandardActions() {
|
private void createStandardActions() {
|
||||||
DockingAction 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);
|
||||||
|
|
||||||
action = new DockingAction("Choose Active FidDbs", getName()) {
|
new ActionBuilder("Create new empty FidDb", getName())
|
||||||
@Override
|
.enabledWhen(ac -> true)
|
||||||
public void actionPerformed(ActionContext context) {
|
.onAction(ac -> createFidDb())
|
||||||
chooseActiveFidDbs();
|
.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")
|
||||||
action.setMenuBarData(new MenuData(
|
.helpLocation(new HelpLocation(FID_HELP, "createemptyfid"))
|
||||||
new String[] { ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Choose active FidDbs..." },
|
.buildAndInstall(tool);
|
||||||
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()) {
|
new ActionBuilder("Attach existing FidDb", getName())
|
||||||
@Override
|
.enabledWhen(ac -> true)
|
||||||
public void actionPerformed(ActionContext context) {
|
.onAction(ac -> attachFidDb())
|
||||||
createFidDb();
|
.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")
|
||||||
action.setMenuBarData(
|
.helpLocation(new HelpLocation(FID_HELP, "attachfid"))
|
||||||
new MenuData(new String[] { ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME,
|
.buildAndInstall(tool);
|
||||||
"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()) {
|
new ActionBuilder("Detach attached FidDb", getName())
|
||||||
@Override
|
.enabledWhen(ac -> fidFileManager.hasUserFidFiles())
|
||||||
public void actionPerformed(ActionContext context) {
|
.onAction(ac -> removeFidFile())
|
||||||
attachFidDb();
|
.menuPath(ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Detach attached FidDb...")
|
||||||
}
|
.menuGroup(MENU_GROUP_1, "4")
|
||||||
};
|
.description("Detach an already attached FidDb")
|
||||||
action.setMenuBarData(new MenuData(
|
.helpLocation(new HelpLocation(FID_HELP, "detachfid"))
|
||||||
new String[] { ToolConstants.MENU_TOOLS, FUNCTION_ID_NAME, "Attach existing FidDb..." },
|
.buildAndInstall(tool);
|
||||||
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("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).
|
* Method to ask for a file (copied from GhidraScript).
|
||||||
* @param title popup window title
|
* @param title popup window title
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue