Search code examples
c++assemblydecompiler

How to read this decompiled statement?


When I decompiled a function I got the following code

((void(__thiscall**)(int))(*v4 + 4))(v4);

*v4 in this context is a virtual table. I can't really break it down (who is resolved first and the exact meaning of it).

I'd kindly ask you to help me resolving this step by step so I can understand how this works.


Solution

  • (
        (   // these parens around the type declaration are a cast
            void (__thiscall**)(int) // this type declaration:
                                     // a pointer to pointer to function taking int parameter
        )
        (*v4 + 4) // this is a pointer expression
                  // this pointer is being cast to a function
    ) // this is a function pointer
    ( // these paren's invoke the function
        v4     // this is the parameter being passed to the function 
    );
    

    The only thing that is strange is that v4, passed as parameter, is not an int as the cast says — it is a pointer.

    It looks like v4 is an object, and the vtable is the first member of the object, so *v4 refers to the vtable. *v4+4 refers to the 5th vtable entry.