Protected of CPP Disassembly

Source: Internet
Author: User

Protected keywords:

Excerpt from MSDN

protected The member-list keyword specifies access to the member in the group until the end of the next access descriptor (public or private) or class definition. class members declared as protected can only be used with the following:

    • The member functions of the class that originally declared these members.

    • The friend of the class that originally declared these members.

    • Classes derived from public or protected access (derived from the class that originally declared these members).

    • A direct class that derives private access to the protected member as well.

When starting with the name of the base class, theprotected keyword specifies that the public and protected members of the base class are the protected members of their derived classes.

Protected members are not dedicated as private members, and private members are accessible only to the members of the class from which they are declared, but the protected members are not as exposed as the public member, which is accessible in any function.

Protected members that are also declared as static are accessible to any friend or member function of a derived class. a protected member that is also declared as static can be accessed by a friend or member function in a derived class, but only by pointing to a pointer to a derived class, to a reference to a derived class, or to an object of a derived class.

Private: only 1. The function in the class, 2. Its friend function is accessed. the object of the class cannot be accessed by any other access.
protected: can be 1. A function in this class, a function of 2. Subclass, and 3. Its friend function is accessed. but cannot be accessed by objects of that class.
Public : can be 1. The function in the class, the function of the 2. Subclass, 3. Its friend function is accessed by 4. The object of the class.

An example is analyzed below

#include <iostream>using namespace Std;class base {public    :    base (int j): I (j)  {}    virtual~base () {}//   virtual void func1 () {        I *=;        Func2 (); Call Subclass    }    int GetValue () {        return  i;    }    Protected:    virtual void Func2 () {        i++;    }    Protected:    int i;}; Class Child:public Base {public    : child    (int J): Base (j) {}    void Func1 () {        I *=;        Func2 ();    }    Protected:    void Func2 () {        i + = 2;    }}; int main () {    Base * PB = new Child (1);    PB->FUNC1 ();//The This pointer here does not change  only one object    cout << pb->getvalue () << Endl; delete pb;}
Output: 12

Here's the disassembly code.

