Ghidra is a software reverse engineering (SRE) framework
GP-949 Added graph API method to set descriptions (tooltips) on vertices and edges.
largepapyrus444100d83595
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/TypeGraphTask.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/TypeGraphTask.javaindex a5d1c2201e..f962c01f26 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/TypeGraphTask.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/actions/TypeGraphTask.java@@ -15,6 +15,7 @@*/package ghidra.app.plugin.core.datamgr.actions;+import ghidra.app.util.ToolTipUtils;import ghidra.program.model.data.*;import ghidra.service.graph.*;import ghidra.util.Msg;@@ -37,7 +38,6 @@ public class TypeGraphTask extends Task {public static final String TYPE_ATTRIBUTE = "Type";public static final String EMBEDDED = "Composite";public static final String POINTER = "Reference";- public static final String CONTENTS_ATTRIBUTE = "Contents";/** Constructor@@ -87,7 +87,8 @@ public class TypeGraphTask extends Task {AttributedVertex lastVertex, String edgeType, TaskMonitor monitor)throws CancelledException {AttributedVertex newVertex = new AttributedVertex(struct.getName());- newVertex.setAttribute(CONTENTS_ATTRIBUTE, struct.toString());+ newVertex.setDescription(ToolTipUtils.getToolTipText(struct));+if (lastVertex == null) {graph.addVertex(newVertex);}diff --git a/Ghidra/Framework/Graph/src/main/java/ghidra/service/graph/Attributed.java b/Ghidra/Framework/Graph/src/main/java/ghidra/service/graph/Attributed.javaindex 4b940d78b8..e0bd9028d8 100644--- a/Ghidra/Framework/Graph/src/main/java/ghidra/service/graph/Attributed.java+++ b/Ghidra/Framework/Graph/src/main/java/ghidra/service/graph/Attributed.java@@ -27,6 +27,7 @@ public class Attributed {* cache of the html rendering of the vertex attributes*/private String htmlString;+ private static final String DESCRIPTION = "Description";/*** the {@link HashMap} to contain attribute mappings@@ -145,6 +146,27 @@ public class Attributed {return attributes.entrySet();}+ /**+ * Sets a description for this Attributed object+ *+ * @param value text that provides a description for this Attributed object.+ * The text can be either a plain string or an HTML string.+ * @return the previously set description+ */+ public String setDescription(String value) {+ htmlString = null;+ return attributes.put(DESCRIPTION, value);+ }++ /**+ * gets the description of this Attributed object.+ *+ * @return the description of this Attributed object.+ */+ public String getDescription() {+ return getAttribute(DESCRIPTION);+ }+/*** parse (one time) then cache the attributes to html* @return the html string@@ -155,22 +177,25 @@ public class Attributed {return htmlString;}- Set<Entry<String, String>> entries = entrySet();- if (entries.isEmpty()) {- return ""; // empty so tooltip clients can handle empty data+ htmlString = getDescription();+ if (htmlString == null) { // if no description is set, create a default one+ Set<Entry<String, String>> entries = entrySet();+ if (entries.isEmpty()) {+ return ""; // empty so tooltip clients can handle empty data+ }+ StringBuilder buf = new StringBuilder();+ for (Map.Entry<String, String> entry : entries) {+ buf.append(entry.getKey());+ buf.append(":");+ String value = entry.getValue();+ value = StringEscapeUtils.escapeHtml4(value);+ String split = String.join("<br>", Splitter.on('\n').split(value));+ split = split.replaceAll("\\s", " ");+ buf.append(split);+ buf.append("<br>");+ }+ htmlString = buf.toString();}-- StringBuilder buf = new StringBuilder("<html>");- for (Map.Entry<String, String> entry : entries) {- buf.append(entry.getKey());- buf.append(":");- String value = StringEscapeUtils.escapeHtml4(entry.getValue());- String split = String.join("<br>", Splitter.on('\n').split(value));- buf.append(split);- buf.append("<br>");- }- htmlString = buf.toString();return htmlString;}-}