Miscellanious bug fixes and code clean up.

This commit is contained in:
ghidravore
2020-09-30 17:31:17 -04:00
parent 608e74f873
commit b647c6cd5b
13 changed files with 405 additions and 346 deletions
@@ -19,6 +19,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import docking.widgets.EventTrigger;
import ghidra.app.cmd.label.AddLabelCmd; import ghidra.app.cmd.label.AddLabelCmd;
import ghidra.app.cmd.label.RenameLabelCmd; import ghidra.app.cmd.label.RenameLabelCmd;
import ghidra.app.events.*; import ghidra.app.events.*;
@@ -65,7 +66,7 @@ public abstract class AddressBasedGraphDisplayListener
} }
@Override @Override
public void locationChanged(String vertexId) { public void locationFocusChanged(String vertexId) {
Address address = getAddressForVertexId(vertexId); Address address = getAddressForVertexId(vertexId);
if (address != null) { if (address != null) {
ProgramLocation location = new ProgramLocation(program, address); ProgramLocation location = new ProgramLocation(program, address);
@@ -101,7 +102,9 @@ public abstract class AddressBasedGraphDisplayListener
ProgramLocationPluginEvent ev = (ProgramLocationPluginEvent) event; ProgramLocationPluginEvent ev = (ProgramLocationPluginEvent) event;
if (isMyProgram(ev.getProgram())) { if (isMyProgram(ev.getProgram())) {
ProgramLocation location = ev.getLocation(); ProgramLocation location = ev.getLocation();
graphDisplay.setLocation(getVertexIdForAddress(location.getAddress())); String id = getVertexIdForAddress(location.getAddress());
// update graph location, but tell it not to send out event
graphDisplay.setLocationFocus(id, EventTrigger.INTERNAL_ONLY);
} }
} }
else if (event instanceof ProgramSelectionPluginEvent) { else if (event instanceof ProgramSelectionPluginEvent) {
@@ -110,7 +113,8 @@ public abstract class AddressBasedGraphDisplayListener
ProgramSelection selection = ev.getSelection(); ProgramSelection selection = ev.getSelection();
List<String> selectedVertices = getVertices(selection); List<String> selectedVertices = getVertices(selection);
if (selectedVertices != null) { if (selectedVertices != null) {
graphDisplay.selectVertices(selectedVertices); // since we are responding to an event, tell the GraphDisplay not to send event
graphDisplay.selectVertices(selectedVertices, EventTrigger.INTERNAL_ONLY);
} }
} }
} }
@@ -17,6 +17,7 @@ package ghidra.app.plugin.core.decompile.actions;
import static ghidra.app.plugin.core.decompile.actions.ASTGraphTask.GraphType.*; import static ghidra.app.plugin.core.decompile.actions.ASTGraphTask.GraphType.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import ghidra.app.plugin.core.decompile.actions.ASTGraphTask.GraphType; import ghidra.app.plugin.core.decompile.actions.ASTGraphTask.GraphType;
@@ -26,6 +27,7 @@ import ghidra.program.model.address.*;
import ghidra.program.model.pcode.HighFunction; import ghidra.program.model.pcode.HighFunction;
import ghidra.program.model.pcode.PcodeBlockBasic; import ghidra.program.model.pcode.PcodeBlockBasic;
import ghidra.service.graph.GraphDisplay; import ghidra.service.graph.GraphDisplay;
import ghidra.util.exception.AssertException;
/** /**
* Listener for when an AST graph's nodes are selected. * Listener for when an AST graph's nodes are selected.
@@ -43,8 +45,20 @@ public class ASTGraphDisplayListener extends AddressBasedGraphDisplayListener {
@Override @Override
protected List<String> getVertices(AddressSetView selection) { protected List<String> getVertices(AddressSetView selection) {
if (graphType != CONTROL_FLOW_GRAPH) {
return null; return null;
} }
List<String> vertices = new ArrayList<>();
List<PcodeBlockBasic> blocks = hfunction.getBasicBlocks();
for (PcodeBlockBasic block : blocks) {
Address start = block.getStart();
Address stop = block.getStop();
if (selection.intersects(start, stop)) {
vertices.add(Integer.toString(block.getIndex()));
}
}
return vertices;
}
@Override @Override
protected AddressSet getAddressSetForVertices(List<String> vertexIds) { protected AddressSet getAddressSetForVertices(List<String> vertexIds) {
@@ -53,7 +67,6 @@ public class ASTGraphDisplayListener extends AddressBasedGraphDisplayListener {
} }
AddressSet set = new AddressSet(); AddressSet set = new AddressSet();
Address location = null;
List<PcodeBlockBasic> blocks = hfunction.getBasicBlocks(); List<PcodeBlockBasic> blocks = hfunction.getBasicBlocks();
for (String vertixId : vertexIds) { for (String vertixId : vertexIds) {
try { try {
@@ -61,9 +74,6 @@ public class ASTGraphDisplayListener extends AddressBasedGraphDisplayListener {
PcodeBlockBasic block = blocks.get(index); PcodeBlockBasic block = blocks.get(index);
Address start = block.getStart(); Address start = block.getStart();
set.addRange(start, block.getStop()); set.addRange(start, block.getStop());
if (location == null || start.compareTo(location) < 0) {
location = start;
}
} }
catch (NumberFormatException e) { catch (NumberFormatException e) {
// continue // continue
@@ -90,7 +100,16 @@ public class ASTGraphDisplayListener extends AddressBasedGraphDisplayListener {
@Override @Override
protected Address getAddressForVertexId(String vertexId) { protected Address getAddressForVertexId(String vertexId) {
return null; List<PcodeBlockBasic> blocks = hfunction.getBasicBlocks();
try {
int index = Integer.parseInt(vertexId);
PcodeBlockBasic block = blocks.get(index);
return block.getStart();
}
catch (NumberFormatException e) {
throw new AssertException("Bad vertex id, expected a number but got " + vertexId);
}
} }
} }
@@ -17,6 +17,7 @@ package ghidra.app.plugin.core.decompile.actions;
import java.util.Iterator; import java.util.Iterator;
import docking.widgets.EventTrigger;
import ghidra.app.services.GraphDisplayBroker; import ghidra.app.services.GraphDisplayBroker;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
@@ -122,7 +123,9 @@ public class ASTGraphTask extends Task {
display.setGraph(graph, description, false, monitor); display.setGraph(graph, description, false, monitor);
// set the graph location // set the graph location
if (location != null) { if (location != null) {
display.setLocation(displayListener.getVertexIdForAddress(location)); String id = displayListener.getVertexIdForAddress(location);
// update graph location, but don't have it send out event
display.setLocationFocus(id, EventTrigger.INTERNAL_ONLY);
} }
} }
@@ -19,6 +19,7 @@ import java.util.List;
import org.jgrapht.Graph; import org.jgrapht.Graph;
import docking.widgets.EventTrigger;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.service.graph.*; import ghidra.service.graph.*;
import ghidra.util.Swing; import ghidra.util.Swing;
@@ -56,12 +57,12 @@ class ExportAttributedGraphDisplay implements GraphDisplay {
} }
@Override @Override
public void selectVertices(List<String> vertexList) { public void selectVertices(List<String> vertexList, EventTrigger eventTrigger) {
// This display is not interactive, so N/A // This display is not interactive, so N/A
} }
@Override @Override
public void setLocation(String vertexID) { public void setLocationFocus(String vertexID, EventTrigger eventTrigger) {
// This display is not interactive, so N/A // This display is not interactive, so N/A
} }
@@ -23,17 +23,15 @@ import org.jungrapht.visualization.MultiLayerTransformer;
import org.jungrapht.visualization.VisualizationViewer; import org.jungrapht.visualization.VisualizationViewer;
import ghidra.graph.job.AbstractAnimatorJob; import ghidra.graph.job.AbstractAnimatorJob;
import ghidra.service.graph.AttributedEdge;
import ghidra.service.graph.AttributedVertex;
public class CenterAnimation<V, E> extends AbstractAnimatorJob { public class CenterAnimationJob extends AbstractAnimatorJob {
protected int duration = 1000; protected int duration = 1000;
private final Point2D oldPoint; private final Point2D oldPoint;
private final Point2D newPoint; private final Point2D newPoint;
private final Point2D lastPoint = new Point2D.Double(); private final Point2D lastPoint = new Point2D.Double();
private final VisualizationViewer<V, E> viewer; private final VisualizationViewer<?, ?> viewer;
public CenterAnimation(VisualizationViewer<V, E> viewer, public CenterAnimationJob(VisualizationViewer<?, ?> viewer,
Point2D oldPoint, Point2D newPoint) { Point2D oldPoint, Point2D newPoint) {
this.viewer = viewer; this.viewer = viewer;
this.oldPoint = oldPoint; this.oldPoint = oldPoint;
@@ -15,21 +15,14 @@
*/ */
package ghidra.graph.visualization; package ghidra.graph.visualization;
import org.jungrapht.visualization.layout.algorithms.BalloonLayoutAlgorithm; import java.util.function.Function;
import org.jungrapht.visualization.layout.algorithms.CircleLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.EiglspergerLayoutAlgorithm; import org.jungrapht.visualization.layout.algorithms.*;
import org.jungrapht.visualization.layout.algorithms.FRLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.GEMLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.KKLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.LayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.RadialTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.TidierRadialTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.TidierTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.TreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.repulsion.BarnesHutFRRepulsion; import org.jungrapht.visualization.layout.algorithms.repulsion.BarnesHutFRRepulsion;
import org.jungrapht.visualization.layout.algorithms.sugiyama.Layering; import org.jungrapht.visualization.layout.algorithms.sugiyama.Layering;
import java.util.function.Function; import ghidra.service.graph.AttributedEdge;
import ghidra.service.graph.AttributedVertex;
/** /**
* A central location to list and provide all layout algorithms, their names, and their builders * A central location to list and provide all layout algorithms, their names, and their builders
@@ -38,8 +31,8 @@ import java.util.function.Function;
* This class provides LayoutAlgorithm builders instead of LayoutAlgorithms because some LayoutAlgorithms * This class provides LayoutAlgorithm builders instead of LayoutAlgorithms because some LayoutAlgorithms
* accumulate state information (so are used only one time). * accumulate state information (so are used only one time).
*/ */
class LayoutFunction<V, E> class LayoutFunction
implements Function<String, LayoutAlgorithm.Builder<V, ?, ?>> { implements Function<String, LayoutAlgorithm.Builder<AttributedVertex, ?, ?>> {
static final String KAMADA_KAWAI = "Force Balanced"; static final String KAMADA_KAWAI = "Force Balanced";
static final String FRUCTERMAN_REINGOLD = "Force Directed"; static final String FRUCTERMAN_REINGOLD = "Force Directed";
@@ -64,51 +57,53 @@ class LayoutFunction<V, E>
} }
@Override @Override
public LayoutAlgorithm.Builder<V, ?, ?> apply(String name) { public LayoutAlgorithm.Builder<AttributedVertex, ?, ?> apply(String name) {
switch(name) { switch(name) {
case GEM: case GEM:
return GEMLayoutAlgorithm.edgeAwareBuilder(); return GEMLayoutAlgorithm.edgeAwareBuilder();
case KAMADA_KAWAI: case KAMADA_KAWAI:
return KKLayoutAlgorithm.<V> builder() return KKLayoutAlgorithm.<AttributedVertex> builder()
.preRelaxDuration(1000); .preRelaxDuration(1000);
case FRUCTERMAN_REINGOLD: case FRUCTERMAN_REINGOLD:
return FRLayoutAlgorithm.<V> builder() return FRLayoutAlgorithm.<AttributedVertex> builder()
.repulsionContractBuilder(BarnesHutFRRepulsion.builder()); .repulsionContractBuilder(BarnesHutFRRepulsion.builder());
case CIRCLE_MINCROSS: case CIRCLE_MINCROSS:
return CircleLayoutAlgorithm.<V> builder() return CircleLayoutAlgorithm.<AttributedVertex> builder()
.reduceEdgeCrossing(true); .reduceEdgeCrossing(true);
case TIDIER_RADIAL_TREE: case TIDIER_RADIAL_TREE:
return TidierRadialTreeLayoutAlgorithm.<V, E> edgeAwareBuilder(); return TidierRadialTreeLayoutAlgorithm
.<AttributedVertex, AttributedEdge> edgeAwareBuilder();
case MIN_CROSS_TOP_DOWN: case MIN_CROSS_TOP_DOWN:
return EiglspergerLayoutAlgorithm return EiglspergerLayoutAlgorithm
.<V, E> edgeAwareBuilder() .<AttributedVertex, AttributedEdge> edgeAwareBuilder()
.layering(Layering.TOP_DOWN); .layering(Layering.TOP_DOWN);
case MIN_CROSS_LONGEST_PATH: case MIN_CROSS_LONGEST_PATH:
return EiglspergerLayoutAlgorithm return EiglspergerLayoutAlgorithm
.<V, E> edgeAwareBuilder() .<AttributedVertex, AttributedEdge> edgeAwareBuilder()
.layering(Layering.LONGEST_PATH); .layering(Layering.LONGEST_PATH);
case MIN_CROSS_NETWORK_SIMPLEX: case MIN_CROSS_NETWORK_SIMPLEX:
return EiglspergerLayoutAlgorithm return EiglspergerLayoutAlgorithm
.<V, E> edgeAwareBuilder() .<AttributedVertex, AttributedEdge> edgeAwareBuilder()
.layering(Layering.NETWORK_SIMPLEX); .layering(Layering.NETWORK_SIMPLEX);
case MIN_CROSS_COFFMAN_GRAHAM: case MIN_CROSS_COFFMAN_GRAHAM:
return EiglspergerLayoutAlgorithm return EiglspergerLayoutAlgorithm
.<V, E> edgeAwareBuilder() .<AttributedVertex, AttributedEdge> edgeAwareBuilder()
.layering(Layering.COFFMAN_GRAHAM); .layering(Layering.COFFMAN_GRAHAM);
case RADIAL: case RADIAL:
return RadialTreeLayoutAlgorithm return RadialTreeLayoutAlgorithm
.<V> builder() .<AttributedVertex> builder()
.verticalVertexSpacing(300); .verticalVertexSpacing(300);
case BALLOON: case BALLOON:
return BalloonLayoutAlgorithm return BalloonLayoutAlgorithm
.<V> builder() .<AttributedVertex> builder()
.verticalVertexSpacing(300); .verticalVertexSpacing(300);
case TREE: case TREE:
return TreeLayoutAlgorithm return TreeLayoutAlgorithm
.builder(); .builder();
case TIDIER_TREE: case TIDIER_TREE:
default: default:
return TidierTreeLayoutAlgorithm.<V, E> edgeAwareBuilder(); return TidierTreeLayoutAlgorithm
.<AttributedVertex, AttributedEdge> edgeAwareBuilder();
} }
} }
} }
@@ -15,61 +15,57 @@
*/ */
package ghidra.graph.visualization; package ghidra.graph.visualization;
import org.jungrapht.visualization.RenderContext; import static ghidra.graph.visualization.LayoutFunction.*;
import org.jungrapht.visualization.VisualizationServer;
import org.jungrapht.visualization.layout.algorithms.Balloon;
import org.jungrapht.visualization.layout.algorithms.BalloonLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.EdgeSorting;
import org.jungrapht.visualization.layout.algorithms.Layered;
import org.jungrapht.visualization.layout.algorithms.LayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.RadialTreeLayout;
import org.jungrapht.visualization.layout.algorithms.RadialTreeLayoutAlgorithm;
import org.jungrapht.visualization.layout.algorithms.TreeLayout;
import org.jungrapht.visualization.layout.algorithms.util.VertexBoundsFunctionConsumer;
import org.jungrapht.visualization.layout.model.Rectangle;
import org.jungrapht.visualization.util.LayoutAlgorithmTransition;
import org.jungrapht.visualization.util.LayoutPaintable;
import java.util.Comparator; import java.util.Comparator;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import static ghidra.graph.visualization.LayoutFunction.TIDIER_TREE; import org.jungrapht.visualization.RenderContext;
import org.jungrapht.visualization.VisualizationServer;
import org.jungrapht.visualization.layout.algorithms.*;
import org.jungrapht.visualization.layout.algorithms.util.VertexBoundsFunctionConsumer;
import org.jungrapht.visualization.layout.model.Rectangle;
import org.jungrapht.visualization.util.LayoutAlgorithmTransition;
import org.jungrapht.visualization.util.LayoutPaintable;
import ghidra.service.graph.AttributedEdge;
import ghidra.service.graph.AttributedVertex;
/** /**
* Manages the selection and transition from one {@link LayoutAlgorithm} to another * Manages the selection and transition from one {@link LayoutAlgorithm} to another
*/ */
class LayoutTransitionManager<V, E> { class LayoutTransitionManager {
LayoutFunction layoutFunction = new LayoutFunction(); LayoutFunction layoutFunction = new LayoutFunction();
/** /**
* the {@link VisualizationServer} used to display graphs using the requested {@link LayoutAlgorithm} * the {@link VisualizationServer} used to display graphs using the requested {@link LayoutAlgorithm}
*/ */
VisualizationServer<V, E> visualizationServer; VisualizationServer<AttributedVertex, AttributedEdge> visualizationServer;
/** /**
* a {@link Predicate} to assist in determining which vertices are root vertices (for Tree layouts) * a {@link Predicate} to assist in determining which vertices are root vertices (for Tree layouts)
*/ */
Predicate<V> rootPredicate; Predicate<AttributedVertex> rootPredicate;
/** /**
* a {@link Comparator} to sort edges during layout graph traversal * a {@link Comparator} to sort edges during layout graph traversal
*/ */
Comparator<E> edgeComparator = (e1, e2) -> 0; Comparator<AttributedEdge> edgeComparator = (e1, e2) -> 0;
/** /**
* a {@link Function} to provide {@link Rectangle} (and thus bounds} for vertices * a {@link Function} to provide {@link Rectangle} (and thus bounds} for vertices
*/ */
Function<V, Rectangle> vertexBoundsFunction; Function<AttributedVertex, Rectangle> vertexBoundsFunction;
/** /**
* the {@link RenderContext} used to draw the graph * the {@link RenderContext} used to draw the graph
*/ */
RenderContext<V, E> renderContext; RenderContext<AttributedVertex, AttributedEdge> renderContext;
LayoutPaintable.BalloonRings<V, E> balloonLayoutRings; LayoutPaintable.BalloonRings<AttributedVertex, AttributedEdge> balloonLayoutRings;
LayoutPaintable.RadialRings<V> radialLayoutRings; LayoutPaintable.RadialRings<AttributedVertex> radialLayoutRings;
/** /**
@@ -78,8 +74,8 @@ class LayoutTransitionManager<V, E> {
* @param rootPredicate selects root vertices * @param rootPredicate selects root vertices
*/ */
public LayoutTransitionManager( public LayoutTransitionManager(
VisualizationServer<V, E> visualizationServer, VisualizationServer<AttributedVertex, AttributedEdge> visualizationServer,
Predicate<V> rootPredicate) { Predicate<AttributedVertex> rootPredicate) {
this.visualizationServer = visualizationServer; this.visualizationServer = visualizationServer;
this.rootPredicate = rootPredicate; this.rootPredicate = rootPredicate;
@@ -87,7 +83,7 @@ class LayoutTransitionManager<V, E> {
this.vertexBoundsFunction = visualizationServer.getRenderContext().getVertexBoundsFunction(); this.vertexBoundsFunction = visualizationServer.getRenderContext().getVertexBoundsFunction();
} }
public void setEdgeComparator(Comparator<E> edgeComparator) { public void setEdgeComparator(Comparator<AttributedEdge> edgeComparator) {
this.edgeComparator = edgeComparator; this.edgeComparator = edgeComparator;
} }
@@ -97,19 +93,19 @@ class LayoutTransitionManager<V, E> {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void setLayout(String layoutName) { public void setLayout(String layoutName) {
LayoutAlgorithm.Builder<V, ?, ?> builder = layoutFunction.apply(layoutName); LayoutAlgorithm.Builder<AttributedVertex, ?, ?> builder = layoutFunction.apply(layoutName);
LayoutAlgorithm<V> layoutAlgorithm = builder.build(); LayoutAlgorithm<AttributedVertex> layoutAlgorithm = builder.build();
if (layoutAlgorithm instanceof VertexBoundsFunctionConsumer) { if (layoutAlgorithm instanceof VertexBoundsFunctionConsumer) {
((VertexBoundsFunctionConsumer<V>) layoutAlgorithm) ((VertexBoundsFunctionConsumer<AttributedVertex>) layoutAlgorithm)
.setVertexBoundsFunction(vertexBoundsFunction); .setVertexBoundsFunction(vertexBoundsFunction);
} }
if (layoutAlgorithm instanceof Layered) { if (layoutAlgorithm instanceof Layered) {
((Layered<V, E>)layoutAlgorithm) ((Layered<AttributedVertex, AttributedEdge>) layoutAlgorithm)
.setMaxLevelCrossFunction(g -> .setMaxLevelCrossFunction(g ->
Math.max(1, Math.min(10, 500 / g.vertexSet().size()))); Math.max(1, Math.min(10, 500 / g.vertexSet().size())));
} }
if (layoutAlgorithm instanceof TreeLayout) { if (layoutAlgorithm instanceof TreeLayout) {
((TreeLayout<V>) layoutAlgorithm).setRootPredicate(rootPredicate); ((TreeLayout<AttributedVertex>) layoutAlgorithm).setRootPredicate(rootPredicate);
} }
// remove any previously added layout paintables // remove any previously added layout paintables
removePaintable(radialLayoutRings); removePaintable(radialLayoutRings);
@@ -117,18 +113,19 @@ class LayoutTransitionManager<V, E> {
if (layoutAlgorithm instanceof BalloonLayoutAlgorithm) { if (layoutAlgorithm instanceof BalloonLayoutAlgorithm) {
balloonLayoutRings = balloonLayoutRings =
new LayoutPaintable.BalloonRings<>( new LayoutPaintable.BalloonRings<>(
visualizationServer, (BalloonLayoutAlgorithm<V>) layoutAlgorithm); visualizationServer,
(BalloonLayoutAlgorithm<AttributedVertex>) layoutAlgorithm);
visualizationServer.addPreRenderPaintable(balloonLayoutRings); visualizationServer.addPreRenderPaintable(balloonLayoutRings);
} }
if (layoutAlgorithm instanceof RadialTreeLayout) { if (layoutAlgorithm instanceof RadialTreeLayout) {
radialLayoutRings = radialLayoutRings =
new LayoutPaintable.RadialRings<>( new LayoutPaintable.RadialRings<>(
visualizationServer, (RadialTreeLayout<V>) layoutAlgorithm); visualizationServer, (RadialTreeLayout<AttributedVertex>) layoutAlgorithm);
visualizationServer.addPreRenderPaintable(radialLayoutRings); visualizationServer.addPreRenderPaintable(radialLayoutRings);
} }
if (layoutAlgorithm instanceof EdgeSorting) { if (layoutAlgorithm instanceof EdgeSorting) {
((EdgeSorting<E>) layoutAlgorithm).setEdgeComparator(edgeComparator); ((EdgeSorting<AttributedEdge>) layoutAlgorithm).setEdgeComparator(edgeComparator);
} }
LayoutAlgorithmTransition.apply(visualizationServer, layoutAlgorithm); LayoutAlgorithmTransition.apply(visualizationServer, layoutAlgorithm);
} }
@@ -140,22 +137,22 @@ class LayoutTransitionManager<V, E> {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public LayoutAlgorithm<V> getInitialLayoutAlgorithm() { public LayoutAlgorithm<AttributedVertex> getInitialLayoutAlgorithm() {
LayoutAlgorithm<V> initialLayoutAlgorithm = LayoutAlgorithm<AttributedVertex> initialLayoutAlgorithm =
layoutFunction.apply(TIDIER_TREE).build(); layoutFunction.apply(TIDIER_TREE).build();
if (initialLayoutAlgorithm instanceof TreeLayout) { if (initialLayoutAlgorithm instanceof TreeLayout) {
((TreeLayout<V>) initialLayoutAlgorithm) ((TreeLayout<AttributedVertex>) initialLayoutAlgorithm)
.setRootPredicate(rootPredicate); .setRootPredicate(rootPredicate);
((TreeLayout<V>) initialLayoutAlgorithm) ((TreeLayout<AttributedVertex>) initialLayoutAlgorithm)
.setVertexBoundsFunction(vertexBoundsFunction); .setVertexBoundsFunction(vertexBoundsFunction);
} }
if (initialLayoutAlgorithm instanceof EdgeSorting) { if (initialLayoutAlgorithm instanceof EdgeSorting) {
((EdgeSorting<E>) initialLayoutAlgorithm) ((EdgeSorting<AttributedEdge>) initialLayoutAlgorithm)
.setEdgeComparator(edgeComparator); .setEdgeComparator(edgeComparator);
} }
if (initialLayoutAlgorithm instanceof VertexBoundsFunctionConsumer) { if (initialLayoutAlgorithm instanceof VertexBoundsFunctionConsumer) {
((VertexBoundsFunctionConsumer<V>) initialLayoutAlgorithm) ((VertexBoundsFunctionConsumer<AttributedVertex>) initialLayoutAlgorithm)
.setVertexBoundsFunction(vertexBoundsFunction); .setVertexBoundsFunction(vertexBoundsFunction);
} }
return initialLayoutAlgorithm; return initialLayoutAlgorithm;
@@ -18,6 +18,7 @@ package ghidra.graph.program;
import java.awt.Color; import java.awt.Color;
import java.util.*; import java.util.*;
import docking.widgets.EventTrigger;
import ghidra.app.plugin.core.colorizer.ColorizingService; import ghidra.app.plugin.core.colorizer.ColorizingService;
import ghidra.framework.plugintool.PluginTool; import ghidra.framework.plugintool.PluginTool;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
@@ -156,12 +157,15 @@ public class BlockGraphTask extends Task {
display.setGraph(graph, actionName, appendGraph, monitor); display.setGraph(graph, actionName, appendGraph, monitor);
if (location != null) { if (location != null) {
display.setLocation(listener.getVertexIdForAddress(location.getAddress())); // initialize the graph location, but don't have the graph send an event
String id = listener.getVertexIdForAddress(location.getAddress());
display.setLocationFocus(id, EventTrigger.INTERNAL_ONLY);
} }
if (selection != null && !selection.isEmpty()) { if (selection != null && !selection.isEmpty()) {
List<String> selectedVertices = listener.getVertices(selection); List<String> selectedVertices = listener.getVertices(selection);
if (selectedVertices != null) { if (selectedVertices != null) {
display.selectVertices(selectedVertices); // intialize the graph selection, but don't have the graph send an event
display.selectVertices(selectedVertices, EventTrigger.INTERNAL_ONLY);
} }
} }
} }
@@ -17,6 +17,7 @@ package ghidra.graph.program;
import java.util.*; import java.util.*;
import docking.widgets.EventTrigger;
import ghidra.service.graph.*; import ghidra.service.graph.*;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
@@ -37,7 +38,7 @@ public class TestGraphDisplay implements GraphDisplay {
} }
@Override @Override
public void setLocation(String vertexID) { public void setLocationFocus(String vertexID, EventTrigger eventTrigger) {
currentFocusedVertex = vertexID; currentFocusedVertex = vertexID;
} }
@@ -46,7 +47,7 @@ public class TestGraphDisplay implements GraphDisplay {
} }
@Override @Override
public void selectVertices(List<String> vertexList) { public void selectVertices(List<String> vertexList, EventTrigger eventTrigger) {
currentSelection = vertexList; currentSelection = vertexList;
} }
@@ -103,7 +104,7 @@ public class TestGraphDisplay implements GraphDisplay {
} }
public void focusChanged(String vertexId) { public void focusChanged(String vertexId) {
listener.locationChanged(vertexId); listener.locationFocusChanged(vertexId);
} }
public void selectionChanged(List<String> vertexIds) { public void selectionChanged(List<String> vertexIds) {
@@ -30,7 +30,7 @@ public class DummyGraphDisplayListener implements GraphDisplayListener {
} }
@Override @Override
public void locationChanged(String vertexId) { public void locationFocusChanged(String vertexId) {
// I'm a dummy // I'm a dummy
} }
@@ -17,6 +17,7 @@ package ghidra.service.graph;
import java.util.List; import java.util.List;
import docking.widgets.EventTrigger;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
@@ -41,18 +42,31 @@ public interface GraphDisplay {
public void setGraphDisplayListener(GraphDisplayListener listener); public void setGraphDisplayListener(GraphDisplayListener listener);
/** /**
* Tells the graph display window to focus * Tells the graph display window to focus the vertex with the given id.
* *
* @param vertexID the id of the vertex to focus * @param vertexID the id of the vertex to focus
* @param eventTrigger Provides a hint to the GraphDisplay as to why we are updating the
* graph location so that the GraphDisplay can decide if it should send out a notification via
* the {@link GraphDisplayListener#locationFocusChanged(String)}. For example, if we are updating
* the the location due to an event from the main application, we don't want to notify the
* application the graph changed to avoid event cycles. See {@link EventTrigger} for more
* information.
*
*/ */
public void setLocation(String vertexID); public void setLocationFocus(String vertexID, EventTrigger eventTrigger);
/** /**
* Tells the graph display window to select the vertices with the given ids * Tells the graph display window to select the vertices with the given ids
* *
* @param vertexList the list of vertex ids to select * @param vertexList the list of vertex ids to select
* @param eventTrigger Provides a hint to the GraphDisplay as to why we are updating the
* graph location so that the GraphDisplay can decide if it should send out a notification via
* the {@link GraphDisplayListener#locationFocusChanged(String)}. For example, if we are updating
* the the location due to an event from the main application, we don't want to notify the
* application the graph changed to avoid event cycles. See {@link EventTrigger} for more
* information.
*/ */
public void selectVertices(List<String> vertexList); public void selectVertices(List<String> vertexList, EventTrigger eventTrigger);
/** /**
* Closes this graph display window. * Closes this graph display window.
@@ -103,7 +117,7 @@ public interface GraphDisplay {
/** /**
* Updates a vertex to a new name * Updates a vertex to a new name
* @param id the vertix id * @param id the vertex id
* @param newName the new name of the vertex * @param newName the new name of the vertex
*/ */
public void updateVertexName(String id, String newName); public void updateVertexName(String id, String newName);
@@ -37,7 +37,7 @@ public interface GraphDisplayListener {
* Notification that the "focused" (active) vertex has changed. * Notification that the "focused" (active) vertex has changed.
* @param vertexId the vertex id of the currently "focused" vertex * @param vertexId the vertex id of the currently "focused" vertex
*/ */
public void locationChanged(String vertexId); public void locationFocusChanged(String vertexId);
default boolean updateVertexName(String vertexId, String oldName, String newName) { default boolean updateVertexName(String vertexId, String oldName, String newName) {
// no op // no op