Ghidra is a software reverse engineering (SRE) framework
GP-5951 - Decompiler - Changed recent middle-mouse highlight update to restore highlighting of if/else keywords.
dragonmacher0f89e04e70d7
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.javaindex 0b470332fa..37608258ac 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@@ -90,6 +90,7 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field}});+ private Set<String> ignoredMiddleMouseTokens = Set.of("{", "}", ";");private ActiveMiddleMouse activeMiddleMouse;private int middleMouseHighlightButton;private Color middleMouseHighlightColor;@@ -264,7 +265,10 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field}// exclude tokens that users do not want to highlight- if (token instanceof ClangSyntaxToken || token instanceof ClangOpToken) {+ if (shouldIgnoreOpToken(token)) {+ return;+ }+ if (shouldIgnoreSyntaxTokenHighlight(token)) {return;}@@ -273,6 +277,26 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, FieldactiveMiddleMouse = newMiddleMouse;}+ private boolean shouldIgnoreOpToken(ClangToken token) {+ if (!(token instanceof ClangOpToken)) {+ return false;+ }++ // users would like to be able to highlight return statements+ String text = token.toString();+ return !text.equals("return");+ }++ private boolean shouldIgnoreSyntaxTokenHighlight(ClangToken token) {++ if (!(token instanceof ClangSyntaxToken syntaxToken)) {+ return false;+ }++ String string = syntaxToken.toString();+ return ignoredMiddleMouseTokens.contains(string);+ }+void addHighlighterHighlights(ClangDecompilerHighlighter highlighter,Supplier<? extends Collection<ClangToken>> tokens, ColorProvider colorProvider) {highlightController.addHighlighterHighlights(highlighter, tokens, colorProvider);@@ -745,7 +769,6 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Fieldint clickCount = ev.getClickCount();int buttonState = ev.getButton();-if (buttonState == MouseEvent.BUTTON1) {if (DockingUtils.isControlModifier(ev) && clickCount == 2) {tryToGoto(location, field, ev, true);diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/ToolUtils.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/ToolUtils.javaindex 73872ea8fc..4af1dfcf08 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/ToolUtils.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/ToolUtils.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.@@ -140,7 +140,7 @@ public class ToolUtils {File[] toolFiles = USER_TOOLS_DIR.listFiles(filter);if (toolFiles != null) {for (File toolFile : toolFiles) {- ToolTemplate template = ToolUtils.readToolTemplate(toolFile);+ ToolTemplate template = readToolTemplate(toolFile);if (template != null) {map.put(template.getName(), template);}@@ -202,9 +202,9 @@ public class ToolUtils {}public static void renameToolTemplate(ToolTemplate toolTemplate, String newName) {- ToolUtils.deleteTool(toolTemplate);+ deleteTool(toolTemplate);toolTemplate.setName(newName);- ToolUtils.writeToolTemplate(toolTemplate);+ writeToolTemplate(toolTemplate);}public static boolean writeToolTemplate(ToolTemplate template) {@@ -232,6 +232,8 @@ public class ToolUtils {}public static ToolTemplate readToolTemplate(File toolFile) {++ LOGGER.trace("Loading tool file {}", toolFile);GhidraToolTemplate toolTemplate = null;try (FileInputStream is = new FileInputStream(toolFile)) {@@ -331,7 +333,7 @@ public class ToolUtils {public static String getUniqueToolName(ToolTemplate template) {String name = template.getName();int n = 1;- while (ToolUtils.getToolFile(name).exists()) {+ while (getToolFile(name).exists()) {name = name + "_" + n++;}return name;