mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-31 18:01:40 +08:00
GP-1261 Improved listing interior selection behavior and associated
clearing of components
This commit is contained in:
@@ -154,28 +154,24 @@ public class ClearPlugin extends Plugin {
|
|||||||
return false;
|
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
|
// get the start offset into the data structure
|
||||||
int index = compData.getComponentIndex();
|
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) {
|
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 {
|
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;
|
Structure structure = (Structure) dataType;
|
||||||
int startOrdinal = getOrdinalAtOrBefore(structure, startOffset);
|
for (int ordinal = endIndex; ordinal >= 0 && ordinal >= index; ordinal--) {
|
||||||
int endOrdinal = getOrdinalAtOrBefore(structure, endOffset);
|
|
||||||
for (int ordinal = endOrdinal; ordinal >= 0 && ordinal >= startOrdinal; ordinal--) {
|
|
||||||
structure.clearComponent(ordinal);
|
structure.clearComponent(ordinal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,18 +186,6 @@ public class ClearPlugin extends Plugin {
|
|||||||
return commit;
|
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
|
// ** private methods
|
||||||
// /////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+10
-6
@@ -1059,14 +1059,18 @@ public class ListingPanel extends JPanel implements FieldMouseListener, FieldLoc
|
|||||||
if (layout != null) {
|
if (layout != null) {
|
||||||
fieldNum1 = layout.getBeginRowFieldNum(loc1.getFieldNum());
|
fieldNum1 = layout.getBeginRowFieldNum(loc1.getFieldNum());
|
||||||
}
|
}
|
||||||
|
|
||||||
Layout layout2 = layoutModel.getLayout(loc2.getIndex());
|
Layout layout2 = layoutModel.getLayout(loc2.getIndex());
|
||||||
BigInteger index2 = null;
|
|
||||||
if (layout2 != null) {
|
if (fieldNum1 >= 0 && layout2 != null) {
|
||||||
index2 = loc2.getIndex().add(BigInteger.valueOf(layout2.getIndexSize()));
|
BigInteger index2 = loc2.getIndex();
|
||||||
}
|
int fieldNum2 = layout.getEndRowFieldNum(loc2.getFieldNum());
|
||||||
if (fieldNum1 >= 0 && index2 != null) {
|
if (fieldNum2 >= layout2.getNumFields()) {
|
||||||
|
index2 = loc2.getIndex().add(BigInteger.valueOf(layout2.getIndexSize()));
|
||||||
|
fieldNum2 = 0;
|
||||||
|
}
|
||||||
fieldSel.addRange(new FieldLocation(loc1.getIndex(), fieldNum1, 0, 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);
|
fieldPanel.setSelection(fieldSel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
/* ###
|
/* ###
|
||||||
* IP: GHIDRA
|
* IP: GHIDRA
|
||||||
* REVIEWED: YES
|
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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) {
|
private Color getPaddingColorBetweenFields(int padIndex) {
|
||||||
FieldLocation start = new FieldLocation(index, padIndex-1,Integer.MAX_VALUE,Integer.MAX_VALUE);
|
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);
|
FieldRange range = new FieldRange(start, end);
|
||||||
boolean gapSelected = selection.containsEntirely(range);
|
boolean gapSelected = selection.containsEntirely(range);
|
||||||
boolean gapHighlighted = highlight.containsEntirely(range);
|
boolean gapHighlighted = highlight.containsEntirely(range);
|
||||||
|
|||||||
Reference in New Issue
Block a user