C语言的反汇编代码 您所在的位置:网站首页 网络诈骗观后感150字 C语言的反汇编代码

C语言的反汇编代码

#C语言的反汇编代码| 来源: 网络整理| 查看: 265

1. 最简单的代码:

test1.c

int main(){

    return 1;

}

 

编译、反汇编:

gcc test1.c

gdb ./a.out

(gdb) disassemble main

 

0x08048344 :        lea    0x4(%esp),%ecx   ; 取出 esp 寄存器里的值 , 加上 4 , 将得到值传递给 ecx ;

0x08048348 :        and    $0xfffffff0,%esp  ; 使栈地址 16 字节对齐

0x0804834b :       pushl  -0x4(%ecx)  ; 取出寄存器 ecx 的值 , 减去 4 , 即 esp 的值 , 将得到的值作为地址 , 在内存找到该地址对应的值 , 将其压入栈中。

0x0804834e :      push   %ebp

0x0804834f :      mov    %esp,%ebp   ; 创建 Stack Frame( 栈框架 )

0x08048351 :      push   %ecx

0x08048352 :      mov    $0x1,%eax

0x08048357 :      pop    %ecx

0x08048358 :      pop    %ebp

0x08048359 :      lea    -0x4(%ecx),%esp  ; 取出 ecx寄存器里的值 , 减去 4 , 将得到值传递给 esp ; 还原 esp 的值

0x0804835c :      ret 

 

常用指令解释 :

CALL 指令 :

用来调用一个函数或过程,此时,下一条指令地址会被压入堆栈,以备返回时能恢复执行下条指令。 RET 指令 :

用来从一个函数或过程返回,之前 CALL 保存的下条指令地址会从栈内弹出到 EIP 寄存器中,程序转到 CALL 之前下条指令处执行

ENTER 指令 :

建立当前函数的栈框架,即相当于以下两条指令:         pushl   %ebp         movl    %esp,%ebp LEAVE 指令 :

释放当前函数或者过程的栈框架,即相当于以下两条指令:         movl ebp esp         popl ebp

 

2. 函数间的调用代码:

假如函数A 调用函数B ,函数B 调用函数C :

/ test2.c

void c(){}

 

void b(){c();}

 

void a(){b();}

 

int main(){

   a();

   return 1;

}

编译、反汇编:

gcc test1.c

gdb ./a.out

(gdb) disassemble main

Dump of assembler code for function main:

0x0804835d :       lea    0x4(%esp),%ecx

0x08048361 :        and    $0xfffffff0,%esp

0x08048364 :        pushl  -0x4(%ecx)

0x08048367 :      push   %ebp

0x08048368 :      mov    %esp,%ebp

0x0804836a :      push   %ecx

0x0804836b :     call   0x8048353

0x08048370 :      mov    $0x1,%eax

0x08048375 :      pop    %ecx

0x08048376 :      pop    %ebp

0x08048377 :      lea    -0x4(%ecx),%esp

0x0804837a :      ret   

End of assembler dump.

(gdb) disassemble a

Dump of assembler code for function a:

0x08048353 :  push   %ebp

0x08048354 :  mov    %esp,%ebp

0x08048356 :  call   0x8048349

0x0804835b :  pop    %ebp

0x0804835c :  ret   

End of assembler dump.

(gdb) disassemble b

Dump of assembler code for function b:

0x08048349 :  push   %ebp

0x0804834a :  mov    %esp,%ebp

0x0804834c :  call   0x8048344

0x08048351 :  pop    %ebp

0x08048352 :  ret   

End of assembler dump.

(gdb) disassemble c

Dump of assembler code for function c:

0x08048344 :  push   %ebp

0x08048345 :  mov    %esp,%ebp

0x08048347 :  pop     %ebp

0x08048348 :  ret   

End of assembler dump.

 

函数调用栈的状态:

      +-------------------------+----> 高地址      | EIP (Main 函数返回地址)   |      +-------------------------+      | EBP (Main 函数的EBP)       | --+ offsetA      | A 中的局部变量            | --+



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有