GP-1261 Improved listing interior selection behavior and associated

clearing of components
This commit is contained in:
ghidra1 2021-08-27 16:21:22 -04:00
parent 9593f16585
commit a41f85c4e4
3 changed files with 23 additions and 36 deletions

View file

@ -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
// /////////////////////////////////////////////////////////////////////

View file

@ -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;
}

View file

@ -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);