From f30666e4e64d5dd93fbd87cf45851d097c77fe96 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Fri, 13 Nov 2020 18:29:09 -0500 Subject: [PATCH] GP-349 - Fixed memory search highlight exception --- .../plugin/core/searchmem/MemSearchPlugin.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchPlugin.java index efbe2b37c0..3096e204a8 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchPlugin.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchmem/MemSearchPlugin.java @@ -373,8 +373,8 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener, return !(context instanceof RestrictedAddressSetContext) && searchInfo != null; } }; - searchAgainAction.setHelpLocation( - new HelpLocation(HelpTopics.SEARCH, searchAgainAction.getName())); + searchAgainAction + .setHelpLocation(new HelpLocation(HelpTopics.SEARCH, searchAgainAction.getName())); menuPath = new String[] { "&Search", "Repeat Memory Search" }; searchAgainAction.setMenuBarData(new MenuData(menuPath, "search")); searchAgainAction.setKeyBindingData(new KeyBindingData(KeyEvent.VK_F3, 0)); @@ -750,14 +750,19 @@ public class MemSearchPlugin extends Plugin implements OptionsChangeListener, private Color getHighlightColor(Address highlightStart, int highlightLength) { ProgramLocation location = navigatable != null ? navigatable.getLocation() : null; - if (location instanceof BytesFieldLocation) { - BytesFieldLocation byteLoc = (BytesFieldLocation) location; - Address byteAddress = byteLoc.getAddressForByte(); + if (!(location instanceof BytesFieldLocation)) { + return defaultHighlightColor; + } + + BytesFieldLocation byteLoc = (BytesFieldLocation) location; + Address byteAddress = byteLoc.getAddressForByte(); + if (highlightStart.hasSameAddressSpace(byteAddress)) { long diff = byteAddress.subtract(highlightStart); if (diff >= 0 && diff < highlightLength) { - return activeHighlightColor; + return activeHighlightColor; // the current location is in the highlight } } + return defaultHighlightColor; }