[x86-debugging]Addressing mode

Memory Addressing ModeCPU가 명령어를 처리할 때, 필요한 데이터를 위치시키는 방법이다. 특히 C/C++ code에서 array pointer 연산이 많은 데, 이러한 pointer array가 가리키고 있는 특정 주소에 저장된 데이터를 Check하는 일은 debugging시 빈번히 나타날 것이다.

Addressing modebase, displacement, index scale로 이뤄진다. 보통, [eax] 와 같은 형태에서 eax base 이다. Eax가 가리키고 있는 address data가 존재하는 경우이다.

 

8d8570ffffff    lea     eax,[ebp-90h]

 

이러한 pattern[ebp-90h] 와 같은 경우는 (ebp-offset이므로,) local variable의 형태인데, baseebpdisplacement에 해당하는 offset값이 90h 가 조합된 형태로, base+displacement 형태인데, lea , ebp-90h이 가리키는 데이터를 eax register load 하는 경우이다.

 

35 00411491 8b8564ffffff    mov     eax,dword ptr [ebp-9Ch]

  35 00411497 8b8d64ffffff    mov     ecx,dword ptr [ebp-9Ch]

  35 0041149d 8a540dac        mov     dl,byte ptr [ebp+ecx-54h]

  35 004114a1 88940570ffffff  mov     byte ptr [ebp+eax-90h],dl

 

[ebp+ecx-54h]의 경우는 ecx index에 해당한다. 그러므로, base+index+displacement 형태인데, 보통, array 연산에서 쉽게 볼 수 있다. 예를 들어 상위의 연산은 아래와 같은 c code disassemble 한 경우이다.

 

tmpCopy[j] = tmp[j];

 

, j 변수에 해당하는 값이 array index에 해당하는 데, 이것이 ecx eax값으로 사용되고 있다.

 

또한, base+(index*scale)+displacement 와 같은 구조도 나올 수 있다.

 

51 00411613 8b450c          mov     eax,dword ptr [ebp+0Ch]

  51 00411616 8b4d08          mov     ecx,dword ptr [ebp+8]

51 00411619 8b1481          mov     edx,dword ptr [ecx+eax*4]

51 0041161c 83c219          add     edx,19h

 

[ecx+eax*4] 에서 4 scale 해당한다. Ecx ebp+8 address값이므로, parameter값이다. 하지만, 이것이 pointer인지라, index 해당하는 eax( 역시 parameter 전달받은 값이다.) pointer size 4만큼 자리이동을 위치를 가리키고 있다. 마지막에 19h add하는 operation 존재하는 , 이는 다시 19h 만큼 displacement 하고 있다. 이유는 ebp+8 parameter 구조체 형태로 19h offset 해당하는 address 대한 연산을 하고 있기 때문이다.

 

(kp command)

0012fdc8 004114f2 mAddrModetest!AddAddrSeoulKorea(struct tagF ** param = 0x0012ff50, int idx = 1)

 

0:000> dv /V

0012fdd0 @ebp+0x08           param = 0x0012ff50

0012fdd4 @ebp+0x0c             idx = 1

 

0:000> dt tagF

mAddrModetest!tagF

   +0x000 name             : [20] Char

   +0x014 sex              : [5] Char

   +0x019 address          : [100] Char

   +0x080 age              : Int4B

 

상위는 아래와 같은 c code disassemble 경우이다.

 

bool AddAddrSeoulKorea (F** param, int idx)

{ /*..... 중략*/

                     strcpy(param[idx]->address, "Seoul Korea") ;

                /*...... 이하 생략*/ 

by SehYoon | 2008/05/06 14:20 | Windows debugging | 트랙백 | 덧글(0)
트랙백 주소 : http://byung.egloos.com/tb/4339721
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글

< 이전페이지 다음페이지 >