본문으로 바로가기

ASM to C with IDA - 012

category Reversing/ASM to C 2018. 5. 27. 20:46

C300_012



C300_소스코드



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h> 
 
#define HUNDRED 100
 
const char j = 10;
 
main() 
    //HUNDRED = 200;    // 에러 발생
    //j = 200;        // 에러 발생
 
    printf"문자형 상수 HUNDRED의 값은 %d \n", HUNDRED );        
    printf"문자형 상수 j의 값은 %d \n", j );
    getch();
cs




IDA - Layout Graph





IDA - Text View




data segment에는 전역변수, 혹은 static 변수가 저장된다.


movsx: 부호 있는 산술 값을 mov할 때 사용된다.



IDA 에서 .rdata는 읽기 전용 data sement로써 사용된다. 즉, const type data가 여기 저장된다.

또한 바로 64가 push 된 것을 보면 #define으로 매크로 함수가 사용된 것을 예측할 수 있다.


const char j=10 과 char j=10의 차이점.

ds:_j 와 j의 차이이다 const char j는 상수 취급, char j는 변수 취급을 한다.


전처리 과정에서 매크로 함수를 처리해서 어셈블리단에서 안보이는 것 같다.


pseudo code - 의사 코드



1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h> 
 
main() 
{
    printf(_Format,100);
 
    eax = ds:_j;
    printf(byte_403040, eax);        
 
    getch();
    eax = 0;
}
 
cs

 


pseudo code - 최종 의사코드



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h> 
 
#define max 100;
 
const char j;
 
main() 
{
    printf(_Format, max);
 
    printf(byte_403040, j);        
 
    getch();
}
 
cs


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

ASM to C with IDA - 014(??)  (0) 2018.05.28
ASM to C with IDA - 013  (0) 2018.05.27
ASM to C with IDA - 011  (0) 2018.05.27
ASM to C with IDA - 010(??)  (0) 2018.05.26
ASM to C with IDA - 009 (??)  (0) 2018.05.26