• c++ 反汇编 if


    1、debug

    • if:
    10:     if (argc == 0)
    0010711E 83 7D 08 00          cmp         dword ptr [argc],0  
    00107122 75 11                jne         If+35h (0107135h)  //不相等则跳转(为保持代码顺序,if的比较条件在汇编中相反)
        11:     {
        12:         printf("%d 
    ", argc);
    00107124 8B 45 08             mov         eax,dword ptr [argc]  
    ···printf00107132 83 C4 08             add         esp,8  
        13:     }
        14:     if (argc > 0)
    00107135 83 7D 08 00          cmp         dword ptr [argc],0  
    00107139 7E 0D                jle         If+48h (0107148h)  
        15:     {
        16:         printf("argc >= 0");
    ···printf00107145 83 C4 04             add         esp,4  
        17:     }

    总结:debug下,简单的if语句结构为:

    cmp

    jxx  {if 外语句}

    {if 块内语句}

    • if···else···
       35:     if (argc == 0)
    0010719E 83 7D 08 00          cmp         dword ptr [argc],0  
    001071A2 75 09                jne         IfElse+2Dh (01071ADh)  
        36:     {
        37:         argc = 5;
    001071A4 C7 45 08 05 00 00 00 mov         dword ptr [argc],5  
        38:     }
        39:     else
    001071AB EB 07                jmp         IfElse+34h (01071B4h)  //if块内语句执行结束后,jmp到if-else结束
        40:     {
        41:         argc = 6;
    001071AD C7 45 08 06 00 00 00 mov         dword ptr [argc],6  
        42:     }
    • if···else if···else
    50:     if (argc > 0)
    00107215 83 7D 08 00          cmp         dword ptr [argc],0  
    00107219 7E 0F                jle         IfElseIf+3Ah (010722Ah)  //if
        51:     {
        52:         printf("argc > 0");
    ···printf 
    00107228 EB 22                jmp         IfElseIf+5Ch (010724Ch)  //if块内结束时jmp出条件结构
        53:     }
        54:     else if (argc == 0)
    0010722A 83 7D 08 00          cmp         dword ptr [argc],0  
    0010722E 75 0F                jne         IfElseIf+4Fh (010723Fh)  //else if 
        55:     {
        56:         printf("argc == 0");
    ···printf  
        57:     }
        58:     else
    0010723D EB 0D                jmp         IfElseIf+5Ch (010724Ch) //else if块内结束后jmp出条件结构 
        59:     {
        60:         printf("argc <= 0");
    ···printf  

    2、release

    • if
    void If(int argc)
    {
        if (argc == 0)
        {
            printf("%d 
    ", argc);
        }
        if (argc > 0)
        {
            printf("argc >= 0");
        }
        
        return;
    }
    View Code
    00351085  | 85C0            | test eax,eax                      | if_else.cpp:73
    00351087  | 75 12           | jne if_else.35109B                |
    ···printf                      |
    00351097  | 33C0            | xor eax,eax                       | if_else.cpp:77
    00351099  | 5D              | pop ebp                           |
    0035109A  | C3              | ret                               |
    0035109B  | 7E 0D           | jle if_else.3510AA                | 优化了一条判断语句
    ···printf                       |
    003510AA  | 33C0            | xor eax,eax                       | if_else.cpp:77
    • if···else
    void IfElse(int argc)
    {
        if (argc == 0)
        {
            argc = 5;
        }
        else
        {
            argc = 6;
        }
        printf("%d 
    ", argc);
    }
    View Code
    01381081  | 3945 08         | cmp dword ptr ss:[ebp+0x8],eax    |//类似条件表达式中的优化,
    01381084  | 0F95C0          | setne al                          |
    01381087  | 83C0 05         | add eax,0x5                       |
    ···
    printf
    ···
    01381098 | 33C0 | xor eax,eax | if_else.cpp:76 0138109A | 5D | pop ebp | if_else.cpp:77 0138109B | C3 | ret |
    • if···else if···else
    void IfElseIf(int argc)
    {
        //argc = 0;
        if (argc > 0)
        {
            printf("argc > 0");
        }
        else if (argc == 0)
        {
            printf("argc == 0");
        }
        else
        {
            printf("argc <= 0");
        }
    }
    View Code
    002910A5  | 85C9            | test ecx,ecx             | if_else.cpp:75
    002910A7  | 7E 12           | jle if_else.2910BB       |
    002910A9  | B8 A4012D00     | mov eax,if_else.2D01A4   | 2D01A4:"argc > 0"
    ···printf              |
    002910B7  | 33C0            | xor eax,eax              |
    002910B9  | 5D              | pop ebp                  | if_else.cpp:77
    002910BA  | C3              | ret                      |
    002910BB  | 85C9            | test ecx,ecx             | if_else.cpp:75
    002910BD  | BA BC012D00     | mov edx,if_else.2D01BC   | 2D01BC:"argc <= 0"
    002910C2  | B8 B0012D00     | mov eax,if_else.2D01B0   | 2D01B0:"argc == 0"
    002910C7  | 0F45C2          | cmovne eax,edx           |//将两条判断优化在一起
    ···printf
  • 相关阅读:
    BUAA_OO_2020_Unit3 Summary
    BUAA_OO_2020_Unit2 Summary
    DataFrame的遍历
    ESMM提升CVR的论文summary
    FaceBook 关于提升CTR的论文研究
    OO终章·GRAND BATTLE
    第三单元规格作业博客总结
    OO电梯单元作业总结
    【OO多项式求导作业总结】
    提问回顾与个人总结
  • 原文地址:https://www.cnblogs.com/DirWang/p/12155100.html
Copyright © 2020-2023  润新知