使用dia-sdk从microsoft-pdb文件加载数据

本文关键字:加载 数据 文件 microsoft-pdb dia-sdk 使用 | 更新日期: 2023-09-27 18:28:30

Hi-im正在尝试从pdb文件读取数据

我遵循了"如何使用C#中的MS DIA SDK?"中的步骤?并生成组件

问题是:在MS pdb文件上调用dataSource.loadDataFromPdb时,会引发ComException(HRESULT:0x806D000C)

我尝试过使用dumpbin.exe/headers,但由于"未知格式"而失败

在自生成的pdb上使用.loadDataFromPdb和dumpbin可以正常工作

IDiaDataSource dataSource = new DiaSourceClass();
//dataSource.loadDataFromPdb(@"D:'Symbols'System.Data.Entity.pdb"); // Fails
dataSource.loadDataFromPdb(@"D:'Symbols'myassembly.pdb"); // Success
IDiaSession session;
dataSource.openSession(out session);
var guid = session.globalScope.guid.ToString();

有没有其他方法可以打开MS pdb文件,特别是提取GUID

使用dia-sdk从microsoft-pdb文件加载数据

基于此处信息的一点数学计算表明,0x806D000C对应于MSDN描述的E_PDB_FORMAT:"试图访问过时格式的文件。"

基于此,我不得不问(是的,可能会晚一点)。。。记得Visual Studio的哪个版本吗;你和DIA一起尝试这个?Microsoft发送的PDB的PDB格式可能发生了更改,您的工具可能不是最新的。

您可以使用BinaryReader从.pdb文件中读取GUID值,如下所示。关键是获得偏移:

var fileName = @"c:'temp'StructureMap.pdb";
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
    using (BinaryReader binReader = new BinaryReader(fs))
    {
        // This is where the GUID for the .pdb file is stored
        fs.Position = 0x00000a0c;
        //starts at 0xa0c but is pieced together up to 0xa1b
        byte[] guidBytes = binReader.ReadBytes(16);
        Guid pdbGuid = new Guid(guidBytes);
        Debug.WriteLine(pdbGuid.ToString());
    }
}

要从.dll或.exe中获取值,需要做更多的工作:)