Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-5492 - PdbReader - bring method records into alignment with each other; expose thisAdjuster; change output format and tests

ghizard766c4c7c04c4
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMemberFunctionMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMemberFunctionMsType.java
index 662cb70cc6..20f78e2f57 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMemberFunctionMsType.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractMemberFunctionMsType.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -154,6 +154,14 @@ public abstract class AbstractMemberFunctionMsType extends AbstractMsType {
return pdb.getTypeRecord(thisPointerRecordNumber);
}
+ /**
+ * Returns the "this" adjuster
+ * @return the adjuster
+ */
+ public int getThisAdjuster() {
+ return thisAdjuster;
+ }
+
@Override
public void emit(StringBuilder builder, Bind bind) {
if (bind.ordinal() < Bind.PROC.ordinal()) {
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.java
index cc0273ede5..c86c146625 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
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -75,7 +75,7 @@ public abstract class AbstractMethodRecordMs extends AbstractParsableItem {
builder.append(attributes);
builder.append(": ");
builder.append(pdb.getTypeRecord(procedureRecordNumber));
- if (attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO) {
+ if (optionalOffset != -1) {
builder.append(",");
builder.append(optionalOffset);
}
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.java
index af68e229fd..daa6cc03f9 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
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -49,7 +49,8 @@ public abstract class AbstractOneMethodMsType extends AbstractMsType implements
offsetInVFTableIfIntroVirtual = reader.parseUnsignedIntVal();
}
else {
- offsetInVFTableIfIntroVirtual = 0;
+ // 20250310: changed this from 0 to -1 to match "MethodRecord" types
+ offsetInVFTableIfIntroVirtual = -1;
}
name = reader.parseString(pdb, strType);
reader.skipPadding();
@@ -92,8 +93,10 @@ public abstract class AbstractOneMethodMsType extends AbstractMsType implements
builder.append(attributes);
builder.append(": ");
builder.append(pdb.getTypeRecord(procedureTypeRecordNumber));
- builder.append(",");
- builder.append(offsetInVFTableIfIntroVirtual);
+ if (offsetInVFTableIfIntroVirtual != -1) {
+ builder.append(",");
+ builder.append(offsetInVFTableIfIntroVirtual);
+ }
builder.append(">");
}
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualBaseClassMsType.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualBaseClassMsType.java
index 35c93efeca..f11f4ffceb 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualBaseClassMsType.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/AbstractVirtualBaseClassMsType.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -63,15 +63,16 @@ public abstract class AbstractVirtualBaseClassMsType extends AbstractMsType impl
/**
* Returns the offset of the base base pointer within the class.
- * @return the offset;
+ * @return the offset
*/
public BigInteger getBasePointerOffset() {
return virtualBasePointerOffsetFromAddressPoint;
}
/**
- * Returns the virtual base offset from VB table.
- * @return the offset;
+ * Returns the virtual base offset from VB table. This seems more like an "index" into
+ * an integer array having values such as 1, 2, 3
+ * @return the offset
*/
public BigInteger getBaseOffsetFromVbt() {
return virtualBaseOffsetFromVBTable;
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/MethodRecord16Ms.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/MethodRecord16Ms.java
index e320341545..e3a9a1ad1d 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/MethodRecord16Ms.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/MethodRecord16Ms.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -35,7 +35,10 @@ public class MethodRecord16Ms extends AbstractMethodRecordMs {
super(pdb, reader);
attributes = new ClassFieldMsAttributes(reader);
procedureRecordNumber = RecordNumber.parse(pdb, reader, RecordCategory.TYPE, 16);
- if (attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO) {
+ // See comment in MethodRecordMs... we are adding INTRO_PURE as it might also occur, and
+ // there should be no harm on doing this
+ if (attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO ||
+ attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO_PURE) {
optionalOffset = reader.parseUnsignedIntVal();
}
else {
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/MethodRecordMs.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/MethodRecordMs.java
index 2a6db61b03..5b1f0e1912 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/MethodRecordMs.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/MethodRecordMs.java
@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -39,8 +39,8 @@ public class MethodRecordMs extends AbstractMethodRecordMs {
// API says optional offset "if intro virtual" but we have seen it for 6=<intro.pure>, so
// it could be that we need to also include 2=virtual here; i.e., each 2, 4, and 6
// (virtual, <intro>, and <intro,pure>) could have this optional field.
- if ((attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO) ||
- (attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO_PURE)) {
+ if (attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO ||
+ attributes.getProperty() == ClassFieldMsAttributes.Property.INTRO_PURE) {
optionalOffset = reader.parseUnsignedIntVal();
}
else {
diff --git a/Ghidra/Features/PDB/src/test/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/TypesTest.java b/Ghidra/Features/PDB/src/test/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/TypesTest.java
index e4466e3f77..6bfe8a149f 100644
--- a/Ghidra/Features/PDB/src/test/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/TypesTest.java
+++ b/Ghidra/Features/PDB/src/test/java/ghidra/app/util/bin/format/pdb2/pdbreader/type/TypesTest.java
@@ -2180,7 +2180,7 @@ public class TypesTest extends AbstractGenericTest {
AbstractMsType type = TypeParser.parse(pdb, reader);
assertEquals(type instanceof OneMethod16MsType, true);
String result = type.toString().trim();
- assertEquals("<public static<pseudo, noinherit, noconstruct>: DummyMsType,0>", result);
+ assertEquals("<public static<pseudo, noinherit, noconstruct>: DummyMsType>", result);
}
@Test
@@ -2204,7 +2204,7 @@ public class TypesTest extends AbstractGenericTest {
AbstractMsType type = TypeParser.parse(pdb, reader);
assertEquals(type instanceof OneMethodStMsType, true);
String result = type.toString().trim();
- assertEquals("<public static<pseudo, noinherit, noconstruct>: DummyMsType,0>", result);
+ assertEquals("<public static<pseudo, noinherit, noconstruct>: DummyMsType>", result);
}
@Test
@@ -2228,7 +2228,7 @@ public class TypesTest extends AbstractGenericTest {
AbstractMsType type = TypeParser.parse(pdb, reader);
assertEquals(type instanceof OneMethodMsType, true);
String result = type.toString().trim();
- assertEquals("<public static<pseudo, noinherit, noconstruct>: DummyMsType,0>", result);
+ assertEquals("<public static<pseudo, noinherit, noconstruct>: DummyMsType>", result);
}
@Test