Merge remote-tracking branch

'origin/GP-4148-dragonmacher-global-data-type-edit-action'
(Closes #5975, Closes #6576)
This commit is contained in:
Ryan Kurtz
2024-05-31 06:13:11 -04:00
7 changed files with 66 additions and 33 deletions
@@ -901,6 +901,17 @@
"../DataTypeEditors/StructureEditor.htm"><FONT color="#0000ff">structure
editor</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 of
@@ -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);
}
@@ -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;
@@ -443,12 +446,36 @@ public class DataTypeManagerPlugin extends ProgramPlugin
*/
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
//**********************************************************************************************
+1
View File
@@ -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'
@@ -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 results
stored 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" labeled
either "viewer/table/xxx" or "listing/[comment, highlight, bookmark]". Items in the second category
are applied immediately to the current program. Items in the first category are added to the table
under 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>&nbsp;</P>
@@ -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 OptionsChangeListener
public 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 OptionsChangeListener
createActions();
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 OptionsChangeListener
if (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:off
new 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 OptionsChangeListener
Options 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;
}
@@ -231,7 +231,6 @@ public abstract class ComponentProvider implements HelpDescriptor, ActionContext
return;
}
dockingTool.toFront();
if (defaultFocusComponent != null) {
DockingWindowManager.requestFocus(defaultFocusComponent);
return;