mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-25 13:42:06 +00:00
BitFields - handle launch of bitfield editor via double click (unaligned
structure only)
This commit is contained in:
parent
0ca31967dd
commit
0a22915976
@ -359,7 +359,7 @@ public class BitFieldEditorPanel extends JPanel {
|
||||
long allocationSize = useCurrentAllocation ? (Long) allocSizeModel.getValue()
|
||||
: initialBaseDataType.getLength();
|
||||
placementComponent.initAdd((int) allocationSize, 1, bitOffset);
|
||||
initControls(null, initialBaseDataType);
|
||||
initControls(null, initialBaseDataType, 1);
|
||||
enableControls(true);
|
||||
}
|
||||
|
||||
@ -397,7 +397,8 @@ public class BitFieldEditorPanel extends JPanel {
|
||||
// TODO: adjust offset and allocationSize if needed
|
||||
placementComponent.setAllocationOffset(allocationOffset);
|
||||
placementComponent.init(allocationSize, bitfieldDtc);
|
||||
initControls(initialFieldName, initialBaseDataType);
|
||||
bitFieldAllocation = placementComponent.getBitFieldAllocation(); // get updated instance
|
||||
initControls(initialFieldName, initialBaseDataType, bitFieldAllocation.getBitSize());
|
||||
enableControls(bitfieldDtc != null);
|
||||
}
|
||||
|
||||
@ -405,7 +406,8 @@ public class BitFieldEditorPanel extends JPanel {
|
||||
placementComponent.componentDeleted(ordinal);
|
||||
}
|
||||
|
||||
private void initControls(String initialFieldName, DataType initialBaseDataType) {
|
||||
private void initControls(String initialFieldName, DataType initialBaseDataType,
|
||||
int initialBitSize) {
|
||||
updating = true;
|
||||
try {
|
||||
baseDataType = initialBaseDataType;
|
||||
@ -416,7 +418,7 @@ public class BitFieldEditorPanel extends JPanel {
|
||||
BitFieldAllocation bitFieldAllocation = placementComponent.getBitFieldAllocation();
|
||||
allocSizeModel.setValue((long) bitFieldAllocation.getAllocationByteSize());
|
||||
int allocBits = 8 * bitFieldAllocation.getAllocationByteSize();
|
||||
bitSizeModel.setValue(1L);
|
||||
bitSizeModel.setValue((long) initialBitSize);
|
||||
bitOffsetModel.setMaximum((long) allocBits - 1);
|
||||
bitOffsetModel.setValue((long) bitFieldAllocation.getBitOffset());
|
||||
updateBitSizeModel();
|
||||
|
@ -446,8 +446,8 @@ public class BitFieldPlacementComponent extends JPanel {
|
||||
class BitFieldAllocation {
|
||||
|
||||
private final int allocationByteSize;
|
||||
private int bitSize;
|
||||
private int bitOffset;
|
||||
private final int bitSize;
|
||||
private final int bitOffset;
|
||||
private boolean hasConflict;
|
||||
|
||||
// bit layout normalized to big-endian layout
|
||||
|
@ -30,6 +30,7 @@ import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.table.*;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import docking.DockingWindowManager;
|
||||
import docking.action.DockingActionIf;
|
||||
import docking.actions.KeyBindingUtils;
|
||||
import docking.dnd.*;
|
||||
@ -148,6 +149,29 @@ public abstract class CompositeEditorPanel extends JPanel
|
||||
table.setDefaultRenderer(DataTypeInstance.class, dtiCellRenderer);
|
||||
}
|
||||
|
||||
private boolean launchBitFieldEditor(int modelColumn, int editingRow) {
|
||||
if (model.viewComposite instanceof Structure &&
|
||||
!model.viewComposite.isInternallyAligned() &&
|
||||
model.getDataTypeColumn() == modelColumn && editingRow < model.getNumComponents()) {
|
||||
// check if we are attempting to edit a bitfield
|
||||
DataTypeComponent dtComponent = model.getComponent(editingRow);
|
||||
if (dtComponent.isBitFieldComponent()) {
|
||||
table.getCellEditor().cancelCellEditing();
|
||||
|
||||
BitFieldEditorDialog dlg = new BitFieldEditorDialog(model.viewComposite,
|
||||
provider.dtmService, editingRow, ordinal -> {
|
||||
model.fireTableDataChanged();
|
||||
model.compositeInfoChanged();
|
||||
});
|
||||
Component c = provider.getComponent();
|
||||
Window w = SwingUtilities.windowForComponent(c);
|
||||
DockingWindowManager.showDialog(w, dlg, c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setupTableCellEditor() {
|
||||
|
||||
table.addPropertyChangeListener("tableCellEditor", evt -> {
|
||||
@ -161,7 +185,9 @@ public abstract class CompositeEditorPanel extends JPanel
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
int editingRow = table.getEditingRow();
|
||||
int modelColumn = table.convertColumnIndexToModel(table.getEditingColumn());
|
||||
model.beginEditingField(editingRow, modelColumn);
|
||||
if (!launchBitFieldEditor(modelColumn, editingRow)) {
|
||||
model.beginEditingField(editingRow, modelColumn);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -29,6 +29,9 @@ import ghidra.util.exception.AssertException;
|
||||
* less than or equal to the base datatype size and will always be the smallest possible size
|
||||
* to contain the bitfield and offset within the least significant byte containing the
|
||||
* lsb of the bitfield.
|
||||
* <p>
|
||||
* NOTE: This datatype implementation is intended for internal use only. Creating bitfields
|
||||
* must be accomplished directly via a Structure or Union instance API method.
|
||||
*/
|
||||
public class BitFieldDataType extends AbstractDataType {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user