본문으로 바로가기

ASM to C with IDA - 043

category Reversing/ASM to C 2018. 7. 8. 14:35

C300_043



C300_소스코드



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h> 
 
void print_x(int x);
void print_gx(void);
 
int x = 20;
 
main()
{
    int x = 5;
    printf("x = %d \n", x);
 
    print_x(10);
    print_gx();
}
 
void print_x(int x)
{
    printf("x = %d \n", x);
}
 
void print_gx(void)
{
    printf("x = %d \n", x);                
}
cs




IDA - Layout Graph






IDA - Text View






전역변수는 main 함수 밖에 선언되어 있기 때문에 함수 내에서는 보이지 않는다.

하지만 IDA가 다른 이름으로 선언해서 사용하고 있는 것을 알 수 있다.



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
24
25
26
#include <stdio.h> 
 
int _x = 20;
 
void print_x(int x)
{
    eax = x;
    printf(aXD_1, eax);
}
 
void print_gx()
{
    eax = _x;
    printf(aXD_0, eax);
}
 
main()
{
    int x;
 
    x = 5;
    eax = x;    
    printf(_Format, eax);                            
 
    print_x(10);
print_gx();
}
prcs




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
24
#include <stdio.h> 
 
int _x = 20;
 
void print_x(int x)
{
    printf(aXD_1, x);
}
 
void print_gx()
{
    printf(aXD_0, _x);
}
 
main()
{
    int x;
 
    x = 5;    
    printf(_Format, x);                            
 
    print_x(10);
    print_gx();
}
cs



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

ASM to C with IDA - 045  (0) 2018.07.09
ASM to C with IDA - 044  (0) 2018.07.09
ASM to C with IDA - 042  (0) 2018.07.08
ASM to C with IDA - 041  (0) 2018.07.08
ASM to C with IDA - 040  (0) 2018.07.06