为什么SEH的实现是push -1;push __ehhandler$_wmain?
在main函数的开始出,生成的汇编代码通常含有:
push -1 ; 建立SEH(Structured Exception Handler)链
; -1表示表头,没有Prev
这个-1到底是什么含义? 难道还可以push -2,push -3么?
而且在main函数的结尾,也没有看到这个-1如何被pop了来平衡堆栈啊。
[解决办法]
给代码
如果用了ebp,是不需要pop的,直接leave
[解决办法]
帮助文件“A Crash Course on the Depths of Win32 Structured Exception Handling”
int main()
{
DWORD handler = (DWORD)_except_handler;
__asm
{ // Build EXCEPTION_REGISTRATION record:
push handler // Address of handler function
push FS:[0] // Address of previous handler
mov FS:[0],ESP // Install new EXECEPTION_REGISTRATION
}
反汇编中看到FS:。。。就是SEH了。
[解决办法]
typedef struct _EXCEPTION_REGISTRATION
{
struct _EXCEPTION_REGISTRATION *prev;
DWORD handler;
}EXCEPTION_REGISTRATION, *PEXCEPTION_REGISTRATION;
给main下面的代码