본문으로 바로가기

ASM to C with IDA- 032

category Reversing/ASM to C 2018. 7. 4. 09:08

C300_032



C300_소스코드



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h> 
 
main()
{
    int i;
    int j;
 
    for (i = 1; i <= 100; i++)
    {
        for (j = 1; j <= 9; j++)
        {
            printf("%d * %d = %2d \n", i, j, i * j);        
            if (i == 9 && j == 9goto ku_ku_end;
        }
    }
 
ku_ku_end:;
}
 
cs



IDA - Layout Graph





IDA - Text View



jg : oeprand1 이 operand2 보다 크면 참이다.

보통 C 의사코드로 복원될 때 disassembly 단에서 조건문의 반대이다.

ku_ku_end의 흐름을 보면 반복문을 돌다가 어느 조건에서 빠져나온다.

중첩된 반복문을 탈출하기 때문에 break가 아닌 go to문을 사용했다고 생각했다.




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 j;
    i = 1
    
    for(i=0; i<=100; i++){
        for(j=1; j<=9; j++){    
            edx = i;
            edx = edx * j;
            eax = j;
            ecx = i;
            printf(_Format, ecx, eax, edx);
            if(i==9 && j==9goto ku_ku_end;                
        }
    }
 
    ku_ku_end:;
    eax = 0;
}
 
cs



pseudo code - 최종 의사코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h> 
 
main()
{
    int i;
    int j;
    i = 1
    
    for(i=0; i<=100; i++){
        for(j=1; j<=9; j++){    
            printf(_Format, i, j, i*j);
            if(i==9 && j==9goto ku_ku_end;                
        }
    }
 
    ku_ku_end:;
    return 0;
}
 
cs


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

ASM to C with IDA - 034  (0) 2018.07.04
ASM to C with IDA - 033  (0) 2018.07.04
ASM to C with IDA - 031  (0) 2018.07.03
ASM to C with IDA - 030  (0) 2018.07.03
ASM to C with IDA - 029  (0) 2018.07.03