????c++?е???
???????????? ???????[ 2013/5/31 10:37:22 ] ????????
??????????м?й??????????????γ????vptr??????
??????????c++???
class X {
private:
int i;
public:
virtual void f() {}
};
class Y : public X {//Y?????X
private:
int j;
};
int main() {
Y y;
}
??????????main?????е?????
_main PROC
; 16 : int main() {
push ebp
mov ebp?? esp
sub esp?? 12 ; ?????y???12 byte???? vptr???4byte ??????????4byte ??????????4byte
; 17 : Y y;
lea ecx?? DWORD PTR _y$[ebp];???????y??????(??this???)????????????????????????
call ??0Y@@QAE@XZ;????y??????? ???y?????????幹?????????????京????????????????????????????
; 18 : }
xor eax?? eax
mov esp?? ebp
pop ebp
ret 0
_main ENDP
???????????????????????
??0Y@@QAE@XZ PROC ; Y::Y?? COMDAT
; _this$ = ecx
push ebp
mov ebp?? esp
push ecx;//??ecx?????????this???
mov DWORD PTR _this$[ebp]?? ecx;??this???(??????????)??????????? ecx?????????????
mov ecx?? DWORD PTR _this$[ebp];????????????ecx ????????????????????????
call ??0X@@QAE@XZ;???????????
mov eax?? DWORD PTR _this$[ebp];??y?????????????eax
mov DWORD PTR [eax]?? OFFSET ??_7Y@@6B@;??y??vtable(??_7Y@@6B@)????????y?????????????? ???????????vptr???
mov eax?? DWORD PTR _this$[ebp];??y??????eax????????????????????????????????
mov esp?? ebp
pop ebp
ret 0
??0Y@@QAE@XZ ENDP
??????????????????????
??0X@@QAE@XZ PROC ; X::X?? COMDAT
; _this$ = ecx
push ebp
mov ebp?? esp
push ecx;??????????????this???(?????????????)?????
mov DWORD PTR _this$[ebp]?? ecx;???????????????(ecx?б???)???????????
mov eax?? DWORD PTR _this$[ebp];???????????????????eax
mov DWORD PTR [eax]?? OFFSET ??_7X@@6B@;??vtable(??_7X@@6B@ ???????)????????????????????????? ??????????????vptr???
mov eax?? DWORD PTR _this$[ebp];?????????????????eax????????????????????????????????
mov esp?? ebp
pop ebp
ret 0
??0X@@QAE@XZ ENDP
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????ecx??????????????????????????????????vptr???λ??????????????????????????У?vptr???????????????????vtable??????????????????У???????????????????????vtable????????????????????У??????????漰??е????vptr???????????????????????
??????
![](/images/ad-banner/ad-banner.png)
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11