mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
GP-1261 Improved listing interior selection behavior and associated
clearing of components
This commit is contained in:
parent
9593f16585
commit
a41f85c4e4
3 changed files with 23 additions and 36 deletions
|
@ -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
|
||||
// /////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue