From 7c67a103cda30ba0b75b146c65aeee82c00fcdb6 Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Wed, 9 Apr 2025 19:14:13 -0400 Subject: [PATCH] GP-5580 Corrected Union editor issue with shift up/down and create array. Removed obsolete method within editor model. --- .../core/compositeeditor/CompEditorModel.java | 54 +++++++++---------- .../compositeeditor/StructureEditorModel.java | 27 ---------- .../compositeeditor/UnionEditorModel.java | 39 ++------------ 3 files changed, 28 insertions(+), 92 deletions(-) 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.java index 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.java index 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); - } - } - @Override public 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.java index 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 - */ @Override protected boolean isAtEnd(int rowIndex) { + // Not applicable to union return 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. - */ @Override protected int consumeByComponent(int rowIndex) { + // Not applicable to union return 0; } @Override public boolean isShowingUndefinedBytes() { + // Not applicable to union return false; }