Skip to content

Commit 3f14e54

Browse files
committed
Merge remote-tracking branch 'origin/GP-4306_ghizard_PDB_cleanup_vftptr_and_method_types'
2 parents 52e6360 + 1470713 commit 3f14e54

11 files changed

+154
-54
lines changed

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractFieldListMsType.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,17 @@ public List<MsTypeField> getBaseClassList() {
104104
}
105105

106106
/**
107-
* Returns the (ordered?) {@link List}&lt;{@link AbstractMsType}&gt; of type members types of
108-
* this field list.
107+
* Returns the (ordered?) {@link List}&lt;{@link MsTypeField}&gt; of type members types of
108+
* this field list. This is a hodge-podge of other types form the field list. This list
109+
* should generally not be used outside of this class
109110
* @return Field list.
110111
*/
111112
public List<MsTypeField> getMemberList() {
112113
return memberList;
113114
}
114115

115116
/**
116-
* Returns the (ordered?) {@link List}&lt;{@link AbstractMsType}&gt; of other types. (We have
117+
* Returns the (ordered?) {@link List}&lt;{@link MsTypeField}&gt; of other types. (We have
117118
* separated these out, but are unsure about what they are at this time.)
118119
* @return List of other types.
119120
*/
@@ -122,7 +123,7 @@ public List<MsTypeField> getMethodList() {
122123
}
123124

124125
/**
125-
* Returns the (ordered?) {@link List}&lt;{@link AbstractMsType}&gt; of non-static members
126+
* Returns the (ordered?) {@link List}&lt;{@link AbstractMemberMsType}&gt; of non-static members
126127
* from this field list
127128
* @return non-static members
128129
*/
@@ -131,18 +132,27 @@ public List<AbstractMemberMsType> getNonStaticMembers() {
131132
}
132133

133134
/**
134-
* Returns the (ordered?) {@link List}&lt;{@link AbstractMsType}&gt; of VFT pointer records
135-
* from this field list
135+
* Returns the (ordered?) {@link List}&lt;{@link AbstractStaticMemberMsType}&gt; of static
136+
* members from this field list
137+
* @return non-static members
138+
*/
139+
public List<AbstractStaticMemberMsType> getStaticMembers() {
140+
return staticMemberList;
141+
}
142+
143+
/**
144+
* Returns the (ordered?) {@link List}&lt;{@link AbstractVirtualFunctionTablePointerMsType}&gt;
145+
* of VFT pointer records from this field list
136146
* @return VFT pointer records
137147
*/
138148
public List<AbstractVirtualFunctionTablePointerMsType> getVftPointers() {
139149
return vftPtrList;
140150
}
141151

142152
/**
143-
* Returns the (ordered?) {@link List}&lt;{@link AbstractNestedTypeMsType}&gt; of enumerates
144-
* from this field list
145-
* @return enumerates
153+
* Returns the (ordered?) {@link List}&lt;{@link AbstractNestedTypeMsType}&gt; of nested
154+
* types from this field list
155+
* @return nested types
146156
*/
147157
public List<AbstractNestedTypeMsType> getNestedTypes() {
148158
return nestedTypeList;

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMethodRecordMs.java

+25
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,31 @@ public AbstractMethodRecordMs(AbstractPdb pdb, PdbByteReader reader) throws PdbE
4343
this.pdb = pdb;
4444
}
4545

