码迷,mamicode.com
首页 > 编程语言 > 详细

C++反汇编实例(1)-输出多行

时间:2015-04-01 14:59:15      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

程序说明:输出多行内容,内容如下:

   *

  ***

 *****

*******

 *****

  ***

   *

 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     cout << "   *" << endl;
 6     cout << "  ***" << endl;
 7     cout << " *****" << endl;
 8     cout << "*******" << endl;
 9     cout << " *****" << endl;
10     cout << "  ***" << endl;
11     cout << "   *" << endl;
12 
13     system("pause");
14     return 0;
15 }

debug下反汇编代码

int main()
{
00FF5E00  push        ebp  //进入函数后的第一件事,保存栈底指针,用来退出函数时还原栈底。
00FF5E01  mov         ebp,esp  //调整栈底指针到栈顶
00FF5E03  sub         esp,0C0h  //为局部变量申请内存空间
00FF5E09  push        ebx  
00FF5E0A  push        esi  
00FF5E0B  push        edi  //保存ebx,esi,edi,即保存现场,退出函数时还原。
00FF5E0C  lea         edi,[ebp-0C0h]  //将为局部变量分配的内存首地址放到edi中
00FF5E12  mov         ecx,30h  
00FF5E17  mov         eax,0CCCCCCCCh  //debug下,为调试方便,将所有局部变量初始化为0cccccccch。
00FF5E1C  rep stos    dword ptr es:[edi]  //用eax的值初始化到es:[edi]所指向的地址中(为局部变量分配的内存首地址),以dword(4字节)为单位,循环次数为ecx中的值。因为在一个函数内,
//为局部变量分配的内存空间是连续的,所以此句就是初始化所有局部变量为eax中的值。 cout
<< " *" << endl; 00FF5E1E mov esi,esp 00FF5E20 push 0FF14A6h 00FF5E25 push 0FFCC70h 00FF5E2A mov eax,dword ptr ds:[0100009Ch] 00FF5E2F push eax 00FF5E30 call std::operator<<<std::char_traits<char> > (0FF14BFh) //调用cout对象的operator<<成员函数(重载操作符<<)。 00FF5E35 add esp,8 00FF5E38 mov ecx,eax 00FF5E3A call dword ptr ds:[1000090h] 00FF5E40 cmp esi,esp 00FF5E42 call __RTC_CheckEsp (0FF132Fh) //debug下特有的函数,用来检测栈平衡。debug下函数退出时,都调用该函数。 cout << " ***" << endl; 00FF5E47 mov esi,esp 00FF5E49 push 0FF14A6h 00FF5E4E push 0FFCD24h 00FF5E53 mov eax,dword ptr ds:[0100009Ch] 00FF5E58 push eax 00FF5E59 call std::operator<<<std::char_traits<char> > (0FF14BFh) 00FF5E5E add esp,8 00FF5E61 mov ecx,eax 00FF5E63 call dword ptr ds:[1000090h] 00FF5E69 cmp esi,esp 00FF5E6B call __RTC_CheckEsp (0FF132Fh) cout << " *****" << endl; 00FF5E70 mov esi,esp cout << " *****" << endl; 00FF5E72 push 0FF14A6h 00FF5E77 push 0FFCE64h 00FF5E7C mov eax,dword ptr ds:[0100009Ch] 00FF5E81 push eax 00FF5E82 call std::operator<<<std::char_traits<char> > (0FF14BFh) 00FF5E87 add esp,8 00FF5E8A mov ecx,eax 00FF5E8C call dword ptr ds:[1000090h] 00FF5E92 cmp esi,esp 00FF5E94 call __RTC_CheckEsp (0FF132Fh) cout << "*******" << endl; 00FF5E99 mov esi,esp 00FF5E9B push 0FF14A6h 00FF5EA0 push 0FFD1A8h 00FF5EA5 mov eax,dword ptr ds:[0100009Ch] 00FF5EAA push eax 00FF5EAB call std::operator<<<std::char_traits<char> > (0FF14BFh) 00FF5EB0 add esp,8 00FF5EB3 mov ecx,eax 00FF5EB5 call dword ptr ds:[1000090h] 00FF5EBB cmp esi,esp 00FF5EBD call __RTC_CheckEsp (0FF132Fh) cout << " *****" << endl; 00FF5EC2 mov esi,esp 00FF5EC4 push 0FF14A6h 00FF5EC9 push 0FFCE64h 00FF5ECE mov eax,dword ptr ds:[0100009Ch] 00FF5ED3 push eax 00FF5ED4 call std::operator<<<std::char_traits<char> > (0FF14BFh) 00FF5ED9 add esp,8 00FF5EDC mov ecx,eax 00FF5EDE call dword ptr ds:[1000090h] 00FF5EE4 cmp esi,esp 00FF5EE6 call __RTC_CheckEsp (0FF132Fh) cout << " ***" << endl; 00FF5EEB mov esi,esp 00FF5EED push 0FF14A6h 00FF5EF2 push 0FFCD24h 00FF5EF7 mov eax,dword ptr ds:[0100009Ch] 00FF5EFC push eax 00FF5EFD call std::operator<<<std::char_traits<char> > (0FF14BFh) 00FF5F02 add esp,8 00FF5F05 mov ecx,eax 00FF5F07 call dword ptr ds:[1000090h] 00FF5F0D cmp esi,esp 00FF5F0F call __RTC_CheckEsp (0FF132Fh) cout << " *" << endl; 00FF5F14 mov esi,esp 00FF5F16 push 0FF14A6h 00FF5F1B push 0FFCC70h 00FF5F20 mov eax,dword ptr ds:[0100009Ch] 00FF5F25 push eax 00FF5F26 call std::operator<<<std::char_traits<char> > (0FF14BFh) 00FF5F2B add esp,8 00FF5F2E mov ecx,eax 00FF5F30 call dword ptr ds:[1000090h] 00FF5F36 cmp esi,esp 00FF5F38 call __RTC_CheckEsp (0FF132Fh) system("pause"); 00FF5F3D mov esi,esp 00FF5F3F push 0FFCBB0h 00FF5F44 call dword ptr ds:[10001D0h] 00FF5F4A add esp,4 00FF5F4D cmp esi,esp 00FF5F4F call __RTC_CheckEsp (0FF132Fh) return 0; 00FF5F54 xor eax,eax } 00FF5F56 pop edi 00FF5F57 pop esi 00FF5F58 pop ebx //恢复现场 00FF5F59 add esp,0C0h //C/C++函数调用约定默认为_cdecel方式,即由调用方平衡堆栈。 00FF5F5F cmp ebp,esp 00FF5F61 call __RTC_CheckEsp (0FF132Fh) 00FF5F66 mov esp,ebp //还原栈底指针 00FF5F68 pop ebp 00FF5F69 ret

 

release下优化后的反汇编代码

int main()
{
011412A0  push        ebp  //保存栈底指针
011412A1  mov         ebp,esp  //调整栈底指针到栈顶
011412A3  and         esp,0FFFFFFF8h  //为局部变量申请内存空间
    cout << "   *" << endl;
011412A6  push        1141A80h  
011412AB  push        ecx  
011412AC  mov         ecx,dword ptr ds:[1143054h]  
011412B2  mov         edx,11431BCh  
011412B7  call        std::operator<<<std::char_traits<char> > (01141840h)  
011412BC  add         esp,4  
011412BF  mov         ecx,eax  
011412C1  call        dword ptr ds:[1143034h]  
    cout << "  ***" << endl;
011412C7  push        1141A80h  
011412CC  push        ecx  
011412CD  mov         ecx,dword ptr ds:[1143054h]  
011412D3  mov         edx,11431C4h  
011412D8  call        std::operator<<<std::char_traits<char> > (01141840h)  
011412DD  add         esp,4  
011412E0  mov         ecx,eax  
011412E2  call        dword ptr ds:[1143034h]  
    cout << " *****" << endl;
011412E8  push        1141A80h  
011412ED  push        ecx  
011412EE  mov         ecx,dword ptr ds:[1143054h]  
011412F4  mov         edx,11431CCh  
011412F9  call        std::operator<<<std::char_traits<char> > (01141840h)  
011412FE  add         esp,4  
01141301  mov         ecx,eax  
01141303  call        dword ptr ds:[1143034h]  
    cout << "*******" << endl;
01141309  push        1141A80h  
0114130E  push        ecx  
0114130F  mov         ecx,dword ptr ds:[1143054h]  
01141315  mov         edx,11431D4h  
0114131A  call        std::operator<<<std::char_traits<char> > (01141840h)  
0114131F  add         esp,4  
01141322  mov         ecx,eax  
01141324  call        dword ptr ds:[1143034h]  
    cout << " *****" << endl;
0114132A  push        1141A80h  
    cout << " *****" << endl;
0114132F  push        ecx  
01141330  mov         ecx,dword ptr ds:[1143054h]  
01141336  mov         edx,11431CCh  
0114133B  call        std::operator<<<std::char_traits<char> > (01141840h)  
01141340  add         esp,4  
01141343  mov         ecx,eax  
01141345  call        dword ptr ds:[1143034h]  
    cout << "  ***" << endl;
0114134B  push        1141A80h  
01141350  push        ecx  
01141351  mov         ecx,dword ptr ds:[1143054h]  
01141357  mov         edx,11431C4h  
0114135C  call        std::operator<<<std::char_traits<char> > (01141840h)  
01141361  add         esp,4  
01141364  mov         ecx,eax  
01141366  call        dword ptr ds:[1143034h]  
    cout << "   *" << endl;
0114136C  push        1141A80h  
01141371  push        ecx  
01141372  mov         ecx,dword ptr ds:[1143054h]  
01141378  mov         edx,11431BCh  
0114137D  call        std::operator<<<std::char_traits<char> > (01141840h)  
01141382  add         esp,4  
01141385  mov         ecx,eax  
01141387  call        dword ptr ds:[1143034h]  

    system("pause");
0114138D  push        11431DCh  
01141392  call        dword ptr ds:[11430DCh]  
01141398  add         esp,4  
    return 0;
0114139B  xor         eax,eax  
}
0114139D  mov         esp,ebp  //还原栈顶指针
}
0114139F  pop         ebp  //恢复栈底指针
011413A0  ret  

 

C++反汇编实例(1)-输出多行

标签:

原文地址:http://www.cnblogs.com/nitianbenbendan/p/4383569.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!