BitFields - corrections to structure editor actions and some packing

fixes
This commit is contained in:
ghidra1 2019-06-28 18:09:43 -04:00
parent 55238b0393
commit fab75940bd
18 changed files with 435 additions and 220 deletions

View file

@ -481,26 +481,7 @@ class StructureDB extends CompositeDB implements Structure {
if (isInternallyAligned()) {
return;
}
int shiftAmount = dtc.getLength();
if (dtc.isBitFieldComponent()) {
// Must handle potential overlap with adjacent components
// NOTE: existing bitfields will not overlap by more than one byte
int minOffset = dtc.getOffset();
int maxOffset = dtc.getEndOffset();
if (index > 0) {
DataTypeComponentDB previousDtc = components.get(index - 1);
if (previousDtc.getEndOffset() == dtc.getOffset()) {
++minOffset;
}
}
if (minOffset <= maxOffset && index < components.size()) {
DataTypeComponentDB nextDtc = components.get(index);
if (nextDtc.getOffset() == dtc.getOffset()) {
--maxOffset;
}
}
shiftAmount = maxOffset - minOffset + 1;
}
int shiftAmount = dtc.isBitFieldComponent() ? 0 : dtc.getLength();
shiftOffsets(index, -1, -shiftAmount);
}

View file

@ -274,28 +274,10 @@ public class AlignedStructurePacker {
updateComponent(lastComponent, ordinal, groupOffset, 1, minimumAlignment);
}
private boolean canPack(DataType dataType) {
if (dataType instanceof TypeDef) {
dataType = ((TypeDef) dataType).getBaseDataType();
}
if (dataType instanceof BitFieldDataType) {
return true;
}
if (dataType instanceof AbstractIntegerDataType) {
return true;
}
if (dataType instanceof Enum) {
return true;
}
return false;
}
private boolean packComponent(InternalDataTypeComponent dataTypeComponent) {
if (lastComponent == null || dataTypeComponent.isZeroBitFieldComponent() ||
!canPack(lastComponent.getDataType()) ||
!canPack(dataTypeComponent.getDataType())) {
return false; // can't pack incompatible types - start new group
if (lastComponent == null || dataTypeComponent.isZeroBitFieldComponent()) {
return false;
}
if (dataTypeComponent.isBitFieldComponent()) {

View file

@ -262,8 +262,8 @@ public interface Composite extends DataType {
/**
* Deletes the component at the given ordinal position.
* <BR>Note: For an aligned structure the delete will have no effect if the
* ordinal position is a component that provides alignment padding.
* <BR>Note: Removal of bitfields from an unaligned structure will
* not shift other components with vacated bytes reverting to undefined.
* @param ordinal the ordinal of the component to be deleted.
* @throws ArrayIndexOutOfBoundsException if component ordinal is out of bounds
*/
@ -271,9 +271,7 @@ public interface Composite extends DataType {
/**
* Deletes the components at the given ordinal positions.
* <BR>Note 1: For an aligned structure the delete will have no effect if the
* ordinal position is a component that provides alignment padding.
* <BR>Note 2: Removal of bitfields from an unaligned structure will
* <BR>Note: Removal of bitfields from an unaligned structure will
* not shift other components with vacated bytes reverting to undefined.
* @param ordinals the ordinals of the component to be deleted.
* @throws ArrayIndexOutOfBoundsException if any specified component ordinal is out of bounds

View file

@ -193,26 +193,7 @@ public class StructureDataType extends CompositeDataTypeImpl implements Structur
if (isInternallyAligned()) {
return;
}
int shiftAmount = dtc.getLength();
if (dtc.isBitFieldComponent()) {
// Must handle potential overlap with adjacent components
// NOTE: existing bitfields will not overlap by more than one byte
int minOffset = dtc.getOffset();
int maxOffset = dtc.getEndOffset();
if (index > 0) {
DataTypeComponentImpl previousDtc = components.get(index - 1);
if (previousDtc.getEndOffset() == dtc.getOffset()) {
++minOffset;
}
}
if (minOffset <= maxOffset && index < components.size()) {
DataTypeComponentImpl nextDtc = components.get(index);
if (nextDtc.getOffset() == dtc.getOffset()) {
--maxOffset;
}
}
shiftAmount = maxOffset - minOffset + 1;
}
int shiftAmount = dtc.isBitFieldComponent() ? 0 : dtc.getLength();
shiftOffsets(index, -1, -shiftAmount);
}