12

At a post of Raymond Chen, he seems to be able to know the function's undecorated name from the decorated name. I have no idea how could he do this.

In this decorated name,

?GetName@PushButton@UILibrary@@UAEPB_WPAPAVStringHolder@2@@Z

What does the each component mean?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Benjamin
  • 10,085
  • 19
  • 80
  • 130
  • 1
    Consult your implementation's documentation or play a bit around with a demangler and learn the most common patterns. – Xeo Feb 07 '12 at 14:03
  • 1
    The answer is in the blog. "We ask the undname program". With a little training you could read such names yourself, just generate a few decorated names from sources you know, but the complete rules are complex (as the c++ type system is complex) and it is not worth discovering and learning them. – Suma Feb 07 '12 at 14:06
  • 1
    Possible duplicate of http://stackoverflow.com/q/1617204/471164 – vitaut Feb 07 '12 at 16:51
  • Does this answer your question? [undecorate function names with visual studio sdk](https://stackoverflow.com/questions/1617204/undecorate-function-names-with-visual-studio-sdk) – bobobobo May 24 '21 at 17:52

3 Answers3

15

To avoid guessing, and still not really use tools, the UnDecorateSymbolName function may be of use. I would hope that gives an authoritative correct answer.

To do it manually, this page has some information on the scheme, as do these.

The basic outline is _name@scope@scope@@parameters@something@@something. I suspect the last two parts are stack size and calling convention or similar, but the documentation likely has more detail.

Paul
  • 6,061
  • 6
  • 39
  • 70
ssube
  • 47,010
  • 7
  • 103
  • 140
  • +1 Thanks for the link. Much complicate than I expected, though -_-; – Benjamin Feb 07 '12 at 17:02
  • The biggest chunk (name and containing scopes) is pretty simple, just listed in reverse order. Apparently the prefix is pretty well documented, and I have seen (but can't find) the scheme for the parameters. – ssube Feb 07 '12 at 18:07
7

Microsoft Visual Studio comes with a undname.exe tool.

http://msdn.microsoft.com/en-us/library/ms937379.aspx

If you have MS VS at a default location you can use:

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\undname.exe" ?GetName@PushButton@UILibrary@@UAEPB_WPAPAVStringHolder@2@@Z

Microsoft (R) C++ Name Undecorator Copyright (C) Microsoft Corporation. All rights reserved.

Undecoration of :- "?GetName@PushButton@UILibrary@@UAEPB_WPAPAVStringHolder@2@@Z" is :- "public: virtual wchar_t const * __thiscall UILibrary::PushButton::GetName(class UILibrary::StringHolder * *)"

Community
  • 1
  • 1
Slava Litvinov
  • 392
  • 3
  • 7
7

Name mangling is compiler dependant.

In the article you linked, Raymond is using an MS util (undname) to remove the mangling.

Here is a table showing how common compilers mangle.

GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
  • 1
    With the `visual-studio` tag, the question is also compiler dependent, and this doesn't help answer it at all. – ssube Feb 07 '12 at 14:08
  • Yes I saw that, but I feel he could demangle the name by himself at the last simple example. Okay, then isn't there no way to guess it easily? – Benjamin Feb 07 '12 at 14:09
  • 1
    @peachykeen: `undname` is a Microsoft tool, and as such tightly bound to Visual Studio. I don't see the problem with this answer. – Xeo Feb 07 '12 at 14:10
  • There are rules, like ? is followed by a name of a member function, @ means a scope, T, U, V are followed by a union, struct, class names, other letters mean builtin types - if you are really interested, just generate a few mangled names from declarations you know and you will soon learn the basic patterns used. – Suma Feb 07 '12 at 14:15
  • 3
    @Benjamin: There is a simple way to guess: experience. The mangling of a particular compiler is fixed and defined. After some time looking at mangled and unmangled names you can recognize common patterns and won't need to look at the docs every time. – David Rodríguez - dribeas Feb 07 '12 at 14:33