Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-2974 PDB Analyzer using CategoryPath forward slash capability

ghizardacd61977fbe4
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplyDataTypes.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplyDataTypes.java
index 1451506c28..565bdb40d4 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplyDataTypes.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/ApplyDataTypes.java
@@ -19,6 +19,7 @@ import java.util.*;
import org.xml.sax.SAXParseException;
+import ghidra.app.util.SymbolPath;
import ghidra.app.util.bin.format.pdb.PdbParserNEW.PdbXmlMember;
import ghidra.app.util.importer.MessageLog;
import ghidra.graph.*;
@@ -110,9 +111,10 @@ public class ApplyDataTypes {
// namespace qualified name used for cache lookups
DataType cachedDataType = pdbParser.getCachedDataType(compositeDefinition.name);
+ SymbolPath symbolPath = new SymbolPath(compositeDefinition.name);
if (!(cachedDataType instanceof Composite) ||
!cachedDataType.getCategoryPath().equals(
- pdbParser.getCategory(compositeDefinition.name, true)) ||
+ pdbParser.getCategory(symbolPath.getParent(), true)) ||
!pdbParser.isCorrectKind(cachedDataType, compositeDefinition.kind)) {
log.appendMsg("Error: Conflicting data type name: " + compositeDefinition.name);
continue;
@@ -255,12 +257,15 @@ public class ApplyDataTypes {
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
CompositeDefinition other = (CompositeDefinition) obj;
return isClass == other.isClass && kind == other.kind && length == other.length &&
SystemUtilities.isEqual(name, other.name);
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParserNEW.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParserNEW.java
index 1706ec1138..acd4aea957 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParserNEW.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/bin/format/pdb/PdbParserNEW.java
@@ -84,7 +84,6 @@ public class PdbParserNEW {
private PdbErrorReaderThread thread;
private boolean parsed = false;
- private String categoryPrefix;
private CategoryPath pdbCategory;
/**
@@ -103,8 +102,7 @@ public class PdbParserNEW {
public PdbParserNEW(File pdbFile, Program program, DataTypeManagerService service,
PdbProgramAttributes programAttributes, boolean forceAnalysis, TaskMonitor monitor) {
this.pdbFile = pdbFile;
- this.categoryPrefix = "/" + pdbFile.getName();
- this.pdbCategory = new CategoryPath(categoryPrefix);
+ this.pdbCategory = new CategoryPath(CategoryPath.ROOT, pdbFile.getName());
this.program = program;
this.dataMgr = program.getDataTypeManager();
this.service = service;
@@ -715,21 +713,26 @@ public class PdbParserNEW {
}
Structure createStructure(String name, int length) {
- return new StructureDataType(getCategory(name, true), stripNamespace(name), length,
+ SymbolPath path = new SymbolPath(name);
+ return new StructureDataType(getCategory(path.getParent(), true), path.getName(), length,
dataMgr);
}
Union createUnion(String name) {
- return new UnionDataType(getCategory(name, true), stripNamespace(name), dataMgr);
+ SymbolPath path = new SymbolPath(name);
+ return new UnionDataType(getCategory(path.getParent(), true), path.getName(), dataMgr);
}
TypedefDataType createTypeDef(String name, DataType baseDataType) {
- return new TypedefDataType(getCategory(name, true), stripNamespace(name), baseDataType,
- dataMgr);
+ SymbolPath path = new SymbolPath(name);
+ return new TypedefDataType(getCategory(path.getParent(), true), path.getName(),
+ baseDataType, dataMgr);
}
EnumDataType createEnum(String name, int length) {
- return new EnumDataType(getCategory(name, true), stripNamespace(name), length, dataMgr);
+ SymbolPath path = new SymbolPath(name);
+ return new EnumDataType(getCategory(path.getParent(), true), path.getName(), length,
+ dataMgr);
}
void createString(boolean isUnicode, Address address, MessageLog log, TaskMonitor monitor) {
@@ -999,6 +1002,24 @@ public class PdbParserNEW {
return category;
}
+ /**
+ * Get the {@link CategoryPath} associated with the namespace specified by the
+ * {@link SymbolPath}, rooting it either at the Category Path root or the PDB Category.
+ * @param symbolPath the {@link SymbolPath} input; can be null if no depth in path.
+ * @param addPdbRoot True if PDB root category should be used, otherwise it will be omitted.
+ * @return {@link CategoryPath} created for the input.
+ */
+ CategoryPath getCategory(SymbolPath symbolPath, boolean addPdbRoot) {
+ CategoryPath category = addPdbRoot ? pdbCategory : CategoryPath.ROOT;
+ if (symbolPath != null) {
+ List<String> names = symbolPath.asList();
+ for (String name : names) {
+ category = new CategoryPath(category, name);
+ }
+ }
+ return category;
+ }
+
/********************************************************************/
/* STATIC METHODS */
/********************************************************************/