Ghidra is a software reverse engineering (SRE) framework
GP-4148 - Added an action to allow editing of data type from anywhere in the tool
dragonmachera797c84de45f
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htm b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htmindex f072007660..f37737d95d 100644--- a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htm+++ b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeManagerPlugin/data_type_manager_description.htm@@ -901,6 +901,17 @@"../DataTypeEditors/StructureEditor.htm"><FONT color="#0000ff">structureeditor</FONT></A> will appear, and for enums the <A href="../DataTypeEditors/EnumEditor.htm">enum editor</A> will appear.</P>+++ <BLOCKQUOTE>+ <P><IMG border="0" src="help/shared/tip.png" alt="">To edit a data type from anywhere+ in the tool, you can activate the global <B>Edit Data Type</B> action from the+ keyboard by pressing <B><I>Ctrl-Shift-D</I></B>. This will present you a+ <A HREF="help/topics/DataTypeEditors/DataTypeSelectionDialog.htm">Data Type Chooser+ Dialog</A> that you can use to choose a type to edit.+ </P>+ </BLOCKQUOTE>+</BLOCKQUOTE><H3><A name="CreateEnumFromSelection"></A>Creating a new Enum from a Selection ofdiff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorListener.javaindex 253c530002..1ff3a98d1a 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorListener.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorListener.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,15 +15,15 @@*/package ghidra.app.plugin.core.compositeeditor;-/**** Interface used for notification when an edit session is ending.*/public interface EditorListener {-+/*** Notification that the editor is closed.+ * @param editor the editor*/public void closed(EditorProvider editor);}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPlugin.javaindex cf1bf7683b..2c12a35369 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypeManagerPlugin.java@@ -30,6 +30,7 @@ import org.apache.commons.lang3.StringUtils;import docking.ActionContext;import docking.Tool;import docking.action.*;+import docking.action.builder.ActionBuilder;import docking.actions.PopupActionProvider;import docking.widgets.tree.GTreeNode;import generic.jar.ResourceFile;@@ -47,6 +48,7 @@ import ghidra.app.plugin.core.datamgr.util.DataDropOnBrowserHandler;import ghidra.app.plugin.core.datamgr.util.DataTypeChooserDialog;import ghidra.app.services.*;import ghidra.app.util.HelpTopics;+import ghidra.app.util.datatype.DataTypeSelectionDialog;import ghidra.framework.Application;import ghidra.framework.main.OpenVersionedFileDialog;import ghidra.framework.model.*;@@ -60,6 +62,7 @@ import ghidra.program.model.data.*;import ghidra.program.model.listing.DataTypeArchive;import ghidra.program.model.listing.Program;import ghidra.util.*;+import ghidra.util.data.DataTypeParser.AllowedDataTypes;import ghidra.util.datastruct.LRUMap;import ghidra.util.exception.CancelledException;import ghidra.util.exception.VersionException;@@ -83,8 +86,8 @@ import ghidra.util.task.TaskMonitor;servicesProvided = { DataTypeManagerService.class, DataTypeArchiveService.class })//@formatter:on-public class DataTypeManagerPlugin extends ProgramPlugin implements DomainObjectListener,- DataTypeManagerService, PopupActionProvider {+public class DataTypeManagerPlugin extends ProgramPlugin+ implements DomainObjectListener, DataTypeManagerService, PopupActionProvider {private static final String EXTENSIONS_PATH_PREFIX = Path.GHIDRA_HOME + "/Extensions";@@ -467,12 +470,36 @@ public class DataTypeManagerPlugin extends ProgramPlugin implements DomainObject*/private void createActions() {createStandardArchivesMenu();++ //@formatter:off+ new ActionBuilder("Edit Data Type", getName())+ .keyBinding("Control Shift D")+ .onAction(this::edit)+ .buildAndInstall(tool);+ //@formatter:on}private void removeRecentAction(DockingAction action) {tool.removeLocalAction(provider, action);}+ private void edit(ActionContext c) {+ DataType dt = chooseType();+ if (dt != null) {+ edit(dt);+ }+ }++ private DataType chooseType() {++ int noSizeRestriction = -1;+ DataTypeSelectionDialog selectionDialog =+ new DataTypeSelectionDialog(tool, null, noSizeRestriction, AllowedDataTypes.ALL);++ tool.showDialog(selectionDialog);+ return selectionDialog.getUserChosenDataType();+ }+//**********************************************************************************************// DataTypeManagerService methods//**********************************************************************************************diff --git a/Ghidra/Features/Sarif/build.gradle b/Ghidra/Features/Sarif/build.gradleindex bee4d880d4..3f62c3b2b6 100644--- a/Ghidra/Features/Sarif/build.gradle+++ b/Ghidra/Features/Sarif/build.gradle@@ -15,6 +15,7 @@*/apply from: "$rootProject.projectDir/gradle/distributableGhidraModule.gradle"apply from: "$rootProject.projectDir/gradle/javaProject.gradle"+apply from: "$rootProject.projectDir/gradle/helpProject.gradle"apply from: "$rootProject.projectDir/gradle/jacocoProject.gradle"apply from: "$rootProject.projectDir/gradle/javaTestProject.gradle"apply plugin: 'eclipse'diff --git a/Ghidra/Features/Sarif/src/main/help/help/topics/Sarif/SARIF.htm b/Ghidra/Features/Sarif/src/main/help/help/topics/Sarif/SARIF.htmindex da6bed2120..e263fe690c 100644--- a/Ghidra/Features/Sarif/src/main/help/help/topics/Sarif/SARIF.htm+++ b/Ghidra/Features/Sarif/src/main/help/help/topics/Sarif/SARIF.htm@@ -51,7 +51,7 @@The default "handle" method takes anything returned by the "parse" method, creates key-value pairs(stored as a map, but...) using "getKey" and the value returned, and adds them to a list of resultsstored in the data frame. These can be retrieved programmatically later or processed immediately.- For example, the SarifPropertyResultHandler looks for results with "AdditionalProperties" labelled+ For example, the SarifPropertyResultHandler looks for results with "AdditionalProperties" labeledeither "viewer/table/xxx" or "listing/[comment, highlight, bookmark]". Items in the second categoryare applied immediately to the current program. Items in the first category are added to the tableunder column "xxx".</P>@@ -73,7 +73,7 @@<UL><LI><A href="help/topics/ImporterPlugin/importer.htm">Importers</A></LI>- <LI><A href="help/topics/ExporterPlugin/importer.htm">Exporters</A></LI>+ <LI><A href="help/topics/ExporterPlugin/exporter.htm">Exporters</A></LI></UL><P> </P>diff --git a/Ghidra/Features/Sarif/src/main/java/sarif/SarifPlugin.java b/Ghidra/Features/Sarif/src/main/java/sarif/SarifPlugin.javaindex 6dadca0383..407a929ff5 100644--- a/Ghidra/Features/Sarif/src/main/java/sarif/SarifPlugin.java+++ b/Ghidra/Features/Sarif/src/main/java/sarif/SarifPlugin.java@@ -17,9 +17,7 @@ package sarif;import java.io.File;import java.io.IOException;-import java.util.HashMap;-import java.util.List;-import java.util.Map;+import java.util.*;import javax.swing.Icon;@@ -30,18 +28,11 @@ import docking.action.builder.ActionBuilder;import docking.tool.ToolConstants;import docking.widgets.filechooser.GhidraFileChooser;import ghidra.MiscellaneousPluginPackage;-import ghidra.app.events.ProgramActivatedPluginEvent;-import ghidra.app.events.ProgramClosedPluginEvent;-import ghidra.app.events.ProgramOpenedPluginEvent;-import ghidra.app.events.ProgramVisibilityChangePluginEvent;+import ghidra.app.events.*;import ghidra.app.plugin.PluginCategoryNames;import ghidra.app.plugin.ProgramPlugin;-import ghidra.framework.options.Options;-import ghidra.framework.options.OptionsChangeListener;-import ghidra.framework.options.ToolOptions;-import ghidra.framework.plugintool.PluginEvent;-import ghidra.framework.plugintool.PluginInfo;-import ghidra.framework.plugintool.PluginTool;+import ghidra.framework.options.*;+import ghidra.framework.plugintool.*;import ghidra.framework.plugintool.util.PluginStatus;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSet;@@ -75,7 +66,7 @@ public class SarifPlugin extends ProgramPlugin implements OptionsChangeListenerpublic SarifPlugin(PluginTool tool) {super(tool);- this.sarifControllers = new HashMap<Program, SarifController>();+ this.sarifControllers = new HashMap<>();this.io = new SarifGsonIO();}@@ -84,13 +75,15 @@ public class SarifPlugin extends ProgramPlugin implements OptionsChangeListenercreateActions();initializeOptions();}-+public void readFile(File file) {if (file != null) {try {showSarif(file.getName(), io.readSarif(file));- } catch (JsonSyntaxException | IOException e) {- Msg.showError(this, tool.getActiveWindow(), "File parse error", "Invalid Sarif File");+ }+ catch (JsonSyntaxException | IOException e) {+ Msg.showError(this, tool.getActiveWindow(), "File parse error",+ "Invalid Sarif File");}}}@@ -135,7 +128,6 @@ public class SarifPlugin extends ProgramPlugin implements OptionsChangeListener}}-/*** Ultimately both selections end up calling this to actually show something on* the Ghidra gui@@ -154,7 +146,7 @@ public class SarifPlugin extends ProgramPlugin implements OptionsChangeListenerif (currentController != null) {currentController.showTable(logName, sarif);return;- }+ }}Msg.showError(this, tool.getActiveWindow(), "File parse error", "No current program");}@@ -166,12 +158,13 @@ public class SarifPlugin extends ProgramPlugin implements OptionsChangeListener}this.setSelection(selection);}-+private void createActions() {//@formatter:offnew ActionBuilder("Read", getName()).menuPath("Sarif", "Read File").menuGroup("sarif", "1")+ .helpLocation(new HelpLocation("Sarif", "Using_SARIF_Files")).enabledWhen(ctx -> getCurrentProgram() != null).onAction(e -> {GhidraFileChooser chooser = new GhidraFileChooser(tool.getActiveWindow());@@ -180,7 +173,7 @@ public class SarifPlugin extends ProgramPlugin implements OptionsChangeListener.buildAndInstall(tool);//@formatter:on}-+private void initializeOptions() {ToolOptions options = tool.getOptions(ToolConstants.GRAPH_OPTIONS);options.addOptionsChangeListener(this);@@ -199,22 +192,21 @@ public class SarifPlugin extends ProgramPlugin implements OptionsChangeListenerOptions sarifOptions = options.getOptions(NAME);loadOptions(sarifOptions);}-+public void registerOptions(Options options, HelpLocation help) {options.setOptionsHelpLocation(help);options.registerOption("Display Artifacts", displayArtifacts(), help,- "Display artifacts by default");+ "Display artifacts by default");options.registerOption("Display Graphs", displayGraphs(), help,- "Display graphs by default");+ "Display graphs by default");options.registerOption("Max Graph Size", getGraphSize(), help,- "Maximum number of nodes per graph");+ "Maximum number of nodes per graph");- options.registerOption("Append Graphs", appendToGraph(), help,- "Append to existing graph");+ options.registerOption("Append Graphs", appendToGraph(), help, "Append to existing graph");}@@ -228,21 +220,25 @@ public class SarifPlugin extends ProgramPlugin implements OptionsChangeListener}private boolean displayGraphsByDefault = false;+public boolean displayGraphs() {return displayGraphsByDefault;}private boolean displayArtifactsByDefault = false;+public boolean displayArtifacts() {return displayArtifactsByDefault;}private int maxGraphSize = 1000;+public int getGraphSize() {return maxGraphSize;}private boolean appendToCurrentGraph = false;+public boolean appendToGraph() {return appendToCurrentGraph;}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/ComponentProvider.java b/Ghidra/Framework/Docking/src/main/java/docking/ComponentProvider.javaindex 324db9f96a..ced187402e 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/ComponentProvider.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/ComponentProvider.java@@ -231,7 +231,6 @@ public abstract class ComponentProvider implements HelpDescriptor, ActionContextreturn;}- dockingTool.toFront();if (defaultFocusComponent != null) {DockingWindowManager.requestFocus(defaultFocusComponent);return;