Ghidra is a software reverse engineering (SRE) framework
GP-5446 - PDB CPP Lay down vxt types
ghizard1d84859a8d23
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/MsftVxtManager.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/MsftVxtManager.javaindex 8b5e04f0ae..6d23d8ccdb 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/MsftVxtManager.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/MsftVxtManager.java@@ -24,11 +24,12 @@ import ghidra.app.util.demangler.microsoft.MicrosoftDemangler;import ghidra.app.util.demangler.microsoft.MicrosoftMangledContext;import ghidra.app.util.importer.MessageLog;import ghidra.program.model.address.Address;-import ghidra.program.model.data.CategoryPath;-import ghidra.program.model.data.DataTypeManager;+import ghidra.program.model.data.*;+import ghidra.program.model.data.DataUtilities.ClearDataMode;import ghidra.program.model.gclass.ClassID;import ghidra.program.model.gclass.ClassUtils;import ghidra.program.model.listing.Program;+import ghidra.program.model.util.CodeUnitInsertionException;import ghidra.util.Msg;import ghidra.util.exception.AssertException;import ghidra.util.exception.CancelledException;@@ -166,17 +167,46 @@ public class MsftVxtManager extends VxtManager {}/**- * Create the vxtable structures+ * Create the vxtable structures; attempts to place the table type down in memory if+ * mode is not null and table has an address* @param dtm the data type manager+ * @param mode clear mode for clearing existing data; if {@code null} will not attempt to place+ * type in memory*/- public void doTableLayouts(DataTypeManager dtm) {+ public void createTables(DataTypeManager dtm, ClearDataMode mode) {for (VirtualBaseTable vbt : vbtsByOwnerParentage.values()) {ClassID id = vbt.getOwner();- vbt.getLayout(dtm, ClassUtils.getClassInternalsPath(id));+ Structure table = vbt.createDataType(dtm, ClassUtils.getClassInternalsPath(id));+ if (mode == null) {+ continue;+ }+ if (!(vbt instanceof ProgramVirtualBaseTable pvbt)) {+ continue;+ }+ Address addr = pvbt.getAddress();+ try {+ DataUtilities.createData(program, addr, table, table.getLength(), mode);+ }+ catch (CodeUnitInsertionException e) {+ Msg.warn(this, "Could not place VBT at address: " + addr);+ }}for (VirtualFunctionTable vft : vftsByOwnerParentage.values()) {ClassID id = vft.getOwner();- vft.getLayout(dtm, ClassUtils.getClassInternalsPath(id));+ Structure table = vft.createDataType(dtm, ClassUtils.getClassInternalsPath(id));+ if (mode == null) {+ continue;+ }+ if (!(vft instanceof ProgramVirtualFunctionTable pvft)) {+ continue;+ }+ Address addr = pvft.getAddress();+ try {+ DataUtilities.createData(program, addr, table, table.getLength(), mode);+ }+ catch (CodeUnitInsertionException e) {+ Msg.warn(this, "Could not place VFT at address: " + addr);+ }}}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/VirtualBaseTable.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/VirtualBaseTable.javaindex 2dfacd4016..ab488d9ba4 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/VirtualBaseTable.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/VirtualBaseTable.java@@ -221,7 +221,7 @@ public abstract class VirtualBaseTable implements VBTable {* @param categoryPath category path for the table* @return the structure of the vbtable*/- public Structure getLayout(DataTypeManager dtm, CategoryPath categoryPath) {+ public Structure createDataType(DataTypeManager dtm, CategoryPath categoryPath) {if (!isBuilt) { // what if we want to rebuild... what should we do?build(dtm, categoryPath);}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/VirtualFunctionTable.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/VirtualFunctionTable.javaindex 27c0a81f48..e322bb070a 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/VirtualFunctionTable.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/classtype/VirtualFunctionTable.java@@ -195,7 +195,7 @@ public abstract class VirtualFunctionTable implements VFTable {* @param categoryPath category path for the table* @return the structure of the vftable*/- public Structure getLayout(DataTypeManager dtm, CategoryPath categoryPath) {+ public Structure createDataType(DataTypeManager dtm, CategoryPath categoryPath) {if (!isBuilt) { // what if we want to rebuild... what should we do?build(dtm, categoryPath);}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DataSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DataSymbolApplier.javaindex b1e9ea195e..86fda53e60 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DataSymbolApplier.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DataSymbolApplier.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.@@ -51,8 +51,13 @@ public class DataSymbolApplier extends MsSymbolApplierif (applicator.isInvalidAddress(address, symbol.getName())) {return;}- // createData() can return false on failure, but we want to put the symbol down regardless- createData(address);+ // Skip placing the vftable data type; we will place a better type later (there is no+ // DataSymbol for vbtable)+ if (!symbol.getName().contains("`vftable'")) {+ // createData(address) can return false on failure, but we want to put the symbol down+ // regardless, so we do not look at the return value and just keep processing+ createData(address);+ }Address symbolAddress = applicator.getAddress(symbol);applicator.createSymbol(symbolAddress, symbol.getName(), false);}diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DefaultPdbApplicator.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DefaultPdbApplicator.javaindex c75fe7fb80..bd4930d897 100644--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DefaultPdbApplicator.java+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DefaultPdbApplicator.java@@ -36,17 +36,19 @@ import ghidra.app.util.bin.format.pdb2.pdbreader.type.PrimitiveMsType;import ghidra.app.util.bin.format.pe.cli.tables.CliAbstractTableRow;import ghidra.app.util.importer.MessageLog;import ghidra.app.util.pdb.PdbCategories;-import ghidra.app.util.pdb.classtype.ClassTypeManager;-import ghidra.app.util.pdb.classtype.MsftVxtManager;+import ghidra.app.util.pdb.classtype.*;import ghidra.framework.options.Options;import ghidra.program.database.data.DataTypeUtilities;import ghidra.program.disassemble.DisassemblerContextImpl;import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSet;import ghidra.program.model.data.*;+import ghidra.program.model.data.DataUtilities.ClearDataMode;+import ghidra.program.model.gclass.ClassID;import ghidra.program.model.lang.Register;import ghidra.program.model.listing.*;import ghidra.program.model.symbol.*;+import ghidra.program.model.util.CodeUnitInsertionException;import ghidra.util.Msg;import ghidra.util.exception.*;import ghidra.util.task.CancelOnlyWrappingTaskMonitor;@@ -371,7 +373,7 @@ public class DefaultPdbApplicator implements PdbApplicator {case ALL:processTypes();processSymbols();- vxtManager.doTableLayouts(dataTypeManager);+ vxtManager.createTables(dataTypeManager, ClearDataMode.CLEAR_ALL_CONFLICT_DATA);break;default:throw new PdbException("PDB: Invalid Application Control: " +diff --git a/Ghidra/Features/PDB/src/test/java/ghidra/app/util/pdb/pdbapplicator/CppCompositeTypeTest.java b/Ghidra/Features/PDB/src/test/java/ghidra/app/util/pdb/pdbapplicator/CppCompositeTypeTest.javaindex fef60a84e6..4a607a5891 100644--- a/Ghidra/Features/PDB/src/test/java/ghidra/app/util/pdb/pdbapplicator/CppCompositeTypeTest.java+++ b/Ghidra/Features/PDB/src/test/java/ghidra/app/util/pdb/pdbapplicator/CppCompositeTypeTest.java@@ -29,6 +29,7 @@ import ghidra.app.util.pdb.*;import ghidra.app.util.pdb.classtype.*;import ghidra.program.model.address.Address;import ghidra.program.model.data.*;+import ghidra.program.model.data.DataUtilities.ClearDataMode;import ghidra.program.model.gclass.ClassID;import ghidra.program.model.gclass.ClassUtils;import ghidra.program.model.listing.Program;@@ -71,6 +72,8 @@ public class CppCompositeTypeTest extends AbstractGenericTest {private static ObjectOrientedClassLayout speculativeLayoutChoice =ObjectOrientedClassLayout.CLASS_HIERARCHY_SPECULATIVE;+ ClearDataMode clearMode = ClearDataMode.CLEAR_ALL_CONFLICT_DATA;+private DataTypeManager dtm32 = new StandAloneDataTypeManager("32-bit win", dataOrg32);private DataTypeManager dtm64 = new StandAloneDataTypeManager("64-bit win", dataOrg64);@@ -2078,7 +2081,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2098,7 +2101,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, null);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});// Not checking vxt structures here.}@@ -2122,7 +2125,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, speculativeLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2147,7 +2150,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2167,7 +2170,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, null);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});// Not checking vxt structures here.}@@ -2191,7 +2194,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, speculativeLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2216,7 +2219,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2236,7 +2239,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, null);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});// Not checking vxt structures here.}@@ -2260,7 +2263,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, speculativeLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2285,7 +2288,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2305,7 +2308,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, null);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});// Not checking vxt structures here.}@@ -2329,7 +2332,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, speculativeLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2354,7 +2357,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2374,7 +2377,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, null);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});// Not checking vxt structures here.}@@ -2398,7 +2401,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, speculativeLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2423,7 +2426,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}@@ -2443,7 +2446,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, classLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, null);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});// Not checking vxt structures here.}@@ -2467,7 +2470,7 @@ public class CppCompositeTypeTest extends AbstractGenericTest {dtm.withTransaction("Processing data.", () -> {createAndTestStructures(program, dtm, speculativeLayoutChoice, pdb, is64Bit, vxtManager,expectedResults, expectedVxtPtrSummaries);- vxtManager.doTableLayouts(dtm);+ vxtManager.createTables(dtm, clearMode);});checkVxtStructures(dtm, expectedVxtStructs);}