Get signature from C++ function name?

This topic is 3079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I exported a function from my DLL called "add" which just adds two ints together and returns the sum. I exported it as a C++ function in order to get the signature from the name, I know it can be done but I don't know how to do it. "?add@@YAHHH@Z" is the name of the function after it is exported from the DLL, now how do I get data which represents the signature from that?

Share on other sites
A quick Google of "unmangle C++ name" turns up this and this. They should get you on the right track :)

Share on other sites
Note that while this will work as long as your functions export only simple types (int, float, etc), it won't be much good if they export more "complex" types. For example, if the method takes a class or struct, you'll be able to find out the name of the struct, but that won't tell you anything about the members of that struct.

That may or may not be important, of course...

Share on other sites
You're pretty much out of luck here. The name mangling algorithm is undocumented, and while there's been some work into reverse engineering it, it's not complete.

If symbol files for the DLL are present, you can use the DBGHELP api and/or the DIA SDK. Be warned however, this is no easy task. There are lots of little corner cases to handle if you want to be able to parse arbitrarily complex function signatures.

Share on other sites
Hmm, I admit I didn't know about this function. My response came from the fact that I once implemented my own undecoration based on DIA SDK because I actually needed semantic info about the types of various arguments, as opposed to just a flat textual representation of the entire signature. I guess if the OP doesn't need that though, perhaps this function suffices.

Share on other sites
Arent you guys overcomplicating this? All i do when i want to unmangle exported function name from a dll project is to add a simple .def file to it, wich look like this:

EXPORTS
SomeFunction @1
SomeOtherFunction @2
... ect

in your case, it should look that way:

.def file
EXPORTS    Add       @1

.h file
#define EXP_FUNC __stdcallvoid EXP_FUNC Add(int x1, int x2);

.cpp
void EXP_FUNC Add(int x1, int x2){}

Share on other sites
Original post by Vortez
Arent you guys overcomplicating this? All i do when i want to unmangle exported function name from a dll project is to add a simple .def file to it, wich look like this:/quote]

His original problem statement implies that he wants to take an EXISTING dll file, for which he does not necessarily have source code and cannot recompile, and DETERMINE at runtime the signature of every function exported by that dll. He doesn't want to actually produce DLL files whose exported function names are unmangled, because as you mention, that is easy.

Share on other sites
Ah, i though it was is own dll.

Share on other sites
Quote:
 Original post by VortezAh, i though it was is own dll.

Well actually when I read it again, you're right it does say it's his own DLL. But still, the problem with C++ is that you can export classes and member functions. And for this to work, it has to mangle the name, If he's only exporting global functions and no class types, then maybe your solution is appropriate

Share on other sites
Quote:
 His original problem statement implies that he wants to take an EXISTING dll file, for which he does not necessarily have source code and cannot recompile, and DETERMINE at runtime the signature of every function exported by that dll. He doesn't want to actually produce DLL files whose exported function names are unmangled, because as you mention, that is easy.

Not necessarily, it is my own DLL but the reason I want to demangle the names is not only to get the name but also the structure of the function, if there is another way to get the structure of a function from the DLL please tell me because I would love to be able to support functions that are exported as C functions.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631773
• Total Posts
3002268
×