Ghidra is a software reverse engineering (SRE) framework
GP-306 fixing graph titles
ghidravored2e0b350f486
diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/GraphAST.java b/Ghidra/Features/Decompiler/ghidra_scripts/GraphAST.javaindex 87ddf30c9e..116ef27dab 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/GraphAST.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/GraphAST.java@@ -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 mapgraphDisplay.setGraphDisplayListener(diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.javaindex a90afdd28a..2ed6c445fe 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ASTGraphTask.java@@ -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 locationif (location != null) {diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/export/ExportAttributedGraphDisplay.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/export/ExportAttributedGraphDisplay.javaindex 44fa500bbb..51cbca873b 100644--- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/export/ExportAttributedGraphDisplay.java+++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/export/ExportAttributedGraphDisplay.java@@ -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;}@Overridediff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.javaindex 7f704c9a78..c3938b79c3 100644--- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java+++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplay.java@@ -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;}/**diff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayComponentProvider.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayComponentProvider.javaindex 5faaaf9765..7658bb42db 100644--- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayComponentProvider.java+++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayComponentProvider.java@@ -41,7 +41,6 @@ public class DefaultGraphDisplayComponentProvider extends ComponentProviderAdaptsetIcon(DefaultDisplayGraphIcons.PROGRAM_GRAPH_ICON);setTransient();setWindowGroup(WINDOW_GROUP);- setSubTitle(Integer.toString(display.getId()));}@Overridediff --git a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayProvider.java b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayProvider.javaindex aa4be85a83..f95a3ff997 100644--- a/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayProvider.java+++ b/Ghidra/Features/GraphServices/src/main/java/ghidra/graph/visualization/DefaultGraphDisplayProvider.java@@ -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;@Overridepublic String getName() {diff --git a/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/BlockGraphTask.java b/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/BlockGraphTask.javaindex dfd5fa95ac..c4266658d6 100644--- a/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/BlockGraphTask.java+++ b/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/BlockGraphTask.java@@ -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.diff --git a/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/ProgramGraphPlugin.java b/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/ProgramGraphPlugin.javaindex fbfda93055..0279faa16f 100644--- a/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/ProgramGraphPlugin.java+++ b/Ghidra/Features/ProgramGraph/src/main/java/ghidra/graph/program/ProgramGraphPlugin.java@@ -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) {diff --git a/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/TestGraphDisplay.java b/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/TestGraphDisplay.javaindex 8a3ccab2a2..a538b39ee2 100644--- a/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/TestGraphDisplay.java+++ b/Ghidra/Features/ProgramGraph/src/test/java/ghidra/graph/program/TestGraphDisplay.java@@ -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;}@Overridediff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/service/graph/GraphDisplay.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/service/graph/GraphDisplay.javaindex ba57ffe0f1..5374264cc7 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/service/graph/GraphDisplay.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/service/graph/GraphDisplay.java@@ -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