Ghidra is a software reverse engineering (SRE) framework
GP-2228 - Added a status message when applying a favorite data type to a non-contiguous selection is not allowed
dragonmacher83d2cbcf3156
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.javaindex a158ae3f6a..cf5620e04d 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java@@ -568,10 +568,11 @@ public abstract class CompEditorModel extends CompositeEditorModel {@Overridepublic DataTypeComponent add(DataType dataType) throws UsrException {- if (isContiguousSelection()) {- return add(getMinIndexSelected(), dataType);+ if (!isContiguousSelection()) {+ setStatus("Replace data type only works on a contiguous selection", true);+ return null;}- return null;+ return add(getMinIndexSelected(), dataType);}/**@@ -598,7 +599,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {return null;}});-+fixSelection();componentEdited();selectionChanged();@@ -822,7 +823,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {* @param length component length* @throws InvalidDataTypeException if check fails*/- private void checkForReplace(int rowIndex, DataType datatype, int length) throws InvalidDataTypeException {+ private void checkForReplace(int rowIndex, DataType datatype, int length)+ throws InvalidDataTypeException {DataTypeComponent dtc = getComponent(rowIndex);if (dtc == null) {throw new InvalidDataTypeException("Invalid component selection");@@ -843,25 +845,28 @@ public abstract class CompEditorModel extends CompositeEditorModel {int currentCompSize = dtc.getLength();int newCompSize = length;int sizeDiff = newCompSize - currentCompSize;-+if (sizeDiff <= 0) {return;}-+int undefinedSpaceAvail = getNumUndefinedBytesAfter(dtc);if (sizeDiff > undefinedSpaceAvail) {int spaceNeeded = sizeDiff - undefinedSpaceAvail;- String msg = newCompSize + " byte replacement at 0x" + Integer.toHexString(dtc.getOffset());+ String msg =+ newCompSize + " byte replacement at 0x" + Integer.toHexString(dtc.getOffset());if (struct.getDefinedComponentAtOrAfterOffset(dtc.getOffset() + 1) == null) {// suggest growing structureint suggestedSize = getLength() + spaceNeeded;- throw new InvalidDataTypeException(msg + " requires structure length of " + suggestedSize + "-bytes.");+ throw new InvalidDataTypeException(+ msg + " requires structure length of " + suggestedSize + "-bytes.");}// suggest insert bytes (NOTE: in the future a conflict removal/grow could be offered)- throw new InvalidDataTypeException(msg + " requires " + spaceNeeded + " additional undefined bytes.");+ throw new InvalidDataTypeException(+ msg + " requires " + spaceNeeded + " additional undefined bytes.");}}-+/*** Get the number of undefined bytes after the specified component.* The viewComposite must be a non-packed structure.@@ -879,16 +884,17 @@ public abstract class CompEditorModel extends CompositeEditorModel {if (struct.isPackingEnabled()) {throw new UnsupportedOperationException();}-+// TODO: May need special logic if dtc is zero-length componentint length = getLength();int nextCompOffset = dtc.getEndOffset() + 1;if (nextCompOffset >= length) {return 0;}- DataTypeComponent nextDefinedDtc = struct.getDefinedComponentAtOrAfterOffset(nextCompOffset);+ DataTypeComponent nextDefinedDtc =+ struct.getDefinedComponentAtOrAfterOffset(nextCompOffset);int nextDefinedOffset = (nextDefinedDtc == null) ? length : nextDefinedDtc.getOffset();- return Math.max(0, nextDefinedOffset - nextCompOffset); // prevent negative return value+ return Math.max(0, nextDefinedOffset - nextCompOffset); // prevent negative return value}/**