end로 점프하면 프로그램이 종료된다고 가정하자. 프로그램이 종료됐을 때, 0x400000 부터 0x400019까지의 데이터를 대응되는 아스키 문자로 변환하면 어느 문자열이 나오는가?
[Register]
rcx = 0
rdx = 0
rsi = 0x400000
=======================
[Memory]
0x400000 | 0x67 0x55 0x5c 0x53 0x5f 0x5d 0x55 0x10
0x400008 | 0x44 0x5f 0x10 0x51 0x43 0x43 0x55 0x5d
0x400010 | 0x52 0x5c 0x49 0x10 0x47 0x5f 0x42 0x5c
0x400018 | 0x54 0x11 0x00 0x00 0x00 0x00 0x00 0x00
=======================
[code]
1: mov dl, BYTE PTR[rsi+rcx]
2: xor dl, 0x30
3: mov BYTE PTR[rsi+rcx], dl
4: inc rcx
5: cmp rcx, 0x19
6: jg end
7: jmp 1
코드를 한 줄 한 줄 해석하며 Memory에 값을 수정해보면
[Register]
rcx = 0
rdx = 0
rsi = 0x400000
=======================
[Memory]
0x400000 | 0x67 0x55 0x5c 0x53 0x5f 0x5d 0x55 0x10
0x400008 | 0x44 0x5f 0x10 0x51 0x43 0x43 0x55 0x5d
0x400010 | 0x52 0x5c 0x49 0x10 0x47 0x5f 0x42 0x5c
0x400018 | 0x54 0x11 0x00 0x00 0x00 0x00 0x00 0x00
=======================
[code]
1: mov dl, BYTE PTR[rsi+rcx] ; dl = 0x67
2: xor dl, 0x30 ; dl = 0x57
3: mov BYTE PTR[rsi+rcx], dl ; BYTE PTR[0x400000] = 0x57
4: inc rcx ; rcx = 0x1
5: cmp rcx, 0x19 ; 0x1 > 0x19 (false)
6: jg end
7: jmp 1 ; jmp 1
=======================
[Memory]
0x400000 | 0x57 0x55 0x5c 0x53 0x5f 0x5d 0x55 0x10
0x400008 | 0x44 0x5f 0x10 0x51 0x43 0x43 0x55 0x5d
0x400010 | 0x52 0x5c 0x49 0x10 0x47 0x5f 0x42 0x5c
0x400018 | 0x54 0x11 0x00 0x00 0x00 0x00 0x00 0x00
=======================
[Register]
rcx = 0x1
rdx = 0
rsi = 0x400000
=======================
[Memory]
0x400000 | 0x57 0x55 0x5c 0x53 0x5f 0x5d 0x55 0x10
0x400008 | 0x44 0x5f 0x10 0x51 0x43 0x43 0x55 0x5d
0x400010 | 0x52 0x5c 0x49 0x10 0x47 0x5f 0x42 0x5c
0x400018 | 0x54 0x11 0x00 0x00 0x00 0x00 0x00 0x00
=======================
[code]
1: mov dl, BYTE PTR[rsi+rcx] ; dl = 0x55
2: xor dl, 0x30 ; dl = 0x65
3: mov BYTE PTR[rsi+rcx], dl ; BYTE PTR[0x400001] = 0x65
4: inc rcx ; rcx = 0x2
5: cmp rcx, 0x19 ; 0x2 > 0x19 (false)
6: jg end
7: jmp 1 ; jmp 1
=======================
[Memory]
0x400000 | 0x57 0x65 0x5c 0x53 0x5f 0x5d 0x55 0x10
0x400008 | 0x44 0x5f 0x10 0x51 0x43 0x43 0x55 0x5d
0x400010 | 0x52 0x5c 0x49 0x10 0x47 0x5f 0x42 0x5c
0x400018 | 0x54 0x11 0x00 0x00 0x00 0x00 0x00 0x00
=======================
.
.
.
.
.
[Register]
rcx = 0x19
rdx = 0
rsi = 0x400000
=======================
[Memory]
0x400000 | 0x57 0x65 0x6c 0x63 0x6f 0x6d 0x65 0x20
0x400008 | 0x74 0x6f 0x20 0x61 0x73 0x73 0x65 0x6d
0x400010 | 0x62 0x6c 0x79 0x20 0x77 0x6f 0x72 0x6c
0x400018 | 0x64 0x11 0x00 0x00 0x00 0x00 0x00 0x00
=======================
[code]
1: mov dl, BYTE PTR[rsi+rcx] ; dl = 0x21
2: xor dl, 0x30 ; dl = 0x21
3: mov BYTE PTR[rsi+rcx], dl ; BYTE PTR[0x400019] = 0x21
4: inc rcx ; rcx = 0x1a
5: cmp rcx, 0x19 ; cmp 0x1a > 0x19 (true)
6: jg end ; jump end
7: jmp 1
=======================
[Memory]
0x400000 | 0x57 0x65 0x6c 0x63 0x6f 0x6d 0x65 0x20
0x400008 | 0x74 0x6f 0x20 0x61 0x73 0x73 0x65 0x6d
0x400010 | 0x62 0x6c 0x79 0x20 0x77 0x6f 0x72 0x6c
0x400018 | 0x64 0x21 0x00 0x00 0x00 0x00 0x00 0x00
=======================
rcx가 0x19보다 클 때 프로그램이 종료되기 때문에, 0x400000부터 0x400019까지 xor 연산을 하고 rcx값이 1 증가되어 0x1a가 되면 cmp 0x1a > 0x19가 true가 돼서 jg end로 프로그램이 종료됩니다.
[Memory]
0x400000 | 0x57 0x65 0x6c 0x63 0x6f 0x6d 0x65 0x20
0x400008 | 0x74 0x6f 0x20 0x61 0x73 0x73 0x65 0x6d
0x400010 | 0x62 0x6c 0x79 0x20 0x77 0x6f 0x72 0x6c
0x400018 | 0x64 0x21 0x00 0x00 0x00 0x00 0x00 0x00
위의 16진수를 Ascii 코드로 변환해보면
Welcome to assembly world!로 변환되었습니다.
사용하신 프로그램은 뭔가요?