函数调用约定
就是告诉编译器:怎么传递参数,怎么传递返回值,怎么平衡堆栈
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);
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论