본문으로 바로가기

ASM to C with IDA - 030

category Reversing/ASM to C 2018. 7. 3. 13:55

C300_030



C300_소스코드



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h> 
 
main()
{
    int i = 1;
    int hap = 0;
 
    while (i <= 10)                
    {
        hap = hap + i;
        i++;                        
    }
 
    printf("hap = %d ", hap);                        
}
cs



IDA - Layout Graph





IDA - Text View





jg : operand1이 operand2 보다 클 때 true

IDA - Layout Graph를 보면 반복을 하는것을 알 수 있다.

while, for 어느 반복문을 사용하더라도 어색하지 않지만 필자는 while을 사용하였다.



pseudo code - 의사코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h> 
 
main()
{
    int i;
    int hap;
    
    i = 1;
    hap = 0;
    
    while(i <= 10){
    eax = hap;
    eax = eax + i;
    hap = eax;
    ecx = i;
    ecx = ecx + 1;
    i = ecx;
    }
 
    edx = hap;
    printf(_Fromat, edx);                
    eax = 0;                        
}
cs



pseudo code - 최종 의사코드 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h> 
 
main()
{
    int i;
    int hap;
    
    i = 1;
    hap = 0;
    
    while(i <= 10){
        hap = hap + i;
        i = i + 1;
    }
 
    printf(_Fromat, hap);                
    return 0;                        
}
cs


'Reversing > ASM to C' 카테고리의 다른 글

ASM to C with IDA- 032  (0) 2018.07.04
ASM to C with IDA - 031  (0) 2018.07.03
ASM to C with IDA - 029  (0) 2018.07.03
ASM to C with IDA - 028  (0) 2018.06.01
ASM to C with IDA - 027  (0) 2018.06.01