Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-836 - Tooltips - updated tooltip usage to keep tootips from getting too large

dragonmacherd14c6353cf03
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypesProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypesProvider.java
index 8919c69140..c0564af08b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypesProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/datamgr/DataTypesProvider.java
@@ -528,7 +528,7 @@ public class DataTypesProvider extends ComponentProviderAdapter {
return;
}
- String toolTipText = ToolTipUtils.getToolTipText(dataType);
+ String toolTipText = ToolTipUtils.getFullToolTipText(dataType);
String updated = HTMLUtilities.convertLinkPlaceholdersToHyperlinks(toolTipText);
previewPane.setText(updated);
previewPane.setCaretPosition(0);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/ToolTipUtils.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/ToolTipUtils.java
index 74660f2435..3a4a6189fa 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/ToolTipUtils.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/ToolTipUtils.java
@@ -32,6 +32,7 @@ import ghidra.program.model.lang.PrototypeModel;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.model.symbol.Symbol;
+import ghidra.util.StringUtilities;
/**
* A utility class that creates tool tip text for given data types.
@@ -41,12 +42,21 @@ import ghidra.program.model.symbol.Symbol;
*/
public class ToolTipUtils {
- private static Color PARAM_NAME_COLOR = new Color(155, 50, 155);
- private static Color PARAM_CUSTOM_STORAGE_COLOR = OptionsGui.PARAMETER_CUSTOM.getDefaultColor();
- private static Color PARAM_DYNAMIC_STORAGE_COLOR =
+ private static final Color PARAM_NAME_COLOR = new Color(155, 50, 155);
+ private static final Color PARAM_CUSTOM_STORAGE_COLOR =
+ OptionsGui.PARAMETER_CUSTOM.getDefaultColor();
+ private static final Color PARAM_DYNAMIC_STORAGE_COLOR =
OptionsGui.PARAMETER_DYNAMIC.getDefaultColor();
- private static int PARAM_LENGTH_WRAP_THRESHOLD = 80;
+ private static final String ELLIPSES = "...";
+ public static final int LINE_LENGTH = 80;
+ private static final int PARAM_LENGTH_WRAP_THRESHOLD = LINE_LENGTH;
+
+ // shorten the length, since the params may get wrapped and tabbed
+ private static final int PARAM_MAX_CHAR_LENGTH = LINE_LENGTH - 20;
+
+ // 13 params + plus the other function signature lines for around 15 lines
+ private static final int PARAM_COUNT_THRESHOLD = 13;
private ToolTipUtils() {
// utils class--no instance construction
@@ -56,6 +66,9 @@ public class ToolTipUtils {
* Examines the give <code>dataType</code> and creates a tool tip for it,
* depending upon its actual class type.
*
+ * <P>Note: the text returned here will be truncated as needed for the type of data. To
+ * get the full tool tip text, use {@link #getFullToolTipText(DataType)}.
+ *
* @param dataType The data type from which a tool tip will be
* created.
* @return tool tip text for the given data type.
@@ -64,6 +77,22 @@ public class ToolTipUtils {
return getHTMLRepresentation(dataType).getHTMLString();
}
+ /**
+ * Examines the give <code>dataType</code> and creates a tool tip for it,
+ * depending upon its actual class type.
+ *
+ * <P>Note: the text returned here will not be truncated. This can result in tool tip windows
+ * that are too large to fit in the screen. For truncated tool tip text, use
+ * {@link #getToolTipText(DataType)}.
+ *
+ * @param dataType The data type from which a tool tip will be
+ * created.
+ * @return tool tip text for the given data type.
+ */
+ public static String getFullToolTipText(DataType dataType) {
+ return getHTMLRepresentation(dataType).getFullHTMLString();
+ }
+
/**
* Return dataType details as HTML.
* @param dataType the dataType to be represented
@@ -164,7 +193,9 @@ public class ToolTipUtils {
if (includeSymbolDetails) {
buf.append("Function");
buf.append(HTML_SPACE).append("-").append(HTML_SPACE);
- buf.append(friendlyEncodeHTML(function.getSymbol().getName(true)));
+ String functionName = function.getSymbol().getName(true);
+ functionName = StringUtilities.trimMiddle(functionName, LINE_LENGTH);
+ buf.append(friendlyEncodeHTML(functionName));
if (extLoc != null) {
Address addr = extLoc.getAddress();
if (addr != null) {
@@ -180,16 +211,19 @@ public class ToolTipUtils {
buf.append("<table cellspacing=0 callpadding=0 border=0>");
- buf.append(getParameterDetailRow(function.getReturn()));
+ buf.append(generateParameterDetailRow(function.getReturn()));
for (Parameter p : function.getParameters()) {
- buf.append(getParameterDetailRow(p));
+ buf.append(generateParameterDetailRow(p));
}
if (extLoc != null) {
String originalImportedName = extLoc.getOriginalImportedName();
if (originalImportedName != null) {
- buf.append("Imported").append(HTML_SPACE).append("Name:").append(HTML_SPACE).append(
- friendlyEncodeHTML(originalImportedName));
+ buf.append("Imported")
+ .append(HTML_SPACE)
+ .append("Name:")
+ .append(HTML_SPACE)
+ .append(friendlyEncodeHTML(originalImportedName));
}
}
@@ -197,11 +231,34 @@ public class ToolTipUtils {
return buf.toString();
}
- private static String getParameterDetailRow(Parameter param) {
+ private static String generateParameterDetailRow(Parameter param) {
+
+ String type = param.getDataType().getName();
+ String name = param.getName();
+ int length = type.length() + 1 + name.length();
+
+ //
+ // Bound the max width of the tooltip
+ //
+ if (length > PARAM_MAX_CHAR_LENGTH) {
+ int half = PARAM_MAX_CHAR_LENGTH / 2;
+ int available = half;
+ if (type.length() > half) {
+ type = type.substring(0, half - 3) + ELLIPSES;
+ }
+ else {
+ available = PARAM_MAX_CHAR_LENGTH - type.length();
+ }
+
+ if (name.length() > available) {
+ name = name.substring(0, available - 3) + ELLIPSES;
+ }
+ }
+
StringBuilder buf = new StringBuilder();
buf.append("<tr><td width=10>&nbsp;</td>"); // indent
buf.append("<td width=\"1%\">");
- buf.append(colorString(Color.BLACK, friendlyEncodeHTML(param.getDataType().getName())));
+ buf.append(colorString(Color.BLACK, friendlyEncodeHTML(type)));
buf.append("</td><td width=\"1%\">");
Color paramColor =
param.getFunction().hasCustomVariableStorage() ? PARAM_CUSTOM_STORAGE_COLOR
@@ -209,7 +266,7 @@ public class ToolTipUtils {
buf.append(
colorString(paramColor, friendlyEncodeHTML(param.getVariableStorage().toString())));
buf.append("</td><td width=\"1%\">");
- buf.append(colorString(PARAM_NAME_COLOR, friendlyEncodeHTML(param.getName())));
+ buf.append(colorString(PARAM_NAME_COLOR, friendlyEncodeHTML(name)));
// consume remaining space and compact other columns
buf.append("</td><td width=\"100%\">&nbsp;</td></tr>");
@@ -227,23 +284,25 @@ public class ToolTipUtils {
* for pretty-printing; otherwise, they are merged into one string and emitted.
*/
- StringBuffer buf = new StringBuffer();
+ StringBuilder buffy = new StringBuilder();
if (function.hasNoReturn()) {
- buf.append("noreturn").append(HTML_SPACE);
+ buffy.append("noreturn").append(HTML_SPACE);
}
- buf.append(friendlyEncodeHTML(function.getReturnType().getName()));
- buf.append(HTML_SPACE);
+ buffy.append(friendlyEncodeHTML(function.getReturnType().getName()));
+ buffy.append(HTML_SPACE);
PrototypeModel callingConvention = function.getCallingConvention();
if (isNonDefaultCallingConvention(callingConvention)) {
- buf.append(friendlyEncodeHTML(callingConvention.getName()));
- buf.append(HTML_SPACE);
+ buffy.append(friendlyEncodeHTML(callingConvention.getName()));
+ buffy.append(HTML_SPACE);
}
- buf.append(colorString(Color.BLUE, friendlyEncodeHTML(function.getName())));
- buf.append(HTML_SPACE).append("(");
- buildParameterPreview(function, buf);
+ String functionName = StringUtilities.trimMiddle(function.getName(), LINE_LENGTH);
+ buffy.append(colorString(Color.BLUE, friendlyEncodeHTML(functionName)));
+ buffy.append(HTML_SPACE).append("(");
- return buf.toString();
+ buildParameterPreview(function, buffy);
+
+ return buffy.toString();
}
private static boolean isNonDefaultCallingConvention(PrototypeModel callingConvention) {
@@ -254,22 +313,13 @@ public class ToolTipUtils {
return !Function.DEFAULT_CALLING_CONVENTION_STRING.equals(callingConvention.getName());
}
- private static void buildParameterPreview(Function function, StringBuffer bufffy) {
- int rawTextLength = 0;
+ private static void buildParameterPreview(Function function, StringBuilder buffy) {
+ int rawTextLength = 0;
Parameter[] parameters = function.getParameters();
List<String> params = new ArrayList<>();
for (Parameter param : parameters) {
- StringBuilder pb = new StringBuilder();
- String type = param.getDataType().getName();
- pb.append(colorString(Color.BLACK, friendlyEncodeHTML(type)));
- pb.append(HTML_SPACE);
-
- String name = param.getName();
- pb.append(colorString(PARAM_NAME_COLOR, friendlyEncodeHTML(name)));
- params.add(pb.toString());
-
- rawTextLength += type.length() + 1 + name.length();
+ rawTextLength += generateParameterHtml(param, params);
}
if (function.hasVarArgs()) {
@@ -284,28 +334,73 @@ public class ToolTipUtils {
}
if (rawTextLength > PARAM_LENGTH_WRAP_THRESHOLD) {
+ generateParameterTable(buffy, params);
+ }
+ else {
+ // inline parameter string
+ buffy.append(StringUtils.join(params, "," + HTML_SPACE));
+ buffy.append(')');
+ }
+ }
+
+ private static void generateParameterTable(StringBuilder buffy, List<String> params) {
+ StringBuilder psb = new StringBuilder("<table cellspacing=0 callpadding=0 border=0>");
+ for (int i = 0; i < params.size(); i++) {
- StringBuilder psb = new StringBuilder("<table cellspacing=0 callpadding=0 border=0>");
- for (int i = 0; i < params.size(); i++) {
- String param = params.get(i);
+ String param = params.get(i);
- // The first parameter is appended directly after the declaration
- if (i == 0) {
- bufffy.append(param).append(",");
+ // The first parameter is appended directly after the declaration
+ if (i == 0) {
+ buffy.append(param).append(",");
+ }
+ else {
+ psb.append("<tr><td width=75px></td><td>");
+ if (i == PARAM_COUNT_THRESHOLD) {
+ psb.append(ELLIPSES).append(')');
+ i = params.size(); // break
}
else {
- psb.append("<tr><td width=75px></td><td>");
psb.append(param).append(i < (params.size() - 1) ? ',' : ')');
- psb.append("</td></tr>");
}
+
+ psb.append("</td></tr>");
}
- bufffy.append(psb.toString());
- bufffy.append("</table>");
}
- else {
- bufffy.append(StringUtils.join(params, "," + HTML_SPACE));
- bufffy.append(')');
+ buffy.append(psb.toString());
+ buffy.append("</table>");
+ }
+
+ private static int generateParameterHtml(Parameter param, List<String> params) {
+ String type = param.getDataType().getName();
+ String name = param.getName();
+ int length = type.length() + 1 + name.length();
+ int rawTextLength = length;
+
+ //
+ // Bound the max width of the tooltip
+ //
+ if (length > PARAM_MAX_CHAR_LENGTH) {
+ int half = PARAM_MAX_CHAR_LENGTH / 2;
+ int available = half;
+ if (type.length() > half) {
+ type = type.substring(0, half - 3) + ELLIPSES;
+ }
+ else {
+ available = PARAM_MAX_CHAR_LENGTH - type.length();
+ }
+
+ if (name.length() > available) {
+ name = name.substring(0, available - 3) + ELLIPSES;
+ }
}
+
+ StringBuilder pb = new StringBuilder();
+ pb.append(colorString(Color.BLACK, friendlyEncodeHTML(type)));
+ pb.append(HTML_SPACE);
+
+ pb.append(colorString(PARAM_NAME_COLOR, friendlyEncodeHTML(name)));
+ params.add(pb.toString());
+ return rawTextLength;
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/ArrayDataTypeHTMLRepresentation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/ArrayDataTypeHTMLRepresentation.java
index c30d033a1d..c57aef672a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/ArrayDataTypeHTMLRepresentation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/ArrayDataTypeHTMLRepresentation.java
@@ -22,6 +22,7 @@ import ghidra.app.util.html.diff.DataTypeDiff;
import ghidra.app.util.html.diff.DataTypeDiffBuilder;
import ghidra.program.model.data.*;
import ghidra.util.HTMLUtilities;
+import ghidra.util.StringUtilities;
public class ArrayDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
@@ -30,13 +31,19 @@ public class ArrayDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation
private ValidatableLine footerContent;
private Array array;
+ private String truncatedHtmlData;
+
public ArrayDataTypeHTMLRepresentation(Array array) {
this.array = array;
this.headerContent = buildHeaderContent();
- this.bodyHtml = buildBodyHTML();
+ this.bodyHtml = buildBodyHTML(false);
this.footerContent = buildFooterContent();
- originalHTMLData = buildHTMLText(headerContent, bodyHtml, footerContent);
+
+ originalHTMLData = buildHTMLText(headerContent, bodyHtml, footerContent, false);
+
+ String trimmedBodyHtml = buildBodyHTML(true);
+ truncatedHtmlData = buildHTMLText(headerContent, trimmedBodyHtml, footerContent, true);
}
private ArrayDataTypeHTMLRepresentation(Array array, ValidatableLine headerContent,
@@ -45,7 +52,8 @@ public class ArrayDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation
this.headerContent = headerContent;
this.bodyHtml = bodyHtml;
this.footerContent = footerContent;
- originalHTMLData = buildHTMLText(headerContent, bodyHtml, footerContent);
+
+ originalHTMLData = buildHTMLText(headerContent, bodyHtml, footerContent, false);
}
private DataType getBaseDataType() {
@@ -57,8 +65,8 @@ public class ArrayDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation
return baseDataType;
}
- private String buildBodyHTML() {
- StringBuffer buffy = new StringBuffer();
+ private String buildBodyHTML(boolean trim) {
+ StringBuilder buffy = new StringBuilder();
DataType baseDataType = getBaseDataType();
buffy.append("Array Base Data Type: ").append(BR);
@@ -73,7 +81,11 @@ public class ArrayDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation
HTMLDataTypeRepresentation representation =
ToolTipUtils.getHTMLRepresentation(baseDataType);
- String baseHTML = representation.getHTMLContentString();
+
+ String baseHTML = representation.getFullHTMLContentString();
+ if (trim) {
+ baseHTML = representation.getHTMLContentString();
+ }
buffy.append(baseHTML);
@@ -88,18 +100,9 @@ public class ArrayDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation
}
private ValidatableLine buildHeaderContent() {
- StringBuffer buffy = new StringBuffer();
+ StringBuilder buffy = new StringBuilder();
buffy.append(FORWARD_SLASH).append(FORWARD_SLASH).append(HTML_SPACE);
-
- String description = "Array of ";
- DataType baseDataType = array;
- while (baseDataType instanceof Array) {
- Array baseArray = (Array) baseDataType;
- description += baseArray.getNumElements() + " elements of ";
- baseDataType = baseArray.getDataType();
- }
- description += HTMLUtilities.friendlyEncodeHTML(baseDataType.getName());
- buffy.append(description);
+ buffy.append(HTMLUtilities.friendlyEncodeHTML(array.getName()));
return new TextLine(buffy.toString());
}
@@ -107,27 +110,43 @@ public class ArrayDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation
return new TextLine("Size: " + array.getLength());
}
- private String buildHTMLText(ValidatableLine header, String body, ValidatableLine footer) {
+ private String buildHTMLText(ValidatableLine header, String body, ValidatableLine info,
+ boolean trim) {
- StringBuffer buffy = new StringBuffer();
+ StringBuilder buffy = new StringBuilder();
TextLine headerLine = (TextLine) header;
String headerText = header.getText();
+ if (trim) {
+ headerText = StringUtilities.trimMiddle(headerText, ToolTipUtils.LINE_LENGTH);
+ }
headerText = wrapStringInColor(headerText, headerLine.getTextColor());
buffy.append(headerText);
+ buffy.append(BR);
+ TextLine infoLine = (TextLine) info;
+ String infoText = info.getText();
+ infoText = wrapStringInColor(infoText, infoLine.getTextColor());
+ buffy.append(infoText);
+
buffy.append(BR).append(BR);
buffy.append(body);
- // footer
- buffy.append(BR);
- TextLine footerLine = (TextLine) footer;
- String footerText = footer.getText();
- footerText = wrapStringInColor(footerText, footerLine.getTextColor());
- buffy.append(footerText);
return buffy.toString();
}
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLString() {
+ return HTML_OPEN + truncatedHtmlData + HTML_CLOSE;
+ }
+
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLContentString() {
+ return truncatedHtmlData;
+ }
+
@Override
public HTMLDataTypeRepresentation[] diff(HTMLDataTypeRepresentation otherRepresentation) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/BitFieldDataTypeHTMLRepresentation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/BitFieldDataTypeHTMLRepresentation.java
index ca25ffbe37..e2f6756670 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/BitFieldDataTypeHTMLRepresentation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/BitFieldDataTypeHTMLRepresentation.java
@@ -15,6 +15,8 @@
*/
package ghidra.app.util.html;
+import org.apache.commons.lang3.StringUtils;
+
import ghidra.app.util.ToolTipUtils;
import ghidra.program.model.data.BitFieldDataType;
import ghidra.program.model.data.DataType;
@@ -28,28 +30,31 @@ public class BitFieldDataTypeHTMLRepresentation extends HTMLDataTypeRepresentati
}
private static String buildHTMLText(BitFieldDataType bitFieldDt) {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
+
+ DataType baseDataType = bitFieldDt.getBaseDataType();
+ HTMLDataTypeRepresentation representation =
+ ToolTipUtils.getHTMLRepresentation(baseDataType);
+ String baseHTML = representation.getHTMLContentString();
+ buffer.append(baseHTML);
+ if (baseHTML.indexOf(LENGTH_PREFIX) < 0) {
+ String lengthString = getDataTypeLengthString(bitFieldDt);
+ buffer.append(LENGTH_PREFIX).append(lengthString);
+ }
+
String description = bitFieldDt.getDescription();
- if (description == null || description.length() == 0) {
+ if (StringUtils.isBlank(description)) {
description = bitFieldDt.getDisplayName();
}
description = HTMLUtilities.friendlyEncodeHTML(description);
buffer.append(description);
- DataType baseDataType = bitFieldDt.getBaseDataType();
-
buffer.append(BR).append(BR);
buffer.append("Bitfield Base Data Type: ").append(BR);
buffer.append(INDENT_OPEN);
- HTMLDataTypeRepresentation representation =
- ToolTipUtils.getHTMLRepresentation(baseDataType);
- String baseHTML = representation.getHTMLContentString();
buffer.append(baseHTML);
- if (baseHTML.indexOf(LENGTH_PREFIX) < 0) {
- addDataTypeLength(baseDataType, buffer);
- }
buffer.append(INDENT_CLOSE);
return buffer.toString();
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/CompositeDataTypeHTMLRepresentation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/CompositeDataTypeHTMLRepresentation.java
index 5ae0045eba..14a7205f26 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/CompositeDataTypeHTMLRepresentation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/CompositeDataTypeHTMLRepresentation.java
@@ -15,19 +15,22 @@
*/
package ghidra.app.util.html;
-import static ghidra.util.HTMLUtilities.friendlyEncodeHTML;
+import static ghidra.util.HTMLUtilities.*;
import java.awt.Color;
import java.util.*;
+import ghidra.app.util.ToolTipUtils;
import ghidra.app.util.datatype.DataTypeUrl;
import ghidra.app.util.html.diff.*;
import ghidra.program.model.data.*;
import ghidra.util.HTMLUtilities;
+import ghidra.util.StringUtilities;
public class CompositeDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
- private static final int MAX_COMPONENT_COUNT = 100;
+ private static final int MAX_COMPONENT_COUNT = 1000;
+ private static final int MAX_LINE_COUNT = 15;
protected List<String> warningLines;
protected List<ValidatableLine> headerContent;
@@ -39,6 +42,8 @@ public class CompositeDataTypeHTMLRepresentation extends HTMLDataTypeRepresentat
protected static final String ALIGNMENT_VALUE_PREFIX = "Alignment: ";
+ private String truncatedHtmlData;
+
// private constructor for making diff copies
protected CompositeDataTypeHTMLRepresentation(List<String> warningLines,
List<ValidatableLine> header, List<ValidatableLine> bodyContent,
@@ -52,8 +57,8 @@ public class CompositeDataTypeHTMLRepresentation extends HTMLDataTypeRepresentat
this.alignmentText = alignmentText;
this.alignmentValueText = alignmentValue;
- originalHTMLData = buildHTMLText(warningLines, header, displayName, bodyContent,
- alignmentText, footerText, alignmentValueText);
+ originalHTMLData = buildHTMLText(false);
+ truncatedHtmlData = buildHTMLText(true);
}
public CompositeDataTypeHTMLRepresentation(Composite comp) {
@@ -72,8 +77,8 @@ public class CompositeDataTypeHTMLRepresentation extends HTMLDataTypeRepresentat
displayName = new TextLine(type + comp.getDisplayName() + " ");
alignmentValueText = buildAlignmentValueText(comp);
- originalHTMLData = buildHTMLText(warningLines, headerContent, displayName, bodyContent,
- alignmentText, footerText, alignmentValueText);
+ originalHTMLData = buildHTMLText(false);
+ truncatedHtmlData = buildHTMLText(true);
}
protected List<String> buildWarnings(Composite comp) {
@@ -153,7 +158,7 @@ public class CompositeDataTypeHTMLRepresentation extends HTMLDataTypeRepresentat
list.add(new DataTypeLine(fieldName, type, comment, locatableType, false));
if (count++ >= MAX_COMPONENT_COUNT) {
// Prevent a ridiculous number of components from consuming all memory.
- list.add(new DataTypeLine("Warning: Too many components to display...", "", "",
+ list.add(new DataTypeLine("", "Warning: Too many components to display...", "",
null, false));
break;
}
@@ -174,104 +179,194 @@ public class CompositeDataTypeHTMLRepresentation extends HTMLDataTypeRepresentat
return list;
}
- private static String buildHTMLText(List<String> warningLines,
- List<ValidatableLine> headerLines, TextLine displayName,
- List<ValidatableLine> bodyLines, List<ValidatableLine> alignmentLines,
- TextLine footerLine, TextLine alignmentValueLine) {
+ /**
+ * Full html is not limited by the number of lines to display; the truncated html line
+ * count is limited. Truncated data will only be returned when the text is being trimmed.
+ * @param trim true signals to truncate lines that are too long and to cap the maximum number
+ * of lines that can be displayed
+ * @return the text
+ */
+ private String buildHTMLText(boolean trim) {
- StringBuilder buffy = new StringBuilder();
+ StringBuilder fullHtml = new StringBuilder();
+ StringBuilder truncatedHtml = new StringBuilder();
+ int lineCount = 0;
// warnings
Iterator<String> warnings = warningLines.iterator();
for (; warnings.hasNext();) {
String warning = warnings.next();
String warningLine = wrapStringInColor(warning, Color.RED);
- buffy.append(warningLine).append(BR);
+
+ //@formatter:off
+ append(fullHtml, truncatedHtml, lineCount, warningLine,
+ BR,
+ BR);
+ //@formatter:on
+ lineCount++;
}
+ //@formatter:off
+ append(fullHtml, truncatedHtml, lineCount, ALIGNMENT_VALUE_PREFIX,
+ alignmentValueText.getText(),
+ BR);
+ append(fullHtml, truncatedHtml, lineCount, LENGTH_PREFIX,
+ footerText.getText(),
+ BR);
+ append(fullHtml, truncatedHtml, lineCount, BR, BR);
+ //@formatter:on
+
// header
- Iterator<ValidatableLine> iterator = headerLines.iterator();
+ Iterator<ValidatableLine> iterator = headerContent.iterator();
for (; iterator.hasNext();) {
TextLine line = (TextLine) iterator.next();
- String headerLine = wrapStringInColor(line.getText(), line.getTextColor());
- buffy.append(headerLine);
+ String text = line.getText();
+ if (trim) {
+ text = truncateAsNecessary(text);
+ }
+ String headerLine = wrapStringInColor(text, line.getTextColor());
+ append(fullHtml, truncatedHtml, lineCount, headerLine);
+ lineCount++;
}
// "<TT> displayName</TT> { "
- String displayNameText = friendlyEncodeHTML(displayName.getText());
+ String name = displayName.getText();
+ if (trim) {
+ name = StringUtilities.trimMiddle(name, ToolTipUtils.LINE_LENGTH);
+ }
+ String displayNameText = friendlyEncodeHTML(name);
displayNameText = wrapStringInColor(displayNameText, displayName.getTextColor());
- buffy.append(TT_OPEN).append(displayNameText).append(TT_CLOSE).append(HTML_SPACE).append(
- "{").append(HTML_SPACE);
- buffy.append("<TABLE BORDER=0 CELLSPACING=5 CELLPADDING=0>");
+ //@formatter:off
+ append(fullHtml, truncatedHtml, lineCount, TT_OPEN,
+ displayNameText,
+ TT_CLOSE,
+ HTML_SPACE,
+ "{",
+ HTML_SPACE);
+ //@formatter:on
+ lineCount++;
- iterator = bodyLines.iterator();
- for (int i = 0; iterator.hasNext(); i++) {
- DataTypeLine line = (DataTypeLine) iterator.next();
+ String tableOpen = "<TABLE BORDER=0 CELLSPACING=5 CELLPADDING=0>";
+ fullHtml.append(tableOpen);
+ truncatedHtml.append(tableOpen);
+
+ iterator = bodyContent.iterator();
+ for (; iterator.hasNext(); lineCount++) {
+
+ iterator.hasNext();
- String typeName = generateTypeName(line);
+ StringBuilder lineBuffer = new StringBuilder();
+ DataTypeLine line = (DataTypeLine) iterator.next();
+ String typeName = generateTypeName(line, trim);
if (line.isFlexibleArray()) {
typeName += "[0]";
}
- String fieldName = friendlyEncodeHTML(line.getName());
+ int fieldLength = ToolTipUtils.LINE_LENGTH / 2;
+ String fieldName = line.getName();
+ if (trim) {
+ fieldName = StringUtilities.trimMiddle(fieldName, fieldLength);
+ }
+ fieldName = friendlyEncodeHTML(fieldName);
fieldName = wrapStringInColor(fieldName, line.getNameColor());
- int commentLength = MAX_CHARACTER_LENGTH; // give a little extra room for comments
- String typeComment = truncateAsNecessary(line.getComment(), commentLength);
+ String typeComment = line.getComment();
+ if (trim) {
+ typeComment = truncateAsNecessary(typeComment, fieldLength);
+ }
typeComment = friendlyEncodeHTML(typeComment);
typeComment = wrapStringInColor(typeComment, line.getCommentColor());
// start the table row
- buffy.append(TR_OPEN);
+ lineBuffer.append(TR_OPEN);
// the name column within the current row
- buffy.append(TD_OPEN).append(TT_OPEN).append(TAB).append(typeName).append(
- TT_CLOSE).append(TD_CLOSE);
+ lineBuffer.append(TD_OPEN)
+ .append(TT_OPEN)
+ .append(TAB)
+ .append(typeName)
+ .append(
+ TT_CLOSE)
+ .append(TD_CLOSE);
// data type name column
- buffy.append(TD_OPEN).append(HTML_SPACE).append(fieldName).append(TD_CLOSE);
+ lineBuffer.append(TD_OPEN).append(HTML_SPACE).append(fieldName).append(TD_CLOSE);
// data type comment
- buffy.append(TD_OPEN).append(HTML_SPACE).append(typeComment).append(HTML_SPACE).append(
- TD_CLOSE);
+ lineBuffer.append(TD_OPEN)
+ .append(HTML_SPACE)
+ .append(typeComment)
+ .append(HTML_SPACE)
+ .append(
+ TD_CLOSE);
// close the row
- buffy.append(TR_CLOSE);
+ lineBuffer.append(TR_CLOSE);
- if (i > MAX_COMPONENTS) {
-// TODO: change to diff color if any of the ellipsed-out args are diffed
- // if ( cointains unmatching lines ( arguments, i ) )
- // then make the ellipses the diff color
+ String lineString = lineBuffer.toString();
+ append(fullHtml, truncatedHtml, lineCount, lineString);
+ }
- buffy.append(TAB).append(ELLIPSES).append(BR);
- break;
- }
+ // show ellipses if needed; the truncated html is much shorter than the full html
+ if (lineCount >= MAX_LINE_COUNT) {
+ truncatedHtml.append(TAB).append(ELLIPSES).append(BR);
}
// Alignment
String alignmentLine = "";
- Iterator<ValidatableLine> alignmentIterator = alignmentLines.iterator();
+ Iterator<ValidatableLine> alignmentIterator = alignmentText.iterator();
for (; alignmentIterator.hasNext();) {
TextLine line = (TextLine) alignmentIterator.next();
alignmentLine += HTML_SPACE + wrapStringInColor(line.getText(), line.getTextColor());
}
// close the table, the structure and then the HTML
- buffy.append(TABLE_CLOSE).append("}").append(TT_OPEN).append(alignmentLine).append(
- TT_CLOSE).append(BR);
+ StringBuilder trailingLines = new StringBuilder();
+ trailingLines.append(TABLE_CLOSE)
+ .append("}")
+ .append(TT_OPEN)
+ .append(alignmentLine)
+ .append(
+ TT_CLOSE)
+ .append(BR);
+
+ String trailingString = trailingLines.toString();
+ fullHtml.append(trailingString);
+ truncatedHtml.append(trailingString);
+
+ if (trim) {
+ return truncatedHtml.toString();
+ }
+ return fullHtml.toString();
+ }
+
+ private static void append(StringBuilder fullHtml, StringBuilder truncatedHtml,
+ int lineCount, String... content) {
- addAlignmentValue(alignmentValueLine.getText(), buffy);
- addDataTypeLength(footerLine.getText(), buffy);
+ for (String string : content) {
+ fullHtml.append(string);
+ }
- buffy.append(BR);
+ maybeAppend(truncatedHtml, lineCount, content);
+ }
- return buffy.toString();
+ private static void maybeAppend(StringBuilder buffer, int lineCount, String... content) {
+ if (lineCount > MAX_LINE_COUNT) {
+ return;
+ }
+
+ for (String string : content) {
+ buffer.append(string);
+ }
}
- private static String generateTypeName(DataTypeLine line) {
+ private static String generateTypeName(DataTypeLine line, boolean trim) {
- String type = truncateAsNecessary(line.getType());
+ String type = line.getType();
+ if (true) {
+ type = truncateAsNecessary(line.getType());
+ }
type = friendlyEncodeHTML(type);
type = wrapStringInColor(type, line.getTypeColor());
@@ -297,6 +392,18 @@ public class CompositeDataTypeHTMLRepresentation extends HTMLDataTypeRepresentat
return buffer;
}
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLString() {
+ return HTML_OPEN + truncatedHtmlData + HTML_CLOSE;
+ }
+
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLContentString() {
+ return truncatedHtmlData;
+ }
+
@Override
protected PlaceHolderLine createPlaceHolderLine(ValidatableLine oppositeLine) {
return new EmptyDataTypeLine();
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/EnumDataTypeHTMLRepresentation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/EnumDataTypeHTMLRepresentation.java
index 858a04f91f..bb3fa2444d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/EnumDataTypeHTMLRepresentation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/EnumDataTypeHTMLRepresentation.java
@@ -17,19 +17,25 @@ package ghidra.app.util.html;
import java.util.*;
+import ghidra.app.util.ToolTipUtils;
import ghidra.app.util.html.diff.DataTypeDiff;
import ghidra.app.util.html.diff.DataTypeDiffBuilder;
import ghidra.program.model.data.Enum;
import ghidra.util.HTMLUtilities;
+import ghidra.util.StringUtilities;
import ghidra.util.exception.AssertException;
public class EnumDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
+ private static final int MAX_LINE_COUNT = 15;
+
protected List<ValidatableLine> headerContent;
protected List<ValidatableLine> bodyContent;
protected TextLine footerLine;
protected TextLine displayName;
+ private static String truncatedHtmlData;
+
// private constructor for making diff copies
private EnumDataTypeHTMLRepresentation(List<ValidatableLine> headerLines, TextLine displayName,
List<ValidatableLine> bodyContent, TextLine footerLine) {
@@ -37,15 +43,34 @@ public class EnumDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
this.displayName = displayName;
this.bodyContent = bodyContent;
this.footerLine = footerLine;
- originalHTMLData = buildHTMLText(headerLines, displayName, bodyContent, footerLine);
+
+ originalHTMLData = buildHTMLText(headerLines, displayName, bodyContent, footerLine, false);
}
public EnumDataTypeHTMLRepresentation(Enum enumDataType) {
headerContent = buildHeaderText(enumDataType);
- bodyContent = buildContent(enumDataType);
+ bodyContent = buildContent(enumDataType, false);
footerLine = buildFooterText(enumDataType);
- displayName = new TextLine(enumDataType.getDisplayName());
- originalHTMLData = buildHTMLText(headerContent, displayName, bodyContent, footerLine);
+ displayName = new TextLine("enum " + enumDataType.getDisplayName());
+
+ originalHTMLData =
+ buildHTMLText(headerContent, displayName, bodyContent, footerLine, false);
+
+ List<ValidatableLine> trimmedBodyContent = buildContent(enumDataType, true);
+ truncatedHtmlData =
+ buildHTMLText(headerContent, displayName, trimmedBodyContent, footerLine, true);
+ }
+
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLString() {
+ return HTML_OPEN + truncatedHtmlData + HTML_CLOSE;
+ }
+
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLContentString() {
+ return truncatedHtmlData;
}
@Override
@@ -58,14 +83,18 @@ public class EnumDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
return new EmptyTextLine(stringLength);
}
- private List<ValidatableLine> buildContent(Enum enumDataType) {
+ private List<ValidatableLine> buildContent(Enum enumDataType, boolean trim) {
long[] values = enumDataType.getValues();
Arrays.sort(values);
int n = enumDataType.getLength();
List<ValidatableLine> list = new ArrayList<>(values.length);
for (long value : values) {
+
String name = enumDataType.getName(value);
+ if (trim) {
+ name = StringUtilities.trimMiddle(name, ToolTipUtils.LINE_LENGTH);
+ }
String hexString = Long.toHexString(value);
if (value < 0) {
@@ -81,9 +110,11 @@ public class EnumDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
}
private static String buildHTMLText(List<ValidatableLine> headerLines, TextLine displayName,
- List<ValidatableLine> bodyLines, TextLine footerLine) {
+ List<ValidatableLine> bodyLines, TextLine infoLine, boolean trim) {
- StringBuilder buffy = new StringBuilder();
+ StringBuilder fullHtml = new StringBuilder();
+ StringBuilder truncatedHtml = new StringBuilder();
+ int lineCount = 0;
// header
Iterator<ValidatableLine> iterator = headerLines.iterator();
@@ -91,46 +122,84 @@ public class EnumDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
TextLine line = (TextLine) iterator.next();
String encodedHeaderLine = line.getText();
String headerLine = wrapStringInColor(encodedHeaderLine, line.getTextColor());
- buffy.append(headerLine);
+ append(fullHtml, truncatedHtml, lineCount, headerLine);
+ lineCount++;
}
+ append(fullHtml, truncatedHtml, lineCount, LENGTH_PREFIX, infoLine.getText());
+ append(fullHtml, truncatedHtml, lineCount, BR, BR);
+
// "<TT> displayName { "
- String encodedDisplayName = HTMLUtilities.friendlyEncodeHTML(displayName.getText());
- String displayNameText = wrapStringInColor(encodedDisplayName, displayName.getTextColor());
- buffy.append(TT_OPEN)
- .append(displayNameText)
- .append(TT_CLOSE)
- .append(HTML_SPACE)
- .append(
- "{")
- .append(HTML_SPACE)
- .append(BR);
+ String displayNameText = displayName.getText();
+ if (trim) {
+ displayNameText = StringUtilities.trimMiddle(displayNameText, ToolTipUtils.LINE_LENGTH);
+ }
+ displayNameText = HTMLUtilities.friendlyEncodeHTML(displayNameText);
+ displayNameText = wrapStringInColor(displayNameText, displayName.getTextColor());
+ //@formatter:off
+ append(fullHtml, truncatedHtml, lineCount, TT_OPEN,
+ displayNameText,
+ TT_CLOSE,
+ HTML_SPACE,
+ "{",
+ HTML_SPACE,
+ BR);
+ //@formatter:on
+ lineCount++;
int length = bodyLines.size();
- for (int i = 0; i < length; i++) {
+ for (int i = 0; i < length; i++, lineCount++) {
TextLine textLine = (TextLine) bodyLines.get(i);
String text = textLine.getText();
String encodedBodyLine = HTMLUtilities.friendlyEncodeHTML(text);
text = wrapStringInColor(encodedBodyLine, textLine.getTextColor());
- buffy.append(TAB).append(text).append(HTML_SPACE);
+ StringBuilder lineBuffer = new StringBuilder();
+ lineBuffer.append(TAB).append(text).append(HTML_SPACE);
if (i < length - 1) {
- buffy.append(BR);
- }
- if (i > MAX_COMPONENTS) {
-// TODO: change to diff color if any of the ellipsed-out args are diffed
- // if ( cointains unmatching lines ( arguments, i ) )
- // then make the ellipses the diff color
- buffy.append(TAB).append(ELLIPSES).append(BR);
- break;
+ lineBuffer.append(BR);
}
+
+ String lineString = lineBuffer.toString();
+ append(fullHtml, truncatedHtml, lineCount, lineString);
+ }
+
+ // show ellipses if needed; the truncated html is much shorter than the full html
+ if (lineCount >= MAX_LINE_COUNT) {
+ truncatedHtml.append(TAB).append(ELLIPSES).append(BR);
}
- buffy.append(BR).append("}").append(BR).append(TT_CLOSE);
+ StringBuilder trailingLines = new StringBuilder();
+ trailingLines.append(BR).append("}").append(BR).append(TT_CLOSE);
+
+ String trailingString = trailingLines.toString();
+ fullHtml.append(trailingString);
+ truncatedHtml.append(trailingString);
+
+ if (trim) {
+ return truncatedHtml.toString();
+ }
+ return fullHtml.toString();
+ }
- addDataTypeLength(footerLine.getText(), buffy);
+ private static void append(StringBuilder fullHtml, StringBuilder truncatedHtml,
+ int lineCount, String... content) {
- return buffy.toString();
+ for (String string : content) {
+ fullHtml.append(string);
+ }
+
+ maybeAppend(truncatedHtml, lineCount, content);
+ }
+
+ private static void maybeAppend(StringBuilder buffer, int lineCount, String... content) {
+ if (lineCount > MAX_LINE_COUNT) {
+ return;
+ }
+
+ for (String string : content) {
+ buffer.append(string);
+ }
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/FunctionDataTypeHTMLRepresentation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/FunctionDataTypeHTMLRepresentation.java
index ef8083b8fa..e54eb13018 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/FunctionDataTypeHTMLRepresentation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/FunctionDataTypeHTMLRepresentation.java
@@ -18,15 +18,21 @@ package ghidra.app.util.html;
import java.util.ArrayList;
import java.util.List;
+import ghidra.app.util.ToolTipUtils;
import ghidra.app.util.datatype.DataTypeUrl;
import ghidra.app.util.html.diff.DataTypeDiff;
import ghidra.app.util.html.diff.DataTypeDiffBuilder;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.FunctionSignature;
import ghidra.util.HTMLUtilities;
+import ghidra.util.StringUtilities;
import ghidra.util.exception.AssertException;
public class FunctionDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
+
+ private static final int MAX_CHAR_COUNT = 30;
+ private static final int MAX_LINE_COUNT = 10;
+
protected TextLine returnType;
protected TextLine functionName;
@@ -34,6 +40,8 @@ public class FunctionDataTypeHTMLRepresentation extends HTMLDataTypeRepresentati
protected TextLine varArgs;
protected TextLine voidArgs;
+ private static String truncatedHtmlData;
+
// private constructor for making diff copies
private FunctionDataTypeHTMLRepresentation(TextLine returnType, TextLine functionName,
List<ValidatableLine> arguments, TextLine varArgs, TextLine voidArgs) {
@@ -42,7 +50,8 @@ public class FunctionDataTypeHTMLRepresentation extends HTMLDataTypeRepresentati
this.arguments = arguments;
this.varArgs = varArgs;
this.voidArgs = voidArgs;
- originalHTMLData = buildHTMLText(returnType, functionName, arguments, varArgs, voidArgs);
+ originalHTMLData =
+ buildHTMLText(returnType, functionName, arguments, varArgs, voidArgs, true);
}
public FunctionDataTypeHTMLRepresentation(FunctionDefinition functionDefinition) {
@@ -51,7 +60,23 @@ public class FunctionDataTypeHTMLRepresentation extends HTMLDataTypeRepresentati
arguments = buildArguments(functionDefinition);
varArgs = buildVarArgs(functionDefinition);
voidArgs = buildVoidArgs(functionDefinition);
- originalHTMLData = buildHTMLText(returnType, functionName, arguments, varArgs, voidArgs);
+
+ originalHTMLData =
+ buildHTMLText(returnType, functionName, arguments, varArgs, voidArgs, false);
+ truncatedHtmlData =
+ buildHTMLText(returnType, functionName, arguments, varArgs, voidArgs, true);
+ }
+
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLString() {
+ return HTML_OPEN + truncatedHtmlData + HTML_CLOSE;
+ }
+
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLContentString() {
+ return truncatedHtmlData;
}
@Override
@@ -112,69 +137,126 @@ public class FunctionDataTypeHTMLRepresentation extends HTMLDataTypeRepresentati
}
private static String buildHTMLText(TextLine returnType, TextLine functionName,
- List<ValidatableLine> arguments, TextLine varArgs, TextLine voidArgs) {
+ List<ValidatableLine> arguments, TextLine varArgs, TextLine voidArgs, boolean trim) {
- StringBuilder sb = new StringBuilder();
+ StringBuilder fullHtml = new StringBuilder();
+ StringBuilder truncatedHtml = new StringBuilder();
+ int lineCount = 0;
String returnTypeText = returnType.getText();
+ if (trim) {
+ returnTypeText =
+ StringUtilities.trimMiddle(returnTypeText, ToolTipUtils.LINE_LENGTH);
+ }
returnTypeText = wrapStringInColor(returnTypeText, returnType.getTextColor());
String functionNameText = functionName.getText();
+ if (trim) {
+ functionNameText =
+ StringUtilities.trimMiddle(functionNameText, ToolTipUtils.LINE_LENGTH);
+ }
functionNameText = wrapStringInColor(functionNameText, functionName.getTextColor());
- sb.append(returnTypeText).append(HTML_SPACE).append(functionNameText).append("(");
+ //@formatter:off
+ append(fullHtml, truncatedHtml, lineCount, returnTypeText,
+ HTML_SPACE,
+ functionNameText,
+ "(");
+ //@formatter:on
String varArgsText = varArgs.getText();
varArgsText = wrapStringInColor(varArgsText, varArgs.getTextColor());
boolean hasVarArgs = varArgsText.length() != 0;
int size = arguments.size();
- for (int i = 0; i < size; i++) { // walk in pairs (display name to name)
- sb.append(BR);
- VariableTextLine variableLine = (VariableTextLine) arguments.get(i);
-
- String typeText = generateTypeText(variableLine);
+ for (int i = 0; i < size; i++, lineCount++) { // walk in pairs (display name to name)
+ append(fullHtml, truncatedHtml, lineCount, BR);
+ VariableTextLine variableLine = (VariableTextLine) arguments.get(i);
+ String typeText = generateTypeText(variableLine, trim);
String variableNameText = variableLine.getVariableName();
+ if (trim) {
+ variableNameText =
+ StringUtilities.trimMiddle(variableNameText, ToolTipUtils.LINE_LENGTH);
+ }
variableNameText =
wrapStringInColor(variableNameText, variableLine.getVariableNameColor());
- sb.append(TAB).append(typeText).append(HTML_SPACE).append(variableNameText);
-
- if ((i + 1 < size - 1) || (size > 0 && hasVarArgs)) {
- sb.append(",");
- }
- if (i > MAX_COMPONENTS) {
-// TODO: change to diff color if any of the ellipsed-out args are diffed
- // if ( cointains unmatching lines ( arguments, i ) )
- // then make the ellipses the diff color
- sb.append(TAB).append(ELLIPSES).append(BR);
- break;
+ String separator = "";
+ if ((i < size - 1) || (size > 0 && hasVarArgs)) {
+ separator = ",";
}
+
+ //@formatter:off
+ append(fullHtml, truncatedHtml, lineCount, TAB,
+ typeText,
+ HTML_SPACE,
+ variableNameText,
+ separator);
+ //@formatter:on
}
if (hasVarArgs) {
if (size > 0) {
- sb.append(BR).append(TAB);
+
+ //@formatter:off
+ append(fullHtml, truncatedHtml, lineCount, BR,
+ TAB);
+ //@formatter:on
+ lineCount++;
}
- sb.append(varArgsText);
+
+ append(fullHtml, truncatedHtml, lineCount, varArgsText);
}
else if (size == 0) {
String voidArgsText = voidArgs.getText();
voidArgsText = wrapStringInColor(voidArgsText, voidArgs.getTextColor());
if (voidArgsText.length() != 0) {
- sb.append(voidArgsText);
+ append(fullHtml, truncatedHtml, lineCount, varArgsText);
}
}
- sb.append(")").append(BR);
+ if (lineCount >= MAX_LINE_COUNT) {
+ truncatedHtml.append(ELLIPSES);
+ }
+
+ fullHtml.append(")").append(BR);
+ truncatedHtml.append(")").append(BR);
+
+ if (trim) {
+ return truncatedHtml.toString();
+ }
+ return fullHtml.toString();
+ }
+
+ private static void append(StringBuilder fullHtml, StringBuilder truncatedHtml,
+ int lineCount, String... content) {
+
+ for (String string : content) {
+ fullHtml.append(string);
+ truncatedHtml.append(string);
+ }
- return sb.toString();
+ //maybeAppend(truncatedHtml, lineCount, content);
}
- private static String generateTypeText(VariableTextLine line) {
+ private static void maybeAppend(StringBuilder buffer, int charCount, String... content) {
+ if (charCount > MAX_LINE_COUNT) {
+ return;
+ }
+
+ for (String string : content) {
+ String trimmed = StringUtilities.trimMiddle(string, MAX_CHAR_COUNT);
+ buffer.append(trimmed);
+ }
+ }
+
+ private static String generateTypeText(VariableTextLine line, boolean trim) {
String type = line.getVariableType();
+ if (trim) {
+ type = StringUtilities.trimMiddle(type, ToolTipUtils.LINE_LENGTH);
+ }
type = wrapStringInColor(type, line.getVariableTypeColor());
if (!line.hasUniversalId()) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/HTMLDataTypeRepresentation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/HTMLDataTypeRepresentation.java
index 0dc8009933..fc5a1bce7f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/HTMLDataTypeRepresentation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/HTMLDataTypeRepresentation.java
@@ -67,22 +67,22 @@ public abstract class HTMLDataTypeRepresentation {
protected static final String TT_OPEN = "<TT>";
protected static final String TT_CLOSE = "</TT>";
- // Indentation tags (note: we switched from <div> tags because the Java rendering engine
+ // Note 1: Indentation tags (note: we switched from <DIV> tags because the Java rendering engine
// does not keep the color of the div's parent tags. The <P> tag seems to work).
- protected static final String INDENT_OPEN = "<P STYLE='margin-left: 10px;'>";
- protected static final String INDENT_CLOSE = "</P>";
+ // Note 2: Switch back to <DIV> from <P>, since the <P> tag gets broken by the <TABLE> tag
+ // used by composite types. If not inheriting the color becomes an issue, then we will need
+ // to find another solution for indentation.
+ protected static final String INDENT_OPEN = "<DIV STYLE='margin-left: 10px;'>";
+ protected static final String INDENT_CLOSE = "</DIV>";
protected static final String ELLIPSES = "...";
protected static final String LENGTH_PREFIX = "Length: ";
protected final static String FORWARD_SLASH = "&#47;";
-// protected final static String COMMENT = FORWARD_SLASH + FORWARD_SLASH + HTML_SPACE;
protected final static String START_COMMENT = FORWARD_SLASH + '*' + BR;
protected final static String MIDDLE_COMMENT = HTML_SPACE + '*' + HTML_SPACE;
protected final static String END_COMMENT = HTML_SPACE + '*' + FORWARD_SLASH + BR;
- private final static int COMMENT_PREFIX_LENGTH = MIDDLE_COMMENT.length();
-// private final static String COMMENT_NEWLINE = BR + COMMENT;
protected final static Color DIFF_COLOR = ValidatableLine.INVALID_COLOR;
@@ -104,8 +104,16 @@ public abstract class HTMLDataTypeRepresentation {
return buffer;
}
- protected static StringBuffer addDataTypeLength(DataType dt, StringBuffer buffer) {
+ protected static StringBuilder addDataTypeLength(DataType dt, StringBuilder buffer) {
+ buffer.append(BR);
+ buffer.append(LENGTH_PREFIX);
+ buffer.append(getDataTypeLengthString(dt));
+
+ return buffer;
+ }
+
+ protected static String getDataTypeLengthString(DataType dt) {
String lengthString = null;
if (dt == null) {
lengthString = "<i>Unknown</i>";
@@ -119,12 +127,7 @@ public abstract class HTMLDataTypeRepresentation {
lengthString = " <i>Unsized</i>";
}
}
-
- buffer.append(BR);
- buffer.append(LENGTH_PREFIX);
- buffer.append(lengthString);
-
- return buffer;
+ return lengthString;
}
/**
@@ -172,7 +175,7 @@ public abstract class HTMLDataTypeRepresentation {
List<String> list = new ArrayList<>();
for (String nativeCommentLine : string.split("\n")) {
List<String> wrappedLines = breakLongLineAtWordBoundaries(nativeCommentLine,
- MAX_LINE_LENGTH - MIDDLE_COMMENT.length());
+ MAX_CHARACTER_LENGTH - MIDDLE_COMMENT.length());
for (int i = 0; i < wrappedLines.size(); i++) {
String wrappedLine = wrappedLines.get(i);
list.add(MIDDLE_COMMENT + wrappedLine + BR);
@@ -240,7 +243,7 @@ public abstract class HTMLDataTypeRepresentation {
* Formats a multi-line plain-text comment as a list of HTML marked-up lines.
*
* @param comment multi-line plain-text string
- * @param maxLines max number of formatted lines to return
+ * @param maxLines max number of formatted lines to return
* @return list of html marked-up {@link TextLine}s
*/
protected static List<TextLine> createCommentLines(String comment, int maxLines) {
@@ -263,14 +266,20 @@ public abstract class HTMLDataTypeRepresentation {
newList.add(new TextLine(commentLine));
}
newList.add(new TextLine(END_COMMENT));
+
+ /*
+ // note sure why we were add so much padding to the header
while (newList.size() < maxLines + 2) {
newList.add(new TextLine(BR)); // pad the end of the header for uniformity in appearance
}
+ */
+
+ newList.add(new TextLine(BR)); // pad the end of the header for visual separation
return newList;
}
- /** Returns a data type that can later be located */
+ /* Returns a data type that can later be located */
protected static DataType getLocatableDataType(DataType type) {
if (type instanceof DefaultDataType) {
@@ -302,7 +311,7 @@ public abstract class HTMLDataTypeRepresentation {
// needed for clients what want to build-up this object later via setter methods
}
- /**
+ /*
* Convenience constructor for those representations that don't really do much, like diffing.
*/
protected HTMLDataTypeRepresentation(String htmlText) {
@@ -315,12 +324,40 @@ public abstract class HTMLDataTypeRepresentation {
}
}
+ /**
+ * Returns an HTML string for this data representation object. The HTML returned will be
+ * truncated if it is too long. To get the full HTML, call {@link #getFullHTMLString()}.
+ *
+ * @return the html
+ * @see #getFullHTMLString()
+ */
public String getHTMLString() {
+ return getFullHTMLString(); // default to full text; subclasses can override
+ }
+
+ /**
+ * Returns an HTML string for this data representation object
+ *
+ * @return the html
+ * @see #getHTMLString()
+ */
+ public String getFullHTMLString() {
return HTML_OPEN + originalHTMLData + HTML_CLOSE;
}
- /** This is like {@link #getHTMLString()}, but does not put HTML tags around the data. */
+ /**
+ * This is like {@link #getHTMLString()}, but does not put HTML tags around the data
+ * @return the content
+ */
public String getHTMLContentString() {
+ return originalHTMLData; // default to full text; subclasses can override
+ }
+
+ /**
+ * This is like {@link #getHTMLString()}, but does not put HTML tags around the data
+ * @return the content
+ */
+ public String getFullHTMLContentString() {
return originalHTMLData;
}
@@ -342,10 +379,12 @@ public abstract class HTMLDataTypeRepresentation {
List<ValidatableLine> headerLines = new ArrayList<>();
headerLines.addAll(createCommentLines(comment, 4));
- // put the path info in
+ // put the path info in; don't display a floating '/' when the path is the root path
CategoryPath path = dataType.getCategoryPath();
- headerLines.add(new TextLine(HTMLUtilities.escapeHTML(path.getPath())));
- headerLines.add(new TextLine(BR));
+ if (!path.equals(CategoryPath.ROOT)) {
+ headerLines.add(new TextLine(HTMLUtilities.escapeHTML(path.getPath())));
+ headerLines.add(new TextLine(BR));
+ }
return headerLines;
}
@@ -391,6 +430,8 @@ public abstract class HTMLDataTypeRepresentation {
/**
* Extension point for adding empty lines. Subclasses that do not wish to use the default
* empty text line can override this method.
+ * @param oppositeLine the line that will go along with the newly created placeholder line
+ * @return the placeholder line
*/
protected PlaceHolderLine createPlaceHolderLine(ValidatableLine oppositeLine) {
// for now, base representations do not know how to create empty lines...if it turns out
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/PointerDataTypeHTMLRepresentation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/PointerDataTypeHTMLRepresentation.java
index a102f1772c..3cc222133c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/PointerDataTypeHTMLRepresentation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/PointerDataTypeHTMLRepresentation.java
@@ -15,32 +15,37 @@
*/
package ghidra.app.util.html;
+import org.apache.commons.lang3.StringUtils;
+
import ghidra.app.util.ToolTipUtils;
import ghidra.program.model.data.*;
import ghidra.util.HTMLUtilities;
+import ghidra.util.StringUtilities;
import ghidra.util.exception.AssertException;
public class PointerDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
+ private String truncatedHtmlData;
+
public PointerDataTypeHTMLRepresentation(Pointer pointer) {
- super(buildHTMLText(pointer));
+ super(buildHTMLText(pointer, false));
+
+ truncatedHtmlData = buildHTMLText(pointer, true);
}
- private static String buildHTMLText(Pointer pointer) {
- StringBuffer buffer = new StringBuffer();
- String description = pointer.getDescription();
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLString() {
+ return HTML_OPEN + truncatedHtmlData + HTML_CLOSE;
+ }
- if (description == null || description.length() == 0) {
- description = pointer.getDisplayName();
- }
- description = HTMLUtilities.friendlyEncodeHTML(description);
- buffer.append(description);
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLContentString() {
+ return truncatedHtmlData;
+ }
- // the base pointer description does not start with an upper case; fix it
- char firstChar = buffer.charAt(0);
- if (!Character.isUpperCase(firstChar)) {
- buffer.replace(0, 1, Character.toString(Character.toUpperCase(firstChar)));
- }
+ private static String buildHTMLText(Pointer pointer, boolean trim) {
DataType baseDataType = pointer;
while (baseDataType instanceof Pointer) {
@@ -48,9 +53,26 @@ public class PointerDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
}
if (baseDataType == null) {
- return buffer.toString();
+ return getDefaultDescription(pointer);
}
+ StringBuilder buffer = new StringBuilder();
+ int length = pointer.getLength();
+ String bits = (length * 8) + " bit ";
+ String baseName = baseDataType.getName();
+ if (trim) {
+ baseName = StringUtilities.trimMiddle(baseName, ToolTipUtils.LINE_LENGTH);
+ }
+ String fullDescription = bits + " Pointer";
+
+ fullDescription = HTMLUtilities.friendlyEncodeHTML(fullDescription);
+ buffer.append(FORWARD_SLASH).append(FORWARD_SLASH).append(HTML_SPACE);
+ buffer.append(HTMLUtilities.friendlyEncodeHTML(pointer.getName()));
+ buffer.append(BR);
+ buffer.append(fullDescription);
+ buffer.append(BR);
+ buffer.append("Size: ").append((length >= 0) ? length : "default");
+
buffer.append(BR).append(BR);
buffer.append("Pointer Base Data Type: ").append(BR);
if (baseDataType instanceof BuiltInDataType) {
@@ -65,7 +87,10 @@ public class PointerDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
HTMLDataTypeRepresentation representation =
ToolTipUtils.getHTMLRepresentation(baseDataType);
- String baseHTML = representation.getHTMLContentString();
+ String baseHTML = representation.getFullHTMLContentString();
+ if (trim) {
+ baseHTML = representation.getHTMLContentString();
+ }
buffer.append(baseHTML);
@@ -76,12 +101,24 @@ public class PointerDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
buffer.append(INDENT_CLOSE);
}
- buffer.append(BR);
- int length = pointer.getLength();
- buffer.append("Size: ").append((length >= 0) ? length : "default");
return buffer.toString();
}
+ private static String getDefaultDescription(Pointer pointer) {
+ String description = pointer.getDescription();
+ if (StringUtils.isBlank(description)) {
+ description = pointer.getDisplayName();
+ }
+
+ // the base pointer description does not start with an upper case; fix it
+ char firstChar = description.charAt(0);
+ if (!Character.isUpperCase(firstChar)) {
+ description = Character.toUpperCase(firstChar) + description.substring(1);
+ }
+
+ return description;
+ }
+
@Override
public HTMLDataTypeRepresentation[] diff(HTMLDataTypeRepresentation otherRepresentation) {
throw new AssertException("Pointer types are not diffable at this time");
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/TypeDefDataTypeHTMLRepresentation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/TypeDefDataTypeHTMLRepresentation.java
index 45232d0c92..2c25cfd646 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/TypeDefDataTypeHTMLRepresentation.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/html/TypeDefDataTypeHTMLRepresentation.java
@@ -23,6 +23,7 @@ import ghidra.app.util.html.diff.DataTypeDiff;
import ghidra.app.util.html.diff.DataTypeDiffBuilder;
import ghidra.program.model.data.*;
import ghidra.util.HTMLUtilities;
+import ghidra.util.StringUtilities;
public class TypeDefDataTypeHTMLRepresentation extends HTMLDataTypeRepresentation {
@@ -32,6 +33,8 @@ public class TypeDefDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
protected List<ValidatableLine> headerContent;
protected List<ValidatableLine> bodyContent;
+ private String truncatedHtmlData;
+
// private constructor for making diff copies
private TypeDefDataTypeHTMLRepresentation(TypeDef typeDef, List<String> warningLines,
List<ValidatableLine> headerLines, List<ValidatableLine> bodyLines) {
@@ -40,23 +43,40 @@ public class TypeDefDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
this.headerContent = headerLines;
this.bodyContent = bodyLines;
- originalHTMLData = buildHTMLText(typeDef, warningLines, headerLines, bodyLines);
+ originalHTMLData = buildHTMLText(typeDef, warningLines, headerLines, bodyLines, false);
}
public TypeDefDataTypeHTMLRepresentation(TypeDef typeDef) {
this.typeDef = typeDef;
warningLines = buildWarnings();
- headerContent = buildHeaderText(typeDef);
- bodyContent = buildBodyText(getBaseDataType());
+ headerContent = buildHeaderText(typeDef, false);
+ bodyContent = buildBodyText(getBaseDataType(), false);
+
+ originalHTMLData = buildHTMLText(typeDef, warningLines, headerContent, bodyContent, false);
- originalHTMLData = buildHTMLText(typeDef, warningLines, headerContent, bodyContent);
+ List<ValidatableLine> trimmedHeaderContent = buildHeaderText(typeDef, true);
+ List<ValidatableLine> trimmedBodyContent = buildBodyText(getBaseDataType(), true);
+ truncatedHtmlData =
+ buildHTMLText(typeDef, warningLines, trimmedHeaderContent, trimmedBodyContent, true);
}
protected DataType getBaseDataType() {
return getBaseDataType(typeDef);
}
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLString() {
+ return HTML_OPEN + truncatedHtmlData + HTML_CLOSE;
+ }
+
+ // overridden to return truncated text by default
+ @Override
+ public String getHTMLContentString() {
+ return truncatedHtmlData;
+ }
+
private static DataType getBaseDataType(DataType dataType) {
DataType basedataType = dataType;
while (basedataType instanceof TypeDef) {
@@ -87,38 +107,41 @@ public class TypeDefDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
return super.buildFooterText(dataType);
}
- @Override
- protected List<ValidatableLine> buildHeaderText(DataType dataType) {
- DataType basedataType = typeDef;
+ protected List<ValidatableLine> buildHeaderText(DataType dataType, boolean trim) {
+ DataType baseDataType = typeDef;
List<ValidatableLine> lines = new ArrayList<>();
- while (basedataType instanceof TypeDef) {
+ while (baseDataType instanceof TypeDef) {
StringBuilder buffy = new StringBuilder();
- String baseDtString = basedataType.toString();
+ String baseDtString = baseDataType.toString();
+ if (trim) {
+ baseDtString = StringUtilities.trimMiddle(baseDtString, ToolTipUtils.LINE_LENGTH);
+ }
String encodedBaseDt = HTMLUtilities.friendlyEncodeHTML(baseDtString);
buffy.append(TT_OPEN).append(encodedBaseDt).append(TT_CLOSE).append(BR);
lines.add(new TextLine(buffy.toString()));
- basedataType = ((TypeDef) basedataType).getDataType();
- while (basedataType instanceof Pointer) {
- basedataType = ((Pointer) basedataType).getDataType();
+ baseDataType = ((TypeDef) baseDataType).getDataType();
+ while (baseDataType instanceof Pointer) {
+ baseDataType = ((Pointer) baseDataType).getDataType();
}
}
return lines;
}
- private List<ValidatableLine> buildBodyText(DataType baseDataType) {
+ private List<ValidatableLine> buildBodyText(DataType baseDataType, boolean trim) {
List<ValidatableLine> lines = new ArrayList<>();
if (baseDataType instanceof BuiltInDataType) {
buildHTMLTextForBuiltIn(lines, baseDataType);
}
else {
- buildHTMLTextForBaseDataType(lines, baseDataType);
+ buildHTMLTextForBaseDataType(lines, baseDataType, trim);
}
return lines;
}
private static String buildHTMLText(TypeDef typeDef, List<String> warningLines,
- List<ValidatableLine> headerLines, List<ValidatableLine> bodyLines) {
- StringBuffer buffy = new StringBuffer();
+ List<ValidatableLine> headerLines, List<ValidatableLine> bodyLines, boolean trim) {
+
+ StringBuilder buffy = new StringBuilder();
// warnings
Iterator<String> warnings = warningLines.iterator();
@@ -132,7 +155,11 @@ public class TypeDefDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
Iterator<ValidatableLine> iterator = headerLines.iterator();
for (; iterator.hasNext();) {
TextLine line = (TextLine) iterator.next(); // This text should already be encoded.
- String headerLine = wrapStringInColor(line.getText(), line.getTextColor());
+ String headerLine = line.getText();
+ if (trim) {
+ headerLine = truncateAsNecessary(headerLine, ToolTipUtils.LINE_LENGTH);
+ }
+ headerLine = wrapStringInColor(line.getText(), line.getTextColor());
buffy.append(headerLine);
}
@@ -142,8 +169,11 @@ public class TypeDefDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
iterator = bodyLines.iterator();
for (; iterator.hasNext();) {
- TextLine line = (TextLine) iterator.next(); // This text should already be encoded.
- String bodyLine = wrapStringInColor(line.getText(), line.getTextColor());
+
+ // This text should already be encoded and already trimmed
+ TextLine line = (TextLine) iterator.next();
+ String bodyLine = line.getText();
+ bodyLine = wrapStringInColor(line.getText(), line.getTextColor());
buffy.append(bodyLine);
}
@@ -159,7 +189,7 @@ public class TypeDefDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
HTMLUtilities.friendlyEncodeHTML(dataTypeDescriptionOrName);
lines.add(new TextLine(encodedDescriptionOrName));
lines.add(new TextLine(TT_CLOSE));
- StringBuffer buffy = addDataTypeLength(basedataType, new StringBuffer());
+ StringBuilder buffy = addDataTypeLength(basedataType, new StringBuilder());
lines.add(new TextLine(buffy.toString()));
lines.add(new TextLine(INDENT_CLOSE));
}
@@ -173,17 +203,21 @@ public class TypeDefDataTypeHTMLRepresentation extends HTMLDataTypeRepresentatio
}
private static void buildHTMLTextForBaseDataType(List<ValidatableLine> lines,
- DataType basedataType) {
+ DataType basedataType, boolean trim) {
lines.add(new TextLine(INDENT_OPEN));
HTMLDataTypeRepresentation baseRepresentation =
ToolTipUtils.getHTMLRepresentation(basedataType);
- String baseHTML = baseRepresentation.getHTMLContentString();
+
+ String baseHTML = baseRepresentation.getFullHTMLContentString();
+ if (trim) {
+ baseHTML = baseRepresentation.getHTMLContentString();
+ }
lines.add(new TextLine(baseHTML));
if (baseHTML.indexOf(LENGTH_PREFIX) < 0) {
- StringBuffer buffy = addDataTypeLength(basedataType, new StringBuffer());
+ StringBuilder buffy = addDataTypeLength(basedataType, new StringBuilder());
lines.add(new TextLine(buffy.toString()));
}