mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
BitFields - improved unaligned structure edit behavior
This commit is contained in:
parent
31163bca26
commit
d4ea232a4d
5 changed files with 121 additions and 43 deletions
|
@ -255,7 +255,17 @@ public class BitFieldPlacementComponent extends JPanel {
|
|||
CompositeChangeListener listener) {
|
||||
HashSet<Integer> ordinalDeleteSet = new HashSet<>();
|
||||
if (editOrdinal >= 0) {
|
||||
int initialLength = composite.getLength();
|
||||
|
||||
composite.delete(editOrdinal);
|
||||
|
||||
int sizeChange = initialLength - composite.getLength();
|
||||
if (!composite.isInternallyAligned() && editOrdinal < composite.getNumComponents()) {
|
||||
// deletions cause shift which is bad - pad with defaults
|
||||
for (int i = 0; i < sizeChange; i++) {
|
||||
composite.insert(editOrdinal, DataType.DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (deleteConflicts) {
|
||||
for (BitAttributes attrs : bitFieldAllocation.bitAttributes) {
|
||||
|
|
|
@ -1238,4 +1238,5 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
|
|||
protected boolean bitfieldsSupported() {
|
||||
return (viewComposite instanceof Structure) || (viewComposite instanceof Union);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,13 +23,12 @@ import javax.swing.KeyStroke;
|
|||
|
||||
import docking.ActionContext;
|
||||
import docking.action.KeyBindingData;
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.data.DataTypeInstance;
|
||||
import ghidra.program.model.data.*;
|
||||
import ghidra.util.exception.UsrException;
|
||||
import resources.ResourceManager;
|
||||
|
||||
/**
|
||||
* Action for use in the composite data type editor.
|
||||
* Action for use in the structure data type editor.
|
||||
* This action has help associated with it.
|
||||
*/
|
||||
public class InsertUndefinedAction extends CompositeEditorTableAction {
|
||||
|
@ -57,8 +56,10 @@ public class InsertUndefinedAction extends CompositeEditorTableAction {
|
|||
if (isContiguousSelection) {
|
||||
int index = model.getMinIndexSelected();
|
||||
if (index >= 0) {
|
||||
DataTypeInstance dti =
|
||||
DataTypeInstance.getDataTypeInstance(DataType.DEFAULT, 1);
|
||||
DataType undefinedDt =
|
||||
model.viewComposite.isInternallyAligned() ? Undefined1DataType.dataType
|
||||
: DataType.DEFAULT;
|
||||
DataTypeInstance dti = DataTypeInstance.getDataTypeInstance(undefinedDt, -1);
|
||||
model.insert(index, dti.getDataType(), dti.getLength());
|
||||
}
|
||||
}
|
||||
|
@ -71,13 +72,16 @@ public class InsertUndefinedAction extends CompositeEditorTableAction {
|
|||
|
||||
@Override
|
||||
public void adjustEnablement() {
|
||||
if (model.viewComposite == null) {
|
||||
return;
|
||||
boolean enabled = false;
|
||||
if (model.viewComposite instanceof Structure) {
|
||||
boolean isContiguousSelection = model.getSelection().getNumRanges() == 1;
|
||||
DataType undefinedDt =
|
||||
model.viewComposite.isInternallyAligned() ? Undefined1DataType.dataType
|
||||
: DataType.DEFAULT;
|
||||
enabled = isContiguousSelection &&
|
||||
model.isInsertAllowed(model.getMinIndexSelected(), undefinedDt);
|
||||
}
|
||||
boolean isContiguousSelection = model.getSelection().getNumRanges() == 1;
|
||||
|
||||
setEnabled(isContiguousSelection && model.isShowingUndefinedBytes() &&
|
||||
model.isInsertAllowed(model.getMinIndexSelected(), DataType.DEFAULT));
|
||||
setEnabled(enabled);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue