Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5414 - Decompiler - Updated highlighting to ignore syntax tokens

dragonmacher99659967e2fd
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
index 607fb667d0..5f24bc30dc 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
@@ -262,6 +262,11 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
}
}
+ // exclude tokens that users do not want to highlight
+ if (token instanceof ClangSyntaxToken || token instanceof ClangOpToken) {
+ return;
+ }
+
ActiveMiddleMouse newMiddleMouse = new ActiveMiddleMouse(token.getText());
newMiddleMouse.apply();
activeMiddleMouse = newMiddleMouse;
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/LocationClangHighlightController.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/LocationClangHighlightController.java
index 4d291b8d10..9453958baa 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/LocationClangHighlightController.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/LocationClangHighlightController.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,8 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import docking.widgets.EventTrigger;
import docking.widgets.fieldpanel.field.Field;
import docking.widgets.fieldpanel.support.FieldLocation;
-import ghidra.app.decompiler.ClangSyntaxToken;
-import ghidra.app.decompiler.ClangToken;
+import ghidra.app.decompiler.*;
/**
* Class to handle location based highlights for a decompiled function.
@@ -47,10 +46,23 @@ public class LocationClangHighlightController extends ClangHighlightController {
return; // do not highlight whitespace
}
- addPrimaryHighlight(tok, defaultHighlightColor);
+ if (tok instanceof ClangOpToken) { // e.g., '='
+ return;
+ }
+
if (tok instanceof ClangSyntaxToken) {
+
+ int type = tok.getSyntaxType();
+ if (type == ClangToken.GLOBAL_COLOR) {
+ // namespaces can fit this case sometimes
+ addPrimaryHighlight(tok, defaultHighlightColor);
+ }
+
addPrimaryHighlightToTokensForParenthesis((ClangSyntaxToken) tok, defaultParenColor);
addPrimaryHighlightToTokensForBrace((ClangSyntaxToken) tok, defaultParenColor);
}
+ else {
+ addPrimaryHighlight(tok, defaultHighlightColor);
+ }
}
}