mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19: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) {
|
private int[] convertRowsToOrdinals(int[] rows) {
|
||||||
int[] ordinals = new int[rows.length];
|
int[] ordinals = new int[rows.length];
|
||||||
DataTypeComponent[] definedComponents = ((Structure) viewComposite).getDefinedComponents();
|
DataTypeComponent[] definedComponents = viewComposite.getDefinedComponents();
|
||||||
for (int i = rows.length - 1; i >= 0; i--) {
|
for (int i = rows.length - 1; i >= 0; i--) {
|
||||||
ordinals[i] = definedComponents[rows[i]].getOrdinal();
|
ordinals[i] = definedComponents[rows[i]].getOrdinal();
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ class StructureEditorModel extends CompEditorModel {
|
||||||
if (isShowingUndefinedBytes()) {
|
if (isShowingUndefinedBytes()) {
|
||||||
return rowIndex;
|
return rowIndex;
|
||||||
}
|
}
|
||||||
DataTypeComponent[] definedComponents = ((Structure) viewComposite).getDefinedComponents();
|
DataTypeComponent[] definedComponents = viewComposite.getDefinedComponents();
|
||||||
return definedComponents[rowIndex].getOrdinal();
|
return definedComponents[rowIndex].getOrdinal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -860,7 +860,7 @@ class StructureEditorModel extends CompEditorModel {
|
||||||
return viewDTM.withTransaction("Insert Component", () -> {
|
return viewDTM.withTransaction("Insert Component", () -> {
|
||||||
DataTypeComponent dtc;
|
DataTypeComponent dtc;
|
||||||
if (isPackingEnabled() || !(dataType instanceof BitFieldDataType)) {
|
if (isPackingEnabled() || !(dataType instanceof BitFieldDataType)) {
|
||||||
dtc = ((Structure) viewComposite).insert(rowIndex, dataType, length, name,
|
dtc = viewComposite.insert(rowIndex, dataType, length, name,
|
||||||
comment);
|
comment);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -957,7 +957,8 @@ class StructureEditorModel extends CompEditorModel {
|
||||||
struct.growStructure(length - avail);
|
struct.growStructure(length - avail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ((Structure) viewComposite).replace(componentOrdinal, dataType, length, name, comment);
|
return ((Structure) viewComposite).replace(componentOrdinal, dataType, length,
|
||||||
|
name, comment);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return dtc;
|
return dtc;
|
||||||
|
@ -1266,8 +1267,9 @@ class StructureEditorModel extends CompEditorModel {
|
||||||
dialog.setStatusText("The name cannot match the external structure name.");
|
dialog.setStatusText("The name cannot match the external structure name.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DataTypeManager originalDTM = getOriginalDataTypeManager();
|
|
||||||
DataType conflictingDt = originalDTM.getDataType(getOriginalCategoryPath(), name);
|
DataTypeManager originalDtm = getOriginalDataTypeManager();
|
||||||
|
DataType conflictingDt = originalDtm.getDataType(getOriginalCategoryPath(), name);
|
||||||
if (conflictingDt != null) {
|
if (conflictingDt != null) {
|
||||||
dialog.setStatusText("A data type named \"" + name + "\" already exists.");
|
dialog.setStatusText("A data type named \"" + name + "\" already exists.");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -16,11 +16,14 @@
|
||||||
package ghidra.app.plugin.core.compositeeditor;
|
package ghidra.app.plugin.core.compositeeditor;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import javax.help.UnsupportedOperationException;
|
import javax.help.UnsupportedOperationException;
|
||||||
|
import javax.swing.table.TableColumn;
|
||||||
|
|
||||||
import docking.widgets.fieldpanel.support.FieldRange;
|
import docking.widgets.fieldpanel.support.FieldRange;
|
||||||
import docking.widgets.fieldpanel.support.FieldSelection;
|
import docking.widgets.fieldpanel.support.FieldSelection;
|
||||||
|
import docking.widgets.table.GTableHeaderRenderer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data union editor model for maintaining information about the edits being
|
* 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 DATATYPE = 2;
|
||||||
private static final int FIELDNAME = 3;
|
private static final int FIELDNAME = 3;
|
||||||
private static final int COMMENT = 4;
|
private static final int COMMENT = 4;
|
||||||
|
private static final int ORDINAL = 5;
|
||||||
|
|
||||||
|
private List<TableColumn> hiddenColumns;
|
||||||
|
|
||||||
UnionEditorModel(UnionEditorProvider provider, boolean showInHex) {
|
UnionEditorModel(UnionEditorProvider provider, boolean showInHex) {
|
||||||
super(provider);
|
super(provider);
|
||||||
|
@ -62,6 +68,12 @@ class UnionEditorModel extends CompEditorModel {
|
||||||
adjustOffsets();
|
adjustOffsets();
|
||||||
this.showHexNumbers = showInHex;
|
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
|
@Override
|
||||||
|
@ -69,6 +81,11 @@ class UnionEditorModel extends CompEditorModel {
|
||||||
return "Union";
|
return "Union";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<TableColumn> getHiddenColumns() {
|
||||||
|
return hiddenColumns;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOffsetColumn() {
|
public int getOffsetColumn() {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -99,6 +116,29 @@ class UnionEditorModel extends CompEditorModel {
|
||||||
return COMMENT;
|
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
|
* returns whether or not a particular component row and field in this
|
||||||
* structure is editable.
|
* structure is editable.
|
||||||
|
@ -381,7 +421,7 @@ class UnionEditorModel extends CompEditorModel {
|
||||||
checkIsAllowableDataType(dataType);
|
checkIsAllowableDataType(dataType);
|
||||||
try {
|
try {
|
||||||
DataTypeComponent dtc = viewDTM.withTransaction("Add Component",
|
DataTypeComponent dtc = viewDTM.withTransaction("Add Component",
|
||||||
() -> ((Union) viewComposite).insert(rowIndex, dataType, length, name, comment));
|
() -> viewComposite.insert(rowIndex, dataType, length, name, comment));
|
||||||
if (rowIndex <= currentEditRow) {
|
if (rowIndex <= currentEditRow) {
|
||||||
currentEditRow++;
|
currentEditRow++;
|
||||||
}
|
}
|
||||||
|
@ -418,8 +458,8 @@ class UnionEditorModel extends CompEditorModel {
|
||||||
try {
|
try {
|
||||||
boolean isSelected = selection.containsEntirely(BigInteger.valueOf(rowIndex));
|
boolean isSelected = selection.containsEntirely(BigInteger.valueOf(rowIndex));
|
||||||
DataTypeComponent dtc = viewDTM.withTransaction("Replace Component", () -> {
|
DataTypeComponent dtc = viewDTM.withTransaction("Replace Component", () -> {
|
||||||
((Union) viewComposite).delete(rowIndex);
|
viewComposite.delete(rowIndex);
|
||||||
return ((Union) viewComposite).insert(rowIndex, dataType, length, name, comment);
|
return viewComposite.insert(rowIndex, dataType, length, name, comment);
|
||||||
});
|
});
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
selection.addRange(rowIndex, rowIndex + 1);
|
selection.addRange(rowIndex, rowIndex + 1);
|
||||||
|
@ -487,7 +527,7 @@ class UnionEditorModel extends CompEditorModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void replaceOriginalComponents() {
|
public void replaceOriginalComponents() {
|
||||||
((Union) getOriginalComposite()).replaceWith(viewComposite);
|
getOriginalComposite().replaceWith(viewComposite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue