Skip to content

Instantly share code, notes, and snippets.

@byteandahalf
Last active March 23, 2020 17:11
Show Gist options
  • Save byteandahalf/49e7c67f850489d41cd6 to your computer and use it in GitHub Desktop.
Save byteandahalf/49e7c67f850489d41cd6 to your computer and use it in GitHub Desktop.
How to demangle C++
Let's say we have this mangled symbol: _ZN5Class8functionEiifb10OtherClass
To demangle this, we start by removing the _Z (I'm not sure what this means)
N means that the following is the class name (There is no N is classless functions)
Next is the length of the class name (in this case 5), followed by the class name (Class)
Class::
Now we have the length of the function name (8 here) and then the function name (function)
Class::function
The pars are the hard part. The pars begin after the capital 'e' (E). Each C++ type has its own letter, I've listed a few here:
i = int
b = bool
d = double
f = float
c = char
a = signed char
Ss = string (I think the S means std::, and the s means string)
A sole 'v' means that there are no parameters, and is only there to differentiate a static variable symbol from a function with no pars (_ZN4Hihi5thingEv is Hihi::thing(); and _ZN4Hihi5thingE is Hihi::thing;)
Now for parameters that are classes, they are just like the class and function names: The length, and then the name
10OtherClass, in this case (OtherClass is 10 letters long)
Last but not least we have the const, references, and pointers. These are denoted as K, R, and P respectively.
These appear before the parameter, so an int* looks like Pi, a const float looks like Kf, a bool reference looks like Rb, and an int const& look like RKi. When looking at class parameters this letter appears before the class length (RK10OtherClass is an OtherClass const&)
After all of this, our mangled symbol from above should look like this:
Class::function(int, int, float, bool, OtherClass);
:)
Here's a few more examples:
_ZN4Item16setDescriptionIdERKSs = Item::setDescriptionId(std::string const&)
_ZN4Tile7getNameEv = Tile::getName()
_ZN4Tile11setMaterialEPK8Material = Tile::setMaterial(Material const*)
_ZN12ItemInstance9setThingyEiiibfddaP4Tile = ItemInstance::setThingy(int, int, int, bool, float, double, double, signed char, Tile*)
@ThePixelGamer
Copy link

what about t? :P
(by the way its unsigned short)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment