How to find the calling convention of a third party dll?

前端 未结 2 617
既然无缘
既然无缘 2020-12-15 17:47

Could any one explain me how to get to know the calling convention of a dll without getting and processing method names? Lets say our application is loading a third party dl

相关标签:
2条回答
  • 2020-12-15 17:58

    If the symbol begins with a _ but has no @, then it's __cdecl. If it begins with _ and has a @ it's __stdcall. If it begins with @ and has another @, it's __fastcall.

    source

    0 讨论(0)
  • 2020-12-15 18:12

    While trying to figure out why I was getting unresolved symbols when linking against a third-party dll I stumbled upon a (sort of) programmatic solution.

    I wrote a small program against the Windows API using UnDecorateSymbolName from Dbghelp.hto decode the mangling scheme:

    #include "Windows.h"
    #include "Dbghelp.h"
    #include "tchar.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        CHAR out[512];
        UnDecorateSymbolName(
            // Mangled symbol
            "?OFFReader@IO@OpenMesh@@YGAAV_OFFReader_@12@XZ",
            out,
            // Length of symbol
            46,
            UNDNAME_32_BIT_DECODE);
    }
    

    There are definitely prettier ways to do it. I just run it in a debugger and look at the contents of out.

    Also worth noting, contrary to Ignacio's answer, the difference between the mangled names for the cdecl methods in the dll and the stdcall methods being looked for was YAAAV vs. YGAAV.

    0 讨论(0)
提交回复
热议问题