我正在尝试在dllexport定义的方法中使用SymEnumSymbols
函数。 SymEnumSymbols
需要一个特殊的PSYM_ENUMERATESYMBOLS_CALLBACK
参数,但是当我尝试创建该回调时,我遇到了一些错误(Visual Studio 2017 btw)。
我使用了Windows Dev Denter的以下页面:https://docs.microsoft.com/en-us/windows/desktop/api/dbghelp/nc-dbghelp-psym_enumeratesymbols_callback 了解如何定义此唯一的回调并将其放在我的代码中:
#include <windows.h>
#include <dbghelp.h>
// and other includes....
#define HOOKERDLL_API __declspec(dllexport)
/* copy-paste from Windows Sev Center... */
PSYM_ENUMERATESYMBOLS_CALLBACK PsymEnumeratesymbolsCallback;
BOOL PsymEnumeratesymbolsCallback(
PSYMBOL_INFO pSymInfo,
ULONG SymbolSize,
PVOID UserContext
)
{
return 0;
}
// I added the function that call 'symEnumSymbols' just in case...
//any way currently no callback is sent and I need to specify 'malloc' and implement other stuff,
//and without the previous callback definitions build succeed....
// count the 'malloc' and 'free' symbols in it using 'SymInitialize' and'SymEnumSymb'
extern "C" HOOKERDLL_API void countMallocFree()
{
printf("Hello from dll: countMallocFree!\n");
// Retrieves a pseudo handle for the current process.
HANDLE thisProc = GetCurrentProcess();
// Initializes the symbol handler for a process.
if (!SymInitialize(thisProc, NULL, 1)) // might need to change '1' to 'true'
{
printf("SymIntialize failed :-(\n");
return;
}
printf("SymIntialize succeeded :-)\n");
//Enumerates all symbols in a process.
if (!SymEnumSymbols(
thisProc, // handler to the process.
0,
"*!*", // combination of the last two lines means: Enumerate every symbol in every loaded module - we might change this...
NULL, // TODO: implement CALLBACK and send it here.
NULL // argument for the callback.
))
{
printf("SymEnumSymbols failed :-(\n");
return;
}
printf("SymEnumSymbols succeeded :-)\n");
}
当我尝试构建时,出现以下错误:
declaration is incompatible with "BOOL PsymEnumeratesymbolsCallback(PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext)"
declaration is incompatible with "PSYM_ENUMERATESYMBOLS_CALLBACK PsymEnumeratesymbolsCallback"
'PsymEnumeratesymbolsCallback': redefinition; previous definition was 'data variable'
由于我使用了与指南中相同的代码,并且countMallocFree
函数不是问题的根源(因为没有回调定义,构建成功),我相信我缺少有关dll ...
感谢您的帮助!