zoukankan      html  css  js  c++  java
  • max函数的嵌套调用

    先来看源代码:

     1 // 函数的嵌套调用.cpp : Defines the entry point for the console application.
     2 //
     3 
     4 #include "stdafx.h"
     5 
     6 int main(int argc, char* argv[])
     7 {
     8     int max(int x,int y);
     9     int a,b,c,d;
    10     scanf("%d,%d,%d",&a,&b,&c);
    11     d=max(max(a,b),c);
    12     printf("max=%d\n",d);
    13     return 0;
    14 }
    15 
    16 
    17 int max(int x,int y)
    18 {
    19     int z;
    20     if (x>y)
    21     {
    22         z=x;
    23     }
    24     else
    25         z=y;
    26     return z;
    27 }

    这段反汇编代码也很简单,只是要认真理解就可以了。

     1 ; int __cdecl main(int argc, const char **argv, const char **envp)
     2 _main proc near
     3 
     4 c= dword ptr -0Ch
     5 b= dword ptr -8
     6 a= dword ptr -4
     7 argc= dword ptr  4
     8 argv= dword ptr  8
     9 envp= dword ptr  0Ch
    10 
    11 sub     esp, 0Ch
    12 lea     eax, [esp+0Ch+c] ; 把a的地址放入eax中
    13 lea     ecx, [esp+0Ch+b]
    14 lea     edx, [esp+0Ch+a]
    15 push    eax
    16 push    ecx
    17 push    edx
    18 push    offset Format   ; "%d,%d,%d"
    19 call    _scanf
    20 mov     eax, [esp+1Ch+c]
    21 mov     ecx, [esp+1Ch+b]
    22 mov     edx, [esp+1Ch+a]
    23 add     esp, 10h
    24 push    eax
    25 push    ecx
    26 push    edx
    27 call    fun_max
    28 add     esp, 8
    29 push    eax
    30 call    fun_max
    31 push    eax
    32 push    offset aMaxD    ; "max=%d\n"
    33 call    _printf
    34 xor     eax, eax
    35 add     esp, 1Ch
    36 retn
    37 _main endp

    如果仔细看,发现这段代码还可以优化,少一下push。

    逆向的开始是一个痛苦的过程,就像我们习惯了向前行走,现在却要倒退行走。

    思维啊,不过可以发现很多东西。这段代码,如果你没有看懂,那就没有任何的意义。

  • 相关阅读:
    网络请求与远程资源
    JavaScript对象
    微信小程序抓包Charles
    归并排序
    顺序表
    后缀表达式
    中缀表达
    ES6 Promise
    Es 方法
    10.26学习
  • 原文地址:https://www.cnblogs.com/tk091/p/2508212.html
Copyright © 2011-2022 走看看