获取功能参数名称visual studio

Bar*_*ski 8 c++ visual-c++

我试图从visual studio中编译的一个错位函数中获取参数列表和返回类型.

我知道我可以用

UnDecorateSymbolName(function.c_str(), undecoratedName, 200, UNDNAME_COMPLETE))
Run Code Online (Sandbox Code Playgroud)

但这只是给了我另一个字符串,我必须弄清楚字符串是以返回类型还是说明符开头的.

是否有返回SymbolNameInfo的函数?一些事情:

struct SymbolInfo
{
    char[255] symbolName
    char[255] returnType
    char[255] parameters
};
Run Code Online (Sandbox Code Playgroud)

Bar*_*ski 1

我设法找到了答案。它并不完美,也许其他人会有更好的想法。

我所做的是使用

UnDecorateSymbolName(function.c_str(), undecoratedName, 200, UNDNAME_COMPLETE))
Run Code Online (Sandbox Code Playgroud)

具有不同的标志。

我使用的标志和解释:

UNDNAME_COMPLETE // this returns the whole undecorated name.
UNDNAME_NAME_ONLY // this return just the name of the symbol
UNDNAME_NO_FUNCTION_RETURNS // this return a string like UNDNAME_COMPLETE 
                            // but without the return type
Run Code Online (Sandbox Code Playgroud)

我使用这 3 个标志执行以下操作:

  1. 为了获取名称,我只使用了 UNDNAME_NAME_ONLY。
  2. 为了获取返回类型,我做了一个以 NO_FUNCTION_RETURNS 结尾的 COMPLETE 子字符串
  3. 为了获取参数,我做了一个 COMPLETE 的子字符串,从 NAME 末尾开始,以 COMPLETE.size() 结束

测试后的效果如何:

function : ?encrypt@@YAPADPAD@Z 
fullName : char * __cdecl encrypt(char*)

SymbolInfo.name : encrypt 
SymbolInfo.returnType : char *
SymbolInfo.parameters : (char *)
Run Code Online (Sandbox Code Playgroud)