GP-306 fixing graph titles

This commit is contained in:
ghidravore 2020-10-23 18:09:29 -04:00
parent 1c145dd781
commit d2e0b350f4
10 changed files with 43 additions and 33 deletions

View File

@ -69,7 +69,9 @@ public class GraphAST extends GhidraScript {
// graphDisplay.defineVertexAttribute(CODE_ATTRIBUTE); //
// graphDisplay.defineVertexAttribute(SYMBOLS_ATTRIBUTE);
// graphDisplay.defineEdgeAttribute(EDGE_TYPE_ATTRIBUTE);
graphDisplay.setGraph(graph, "Data-flow AST", false, monitor);
String description = "AST Data Flow Graph For " + func.getName();
graphDisplay.setGraph(graph, description, false, monitor);
// Install a handler so the selection/location will map
graphDisplay.setGraphDisplayListener(

View File

@ -121,6 +121,7 @@ public class ASTGraphTask extends Task {
String description =
graphType == GraphType.DATA_FLOW_GRAPH ? "AST Data Flow" : "AST Control Flow";
description = description + " for " + hfunction.getFunction().getName();
display.setGraph(graph, description, false, monitor);
// set the graph location
if (location != null) {

View File

@ -38,7 +38,7 @@ import ghidra.util.task.TaskMonitor;
class ExportAttributedGraphDisplay implements GraphDisplay {
private final PluginTool pluginTool;
private String description;
private String title;
/**
* Create the initial display, the graph-less visualization viewer, and its controls
@ -86,9 +86,9 @@ class ExportAttributedGraphDisplay implements GraphDisplay {
}
@Override
public void setGraph(AttributedGraph graphData, String description, boolean append,
public void setGraph(AttributedGraph graphData, String title, boolean append,
TaskMonitor monitor) {
this.description = description;
this.title = title;
doSetGraphData(graphData);
}
@ -106,8 +106,8 @@ class ExportAttributedGraphDisplay implements GraphDisplay {
}
@Override
public String getGraphDescription() {
return description;
public String getGraphTitle() {
return title;
}
@Override

View File

@ -81,7 +81,7 @@ public class DefaultGraphDisplay implements GraphDisplay {
Logger log = Logger.getLogger(DefaultGraphDisplay.class.getName());
private GraphDisplayListener listener = new DummyGraphDisplayListener();
private String description;
private String title;
/**
* the {@link Graph} to visualize
@ -892,20 +892,21 @@ public class DefaultGraphDisplay implements GraphDisplay {
/**
* consume a {@link Graph} and display it
* @param graph the graph to display or consume
* @param description a description of the graph
* @param title a title for the graph
* @param append if true, append the new graph to any existing graph.
* @param monitor a {@link TaskMonitor} which can be used to cancel the graphing operation
*/
@Override
public void setGraph(AttributedGraph graph, String description, boolean append,
public void setGraph(AttributedGraph graph, String title, boolean append,
TaskMonitor monitor) {
iconCache.clear();
if (append && Objects.equals(description, this.description) && this.graph != null) {
if (append && Objects.equals(title, this.title) && this.graph != null) {
graph = mergeGraphs(graph, this.graph);
}
this.description = description;
this.title = title;
componentProvider.setTitle(title);
int count = graph.getVertexCount();
if (count > MAX_NODES) {
Msg.showWarn(this, null, "Graph Not Rendered - Too many nodes!",
@ -1014,13 +1015,9 @@ public class DefaultGraphDisplay implements GraphDisplay {
viewer.repaint();
}
/**
*
* @return a description of this graph
*/
@Override
public String getGraphDescription() {
return description;
public String getGraphTitle() {
return title;
}
/**

View File

@ -41,7 +41,6 @@ public class DefaultGraphDisplayComponentProvider extends ComponentProviderAdapt
setIcon(DefaultDisplayGraphIcons.PROGRAM_GRAPH_ICON);
setTransient();
setWindowGroup(WINDOW_GROUP);
setSubTitle(Integer.toString(display.getId()));
}
@Override

View File

@ -31,7 +31,7 @@ public class DefaultGraphDisplayProvider implements GraphDisplayProvider {
private final Set<DefaultGraphDisplay> displays = new HashSet<>();
private PluginTool pluginTool;
private Options options;
private int displayCounter;
private int displayCounter = 1;
@Override
public String getName() {

View File

@ -153,7 +153,7 @@ public class BlockGraphTask extends Task {
display.setVertexLabel(CODE_ATTRIBUTE, GraphDisplay.ALIGN_LEFT, 12, true,
codeLimitPerBlock + 1);
}
display.setGraph(graph, actionName, appendGraph, monitor);
display.setGraph(graph, getDescription(), appendGraph, monitor);
if (location != null) {
// initialize the graph location, but don't have the graph send an event
@ -175,6 +175,17 @@ public class BlockGraphTask extends Task {
}
}
private String getDescription() {
String description = actionName;
if (selection != null && !selection.isEmpty()) {
description += ": " + selection.getMinAddress();
}
else {
description += " (Entire Program)";
}
return description;
}
/**
* Set the maximum number of code lines which will be used per block when
* showCode is enabled.

View File

@ -277,11 +277,11 @@ public class ProgramGraphPlugin extends ProgramPlugin
}
private void graphBlockFlow() {
graph("Flow Graph", blockModelService.getActiveBlockModelName(), false);
graph("Block Flow Graph", blockModelService.getActiveBlockModelName(), false);
}
private void graphCodeFlow() {
graph("Code Graph", blockModelService.getActiveBlockModelName(), true);
graph("Code Flow Graph", blockModelService.getActiveBlockModelName(), true);
}
private void graphSubroutines() {
@ -289,7 +289,7 @@ public class ProgramGraphPlugin extends ProgramPlugin
}
private void graphSubroutinesUsing(String modelName) {
graph("Call Graph", modelName, false);
graph("Call Graph (" + modelName + ")", modelName, false);
}
private void graph(String actionName, String modelName, boolean showCode) {

View File

@ -28,7 +28,7 @@ public class TestGraphDisplay implements GraphDisplay {
private Set<String> definedVertexAttributes = new HashSet<>();
private Set<String> definedEdgeAttributes = new HashSet<>();
private AttributedGraph graph;
private String graphDescription;
private String title;
private GraphDisplayListener listener;
private AttributedVertex focusedVertex;
private Set<AttributedVertex> currentSelection;
@ -80,11 +80,11 @@ public class TestGraphDisplay implements GraphDisplay {
}
@Override
public void setGraph(AttributedGraph graph, String description, boolean append,
public void setGraph(AttributedGraph graph, String title, boolean append,
TaskMonitor monitor)
throws CancelledException {
this.graph = graph;
this.graphDescription = description;
this.title = title;
}
@Override
@ -98,8 +98,8 @@ public class TestGraphDisplay implements GraphDisplay {
}
@Override
public String getGraphDescription() {
return graphDescription;
public String getGraphTitle() {
return title;
}
@Override

View File

@ -119,12 +119,12 @@ public interface GraphDisplay {
/**
* Sets the graph to be displayed or consumed by this graph display
* @param graph the graph to display or consume
* @param description a description of the graph
* @param title a title for the graph
* @param monitor a {@link TaskMonitor} which can be used to cancel the graphing operation
* @param append if true, append the new graph to any existing graph.
* @throws CancelledException thrown if the graphing operation was cancelled
*/
public void setGraph(AttributedGraph graph, String description, boolean append,
public void setGraph(AttributedGraph graph, String title, boolean append,
TaskMonitor monitor)
throws CancelledException;
@ -141,10 +141,10 @@ public interface GraphDisplay {
public void updateVertexName(AttributedVertex vertex, String newName);
/**
* Returns the description of the current graph
* @return the description of the current graph
* Returns the title of the current graph
* @return the title of the current graph
*/
public String getGraphDescription();
public String getGraphTitle();
/**
* Adds the action to the graph display. Not all GraphDisplays support adding custom