SymGetLineFromAddr not working properly

旧城冷巷雨未停 提交于 2019-11-30 23:39:38

Had the same problem with your code (Windows Seven 64b, Unicode 32 bits build, VS2012 Express)

Fixed it with :

DWORD dwDisplacement;
SymGetLineFromAddr(process, (DWORD)(stack[i]), &dwDisplacement, line);
SYMBOL_INFO *symbol = (SYMBOL_INFO *)malloc(sizeof(SYMBOL_INFO));
symbol->MaxNameLen = 1024;
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);

The documentation for SizeOfStruct states:

The size of the structure, in bytes. This member must be set to sizeof(SYMBOL_INFO). Note that the total size of the data is the SizeOfStruct + (MaxNameLen - 1) * sizeof(TCHAR). The reason to subtract one is that the first character in the name is accounted for in the size of the structure.

Emphasis mine. You must allocate storage of at least sizeof(SYMBOL_INFO) + MaxNameLen + 1 bytes. You are only allocating sizeof(SYMBOL_INFO) bytes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!