0

我正在构建一个符号服务,我希望能够打印结构变量及其偏移量。我正在加载所需的 pdb,并试图找到一个适合给定掩码的结构。例如,我想获取有关 struct 的详细信息_RTL_CRITICAL_SECTION

使用windbg时,我使用命令dt MSVCP120!_RTL_CRITICAL_SECTION并获得结构信息(正是我想要的)。但是,当我使用我的代码搜索符号时:

SymEnumSymbols(GetCurrentProcess(), base_addr,"MSVCP120!_RTL_CRITICAL_SECTION", enum_symbols_callback, NULL);

BOOL CALLBACK symbol_processor::enum_symbols_callback(PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext)
{
    printf("Name = %s\n", pSymInfo->Name);
    return TRUE;
}

什么都没有打印..意思是,没有匹配的掩码..当掩码是一个函数时,这确实有效(例如"MSVCP120!std::tr2::sys::_Open_dir"

那么,如何获得结构的符号..?

谢谢!

4

1 回答 1

1

编译前的文件夹内容

:\>ls -l
-rw-rw-rw-  1 Admin 0 459 2015-09-10 10:23 structshow.cpp

资源

:\>cat structshow.cpp
#include <windows.h>
#include <dbghelp.h>
#include <stdio.h>
#pragma comment (lib,"dbghelp.lib")
BOOL CALLBACK mycallback(PSYMBOL_INFO pSymInfo,ULONG,PVOID){
  printf("%s\n",pSymInfo->Name);
  return true;
}
int main(){
  HMODULE hmod = LoadLibraryA("c:\\windows\\system32\\ntdll.dll");
  HANDLE hproc = GetCurrentProcess();
  SymInitialize(hproc,"F:\\symbols",TRUE);
  SymEnumTypesByName(hproc,(ULONG64)hmod,"*!_R*",mycallback,0);
  return 0;
}

编译使用

:\>..\compile.bat

:\>if "C:\Program Files\Microsoft Visual Studio 10.0\VC\" == "" ()

:\>cl /Zi /EHsc /nologo /W4 /analyze *.cpp /link /RELEASE structshow.cpp

:\>ls -l

文件夹后编译的内容

-rw-rw-rw-  1 Admin 0     459 2015-09-10 10:23 structshow.cpp
-rwxrwxrwx  1 Admin 0   89088 2015-09-10 10:29 structshow.exe
-rw-rw-rw-  1 Admin 0   21081 2015-09-10 10:29 structshow.obj
-rw-rw-rw-  1 Admin 0 1002496 2015-09-10 10:29 structshow.pdb
-rw-rw-rw-  1 Admin 0   94208 2015-09-10 10:29 vc100.pdb

使用最新的 dbghelp.dll

:\>copy xxxx\dbghelp.dll .
        1 file(s) copied.

:\>echo "do not use system dbghelp.dll it is 
outdated SymbolEnumTypesbyName is available in 
dbghelp version 6.8 and above only "

执行编译的二进制文件

:\>structshow.exe
_RTL_USER_PROCESS_PARAMETERS
_RTL_CRITICAL_SECTION <----------------------
_RTL_STACK_TRACE_ENTRY
_RTL_TRACE_BLOCK
_RTL_CRITICAL_SECTION_DEBUG
_RTL_DRIVE_LETTER_CURDIR
_RTL_TRACE_DATABASE
_RTL_TRACE_SEGMENT
于 2015-09-10T05:04:22.387 回答