2

嗨,我正在尝试从 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

4

2 回答 2

2

根据此处的信息进行的一些数学运算表明 0x806D000C 对应于 E_PDB_FORMAT ,MSDN 的描述为:“尝试访问具有过时格式的文件”。

基于此,我不得不问(是的,可能晚了)......您还记得您尝试使用哪个版本的 Visual Studio 和 DIA 吗?对于 Microsoft 发送的那些 PDB,PDB 格式可能已更改,您的工具可能不是最新的。

于 2014-12-02T01:53:50.800 回答
1

您可以使用如下所示的 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 获取值需要更多的工作:)

于 2014-06-17T21:40:31.270 回答