mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
BitFields - handle launch of bitfield editor via double click (unaligned
structure only)
This commit is contained in:
parent
0ca31967dd
commit
0a22915976
4 changed files with 38 additions and 7 deletions
|
@ -359,7 +359,7 @@ public class BitFieldEditorPanel extends JPanel {
|
||||||
long allocationSize = useCurrentAllocation ? (Long) allocSizeModel.getValue()
|
long allocationSize = useCurrentAllocation ? (Long) allocSizeModel.getValue()
|
||||||
: initialBaseDataType.getLength();
|
: initialBaseDataType.getLength();
|
||||||
placementComponent.initAdd((int) allocationSize, 1, bitOffset);
|
placementComponent.initAdd((int) allocationSize, 1, bitOffset);
|
||||||
initControls(null, initialBaseDataType);
|
initControls(null, initialBaseDataType, 1);
|
||||||
enableControls(true);
|
enableControls(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +397,8 @@ public class BitFieldEditorPanel extends JPanel {
|
||||||
// TODO: adjust offset and allocationSize if needed
|
// TODO: adjust offset and allocationSize if needed
|
||||||
placementComponent.setAllocationOffset(allocationOffset);
|
placementComponent.setAllocationOffset(allocationOffset);
|
||||||
placementComponent.init(allocationSize, bitfieldDtc);
|
placementComponent.init(allocationSize, bitfieldDtc);
|
||||||
initControls(initialFieldName, initialBaseDataType);
|
bitFieldAllocation = placementComponent.getBitFieldAllocation(); // get updated instance
|
||||||
|
initControls(initialFieldName, initialBaseDataType, bitFieldAllocation.getBitSize());
|
||||||
enableControls(bitfieldDtc != null);
|
enableControls(bitfieldDtc != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +406,8 @@ public class BitFieldEditorPanel extends JPanel {
|
||||||
placementComponent.componentDeleted(ordinal);
|
placementComponent.componentDeleted(ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initControls(String initialFieldName, DataType initialBaseDataType) {
|
private void initControls(String initialFieldName, DataType initialBaseDataType,
|
||||||
|
int initialBitSize) {
|
||||||
updating = true;
|
updating = true;
|
||||||
try {
|
try {
|
||||||
baseDataType = initialBaseDataType;
|
baseDataType = initialBaseDataType;
|
||||||
|
@ -416,7 +418,7 @@ public class BitFieldEditorPanel extends JPanel {
|
||||||
BitFieldAllocation bitFieldAllocation = placementComponent.getBitFieldAllocation();
|
BitFieldAllocation bitFieldAllocation = placementComponent.getBitFieldAllocation();
|
||||||
allocSizeModel.setValue((long) bitFieldAllocation.getAllocationByteSize());
|
allocSizeModel.setValue((long) bitFieldAllocation.getAllocationByteSize());
|
||||||
int allocBits = 8 * bitFieldAllocation.getAllocationByteSize();
|
int allocBits = 8 * bitFieldAllocation.getAllocationByteSize();
|
||||||
bitSizeModel.setValue(1L);
|
bitSizeModel.setValue((long) initialBitSize);
|
||||||
bitOffsetModel.setMaximum((long) allocBits - 1);
|
bitOffsetModel.setMaximum((long) allocBits - 1);
|
||||||
bitOffsetModel.setValue((long) bitFieldAllocation.getBitOffset());
|
bitOffsetModel.setValue((long) bitFieldAllocation.getBitOffset());
|
||||||
updateBitSizeModel();
|
updateBitSizeModel();
|
||||||
|
|
|
@ -446,8 +446,8 @@ public class BitFieldPlacementComponent extends JPanel {
|
||||||
class BitFieldAllocation {
|
class BitFieldAllocation {
|
||||||
|
|
||||||
private final int allocationByteSize;
|
private final int allocationByteSize;
|
||||||
private int bitSize;
|
private final int bitSize;
|
||||||
private int bitOffset;
|
private final int bitOffset;
|
||||||
private boolean hasConflict;
|
private boolean hasConflict;
|
||||||
|
|
||||||
// bit layout normalized to big-endian layout
|
// bit layout normalized to big-endian layout
|
||||||
|
|
|
@ -30,6 +30,7 @@ import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.table.*;
|
import javax.swing.table.*;
|
||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
|
|
||||||
|
import docking.DockingWindowManager;
|
||||||
import docking.action.DockingActionIf;
|
import docking.action.DockingActionIf;
|
||||||
import docking.actions.KeyBindingUtils;
|
import docking.actions.KeyBindingUtils;
|
||||||
import docking.dnd.*;
|
import docking.dnd.*;
|
||||||
|
@ -148,6 +149,29 @@ public abstract class CompositeEditorPanel extends JPanel
|
||||||
table.setDefaultRenderer(DataTypeInstance.class, dtiCellRenderer);
|
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() {
|
private void setupTableCellEditor() {
|
||||||
|
|
||||||
table.addPropertyChangeListener("tableCellEditor", evt -> {
|
table.addPropertyChangeListener("tableCellEditor", evt -> {
|
||||||
|
@ -161,7 +185,9 @@ public abstract class CompositeEditorPanel extends JPanel
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
int editingRow = table.getEditingRow();
|
int editingRow = table.getEditingRow();
|
||||||
int modelColumn = table.convertColumnIndexToModel(table.getEditingColumn());
|
int modelColumn = table.convertColumnIndexToModel(table.getEditingColumn());
|
||||||
|
if (!launchBitFieldEditor(modelColumn, editingRow)) {
|
||||||
model.beginEditingField(editingRow, modelColumn);
|
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
|
* 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
|
* to contain the bitfield and offset within the least significant byte containing the
|
||||||
* lsb of the bitfield.
|
* 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 {
|
public class BitFieldDataType extends AbstractDataType {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue