Ghidra is a software reverse engineering (SRE) framework
Preserve PDB enum underlying widths and signed values
Rudy Celekli196f0378ca06
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/EnumTypeApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/EnumTypeApplier.javaindex ec0d3de804..98d7d2ded3 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/EnumTypeApplier.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/EnumTypeApplier.java@@ -69,6 +69,9 @@ public class EnumTypeApplier extends AbstractComplexTypeApplier {if (underlyingType == null) {return false;}+ if (underlyingType instanceof TypeDef typedef) {+ underlyingType = typedef.getBaseDataType();+ }if (underlyingType instanceof AbstractIntegerDataType) {return ((AbstractIntegerDataType) underlyingType).isSigned();}@@ -96,7 +99,10 @@ public class EnumTypeApplier extends AbstractComplexTypeApplier {AbstractEnumMsType definedEnum =(AbstractEnumMsType) applicator.getMappedTypeRecord(type.getRecordNumber());- // Note that we do not need to check on underlying data types, as there are none.+ // The primitive underlying type may not have been processed by another record.+ if (applicator.getDataTypeOrSchedule(definedEnum.getUnderlyingRecordNumber()) == null) {+ return false;+ }EnumDataType enumDataType = createEmptyEnum(definedEnum);applyEnumMsType(enumDataType, definedEnum);@@ -160,7 +166,12 @@ public class EnumTypeApplier extends AbstractComplexTypeApplier {pdbLogAndInfoMessage(this, "Using zero in place of non-integral enumerate: " + numeric);return 0L; //}- return numeric.getIntegral().longValue() & getMask(type);+ long value = numeric.getIntegral().longValue() & getMask(type);+ if (outputSigned && outputSize < Long.BYTES) {+ int shift = Long.SIZE - outputSize * Byte.SIZE;+ value = (value << shift) >> shift;+ }+ return value;}private AbstractEnumMsType getDefinitionType(AbstractComplexMsType type) {