Jump to content
  • Advertisement
Sign in to follow this  
SteveDeFacto

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 __stdcall

void EXP_FUNC Add(int x1, int x2);



.cpp

void EXP_FUNC Add(int x1, int x2)
{

}

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Vortez
Ah, 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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!