mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
Merge remote-tracking branch 'origin/GP-5485-dragonmacher-union-editor-ordinal-col' into patch
This commit is contained in:
commit
fa554361d5
2 changed files with 59 additions and 17 deletions
|
@ -309,7 +309,7 @@ class StructureEditorModel extends CompEditorModel {
|
|||
|
||||
private int[] convertRowsToOrdinals(int[] rows) {
|
||||
int[] ordinals = new int[rows.length];
|
||||
DataTypeComponent[] definedComponents = ((Structure) viewComposite).getDefinedComponents();
|
||||
DataTypeComponent[] definedComponents = viewComposite.getDefinedComponents();
|
||||
for (int i = rows.length - 1; i >= 0; i--) {
|
||||
ordinals[i] = definedComponents[rows[i]].getOrdinal();
|
||||
}
|
||||
|
@ -328,7 +328,7 @@ class StructureEditorModel extends CompEditorModel {
|
|||
if (isShowingUndefinedBytes()) {
|
||||
return rowIndex;
|
||||
}
|
||||
DataTypeComponent[] definedComponents = ((Structure) viewComposite).getDefinedComponents();
|
||||
DataTypeComponent[] definedComponents = viewComposite.getDefinedComponents();
|
||||
return definedComponents[rowIndex].getOrdinal();
|
||||
}
|
||||
|
||||
|
@ -860,7 +860,7 @@ class StructureEditorModel extends CompEditorModel {
|
|||
return viewDTM.withTransaction("Insert Component", () -> {
|
||||
DataTypeComponent dtc;
|
||||
if (isPackingEnabled() || !(dataType instanceof BitFieldDataType)) {
|
||||
dtc = ((Structure) viewComposite).insert(rowIndex, dataType, length, name,
|
||||
dtc = viewComposite.insert(rowIndex, dataType, length, name,
|
||||
comment);
|
||||
}
|
||||
else {
|
||||
|
@ -957,7 +957,8 @@ class StructureEditorModel extends CompEditorModel {
|
|||
struct.growStructure(length - avail);
|
||||
}
|
||||
}
|
||||
return ((Structure) viewComposite).replace(componentOrdinal, dataType, length, name, comment);
|
||||
return ((Structure) viewComposite).replace(componentOrdinal, dataType, length,
|
||||
name, comment);
|
||||
});
|
||||
}
|
||||
return dtc;
|
||||
|
@ -1266,8 +1267,9 @@ class StructureEditorModel extends CompEditorModel {
|
|||
dialog.setStatusText("The name cannot match the external structure name.");
|
||||
return false;
|
||||
}
|
||||
DataTypeManager originalDTM = getOriginalDataTypeManager();
|
||||
DataType conflictingDt = originalDTM.getDataType(getOriginalCategoryPath(), name);
|
||||
|
||||
DataTypeManager originalDtm = getOriginalDataTypeManager();
|
||||
DataType conflictingDt = originalDtm.getDataType(getOriginalCategoryPath(), name);
|
||||
if (conflictingDt != null) {
|
||||
dialog.setStatusText("A data type named \"" + name + "\" already exists.");
|
||||
return false;
|
||||
|
|
|
@ -16,11 +16,14 @@
|
|||
package ghidra.app.plugin.core.compositeeditor;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
import javax.help.UnsupportedOperationException;
|
||||
import javax.swing.table.TableColumn;
|
||||
|
||||
import docking.widgets.fieldpanel.support.FieldRange;
|
||||
import docking.widgets.fieldpanel.support.FieldSelection;
|
||||
import docking.widgets.table.GTableHeaderRenderer;
|
||||
|
||||
/**
|
||||
* Data union editor model for maintaining information about the edits being
|
||||
|
@ -53,6 +56,9 @@ class UnionEditorModel extends CompEditorModel {
|
|||
private static final int DATATYPE = 2;
|
||||
private static final int FIELDNAME = 3;
|
||||
private static final int COMMENT = 4;
|
||||
private static final int ORDINAL = 5;
|
||||
|
||||
private List<TableColumn> hiddenColumns;
|
||||
|
||||
UnionEditorModel(UnionEditorProvider provider, boolean showInHex) {
|
||||
super(provider);
|
||||
|
@ -62,6 +68,12 @@ class UnionEditorModel extends CompEditorModel {
|
|||
adjustOffsets();
|
||||
this.showHexNumbers = showInHex;
|
||||
|
||||
List<TableColumn> additionalColumns = new ArrayList<>();
|
||||
TableColumn ordinalColumn = new TableColumn(ORDINAL, 75);
|
||||
ordinalColumn.setHeaderRenderer(new GTableHeaderRenderer());
|
||||
ordinalColumn.setHeaderValue("Ordinal");
|
||||
additionalColumns.add(ordinalColumn);
|
||||
hiddenColumns = Collections.unmodifiableList(additionalColumns);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,6 +81,11 @@ class UnionEditorModel extends CompEditorModel {
|
|||
return "Union";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TableColumn> getHiddenColumns() {
|
||||
return hiddenColumns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOffsetColumn() {
|
||||
return -1;
|
||||
|
@ -99,6 +116,29 @@ class UnionEditorModel extends CompEditorModel {
|
|||
return COMMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
|
||||
if ((viewComposite == null) || (rowIndex < 0) || (columnIndex < 0)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
DataTypeComponent dtc = getComponent(rowIndex);
|
||||
if (dtc == null) {
|
||||
if (columnIndex == getDataTypeColumn()) {
|
||||
return null;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
if (columnIndex == ORDINAL) {
|
||||
int ordinal = dtc.getOrdinal();
|
||||
return showHexNumbers ? getHexString(ordinal, true) : Integer.toString(ordinal);
|
||||
}
|
||||
|
||||
return super.getValueAt(rowIndex, columnIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns whether or not a particular component row and field in this
|
||||
* structure is editable.
|
||||
|
@ -381,7 +421,7 @@ class UnionEditorModel extends CompEditorModel {
|
|||
checkIsAllowableDataType(dataType);
|
||||
try {
|
||||
DataTypeComponent dtc = viewDTM.withTransaction("Add Component",
|
||||
() -> ((Union) viewComposite).insert(rowIndex, dataType, length, name, comment));
|
||||
() -> viewComposite.insert(rowIndex, dataType, length, name, comment));
|
||||
if (rowIndex <= currentEditRow) {
|
||||
currentEditRow++;
|
||||
}
|
||||
|
@ -418,8 +458,8 @@ class UnionEditorModel extends CompEditorModel {
|
|||
try {
|
||||
boolean isSelected = selection.containsEntirely(BigInteger.valueOf(rowIndex));
|
||||
DataTypeComponent dtc = viewDTM.withTransaction("Replace Component", () -> {
|
||||
((Union) viewComposite).delete(rowIndex);
|
||||
return ((Union) viewComposite).insert(rowIndex, dataType, length, name, comment);
|
||||
viewComposite.delete(rowIndex);
|
||||
return viewComposite.insert(rowIndex, dataType, length, name, comment);
|
||||
});
|
||||
if (isSelected) {
|
||||
selection.addRange(rowIndex, rowIndex + 1);
|
||||
|
@ -487,7 +527,7 @@ class UnionEditorModel extends CompEditorModel {
|
|||
|
||||
@Override
|
||||
public void replaceOriginalComponents() {
|
||||
((Union) getOriginalComposite()).replaceWith(viewComposite);
|
||||
getOriginalComposite().replaceWith(viewComposite);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue