1

当我尝试使用 SymbolFromName() e SymbolFromAddress() 函数时,返回代码总是返回 126 (MODULE_NOT_FOUND),代码是:

    #include<dbghelp.h>
    #include <iostream>
    #include <Windows.h>
    #include <windows.h>
    #include <debugapi.h>
    #include <WinBase.h>
    
    using namespace std;

    int main(){
    DWORD  error;
    HANDLE hProcess;

    SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);

    hProcess = GetCurrentProcess();

    if (!SymInitialize(hProcess, NULL, TRUE))
    {
        // SymInitialize failed
        error = GetLastError();
        cout << "SymInitialize returned error " << error << endl;;
        return FALSE;
    }}
    

    hProcess = GetCurrentProcess();

    SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS);
    SymInitialize(hProcess, NULL, TRUE);

    TCHAR szSymbolName[MAX_SYM_NAME];
    ULONG64 buffer[(sizeof(SYMBOL_INFOW) +
        MAX_SYM_NAME * sizeof(TCHAR) +
        sizeof(ULONG64) - 1) /
        sizeof(ULONG64)];
    PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;

    _tcscpy_s(szSymbolName, MAX_SYM_NAME, TEXT("mainCRTStartup")); // i  
    know the entrypoint name by using >>nm command in windows for extract 
    symbol
    pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
    pSymbol->MaxNameLen = MAX_SYM_NAME;

    if (SymFromName(hProcess, szSymbolName, pSymbol)){
       cout << pSybol->address
    } // this return always 126

    }

我使用 VisualStudio 和默认调试器来测试它。上面的部分代码取自 MSDN 文档,这里是。

编辑:感谢nm我知道主要的符号,它可以提取符号列表,在我的例子中它包含:

 00401300 T _WinMainCRTStartup
 00401460 T _main
 004012e0 T _mainCRTStartup

我也尝试使用不同的符号名称,如 main、mainCRTStartup、wWinMain、WinMain 等,但没有任何结果

4

0 回答 0