struct C041 { C041() : c_(0x01) {} virtual void foo() { c_ = 0x02; } char c_; }; |
C041 obj; PRINT_DETAIL(C041, obj) PRINT_VTABLE_ITEM(obj, 0, 0) obj.foo(); C041 * pt = &obj; pt->foo(); |
The detail of C041 is 14 b3 45 00 01 obj : objadr:0012F824 vpadr:0012F824 vtadr:0045B314 vtival(0):0041DF1E |
004230DF lea ecx,[ebp+FFFFF948h] 004230E5 call 0041DF1E |
01 004263F0 push ebp 02 004263F1 mov ebp,esp 03 004263F3 sub esp,0CCh 04 004263F9 push ebx 05 004263FA push esi 06 004263FB push edi 07 004263FC push ecx 08 004263FD lea edi,[ebp+FFFFFF34h] 09 00426403 mov ecx,33h 10 00426408 mov eax,0CCCCCCCCh 11 0042640D rep stos dword ptr [edi] 12 0042640F pop ecx 13 00426410 mov dword ptr [ebp-8],ecx 14 00426413 mov eax,dword ptr [ebp-8] 15 00426416 mov byte ptr [eax+4],2 16 0042641A pop edi 17 0042641B pop esi 18 0042641C pop ebx 19 0042641D mov esp,ebp 20 0042641F pop ebp 21 00426420 ret |
值得注意的是第14、15行。第14行把this指针的值移到eax寄存器中,第15行给类的第一个成员变量赋值,这时我们可以看到在取变量的地址时用的是[eax+4],即跳过了对象布局最前面的4字节的虚表指针。