mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 01:39:21 +02:00
GP-943 Added support for zero-length arrays and
zero-length components. NOTE: We still never return 0 for DataType.getLength(). Added DataType.isZeroLength().
This commit is contained in:
parent
579e3bacf7
commit
cfdec26da4
188 changed files with 7968 additions and 6645 deletions
|
@ -241,7 +241,7 @@ public class TypeDescriptorModel extends AbstractCreateDataTypeModel {
|
|||
// included in the length of the structure and must have a properly sized char array
|
||||
// created immediately following the structure in memory.
|
||||
|
||||
struct.setFlexibleArrayComponent(CharDataType.dataType, "name", null);
|
||||
struct.add(new ArrayDataType(CharDataType.dataType, 0, -1), "name", null);
|
||||
|
||||
return MSDataTypeUtils.getMatchingDataType(program, struct);
|
||||
}
|
||||
|
@ -281,8 +281,7 @@ public class TypeDescriptorModel extends AbstractCreateDataTypeModel {
|
|||
@Override
|
||||
protected int getDataTypeLength() {
|
||||
Structure struct = (Structure) getDataType();
|
||||
DataTypeComponent nameComponent = struct.getFlexibleArrayComponent();
|
||||
int preNameLength = nameComponent.getOffset();
|
||||
int preNameLength = struct.getLength();
|
||||
int totalLength = preNameLength;
|
||||
// Add the length of the name string too if we can get it.
|
||||
Address nameAddress = getAddress().add(preNameLength);
|
||||
|
|
|
@ -384,24 +384,24 @@ public class AbstractCreateDataTypeModelTest extends AbstractGenericTest {
|
|||
|
||||
protected void CheckTypeDefOnStructureData(ProgramDB program, long address, String expectedName,
|
||||
String[] expectedFieldNames, int expectedDtLength) {
|
||||
CheckStructureData(program, address, expectedName, expectedFieldNames, null,
|
||||
CheckStructureData(program, address, expectedName, expectedFieldNames, false,
|
||||
expectedDtLength, true);
|
||||
}
|
||||
|
||||
protected void CheckStructureData(ProgramDB program, long address, String expectedName,
|
||||
String[] expectedFieldNames, int expectedDtLength) {
|
||||
CheckStructureData(program, address, expectedName, expectedFieldNames, null,
|
||||
CheckStructureData(program, address, expectedName, expectedFieldNames, false,
|
||||
expectedDtLength, false);
|
||||
}
|
||||
|
||||
protected void CheckStructureData(ProgramDB program, long address, String expectedName,
|
||||
String[] expectedFieldNames, String flexArrayName, int expectedDtLength) {
|
||||
CheckStructureData(program, address, expectedName, expectedFieldNames, flexArrayName,
|
||||
String[] expectedFieldNames, boolean lastFieldIsFlexArray, int expectedDtLength) {
|
||||
CheckStructureData(program, address, expectedName, expectedFieldNames, lastFieldIsFlexArray,
|
||||
expectedDtLength, false);
|
||||
}
|
||||
|
||||
protected void CheckStructureData(ProgramDB program, long address, String expectedName,
|
||||
String[] expectedFieldNames, String flexArrayName, int expectedDtLength,
|
||||
String[] expectedFieldNames, boolean lastFieldIsFlexArray, int expectedDtLength,
|
||||
boolean isTypeDefOfStructure) {
|
||||
Listing listing = program.getListing();
|
||||
Data data = listing.getDataAt(addr(program, address));
|
||||
|
@ -421,24 +421,22 @@ public class AbstractCreateDataTypeModelTest extends AbstractGenericTest {
|
|||
assertEquals("Mismatch in expected structure component count: " + name,
|
||||
expectedFieldNames.length, structure.getNumComponents());
|
||||
DataTypeComponent[] components = structure.getComponents();
|
||||
boolean hasTrailingFlexArray = false;
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
assertEquals(
|
||||
"Expected component " + i + " to be named " + expectedFieldNames[i] + " but was " +
|
||||
components[i].getFieldName(),
|
||||
expectedFieldNames[i], components[i].getFieldName());
|
||||
DataType dt = components[i].getDataType();
|
||||
hasTrailingFlexArray = (dt instanceof Array) && dt.isZeroLength();
|
||||
}
|
||||
if (flexArrayName != null) {
|
||||
DataTypeComponent flexibleArrayComponent = structure.getFlexibleArrayComponent();
|
||||
assertNotNull("Structure does not contain flexible array: " + name,
|
||||
flexibleArrayComponent);
|
||||
assertEquals(
|
||||
"Expected flexible array named " + flexArrayName + " but was " +
|
||||
flexibleArrayComponent.getFieldName(),
|
||||
flexArrayName, flexibleArrayComponent.getFieldName());
|
||||
|
||||
if (lastFieldIsFlexArray) {
|
||||
assertTrue("Structure does not end with flexible array", hasTrailingFlexArray);
|
||||
}
|
||||
else {
|
||||
assertFalse("Structure contains unexpected flexible array component: " + name,
|
||||
structure.hasFlexibleArrayComponent());
|
||||
assertFalse("Structure contains unexpected flexible array component",
|
||||
hasTrailingFlexArray);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -493,8 +491,9 @@ public class AbstractCreateDataTypeModelTest extends AbstractGenericTest {
|
|||
|
||||
protected void checkTypeDescriptorData(ProgramDB program, long address, int structLength,
|
||||
int nameArrayLength, String expectedTypeName) {
|
||||
CheckStructureData(program, address, "TypeDescriptor", new String[] { "pVFTable", "spare" },
|
||||
"name", structLength);
|
||||
CheckStructureData(program, address, "TypeDescriptor",
|
||||
new String[] { "pVFTable", "spare", "name" },
|
||||
true, structLength);
|
||||
checkTypeName(program, address, expectedTypeName);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue