|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
下面是《天书夜读》的一道反汇编的练习题,我试着翻译成C语言,但是只翻译了一些程序的片断出来,不能组成一个完整的程序,请高手帮忙看看,到底能不能翻译成一个完整的程序!谢谢!(练习题下面有我翻译的片断)
====================================================================
;下面是一个练习,内容是把下面的汇编代码还原成c语言(后面的注释是我自己分析的,也不知道对不对)
00411A20 push ebp ;保存ebp
00411A21 mov ebp,esp ;esp的值送给ebp(此时esp==ebp)
00411A23 sub esp,0E8h ;开辟 0E8h 字节的栈空间
00411A29 push ebx ;保存 ebx esi edi 三个寄存器
00411A2A push esi
00411A2B push edi
00411A2C lea edi,[ebp-0E8h] ;把上面开辟的 0E8h 字节大小的栈空间地址
;送入edi中
00411A32 mov ecx,3Ah ;设定装载 0CCCCCCCCh 次数(0E8h/4=3Ah)
00411A37 mov eax,0CCCCCCCCh
00411A3C rep stos dword ptr [edi] ;用eax的值初始化
00411A3E mov eax,dword ptr [a] ;eax=a
00411A41 add eax,dword ptr [b] ;eax=a+b
00411A44 mov dword ptr [d],eax ;b=eax b=a+b
00411A47 mov dword ptr [i],1 ;i=1
00411A4E mov dword ptr [c],0 ;c=0
00411A55 cmp dword ptr [c],64h ;c与100比较
00411A59 jge myfunction+46h (411A66h) ;如果 c>=100 跳转到 411A66h 处
00411A5B mov eax,dword ptr [c] ;eax=c
00411A5E add eax,dword ptr [i] ;eax=c+i
00411A61 mov dword ptr [c],eax ;c=eax c=c+i
00411A64 jmp myfunction+35h (411A55h) ;无条件跳转到 411A55h 处(进入下次循环)
00411A66 mov eax,dword ptr [c] ;c的值送入eax
00411A69 mov dword ptr [ebp-0E8h],eax ;eax(c)的值送入栈保存
00411A6F cmp dword ptr [ebp-0E8h],0 ;eax(c)的值与0比较 (case 0:)
00411A76 je myfunction+63h (411A83h) ;如果eax(c)=0,则跳到 411A83h 处
00411A78 cmp dword ptr [ebp-0E8h],1 ;eax(c)的值与1比较 (case 1:)
00411A7F je myfunction+6Ah (411A8Ah) ;如果eax(c)=1,则跳到 411A8Ah 处
00411A81 jmp myfunction+72h (411A92h) ;无条件跳转到 411A92h 处 (default)
00411A83 mov dword ptr [d],1 ;d=1
00411A8A mov eax,dword ptr [c] ;c送入eax
00411A8D mov dword ptr [d],eax ;d=c(eax)
00411A90 jmp myfunction+79h (411A99h) ;无条件跳转到 411A99h 处
00411A92 mov dword ptr [d],0 ;d=0
00411A99 mov eax,dword ptr [d] ;d送入eax (return d)
00411A9C pop edi ;恢复 edi esi ebx esp ebp 的值
00411A9D pop esi
00411A9E pop ebx
00411A9F mov esp,ebp
00411AA1 pop ebp
00411AA2 ret
====================================================================
下面是我翻译的片断:
====================================================================
b = a + b;
i = 1;
c = 0;
while ( c<100 )
{
c = c + i;
}
switch ( c )
{
case 0:
{
d = 1;
d = c;
}
break;
case 1:
{
d = c;
}
break;
default:
d = 0;
}
return d;
|
|