Overriding C++ virtual functions at run time
blog.visionappster.com
Overriding C++ virtual functions at run time
1–10 of 39 posts
Re: Overriding C++ virtual functions at run time
#2Re: Overriding C++ virtual functions at run time
#3wishful thinking: https://gcc.godbolt.org/z/qWEe9r
Re: Overriding C++ virtual functions at run time
#4I don’t think the articles vtable layout is entirely accurate for gcc though - usually you’ll get 2 destructors at the start of the vtable (assuming the first virtual func declared is the destructor).
Re: Overriding C++ virtual functions at run time
#5Re: Overriding C++ virtual functions at run time
#6> The C++ standard does not specify how virtual functions should be implemented. In practice, however, compilers generate a virtual function table and place a pointer to it as the first member of a class. wishful thinking: https://gcc.godbolt.org/z/qWEe9r
Re: Overriding C++ virtual functions at run time
#7> The C++ standard does not specify how virtual functions should be implemented. In practice, however, compilers generate a virtual function table and place a pointer to it as the first member of a class. wishful thinking: https://gcc.godbolt.org/z/qWEe9r
Obviously if you enable optimizations and one of those optimizations is avoiding the virtual call when the compiler thinks it isn't necessary, then sure you wont get a virtual call everywhere.
But if your code is relying on implementation assumptions like having a vtable at the start of a class, then it should also make sure that this assumption holds by not trying to work around it (e.g. via final) and using compiler options that control that optimization (e.g. GCC has -fno-devirtualize).
It doesn't make much sense to both try and take advantage of implementation details and work against taking advantage of implementation details at the same time.
Re: Overriding C++ virtual functions at run time
#8Re: Overriding C++ virtual functions at run time
#9As you might imagine, overwriting vtables in memory is a common technique to hijack control flow and making your program execute attacker's code in an exploit.