Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Platform:Microsoft Visual C++ ABI/Name decoration

From ReverseEngineering.wiki

How MSVC decorates (mangles) C++ names: '?' + name + '@'-terminated scopes + '@' + codes for access, calling convention and types; special names for constructors, vftables and RTTI records; and the number encoding used inside them. Test vectors were decoded with undname.exe from Visual Studio 2022.

Structure

A decorated function name is ?<name>@<scope>@...@@<function class>[<this qualifiers>]<calling convention><return type><parameter types>@Z; a function without parameters ends in XZ (X = void). Scopes are listed innermost first. Data: ?<name>@<scope>@@<storage class><type><cv>, e.g. ?counter@Klass@@2HA (2 = public static member).

  • Back references: a digit 0-9 instead of a name repeats the n-th name already seen in this symbol (??_7Duck@zoo@@6BSwimmer@1@@: 1 = zoo). Digits also back-reference earlier parameter types.
  • Special names start with ??: ??0 constructor, ??1 destructor, ??_7 vftable, ??_8 vbtable, ??_G scalar deleting destructor, ??_E vector deleting destructor, ??_R0-??_R4 RTTI records (Platform:Microsoft Visual C++ ABI/RTTI), ??_C@_ string literals, ??2/??3 operator new/delete, ??4 operator=; ??$name@<args>@ template functions; ?$ in type names (.?AU?$Box@H@zoo@@ = zoo::Box<int>).
  • EH records (no leading ?): _TI<n><type> ThrowInfo, _CTA<n><type> CatchableTypeArray, _CT??_R0<type>@8<copy ctor><size> CatchableType. On x86 the linker adds the C _ prefix (__TI3?AUMyError@zoo@@).

Function class and calling convention

The letter after @@ for functions: Y global (Z far); members A-X in groups: private A (plain), C (static), E (virtual); protected I, K, M; public Q, S, U; G/O/W are this-adjusting thunks; each next letter (B, D, ...) is the far variant. Non-static members then carry the this qualifiers: on 64-bit targets E (__ptr64), then A (none), B (const), C (volatile), D (const volatile).

Calling convention letter: A __cdecl, C __pascal, E __thiscall, G __stdcall, I __fastcall, M __clrcall, Q __vectorcall (B, D, F, H, J, N decode to the same conventions). On x64 every function gets A.

Types

C signed char, D char, E unsigned char, F short, G unsigned short, H int, I unsigned int, J long, K unsigned long, M float, N double, O long double, X void; with _: _N bool, _J __int64, _K unsigned __int64, _W wchar_t, _Q char8_t, _S char16_t, _U char32_t. P pointer, A reference, $$Q rvalue reference, each followed (64-bit targets) by E and a cv letter (A none, B const) and the pointee: PEBD = char const * __ptr64, PBD = char const * on x86. Classes V<name>@@, structs U, unions T, enums W4.

Numbers

Used for template arguments and in BaseClassDescriptor names: A@ = 0; a digit 0-9 = 1-10; larger values are hexadecimal with the letters A-P for 0-15, ended by @ (BA@ = 0x10 = 16, EA@ = 0x40 = 64, FA@ = 0x50 = 80); a leading ? negates (?0 = -1). So ??_R1A@?0A@EA@Animal@zoo@@8 is the descriptor at (mdisp 0, pdisp -1, vdisp 0, attributes 64) and ??_R1A@A@3FA@Base@zoo@@8 the one at (0, 0, 4, 80).

Test vectors

Names emitted by cl.exe 19.44 for one test source, decoded with undname.exe 14.44:

Decorated Decoded
?test_cdecl@@YAHHN@Z int __cdecl test_cdecl(int,double)
?test_stdcall@@YGHH@Z (x86) int __stdcall test_stdcall(int)
?test_fastcall@@YIHH@Z (x86) int __fastcall test_fastcall(int)
?test_stdcall@@YAHH@Z (x64) the same function built for x64: the convention letter becomes A
?method@Klass@@QEBAHPEBD@Z (x64) public: int __cdecl Klass::method(char const * __ptr64)const __ptr64
?method@Klass@@QBEHPBD@Z (x86) public: int __thiscall Klass::method(char const *)const
?make@@YAPEAUAnimal@zoo@@H@Z struct zoo::Animal * __ptr64 __cdecl make(int)
?say@Duck@zoo@@UEBAPEBDXZ public: virtual char const * __ptr64 __cdecl zoo::Duck::say(void)const __ptr64
??0Dog@zoo@@QEAA@XZ public: __cdecl zoo::Dog::Dog(void) __ptr64
??1Animal@zoo@@UEAA@XZ public: virtual __cdecl zoo::Animal::~Animal(void) __ptr64
??_GAnimal@zoo@@UEAAPEAXI@Z public: virtual void * __ptr64 __cdecl zoo::Animal::`scalar deleting destructor'(unsigned int) __ptr64
?counter@Klass@@2HA public: static int Klass::counter
??_7?$Box@H@zoo@@6B@ const zoo::Box<int>::`vftable'
??_8VLeft@zoo@@7B@ const zoo::VLeft::`vbtable'

undname.exe returns _TI3?AUMyError@zoo@@ unchanged: it does not decode the EH record names.

Pitfalls

  • Names longer than 4096 characters are replaced by ??@<md5>@ (clang reproduces this), so the original name cannot be recovered from such a symbol.
  • To decode a TypeDescriptor name (.?AV...), drop the '.' first.
  • extern "C" functions are not decorated this way: x86 __cdecl gets _name, __stdcall _name@<argument bytes>, __fastcall @name@<argument bytes>; x64 names are left as they are.

Evidence & references

  • llvm-project 8cdfc2de: llvm/lib/Demangle/MicrosoftDemangle.cpp (special prefixes 134-170, function classes 1672-1758, calling conventions 1760-1798, primitive types 2010-2075); clang/lib/AST/MicrosoftMangle.cpp (mangleNumber 977-996, RTTI and EH record names 4178-4383, TypeDescriptor name and its 4095-character hashing threshold 4236-4246); tests llvm/test/Demangle/ms-*.test.
  • Runtime test: names from the MAP files of x86 and x64 builds, decoded with undname.exe (Visual Studio 2022, MSVC 14.44.35207).