函数调用约定

就是告诉编译器:怎么传递参数,怎么传递返回值,怎么平衡堆栈

int method(int x,int y)
{
    return x+y;
}
//调用
method(1,2);

常见的几种调用约定:

调用约定 参数压栈顺序 平衡堆栈
__cdecl 从右至左入栈 调用者清理栈
__stdcall 从右至左入栈 自身清理堆栈
__fastcall ECX/EDX 传送前两个,剩下:从右至左入栈 自身清理堆栈
int __stdcall method(int x,int y)
{
    return x+y;
}
//调用
method(1,2);
//观察反汇编堆栈变化

PS:一般情况下自带库默认使用 __stdcall 我们写的代码默认使用 __cdecl

函数指针类型变量的定义

函数指针变量定义的格式:

返回类型(调用约定 *变量名)(参数列表):

int (__cdecl *pFun)(int,int);

函数指针类型变量的赋值与使用

//定义函数指针变量
int (__cdecl *pFun)(int,int);
//为函数指针变量赋值
pFun =(int (__cdecl *)(int,int))10;
//使用函数指针变量
int r=pFun(1,2);
9:        //定义函数指针变量
10:       int (__cdecl *pFun)(int,int);
11:       //为函数指针变量赋值
12:       pFun =(int (__cdecl *)(int,int))10;
00401028   mov         dword ptr [ebp-4],0Ah
13:
14:       //使用函数指针变量
15:       int r=pFun(1,2);
0040102F   mov         esi,esp
00401031   push        2
00401033   push        1
00401035   call        dword ptr [ebp-4]
00401038   add         esp,8

通过函数指针绕过调试器断点

函数指针变量的定义

int (__stdcall *pFun)(int,int,int,int,int);

正常调用

MessageBox(0,0,0,0;

通过函数指针 绕过断点

pFun = (int (__stdcall *pFun)(int,int,int,int,int))0x77D5055c;
pFun(0,0,0,0,0);