본문 바로가기

해킹, 보안/리버싱

함수 호출 규악 (Calling Convention)

__cdecl Caller 매개 변수를 스택에 역순으로(오른쪽에서 왼쪽으로) 푸시합니다.
__stdcall 호출 수신자  
__fastcall 호출 수신자 매개 변수를 스택에 역순으로(오른쪽에서 왼쪽으로) 푸시합니다.

 

cdecl

C, C++ 기본 호출 규약

스택 정리 : 호출자

인자 전달 : 오른쪽에서 왼쪽

 

Example

int __cdecl cdeclCall(int arg1, int arg2, int arg3);

 

스택

push arg3

push arg2

push arg1

CALL cdeclCall


stdcall

Win32 API 표준 호출 규약

스택 정리 : 피호출자

인자 전달 : 오른쪽에서 왼쪽

 

Example

int __stdcall stdcallCall(int arg1, int arg2, int arg3);

스택

push arg3

push arg2

push arg1

CALL stdcallCall


fastcall

x86 아키텍쳐에만 적용됨

스택 정리 : 피호출자

인자 전달

처음 두 개의 DWORD 이하의 크기를 가지는 인자는 ECX 및 EDX 레지스터로 전달

다른 모든 인자는 오른쪽에서 왼쪽으로 스택을 통해 전달

 

Example

int __fastcall fastcallCall(int arg1, int arg2, int arg3);

스택

push arg3

mov edx, arg2

mov ecx, arg1

CALL fastcalllCall