1: #include <iostream>2:using namespace Std;3:4: class Base {5:public:6: Base (int J): I (J) {}00401800 Push ebp00401801 mov ebp,esp00401803 sub esp,44h00401806 push ebx0040180         7 Push esi00401808 push edi00401809 push ecx0040180a Lea EDI,[EBP-44H]0040180D mov ECX,11H00401812 mov eax,0cccccccch00401817 rep stos dword ptr [edi]00401819 pop ecx004018 1 a MOV DWORD ptr [ebp-4],ecx0040181d mov eax,dword ptr [ebp-4]00401820 mov ecx,dword ptr [eb p+8]00401823 mov dword ptr [eax+4],ecx00401826 mov edx,dword ptr [ebp-4]00401829 mov DWORD P   TR [edx],offset Base:: ' vftable ' (0046e028) 0040182F mov eax,dword ptr [ebp-4]00401832 pop edi00401833 Pop esi00401834 pop ebx00401835 mov esp,ebp00401837 pop ebp00401838 ret 4 7:virtual~base () {}00401900 Push ebp00401901 mov ebp,esp00401903 sub esp,44h00401906 push ebx0040190         7 Push esi00401908 push edi00401909 push ecx0040190a Lea EDI,[EBP-44H]0040190D mov ecx,11h00401912 mov eax,0cccccccch00401917 rep stos dword ptr [edi]00401919 pop ecx004019 1 a MOV DWORD ptr [EBP-4],ECX0040191D mov eax,dword ptr [ebp-4]00401920 mov dword ptr [Eax],o Ffset Base:: ' vftable ' (0046e028) 00401926 pop edi00401927 pop esi00401928 pop ebx00401929 m          OV esp,ebp0040192b pop ebp0040192c ret8:void func1 () {004016f0 push EBP004016F1 mov Ebp,esp004016f3 Sub Esp,44h004016f6 push ebx004016f7 push Esi004016f8 push E DI004016F9 push ECX004016FA Lea EDI,[EBP-44H]004016FD mov ecx,11h00401702 mov eax,0 CCCCCCCCh00401707 RepSTOs DWORD ptr [edi]00401709 pop ecx0040170a mov dword ptr [ebp-4],ecx//this9:i *= 10;0 040170D mov eax,dword ptr [ebp-4]00401710 mov ecx,dword ptr [eax+4]00401713 imul ecx,ecx,0ah0 0401716 mov edx,dword ptr [ebp-4]00401719 mov dword ptr [EDX+4],ECX10:FUNC2 (); 0040171C mo         V eax,dword ptr [ebp-4]0040171f mov edx,dword ptr [eax]00401721 mov esi,esp00401723 mov        Ecx,dword PTR [ebp-4]//this00401726 call DWORD ptr [edx+4]00401729 CMP esi,esp0040172b call __CHKESP (00420E90) One:}00401730 pop edi00401731 pop esi00401732 pop ebx00401733 A DD esp,44h00401736 CMP ebp,esp00401738 call __CHKESP (00420e90) 0040173D mov esp,ebp00 40173F pop ebp00401740 ret12:int getValue () {00401760 push ebp00401761 mov ebp,esp00 401763 Sub ESP, 44h00401766 push ebx00401767 push esi00401768 push edi00401769 push ecx0040176a Lea EDI,[EBP-44H]0040176D mov ecx,11h00401772 mov eax,0cccccccch00401777 rep stos dword ptr         [edi]00401779 pop ecx0040177a mov dword ptr [Ebp-4],ecx13:return i;0040177d mov         Eax,dword ptr [ebp-4]00401780 mov eax,dword ptr [eax+4]14:}00401783 pop edi00401784 Pop esi00401785 pop ebx00401786 mov esp,ebp00401788 pop ebp00401789 ret15:protected: 16:virtual void Func2 () {00401850 push ebp00401851 mov ebp,esp00401853 sub esp,44h0040         1856 push ebx00401857 push esi00401858 push edi00401859 push ecx0040185a Lea EDI,[EBP-44H]0040185D mov ecx,11h00401862 mov eax,0cccccccch00401867 rep stos dword ptr [edi]004 01869 Pop ecx0040186A mov dword ptr [ebp-4],ecx17:i++;0040186d mov eax,dword ptr [ebp-4]00401870 mov         Ecx,dword ptr [eax+4]00401873 add ecx,100401876 mov edx,dword ptr [ebp-4]00401879 mov DWORD ptr [edx+4],ecx18:}0040187c pop edi0040187d pop esi0040187e pop ebx0040187f m OV esp,ebp00401881 pop ebp00401882 ret19:protected:20:int i;21:};22:class child:p Ublic Base {23:public:24:child (int J): Base (j) {}004017a0 push EBP004017A1 mov ebp,esp004        017a3 Sub esp,44h004017a6 push ebx004017a7 push esi004017a8 push edi004017a9 push   ECX004017AA Lea EDI,[EBP-44H]004017AD mov ecx,11h004017b2 mov eax,0cccccccch004017b7 Rep STOs dword ptr [edi]004017b9 pop ecx004017ba mov dword ptr [EBP-4],ECX004017BD mov E Ax,dword ptr [ebp+8]004017C0 push EAX004017C1 mov ecx,dword ptr [ebp-4]004017c4 call @ILT +35 (base::base) (00401028) 004    017C9 mov ecx,dword ptr [ebp-4]004017cc mov dword ptr [Ecx],offset Child:: ' vftable ' (0046e01c) 004017d2    mov Eax,dword ptr [ebp-4]004017d5 pop edi004017d6 pop esi004017d7 pop Ebx004017d8 Add esp,44h004017db cmp ebp,esp004017dd call __CHKESP (00420e90) 004017E2 mov esp,e Bp004017e4 pop ebp004017e5 ret 425:void func1 () {26:i *= 100;27:func2 (); 2 8:}29:protected:30:void Func2 () {00401940 push ebp00401941 mov ebp,esp00401943 s UB esp,44h00401946 Push ebx00401947 push esi00401948 push edi00401949 push ECX     0040194A Lea EDI,[EBP-44H]0040194D mov ecx,11h00401952 mov eax,0cccccccch00401957 rep stos DWORD ptr [edi]00401959 pop ecx0040195a mov dword ptr [ebp-4],ecx31:i + 2;0040195d mov eax,dword ptr [ebp-4]00401960 mov ecx,dword ptr [eax+4]00401963 add ecx,200401966 mov edx,dword ptr [ebp- 4]00401969 mov dword ptr [edx+4],ecx32:}0040196c pop edi0040196d pop esi0040196e po P ebx0040196f mov esp,ebp00401971 pop ebp00401972 ret33:};34:int main () {004015d0 PU SH ebp004015d1 mov ebp,esp004015d3 push 0ffh004015d5 push offset __ehhandler$_main (004 47C4B) 004015DA mov eax,fs:[00000000]004015e0 push eax004015e1 mov dword ptr fs:[0],esp004015e         8 Sub Esp,5ch004015eb push EBX004015EC push esi004015ed push Edi004015ee Lea EDI,[EBP-68H]004015F1 mov ECX,17H004015F6 mov eax,0cccccccch004015fb rep stos dword ptr [edi]35 : Base * PB = newChild (1), 004015FD push 8004015FF call operator new (004209A0) 00401604 add esp,400401607 mov DWORD ptr [EBP-18H],EAX0040160A mov dword ptr [ebp-4],000401611 cmp dword ptr [ebp-18h],000401         615 JE main+56h (00401626) 00401617 push 100401619 mov ecx,dword ptr [ebp-18h]0040161c call @ILT +405 (Child::child) (0040119a) 00401621 mov dword ptr [EBP-24H],EAXEAX = = ecx00401624 jmp ma         IN+5DH (0040162d) 00401626 mov dword ptr [ebp-24h],00040162d mov eax,dword ptr [ebp-24h]00401630 mov DWORD ptr [ebp-14h],eax00401633 mov dword ptr [ebp-4],0ffffffffh0040163a mov ecx,dword ptr [eb p-14h]0040163d mov dword ptr [Ebp-10h],ecxthis36:pb->func1 (); 00401640 mov ecx,dword ptr [ebp -10h]00401643 call @ILT +160 (BASE::FUNC1) (004010a5) this37:cout << pb->getvalue () << endl;00 401648 Push offSet @ILT +220 (Std::endl) (004010e1) 0040164D mov ecx,dword ptr [ebp-10h]00401650 call @ILT +575 (Base::getv Alue) (00401244) 00401655 push eax00401656 mov ecx,offset std::cout (0047be90) 0040165B call @IL t+280 (std::basic_ostream<char,std::char_traits<char> >::operator<<) (0040111d) 00401660 mov ecx , eax00401662 call @ILT +515 (std::basic_ostream<char,std::char_traits<char> >::operator<<) (00401 208) 38:delete pb;00401667 mov edx,dword ptr [ebp-10h]0040166a mov dword ptr [ebp-20h],edx004016 6D mov eax,dword ptr [ebp-20h]00401670 mov dword ptr [ebp-1ch],eax00401673 cmp dword ptr [EB         p-1ch],000401677 JE main+0c3h (00401693) 00401679 mov esi,esp0040167b push 10040167D mov Ecx,dword ptr [ebp-1ch]00401680 mov edx,dword ptr [ecx]00401682 mov ecx,dword ptr [ebp-1ch]00401 685 Call DWORDPTR [edx]00401687 cmp esi,esp00401689 call __CHKESP (00420E90) 0040168E mov dword ptr [ebp-28h         ],eax00401691 jmp Main+0cah (0040169a) 00401693 mov dword ptr [ebp-28h],039:}0040169a mov Ecx,dword ptr [ebp-0ch]0040169d mov dword ptr fs:[0],ecx004016a4 pop edi004016a5 pop esi0040 16A6 pop ebx004016a7 Add ESP,68H004016AA cmp ebp,esp004016ac call __CHKESP (00420e9   0) 004016B1 mov esp,ebp004016b3 pop ebp004016b4 ret@ilt+160 ([email protected]@ @QAEXXZ): 004010a5 JMP base::func1 (004016f0) @ILT +130 ([email protected]@[email protected]): 00401087 jmp base::~ Base (00401900) @ILT +55 ([email protected]@ @MAEXXZ): 0040103C jmp child::func2 (00401940) @ILT +35 ([email p ROTECTED]@[EMAIL&NBSP;PROTECTED]@Z): 00401028 jmp base::base (00401800) @ILT +40 ([email protected]@ @MAEXXZ): 00 40102D jmp BasE::FUNC2 (00401850) @ILT +130 ([email protected]@[email protected]): 00401087 jmp base::~base (00401900) @I lt+405 ([email protected]@[email protected]@z): 0040119A jmp child::child (004017a0) @ILT +575 ([email&nbsp ;p rotected]@ @QAEHXZ): 00401244 jmp base::getvalue (00401760) @ILT +585 (_main): 0040124E jmp Main (004015d0 ) @ILT +610 ([email protected]@[email protected]): 00401267 jmp Child:: ' scalar deleting destructor ' (00401 980) @ILT +615 ([email protected]@[email protected]): 0040126C jmp Base:: ' scalar deleting destructor ' (004 01890) @ILT +660 ([email protected]@[email protected]): 00401299 jmp child::~child (004019f0) @ILT +575 ([EMA il protected]@ @QAEHXZ): 00401244 jmp base::getvalue (00401760) @ILT +585 (_main): 0040124E jmp Main (0 04015D0) @ILT +575 ([email protected]@ @UAEXXZ): 00401244 jmp child::func1 (00401960) Child:: ' scalar deleting des Tructor ': 00401980 push        ebp00401981 mov ebp,esp00401983 Sub esp,44h00401986 push ebx00401987 push ES i00401988 push edi00401989 push ecx0040198a Lea EDI,[EBP-44H]0040198D mov ecx,11h004 01992 mov eax,0cccccccch00401997 rep stos dword ptr [edi]00401999 pop ecx0040199a mov D Word ptr [ebp-4],ecx0040199d mov ecx,dword ptr [ebp-4]004019a0 call @ILT +660 (child::~child) (00401299) 0          04019A5 mov eax,dword ptr [ebp+8]004019a8 and eax,1004019ab Test Eax,eax004019ad JE Child:: ' scalar deleting destructor ' +3bh (004019BB) 004019AF mov ecx,dword ptr [ebp-4]004019b2 push ECX 004019B3 call operator Delete (00406D20) 004019b8 add ESP,4004019BB mov eax,dword ptr [ebp-4]0         04019BE pop edi004019bf pop esi004019c0 pop ebx004019c1 add ESP,44H004019C4 cmp Ebp,esp004019c6  Call __chkesp (00420E90) 004019CB mov esp,ebp004019cd pop ebp004019ce ret 4Base:: ' SC   Alar deleting destructor ': 00401890 push ebp00401891 mov ebp,esp00401893 sub esp,44h00401896 Push ebx00401897 push esi00401898 push edi00401899 push ecx0040189a Lea edi,[   EBP-44H]0040189D mov ECX,11H004018A2 mov eax,0cccccccch004018a7 rep stos dword ptr [EDI]004018A9        Pop ECX004018AA mov dword ptr [EBP-4],ECX004018AD mov ecx,dword ptr [ebp-4]004018b0 call @ILT +130 (base::~base) (00401087) 004018B5 mov eax,dword ptr [ebp+8]004018b8 and EAX,1004018BB t  Est eax,eax004018bd je Base:: ' scalar deleting destructor ' +3bh (004018CB) 004018BF mov Ecx,dword PTR [EBP-4]004018C2 push ecx004018c3 call operator delete (00406D20) 004018c8 add esp,4004018c B mov eax,dworD ptr [ebp-4]004018ce pop edi004018cf pop esi004018d0 pop ebx004018d1 add esp,44h0         04018D4 CMP Ebp,esp004018d6 call __CHKESP (00420e90) 004018DB mov esp,ebp004018dd pop EBP004018DE ret 4Child:: ' scalar deleting destructor ': 00401980 push ebp00401981 mov ebp,esp0         0401983 Sub esp,44h00401986 push ebx00401987 push esi00401988 push edi00401989 push    ecx0040198a Lea edi,[ebp-44h]0040198d mov ecx,11h00401992 mov eax,0cccccccch00401997         Rep STOs dword ptr [edi]00401999 pop ecx0040199a mov dword ptr [EBP-4],ECX0040199D mov Ecx,dword ptr [ebp-4]004019a0 call @ILT +660 (child::~child) (00401299) 004019A5 mov eax,dword ptr [ebp+8 ]004019a8 and eax,1004019ab Test eax,eax004019ad JE Child:: ' scalar deleting destructor ' +3bh (004019BB) 004019AF mov         Ecx,dword ptr [ebp-4]004019b2 push ecx004019b3 call operator delete (00406D20) 004019b8 add         ESP,4004019BB mov eax,dword ptr [ebp-4]004019be pop edi004019bf pop esi004019c0 pop   EBX004019C1 Add ESP,44H004019C4 cmp ebp,esp004019c6 call __CHKESP (00420E90) 004019CB   mov esp,ebp004019cd pop ebp004019ce ret 4child::~child:004019f0 push EBP004019F1        MOV ebp,esp004019f3 sub esp,44h004019f6 push ebx004019f7 push esi004019f8 push EDI004019F9 push ECX004019FA Lea EDI,[EBP-44H]004019FD mov ECX,11H00401A02 mov ea X,0cccccccch00401a07 Rep stos dword ptr [edi]00401a09 pop ecx00401a0a mov dword ptr [ebp-4],ecx00 401A0D mov ecx,dword ptr [ebp-4]00401a10 call @ILT +130 (base::~base) (00401087) 00401a15 pop Ed         I00401a16 PopEsi00401a17 pop ebx00401a18 Add esp,44h00401a1b cmp ebp,esp00401a1d call __CHKESP ( 00420E90) 00401a22 mov esp,ebp00401a24 pop ebp00401a25 ret if changed to virtual function func1 () 36:pb->func1 (); 004 01650 mov edx,dword ptr [ebp-10h]00401653 mov eax,dword ptr [edx]00401655 mov esi,esp0040165 7 mov ecx,dword PTR [ebp-10h]0040165a call DWORD ptr [EAX+4]


Protected of CPP Disassembly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.