Ghidra is a software reverse engineering (SRE) framework
GP-5580 Corrected Union editor issue with shift up/down and create array. Removed obsolete method within editor model.
ghidra17c67a103cda3
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 ff8edd751e..417010fcc9 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@@ -936,16 +936,18 @@ public abstract class CompEditorModel extends CompositeEditorModel {endRowIndex <= 0 || endRowIndex >= numComps) {return false;}- DataTypeComponent comp = getComponent(startRowIndex - 1);- deleteComponent(startRowIndex - 1);- try {- insert(endRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),- comp.getComment());- }- catch (InvalidDataTypeException e) {- return false;- }- return true;+ return viewDTM.withTransaction("Shift Up", () -> {+ DataTypeComponent comp = getComponent(startRowIndex - 1);+ deleteComponent(startRowIndex - 1);+ try {+ insert(endRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),+ comp.getComment());+ }+ catch (InvalidDataTypeException e) {+ return false;+ }+ return true;+ });}/**@@ -962,16 +964,18 @@ public abstract class CompEditorModel extends CompositeEditorModel {endRowIndex < 0 || endRowIndex >= numComps - 1) {return false;}- DataTypeComponent comp = getComponent(endRowIndex + 1);- deleteComponent(endRowIndex + 1);- try {- insert(startRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),- comp.getComment());- }- catch (InvalidDataTypeException e) {- return false;- }- return true;+ return viewDTM.withTransaction("Shift Down", () -> {+ DataTypeComponent comp = getComponent(endRowIndex + 1);+ deleteComponent(endRowIndex + 1);+ try {+ insert(startRowIndex, comp.getDataType(), comp.getLength(), comp.getFieldName(),+ comp.getComment());+ }+ catch (InvalidDataTypeException e) {+ return false;+ }+ return true;+ });}@Override@@ -1066,6 +1070,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {replace(rowIndex, array, array.getLength()); // Can throw UsrException.}});+ componentEdited();}/**@@ -1629,15 +1634,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {}}- /**- * Removes the indicated data type from any components to prevent a cycle- * being created by this component being updated. Structures will actually- * clear any components containing the indicated data type.- * Unions will delete their components that contain the data type.- * @param comp the composite data type that contains the data type being edited.- */- abstract void removeDtFromComponents(Composite comp);-//==================================================================================================// End of Override CompositeViewerModel CategoryChangeListener methods//==================================================================================================diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.javaindex ab9f52d06a..df8bf09d89 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java@@ -1062,33 +1062,6 @@ class StructureEditorModel extends CompEditorModel {}}- @Override- void removeDtFromComponents(Composite comp) {- DataType newDt = viewDTM.getDataType(comp.getDataTypePath());- if (newDt == null) {- return;- }- boolean clearedComponents = viewDTM.withTransaction("Remove Components", () -> {- boolean cleared = false;- int num = getNumComponents();- for (int i = num - 1; i >= 0; i--) {- DataTypeComponent dtc = getComponent(i);- DataType dt = dtc.getDataType();- if (dt instanceof Composite) {- Composite dtcComp = (Composite) dt;- if (dtcComp.isPartOf(newDt)) {- clearComponents(new int[] { i });- cleared = true;- }- }- }- return cleared;- });- if (clearedComponents) {- setStatus("Components containing " + comp.getDisplayName() + " were cleared.", true);- }- }-@Overridepublic boolean isShowingUndefinedBytes() {return !viewComposite.isPackingEnabled();diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.javaindex 70df062d1c..86898c9551 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/UnionEditorModel.java@@ -540,54 +540,21 @@ class UnionEditorModel extends CompEditorModel {throw new UnsupportedOperationException("Can't clear components in a union.");}- @Override- void removeDtFromComponents(Composite comp) {- DataTypePath path = comp.getDataTypePath();- DataType newDt = viewDTM.getDataType(path);- if (newDt == null) {- return;- }- viewDTM.withTransaction("Remove use of " + path, () -> {- int num = getNumComponents();- for (int i = num - 1; i >= 0; i--) {- DataTypeComponent dtc = getComponent(i);- DataType dt = dtc.getDataType();- if (dt instanceof Composite) {- Composite dtcComp = (Composite) dt;- if (dtcComp.isPartOf(newDt)) {- deleteComponent(i);- String msg =- "Components containing " + comp.getDisplayName() + " were removed.";- setStatus(msg, true);- }- }- }- });- }-- /**- * ?????- *- * @param rowIndex the index of the row- */@Overrideprotected boolean isAtEnd(int rowIndex) {+ // Not applicable to unionreturn false;}- /**- * Cause the component at the specified index to consume undefined bytes- * that follow it.- * Note: this method adjusts the selection.- * @return the number of Undefined bytes consumed.- */@Overrideprotected int consumeByComponent(int rowIndex) {+ // Not applicable to unionreturn 0;}@Overridepublic boolean isShowingUndefinedBytes() {+ // Not applicable to unionreturn false;}