Ghidra is a software reverse engineering (SRE) framework
Merge remote-tracking branch 'origin/patch' into GP-0-dragonmacher-merge-conflict-resolution
dragonmacher0e23fe8c23cb
diff --cc Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangHighlightController.javaindex ad67cffac0,ea6c709ca2..bae9a14109--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangHighlightController.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/ClangHighlightController.java@@@ -35,7 -32,7 +35,7 @@@ import util.CollectionUtils/*** Class to handle highlights for a decompiled function.*-- * <p>This class does not painting directly. Rather, this class tracks the currently highlighted++ * <p>This class does not paint directly. Rather, this class tracks the currently highlighted* tokens and then sets the highlight color on the token when it is highlighted and clears the* highlight color when the highlight is removed.*diff --cc Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.javaindex 74b8d6eeb6,d78d0b36e2..bf839db6d7--- 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@@@ -209,161 -204,6 +209,157 @@@ public class DecompilerPanel extends JPhighlightController.togglePrimaryHighlights(middleMouseHighlightColor, lazyTokens);}+ void addHighlighterHighlights(ClangDecompilerHighlighter highlighter,+ Supplier<? extends Collection<ClangToken>> tokens, ColorProvider colorProvider) {+ highlightController.addHighlighterHighlights(highlighter, tokens, colorProvider);+ }++ void removeHighlighterHighlights(DecompilerHighlighter highlighter) {+ highlightController.removeHighlighterHighlights(highlighter);+ }++ public ClangDecompilerHighlighter createHighlighter(CTokenHighlightMatcher tm) {+ UUID uuId = UUID.randomUUID();+ String id = uuId.toString();+ return createHighlighter(id, tm);+ }++ public ClangDecompilerHighlighter createHighlighter(String id, CTokenHighlightMatcher tm) {+ ClangDecompilerHighlighter currentHighlighter = highlightersById.get(id);+ if (currentHighlighter != null) {+ currentHighlighter.dispose();+ }++ ClangDecompilerHighlighter newHighlighter = new ClangDecompilerHighlighter(id, this, tm);+ highlightersById.put(id, newHighlighter);+ highlightController.addHighlighter(newHighlighter);+ return newHighlighter;+ }++ public DecompilerHighlighter getHighlighter(String id) {+ return highlightersById.get(id);+ }++ void removeHighlighter(String id) {+ ClangDecompilerHighlighter highlighter = highlightersById.remove(id);+ highlightController.removeHighlighter(highlighter);+ }++ public void clearPrimaryHighlights() {+ highlightController.clearPrimaryHighlights();+ }++ public void addHighlights(Set<Varnode> varnodes, ColorProvider colorProvider) {+ ClangTokenGroup root = layoutMgr.getRoot();+ highlightController.addPrimaryHighlights(root, colorProvider);+ }++ public void addHighlights(Set<PcodeOp> ops, Color hlColor) {+ ClangTokenGroup root = layoutMgr.getRoot();+ highlightController.addPrimaryHighlights(root, ops, hlColor);+ }+- public String getHighlightedText() {- return highlightController.getPrimaryHighlightedText();- }-+ public void setHighlightController(ClangHighlightController highlightController) {+ if (this.highlightController != null) {+ this.highlightController.removeListener(this);+ }++ this.highlightController = ClangHighlightController.dummyIfNull(highlightController);+ highlightController.setHighlightColor(currentVariableHighlightColor);+ highlightController.addListener(this);+ }++ public ClangHighlightController getHighlightController() {+ return highlightController;+ }++ @Override+ public void tokenHighlightsChanged() {+ repaint();+ }++ /**+ * This function is used to alert the panel that a token was renamed. If the token being renamed+ * had a secondary highlight, we must re-apply the highlight to the new token.+ *+ * <p>This is not needed for highlighter service highlights, since they get called again to+ * re-apply highlights. It is up to that highlighter to determine if highlighting still applies+ * to the new token name. Alternatively, for secondary highlights, we know the user chose the+ * highlight based upon name. Thus, when the name changes, we need to take action to update+ * the secondary highlight.+ *+ * @param token the token being renamed+ * @param newName the new name of the token+ */+ public void tokenRenamed(ClangToken token, String newName) {++ Color hlColor = highlightController.getSecondaryHighlight(token);+ if (hlColor == null) {+ return; // not highlighted+ }++ // remove the old highlighter+ highlightController.removeSecondaryHighlights(token);++ controller.doWhenNotBusy(() -> {+ addSecondaryHighlight(newName, t -> hlColor);+ });+ }++ private void cloneGlobalHighlighters(DecompilerPanel sourcePanel) {++ Set<ClangDecompilerHighlighter> globalHighlighters =+ sourcePanel.highlightController.getGlobalHighlighters();+ for (ClangDecompilerHighlighter otherHighlighter : globalHighlighters) {++ ClangDecompilerHighlighter newHighlighter = otherHighlighter.clone(this);+ highlightersById.put(newHighlighter.getId(), newHighlighter);++ TokenHighlights otherHighlighterTokens =+ sourcePanel.highlightController.getHighlighterHighlights(otherHighlighter);+ if (otherHighlighterTokens == null || otherHighlighterTokens.isEmpty()) {+ // The highlighter has been created but no highlights have been applied. It is up+ // to the client to apply the highlights. The new highlighter will respond to the+ // client request if the later apply the highlights.+ continue;+ }++ newHighlighter.applyHighlights();+ }+ }++ /**+ * Called by the provider to clone all highlights in the source panel and apply them to this+ * panel+ * @param sourcePanel the panel that was cloned+ */+ public void cloneHighlights(DecompilerPanel sourcePanel) {++ cloneGlobalHighlighters(sourcePanel);++ //+ // Keep only those secondary highlighters for the current function. This ensures that the+ // clone will match the cloned decompiler.+ //+ Function function = decompileData.getFunction();+ Set<ClangDecompilerHighlighter> secondaryHighlighters =+ sourcePanel.getSecondaryHighlihgtersByFunction(function);++ //+ // We do NOT clone the secondary highlighters. This allows the user the remove them+ // from the primary provider without effecting the cloned provider and vice versa.+ //+ for (ClangDecompilerHighlighter highlighter : secondaryHighlighters) {+ ClangDecompilerHighlighter newHighlighter = highlighter.copy(this);+ highlightersById.put(newHighlighter.getId(), newHighlighter);+ applySecondaryHighlights(newHighlighter);+ }+ }++//==================================================================================================+// End Highlight Methods+//==================================================================================================+@Overridepublic void setBackground(Color bg) {originalBackgroundColor = bg;@@@ -694,10 -533,14 +690,15 @@@layoutMgr = null;decompilerHoverProvider.dispose();highlighCursorUpdater.dispose();- highlightController.clearAllHighlights();+ highlightController.dispose();+ highlightersById.clear();}+ public FontMetrics getFontMetrics() {+ Font font = options.getDefaultFont();+ return super.getFontMetrics(font);+ }+private FontMetrics getFontMetrics(DecompileOptions decompileOptions) {Font font = decompileOptions.getDefaultFont();return getFontMetrics(font);