一個簡單的學習程式,代碼如下:
int fun()<br />{<br />int i,a = 0;<br />for(i = 0; i < 50; i ++)<br />{<br />a += i;<br />}<br />return i;<br />}
調試查看反組譯碼代碼如下:
int fun()
{
009C1A10 push ebp
009C1A11 mov ebp,esp
009C1A13 sub esp,0D8h
009C1A19 push ebx
009C1A1A push esi
009C1A1B push edi
009C1A1C lea edi,[ebp-0D8h]
009C1A22 mov ecx,36h
009C1A27 mov eax,0CCCCCCCCh
009C1A2C rep stos dword ptr es:[edi]
int i,a = 0;
009C1A2E mov dword ptr [a],0
for(i = 0; i < 50; i ++)
009C1A35 mov dword ptr [i],0
009C1A3C jmp fun+37h (9C1A47h)
009C1A3E mov eax,dword ptr [i]
009C1A41 add eax,1
009C1A44 mov dword ptr [i],eax
009C1A47 cmp dword ptr [i],32h
009C1A4B jge fun+48h (9C1A58h)
{
a += i;
009C1A4D mov eax,dword ptr [a]
009C1A50 add eax,dword ptr [i]
009C1A53 mov dword ptr [a],eax
}
009C1A56 jmp fun+2Eh (9C1A3Eh)
return i;
009C1A58 mov eax,dword ptr [i]
}
009C1A5B pop edi
009C1A5C pop esi
009C1A5D pop ebx
009C1A5E mov esp,ebp
009C1A60 pop ebp
009C1A61 ret
簡單分析for反組譯碼代碼
for迴圈的執行流程是:
mov <迴圈變數>,<初始值>
jmp B
A: (改變迴圈變數)
.................
B: cmp <迴圈變數>,< 限制的變數>
jge 跳出for
(迴圈體)
.................
jmp A