反汇编逆向实例_swirch case语句反汇编

反汇编逆向实例_swirch case语句反汇编

                                                                                               by:比方

逆向反汇编第六章,swirch case语句反汇编

示例代码如下:

 

 1 #include"stdio.h"
 2 int function(int a,int b)
 3 {
 4     int c=a+b;
 5     
 6     switch(c)
 7     {
 8         case 0:
 9             printf("c>0");
10         case 1:
11             printf("c>10&&c<100");
12             break;
13         default:
14             printf("c>10&&c<100");
15     }
16     return c;
17 }
18 void main()
19 {
20     function(1,2);
21 }

反汇编结果:

1 #include "stdio.h"
2 
3 int function(int a,int b)
4 
5 {
00EA2FE0 push ebp
00EA2FE1 mov ebp,esp
00EA2FE3 sub esp,0D0h
 
00EA2FE9 push ebx
00EA2FEA push esi
00EA2FEB push edi
 
00EA2FEC lea edi,[ebp-0D0h]
00EA2FF2 mov ecx,34h
00EA2FF7 mov eax,0CCCCCCCCh
00EA2FFC rep stos dword ptr es:[edi]                      ;开始分配34个4字节空间,定位到edi,edi是来自[ebp-0CCh],定位到缓冲区头部并初始化为CC,
 
1 int c=a+b;
00EA2FFE mov eax,dword ptr [a]                             变量A放入到eax,  
00EA3001 add eax,dword ptr [b]                                 ;   变量B加上个变量A ,结果放入到eax 
00EA3004 mov dword ptr [c],eax                                ;   变量C等于变量A+变量B,等于 C = A+B;
 
1 switch(c)
00EA3007 mov eax,dword ptr [c]
00EA300A mov dword ptr [ebp-0D0h],eax                    ; 
00EA3010 cmp dword ptr [ebp-0D0h],0                        ; 
00EA3017 je function+44h (0EA3024h)                        ; 比较结果是否为等于0,如果不等与0则继续下一句否则,跳转到0x0EA3024h
00EA3019 cmp dword ptr [ebp-0D0h],1                       
00EA3020 je function+5Bh (0EA303Bh)                        ; 比较结果是否为等于1,如果不等与1则继续下一句否则,跳转到0x0EA303Bh
00EA3022 jmp function+74h (0EA3054h)                     ; 如果上面的两个结果都不满足,则跳转到0x0EA3054h处继续执行
 
1 {
2         case 0:
3             printf("c>0");
00EA3024 mov esi,esp
00EA3026 push offset string "c>0" (0EA573Ch)
00EA302B call dword ptr [__imp__printf (0EA82B8h)]   ;;则调用printf函数,输出字符"c>0"
00EA3031 add esp,4
00EA3034 cmp esi,esp
00EA3036 call @ILT+315(__RTC_CheckEsp) (0EA1140h)
 
 
1 break;

00EA3052 jmp function+8Bh (0EA306Bh)

 

1 default:
2             printf("c>10&&c<100");

00EA3054 mov esi,esp

 

00EA3056 push offset string "c>10&&c<100" (0EA57A0h)   ;;则调用printf函数,输出字符

00EA305B call dword ptr [__imp__printf (0EA82B8h)]
00EA3061 add esp,4
00EA3064 cmp esi,esp
00EA3066 call @ILT+315(__RTC_CheckEsp) (0EA1140h)

 

1     }
2     return c;

 

00EA306B mov eax,dword ptr [c]
}
 
00EA306E pop edi
00EA306F pop esi
00EA3070 pop ebx
 
00EA3071 add esp,0D0h
 
00EA3077 cmp ebp,esp
00EA3079 call @ILT+315(__RTC_CheckEsp) (0EA1140h)
00EA307E mov esp,ebp
00EA3080 pop ebp
00EA3081 ret 
 
在大数目的swirch case 语句中,会首先减成零值,然后每次加上他的差值,还原的时候注意以下

对于switch csse语句中,识别的特征也比较容易,在每条语句下面会有一个jmp指令,其实对应源码中的 break;
特征:
mov reg,mem
jxx ********
jxx ********
jxx ********
jmp     end
……
jmp     end
……
jmp     end
…… 
end  

 

转载于:https://www.cnblogs.com/hailunchina/p/3913966.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值