46+
/**
47+
* Returns the attributes of this procedure
48+
* @return the attributes
49+
*/
50+
public ClassFieldMsAttributes getAttributes() {
51+
return attributes;
52+
}
53+
54+
/**
55+
* Returns the record number of the data type (?) for this procedure
56+
* @return the record number
57+
*/
58+
public RecordNumber getProcedureTypeRecordNumber() {
59+
return procedureRecordNumber;
60+
}
61+
62+
/**
63+
* Returns the offset of the procedure in the VFTable if intro/virtual. Value of -1 means
64+
* there was not a value
65+
* @return the offset
66+
*/
67+
public long getOptionalOffset() {
68+
return optionalOffset;
69+
}
70+
4671
@Override
4772
public void emit(StringBuilder builder) {
4873
// Making this up; no API for output.

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOneMethodMsType.java

+34-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
public abstract class AbstractOneMethodMsType extends AbstractMsType implements MsTypeField {
2727

28-
protected ClassFieldMsAttributes attribute;
28+
protected ClassFieldMsAttributes attributes;
2929
protected RecordNumber procedureTypeRecordNumber;
3030
protected long offsetInVFTableIfIntroVirtual;
3131
protected String name;
@@ -41,11 +41,11 @@ public abstract class AbstractOneMethodMsType extends AbstractMsType implements
4141
public AbstractOneMethodMsType(AbstractPdb pdb, PdbByteReader reader, int recordNumberSize,
4242
StringParseType strType) throws PdbException {
4343
super(pdb, reader);
44-
attribute = new ClassFieldMsAttributes(reader);
44+
attributes = new ClassFieldMsAttributes(reader);
4545
procedureTypeRecordNumber =
4646
RecordNumber.parse(pdb, reader, RecordCategory.TYPE, recordNumberSize);
47-
if ((attribute.getProperty() == ClassFieldMsAttributes.Property.INTRO) ||
48-
(attribute.getProperty() == ClassFieldMsAttributes.Property.INTRO_PURE)) {
47+
if ((attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO) ||
48+
(attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO_PURE)) {
4949
offsetInVFTableIfIntroVirtual = reader.parseUnsignedIntVal();
5050
}
5151
else {
@@ -55,12 +55,41 @@ public AbstractOneMethodMsType(AbstractPdb pdb, PdbByteReader reader, int record
5555
reader.skipPadding();
5656
}
5757

58+
@Override
59+
public String getName() {
60+
return name;
61+
}
62+
63+
/**
64+
* Returns the record number of the data type for this procedure
65+
* @return the record number
66+
*/
67+
public RecordNumber getProcedureTypeRecordNumber() {
68+
return procedureTypeRecordNumber;
69+
}
70+
71+
/**
72+
* Returns the attributes of this procedure
73+
* @return the attributes
74+
*/
75+
public ClassFieldMsAttributes getAttributes() {
76+
return attributes;
77+
}
78+
79+
/**
80+
* Returns the offset of the procedure in the VFTable if intro/virtual
81+
* @return the offset
82+
*/
83+
public long getOffsetInVFTableIfIntroVirtual() {
84+
return offsetInVFTableIfIntroVirtual;
85+
}
86+
5887
@Override
5988
public void emit(StringBuilder builder, Bind bind) {
6089
// No API for this. Just outputting something that might be useful.
6190
// At this time, not doing anything with bind here; don't think it is warranted.
6291
builder.append("<");
63-
builder.append(attribute);
92+
builder.append(attributes);
6493
builder.append(": ");
6594
builder.append(pdb.getTypeRecord(procedureTypeRecordNumber));
6695
builder.append(",");

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractOverloadedMethodMsType.java

+21
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ public AbstractOverloadedMethodMsType(AbstractPdb pdb, PdbByteReader reader,
4747

4848
}
4949

50+
@Override
51+
public String getName() {
52+
return name;
53+
}
54+
55+
/**
56+
* Returns the number of methods overloaded with the name
57+
* @return the number of methods
58+
*/
59+
public int getCount() {
60+
return count;
61+
}
62+
63+
/**
64+
* Returns the record number of the method list for this overloaded method name
65+
* @return the record number
66+
*/
67+
public RecordNumber getTypeMethodListRecordNumber() {
68+
return methodListRecordNumber;
69+
}
70+
5071
@Override
5172
public void emit(StringBuilder builder, Bind bind) {
5273
// No API for this. Just outputting something that might be useful.

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractStaticMemberMsType.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
public abstract class AbstractStaticMemberMsType extends AbstractMsType implements MsTypeField {
2727

28-
protected ClassFieldMsAttributes attribute;
28+
protected ClassFieldMsAttributes attributes;
2929
protected RecordNumber fieldTypeRecordNumber;
3030
protected String name;
3131

@@ -43,13 +43,29 @@ public String getName() {
4343
return name;
4444
}
4545

46+
/**
47+
* Returns the record number of the data type for this member
48+
* @return the record number
49+
*/
50+
public RecordNumber getFieldTypeRecordNumber() {
51+
return fieldTypeRecordNumber;
52+
}
53+
54+
/**
55+
* Returns the attributes of this procedure
56+
* @return the attributes
57+
*/
58+
public ClassFieldMsAttributes getAttributes() {
59+
return attributes;
60+
}
61+
4662
@Override
4763
public void emit(StringBuilder builder, Bind bind) {
4864
// No API for this.
4965
builder.append(name);
5066
pdb.getTypeRecord(fieldTypeRecordNumber).emit(builder, Bind.NONE);
5167
StringBuilder myBuilder = new StringBuilder();
52-
myBuilder.append(attribute);
68+
myBuilder.append(attributes);
5369
myBuilder.append(": ");
5470
builder.insert(0, myBuilder);
5571
}

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerMsType.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ public AbstractVirtualFunctionTablePointerMsType(AbstractPdb pdb, PdbByteReader
3737
super(pdb, reader);
3838
}
3939

40-
@Override
41-
public void emit(StringBuilder builder, Bind bind) {
42-
builder.append("VFTablePtr: ");
43-
builder.append(pdb.getTypeRecord(pointerTypeRecordNumber));
44-
}
45-
4640
/**
4741
* Returns the record number of the pointer type.
4842
* @return the record number of the pointer type.
@@ -51,4 +45,18 @@ public RecordNumber getPointerTypeRecordNumber() {
5145
return pointerTypeRecordNumber;
5246
}
5347

48+
/**
49+
* Returns the pointer offset.
50+
* @return the offset.
51+
*/
52+
public int getOffset() {
53+
return 0;
54+
}
55+
56+
@Override
57+
public void emit(StringBuilder builder, Bind bind) {
58+
builder.append("VFTablePtr: ");
59+
builder.append(pdb.getTypeRecord(pointerTypeRecordNumber));
60+
}
61+
5462
}

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualFunctionTablePointerWithOffsetMsType.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
* Note: we do not necessarily understand each of these data type classes. Refer to the
2424
* base class for more information.
2525
*/
26-
public abstract class AbstractVirtualFunctionTablePointerWithOffsetMsType extends AbstractMsType {
26+
public abstract class AbstractVirtualFunctionTablePointerWithOffsetMsType
27+
extends AbstractVirtualFunctionTablePointerMsType {
2728

28-
protected RecordNumber pointerTypeRecordNumber;
2929
protected int offset;
3030

3131
/**
@@ -45,18 +45,11 @@ public AbstractVirtualFunctionTablePointerWithOffsetMsType(AbstractPdb pdb,
4545
offset = reader.parseInt();
4646
}
4747

48-
@Override
49-
public void emit(StringBuilder builder, Bind bind) {
50-
builder.append("VFTablePtr<off=");
51-
builder.append(offset);
52-
builder.append(">: ");
53-
builder.append(pdb.getTypeRecord(pointerTypeRecordNumber));
54-
}
55-
5648
/**
5749
* Returns the record number of the pointer type.
5850
* @return the record number of the pointer type.
5951
*/
52+
@Override
6053
public RecordNumber getPointerTypeRecordNumber() {
6154
return pointerTypeRecordNumber;
6255
}
@@ -65,8 +58,17 @@ public RecordNumber getPointerTypeRecordNumber() {
6558
* Returns the pointer offset.
6659
* @return the offset.
6760
*/
61+
@Override
6862
public int getOffset() {
6963
return offset;
7064
}
7165

66+
@Override
67+
public void emit(StringBuilder builder, Bind bind) {
68+
builder.append("VFTablePtr<off=");
69+
builder.append(offset);
70+
builder.append(">: ");
71+
builder.append(pdb.getTypeRecord(pointerTypeRecordNumber));
72+
}
73+
7274
}

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMember16MsType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class StaticMember16MsType extends AbstractStaticMemberMsType {
3636
public StaticMember16MsType(AbstractPdb pdb, PdbByteReader reader) throws PdbException {
3737
super(pdb, reader);
3838
fieldTypeRecordNumber = RecordNumber.parse(pdb, reader, RecordCategory.TYPE, 16);
39-
attribute = new ClassFieldMsAttributes(reader);
39+
attributes = new ClassFieldMsAttributes(reader);
4040
name = reader.parseString(pdb, StringParseType.StringSt);
4141
reader.skipPadding();
4242
}

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberMsType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class StaticMemberMsType extends AbstractStaticMemberMsType {
3535
*/
3636
public StaticMemberMsType(AbstractPdb pdb, PdbByteReader reader) throws PdbException {
3737
super(pdb, reader);
38-
attribute = new ClassFieldMsAttributes(reader);
38+
attributes = new ClassFieldMsAttributes(reader);
3939
fieldTypeRecordNumber = RecordNumber.parse(pdb, reader, RecordCategory.TYPE, 32);
4040
name = reader.parseString(pdb, StringParseType.StringNt);
4141
reader.align4();

Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/StaticMemberStMsType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class StaticMemberStMsType extends AbstractStaticMemberMsType {
3535
*/
3636
public StaticMemberStMsType(AbstractPdb pdb, PdbByteReader reader) throws PdbException {
3737
super(pdb, reader);
38-
attribute = new ClassFieldMsAttributes(reader);
38+
attributes = new ClassFieldMsAttributes(reader);
3939
fieldTypeRecordNumber = RecordNumber.parse(pdb, reader, RecordCategory.TYPE, 32);
4040
name = reader.parseString(pdb, StringParseType.StringSt);
4141
reader.align4();

Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/VirtualFunctionTablePointerTypeApplier.java

+8-19
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import ghidra.app.util.bin.format.pdb2.pdbreader.RecordNumber;
2020
import ghidra.app.util.bin.format.pdb2.pdbreader.type.*;
2121
import ghidra.program.model.data.DataType;
22-
import ghidra.program.model.data.VoidDataType;
2322
import ghidra.util.exception.CancelledException;
2423

2524
/**
@@ -36,7 +35,8 @@ public class VirtualFunctionTablePointerTypeApplier extends MsTypeApplier {
3635
* @param applicator {@link DefaultPdbApplicator} for which this class is working.
3736
* @throws IllegalArgumentException Upon invalid arguments.
3837
*/
39-
public VirtualFunctionTablePointerTypeApplier(DefaultPdbApplicator applicator) throws IllegalArgumentException {
38+
public VirtualFunctionTablePointerTypeApplier(DefaultPdbApplicator applicator)
39+
throws IllegalArgumentException {
4040
super(applicator);
4141
}
4242

@@ -61,20 +61,10 @@ DataType apply(AbstractMsType type, FixupContext fixupContext, boolean breakCycl
6161
throws PdbException, CancelledException {
6262

6363
// usually no record number, so cannot retrieve or store from/to applicator
64-
DataType dataType;
6564

66-
if (type instanceof AbstractVirtualFunctionTablePointerWithOffsetMsType vftPtrWOffset) {
67-
dataType =
68-
applyPointer(vftPtrWOffset.getPointerTypeRecordNumber(), fixupContext, breakCycle);
69-
}
70-
else if (type instanceof AbstractVirtualFunctionTablePointerMsType vftPtr) {
71-
dataType = applyPointer(vftPtr.getPointerTypeRecordNumber(), fixupContext, breakCycle);
72-
}
73-
else {
74-
dataType = VoidDataType.dataType;
75-
applicator.appendLogMsg(
76-
"PDB Warning: Type not handled: " + type.getClass().getSimpleName());
77-
}
65+
AbstractVirtualFunctionTablePointerMsType vftPtrType = validateType(type);
66+
RecordNumber recordNumber = vftPtrType.getPointerTypeRecordNumber();
67+
DataType dataType = applyPointer(recordNumber, fixupContext, breakCycle);
7868

7969
// unlike regular pointer, we are resolving vft pointer
8070
dataType = applicator.resolve(dataType);
@@ -93,15 +83,14 @@ private DataType applyPointer(RecordNumber pointerTypeRecordNumber, FixupContext
9383
return null;
9484
}
9585

96-
private static AbstractMsType validateType(AbstractMsType type)
86+
private static AbstractVirtualFunctionTablePointerMsType validateType(AbstractMsType type)
9787
throws IllegalArgumentException {
98-
if (!(type instanceof AbstractVirtualFunctionTablePointerMsType) &&
99-
!(type instanceof AbstractVirtualFunctionTablePointerWithOffsetMsType)) {
88+
if (!(type instanceof AbstractVirtualFunctionTablePointerMsType vftPtrType)) {
10089
throw new IllegalArgumentException(
10190
"PDB Incorrectly applying " + type.getClass().getSimpleName() + " to " +
10291
VirtualFunctionTablePointerTypeApplier.class.getSimpleName());
10392
}
104-
return type;
93+
return vftPtrType;
10594
}
10695

10796
}

0 commit comments

Comments
 (0)