Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7427 - Updated Comments copying to preserve newlines; added a truncation indicator to the Comments Field

dragonmacherdd1a9ac9013e
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java
index 9fd2e5a7b6..e0e6ed8682 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clipboard/CodeBrowserClipboardProvider.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.stream.Collectors;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -42,7 +43,6 @@ import ghidra.app.cmd.label.RenameLabelCmd;
import ghidra.app.plugin.core.codebrowser.CodeViewerActionContext;
import ghidra.app.services.ClipboardContentProviderService;
import ghidra.app.util.*;
-import ghidra.app.util.viewer.field.*;
import ghidra.app.util.viewer.listingpanel.ListingModel;
import ghidra.framework.model.DomainFile;
import ghidra.framework.options.OptionsChangeListener;
@@ -179,20 +179,20 @@ public class CodeBrowserClipboardProvider extends ByteCopier
public boolean paste(Transferable pasteData) {
try {
DataFlavor[] flavors = pasteData.getTransferDataFlavors();
- for (DataFlavor element : flavors) {
- if (element.equals(LABELS_COMMENTS_TYPE.getFlavor())) {
+ for (DataFlavor flavor : flavors) {
+ if (flavor.equals(LABELS_COMMENTS_TYPE.getFlavor())) {
return pasteLabelsComments(pasteData, true, true);
}
- else if (element.equals(LABELS_TYPE.getFlavor())) {
+ else if (flavor.equals(LABELS_TYPE.getFlavor())) {
return pasteLabelsComments(pasteData, true, false);
}
- else if (element.equals(COMMENTS_TYPE.getFlavor())) {
+ else if (flavor.equals(COMMENTS_TYPE.getFlavor())) {
return pasteLabelsComments(pasteData, false, true);
}
- else if (element.equals(LabelStringTransferable.labelStringFlavor)) {
+ else if (flavor.equals(LabelStringTransferable.labelStringFlavor)) {
return pasteLabelString(pasteData);
}
- else if (element.equals(NonLabelStringTransferable.nonLabelStringFlavor)) {
+ else if (flavor.equals(NonLabelStringTransferable.nonLabelStringFlavor)) {
return pasteNonLabelString(pasteData);
}
}
@@ -357,7 +357,8 @@ public class CodeBrowserClipboardProvider extends ByteCopier
else if (currentLocation instanceof CommentFieldLocation) {
CommentFieldLocation commentFieldLocation = (CommentFieldLocation) currentLocation;
String[] comment = commentFieldLocation.getComment();
- return new NonLabelStringTransferable(comment);
+ String text = Arrays.stream(comment).collect(Collectors.joining("\n"));
+ return new NonLabelStringTransferable(text);
}
else if (currentLocation instanceof BytesFieldLocation) {
// bytes are special--let them get copied and pasted as normal
@@ -1027,21 +1028,6 @@ public class CodeBrowserClipboardProvider extends ByteCopier
private final DataFlavor[] flavors = { nonLabelStringFlavor, DataFlavor.stringFlavor };
private final List<DataFlavor> flavorList = Arrays.asList(flavors);
- NonLabelStringTransferable(String[] text) {
- super(combine(text));
- }
-
- private static String combine(String[] text) {
- StringBuilder buildy = new StringBuilder();
- for (String string : text) {
- if (buildy.length() > 0) {
- buildy.append('\n');
- }
- buildy.append(string);
- }
- return buildy.toString();
- }
-
NonLabelStringTransferable(String text) {
super(text);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/TruncatedTextListingHover.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/TruncatedTextListingHover.java
index 2ed7e9921f..862bfbf28b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/TruncatedTextListingHover.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/TruncatedTextListingHover.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -71,8 +71,9 @@ public class TruncatedTextListingHover extends AbstractConfigurableHover
return null;
}
- if (((ListingTextField) field).isClipped()) {
- String text = field.getTextWithLineSeparators();
+ ListingTextField ltf = (ListingTextField) field;
+ if (ltf.isClipped()) {
+ String text = ltf.getFullTextWithLineSeparators();
String convertToHtml = HTMLUtilities.toLiteralHTMLForTooltip(text);
JToolTip toolTip = new JToolTip();
toolTip.setTipText(convertToHtml);
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/hover/AbstractReferenceHover.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/hover/AbstractReferenceHover.java
index 21885dcd8e..19fc9719f5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/hover/AbstractReferenceHover.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/hover/AbstractReferenceHover.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -36,8 +36,7 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.*;
import ghidra.program.util.*;
-import ghidra.util.HTMLUtilities;
-import ghidra.util.HelpLocation;
+import ghidra.util.*;
import ghidra.util.bean.opteditor.OptionsVetoException;
/**
@@ -162,6 +161,7 @@ public abstract class AbstractReferenceHover extends AbstractConfigurableHover {
codeFormatService = tool.getService(CodeFormatService.class);
}
if (codeFormatService == null) {
+ Msg.info(this, "Cannot show reference hovers without the CodeFormatService installed");
return;
}
@@ -251,21 +251,21 @@ public abstract class AbstractReferenceHover extends AbstractConfigurableHover {
/*
Format
-
+
Address: ram:1234
Address not in memory
-
-
+
+
Or, when multiple symbols at destination
-
-
+
+
Address: ram:1234
Symbols (3):
foo
bar
baz
Address not in memory
-
+
*/
String newline = HTMLUtilities.HTML_NEW_LINE;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/CodeUnitInfoTransferable.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/CodeUnitInfoTransferable.java
index afc19f627b..6698940cd4 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/CodeUnitInfoTransferable.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/CodeUnitInfoTransferable.java
@@ -15,14 +15,13 @@
*/
package ghidra.app.util;
-import ghidra.util.Msg;
-
import java.awt.datatransfer.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import docking.dnd.GenericDataFlavor;
+import ghidra.util.Msg;
/**
* Defines data that is available for drag/drop and clipboard transfers.
@@ -49,7 +48,7 @@ public class CodeUnitInfoTransferable implements Transferable, ClipboardOwner {
return null;
}
- private static DataFlavor[] flavors = { localDataTypeFlavor /*, textDataTypeFlavor*/};
+ private static DataFlavor[] flavors = { localDataTypeFlavor /*, textDataTypeFlavor*/ };
private static List<DataFlavor> flavorList = Arrays.asList(flavors);
private List<CodeUnitInfo> infoList;
@@ -62,25 +61,16 @@ public class CodeUnitInfoTransferable implements Transferable, ClipboardOwner {
infoList = list;
}
- /**
- * Return all data flavors that this class supports.
- */
@Override
public synchronized DataFlavor[] getTransferDataFlavors() {
return flavors;
}
- /**
- * Return whether the specified data flavor is supported.
- */
@Override
public boolean isDataFlavorSupported(DataFlavor f) {
return flavorList.contains(f);
}
- /**
- * Return the transfer data with the given data flavor.
- */
@Override
public synchronized Object getTransferData(DataFlavor f) throws UnsupportedFlavorException,
IOException {
@@ -91,20 +81,14 @@ public class CodeUnitInfoTransferable implements Transferable, ClipboardOwner {
throw new UnsupportedFlavorException(f);
}
- /**
- * Get the string representation for this transferable.
- */
@Override
public String toString() {
return "CodeUnitInfoTransferable";
}
- /*
- * (non-Javadoc)
- * @see java.awt.datatransfer.ClipboardOwner#lostOwnership(java.awt.datatransfer.Clipboard, java.awt.datatransfer.Transferable)
- */
@Override
public void lostOwnership(Clipboard clipboard, Transferable contents) {
+ // stub
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/EolComments.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/EolComments.java
index 0b8075c3aa..3403c17758 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/EolComments.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/EolComments.java
@@ -81,6 +81,7 @@ public class EolComments {
private boolean operandsShowReferences = false;
private int maxDisplayComments;
+ private boolean isTruncated;
private EolExtraCommentsOption extraCommentsOption;
public EolComments(CodeUnit cu, boolean operandsShowReferences, int maxDisplayComments,
@@ -182,10 +183,11 @@ public class EolComments {
private void addStrings(Collection<String> from, Collection<String> to) {
int space = getAvailableSpace();
for (String item : from) {
- to.add(item);
- if (to.size() == space) {
+ if (to.size() >= space) {
+ isTruncated = from.size() > to.size();
return;
}
+ to.add(item);
}
}
@@ -678,11 +680,15 @@ public class EolComments {
return Collections.unmodifiableList(offcuts);
}
+ public boolean isTruncated() {
+ return isTruncated;
+ }
+
@Override
public String toString() {
StringBuilder buffy = new StringBuilder();
- if (eols.isEmpty()) {
+ if (!eols.isEmpty()) {
buffy.append("EOLs: ").append(eols);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/CommentFieldMouseHandler.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/CommentFieldMouseHandler.java
index 3073a40ca0..fb5b22a099 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/CommentFieldMouseHandler.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/CommentFieldMouseHandler.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -54,8 +54,9 @@ public class CommentFieldMouseHandler implements FieldMouseHandlerExtension {
}
if (commentRow < 0) {
- return false; // Plate field locations can return negative values when clicking above
- // the border
+ // Plate field locations can return negative values when clicking above the border
+ return false;
+
}
String clickedWord =
@@ -69,11 +70,11 @@ public class CommentFieldMouseHandler implements FieldMouseHandlerExtension {
if (programLocation instanceof PlateFieldLocation) {
return ((PlateFieldLocation) programLocation).getCommentRow();
}
- return ((CommentFieldLocation) programLocation).getRow();
+ return programLocation.getRow();
}
protected int getCommentColumn(ProgramLocation programLocation) {
- return ((CommentFieldLocation) programLocation).getCharOffset();
+ return programLocation.getCharOffset();
}
protected String[] getComment(ProgramLocation programLocation) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/EolCommentFieldFactory.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/EolCommentFieldFactory.java
index 7100a7861c..bc540cbd64 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/EolCommentFieldFactory.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/EolCommentFieldFactory.java
@@ -19,6 +19,7 @@ import java.awt.Color;
import java.math.BigInteger;
import java.util.*;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
import docking.widgets.fieldpanel.field.*;
import docking.widgets.fieldpanel.support.*;
@@ -43,6 +44,7 @@ import utility.function.Dummy;
* Generates End of line comment Fields.
*/
public class EolCommentFieldFactory extends FieldFactory {
+
public static final String FIELD_NAME = "EOL Comment";
private static final String GROUP_TITLE = "EOL Comments Field";
private static final String SEMICOLON_PREFIX = "; ";
@@ -58,6 +60,7 @@ public class EolCommentFieldFactory extends FieldFactory {
public static final String EXTRA_COMMENT_KEY =
GROUP_TITLE + Options.DELIMITER + "Auto Comments";
+ private static final String ELLIPSIS = "...";
public static final Color DEFAULT_COLOR = Palette.BLUE;
private boolean isWordWrap;
@@ -256,11 +259,11 @@ public class EolCommentFieldFactory extends FieldFactory {
maxDisplayLines, extraCommentsOption);
// This Code Unit's End of Line Comment
- List<FieldElement> elementList = new ArrayList<>();
+ List<FieldElement> allElements = new ArrayList<>();
AttributedString prefix = createPrefix(CommentStyle.EOL);
List<String> eols = comments.getEOLComments();
List<FieldElement> eolElements = convertToFieldElements(program, eols, prefix, 0, true);
- elementList.addAll(eolElements);
+ allElements.addAll(eolElements);
/*
This section describes the various EOL comment types that may appear. The user can
@@ -288,11 +291,11 @@ public class EolCommentFieldFactory extends FieldFactory {
if (comments.isShowingRepeatables()) {
prefix = createPrefix(CommentStyle.REPEATABLE);
- int row = getNextRow(elementList);
+ int row = getNextRow(allElements);
List<String> repeatables = comments.getRepeatableComments();
List<FieldElement> elements =
convertToFieldElements(program, repeatables, prefix, row, true);
- elementList.addAll(elements);
+ allElements.addAll(elements);
}
if (comments.isShowingRefRepeatables()) {
@@ -301,7 +304,7 @@ public class EolCommentFieldFactory extends FieldFactory {
List<RefRepeatComment> refRepeatables = comments.getReferencedRepeatableComments();
for (RefRepeatComment comment : refRepeatables) {
- int row = getNextRow(elementList);
+ int row = getNextRow(allElements);
String[] lines = comment.getCommentLines();
Address refAddress = comment.getAddress();
List<String> linesList = Arrays.asList(lines);
@@ -312,36 +315,52 @@ public class EolCommentFieldFactory extends FieldFactory {
List<FieldElement> elements =
convertToFieldElements(program, linesList, decorator, prefix, row, true);
- elementList.addAll(elements);
+ allElements.addAll(elements);
}
}
if (comments.isShowingAutoComments()) {
prefix = createPrefix(CommentStyle.AUTO);
- int row = getNextRow(elementList);
+ int row = getNextRow(allElements);
List<String> autos = comments.getAutomaticComment();
// Note: we pass 'false' for allowing annotations so that the user will see the raw data
// and not an interpreted annotation.
List<FieldElement> elements =
convertToFieldElements(program, autos, prefix, row, false);
- elementList.addAll(elements);
+ allElements.addAll(elements);
}
if (comments.isShowingOffcutComments()) {
prefix = createPrefix(CommentStyle.OFFCUT);
- int row = getNextRow(elementList);
+ int row = getNextRow(allElements);
List<String> offcuts = comments.getOffcutEolComments();
List<FieldElement> elements =
convertToFieldElements(program, offcuts, prefix, row, true);
- elementList.addAll(elements);
+ allElements.addAll(elements);
}
- if (elementList.isEmpty()) {
+ if (allElements.isEmpty()) {
return null;
}
- return ListingTextField.createMultilineTextField(this, proxy, elementList, x, width,
- maxDisplayLines, hlProvider);
+
+ int maxLines = maxDisplayLines;
+ boolean isTruncated = comments.isTruncated();
+ if (isTruncated) {
+ // add a visual signal that not all comment lines are shown
+ AttributedString prototype = prefix;
+ int row = maxDisplayLines;
+ FieldElement element = createCommentField(ELLIPSIS, prototype, program, row, false);
+ allElements.add(element);
+ maxLines++;
+ }
+
+ // This code is taken from ListingTextField.createMultilineTextField()
+ ListingFieldHighlightFactoryAdapter hlFactory =
+ new ListingFieldHighlightFactoryAdapter(hlProvider);
+ TextField field =
+ new VerticalLayoutTextField(allElements, x, width, maxLines, hlFactory);
+ return new EolCommentListingTextField(proxy, field, hlFactory, cu, isTruncated);
}
private boolean isOpenData(CodeUnit cu, ProxyObj<?> proxy) {
@@ -493,11 +512,28 @@ public class EolCommentFieldFactory extends FieldFactory {
if (!(obj instanceof CodeUnit)) {
return null;
}
+
CodeUnit cu = (CodeUnit) obj;
- EolComments displayableEol = new EolComments(cu,
+ EolComments comments = new EolComments(cu,
codeUnitFormatOptions.followReferencedPointers(), maxDisplayLines, extraCommentsOption);
- // Hold position in connected tool if navigating within semicolon.
+ if (comments.isTruncated()) {
+ if (screenRow == maxDisplayLines) { // on the '...' line
+ Program program = cu.getProgram();
+ Address addr = cu.getMinAddress();
+ int[] cpath = null;
+ if (cu instanceof Data data) {
+ cpath = data.getComponentPath();
+ }
+ List<String> allComments = comments.getComments();
+ String[] asArray = allComments.toArray(String[]::new);
+ return new EolCommentFieldLocation(program, addr, cpath, asArray, screenRow,
+ screenColumn, screenRow);
+ }
+ }
+
+ // Hold position in connected tool if navigating within semicolon. This allows other tools
+ // not showing the prefix to track correctly.
int numLeadColumns = 0;
if (showSemicolon) {
numLeadColumns += SEMICOLON_PREFIX.length();
@@ -511,7 +547,7 @@ public class EolCommentFieldFactory extends FieldFactory {
int eolRow = rowCol.row();
int eolColumn = rowCol.col();
- return displayableEol.getLocation(eolRow, eolColumn);
+ return comments.getLocation(eolRow, eolColumn);
}
@Override
@@ -530,19 +566,40 @@ public class EolCommentFieldFactory extends FieldFactory {
return null;
}
- EolComments displayableEol = new EolComments((CodeUnit) obj,
- codeUnitFormatOptions.followReferencedPointers(), maxDisplayLines, extraCommentsOption);
-
ListingTextField btf = (ListingTextField) bf;
if (!hasSamePath(bf, loc)) {
return null;
}
- RowColLocation eolRowCol = displayableEol.getRowCol((CommentFieldLocation) loc);
+ EolComments comments = new EolComments((CodeUnit) obj,
+ codeUnitFormatOptions.followReferencedPointers(), maxDisplayLines, extraCommentsOption);
+
+ if (comments.isTruncated()) {
+ int row = loc.getRow();
+ if (row >= maxDisplayLines) { // on the '...' line
+ int col = loc.getCharOffset();
+ col = Math.min(3, col); // cap at the length of '...' to keep the cursor on our row
+ return new FieldLocation(index, fieldNum, maxDisplayLines, col);
+ }
+ }
+
+ RowColLocation eolRowCol = comments.getRowCol((CommentFieldLocation) loc);
int row = eolRowCol.row();
int col = eolRowCol.col();
RowColLocation screenRowCol = btf.dataToScreenLocation(row, col);
+ if (screenRowCol instanceof DefaultRowColLocation) {
+ // This means that we do not have a valid character location for the given row and col.
+ // With connected tools, if the source of the event has less rows than we do, and the
+ // user is on the '...' row, then this can happen. Just create a location that is
+ // reasonable for our row configuration. Assume that we do not have wrapping rows.
+ int locRow = loc.getRow();
+ if (locRow < maxDisplayLines) {
+ int screenCol = 0;
+ return new FieldLocation(index, fieldNum, locRow, screenCol);
+ }
+ }
+
int screenRow = screenRowCol.row();
int screenCol = screenRowCol.col();
if (screenRowCol.isHidden()) { // clipped location
@@ -569,23 +626,45 @@ public class EolCommentFieldFactory extends FieldFactory {
newFieldOptions);
}
- /**
- * Convert the array of comments to a single string and use the given
- * separatorChar as the delimiter.
- *
- * @param comments array of comments to convert
- * @param separatorChar character to insert after each element in the comment array
- * @return the converted string
+//=================================================================================================
+// Inner Classes
+//=================================================================================================
+
+ /*
+ We create our own text field to control isClipped() so that hovers in the listing will work
+ for truncated text as well as clipped text.
*/
- public static String getSingleString(String[] comments, char separatorChar) {
- if (comments.length == 0) {
- return null;
+ private class EolCommentListingTextField extends ListingTextField {
+
+ // vertically clipped
+ private boolean isTruncated;
+ private CodeUnit cu;
+
+ public EolCommentListingTextField(ProxyObj<?> proxy, TextField field,
+ ListingFieldHighlightFactoryAdapter hlFactory, CodeUnit cu, boolean isTruncated) {
+ super(EolCommentFieldFactory.this, proxy, field, hlFactory);
+ this.cu = cu;
+ this.isTruncated = isTruncated;
}
- StringBuilder buf = new StringBuilder(comments[0]);
- for (int i = 1; i < comments.length; i++) {
- buf.append(separatorChar + comments[i]);
+ @Override
+ public boolean isClipped() {
+ return isTruncated || super.isClipped();
+ }
+
+ @Override
+ public String getFullTextWithLineSeparators() {
+
+ if (isTruncated) {
+ int allLines = 100; // limit to something reasonable for a tooltip
+ EolComments comments =
+ new EolComments(cu, codeUnitFormatOptions.followReferencedPointers(),
+ allLines, extraCommentsOption);
+ List<String> allComments = comments.getComments();
+ return allComments.stream().collect(Collectors.joining("\n"));
+ }
+ return super.getFullTextWithLineSeparators();
}
- return buf.toString();
}
+
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FunctionRepeatableCommentFieldMouseHandler.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FunctionRepeatableCommentFieldMouseHandler.java
index a01f094ac0..78506dd00e 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FunctionRepeatableCommentFieldMouseHandler.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/FunctionRepeatableCommentFieldMouseHandler.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -43,16 +43,6 @@ public class FunctionRepeatableCommentFieldMouseHandler extends CommentFieldMous
return checkWord(clickedWord, serviceProvider, sourceNavigatable);
}
- @Override
- protected int getCommentRow(ProgramLocation programLocation) {
- return ((FunctionRepeatableCommentFieldLocation) programLocation).getRow();
- }
-
- @Override
- protected int getCommentColumn(ProgramLocation programLocation) {
- return ((FunctionRepeatableCommentFieldLocation) programLocation).getCharOffset();
- }
-
@Override
protected String[] getComment(ProgramLocation programLocation) {
return ((FunctionRepeatableCommentFieldLocation) programLocation).getComment();
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/ListingField.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/ListingField.java
index bf2a381348..d20d4086a0 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/ListingField.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/ListingField.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -44,4 +44,15 @@ public interface ListingField extends Field {
* @return the object that was clicked
*/
public Object getClickedObject(FieldLocation fieldLocation);
+
+ /**
+ * Returns the full text for this field. For most fields this will be the same value as
+ * {@link #getTextWithLineSeparators()}. Some classes may override this method to return more
+ * text than is provided to the Listing. For example, a comment fields may only give the
+ * listing a small number of lines to display, even when the database has more.
+ * @return the full text
+ */
+ public default String getFullTextWithLineSeparators() {
+ return getTextWithLineSeparators();
+ }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/VariableCommentFieldMouseHandler.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/VariableCommentFieldMouseHandler.java
index 8ab92ea29f..8140ddcfd6 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/VariableCommentFieldMouseHandler.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/VariableCommentFieldMouseHandler.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -46,11 +46,6 @@ public class VariableCommentFieldMouseHandler extends CommentFieldMouseHandler {
return 0;
}
- @Override
- protected int getCommentColumn(ProgramLocation programLocation) {
- return ((VariableCommentFieldLocation) programLocation).getCharOffset();
- }
-
@Override
protected String[] getComment(ProgramLocation programLocation) {
return new String[] { ((VariableCommentFieldLocation) programLocation).getComment() };
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/AttributedString.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/AttributedString.java
index 3135744173..164a611c81 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/AttributedString.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/field/AttributedString.java
@@ -226,7 +226,19 @@ public class AttributedString {
}
g.setColor(textColor);
- GraphicsUtils.drawString(c, g, text, x, 0);
+
+ // The call to GraphicsUtils.drawString() will not paint text that is empty. Some clients
+ // provider a Graphics object used to convert calls to drawString() into text output to be
+ // used for copying/pasting of text. We may have empty text when the UI builds fields that
+ // have blank lines, such as for comments. We must manually call the graphics object for
+ // blank text to make sure that out custom Graphics objects work as intended.
+ if (text.length() == 0) {
+ g.drawString(text, x, 0);
+ }
+ else {
+ GraphicsUtils.drawString(c, g, text, x, 0);
+ }
+
}
//==================================================================================================
diff --git a/Ghidra/Framework/Generic/src/main/java/generic/text/TextLayoutGraphics.java b/Ghidra/Framework/Generic/src/main/java/generic/text/TextLayoutGraphics.java
index 2823e9ec39..add3eeb37d 100644
--- a/Ghidra/Framework/Generic/src/main/java/generic/text/TextLayoutGraphics.java
+++ b/Ghidra/Framework/Generic/src/main/java/generic/text/TextLayoutGraphics.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -172,8 +172,8 @@ public class TextLayoutGraphics extends Graphics2D {
textInfos.sort(pointComparator);
// Group the text into rows based on font height and y position
- //TODO - Ideally, it would be nice if there was a good way to group text that
- // varied in height in a nice way
+ // Note: Ideally, it would be nice if there was a better way to group text that
+ // varied in height
int lastPos = textInfos.get(0).point.y;
int row = 0;
for (TextInfo info : textInfos) {
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/FunctionRepeatableCommentFieldLocation.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/FunctionRepeatableCommentFieldLocation.java
index 30153480b6..9899095fb6 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/FunctionRepeatableCommentFieldLocation.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/FunctionRepeatableCommentFieldLocation.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -67,7 +67,7 @@ public class FunctionRepeatableCommentFieldLocation extends FunctionLocation {
}
/**
- * Return the function comment string at this location.
+ * {@return the function comment string at this location}
*/
public String[] getComment() {
return commentArray;
@@ -83,15 +83,19 @@ public class FunctionRepeatableCommentFieldLocation extends FunctionLocation {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
FunctionRepeatableCommentFieldLocation other = (FunctionRepeatableCommentFieldLocation) obj;
- if (!Arrays.equals(commentArray, other.commentArray))
+ if (!Arrays.equals(commentArray, other.commentArray)) {
return false;
+ }
return true;
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/VariableCommentFieldLocation.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/VariableCommentFieldLocation.java
index fa5877848d..cb323c60d6 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/VariableCommentFieldLocation.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/VariableCommentFieldLocation.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -67,7 +67,7 @@ public class VariableCommentFieldLocation extends VariableLocation {
}
/**
- * Return the function variable comment string at this location.
+ * {@return the function variable comment string at this location}
*/
public String getComment() {
return comment;
@@ -83,19 +83,24 @@ public class VariableCommentFieldLocation extends VariableLocation {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (!super.equals(obj))
+ }
+ if (!super.equals(obj)) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
VariableCommentFieldLocation other = (VariableCommentFieldLocation) obj;
if (comment == null) {
- if (other.comment != null)
+ if (other.comment != null) {
return false;
+ }
}
- else if (!comment.equals(other.comment))
+ else if (!comment.equals(other.comment)) {
return false;
+ }
return true;
}