mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
GP-306 fixing graph titles
This commit is contained in:
parent
1c145dd781
commit
d2e0b350f4
10 changed files with 43 additions and 33 deletions
|
@ -69,7 +69,9 @@ public class GraphAST extends GhidraScript {
|
||||||
// graphDisplay.defineVertexAttribute(CODE_ATTRIBUTE); //
|
// graphDisplay.defineVertexAttribute(CODE_ATTRIBUTE); //
|
||||||
// graphDisplay.defineVertexAttribute(SYMBOLS_ATTRIBUTE);
|
// graphDisplay.defineVertexAttribute(SYMBOLS_ATTRIBUTE);
|
||||||
// graphDisplay.defineEdgeAttribute(EDGE_TYPE_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
|
// Install a handler so the selection/location will map
|
||||||
graphDisplay.setGraphDisplayListener(
|
graphDisplay.setGraphDisplayListener(
|
||||||
|
|
|
@ -121,6 +121,7 @@ public class ASTGraphTask extends Task {
|
||||||
|
|
||||||
String description =
|
String description =
|
||||||
graphType == GraphType.DATA_FLOW_GRAPH ? "AST Data Flow" : "AST Control Flow";
|
graphType == GraphType.DATA_FLOW_GRAPH ? "AST Data Flow" : "AST Control Flow";
|
||||||
|
description = description + " for " + hfunction.getFunction().getName();
|
||||||
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) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ import ghidra.util.task.TaskMonitor;
|
||||||
class ExportAttributedGraphDisplay implements GraphDisplay {
|
class ExportAttributedGraphDisplay implements GraphDisplay {
|
||||||
|
|
||||||
private final PluginTool pluginTool;
|
private final PluginTool pluginTool;
|
||||||
private String description;
|
private String title;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the initial display, the graph-less visualization viewer, and its controls
|
* Create the initial display, the graph-less visualization viewer, and its controls
|
||||||
|
@ -86,9 +86,9 @@ class ExportAttributedGraphDisplay implements GraphDisplay {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGraph(AttributedGraph graphData, String description, boolean append,
|
public void setGraph(AttributedGraph graphData, String title, boolean append,
|
||||||
TaskMonitor monitor) {
|
TaskMonitor monitor) {
|
||||||
this.description = description;
|
this.title = title;
|
||||||
doSetGraphData(graphData);
|
doSetGraphData(graphData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ class ExportAttributedGraphDisplay implements GraphDisplay {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGraphDescription() {
|
public String getGraphTitle() {
|
||||||
return description;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class DefaultGraphDisplay implements GraphDisplay {
|
||||||
Logger log = Logger.getLogger(DefaultGraphDisplay.class.getName());
|
Logger log = Logger.getLogger(DefaultGraphDisplay.class.getName());
|
||||||
|
|
||||||
private GraphDisplayListener listener = new DummyGraphDisplayListener();
|
private GraphDisplayListener listener = new DummyGraphDisplayListener();
|
||||||
private String description;
|
private String title;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the {@link Graph} to visualize
|
* the {@link Graph} to visualize
|
||||||
|
@ -892,20 +892,21 @@ public class DefaultGraphDisplay implements GraphDisplay {
|
||||||
/**
|
/**
|
||||||
* consume a {@link Graph} and display it
|
* consume a {@link Graph} and display it
|
||||||
* @param graph the graph to display or consume
|
* @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 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
|
* @param monitor a {@link TaskMonitor} which can be used to cancel the graphing operation
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setGraph(AttributedGraph graph, String description, boolean append,
|
public void setGraph(AttributedGraph graph, String title, boolean append,
|
||||||
TaskMonitor monitor) {
|
TaskMonitor monitor) {
|
||||||
iconCache.clear();
|
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);
|
graph = mergeGraphs(graph, this.graph);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.description = description;
|
this.title = title;
|
||||||
|
componentProvider.setTitle(title);
|
||||||
int count = graph.getVertexCount();
|
int count = graph.getVertexCount();
|
||||||
if (count > MAX_NODES) {
|
if (count > MAX_NODES) {
|
||||||
Msg.showWarn(this, null, "Graph Not Rendered - Too many nodes!",
|
Msg.showWarn(this, null, "Graph Not Rendered - Too many nodes!",
|
||||||
|
@ -1014,13 +1015,9 @@ public class DefaultGraphDisplay implements GraphDisplay {
|
||||||
viewer.repaint();
|
viewer.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return a description of this graph
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String getGraphDescription() {
|
public String getGraphTitle() {
|
||||||
return description;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,7 +41,6 @@ public class DefaultGraphDisplayComponentProvider extends ComponentProviderAdapt
|
||||||
setIcon(DefaultDisplayGraphIcons.PROGRAM_GRAPH_ICON);
|
setIcon(DefaultDisplayGraphIcons.PROGRAM_GRAPH_ICON);
|
||||||
setTransient();
|
setTransient();
|
||||||
setWindowGroup(WINDOW_GROUP);
|
setWindowGroup(WINDOW_GROUP);
|
||||||
setSubTitle(Integer.toString(display.getId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class DefaultGraphDisplayProvider implements GraphDisplayProvider {
|
||||||
private final Set<DefaultGraphDisplay> displays = new HashSet<>();
|
private final Set<DefaultGraphDisplay> displays = new HashSet<>();
|
||||||
private PluginTool pluginTool;
|
private PluginTool pluginTool;
|
||||||
private Options options;
|
private Options options;
|
||||||
private int displayCounter;
|
private int displayCounter = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
@ -153,7 +153,7 @@ public class BlockGraphTask extends Task {
|
||||||
display.setVertexLabel(CODE_ATTRIBUTE, GraphDisplay.ALIGN_LEFT, 12, true,
|
display.setVertexLabel(CODE_ATTRIBUTE, GraphDisplay.ALIGN_LEFT, 12, true,
|
||||||
codeLimitPerBlock + 1);
|
codeLimitPerBlock + 1);
|
||||||
}
|
}
|
||||||
display.setGraph(graph, actionName, appendGraph, monitor);
|
display.setGraph(graph, getDescription(), appendGraph, monitor);
|
||||||
|
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
// initialize the graph location, but don't have the graph send an event
|
// 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
|
* Set the maximum number of code lines which will be used per block when
|
||||||
* showCode is enabled.
|
* showCode is enabled.
|
||||||
|
|
|
@ -277,11 +277,11 @@ public class ProgramGraphPlugin extends ProgramPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
private void graphBlockFlow() {
|
private void graphBlockFlow() {
|
||||||
graph("Flow Graph", blockModelService.getActiveBlockModelName(), false);
|
graph("Block Flow Graph", blockModelService.getActiveBlockModelName(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void graphCodeFlow() {
|
private void graphCodeFlow() {
|
||||||
graph("Code Graph", blockModelService.getActiveBlockModelName(), true);
|
graph("Code Flow Graph", blockModelService.getActiveBlockModelName(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void graphSubroutines() {
|
private void graphSubroutines() {
|
||||||
|
@ -289,7 +289,7 @@ public class ProgramGraphPlugin extends ProgramPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
private void graphSubroutinesUsing(String modelName) {
|
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) {
|
private void graph(String actionName, String modelName, boolean showCode) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class TestGraphDisplay implements GraphDisplay {
|
||||||
private Set<String> definedVertexAttributes = new HashSet<>();
|
private Set<String> definedVertexAttributes = new HashSet<>();
|
||||||
private Set<String> definedEdgeAttributes = new HashSet<>();
|
private Set<String> definedEdgeAttributes = new HashSet<>();
|
||||||
private AttributedGraph graph;
|
private AttributedGraph graph;
|
||||||
private String graphDescription;
|
private String title;
|
||||||
private GraphDisplayListener listener;
|
private GraphDisplayListener listener;
|
||||||
private AttributedVertex focusedVertex;
|
private AttributedVertex focusedVertex;
|
||||||
private Set<AttributedVertex> currentSelection;
|
private Set<AttributedVertex> currentSelection;
|
||||||
|
@ -80,11 +80,11 @@ public class TestGraphDisplay implements GraphDisplay {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGraph(AttributedGraph graph, String description, boolean append,
|
public void setGraph(AttributedGraph graph, String title, boolean append,
|
||||||
TaskMonitor monitor)
|
TaskMonitor monitor)
|
||||||
throws CancelledException {
|
throws CancelledException {
|
||||||
this.graph = graph;
|
this.graph = graph;
|
||||||
this.graphDescription = description;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -98,8 +98,8 @@ public class TestGraphDisplay implements GraphDisplay {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getGraphDescription() {
|
public String getGraphTitle() {
|
||||||
return graphDescription;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -119,12 +119,12 @@ public interface GraphDisplay {
|
||||||
/**
|
/**
|
||||||
* Sets the graph to be displayed or consumed by this graph display
|
* Sets the graph to be displayed or consumed by this graph display
|
||||||
* @param graph the graph to display or consume
|
* @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 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.
|
* @param append if true, append the new graph to any existing graph.
|
||||||
* @throws CancelledException thrown if the graphing operation was cancelled
|
* @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)
|
TaskMonitor monitor)
|
||||||
throws CancelledException;
|
throws CancelledException;
|
||||||
|
|
||||||
|
@ -141,10 +141,10 @@ public interface GraphDisplay {
|
||||||
public void updateVertexName(AttributedVertex vertex, String newName);
|
public void updateVertexName(AttributedVertex vertex, String newName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the description of the current graph
|
* Returns the title of the current graph
|
||||||
* @return the description 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
|
* Adds the action to the graph display. Not all GraphDisplays support adding custom
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue