【问题标题】:How to get global variables definition from symbols tables?如何从符号表中获取全局变量定义?
【发布时间】:2012-12-17 09:02:57
【问题描述】:

我正在使用 C/C++ 语言的 Visual Studio 2005 或 2010 进行开发。我想从二进制或执行文件中的符号表中获取全局结构定义信息。下面举个例子。一个名为“TD”的全局结构和结构中的三个成员。代码编译后,信息将在符号表、PDB 符号文件或 DBG 文件中。是否有任何一组函数可以从符号表中提取信息?我可以得到一个成员的大小和这个成员的类型吗?

typedef struct {
void * pointer;
int    b;
char c;
}TD;

【问题讨论】:

    标签: c visual-studio data-structures global symbol-table


    【解决方案1】:

    你必须使用ISymbolReader 接口。我在这里有 C# 示例:

            // Create the Metadata dispenser.
            IMetaDataDispenserEx pDispenser = new IMetaDataDispenserEx();
    
            // Open the Metadata importer for the given file.
            Guid importerIID = new Guid(RCWHelper.IID_IMetaDataImport);
            IntPtr pImporter = IntPtr.Zero;
            pDispenser.OpenScope(filepath, COR_OPEN_FLAGS.ofRead, ref importerIID, out pImporter);
    
            SymBinder binder = new SymBinder();
            ISymbolReader symReader = binder.GetReader(pImporter, filepath);
    

    然后,您可以使用此接口的 GetGlobalVariables 和 GetVariables 方法来获取有关变量的完整信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      • 2018-01-27
      相关资源
      最近更新 更多