Ghidra is a software reverse engineering (SRE) framework
GP-4306 - PDB - cleanup some types pertaining to vftptrs and methods
ghizard1470713dbb12
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractFieldListMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractFieldListMsType.javaindex 8d774dbd18..03f02f3096 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractFieldListMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractFieldListMsType.java@@ -104,8 +104,9 @@ public abstract class AbstractFieldListMsType extends AbstractMsType {}/**- * Returns the (ordered?) {@link List}<{@link AbstractMsType}> of type members types of- * this field list.+ * Returns the (ordered?) {@link List}<{@link MsTypeField}> of type members types of+ * this field list. This is a hodge-podge of other types form the field list. This list+ * should generally not be used outside of this class* @return Field list.*/public List<MsTypeField> getMemberList() {@@ -113,7 +114,7 @@ public abstract class AbstractFieldListMsType extends AbstractMsType {}/**- * Returns the (ordered?) {@link List}<{@link AbstractMsType}> of other types. (We have+ * Returns the (ordered?) {@link List}<{@link MsTypeField}> of other types. (We have* separated these out, but are unsure about what they are at this time.)* @return List of other types.*/@@ -122,7 +123,7 @@ public abstract class AbstractFieldListMsType extends AbstractMsType {}/**- * Returns the (ordered?) {@link List}<{@link AbstractMsType}> of non-static members+ * Returns the (ordered?) {@link List}<{@link AbstractMemberMsType}> of non-static members* from this field list* @return non-static members*/@@ -131,8 +132,17 @@ public abstract class AbstractFieldListMsType extends AbstractMsType {}/**- * Returns the (ordered?) {@link List}<{@link AbstractMsType}> of VFT pointer records- * from this field list+ * Returns the (ordered?) {@link List}<{@link AbstractStaticMemberMsType}> of static+ * members from this field list+ * @return non-static members+ */+ public List<AbstractStaticMemberMsType> getStaticMembers() {+ return staticMemberList;+ }++ /**+ * Returns the (ordered?) {@link List}<{@link AbstractVirtualFunctionTablePointerMsType}>+ * of VFT pointer records from this field list* @return VFT pointer records*/public List<AbstractVirtualFunctionTablePointerMsType> getVftPointers() {@@ -140,9 +150,9 @@ public abstract class AbstractFieldListMsType extends AbstractMsType {}/**- * Returns the (ordered?) {@link List}<{@link AbstractNestedTypeMsType}> of enumerates- * from this field list- * @return enumerates+ * Returns the (ordered?) {@link List}<{@link AbstractNestedTypeMsType}> of nested+ * types from this field list+ * @return nested types*/public List<AbstractNestedTypeMsType> getNestedTypes() {return nestedTypeList;diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMethodRecordMs.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMethodRecordMs.javaindex 68459b5324..cc0273ede5 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMethodRecordMs.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMethodRecordMs.java@@ -43,6 +43,31 @@ public abstract class AbstractMethodRecordMs extends AbstractParsableItem {this.pdb = pdb;}+ /**+ * Returns the attributes of this procedure+ * @return the attributes+ */+ public ClassFieldMsAttributes getAttributes() {+ return attributes;+ }++ /**+ * Returns the record number of the data type (?) for this procedure+ * @return the record number+ */+ public RecordNumber getProcedureTypeRecordNumber() {+ return procedureRecordNumber;+ }++ /**+ * Returns the offset of the procedure in the VFTable if intro/virtual. Value of -1 means+ * there was not a value+ * @return the offset+ */+ public long getOptionalOffset() {+ return optionalOffset;+ }+@Overridepublic void emit(StringBuilder builder) {// Making this up; no API for output.diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOneMethodMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOneMethodMsType.javaindex 533fff5a88..af68e229fd 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOneMethodMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOneMethodMsType.java@@ -25,7 +25,7 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.*;*/public abstract class AbstractOneMethodMsType extends AbstractMsType implements MsTypeField {- protected ClassFieldMsAttributes attribute;+ protected ClassFieldMsAttributes attributes;protected RecordNumber procedureTypeRecordNumber;protected long offsetInVFTableIfIntroVirtual;protected String name;@@ -41,11 +41,11 @@ public abstract class AbstractOneMethodMsType extends AbstractMsType implementspublic AbstractOneMethodMsType(AbstractPdb pdb, PdbByteReader reader, int recordNumberSize,StringParseType strType) throws PdbException {super(pdb, reader);- attribute = new ClassFieldMsAttributes(reader);+ attributes = new ClassFieldMsAttributes(reader);procedureTypeRecordNumber =RecordNumber.parse(pdb, reader, RecordCategory.TYPE, recordNumberSize);- if ((attribute.getProperty() == ClassFieldMsAttributes.Property.INTRO) ||- (attribute.getProperty() == ClassFieldMsAttributes.Property.INTRO_PURE)) {+ if ((attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO) ||+ (attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO_PURE)) {offsetInVFTableIfIntroVirtual = reader.parseUnsignedIntVal();}else {@@ -55,12 +55,41 @@ public abstract class AbstractOneMethodMsType extends AbstractMsType implementsreader.skipPadding();}+ @Override+ public String getName() {+ return name;+ }++ /**+ * Returns the record number of the data type for this procedure+ * @return the record number+ */+ public RecordNumber getProcedureTypeRecordNumber() {+ return procedureTypeRecordNumber;+ }++ /**+ * Returns the attributes of this procedure+ * @return the attributes+ */+ public ClassFieldMsAttributes getAttributes() {+ return attributes;+ }++ /**+ * Returns the offset of the procedure in the VFTable if intro/virtual+ * @return the offset+ */+ public long getOffsetInVFTableIfIntroVirtual() {+ return offsetInVFTableIfIntroVirtual;+ }+@Overridepublic void emit(StringBuilder builder, Bind bind) {// No API for this. Just outputting something that might be useful.// At this time, not doing anything with bind here; don't think it is warranted.builder.append("<");- builder.append(attribute);+ builder.append(attributes);builder.append(": ");builder.append(pdb.getTypeRecord(procedureTypeRecordNumber));builder.append(",");diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOverloadedMethodMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOverloadedMethodMsType.javaindex 0e529740cd..fcfb689fe8 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOverloadedMethodMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOverloadedMethodMsType.java@@ -47,6 +47,27 @@ public abstract class AbstractOverloadedMethodMsType extends AbstractMsType impl}+ @Override+ public String getName() {+ return name;+ }++ /**+ * Returns the number of methods overloaded with the name+ * @return the number of methods+ */+ public int getCount() {+ return count;+ }++ /**+ * Returns the record number of the method list for this overloaded method name+ * @return the record number+ */+ public RecordNumber getTypeMethodListRecordNumber() {+ return methodListRecordNumber;+ }+@Overridepublic void emit(StringBuilder builder, Bind bind) {// No API for this. Just outputting something that might be useful.diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractStaticMemberMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractStaticMemberMsType.javaindex c24d967857..cdc5d0702c 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractStaticMemberMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractStaticMemberMsType.java@@ -25,7 +25,7 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.*;*/public abstract class AbstractStaticMemberMsType extends AbstractMsType implements MsTypeField {- protected ClassFieldMsAttributes attribute;+ protected ClassFieldMsAttributes attributes;protected RecordNumber fieldTypeRecordNumber;protected String name;@@ -43,13 +43,29 @@ public abstract class AbstractStaticMemberMsType extends AbstractMsType implemenreturn name;}+ /**+ * Returns the record number of the data type for this member+ * @return the record number+ */+ public RecordNumber getFieldTypeRecordNumber() {+ return fieldTypeRecordNumber;+ }++ /**+ * Returns the attributes of this procedure+ * @return the attributes+ */+ public ClassFieldMsAttributes getAttributes() {+ return attributes;+ }+@Overridepublic void emit(StringBuilder builder, Bind bind) {// No API for this.builder.append(name);pdb.getTypeRecord(fieldTypeRecordNumber).emit(builder, Bind.NONE);StringBuilder myBuilder = new StringBuilder();- myBuilder.append(attribute);+ myBuilder.append(attributes);myBuilder.append(": ");builder.insert(0, myBuilder);}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerMsType.javaindex 864d8c6b07..896a2239f8 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerMsType.java@@ -37,12 +37,6 @@ public abstract class AbstractVirtualFunctionTablePointerMsType extends Abstractsuper(pdb, reader);}- @Override- public void emit(StringBuilder builder, Bind bind) {- builder.append("VFTablePtr: ");- builder.append(pdb.getTypeRecord(pointerTypeRecordNumber));- }-/*** Returns the record number of the pointer type.* @return the record number of the pointer type.@@ -51,4 +45,18 @@ public abstract class AbstractVirtualFunctionTablePointerMsType extends Abstractreturn pointerTypeRecordNumber;}+ /**+ * Returns the pointer offset.+ * @return the offset.+ */+ public int getOffset() {+ return 0;+ }++ @Override+ public void emit(StringBuilder builder, Bind bind) {+ builder.append("VFTablePtr: ");+ builder.append(pdb.getTypeRecord(pointerTypeRecordNumber));+ }+}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerWithOffsetMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerWithOffsetMsType.javaindex 3713be0524..af77bdcf41 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerWithOffsetMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerWithOffsetMsType.java@@ -23,9 +23,9 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.*;* Note: we do not necessarily understand each of these data type classes. Refer to the* base class for more information.*/-public abstract class AbstractVirtualFunctionTablePointerWithOffsetMsType extends AbstractMsType {+public abstract class AbstractVirtualFunctionTablePointerWithOffsetMsType+ extends AbstractVirtualFunctionTablePointerMsType {- protected RecordNumber pointerTypeRecordNumber;protected int offset;/**@@ -45,18 +45,11 @@ public abstract class AbstractVirtualFunctionTablePointerWithOffsetMsType extendoffset = reader.parseInt();}- @Override- public void emit(StringBuilder builder, Bind bind) {- builder.append("VFTablePtr<off=");- builder.append(offset);- builder.append(">: ");- builder.append(pdb.getTypeRecord(pointerTypeRecordNumber));- }-/*** Returns the record number of the pointer type.* @return the record number of the pointer type.*/+ @Overridepublic RecordNumber getPointerTypeRecordNumber() {return pointerTypeRecordNumber;}@@ -65,8 +58,17 @@ public abstract class AbstractVirtualFunctionTablePointerWithOffsetMsType extend* Returns the pointer offset.* @return the offset.*/+ @Overridepublic int getOffset() {return offset;}+ @Override+ public void emit(StringBuilder builder, Bind bind) {+ builder.append("VFTablePtr<off=");+ builder.append(offset);+ builder.append(">: ");+ builder.append(pdb.getTypeRecord(pointerTypeRecordNumber));+ }+}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMember16MsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMember16MsType.javaindex afeae21249..5ecdfccbd0 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMember16MsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMember16MsType.java@@ -36,7 +36,7 @@ public class StaticMember16MsType extends AbstractStaticMemberMsType {public StaticMember16MsType(AbstractPdb pdb, PdbByteReader reader) throws PdbException {super(pdb, reader);fieldTypeRecordNumber = RecordNumber.parse(pdb, reader, RecordCategory.TYPE, 16);- attribute = new ClassFieldMsAttributes(reader);+ attributes = new ClassFieldMsAttributes(reader);name = reader.parseString(pdb, StringParseType.StringSt);reader.skipPadding();}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberMsType.javaindex 5f0ea5caf9..d62c6c7f8a 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberMsType.java@@ -35,7 +35,7 @@ public class StaticMemberMsType extends AbstractStaticMemberMsType {*/public StaticMemberMsType(AbstractPdb pdb, PdbByteReader reader) throws PdbException {super(pdb, reader);- attribute = new ClassFieldMsAttributes(reader);+ attributes = new ClassFieldMsAttributes(reader);fieldTypeRecordNumber = RecordNumber.parse(pdb, reader, RecordCategory.TYPE, 32);name = reader.parseString(pdb, StringParseType.StringNt);reader.align4();diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberStMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberStMsType.javaindex 1e0f3f138e..7a3328e778 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberStMsType.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberStMsType.java@@ -35,7 +35,7 @@ public class StaticMemberStMsType extends AbstractStaticMemberMsType {*/public StaticMemberStMsType(AbstractPdb pdb, PdbByteReader reader) throws PdbException {super(pdb, reader);- attribute = new ClassFieldMsAttributes(reader);+ attributes = new ClassFieldMsAttributes(reader);fieldTypeRecordNumber = RecordNumber.parse(pdb, reader, RecordCategory.TYPE, 32);name = reader.parseString(pdb, StringParseType.StringSt);reader.align4();diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/VirtualFunctionTablePointerTypeApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/VirtualFunctionTablePointerTypeApplier.javaindex 2d5bd89be5..2c3379a691 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/VirtualFunctionTablePointerTypeApplier.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/VirtualFunctionTablePointerTypeApplier.java@@ -19,7 +19,6 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.PdbException;import ghidra.app.util.bin.format.pdb2.pdbreader.RecordNumber;import ghidra.app.util.bin.format.pdb2.pdbreader.type.*;import ghidra.program.model.data.DataType;-import ghidra.program.model.data.VoidDataType;import ghidra.util.exception.CancelledException;/**@@ -36,7 +35,8 @@ public class VirtualFunctionTablePointerTypeApplier extends MsTypeApplier {* @param applicator {@link DefaultPdbApplicator} for which this class is working.* @throws IllegalArgumentException Upon invalid arguments.*/- public VirtualFunctionTablePointerTypeApplier(DefaultPdbApplicator applicator) throws IllegalArgumentException {+ public VirtualFunctionTablePointerTypeApplier(DefaultPdbApplicator applicator)+ throws IllegalArgumentException {super(applicator);}@@ -61,20 +61,10 @@ public class VirtualFunctionTablePointerTypeApplier extends MsTypeApplier {throws PdbException, CancelledException {// usually no record number, so cannot retrieve or store from/to applicator- DataType dataType;- if (type instanceof AbstractVirtualFunctionTablePointerWithOffsetMsType vftPtrWOffset) {- dataType =- applyPointer(vftPtrWOffset.getPointerTypeRecordNumber(), fixupContext, breakCycle);- }- else if (type instanceof AbstractVirtualFunctionTablePointerMsType vftPtr) {- dataType = applyPointer(vftPtr.getPointerTypeRecordNumber(), fixupContext, breakCycle);- }- else {- dataType = VoidDataType.dataType;- applicator.appendLogMsg(- "PDB Warning: Type not handled: " + type.getClass().getSimpleName());- }+ AbstractVirtualFunctionTablePointerMsType vftPtrType = validateType(type);+ RecordNumber recordNumber = vftPtrType.getPointerTypeRecordNumber();+ DataType dataType = applyPointer(recordNumber, fixupContext, breakCycle);// unlike regular pointer, we are resolving vft pointerdataType = applicator.resolve(dataType);@@ -93,15 +83,14 @@ public class VirtualFunctionTablePointerTypeApplier extends MsTypeApplier {return null;}- private static AbstractMsType validateType(AbstractMsType type)+ private static AbstractVirtualFunctionTablePointerMsType validateType(AbstractMsType type)throws IllegalArgumentException {- if (!(type instanceof AbstractVirtualFunctionTablePointerMsType) &&- !(type instanceof AbstractVirtualFunctionTablePointerWithOffsetMsType)) {+ if (!(type instanceof AbstractVirtualFunctionTablePointerMsType vftPtrType)) {throw new IllegalArgumentException("PDB Incorrectly applying " + type.getClass().getSimpleName() + " to " +VirtualFunctionTablePointerTypeApplier.class.getSimpleName());}- return type;+ return vftPtrType;}}