Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3292 - Decompiler - Secondary Highlights - Checkpoint 6 - Added help and rearranged the context menu actions

dragonmacherea7dd49f07b8
diff --git a/Ghidra/Features/Decompiler/src/main/help/help/topics/DecompilePlugin/Decompiler.htm b/Ghidra/Features/Decompiler/src/main/help/help/topics/DecompilePlugin/Decompiler.htm
index b9077a8c2e..c248437dfc 100644
--- a/Ghidra/Features/Decompiler/src/main/help/help/topics/DecompilePlugin/Decompiler.htm
+++ b/Ghidra/Features/Decompiler/src/main/help/help/topics/DecompilePlugin/Decompiler.htm
@@ -721,6 +721,79 @@
contribute to the creation of the value in the variable under the cursor.</P>
</BLOCKQUOTE>
+ <BR>
+ <BR>
+ <BR>
+ <!-- Secondary Highlights -->
+ <BLOCKQUOTE>
+
+ <H2>Secondary Highlights</H2>
+ <BLOCKQUOTE>
+ <P>
+ Secondary highlights are highlights that you can apply to text that will
+ stay until you remove them (this is in contrast to normal highlights, which go
+ away whenever you click in the Decompiler). Further, each secondary highlight will get a
+ different color (chosen randomly or by the user). The Decompiler will remember
+ the color previously used for a particular highlighted piece of text <b>for a
+ given Ghidra session</b>. Use the actions listed below to add and remove
+ secondary highlights.
+ </P>
+
+ <H3><A name="Set_Secondary_Highlight"></A>Set Secondary Highlight</H3>
+
+ <BLOCKQUOTE>
+ <P>
+ Use this action to apply a secondary highlight to all text matching the text of the
+ token under the cursor. This action will reuse the previously applied color for
+ that text or choose a new color randomly. This action is accessible from the
+ context menu via
+ <b>Secondary Highlight<img border="0" src="../../shared/arrow.gif">Set Highlight</b>
+ </P>
+ </BLOCKQUOTE>
+
+ <H3><A name="Set_Secondary_Highlight_With_Color"></A>Set Secondary Highlight With Color</H3>
+
+ <BLOCKQUOTE>
+ <P>
+ Use this action to apply a secondary highlight to all text matching the text of the
+ token under the cursor. This action will show a Color Chooser dialog initialized with
+ the previously applied color for
+ that text or choose a new color randomly. This action is accessible from the
+ context menu via
+ <b>Secondary Highlight<img border="0" src="../../shared/arrow.gif">Set Highlight...</b>
+ </P>
+ </BLOCKQUOTE>
+
+ <H3><A name="Remove_Secondary_Highlight"></A>Remove Secondary Highlight</H3>
+
+ <BLOCKQUOTE>
+ <P>
+ Use this action to remove an existing secondary highlight under the cursor.
+ This action is accessible from the context menu via
+ <b>Secondary Highlight<img border="0" src="../../shared/arrow.gif">Remove Highlight</b>
+ </P>
+ </BLOCKQUOTE>
+
+
+ <H3><A name="Remove_All_Secondary_Highlights"></A>Remove All Secondary Highlights</H3>
+
+ <BLOCKQUOTE>
+ <P>
+ Use this action to remove all existing secondary highlights.
+ This action is accessible from the context menu via
+ <b>Secondary Highlight<img border="0" src="../../shared/arrow.gif">Remove All Highlights</b>
+ </P>
+ </BLOCKQUOTE>
+
+
+ </BLOCKQUOTE>
+ </BLOCKQUOTE>
+
+ <!-- End Secondary Highlights -->
+ <BR>
+ <BR>
+ <BR>
+
<H3><A name="Rename_Variable"></A>Rename Variable</H3>
<BLOCKQUOTE>
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangFieldElement.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangFieldElement.java
index a0430cce7d..920475991c 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangFieldElement.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangFieldElement.java
@@ -15,7 +15,8 @@
*/
package ghidra.app.decompiler.component;
-import java.awt.*;
+import java.awt.Color;
+import java.awt.Graphics;
import javax.swing.JComponent;
@@ -37,9 +38,9 @@ public class ClangFieldElement extends AbstractTextFieldElement {
@Override
public void paint(JComponent c, Graphics g, int x, int y) {
- Paint highlightColor = token.getHighlight();
+ Color highlightColor = token.getHighlight();
if (highlightColor != null) {
- ((Graphics2D) g).setPaint(highlightColor);
+ g.setColor(highlightColor);
g.fillRect(x, y - getHeightAbove(), getStringWidth(),
getHeightAbove() + getHeightBelow());
}
@@ -48,7 +49,7 @@ public class ClangFieldElement extends AbstractTextFieldElement {
if (token.isMatchingToken()) {
// paint a bounding box around the token
- ((Graphics2D) g).setPaint(Color.GRAY);
+ g.setColor(Color.GRAY);
int offset = 1;
g.drawRect(x - offset, y - getHeightAbove() - offset, getStringWidth() + (offset * 2),
getHeightAbove() + getHeightBelow() + (offset * 2));
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/HighlightToken.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/HighlightToken.java
index 3d16368367..29acf550de 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/HighlightToken.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/HighlightToken.java
@@ -17,11 +17,11 @@ package ghidra.app.decompiler.component;
import java.awt.Color;
-import ghidra.app.decompiler.ClangFunction;
import ghidra.app.decompiler.ClangToken;
-import ghidra.program.model.listing.Function;
-// TODO better name: TokenHighlight
+/**
+ * A class to used to track a {@link Decompiler} token along with its highlight color
+ */
public class HighlightToken {
private ClangToken token;
@@ -40,17 +40,6 @@ public class HighlightToken {
return color;
}
- public Function getFunction() {
- if (token == null) {
- return null;
- }
- ClangFunction clangFunc = token.getClangFunction();
- if (clangFunc == null) {
- return null;
- }
- return clangFunc.getHighFunction().getFunction();
- }
-
@Override
public String toString() {
return token.toString() + "; color=" + color;
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
index 8867deaa25..6dd8a05718 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java
@@ -785,21 +785,6 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
editDataTypeAction = new EditDataTypeAction(tool, controller);
setGroupInfo(editDataTypeAction, variableGroup, subGroupPosition++);
- defUseHighlightAction = new HighlightDefinedUseAction(controller);
- setGroupInfo(defUseHighlightAction, variableGroup, subGroupPosition++);
-
- forwardSliceAction = new ForwardSliceAction(controller);
- setGroupInfo(forwardSliceAction, variableGroup, subGroupPosition++);
-
- backwardSliceAction = new BackwardsSliceAction();
- setGroupInfo(backwardSliceAction, variableGroup, subGroupPosition++);
-
- forwardSliceToOpsAction = new ForwardSliceToPCodeOpsAction(controller);
- setGroupInfo(forwardSliceToOpsAction, variableGroup, subGroupPosition++);
-
- backwardSliceToOpsAction = new BackwardsSliceToPCodeOpsAction(controller);
- setGroupInfo(backwardSliceToOpsAction, variableGroup, subGroupPosition++);
-
//
// Listing action for Creating Structure on a Variable
//
@@ -817,12 +802,29 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter
lockLocalAction = new CommitLocalsAction(tool, controller);
setGroupInfo(lockLocalAction, commitGroup, subGroupPosition++);
- String highlightGroup = "4 - Highlight Group";
subGroupPosition = 0; // reset for the next group
//
// Highlight
//
+ String highlightGroup = "4a - Highlight Group";
+ tool.setMenuGroup(new String[] { "Highlight" }, highlightGroup);
+ defUseHighlightAction = new HighlightDefinedUseAction(controller);
+ setGroupInfo(defUseHighlightAction, highlightGroup, subGroupPosition++);
+
+ forwardSliceAction = new ForwardSliceAction(controller);
+ setGroupInfo(forwardSliceAction, highlightGroup, subGroupPosition++);
+
+ backwardSliceAction = new BackwardsSliceAction();
+ setGroupInfo(backwardSliceAction, highlightGroup, subGroupPosition++);
+
+ forwardSliceToOpsAction = new ForwardSliceToPCodeOpsAction(controller);
+ setGroupInfo(forwardSliceToOpsAction, highlightGroup, subGroupPosition++);
+
+ backwardSliceToOpsAction = new BackwardsSliceToPCodeOpsAction(controller);
+ setGroupInfo(backwardSliceToOpsAction, highlightGroup, subGroupPosition++);
+
+ tool.setMenuGroup(new String[] { "Secondary Highlight" }, highlightGroup);
setSecondaryHighlightAction = new SetSecondaryHighlightAction();
setGroupInfo(setSecondaryHighlightAction, highlightGroup, subGroupPosition++);
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/AbstractSetSecondaryHighlightAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/AbstractSetSecondaryHighlightAction.java
index caf491f0f0..d4483a3c9a 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/AbstractSetSecondaryHighlightAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/AbstractSetSecondaryHighlightAction.java
@@ -19,16 +19,11 @@ import ghidra.app.decompiler.ClangToken;
import ghidra.app.decompiler.component.DecompilerPanel;
import ghidra.app.decompiler.component.TokenHighlights;
import ghidra.app.plugin.core.decompile.DecompilerActionContext;
-import ghidra.app.util.HelpTopics;
-import ghidra.util.HelpLocation;
public abstract class AbstractSetSecondaryHighlightAction extends AbstractDecompilerAction {
AbstractSetSecondaryHighlightAction(String name) {
super(name);
-
- // TODO new help
- setHelpLocation(new HelpLocation(HelpTopics.SELECTION, getName()));
}
@Override
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceAction.java
index a7540daeb0..3b04af6d22 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceAction.java
@@ -31,7 +31,7 @@ public class BackwardsSliceAction extends AbstractDecompilerAction {
public BackwardsSliceAction() {
super("Highlight Backward Slice");
- setPopupMenuData(new MenuData(new String[] { NAME }, "Decompile"));
+ setPopupMenuData(new MenuData(new String[] { "Highlight", "Backward Slice" }, "Decompile"));
}
@Override
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceToPCodeOpsAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceToPCodeOpsAction.java
index 1e6b50c648..027a7381ee 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceToPCodeOpsAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceToPCodeOpsAction.java
@@ -31,7 +31,7 @@ public class BackwardsSliceToPCodeOpsAction extends AbstractDecompilerAction {
super("Highlight Backward Inst Slice");
this.controller = controller;
setPopupMenuData(
- new MenuData(new String[] { "Highlight Backward Inst Slice" }, "Decompile"));
+ new MenuData(new String[] { "Highlight", "Backward Inst Slice" }, "Decompile"));
}
@Override
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceAction.java
index 25add9c3dd..432a50e05b 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceAction.java
@@ -30,7 +30,7 @@ public class ForwardSliceAction extends AbstractDecompilerAction {
public ForwardSliceAction(DecompilerController controller) {
super("Highlight Forward Slice");
this.controller = controller;
- setPopupMenuData(new MenuData(new String[] { "Highlight Forward Slice" }, "Decompile"));
+ setPopupMenuData(new MenuData(new String[] { "Highlight", "Forward Slice" }, "Decompile"));
}
@Override
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceToPCodeOpsAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceToPCodeOpsAction.java
index 7ec1bb5cc7..154aa17c3d 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceToPCodeOpsAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceToPCodeOpsAction.java
@@ -31,7 +31,7 @@ public class ForwardSliceToPCodeOpsAction extends AbstractDecompilerAction {
super("Highlight Forward Inst Slice");
this.controller = controller;
setPopupMenuData(
- new MenuData(new String[] { "Highlight Forward Inst Slice" }, "Decompile"));
+ new MenuData(new String[] { "Highlight", "Forward Inst Slice" }, "Decompile"));
}
@Override
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/HighlightDefinedUseAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/HighlightDefinedUseAction.java
index 486bf89d22..7e619f2442 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/HighlightDefinedUseAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/HighlightDefinedUseAction.java
@@ -30,7 +30,7 @@ public class HighlightDefinedUseAction extends AbstractDecompilerAction {
public HighlightDefinedUseAction(DecompilerController controller) {
super("Highlight Defined Use");
this.controller = controller;
- setPopupMenuData(new MenuData(new String[] { "Highlight Def-use" }, "Decompile"));
+ setPopupMenuData(new MenuData(new String[] { "Highlight", "Def-use" }, "Decompile"));
}
@Override
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveAllSecondaryHighlightsAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveAllSecondaryHighlightsAction.java
index 112a65b6bf..89f9adca10 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveAllSecondaryHighlightsAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveAllSecondaryHighlightsAction.java
@@ -33,7 +33,8 @@ public class RemoveAllSecondaryHighlightsAction extends AbstractDecompilerAction
public RemoveAllSecondaryHighlightsAction() {
super(NAME);
- setPopupMenuData(new MenuData(new String[] { NAME }, "Decompile"));
+ setPopupMenuData(new MenuData(
+ new String[] { "Secondary Highlight", "Remove All Highlights" }, "Decompile"));
setHelpLocation(new HelpLocation(HelpTopics.SELECTION, getName()));
}
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveSecondaryHighlightAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveSecondaryHighlightAction.java
index 56bcbc6ecf..02512ae94a 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveSecondaryHighlightAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveSecondaryHighlightAction.java
@@ -34,7 +34,8 @@ public class RemoveSecondaryHighlightAction extends AbstractDecompilerAction {
public RemoveSecondaryHighlightAction() {
super(NAME);
- setPopupMenuData(new MenuData(new String[] { NAME }, "Decompile"));
+ setPopupMenuData(
+ new MenuData(new String[] { "Secondary Highlight", "Remove Highlight" }, "Decompile"));
setHelpLocation(new HelpLocation(HelpTopics.SELECTION, getName()));
}
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetSecondaryHighlightAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetSecondaryHighlightAction.java
index a0ef48b0cf..e8cb698568 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetSecondaryHighlightAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetSecondaryHighlightAction.java
@@ -33,7 +33,8 @@ public class SetSecondaryHighlightAction extends AbstractSetSecondaryHighlightAc
public SetSecondaryHighlightAction() {
super(NAME);
- setPopupMenuData(new MenuData(new String[] { NAME }, "Decompile"));
+ setPopupMenuData(
+ new MenuData(new String[] { "Secondary Highlight", "Set Highlight" }, "Decompile"));
}
@Override
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetSecondaryHighlightColorChooserAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetSecondaryHighlightColorChooserAction.java
index b03f4dccc6..c5ceb11de1 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetSecondaryHighlightColorChooserAction.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SetSecondaryHighlightColorChooserAction.java
@@ -32,7 +32,8 @@ public class SetSecondaryHighlightColorChooserAction extends AbstractSetSecondar
public SetSecondaryHighlightColorChooserAction() {
super(NAME);
- setPopupMenuData(new MenuData(new String[] { NAME + "..." }, "Decompile"));
+ setPopupMenuData(
+ new MenuData(new String[] { "Secondary Highlight", "Set Highlight..." }, "Decompile"));
}
@Override