Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-2095 changed structure/union editor duplicate component actions to select last component added

ghidra10ee2b07f5bdb
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeEditors/StructureEditor.htm b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeEditors/StructureEditor.htm
index dbb850fea7..c95b7b9d58 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/DataTypeEditors/StructureEditor.htm
+++ b/Ghidra/Features/Base/src/main/help/help/topics/DataTypeEditors/StructureEditor.htm
@@ -457,12 +457,14 @@
<LI>Press the <IMG src="images/DuplicateData.png" alt=""> <B>Duplicate Component</B>
button.</LI>
- <LI>A single copy of the component is created immediately following the selected one.</LI>
+ <LI>A single copy of the component is created immediately following the selected one.
+ The newly created component will become selected allowing for repeated use of the action.</LI>
</OL>
<P>If the structure is not packed (i.e., pack disabled), then there must be enough <i>undefined</i> components following the
component to accommodate the duplicate. In such a such a structure, <i>undefined</i> bytes get
- consumed by the new copy of the component.</P>
+ consumed by the new copy of the component. If action is performed on the last component the structure
+ length will grow as needed.</P>
</BLOCKQUOTE>
<H3><A name="Structure_Editor_Duplicate_Multiple_of_Component"></A> <IMG src=
@@ -479,7 +481,8 @@
<LI><A name="Structure_Editor_Duplicates_NumberInputDialog"></A> The number of duplicates
dialog appears. In a non-packed structure, you can only indicate as many duplicates as will
- fit in place of <i>undefined</i> bytes.</LI>
+ fit in place of <i>undefined</i> bytes unless duplicating the last component in which case the
+ structure will grow as needed. The last component added will become the selected component.</LI>
</OL>
</BLOCKQUOTE>
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 c56a6065f2..1889931f18 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
@@ -989,6 +989,9 @@ public abstract class CompEditorModel extends CompositeEditorModel {
insertComponentMultiple(rowIndex + 1, dt, dtLen, multiple, monitor);
+ // Adjust the selection since we added some components. Select last component added.
+ setSelection(new int[] { rowIndex + multiple });
+
componentEdited();
lastNumDuplicates = multiple;
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java
index ed452f8d53..df423b09bc 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java
@@ -581,7 +581,9 @@ public abstract class CompositeEditorPanel extends JPanel
return;
}
model.setSelection(table.getSelectedRows());
-
+ if (table.getAutoscrolls()) {
+ table.scrollToSelectedRow();
+ }
});
table.getColumnModel().getSelectionModel().addListSelectionListener(e -> {
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 549eae7cda..b99eafd8e8 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
@@ -381,7 +381,10 @@ class StructureEditorModel extends CompEditorModel {
}
insertComponentMultiple(startIndex, dt, originalComp.getLength(), multiple, monitor);
- // Adjust the selection since we added some
+ // Adjust the selection since we added some components. Select last component added.
+ // Ensure that last added component is selected to allow for repeated duplication
+ setSelection(new int[] { index + multiple });
+
componentEdited();
lastNumDuplicates = multiple;
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
index 6d19c55eb8..ba00456f84 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
@@ -220,7 +220,7 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
invoke(duplicateAction);
assertEquals(num - 1, getModel().getNumComponents());
assertEquals(len, getModel().getLength());
- checkSelection(new int[] { 2 });
+ checkSelection(new int[] { 3 });
assertEquals(getDataType(2), dt2);
assertEquals(getDataType(3), dt2);
assertEquals(getDataType(4), dt3);
@@ -255,7 +255,7 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
waitForBusyTool(tool); // the 'Duplicate Multiple' action uses a task
assertEquals(num - 2, getModel().getNumComponents());
- checkSelection(new int[] { 2 });
+ checkSelection(new int[] { 4 });
assertEquals(getDataType(2), dt2);
assertEquals(getDataType(3), dt2);
assertEquals(getDataType(4), dt2);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions3Test.java
index 82fa2c4e00..f87636a857 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions3Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions3Test.java
@@ -52,7 +52,7 @@ public class StructureEditorUnlockedActions3Test
waitUntilDialogProviderGone(NumberInputDialog.class, 2000);
assertEquals(num - 2, model.getNumComponents());
- checkSelection(new int[] { 2 });
+ checkSelection(new int[] { 4 });
assertEquals(getDataType(2), dt2);
assertEquals(getDataType(3), dt2);
assertEquals(getDataType(4), dt2);
@@ -83,7 +83,7 @@ public class StructureEditorUnlockedActions3Test
num += 2;
assertEquals(num, model.getNumComponents());
- checkSelection(new int[] { 1 });
+ checkSelection(new int[] { 3 });
assertEquals(getDataType(0), dt0);
assertEquals(getDataType(1), dt1);
assertEquals(getDataType(2), dt1);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
index 7532cbb2b1..d939d73938 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
@@ -119,7 +119,7 @@ public class StructureEditorUnlockedActions4Test
invoke(duplicateAction);
assertEquals(num, model.getNumComponents());
assertEquals(len, model.getLength());
- checkSelection(new int[] { 1 });
+ checkSelection(new int[] { 2 });
assertEquals(getDataType(1), dt1);
assertEquals(getDataType(2), dt1);
assertEquals(getDataType(3), dt2);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
index 4c188b6d3c..10458306be 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
@@ -569,7 +569,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
num++;
assertEquals(num, model.getNumComponents());
assertEquals(len, model.getLength());
- checkSelection(new int[] { 0 });
+ checkSelection(new int[] { 1 });
assertEquals(getDataType(0), dt0);
assertEquals(getDataType(1), dt0);
assertEquals(getDataType(2), dt1);
@@ -582,7 +582,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
num++;
assertEquals(num, model.getNumComponents());
assertEquals(len, model.getLength());
- checkSelection(new int[] { 6 });
+ checkSelection(new int[] { 7 });
assertEquals(getDataType(6), dt0);
assertEquals(getDataType(7), dt0);
assertEquals(getDataType(8), dt1);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions4Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions4Test.java
index 5af5f6707d..7bcf8eade7 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions4Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions4Test.java
@@ -68,7 +68,7 @@ public class UnionEditorActions4Test extends AbstractUnionEditorTest {
num += 5;
assertEquals(num, model.getNumComponents());
- checkSelection(new int[] { 2 });
+ checkSelection(new int[] { 7 });
assertEquals(getDataType(2), dt2);
assertEquals(getDataType(3), dt2);
assertEquals(getDataType(4), dt2);