当前位置: 代码迷 >> 汇编语言 >> 请问c反汇编生成的汇编语言
  详细解决方案

请问c反汇编生成的汇编语言

热度:5820   发布时间:2013-02-26 00:00:00.0
请教c反汇编生成的汇编语言
#include <stdio.h>

int main()
{
printf("hello ");
printf("from my cat.\n");

return 0;
}
反汇编结果
_main:
  00000000: 55 push ebp
  00000001: 8B EC mov ebp,esp
  00000003: 68 00 00 00 00 push offset _main
  00000008: E8 00 00 00 00 call 0000000D
  0000000D: 83 C4 04 add esp,4
  00000010: 68 00 00 00 00 push offset _main
  00000015: E8 00 00 00 00 call 0000001A
  0000001A: 83 C4 04 add esp,4
  0000001D: 33 C0 xor eax,eax
  0000001F: 5D pop ebp
  00000020: C3 ret

2个call调用的是printf,之前push是参数
为什么2个字符串指针都是push offset _main 呢


------解决方案--------------------------------------------------------
你反汇编的不是可执行文件吧?代码里面的偏移量都是0,所以反汇编出来的代码也是错的。
------解决方案--------------------------------------------------------
仔细看机器码,这里的偏移量是没有初始化的,全是 0。等到目标文件链接成程序时或者程序加载时,这里才会填上正确的偏移量。

_main:
00000000: 55 push ebp
00000001: 8B EC mov ebp,esp
00000003: 68 00 00 00 00 push offset _main
00000008: E8 00 00 00 00 call 0000000D
0000000D: 83 C4 04 add esp,4
00000010: 68 00 00 00 00 push offset _main
00000015: E8 00 00 00 00 call 0000001A
0000001A: 83 C4 04 add esp,4
0000001D: 33 C0 xor eax,eax
0000001F: 5D pop ebp
00000020: C3 ret
------解决方案--------------------------------------------------------
探讨

我用
cl /c helloworld.c 编译的
cl /DISASM helloworld.obj 显示反汇编结果

------解决方案--------------------------------------------------------
所以你要反汇编exe才行。
  相关解决方案