C++ type details
IDA can parse and handle simple C++ class declarations. It cannot parse templates and other complex constructs but simple standard cases can be parsed.
If a C++ class contains virtual functions, IDA will try to rebuild the virtual function table (VFT) for the class. The VFT will be linked to the class by the name: if the class is called "A", the VFT type will be "A_vtbl".
Let us consider the following class hierarchy:
IDA will create the following structures:
Please note that the VFT pointer in the class A has a special name: "__vftable". This name allows IDA to recognize the pointer as a VFT pointer and treat it accordingly.
Another example of more complex class hierarchy:
Compiling in 32-bit Visual Studio mode yields the following layout:
IDA will generate the following types:
The 'derived' class will use 2 VFTs:
IDA and Decompiler can use both VFTs and produce nice code for virtual calls.
Please note that the VFT layout will be different in g++ mode and IDA can handle it too. Therefore it is important to have the target compiler set correctly.
It is possible to build the class hierarchy manually. Just abide by the following rules:
C++ classes are marked with "__cppobj" keyword, it influences the class layout. However, this keyword is not required for VFT types.
In the case of a multiple inheritance it is possible to override a virtual table for a secondary base class by declaring a type with the following name: "CLASSNAME_XXXX_vtbl" where XXXX is the offset to the virtual table inside the derived (CLASSNAME) class.
Example: if in the above example we add one more function
then we need one more virtual table. Its name must be "derived_0008_vtbl". Please note that our parser does not create such vtables, you have to do it manually. See also Local types window.
Last updated