Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3193 - Tool - Fixed bug that caused exported tool to exclude plugin config settings

dragonmacherfeb5d6902253
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/Tool/Ghidra_Tool_Administration.htm b/Ghidra/Features/Base/src/main/help/help/topics/Tool/Ghidra_Tool_Administration.htm
index 8031bc4cb5..432a8eb8bb 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/Tool/Ghidra_Tool_Administration.htm
+++ b/Ghidra/Features/Base/src/main/help/help/topics/Tool/Ghidra_Tool_Administration.htm
@@ -197,6 +197,25 @@
jar file in one of the <A href=
"help/topics/FrontEndPlugin/Edit_Plugin_Path.htm#SearchOrder">locations</A> where Ghidra
will search for available Plugins.</I>&nbsp;</P>
+
+
+ <H4><A name="Export_Default_Tool"></A>Export Default Tool</H4>
+
+ <BLOCKQUOTE>
+ <P>Exports the chosen tool <b>without including user configuration information</b>.
+ This allows the user to export a tool without including personal settings. This
+ may be helpful if the user is going to share the exported tool with others.
+ </P>
+ <P>This action is only available from within a running tool via
+ <B><FONT size="4">
+ File <IMG src="../../shared/arrow.gif">
+ Export <IMG src="../../shared/arrow.gif">
+ Export Default Tool...
+ </FONT>
+ </B>
+ </P>
+ </BLOCKQUOTE>
+
</BLOCKQUOTE>
<H3>Import Tool</H3>
@@ -204,55 +223,56 @@
<BLOCKQUOTE>
<H4><A name="Import_Tool"></A>Import Tool to Tool Chest</H4>
- <P>Use the Import Tool option to import an <A href="#Export_Tool">exported tool</A>&nbsp;
- into Ghidra.&nbsp; The imported tool will appear in your <A href=
- "help/topics/FrontEndPlugin/Ghidra_Front_end.htm#ToolChest">Tool Chest</A> with the other
- tools. If the name of the imported tool already exists, a one-up number is assigned to the
- newly imported tool to make the name unique.</P>
-
- <P>To import a tool,</P>
-
- <OL>
- <LI>From the Ghidra Project Window, select <B><FONT size="4">Tools</FONT></B><IMG src=
- "../../shared/arrow.gif"> <B><FONT size="4">Import Tool to Tool Chest...</FONT></B></LI>
-
- <LI>Select a file with a ".tool" or ".obj" extension.</LI>
-
- <LI>Click on the <B><FONT size="4">Import</FONT></B> button.</LI>
- </OL>
-
- <P>If the import was successful, an icon for the tool is added to the Tool Chest panel. Any
- errors during the import are reported in the <A href=
- "help/topics/FrontEndPlugin/Ghidra_Front_end.htm#StatusWindow">Status</A> area on the
- Ghidra Project Window.</P>
-
- <P><I><IMG src="../../shared/note.png"> If the tool that you are importing contains Plugins
- that are not part of Ghidra, you must have the jar file containing the class files for the
- Plugins. Place the jar file in one of the <A href=
- "help/topics/FrontEndPlugin/Edit_Plugin_Path.htm#SearchOrder">locations</A> where Ghidra
- will search for available Plugins and restart Ghidra.</I></P>
- </BLOCKQUOTE>
-
- <H4><A name="Import_Ghidra_Tools"></A>Import Default Tools to Tool Chest</H4>
-
- <BLOCKQUOTE>
- <P>The default tool for the <A href="help/topics/CodeBrowserPlugin/CodeBrowser.htm">Code
- Browser</A> is part of the Ghidra installation, and can be added to your Tool Chest at any
- time. So if you <A href="#Delete_Tool">delete</A> the default tool from your Tool Chest,
- you can always recover them by using the <B><FONT size="4">Import Default Tools to Tool
- Chest</FONT></B> option.</P>
-
- <P>To import default tools,</P>
-
- <OL>
- <LI>From the <A href="help/topics/FrontEndPlugin/Ghidra_Front_end.htm">Ghidra Project
- Window</A>, select <B><FONT size="4">Tools</FONT></B><IMG src="../../shared/arrow.gif">
- <FONT size="4"><B>Import Default...</B>.</FONT></LI>
-
- <LI><FONT size="4">A dialog is displayed that allows you to selectively import default
- tools. Select the tools you want to import and then select <B>OK</B>.</FONT></LI>
- </OL>
- </BLOCKQUOTE>
+ <BLOCKQUOTE>
+ <P>Use the Import Tool option to import an <A href="#Export_Tool">exported tool</A>&nbsp;
+ into Ghidra.&nbsp; The imported tool will appear in your <A href=
+ "help/topics/FrontEndPlugin/Ghidra_Front_end.htm#ToolChest">Tool Chest</A> with the other
+ tools. If the name of the imported tool already exists, a one-up number is assigned to the
+ newly imported tool to make the name unique.</P>
+
+ <P>To import a tool,</P>
+
+ <OL>
+ <LI>From the Ghidra Project Window, select <B><FONT size="4">Tools</FONT></B><IMG src=
+ "../../shared/arrow.gif"> <B><FONT size="4">Import Tool to Tool Chest...</FONT></B></LI>
+
+ <LI>Select a file with a ".tool" or ".obj" extension.</LI>
+
+ <LI>Click on the <B><FONT size="4">Import</FONT></B> button.</LI>
+ </OL>
+
+ <P>If the import was successful, an icon for the tool is added to the Tool Chest panel. Any
+ errors during the import are reported in the <A href=
+ "help/topics/FrontEndPlugin/Ghidra_Front_end.htm#StatusWindow">Status</A> area on the
+ Ghidra Project Window.</P>
+
+ <P><I><IMG src="../../shared/note.png"> If the tool that you are importing contains Plugins
+ that are not part of Ghidra, you must have the jar file containing the class files for the
+ Plugins. Place the jar file in one of the <A href=
+ "help/topics/FrontEndPlugin/Edit_Plugin_Path.htm#SearchOrder">locations</A> where Ghidra
+ will search for available Plugins and restart Ghidra.</I></P>
+ </BLOCKQUOTE>
+
+ <H4><A name="Import_Ghidra_Tools"></A>Import Default Tools to Tool Chest</H4>
+
+ <BLOCKQUOTE>
+ <P>The default tool for the <A href="help/topics/CodeBrowserPlugin/CodeBrowser.htm">Code
+ Browser</A> is part of the Ghidra installation, and can be added to your Tool Chest at any
+ time. So if you <A href="#Delete_Tool">delete</A> the default tool from your Tool Chest,
+ you can always recover them by using the <B><FONT size="4">Import Default Tools to Tool
+ Chest</FONT></B> option.</P>
+
+ <P>To import default tools,</P>
+
+ <OL>
+ <LI>From the <A href="help/topics/FrontEndPlugin/Ghidra_Front_end.htm">Ghidra Project
+ Window</A>, select <B><FONT size="4">Tools</FONT></B><IMG src="../../shared/arrow.gif">
+ <FONT size="4"><B>Import Default...</B>.</FONT></LI>
+
+ <LI><FONT size="4">A dialog is displayed that allows you to selectively import default
+ tools. Select the tools you want to import and then select <B>OK</B>.</FONT></LI>
+ </OL>
+ </BLOCKQUOTE>
<DIV align="center">
<IMG src="images/ImportDefaultToolsDialog.png"><BR>
@@ -265,19 +285,11 @@
CodeBrowser_1.</LI>
</OL>
</BLOCKQUOTE>
-
-
- <H4><A name="Export_Default_Tool"></A>Export Default Tool</H4>
-
- <BLOCKQUOTE>
- <P><A HREF="#Export_Tool">Exports</A> the chosen tool <b>without including user configuration information</b>.
- This allows the user to export a tool without including personal settings. This
- may be helpful if the user is going to share the exported tool with others.
- </P>
</BLOCKQUOTE>
+
<H3><A name="Run_Tool"></A>Run Tool</H3>
<BLOCKQUOTE>
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/framework/project/tool/ToolSaving3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/framework/project/tool/ToolSaving3Test.java
index 89efc101a6..808e842856 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/framework/project/tool/ToolSaving3Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/framework/project/tool/ToolSaving3Test.java
@@ -25,7 +25,6 @@ import org.junit.Test;
import docking.action.DockingActionIf;
import docking.widgets.OptionDialog;
-import docking.widgets.dialogs.InputWithChoicesDialog;
import docking.widgets.filechooser.GhidraFileChooser;
import ghidra.framework.ToolUtils;
import ghidra.framework.plugintool.PluginTool;
@@ -87,10 +86,6 @@ public class ToolSaving3Test extends AbstractToolSavingTest {
DockingActionIf exportAction = getAction(tool1, "Export Default Tool");
performAction(exportAction, false);
- InputWithChoicesDialog chooseToolDialog =
- waitForDialogComponent(InputWithChoicesDialog.class);
- pressButtonByText(chooseToolDialog, "OK");
-
GhidraFileChooser chooser = waitForDialogComponent(GhidraFileChooser.class);
File exportedFile = createTempFile("ExportedDefaultTool", ToolUtils.TOOL_EXTENSION);
chooser.setSelectedFile(exportedFile);
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndPlugin.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndPlugin.java
index 15a8addafa..63ab08215f 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndPlugin.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/main/FrontEndPlugin.java
@@ -642,20 +642,35 @@ public class FrontEndPlugin extends Plugin
*/
void exportToolConfig(ToolTemplate template, String msgSource) {
+ ToolTemplate updatedTeplate = getUpToDateTemplate(template);
ToolServices services = activeProject.getToolServices();
try {
- File savedFile = services.exportTool(template);
+ File savedFile = services.exportTool(updatedTeplate);
if (savedFile != null) {
- Msg.info(this, msgSource + ": Successfully exported " + template.getName() +
+ Msg.info(this, msgSource + ": Successfully exported " + updatedTeplate.getName() +
" to " + savedFile.getAbsolutePath());
}
}
catch (Exception e) {
- Msg.showError(this, null, "Error", "Error exporting tool tool", e);
+ Msg.showError(this, null, "Error Exporting Tool", "Error exporting tool tool", e);
}
}
+ private ToolTemplate getUpToDateTemplate(ToolTemplate template) {
+
+ ToolManager toolManager = activeProject.getToolManager();
+ Tool[] runningTools = toolManager.getRunningTools();
+ String templateName = template.getName();
+ for (Tool runningTool : runningTools) {
+ if (runningTool.getName().equals(templateName)) {
+ return runningTool.getToolTemplate(true);
+ }
+ }
+
+ return template;
+ }
+
private void updateConnectionPanel(Project project) {
repositoryLabel.setText(" ");
connectionIconPanel.remove(connectionLabel);
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginTool.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginTool.java
index 94b136af0d..30615f55f3 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginTool.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/PluginTool.java
@@ -972,6 +972,12 @@ public abstract class PluginTool extends AbstractDockingTool implements Tool, Se
}
protected void addExportToolAction() {
+
+ String menuGroup = "Tool";
+ String exportPullright = "Export";
+ setMenuGroup(new String[] { ToolConstants.MENU_FILE, exportPullright }, menuGroup);
+
+ int subGroup = 1;
DockingAction exportToolAction =
new DockingAction("Export Tool", ToolConstants.TOOL_OWNER) {
@Override
@@ -979,11 +985,10 @@ public abstract class PluginTool extends AbstractDockingTool implements Tool, Se
dialogMgr.exportTool();
}
};
- MenuData menuData =
- new MenuData(new String[] { ToolConstants.MENU_FILE, "Export Tool..." }, null, "Tool");
- menuData.setMenuSubGroup("3Tool");
+ MenuData menuData = new MenuData(
+ new String[] { ToolConstants.MENU_FILE, exportPullright, "Export Tool..." });
+ menuData.setMenuSubGroup(Integer.toString(subGroup++));
exportToolAction.setMenuBarData(menuData);
-
exportToolAction.setHelpLocation(
new HelpLocation(ToolConstants.TOOL_HELP_TOPIC, "Export_Tool"));
addAction(exportToolAction);
@@ -995,8 +1000,10 @@ public abstract class PluginTool extends AbstractDockingTool implements Tool, Se
dialogMgr.exportDefaultTool();
}
};
- exportDefautToolAction.setMenuBarData(new MenuData(
- new String[] { ToolConstants.MENU_TOOLS, "Export Default Tool..." }, null, "Tool"));
+ menuData = new MenuData(
+ new String[] { ToolConstants.MENU_FILE, exportPullright, "Export Default Tool..." });
+ menuData.setMenuSubGroup(Integer.toString(subGroup++));
+ exportDefautToolAction.setMenuBarData(menuData);
exportDefautToolAction.setHelpLocation(
new HelpLocation(ToolConstants.TOOL_HELP_TOPIC, "Export_Default_Tool"));
diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/DialogManager.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/DialogManager.java
index 8ef0f3d20a..5d74790a92 100644
--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/DialogManager.java
+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/DialogManager.java
@@ -16,25 +16,19 @@
package ghidra.framework.plugintool.mgr;
import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Collectors;
-import docking.widgets.OptionDialog;
-import docking.widgets.filechooser.GhidraFileChooser;
-import ghidra.framework.model.*;
+import ghidra.framework.model.ToolServices;
+import ghidra.framework.model.ToolTemplate;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.dialog.SaveToolConfigDialog;
import ghidra.util.Msg;
/**
- * Helper class to manage actions for saving and exporting the tool.
- *
+ * Helper class to manage actions for saving and exporting the tool
*/
public class DialogManager {
private PluginTool tool;
private SaveToolConfigDialog saveToolDialog;
- private GhidraFileChooser ghidraFileChooser;
public DialogManager(PluginTool tool) {
this.tool = tool;
@@ -43,7 +37,7 @@ public class DialogManager {
/**
* Show the "Save Tool" dialog. Returns true if the user performed a 'save as'; returns false
* if the user cancelled.
- *
+ * @return false if the user cancelled
*/
public boolean saveToolAs() {
if (saveToolDialog == null) {
@@ -62,6 +56,15 @@ public class DialogManager {
exportTool(template);
}
+ /**
+ * Exports a version of our tool without any config settings. This is useful for making a
+ * new 'default' tool to be shared with others, which will not contain any user settings.
+ */
+ public void exportDefaultTool() {
+ ToolTemplate template = tool.getToolTemplate(false);
+ exportTool(template);
+ }
+
private void exportTool(ToolTemplate template) {
ToolServices services = tool.getProject().getToolServices();
try {
@@ -75,35 +78,4 @@ public class DialogManager {
Msg.showError(this, null, "Error", "Error exporting tool tool", e);
}
}
-
- /**
- * Exports a version of our tool without any config settings. This is useful for making a
- * new 'default' tool to be shared with others, which will not contain any user settings.
- */
- public void exportDefaultTool() {
-
- Project project = tool.getProject();
- ToolChest toolChest = project.getLocalToolChest();
- ToolTemplate[] templates = toolChest.getToolTemplates();
- List<String> namesList =
- Arrays.stream(templates).map(t -> t.getName()).collect(Collectors.toList());
- if (namesList.isEmpty()) {
- Msg.showInfo(this, null, "No Tools", "There are no tools to export");
- return;
- }
-
- String[] names = namesList.toArray(new String[namesList.size()]);
- String choice = OptionDialog.showInputChoiceDialog(null, "Choose Tool", "Choose Tool",
- names, null, OptionDialog.QUESTION_MESSAGE);
- if (choice == null) {
- return;
- }
-
- ToolTemplate template = toolChest.getToolTemplate(choice);
- Tool templateTool = template.createTool(project);
- ToolTemplate defaultTemplate = templateTool.getToolTemplate(false);
-
- exportTool(defaultTemplate);
- }
-
}