Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get function parameters name visual studio

Tags:

c++

visual-c++

I am trying to get a list of parameters and the return type from a mangled function compiled in visual studio.

I know that I can use

UnDecorateSymbolName(function.c_str(), undecoratedName, 200, UNDNAME_COMPLETE))

but this just gives me another string, and I have to figure out if the string starts with a return type, or a specifier.

Is there a function to return SymbolNameInfo? Something along the lines:

struct SymbolInfo
{
    char[255] symbolName
    char[255] returnType
    char[255] parameters
};
like image 653
Bartlomiej Lewandowski Avatar asked Jan 03 '14 13:01

Bartlomiej Lewandowski


People also ask

How do I view parameters in Visual Studio?

This feature has now been released in the latest product update released version Visual Studio 2019 version 16.8. To access this feature, you will need to turn this option on in Tools > Options > Text Editor > C# or Basic > Advanced and select Display inline parameter name hints (experimental).

How do I get hints for Visual Studio code?

You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.)

What is inline parameter?

Inline Parameter refactoring This refactoring allows you to replace a method parameter with argument value from a method call. If there are several calls, you can choose the call to take the argument from.


1 Answers

I managed to find an answer. It's not perfect, maybe someone else will have some better idea.

What I did was use

UnDecorateSymbolName(function.c_str(), undecoratedName, 200, UNDNAME_COMPLETE))

with different flags.

The flags I used with explanation:

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

I used these 3 flags to do the following:

  1. To get the name, I just used UNDNAME_NAME_ONLY.
  2. To get the return type, I did a substring of COMPLETE ending at NO_FUNCTION_RETURNS
  3. To get the parameters, I did a substring of COMPLETE starting at the end of NAME ending at COMPLETE.size()

How this looks after test:

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

SymbolInfo.name : encrypt 
SymbolInfo.returnType : char *
SymbolInfo.parameters : (char *)
like image 61
Bartlomiej Lewandowski Avatar answered Oct 08 '22 01:10

Bartlomiej Lewandowski