diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clear/ClearPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clear/ClearPlugin.java index 193e6bcf2a..97fba29664 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clear/ClearPlugin.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/clear/ClearPlugin.java @@ -154,28 +154,24 @@ public class ClearPlugin extends Plugin { return false; } - // don't allow clearing the last component from a union - if (dataType instanceof Union && ((Composite) dataType).getNumComponents() <= 1) { - return false; - } - // get the start offset into the data structure int index = compData.getComponentIndex(); + int endIndex = index; + if (end != null) { + // assume start and end relate to ths same composite + int[] cpath = end.getComponentPath(); + endIndex = cpath[cpath.length - 1]; + } + if (dataType instanceof Union) { - ((Union) dataType).delete(index); + Union union = (Union) dataType; + for (int ordinal = endIndex; ordinal >= 0 && ordinal >= index; ordinal--) { + union.delete(ordinal); + } } else { - // now clear it - Address startAddress = start.getByteAddress(); - Address endAddress = (end != null) ? end.getByteAddress() : startAddress; - Data parent = compData.getParent(); - Address parentAddress = parent.getAddress(); - int startOffset = (int) startAddress.subtract(parentAddress); - int endOffset = (int) endAddress.subtract(parentAddress); Structure structure = (Structure) dataType; - int startOrdinal = getOrdinalAtOrBefore(structure, startOffset); - int endOrdinal = getOrdinalAtOrBefore(structure, endOffset); - for (int ordinal = endOrdinal; ordinal >= 0 && ordinal >= startOrdinal; ordinal--) { + for (int ordinal = endIndex; ordinal >= 0 && ordinal >= index; ordinal--) { structure.clearComponent(ordinal); } } @@ -190,18 +186,6 @@ public class ClearPlugin extends Plugin { return commit; } - private int getOrdinalAtOrBefore(Structure structure, int offset) { - DataTypeComponent component = structure.getComponentAt(offset); - for (int adjustedOffset = offset; component == null && - adjustedOffset >= 0; adjustedOffset--) { - component = structure.getComponentAt(offset); - } - if (component == null) { - return -1; - } - return component.getOrdinal(); - } - // ///////////////////////////////////////////////////////////////////// // ** private methods // ///////////////////////////////////////////////////////////////////// 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.java index 470a3d792a..dad3ae52e6 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 @@ -1059,14 +1059,18 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc if (layout != null) { fieldNum1 = layout.getBeginRowFieldNum(loc1.getFieldNum()); } + Layout layout2 = layoutModel.getLayout(loc2.getIndex()); - BigInteger index2 = null; - if (layout2 != null) { - index2 = loc2.getIndex().add(BigInteger.valueOf(layout2.getIndexSize())); - } - if (fieldNum1 >= 0 && index2 != null) { + + if (fieldNum1 >= 0 && layout2 != null) { + BigInteger index2 = loc2.getIndex(); + int fieldNum2 = layout.getEndRowFieldNum(loc2.getFieldNum()); + if (fieldNum2 >= layout2.getNumFields()) { + index2 = loc2.getIndex().add(BigInteger.valueOf(layout2.getIndexSize())); + fieldNum2 = 0; + } fieldSel.addRange(new FieldLocation(loc1.getIndex(), fieldNum1, 0, 0), - new FieldLocation(index2, 0, 0, 0)); + new FieldLocation(index2, fieldNum2, 0, 0)); fieldPanel.setSelection(fieldSel); return; } diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/MixedLayoutBackgroundColorManager.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/MixedLayoutBackgroundColorManager.java index e731b30486..a1e56347af 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/MixedLayoutBackgroundColorManager.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/internal/MixedLayoutBackgroundColorManager.java @@ -1,6 +1,5 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +92,7 @@ public class MixedLayoutBackgroundColorManager implements LayoutBackgroundColorM private Color getPaddingColorBetweenFields(int padIndex) { FieldLocation start = new FieldLocation(index, padIndex-1,Integer.MAX_VALUE,Integer.MAX_VALUE); - FieldLocation end = new FieldLocation(index, padIndex, 0, 1); + FieldLocation end = new FieldLocation(index, padIndex, 0, 0); FieldRange range = new FieldRange(start, end); boolean gapSelected = selection.containsEntirely(range); boolean gapHighlighted = highlight.containsEntirely(range);