Ghidra is a software reverse engineering (SRE) framework
Marker Set refactor fix
dragonmacher5f2d3a3d6e60
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bookmark/BookmarkNavigator.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bookmark/BookmarkNavigator.javaindex 1a32946407..469c83fc2e 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bookmark/BookmarkNavigator.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/bookmark/BookmarkNavigator.java@@ -18,15 +18,16 @@ package ghidra.app.plugin.core.bookmark;import java.awt.Color;import javax.swing.ImageIcon;-import javax.swing.SwingUtilities;++import org.apache.commons.lang3.StringUtils;import ghidra.app.services.*;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSet;import ghidra.program.model.listing.*;import ghidra.program.util.MarkerLocation;-import ghidra.program.util.ProgramLocation;import ghidra.util.HTMLUtilities;+import ghidra.util.Swing;import resources.ResourceManager;/**@@ -72,12 +73,7 @@ public class BookmarkNavigator {bookmarkMgr = bookmarkManager;this.type = bmt.getTypeString();- updateRunnable = new Runnable() {- @Override- public void run() {- updateMarkerSetAddresses();- }- };+ updateRunnable = () -> updateMarkerSetAddresses();int priority = bmt.getMarkerPriority();if (priority < 0) {@@ -97,11 +93,7 @@ public class BookmarkNavigator {markerSet = markerService.createPointMarker(type + " Bookmarks", type + " Bookmarks",bookmarkMgr.getProgram(), priority, true, true, false, color, icon);- markerSet.setNavigationListener(new MarkerListener() {- @Override- public ProgramLocation getProgramLocation(MarkerLocation loc) {- return null;- }+ markerSet.setMarkerDescriptor(new MarkerDescriptor() {@Overridepublic String getTooltip(MarkerLocation loc) {@@ -109,27 +101,23 @@ public class BookmarkNavigator {if (bookmarks == null) {return BookmarkNavigator.this.type;}- StringBuffer buf = new StringBuffer();+ StringBuilder buffy = new StringBuilder();for (int i = 0; i < bookmarks.length; i++) {if (i != 0) {- buf.append("<br>");+ buffy.append("<br>");}- buf.append(BookmarkNavigator.this.type);++ buffy.append(BookmarkNavigator.this.type);String cat = bookmarks[i].getCategory();- if (cat != null && cat.length() != 0) {- buf.append(" [");- buf.append(HTMLUtilities.escapeHTML(cat));- buf.append("]");+ if (!StringUtils.isBlank(cat)) {+ buffy.append(" [");+ buffy.append(HTMLUtilities.escapeHTML(cat));+ buffy.append("]");}- buf.append(": ");- buf.append(HTMLUtilities.escapeHTML(bookmarks[i].getComment()));+ buffy.append(": ");+ buffy.append(HTMLUtilities.escapeHTML(bookmarks[i].getComment()));}- return buf.toString();- }-- @Override- public ImageIcon getIcon(MarkerLocation loc) {- return null;+ return buffy.toString();}});@@ -155,13 +143,15 @@ public class BookmarkNavigator {/*** Return the type String for the bookmarks+ * @return the type*/String getType() {return type;}/**- * Refresh bookmark markers.+ * Refresh bookmark markers+ * @param set the addresses*/public synchronized void updateBookmarkers(AddressSet set) {if (addressSet != null) {@@ -169,12 +159,12 @@ public class BookmarkNavigator {return;}addressSet = set;- SwingUtilities.invokeLater(updateRunnable);+ Swing.runLater(updateRunnable);}/*** Add bookmark marker at specified address.- * @param addr+ * @param addr the address*/public void add(Address addr) {markerSet.add(addr);@@ -182,7 +172,7 @@ public class BookmarkNavigator {/*** Clear bookmark marker at specified address.- * @param addr+ * @param addr the address*/public void clear(Address addr) {markerSet.clear(addr);@@ -192,27 +182,23 @@ public class BookmarkNavigator {* Return whether the marker set intersections with the given range.* @param start start of the range* @param end end of the range+ * @return true if intersects*/public boolean intersects(Address start, Address end) {return markerSet.intersects(start, end);}/**- * Define the bookmark types, as this information is not maintained- * in the program.+ * Define the bookmark types, as this information is not maintained in the program+ * @param program the program*/public static void defineBookmarkTypes(Program program) {BookmarkManager mgr = program.getBookmarkManager();- mgr.defineType(BookmarkType.NOTE, BookmarkNavigator.NOTE_ICON, BookmarkNavigator.NOTE_COLOR,- BookmarkNavigator.NOTE_PRIORITY);- mgr.defineType(BookmarkType.INFO, BookmarkNavigator.INFO_ICON, BookmarkNavigator.INFO_COLOR,- BookmarkNavigator.INFO_PRIORITY);- mgr.defineType(BookmarkType.WARNING, BookmarkNavigator.WARNING_ICON,- BookmarkNavigator.WARNING_COLOR, BookmarkNavigator.WARNING_PRIORITY);- mgr.defineType(BookmarkType.ERROR, BookmarkNavigator.ERROR_ICON,- BookmarkNavigator.ERROR_COLOR, BookmarkNavigator.ERROR_PRIORITY);- mgr.defineType(BookmarkType.ANALYSIS, BookmarkNavigator.ANALYSIS_ICON,- BookmarkNavigator.ANALYSIS_COLOR, BookmarkNavigator.ANALYSIS_PRIORITY);+ mgr.defineType(BookmarkType.NOTE, NOTE_ICON, NOTE_COLOR, NOTE_PRIORITY);+ mgr.defineType(BookmarkType.INFO, INFO_ICON, INFO_COLOR, INFO_PRIORITY);+ mgr.defineType(BookmarkType.WARNING, WARNING_ICON, WARNING_COLOR, WARNING_PRIORITY);+ mgr.defineType(BookmarkType.ERROR, ERROR_ICON, ERROR_COLOR, ERROR_PRIORITY);+ mgr.defineType(BookmarkType.ANALYSIS, ANALYSIS_ICON, ANALYSIS_COLOR, ANALYSIS_PRIORITY);}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/AreaMarkerSet.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/AreaMarkerSet.javaindex 5c8a06fecb..6b5bf8870d 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/AreaMarkerSet.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/AreaMarkerSet.java@@ -32,7 +32,7 @@ import resources.ResourceManager;class AreaMarkerSet extends MarkerSetImpl {/**- * @param navigationManager manager for these area markers+ * @param markerManager manager for these area markers* @param name the name for this area marker* @param desc the description associated with this area marker* @param priority to sort out what displays on top, higher is more likely to be on top@@ -42,16 +42,18 @@ class AreaMarkerSet extends MarkerSetImpl {* If color is null, no results are displayed in the associated marker bar.* @param markerColor the color for the marker* @param isPreferred true indicates higher priority than all non-preferred MarkerSets+ * @param program the program to which the markers apply*/- AreaMarkerSet(MarkerManager navigationManager, String name, String desc, int priority,+ AreaMarkerSet(MarkerManager markerManager, String name, String desc, int priority,boolean showMarkers, boolean showNavigation, boolean colorBackground, Color markerColor,- boolean isPreferred) {- super(navigationManager, name, desc, priority, showMarkers, showNavigation, colorBackground,+ boolean isPreferred, Program program) {+ super(markerManager, program, name, desc, priority, showMarkers, showNavigation,+ colorBackground,markerColor, isPreferred);}/**- * @param navigationManager manager for these area markers+ * @param markerManager manager for these area markers* @param name the name for this area marker* @param desc the description associated with this area marker* @param priority to sort out what displays on top, higher is more likely to be on top@@ -60,12 +62,13 @@ class AreaMarkerSet extends MarkerSetImpl {* @param colorBackground the color of marked areas in navigation bar* If color is null, no results are displayed in the associated marker bar.* @param markerColor the color for the marker+ * @param program the program to which the markers apply*/- AreaMarkerSet(MarkerManager navigationManager, String name, String desc, int priority,+ AreaMarkerSet(MarkerManager markerManager, String name, String desc, int priority,boolean showMarkers, boolean showNavigation, boolean colorBackground, Color markerColor,Program program) {- this(navigationManager, name, desc, priority, showMarkers, showNavigation, colorBackground,- markerColor, false);+ this(markerManager, name, desc, priority, showMarkers, showNavigation,+ colorBackground, markerColor, false, program);}@Override@@ -85,9 +88,6 @@ class AreaMarkerSet extends MarkerSetImpl {}}- /*- * @see ghidra.app.plugin.codebrowser.MarkerSetImpl#doPaintNavigation(java.awt.Graphics, int, int, int)- */@Overrideprotected void doPaintNavigation(Graphics g, int height, int width, SortedRangeList rangeList) {@@ -108,9 +108,6 @@ class AreaMarkerSet extends MarkerSetImpl {}}- /* (non-Javadoc)- * @see ghidra.app.plugin.codebrowser.MarkerSetImpl#getNavIcon()- */@Overridepublic ImageIcon getNavIcon() {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.javaindex 1a156521ce..3c0cc457b4 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerManager.java@@ -58,7 +58,7 @@ public class MarkerManager implements MarkerService {private final static String POPUP_WINDOW_NAME = "Bookmark ToolTip Window";private final static int MAX_TOOLTIP_LINES = 10;- private MarkerPanel markPanel;+ private MarkerPanel markerPanel;private NavigationPanel navigationPanel;private MarkerActionList actionList;private VerticalPixelAddressMap pixmap;@@ -69,8 +69,10 @@ public class MarkerManager implements MarkerService {* mapped to a MarkerSet. This structure allows for a lookup of the marker set group to* get a mapping of program->marker set.*/- private Map<String, Map<Program, MarkerSetImpl>> groupToProgramMarkerMap;- private List<MarkerSetImpl> currentMarkerSets;+ private Map<String, Map<Program, MarkerSetImpl>> programMarkersByGroup =+ LazyMap.lazyMap(new HashMap<>(), () -> new HashMap<>());++ private List<MarkerSetImpl> currentMarkerSets = Collections.emptyList();/*** A cache of programs to marker sets so that clients can install marker sets on a@@ -79,7 +81,8 @@ public class MarkerManager implements MarkerService {private Map<Program, List<MarkerSetImpl>> markerSetCache =LazyMap.lazyMap(new HashMap<>(), () -> new ArrayList<>());- private SwingUpdateManager updateMgr;+ /** Buffers requests to repaint and notify of marker changes */+ private SwingUpdateManager updater;private GoToService goToService;private Navigatable navigatable;@@ -105,10 +108,8 @@ public class MarkerManager implements MarkerService {this.owner = owner;this.tool = tool;- currentMarkerSets = Collections.emptyList();-- updateMgr = new SwingUpdateManager(100, 60000, () -> {- markPanel.repaint();+ updater = new SwingUpdateManager(100, 60000, () -> {+ markerPanel.repaint();navigationPanel.repaint();notifyListeners();});@@ -123,18 +124,17 @@ public class MarkerManager implements MarkerService {});overviewProvider = new MyOverviewProvider();- markPanel = new MarkerPanel(this);- markPanel.setPreferredSize(new Dimension(16, 1));+ markerPanel = new MarkerPanel(this);+ markerPanel.setPreferredSize(new Dimension(16, 1));marginProvider = new MyMarginProvider();actionList = new MarkerActionList();- groupToProgramMarkerMap = new HashMap<>();}void programClosed(Program program) {markerSetCache.remove(program);- Map<String, Map<Program, MarkerSetImpl>> values = groupToProgramMarkerMap;+ Map<String, Map<Program, MarkerSetImpl>> values = programMarkersByGroup;Collection<Map<Program, MarkerSetImpl>> valueValues = values.values();for (Map<Program, MarkerSetImpl> map : valueValues) {map.remove(program);@@ -147,7 +147,7 @@ public class MarkerManager implements MarkerService {Color color) {AreaMarkerSet mgr = new AreaMarkerSet(this, name, markerDescription, priority, showMarkers,showNavigation, colorBackground, color, program);- insertManager(mgr, program);+ insertMarkers(mgr, program);return mgr;}@@ -156,8 +156,8 @@ public class MarkerManager implements MarkerService {int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground,Color color, boolean isPreferred) {AreaMarkerSet mgr = new AreaMarkerSet(this, name, markerDescription, priority, showMarkers,- showNavigation, colorBackground, color, isPreferred);- insertManager(mgr, program);+ showNavigation, colorBackground, color, isPreferred, program);+ insertMarkers(mgr, program);return mgr;}@@ -165,20 +165,22 @@ public class MarkerManager implements MarkerService {public MarkerSet createPointMarker(String name, String markerDescription, Program program,int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground,Color color, ImageIcon icon) {- MarkerSetImpl mgr = new PointMarkerSet(this, name, markerDescription, priority, showMarkers,- showNavigation, colorBackground, color, icon);- insertManager(mgr, program);- return mgr;+ MarkerSetImpl markers =+ new PointMarkerSet(this, name, markerDescription, priority, showMarkers,+ showNavigation, colorBackground, color, icon, program);+ insertMarkers(markers, program);+ return markers;}@Overridepublic MarkerSet createPointMarker(String name, String markerDescription, Program program,int priority, boolean showMarkers, boolean showNavigation, boolean colorBackground,Color color, ImageIcon icon, boolean isPreferred) {- MarkerSetImpl mgr = new PointMarkerSet(this, name, markerDescription, priority, showMarkers,- showNavigation, colorBackground, color, icon, isPreferred);- insertManager(mgr, program);- return mgr;+ MarkerSetImpl markers =+ new PointMarkerSet(this, name, markerDescription, priority, showMarkers,+ showNavigation, colorBackground, color, icon, isPreferred, program);+ insertMarkers(markers, program);+ return markers;}@Override@@ -201,32 +203,32 @@ public class MarkerManager implements MarkerService {}@Override- public void removeMarker(MarkerSet markerManager, Program program) {+ public void removeMarker(MarkerSet markers, Program program) {if (program == null) {throw new NullPointerException("Cannot remove marker set for a null program.");}- doRemoveMarker(markerManager, program);+ doRemoveMarker(markers, program);actionList.refresh();- update();+ markersChanged(program);}- private void doRemoveMarker(MarkerSet markerSet, Program program) {- if (markerSet == null || program == null) {+ private void doRemoveMarker(MarkerSet markers, Program program) {+ if (markers == null || program == null) {return;}// per-program listList<MarkerSetImpl> list = markerSetCache.get(program);- list.remove(markerSet);+ list.remove(markers);// per-group list// We need to find the marker by searching through the map of maps (when used in a// group setting the marker manager will be mapped directly to one program)- Collection<Map<Program, MarkerSetImpl>> values = groupToProgramMarkerMap.values();+ Collection<Map<Program, MarkerSetImpl>> values = programMarkersByGroup.values();for (Map<Program, MarkerSetImpl> map : values) {MarkerSetImpl markerSetImpl = map.get(program);- if (markerSetImpl == markerSet) {+ if (markerSetImpl == markers) {map.clear();break;}@@ -250,7 +252,7 @@ public class MarkerManager implements MarkerService {this.currentProgram = program;if (program == null) {currentMarkerSets = Collections.emptyList();- updateMgr.update();+ updater.update();return;}@@ -258,11 +260,11 @@ public class MarkerManager implements MarkerService {setCurrentMarkerSets(program);actionList.refresh();- updateMgr.update();+ updater.update();}public void dispose() {- updateMgr.dispose();+ updater.dispose();actionList.dispose();currentMarkerSets.clear();markerSetCache.clear();@@ -272,10 +274,10 @@ public class MarkerManager implements MarkerService {void navigateTo(int x, int y) {int viewHeight = navigationPanel.getHeight() - MarkerSetImpl.MARKER_HEIGHT;for (int i = currentMarkerSets.size() - 1; i >= 0; i--) {- MarkerSetImpl marker = currentMarkerSets.get(i);- if (marker.isActive()) {+ MarkerSetImpl markers = currentMarkerSets.get(i);+ if (markers.isActive()) {GoToService service = getGoToService();- ProgramLocation loc = marker.getProgramLocation(y, viewHeight, addrMap, x);+ ProgramLocation loc = markers.getProgramLocation(y, viewHeight, addrMap, x);if (loc != null && service != null) {service.goTo(navigatable, loc, loc.getProgram());break;@@ -285,12 +287,12 @@ public class MarkerManager implements MarkerService {}void paintMarkers(Graphics g) {- Iterator<MarkerSetImpl> iter = currentMarkerSets.iterator();+ Iterator<MarkerSetImpl> it = currentMarkerSets.iterator();int count = 0;- while (iter.hasNext()) {- MarkerSetImpl marker = iter.next();- if (marker.isActive()) {- marker.paintMarkers(g, count++, pixmap, addrMap);+ while (it.hasNext()) {+ MarkerSetImpl markers = it.next();+ if (markers.isActive()) {+ markers.paintMarkers(g, count++, pixmap, addrMap);}}}@@ -299,12 +301,13 @@ public class MarkerManager implements MarkerService {if (addrMap == null) {return;}+int viewHeight = panel.getHeight() - MarkerSetImpl.MARKER_HEIGHT;- Iterator<MarkerSetImpl> iter = currentMarkerSets.iterator();- while (iter.hasNext()) {- MarkerSetImpl mgr = iter.next();- if (mgr.active) {- mgr.paintNavigation(g, viewHeight, panel, addrMap);+ Iterator<MarkerSetImpl> it = currentMarkerSets.iterator();+ while (it.hasNext()) {+ MarkerSetImpl markers = it.next();+ if (markers.active) {+ markers.paintNavigation(g, viewHeight, panel, addrMap);}}}@@ -357,17 +360,17 @@ public class MarkerManager implements MarkerService {List<String> lines = new ArrayList<>();for (int i = currentMarkerSets.size() - 1; i >= 0; i--) {- MarkerSetImpl marker = currentMarkerSets.get(i);- if (!marker.displayInMarkerBar()) {+ MarkerSetImpl markers = currentMarkerSets.get(i);+ if (!markers.displayInMarkerBar()) {continue;}- AddressSet set = marker.getAddressSet();+ AddressSet set = markers.getAddressSet();AddressSet intersection = set.intersect(new AddressSet(layoutAddress, endAddr));for (Address a : intersection.getAddresses(true)) {- lines.add(getMarkerToolTip(marker, a, x, y));+ lines.add(getMarkerToolTip(markers, a, x, y));- if (marker instanceof AreaMarkerSet) {+ if (markers instanceof AreaMarkerSet) {break; // no more tooltips from this area}if (lines.size() >= MAX_TOOLTIP_LINES) {@@ -380,17 +383,18 @@ public class MarkerManager implements MarkerService {}private String getMarkerToolTip(MarkerSetImpl marker, Address a, int x, int y) {- String markerTip = marker.getTooltip(a, x, y);- if (markerTip == null) {- markerTip = marker.getName();+ String tip = marker.getTooltip(a, x, y);+ if (tip == null) {+ tip = marker.getName();}- return markerTip;+ return tip;}private String toHTML(List<String> lines) {if (lines.isEmpty()) {return null;}+StringBuilder buffy = new StringBuilder("<html><font size=\"" + 4 + "\">");for (String string : lines) {buffy.append(string).append("<BR>");@@ -398,41 +402,46 @@ public class MarkerManager implements MarkerService {return buffy.toString();}- void update() {- AddressColorCache addressColorCache = colorCache.get(currentProgram);- addressColorCache.clear();- updateMgr.update();+ /**+ * Call to signal that the markers for a given program have changed in some way, such as being+ * removed, changing colors or the active state being changed+ *+ * @param p the program associated with the markers+ */+ void markersChanged(Program p) {+ colorCache.get(p).clear();+ updater.update();}- private void insertManager(MarkerSetImpl mgr, Program program) {+ private void insertMarkers(MarkerSetImpl markers, Program program) {if (program == null) {throw new AssertException("Program cannot be null");}- List<MarkerSetImpl> markerSetList = markerSetCache.get(program);- if (markerSetList == null) {+ List<MarkerSetImpl> markerSets = markerSetCache.get(program);+ if (markerSets == null) {return; // no list means deprecated usage}- int index = Collections.binarySearch(markerSetList, mgr);+ int index = Collections.binarySearch(markerSets, markers);if (index < 0) {index = -(index + 1);}- markerSetList.add(index, mgr);+ markerSets.add(index, markers);actionList.refresh();}private void setCurrentMarkerSets(Program program) {- List<MarkerSetImpl> markerSetList = markerSetCache.get(program);+ List<MarkerSetImpl> markerSets = markerSetCache.get(program);// determine if we are switching lists- boolean switchingLists = (markerSetList != currentMarkerSets);+ boolean switchingLists = (markerSets != currentMarkerSets);if (!switchingLists) {return;}- currentMarkerSets = markerSetList;+ currentMarkerSets = markerSets;Collections.sort(currentMarkerSets);}@@ -446,17 +455,17 @@ public class MarkerManager implements MarkerService {private void updateMarkerSets(boolean updateMarkers, boolean updateNavigation,boolean updateNow) {- Iterator<MarkerSetImpl> iter = currentMarkerSets.iterator();- while (iter.hasNext()) {- MarkerSetImpl marker = iter.next();+ Iterator<MarkerSetImpl> it = currentMarkerSets.iterator();+ while (it.hasNext()) {+ MarkerSetImpl marker = it.next();marker.updateView(updateMarkers, updateNavigation);}if (updateNow) {- updateMgr.updateNow();+ updater.updateNow();}else {- updateMgr.update();+ updater.update();}}@@ -479,9 +488,9 @@ public class MarkerManager implements MarkerService {private MarkerSetImpl getMarkerSet(Address addr) {for (int i = currentMarkerSets.size() - 1; i >= 0; i--) {- MarkerSetImpl marker = currentMarkerSets.get(i);- if (marker.displayInMarkerBar() && marker.contains(addr)) {- return marker;+ MarkerSetImpl markers = currentMarkerSets.get(i);+ if (markers.displayInMarkerBar() && markers.contains(addr)) {+ return markers;}}return null;@@ -497,32 +506,26 @@ public class MarkerManager implements MarkerService {throw new IllegalArgumentException("Invalid marker set provided");}- Map<Program, MarkerSetImpl> programToMarkerMap = groupToProgramMarkerMap.get(groupName);- if (programToMarkerMap == null) {- programToMarkerMap = new HashMap<>();- groupToProgramMarkerMap.put(groupName, programToMarkerMap);- }-- MarkerSetImpl previousSet = programToMarkerMap.get(program);- MarkerSetImpl markerSet = (MarkerSetImpl) ms;-- if (markerSet == previousSet) {+ Map<Program, MarkerSetImpl> markersByProgram = programMarkersByGroup.get(groupName);+ MarkerSetImpl previousMarkers = markersByProgram.get(program);+ MarkerSetImpl markers = (MarkerSetImpl) ms;+ if (markers == previousMarkers) {return;}- removeMarker(previousSet, program);- programToMarkerMap.put(program, markerSet);- insertManager(markerSet, program);+ removeMarker(previousMarkers, program);+ markersByProgram.put(program, markers);+ insertMarkers(markers, program);}@Override- public void removeMarkerForGroup(String groupName, MarkerSet markerSet, Program program) {- Map<Program, MarkerSetImpl> programToMarkerMap = groupToProgramMarkerMap.get(groupName);- MarkerSet currentMarkerSet = programToMarkerMap.get(program);+ public void removeMarkerForGroup(String groupName, MarkerSet markers, Program program) {+ Map<Program, MarkerSetImpl> markersByProgram = programMarkersByGroup.get(groupName);+ MarkerSet previousMarkers = markersByProgram.get(program);- if (markerSet == currentMarkerSet) {- programToMarkerMap.remove(program);- removeMarker(currentMarkerSet, program);+ if (markers == previousMarkers) {+ markersByProgram.remove(program);+ removeMarker(previousMarkers, program);}}@@ -531,30 +534,29 @@ public class MarkerManager implements MarkerService {return getBackgroundColor(currentProgram, currentMarkerSets, address);}+ @Overridepublic Color getBackgroundColor(Program program, Address address) {- return getBackgroundColor(program, markerSetCache.get(program), address);+ Program markerProgram = program == null ? currentProgram : program;+ return getBackgroundColor(markerProgram, markerSetCache.get(markerProgram), address);}private Color getBackgroundColor(Program program, List<MarkerSetImpl> markerSets,Address address) {- AddressColorCache addressColorCache = colorCache.get(currentProgram);++ AddressColorCache addressColorCache = colorCache.get(program);if (addressColorCache.containsKey(address)) {return addressColorCache.get(address);}- Color color = null;for (int index = markerSets.size() - 1; index >= 0; index--) {- MarkerSet marker = markerSets.get(index);- if (marker.isActive() && marker.isColoringBackground() && marker.contains(address)) {- color = marker.getMarkerColor();- break;+ MarkerSet markers = markerSets.get(index);+ if (markers.isActive() && markers.isColoringBackground() && markers.contains(address)) {+ Color color = markers.getMarkerColor();+ addressColorCache.put(address, color);+ return color;}}-- if (color != null) {- addressColorCache.put(address, color);- }- return color;+ return null;}public GoToService getGoToService() {@@ -591,7 +593,6 @@ public class MarkerManager implements MarkerService {private void initOptions() {listOptions = tool.getOptions(GhidraOptions.CATEGORY_BROWSER_NAVIGATION_MARKERS);-listOptions.removeOptionsChangeListener(this);listOptions.addOptionsChangeListener(this);}@@ -623,10 +624,7 @@ public class MarkerManager implements MarkerService {}actions.clear();- ArrayList<MarkerSetImpl> list = new ArrayList<>();- for (MarkerSetImpl mgr : currentMarkerSets) {- list.add(mgr);- }+ List<MarkerSetImpl> list = new ArrayList<>(currentMarkerSets);// separate the marker sets into grouped and non-groupedList<List<MarkerSetImpl>> groupsList = extractManagerGroups(list);@@ -691,38 +689,36 @@ public class MarkerManager implements MarkerService {void dispose() {listOptions.removeOptionsChangeListener(this);- Iterator<DockingAction> iter = actions.iterator();- while (iter.hasNext()) {- DockingAction action = iter.next();- tool.removeAction(action);- }- }+ actions.forEach(a -> tool.removeAction(a));+ }}private static class ActivateMarkerAction extends ToggleDockingAction {- private MarkerSetImpl mgr;+ private MarkerSetImpl markers;private NavigationPanel panel;private Options options;- ActivateMarkerAction(String owner, MarkerSetImpl mgr, NavigationPanel panel,+ ActivateMarkerAction(String owner, MarkerSetImpl markers, NavigationPanel panel,Options options) {- super(mgr.getName(), owner);- this.mgr = mgr;+ super(markers.getName(), owner);+ this.markers = markers;this.panel = panel;this.options = options;HelpLocation helpLocation = new HelpLocation(HelpTopics.CODE_BROWSER, "Markers");- options.registerOption(mgr.getName(), true, helpLocation,- "This options enables/disables the display of " + mgr.getName() + " marker types.");+ options.registerOption(markers.getName(), true, helpLocation,+ "This options enables/disables the display of " + markers.getName() ++ " marker types.");setEnabled(true);- setSelected(mgr.active);- setPopupMenuData(new MenuData(new String[] { mgr.getName() }, mgr.getNavIcon(), null));+ setSelected(markers.active);+ setPopupMenuData(+ new MenuData(new String[] { markers.getName() }, markers.getNavIcon(), null));boolean isEnabled = isOptionEnabled();setSelected(isEnabled);- mgr.setActive(isEnabled);+ markers.setActive(isEnabled);HelpLocation location = new HelpLocation(HelpTopics.CODE_BROWSER, "Markers");setHelpLocation(location);}@@ -737,31 +733,31 @@ public class MarkerManager implements MarkerService {boolean selected = isOptionEnabled();if (selected != isSelected()) {setSelected(selected);- mgr.setActive(selected);+ markers.setActive(selected);}}private boolean isOptionEnabled() {- return options.getBoolean(mgr.getName(), true);+ return options.getBoolean(markers.getName(), true);}@Overridepublic void actionPerformed(ActionContext context) {- options.setBoolean(mgr.getName(), isSelected());- mgr.setActive(isSelected());+ options.setBoolean(markers.getName(), isSelected());+ markers.setActive(isSelected());}}private static class ActivateMarkerGroupAction extends ToggleDockingAction {- private List<MarkerSetImpl> managerList;+ private List<MarkerSetImpl> markerSets;private NavigationPanel panel;private Options options;ActivateMarkerGroupAction(String owner, List<MarkerSetImpl> managerList,NavigationPanel panel, Options options) {super(managerList.get(0).getName(), owner);- this.managerList = managerList;+ this.markerSets = managerList;this.panel = panel;this.options = options;HelpLocation helpLocation = new HelpLocation(HelpTopics.CODE_BROWSER, "Markers");@@ -779,18 +775,13 @@ public class MarkerManager implements MarkerService {}private void setActive(boolean active) {- for (MarkerSetImpl manager : managerList) {+ for (MarkerSetImpl manager : markerSets) {manager.setActive(active);}}private boolean isActive() {- for (MarkerSetImpl manager : managerList) {- if (manager.isActive()) {- return true;- }- }- return false;+ return markerSets.stream().anyMatch(markers -> markers.isActive());}@Override@@ -822,7 +813,7 @@ public class MarkerManager implements MarkerService {private class MyMarginProvider implements MarginProvider {@Overridepublic JComponent getComponent() {- return markPanel;+ return markerPanel;}@Override@@ -832,7 +823,7 @@ public class MarkerManager implements MarkerService {return null;}MarkerSet marker = getMarkerSet(addr);- return new MarkerLocation(marker, addr, x, y);+ return new MarkerLocation(marker, currentProgram, addr, x, y);}@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.javaindex 72ce0c914b..4601aa4b1d 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/MarkerSetImpl.java@@ -26,18 +26,22 @@ import javax.swing.ImageIcon;import docking.widgets.fieldpanel.support.FieldRange;import docking.widgets.fieldpanel.support.FieldSelection;-import ghidra.app.services.MarkerListener;+import generic.json.Json;+import ghidra.app.services.MarkerDescriptor;import ghidra.app.services.MarkerSet;import ghidra.app.util.viewer.listingpanel.VerticalPixelAddressMap;import ghidra.app.util.viewer.util.AddressIndexMap;import ghidra.program.model.address.*;+import ghidra.program.model.listing.Program;import ghidra.program.util.MarkerLocation;import ghidra.program.util.ProgramLocation;-import ghidra.util.SystemUtilities;+import ghidra.util.Swing;import ghidra.util.datastruct.SortedRangeList;abstract class MarkerSetImpl implements MarkerSet {+protected MarkerManager mgr;+ private Program program;private String name;protected String description;@@ -53,7 +57,7 @@ abstract class MarkerSetImpl implements MarkerSet {protected int lastHeight = 1;protected int lastWidth = 16;- protected MarkerListener listener;+ protected MarkerDescriptor markerDescriptor;protected final static int MARKER_WIDTH_OFFSET = 7;protected final static int MARKER_HEIGHT = 4;@@ -65,11 +69,13 @@ abstract class MarkerSetImpl implements MarkerSet {private boolean colorBackground;private boolean isPreferred;- MarkerSetImpl(MarkerManager mgr, String name, String desc, int priority, boolean showMarkers,+ MarkerSetImpl(MarkerManager mgr, Program program, String name, String desc, int priority,+ boolean showMarkers,boolean showNavigation, boolean colorBackground, Color markerColor,boolean isPreferred) {this.mgr = mgr;+ this.program = program;this.name = name;this.description = desc;this.priority = priority;@@ -97,8 +103,8 @@ abstract class MarkerSetImpl implements MarkerSet {public abstract ImageIcon getNavIcon();@Override- public void setNavigationListener(MarkerListener listener) {- this.listener = listener;+ public void setMarkerDescriptor(MarkerDescriptor markerDescriptor) {+ this.markerDescriptor = markerDescriptor;}@Override@@ -109,7 +115,7 @@ abstract class MarkerSetImpl implements MarkerSet {@Overridepublic void setMarkerColor(Color markerColor) {this.markerColor = markerColor;- mgr.update();+ mgr.markersChanged(program);}public String getDescription() {@@ -222,7 +228,7 @@ abstract class MarkerSetImpl implements MarkerSet {assertSwing();overview = null;activeLayouts = null;- mgr.update();+ mgr.markersChanged(program);}void updateView(boolean updateMarkers, boolean updateNavigation) {@@ -274,13 +280,6 @@ abstract class MarkerSetImpl implements MarkerSet {return result;}- /**- * Check if this Manager contains the address.- *- * @param addr address to check- *- * @return true if this manager contains the address.- */@Overridepublic boolean contains(Address addr) {assertSwing();@@ -391,8 +390,9 @@ abstract class MarkerSetImpl implements MarkerSet {* @return tool tip string, null if no tool tip*/public String getTooltip(Address addr, int x, int y) {- if (listener != null) {- return listener.getTooltip(new MarkerLocation(this, addr, x, y));+ if (markerDescriptor != null) {+ MarkerLocation loc = new MarkerLocation(this, mgr.getProgram(), addr, x, y);+ return markerDescriptor.getTooltip(loc);}return null;}@@ -415,7 +415,7 @@ abstract class MarkerSetImpl implements MarkerSet {@Overridepublic void setColoringBackground(boolean b) {colorBackground = b;- mgr.update();+ mgr.markersChanged(program);}public ProgramLocation getProgramLocation(int y, int height, AddressIndexMap map, int x) {@@ -454,9 +454,11 @@ abstract class MarkerSetImpl implements MarkerSet {if (addr == null) {addr = set.getMinAddress();}- if (listener != null) {- loc = listener.getProgramLocation(new MarkerLocation(this, addr, x, y));+ if (markerDescriptor != null) {+ MarkerLocation ml = new MarkerLocation(this, mgr.getProgram(), addr, x, y);+ loc = markerDescriptor.getProgramLocation(ml);}+if (loc == null) {loc = new ProgramLocation(mgr.getProgram(), addr);}@@ -492,7 +494,7 @@ abstract class MarkerSetImpl implements MarkerSet {@Overridepublic void setActive(boolean state) {active = state;- mgr.update();+ mgr.markersChanged(program);}@Override@@ -521,7 +523,12 @@ abstract class MarkerSetImpl implements MarkerSet {// Note: reading and writing to 'markers' is synchronized via the Swing threadprivate void assertSwing() {- SystemUtilities.assertThisIsTheSwingThread(+ Swing.assertSwingThread("Calls to the MarkerSetImpl must be made on the Swing thread");}++ @Override+ public String toString() {+ return Json.toString(this, "active", "colorBackground", "markers");+ }}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/PointMarkerSet.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/PointMarkerSet.javaindex 6c931e299a..86153326c7 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/PointMarkerSet.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/PointMarkerSet.java@@ -25,6 +25,8 @@ import javax.swing.ImageIcon;import ghidra.app.util.viewer.listingpanel.VerticalPixelAddressMap;import ghidra.app.util.viewer.util.AddressIndexMap;+import ghidra.program.model.address.Address;+import ghidra.program.model.listing.Program;import ghidra.program.util.MarkerLocation;import ghidra.util.datastruct.Range;import ghidra.util.datastruct.SortedRangeList;@@ -48,11 +50,13 @@ class PointMarkerSet extends MarkerSetImpl {* @param markerColor the color of the marker* @param icon the icon used to represent the cursor in the marker margin* @param isPreferred true indicates higher priority than all non-preferred MarkerSets+ * @param program the program to which the markers apply*/PointMarkerSet(MarkerManager navigationManager, String name, String desc, int priority,boolean showMarkers, boolean showNavigation, boolean colorBackground, Color markerColor,- ImageIcon icon, boolean isPreferred) {- super(navigationManager, name, desc, priority, showMarkers, showNavigation, colorBackground,+ ImageIcon icon, boolean isPreferred, Program program) {+ super(navigationManager, program, name, desc, priority, showMarkers, showNavigation,+ colorBackground,markerColor, isPreferred);if (icon == null) {icon = ResourceManager.loadImage("images/warning.png");@@ -76,12 +80,14 @@ class PointMarkerSet extends MarkerSetImpl {* If color is null, no results are displayed in the associated marker bar.* @param markerColor the color of the marker* @param icon the icon used to represent the cursor in the marker margin+ * @param program the program to which the markers apply*/PointMarkerSet(MarkerManager navigationManager, String name, String desc, int priority,boolean showMarkers, boolean showNavigation, boolean colorBackground, Color markerColor,- ImageIcon icon) {- this(navigationManager, name, desc, priority, showMarkers, showNavigation, colorBackground,- markerColor, icon, true);+ ImageIcon icon, Program program) {+ this(navigationManager, name, desc, priority, showMarkers, showNavigation,+ colorBackground,+ markerColor, icon, true, program);}@Override@@ -97,19 +103,28 @@ class PointMarkerSet extends MarkerSetImpl {int i = it.next().intValue();int yStart = pixmap.getMarkPosition(i);- Image curImage = image;- if (listener != null) {- ImageIcon icon = listener.getIcon(- new MarkerLocation(this, pixmap.getLayoutAddress(i), 0, yStart));- if (icon != null) {- curImage = icon.getImage();- }- }+ Image curImage = getMarkerImage(pixmap, i, yStart);g.drawImage(curImage, 0, yStart, imageObserver);}}+ private Image getMarkerImage(VerticalPixelAddressMap pixmap, int i, int yStart) {+ if (markerDescriptor == null) {+ return image;+ }++ Address address = pixmap.getLayoutAddress(i);+ Program program = mgr.getProgram();+ MarkerLocation loc = new MarkerLocation(this, program, address, 0, yStart);+ ImageIcon icon = markerDescriptor.getIcon(loc);+ if (icon != null) {+ return icon.getImage();+ }++ return image;+ }+@Overrideprotected void doPaintNavigation(Graphics g, int height, int width, SortedRangeList rangeList) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/table/TableComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/table/TableComponentProvider.javaindex 7a33de76a5..8476fe75ae 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/table/TableComponentProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/table/TableComponentProvider.java@@ -104,21 +104,11 @@ public class TableComponentProvider<T> extends ComponentProviderAdapterif (markerService != null) {markerSet = markerService.createPointMarker(name, title, program,MarkerService.SEARCH_PRIORITY, true, true, false, markerColor, markerIcon);- markerSet.setNavigationListener(new MarkerListener() {+ markerSet.setMarkerDescriptor(new MarkerDescriptor() {@Overridepublic ProgramLocation getProgramLocation(MarkerLocation loc) {return new BytesFieldLocation(program, loc.getAddr());}-- @Override- public String getTooltip(MarkerLocation loc) {- return null;- }-- @Override- public ImageIcon getIcon(MarkerLocation loc) {- return null;- }});// remove it; we will add it later to a groupdiff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerDescriptor.javasimilarity index 54%rename from Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerListener.javarename to Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerDescriptor.javaindex 7643167586..0dd46872fa 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerListener.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerDescriptor.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,37 +15,43 @@*/package ghidra.app.services;+import javax.swing.ImageIcon;+import ghidra.program.util.MarkerLocation;import ghidra.program.util.ProgramLocation;-import javax.swing.ImageIcon;-/**- * Listener for MarkerManager's created from the MarkerService.- * It is called for navigation to the marker or to get a tooltip- * for a marker.- *- *- *+ * Allows clients to specify how {@link MarkerLocation}s are navigated, as well as how they+ * should be painted*/+public abstract class MarkerDescriptor {-public interface MarkerListener {/**- * Called when the navigation bar to the right of the window is selected to- * allow the the creator of a Marker an opportunity to provide a more specific- * ProgramLocation to navigate to - otherwise the browser will navigate to- * the corresponding AddressLocation.+ * Called when the navigation bar to the right of the window is clicked to allow the the+ * creator of a Marker an opportunity to provide a more specific ProgramLocation for+ * navigation. If null is specified, the client will navigate to the corresponding address.+ * @param loc the marker location+ * @return the desired location; may be null*/- public ProgramLocation getProgramLocation(MarkerLocation loc);-+ public ProgramLocation getProgramLocation(MarkerLocation loc) {+ return null;+ }+/**- * Called to get a tool tip for a marker under the cursor in the marker panel- * to the left of the browser.+ * Called to get a tool tip for a marker under the cursor in the marker panel+ * @param loc the marker location+ * @return the tooltip; may be null*/- public String getTooltip(MarkerLocation loc);-+ public String getTooltip(MarkerLocation loc) {+ return null;+ }+/**- * Called to get the icon that corresponds to the given location.+ * Called to get the icon that corresponds to the given location+ * @param loc the marker location+ * @return the icon; may be null*/- public ImageIcon getIcon(MarkerLocation loc);+ public ImageIcon getIcon(MarkerLocation loc) {+ return null;+ }}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.javaindex 3b0191e39b..f7b09551fa 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerService.java@@ -26,24 +26,24 @@ import ghidra.program.model.address.Address;import ghidra.program.model.listing.Program;/**- * <p>Service to manage navigation markers displayed around a scrollable window- * like the Listing. The navigation bar displays the general location of- * markers for the entire view. The marker bar displays a marker at each marked- * address visible within the view. </p>* <p>- * The interface defines priorities for display of markers in Marker Margin and- * colored bars in Navigation Margin. The higher the priority, the more likely- * the marker/bar will be displayed on the top. Areas will always be lower than- * marker priorities.+ * Service to manage navigation markers displayed around a scrollable window like the Listing.+ * The navigation bar displays the general location of markers for the entire view. The marker bar+ * displays a marker at each marked address visible within the view.* </p>- * <a id="usage"></a>+ * <p>+ * The interface defines priorities for display of markers in Marker Margin and colored bars in+ * Navigation Margin. The higher the priority, the more likely the marker/bar will be displayed on+ * the top. Areas will always be lower than marker priorities.+ * </p>+ * <a name="usage"></a> <u>Recommended Usage</u><br>* <u>Recommended Usage</u><br>- * The service used to work independent of {@link Program}s. In order to work effectively this+ * The service used to work independently of {@link Program}s. In order to work effectively this* service has been changed to associate created markers with individual programs. Thus, it is* up to the clients of this class perform lifecycle management of markers created by this* service. For example, a client that creates a marker from- * {@link #createAreaMarker(String, String, Program, int, boolean, boolean, boolean, Color)} should call- * {@link #removeMarker(MarkerSet, Program)} when the markers are no longer used, such as when+ * {@link #createAreaMarker(String, String, Program, int, boolean, boolean, boolean, Color)} should+ * call {@link #removeMarker(MarkerSet, Program)} when the markers are no longer used, such as when* a program has become deactivated. In this example usage markers are added and removed as the* user tabs through open programs.*/@@ -182,15 +182,15 @@ public interface MarkerService {Color color, ImageIcon icon, boolean isPreferred);/**- * Remove the marker manager+ * Remove the marker set*- * @param markerManager marker manager to be removed from navigation bars.+ * @param markerSet marker set to be removed from navigation bars.* @param program The program with which the markers are associated.*/- public void removeMarker(MarkerSet markerManager, Program program);+ public void removeMarker(MarkerSet markerSet, Program program);/**- * Return the markerset with the given name;+ * Return the marker set with the given name;** @param name The name of the marker set for which to search* @param program The program with which the created markers will be associated.@@ -230,14 +230,31 @@ public interface MarkerService {public Color getBackgroundColor(Address address);/**- * Adds a change listener to be notified when markers are added/removed or the addresses in- * any current markerSets are changed.- * @param listener the listener to be notified.+ * Returns the background color associated with the given program and address. Each markerSet+ * that supports background coloring is checked in priority order to see if it wants to specify+ * a background color for the given address.+ *+ * If {@code program} is the current program, this is equivalent to+ * {@link #getBackgroundColor(Address)}.+ *+ * @param program the program to check for a background color.+ * @param address the address to check for a background color.+ * @return the background color to use for that address or null if no markers contain that+ * address.+ */+ public Color getBackgroundColor(Program program, Address address);++ /**+ * Adds a change listener to be notified when markers are added/removed or the addresses in any+ * current markerSets are changed+ *+ * @param listener the listener*/public void addChangeListener(ChangeListener listener);/**- * Removes the given change listener from the list of listeners to be notified of changes.+ * Removes the given change listener from the list of listeners to be notified of changes+ ** @param listener the listener*/public void removeChangeListener(ChangeListener listener);diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.javaindex 3a30b44072..7fa114066c 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/MarkerSet.java@@ -153,9 +153,9 @@ public interface MarkerSet extends Comparable<MarkerSet> {/*** Set the marker manager listener to use for user interaction* with markers owned by this manager.- * @param listener the listener+ * @param markerDescriptor the descriptor*/- public void setNavigationListener(MarkerListener listener);+ public void setMarkerDescriptor(MarkerDescriptor markerDescriptor);/*** True if this marker manager displays in the right hand navigation bardiff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/MarkerLocation.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/MarkerLocation.javaindex 1bfe678294..7ba9c5ce6d 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/MarkerLocation.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/MarkerLocation.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,39 +15,49 @@*/package ghidra.program.util;+import java.io.Serializable;+import java.util.Objects;+import ghidra.app.services.MarkerSet;import ghidra.program.model.address.Address;--import java.io.Serializable;+import ghidra.program.model.listing.Program;/**- * Object generated when pointer is over a particular marker in the browser- * navigation bars.- *- *- *+ * Marker location in the tool navigation bars*/public class MarkerLocation implements Serializable {-+private int x;private int y;private Address addr;- private MarkerSet mgr;-+ private MarkerSet markers;+ private final Program program;+/*** Construct a new MarkerLocation.- * @param mgr marker manager service+ * @param markers marker manager service+ * @param program program containing the address* @param addr address of the location* @param x x position of the popup point on the screen* @param y y position of the popup point on the screen*/- public MarkerLocation(MarkerSet mgr, Address addr, int x, int y) {- this.mgr = mgr;+ public MarkerLocation(MarkerSet markers, Program program, Address addr, int x, int y) {+ this.markers = markers;+ this.program = program;this.addr = addr;this.x = x;this.y = y;}+ /**+ * Returns the program.+ *+ * @return the program for this marker location+ */+ public Program getProgram() {+ return program;+ }+/*** Returns the address.*@@ -64,7 +73,7 @@ public class MarkerLocation implements Serializable {* @return the marker manager*/public MarkerSet getMarkerManager() {- return mgr;+ return markers;}/**@@ -84,29 +93,45 @@ public class MarkerLocation implements Serializable {public int getY() {return y;}-- /**- * @see java.lang.Object#equals(java.lang.Object)- */+@Override- public boolean equals(Object obj) {- if(obj == null) {+ public int hashCode() {+ final int prime = 31;+ int result = 1;+ result = prime * result + ((addr == null) ? 0 : addr.hashCode());+ result = prime * result + ((markers == null) ? 0 : markers.hashCode());+ result = prime * result + x;+ result = prime * result + y;+ return result;+ }++ @Override+ public boolean equals(Object obj) {+ if (this == obj) {+ return true;+ }+ if (obj == null) {return false;}- if(this == obj) {- return true;+ if (getClass() != obj.getClass()) {+ return false;+ }++ MarkerLocation other = (MarkerLocation) obj;+ if (!Objects.equals(addr, other.addr)) {+ return false;+ }++ if (!Objects.equals(markers, other.markers)) {+ return false;+ }++ if (x != other.x) {+ return false;}- if (getClass() != obj.getClass()) {+ if (y != other.y) {return false;}- MarkerLocation ml = (MarkerLocation) obj;- if (addr.equals(ml.addr)) {- if (x == ml.x && y == ml.y) {- if (mgr == ml.mgr) {- return true;- }- }- }- return false;+ return true;}}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.javaindex 345b83e15a..903aca2d01 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/bookmark/BookmarkPluginTest.java@@ -432,7 +432,7 @@ public class BookmarkPluginTest extends AbstractGhidraHeadedIntegrationTest {Bookmark bookmark = list.get(0);Address address = bookmark.getAddress();DeleteBookmarkAction action = new DeleteBookmarkAction(plugin, bookmark, true);- MarkerLocation markerLocation = new MarkerLocation(null, address, 0, 0);+ MarkerLocation markerLocation = new MarkerLocation(null, program, address, 0, 0);performAction(action, createContext(markerLocation), true);list = getBookmarks(program.getBookmarkManager());assertFalse(list.contains(bookmark));@@ -440,7 +440,7 @@ public class BookmarkPluginTest extends AbstractGhidraHeadedIntegrationTest {bookmark = list.get(0);address = bookmark.getAddress();action = new DeleteBookmarkAction(plugin, bookmark, false);- markerLocation = new MarkerLocation(null, address, 0, 0);+ markerLocation = new MarkerLocation(null, program, address, 0, 0);performAction(action, createContext(markerLocation), true);list = getBookmarks(program.getBookmarkManager());assertFalse(list.contains(bookmark));@@ -540,7 +540,7 @@ public class BookmarkPluginTest extends AbstractGhidraHeadedIntegrationTest {applyCmd(program, cmd);List<DockingActionIf> actions = runSwing(() -> plugin.getPopupActions(null,- createContext(new MarkerLocation(null, addr("0100b6db"), 0, 0))));+ createContext(new MarkerLocation(null, program, addr("0100b6db"), 0, 0))));assertEquals(10, actions.size());}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/marker/MarkerTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/marker/MarkerTest.javaindex 8dc69e28d7..63fe7a2e2c 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/marker/MarkerTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/marker/MarkerTest.java@@ -17,10 +17,12 @@ package ghidra.app.plugin.core.marker;import static org.junit.Assert.*;+import java.awt.Color;import java.awt.Point;import java.awt.event.MouseEvent;-import javax.swing.*;+import javax.swing.JCheckBox;+import javax.swing.JPanel;import org.junit.*;@@ -32,16 +34,14 @@ import docking.widgets.fieldpanel.FieldPanel;import docking.widgets.fieldpanel.support.FieldLocation;import docking.widgets.fieldpanel.support.FieldSelection;import ghidra.app.cmd.data.CreateStructureCmd;+import ghidra.app.events.ProgramActivatedPluginEvent;import ghidra.app.events.ProgramSelectionPluginEvent;import ghidra.app.plugin.core.bookmark.BookmarkEditCmd;import ghidra.app.plugin.core.bookmark.BookmarkPlugin;import ghidra.app.plugin.core.clear.ClearDialog;import ghidra.app.plugin.core.clear.ClearPlugin;import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;-import ghidra.app.plugin.core.disassembler.DisassemblerPlugin;import ghidra.app.plugin.core.highlight.SetHighlightPlugin;-import ghidra.app.plugin.core.misc.MyProgramChangesDisplayPlugin;-import ghidra.app.plugin.core.navigation.NextPrevAddressPlugin;import ghidra.app.services.*;import ghidra.app.util.viewer.listingpanel.OverviewProvider;import ghidra.app.util.viewer.util.AddressIndexMap;@@ -66,35 +66,14 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {private MarkerService markerService;private CodeViewerService codeViewerService;- private Address addr(String address) {- return addrFactory.getAddress(address);- }-@Beforepublic void setUp() throws Exception {- env = new TestEnv();- tool = env.showTool();- setupTool(tool);- cb = env.getPlugin(CodeBrowserPlugin.class);- loadProgram("notepad");- env.showTool();- markerService = tool.getService(MarkerService.class);- codeViewerService = tool.getService(CodeViewerService.class);- }-- private void setupTool(PluginTool tool) throws Exception {- tool.addPlugin(CodeBrowserPlugin.class.getName());- tool.addPlugin(MarkerManagerPlugin.class.getName());- tool.addPlugin(NextPrevAddressPlugin.class.getName());- tool.addPlugin(DisassemblerPlugin.class.getName());- tool.addPlugin(ClearPlugin.class.getName());- tool.addPlugin(SetHighlightPlugin.class.getName());- tool.addPlugin(MyProgramChangesDisplayPlugin.class.getName());+ setupProgram();- ClearPlugin cp = getPlugin(tool, ClearPlugin.class);- clearAction = getAction(cp, "Clear Code Bytes");- clearWithOptionsAction = getAction(cp, "Clear With Options");+ env = new TestEnv();+ tool = env.launchDefaultTool(program);+ setupTool(tool);}@After@@ -102,30 +81,10 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {env.dispose();}- private void loadProgram(String programName) throws Exception {-- ClassicSampleX86ProgramBuilder builder = new ClassicSampleX86ProgramBuilder();- builder.setBytes("0x010032d7",- "53 56 8b 74 24 18 33 db 8d 04 b6 c1 e0 04 66 39 98 60 8f 00 01", true);-- builder.setRecordChanges(true); // to trigger changed bookmarks- program = builder.getProgram();-- final ProgramManager pm = tool.getService(ProgramManager.class);- SwingUtilities.invokeAndWait(() -> pm.openProgram(program.getDomainFile()));- builder.dispose();- addrFactory = program.getAddressFactory();- }-- private void waitForBookmarkUpdate() {- program.flushEvents();- waitForProgram(program);- }-@Testpublic void testCursorMarker() {- waitForPostedSwingRunnables();+ waitForSwing();assertTrue(cb.goToField(addr("0x100485c"), "Address", 0, 0));MarkerSet set = markerService.getMarkerSet("Cursor", program);@@ -133,14 +92,6 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {AddressSet addrSet = getAddresses(set);assertEquals(1, addrSet.getNumAddresses());assertEquals(addr("0x100485c"), addrSet.getMinAddress());-- }-- private void setSelection(FieldPanel fp, FieldSelection sel) {- fp.setSelection(sel);- Class<?>[] argClasses = new Class<?>[] { EventTrigger.class };- Object[] args = new Object[] { EventTrigger.GUI_ACTION };- runSwing(() -> invokeInstanceMethod("notifySelectionChanged", fp, argClasses, args));}@Test@@ -237,30 +188,7 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {FieldPanel fp = cb.getFieldPanel();- assertTrue(cb.goToField(addr("0x1001000"), "Bytes", 0, 4));- FieldLocation p1 = fp.getCursorLocation();- assertTrue(cb.goToField(addr("0x1001014"), "Address", 0, 0, 2));- FieldLocation p2 = fp.getCursorLocation();- FieldSelection sel = new FieldSelection();- sel.addRange(p1, p2);-- assertTrue(cb.goToField(addr("0x10032d2"), "Bytes", 0, 4));- p1 = fp.getCursorLocation();- assertTrue(cb.goToField(addr("0x10032d8"), "Address", 0, 0, 2));- p2 = fp.getCursorLocation();- sel.addRange(p1, p2);-- assertTrue(cb.goToField(addr("0xf0001315"), "Bytes", 0, 4));- p1 = fp.getCursorLocation();- assertTrue(cb.goToField(addr("0xf000131b"), "Address", 0, 0, 2));- p2 = fp.getCursorLocation();- sel.addRange(p1, p2);-- setSelection(fp, sel);-- DockingActionIf a = getAction(getPlugin(tool, SetHighlightPlugin.class),- "Set Highlight From Selection");- performAction(a, cb.getProvider(), true);+ makeHighlights(fp);cb.goToField(addr("0x1001000"), "Address", 0, 0);setSelection(fp, new FieldSelection());@@ -272,10 +200,6 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {assertEquals(addr("0x1001000"), set.getMinAddress());}- private AddressSet getAddresses(MarkerSet ms) {- return runSwing(() -> ms.getAddressSet());- }-@Testpublic void testPointMarkers() throws Exception {tool.addPlugin(BookmarkPlugin.class.getName());@@ -289,7 +213,7 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {cmd = new BookmarkEditCmd(addr("0xf000131b"), "Note", "TEST", "comment");applyCmd(program, cmd);- waitForPostedSwingRunnables();+ waitForSwing();MarkerSet set = markerService.getMarkerSet("Note Bookmarks", program);AddressSet addrSet = getAddresses(set);assertEquals(3, addrSet.getNumAddresses());@@ -338,15 +262,12 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {waitForBookmarkUpdate();- ProgramSelection selection = new ProgramSelection(addr("0x10032d8"), addr("0x10032df"));- tool.firePluginEvent(new ProgramSelectionPluginEvent("test", selection, program));+ makeSelection(tool, program, addr("0x10032d8"), addr("0x10032df"));- final ActionContext context = cb.getProvider().getActionContext(null);+ ActionContext context = cb.getProvider().getActionContext(null);runSwing(() -> clearAction.actionPerformed(context));waitForBusyTool(tool); // allow background clear command to complete- waitForSwing();-cb.goToField(addr("0x10032d9"), "Address", 0, 4);int x = 1;@@ -362,11 +283,6 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {}- private int getCursorOffset() {- FieldPanel fp = cb.getFieldPanel();- return fp.getCursorOffset();- }-@Testpublic void testToolTipMaxLines() throws Exception {tool.addPlugin(BookmarkPlugin.class.getName());@@ -378,14 +294,14 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {}if (!applyCmd(program, addCmd)) {- Assert.fail("Could not create bookmarks - " + addCmd.getStatusMsg());+ fail("Could not create bookmarks - " + addCmd.getStatusMsg());}//make a structureCreateStructureCmd cmd = new CreateStructureCmd(addr("0100b6db"), 20);applyCmd(program, cmd);program.flushEvents();- waitForPostedSwingRunnables();+ waitForSwing();MarkerManager mm = (MarkerManager) markerService;@@ -416,11 +332,211 @@ public class MarkerTest extends AbstractGhidraHeadedIntegrationTest {tooltip.endsWith(expected));}+ @Test+ public void testChangeMarkerColors() throws Exception {++ //+ // Tests the setting of colors for more than one program to ensure the internal program+ // color caching and updating works correctly.+ //++ Program program2 = loadSecondProgram();++ Color startColor = Color.PINK;+ MarkerSet markersP1 = markerService.createPointMarker("Awesome Markers", "Description",+ program, 0, true, true,+ true, startColor, null, true);+ MarkerSet markersP2 = markerService.createPointMarker("Awesome Markers", "Description",+ program2, 0, true, true,+ true, startColor, null, true);++ Address addressP1 = addr(program, "0x1001000");+ Address addressP2 = addr(program2, "0x1001004");+ addMarker(markersP1, addressP1);+ addMarker(markersP2, addressP2);++ assertMarkerColor(program, addressP1, startColor);+ assertMarkerColor(program2, addressP2, startColor);++ Color c1 = Color.ORANGE;+ Color c2 = Color.BLUE;++ setMarkerColor(markersP1, c1);+ setMarkerColor(markersP2, c2);++ assertMarkerColor(program, addressP1, c1);+ assertMarkerColor(program2, addressP2, c2);++ Color c3 = Color.RED;+ Color c4 = Color.GREEN;++ // change markers for current program+ setMarkerColor(markersP1, c3);+ assertMarkerColor(program, addressP1, c3);+ assertMarkerColor(program2, addressP2, c2);++ // change markers for secondary program+ setMarkerColor(markersP2, c4);+ assertMarkerColor(program, addressP1, c3);+ assertMarkerColor(program2, addressP2, c4);++ //+ // Switch programs and repeat color changing with a different active program+ //+ switchToProgram(program2);++ setMarkerColor(markersP1, c1);+ assertMarkerColor(program, addressP1, c1);+ assertMarkerColor(program2, addressP2, c4);++ setMarkerColor(markersP2, c2);+ assertMarkerColor(program, addressP1, c1);+ assertMarkerColor(program2, addressP2, c2);+ }++ /*+ Untested Code as of 9/15/20++ -Group markers+ -Group marker activation action++ */++//==================================================================================================+// Private Methods+//==================================================================================================++ private void addMarker(MarkerSet markers, Address address) {+ runSwing(() -> markers.add(address));+ }++ private void setMarkerColor(MarkerSet markers, Color c) {+ runSwing(() -> {+ markers.setMarkerColor(c);+ });+ }++ private void assertMarkerColor(Program p, Address address, Color c) {++ Color actual = runSwing(() -> {+ return markerService.getBackgroundColor(p, address);+ });++ assertEquals("Marker color not correct", c, actual);+ }++ private void switchToProgram(Program p) {+ tool.firePluginEvent(new ProgramActivatedPluginEvent("Test", p));+ }++ private void setupTool(PluginTool tool) throws Exception {++ cb = env.getPlugin(CodeBrowserPlugin.class);+ markerService = tool.getService(MarkerService.class);+ codeViewerService = tool.getService(CodeViewerService.class);++ ClearPlugin cp = getPlugin(tool, ClearPlugin.class);+ clearAction = getAction(cp, "Clear Code Bytes");+ clearWithOptionsAction = getAction(cp, "Clear With Options");+ }++ private Address addr(String address) {+ return addrFactory.getAddress(address);+ }++ private Address addr(Program p, String address) {+ return p.getAddressFactory().getAddress(address);+ }++ private void makeHighlights(FieldPanel fp) {+ makeHighlights(program, fp);+ }++ private void makeHighlights(Program p, FieldPanel fp) {+ assertTrue(cb.goToField(addr(p, "0x1001000"), "Bytes", 0, 4));+ FieldLocation p1 = fp.getCursorLocation();+ assertTrue(cb.goToField(addr(p, "0x1001014"), "Address", 0, 0, 2));+ FieldLocation p2 = fp.getCursorLocation();+ FieldSelection sel = new FieldSelection();+ sel.addRange(p1, p2);++ assertTrue(cb.goToField(addr(p, "0x10032d2"), "Bytes", 0, 4));+ p1 = fp.getCursorLocation();+ assertTrue(cb.goToField(addr(p, "0x10032d8"), "Address", 0, 0, 2));+ p2 = fp.getCursorLocation();+ sel.addRange(p1, p2);++ assertTrue(cb.goToField(addr(p, "0xf0001315"), "Bytes", 0, 4));+ p1 = fp.getCursorLocation();+ assertTrue(cb.goToField(addr(p, "0xf000131b"), "Address", 0, 0, 2));+ p2 = fp.getCursorLocation();+ sel.addRange(p1, p2);++ setSelection(fp, sel);++ DockingActionIf a = getAction(getPlugin(tool, SetHighlightPlugin.class),+ "Set Highlight From Selection");+ performAction(a, cb.getProvider(), true);++ clearSelection(p);+ }++ private void clearSelection(Program p) {+ ProgramSelection emptySelection = new ProgramSelection(p.getAddressFactory());+ tool.firePluginEvent(+ new ProgramSelectionPluginEvent("Test", emptySelection, p));+ }++ private int getCursorOffset() {+ FieldPanel fp = cb.getFieldPanel();+ return fp.getCursorOffset();+ }++ private void setSelection(FieldPanel fp, FieldSelection sel) {+ fp.setSelection(sel);+ Class<?>[] argClasses = new Class<?>[] { EventTrigger.class };+ Object[] args = new Object[] { EventTrigger.GUI_ACTION };+ runSwing(() -> invokeInstanceMethod("notifySelectionChanged", fp, argClasses, args));+ }++ private AddressSet getAddresses(MarkerSet ms) {+ return runSwing(() -> ms.getAddressSet());+ }++ private void setupProgram() throws Exception {++ ClassicSampleX86ProgramBuilder builder = new ClassicSampleX86ProgramBuilder();+ builder.setBytes("0x010032d7",+ "53 56 8b 74 24 18 33 db 8d 04 b6 c1 e0 04 66 39 98 60 8f 00 01", true);++ builder.setRecordChanges(true); // to trigger changed bookmarks+ program = builder.getProgram();+ addrFactory = program.getAddressFactory();+ }++ private Program loadSecondProgram() throws Exception {++ ClassicSampleX86ProgramBuilder builder = new ClassicSampleX86ProgramBuilder(+ "Second Sample Program", true);+ builder.setBytes("0x010032d7",+ "53 56 8b 74 24 18 33 db 8d 04 b6 c1 e0 04 66 39 98 60 8f 00 01", true);++ builder.setRecordChanges(true); // to trigger changed bookmarks+ Program newProgram = builder.getProgram();+ env.open(newProgram);+ return newProgram;+ }++ private void waitForBookmarkUpdate() {+ program.flushEvents();+ waitForProgram(program);+ }+private void removeAllBookmarks() {DockingActionIf action = getAction(cb, "Select All");performAction(action, cb.getProvider(), true);performAction(clearWithOptionsAction, cb.getProvider(), false);- final ClearDialog cd = env.waitForDialogComponent(ClearDialog.class, 500);+ ClearDialog cd = waitForDialogComponent(ClearDialog.class);JCheckBox commentsCheckBox = (JCheckBox) getInstanceField("commentsCb", cd);commentsCheckBox.setSelected(false);