Ghidra is a software reverse engineering (SRE) framework
GT-2942 - Search Text Preview - fixed bug that causes some separator tokens to not appear in the Search Text Preview column
dragonmacherf5f6b7c18b49
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/OperandFieldHelper.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/OperandFieldHelper.javaindex 63851635bb..7c931108dd 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/OperandFieldHelper.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/field/OperandFieldHelper.java@@ -401,8 +401,8 @@ abstract class OperandFieldHelper extends FieldFactory {for (int opIndex = 0; opIndex < numOperands; opIndex++) {OperandRepresentationList operandRepresentationList =codeUnitFormat.getOperandRepresentationList(inst, opIndex);- characterOffset = addElementsForOperand(inst, elements, opIndex,- operandRepresentationList, characterOffset);+ addElementsForOperand(inst, elements, opIndex, operandRepresentationList,+ characterOffset);characterOffset = 0;}@@ -504,8 +504,8 @@ abstract class OperandFieldHelper extends FieldFactory {}private boolean containsNonPrimary(Reference[] refs) {- for (int i = 0; i < refs.length; i++) {- if (!refs[i].isPrimary()) {+ for (Reference ref : refs) {+ if (!ref.isPrimary()) {return true;}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ListingPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ListingPanel.javaindex fee2ae523a..ca14dfa747 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ListingPanel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/viewer/listingpanel/ListingPanel.java@@ -519,8 +519,10 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc/*** Moves the cursor to the given program location and repositions the scrollbar to- * show that location in the screen.- * @param loc the location to move to.+ * show that location in the screen+ *+ * @param loc the location to move to+ * @return true if the 'go to' was successful*/public boolean goTo(ProgramLocation loc) {return goTo(loc, true);@@ -536,6 +538,7 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc* the given location will be placed in the center of the screen;* when the parameter is false, then the screen will be scrolled* only enough to show the cursor.+ * @return true if the 'go to' was successful*/public boolean goTo(ProgramLocation loc, boolean centerWhenNotVisible) {final FieldLocation floc = getFieldLocation(loc);@@ -555,15 +558,27 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLocreturn true;}- /** Scroll the view of the listing to the given location. */+ /**+ * Scroll the view of the listing to the given location+ * @param location the location+ */public void scrollTo(ProgramLocation location) {FieldLocation fieldLocation = getFieldLocation(location);+ if (fieldLocation == null) {+ return; // this can happen when using restricted views+ }fieldPanel.scrollTo(fieldLocation);}- /** Center the view of the listing around the given location. */+ /**+ * Center the view of the listing around the given location+ * @param location the location+ */public void center(ProgramLocation location) {FieldLocation fieldLocation = getFieldLocation(location);+ if (fieldLocation == null) {+ return; // this can happen when using restricted views+ }fieldPanel.center(fieldLocation);}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java b/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.javaindex a091bb3d66..ea643769bd 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/model/listing/CodeUnitFormat.java@@ -17,6 +17,8 @@ package ghidra.program.model.listing;import java.util.*;+import org.apache.commons.lang3.StringUtils;+import ghidra.app.util.NamespaceUtils;import ghidra.app.util.viewer.field.CommentUtils;import ghidra.program.model.address.*;@@ -36,6 +38,8 @@ import ghidra.util.MathUtilities;public class CodeUnitFormat {+ private static final String EMPTY = "";+protected static final String PLUS = "+";protected static final String UNDERSCORE = "_";@@ -112,37 +116,39 @@ public class CodeUnitFormat {*/public String getRepresentationString(CodeUnit cu, boolean includeEOLcomment) {- StringBuffer stringBuffer = new StringBuffer(getMnemonicRepresentation(cu));+ StringBuilder buffy = new StringBuilder(getMnemonicRepresentation(cu));if (cu instanceof Instruction) {Instruction instr = (Instruction) cu;int n = instr.getNumOperands();+ if (n > 1) {+ buffy.append(' ');+ }+for (int i = 0; i < n; i++) {- if (i == 0) {- stringBuffer.append(" ");- }- else {- String separator = instr.getSeparator(i);- if (separator != null && separator.length() != 0) {- stringBuffer.append(separator);- }- }- stringBuffer.append(getOperandRepresentationString(cu, i));+ String sep = instr.getSeparator(i);+ buffy.append(StringUtils.isBlank(sep) ? EMPTY : sep);+ buffy.append(getOperandRepresentationString(cu, i));}++ // grab any trailing separator at n (index + 1; see Instruction.getSeparator())+ String sep = instr.getSeparator(n);+ buffy.append(StringUtils.isBlank(sep) ? EMPTY : sep);}else { // data always has one operand- stringBuffer.append(" ");- stringBuffer.append(getOperandRepresentationString(cu, 0));+ buffy.append(' ');+ buffy.append(getOperandRepresentationString(cu, 0));}+if (includeEOLcomment) {String eolComment = cu.getComment(CodeUnit.EOL_COMMENT);if (eolComment != null) {// fixup annotationseolComment = CommentUtils.getDisplayString(eolComment, cu.getProgram());- stringBuffer.append(" // ");- stringBuffer.append(eolComment);+ buffy.append(" // ");+ buffy.append(eolComment);}}- return stringBuffer.toString();+ return buffy.toString();}/**@@ -152,19 +158,19 @@ public class CodeUnitFormat {* @return mnemonic representation*/public String getMnemonicRepresentation(CodeUnit cu) {- StringBuffer stringBuffer = new StringBuffer();+ StringBuilder buffy = new StringBuilder();String mnemonic = cu.getMnemonicString();if (options.showDataMutability && (cu instanceof Data) && mnemonic != null) {Data d = (Data) cu;if (d.isConstant()) {- stringBuffer.append("const ");+ buffy.append("const ");}else if (d.isVolatile()) {- stringBuffer.append("volatile ");+ buffy.append("volatile ");}}- stringBuffer.append(mnemonic);- return stringBuffer.toString();+ buffy.append(mnemonic);+ return buffy.toString();}/**@@ -273,7 +279,7 @@ public class CodeUnitFormat {* Perform register markup with explicit and implied register variable* reference.*- * @param inst instruction+ * @param instr instruction* @param opIndex* @param func function containing instruction* @param primaryRef primary reference or null@@ -446,18 +452,17 @@ public class CodeUnitFormat {* @param opIndex operand index* @param func function containing instruction* @param primaryRef primary reference- * @param referencedVariable optional variable associated with reference- * @param regIndexMap register index map- * @param representationList+ * @param representationList the representation objects* @return true if primaryRef was included in scalar mark-up*/private boolean performAddressMarkup(Instruction instr, int opIndex, Function func,Reference primaryRef, List<Object> representationList) {+if (primaryRef == null || !primaryRef.isMemoryReference()) {return false;}- Address refAddr = primaryRef.getToAddress();+ Address refAddr = primaryRef.getToAddress();int size = representationList.size();for (int i = 0; i < size; i++) {Object obj = representationList.get(i);@@ -1133,13 +1138,9 @@ public class CodeUnitFormat {* Get a representation object corresponding to the specified reference.* Format options are considered when generating label.*- * @param cu- * @param ref+ * @param cu the code unit+ * @param ref the reference* @param var variable which corresponds to reference or null- * @param showIndirectValue if true, indirect memory references which refer- * to a pointer will get an additional "=value" appended where- * value corresponds to data pointed to by the referenced- * pointer.* @return reference representation object*/private Object getReferenceRepresentation(CodeUnit cu, Reference ref, Variable var) {@@ -1417,9 +1418,6 @@ public class CodeUnitFormat {return symbol.getName();}- /**- * Returns ShowBlockName setting- */public ShowBlockName getShowBlockName() {return options.showBlockName;}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerUtils.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerUtils.javaindex 42e038a273..9a08c05bb1 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerUtils.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerUtils.java@@ -24,7 +24,6 @@ import ghidra.program.model.address.*;import ghidra.program.model.listing.Function;import ghidra.program.model.listing.Program;import ghidra.program.model.pcode.*;-import ghidra.util.Msg;public class DecompilerUtils {@@ -315,11 +314,6 @@ public class DecompilerUtils {int nchild = parentNode.numChildren();for (int i = 0; i < nchild; i++) {ClangNode node = parentNode.Child(i);-- if (node instanceof ClangFuncProto) {- Msg.debug(null, "");- }-if (node.numChildren() > 0) {collectTokens(tokenList, node, addressSet);}