GP-5935: The IMAGE_RESOURCE_DIRECTORY_ENTRY data type is now correctly

defined as a structures instead of a union
This commit is contained in:
Ryan Kurtz 2025-08-18 13:06:24 -04:00
parent 465fba743b
commit 328042f00f

View file

@ -161,8 +161,7 @@ public class ResourceDirectoryEntry implements StructConverter {
} }
/** /**
* Returns true if the parent resource directory is named, * {@return true if the parent resource directory is named; false indicates an ID}
* false indicates an ID.
*/ */
public boolean isNameEntry() { public boolean isNameEntry() {
return isNameEntry; return isNameEntry;
@ -254,8 +253,14 @@ public class ResourceDirectoryEntry implements StructConverter {
@Override @Override
public DataType toDataType() throws DuplicateNameException, IOException { public DataType toDataType() throws DuplicateNameException, IOException {
StructureDataType nameStruct = new StructureDataType(NAME + "_" + "NameStruct", 0); StructureDataType nameStruct = new StructureDataType(NAME + "_" + "NameStruct", 0);
nameStruct.add(DWORD, "NameOffset", null); nameStruct.setPackingEnabled(true);
nameStruct.add(DWORD, "NameIsString", null); try {
nameStruct.addBitField(DWORD, 31, "NameOffset", null);
nameStruct.addBitField(DWORD, 1, "NameIsString", null);
}
catch (InvalidDataTypeException e) {
throw new IOException(e);
}
nameStruct.setCategoryPath(new CategoryPath("/PE")); nameStruct.setCategoryPath(new CategoryPath("/PE"));
UnionDataType union1 = new UnionDataType(NAME + "_" + "NameUnion"); UnionDataType union1 = new UnionDataType(NAME + "_" + "NameUnion");
@ -265,19 +270,25 @@ public class ResourceDirectoryEntry implements StructConverter {
union1.setCategoryPath(new CategoryPath("/PE")); union1.setCategoryPath(new CategoryPath("/PE"));
StructureDataType offsetStruct = new StructureDataType(NAME + "_" + "DirectoryStruct", 0); StructureDataType offsetStruct = new StructureDataType(NAME + "_" + "DirectoryStruct", 0);
offsetStruct.add(DWORD, "OffsetToDirectory", null); offsetStruct.setPackingEnabled(true);
offsetStruct.add(DWORD, "DataIsDirectory", null); try {
offsetStruct.addBitField(DWORD, 31, "OffsetToDirectory", null);
offsetStruct.addBitField(DWORD, 1, "DataIsDirectory", null);
}
catch (InvalidDataTypeException e) {
throw new IOException(e);
}
UnionDataType union2 = new UnionDataType(NAME + "_" + "DirectoryUnion"); UnionDataType union2 = new UnionDataType(NAME + "_" + "DirectoryUnion");
union2.add(DWORD, "OffsetToData", null); union2.add(DWORD, "OffsetToData", null);
union2.add(offsetStruct, offsetStruct.getName(), null); union2.add(offsetStruct, offsetStruct.getName(), null);
UnionDataType union3 = new UnionDataType(NAME); StructureDataType struct = new StructureDataType(NAME, 0);
union3.add(union1, "NameUnion", null); struct.add(union1, "NameUnion", null);
union3.add(union2, "DirectoryUnion", null); struct.add(union2, "DirectoryUnion", null);
union3.setCategoryPath(new CategoryPath("/PE")); struct.setCategoryPath(new CategoryPath("/PE"));
return union3; return struct;
} }
public boolean isValid() { public boolean isValid() {