I just compiled the following on VS2010(with optimization turned off).
class Shape {
public:
int x,y;
Shape() {
x=10;
y=20;
}
virtual void function1() {
cout<<"function1";
}
virtual void function2() {
cout<<"function2";
}
};
int main() {
Shape *s = new Shape();
s->function1();
s->function2();
return 0;
}
The disassembly does not show the code blocks corresponding to the virtual functions or any calls to it, so Im assuming that it is because of the way virtual functions are looked up using the vftable. I’m using IDA Pro so it is probably not able to resolve such issues. Please correct me if I’m wrong.
I also have a few doubts in this regard.
- Is there any way I can view the virtual functions just as the other functions during disassembly? Any script(IDAPython)/method that I could use?
- Is there any way I can list all virtual functions in an executable?
- Suggested Reading?
Virtual dispatch is only involved when the dynamic type of an object is different from its static type (pointer-to-Base pointing to a derived class). Since you don’t even have inheritance, and an exact type at the call site, why should it do the lookup in the vtable?