SetUnhandledExceptionFilter
来源:互联网 发布:淘宝书店哪家是卖正品 编辑:程序博客网 时间:2024/05/16 04:19
最近解决了一个困扰项目多年的问题:程序弹出崩溃窗口(CRT窗口,或者是调用了不可靠的第三方动态库弹出的窗口)。百度上搜索SetUnhandledExceptionFilter,都是这样的代码
----------------------------------------------------------------------------------------------------------------------------
HMODULE hKernel32 = LoadLibrary(_T("kernel32.dll"));
if (hKernel32 == NULL)
return FALSE;
void *pOrgEntry = GetProcAddress(hKernel32, "SetUnhandledExceptionFilter");
if(pOrgEntry == NULL)
return FALSE;
unsigned char newJump[ 100 ];
DWORD dwOrgEntryAddr = (DWORD) pOrgEntry;
dwOrgEntryAddr += 5; // add 5 for 5 op-codes for jmp far
void *pNewFunc = &MyDummySetUnhandledExceptionFilter;
DWORD dwNewEntryAddr = (DWORD) pNewFunc;
DWORD dwRelativeAddr = dwNewEntryAddr - dwOrgEntryAddr;
newJump[ 0 ] = 0xE9; // JMP absolute
memcpy(&newJump[ 1 ], &dwRelativeAddr, sizeof(pNewFunc));
SIZE_T bytesWritten;
BOOL bRet = WriteProcessMemory(GetCurrentProcess(), pOrgEntry, newJump, sizeof(pNewFunc) + 1, &bytesWritten);
return bRet;
-------------------------------------------------------------------------------------------------------------------------------------
可是这些代码在我们的项目中完全不起作用,无论怎么用__try, __except都不行,最后写了个HOOK,钩住了3个函数:
MessageBoxA,MessageBoxW,SetUnhandledExceptionFilter
其中MessageBoxA,MessageBoxW针对CRT弹出错误窗口,SetUnhandledExceptionFilter针对werfault.exe之类的错误窗口,在进程winmain进入的时候,先调用SetUnhandledExceptionFilter,然后LoadLibrary这个HOOK动态库,程序终于消停了,再怎么崩溃也不弹窗口了
----------------------------------------------------------------------------------------------------------------------------
HMODULE hKernel32 = LoadLibrary(_T("kernel32.dll"));
if (hKernel32 == NULL)
return FALSE;
void *pOrgEntry = GetProcAddress(hKernel32, "SetUnhandledExceptionFilter");
if(pOrgEntry == NULL)
return FALSE;
unsigned char newJump[ 100 ];
DWORD dwOrgEntryAddr = (DWORD) pOrgEntry;
dwOrgEntryAddr += 5; // add 5 for 5 op-codes for jmp far
void *pNewFunc = &MyDummySetUnhandledExceptionFilter;
DWORD dwNewEntryAddr = (DWORD) pNewFunc;
DWORD dwRelativeAddr = dwNewEntryAddr - dwOrgEntryAddr;
newJump[ 0 ] = 0xE9; // JMP absolute
memcpy(&newJump[ 1 ], &dwRelativeAddr, sizeof(pNewFunc));
SIZE_T bytesWritten;
BOOL bRet = WriteProcessMemory(GetCurrentProcess(), pOrgEntry, newJump, sizeof(pNewFunc) + 1, &bytesWritten);
return bRet;
-------------------------------------------------------------------------------------------------------------------------------------
可是这些代码在我们的项目中完全不起作用,无论怎么用__try, __except都不行,最后写了个HOOK,钩住了3个函数:
MessageBoxA,MessageBoxW,SetUnhandledExceptionFilter
其中MessageBoxA,MessageBoxW针对CRT弹出错误窗口,SetUnhandledExceptionFilter针对werfault.exe之类的错误窗口,在进程winmain进入的时候,先调用SetUnhandledExceptionFilter,然后LoadLibrary这个HOOK动态库,程序终于消停了,再怎么崩溃也不弹窗口了
阅读全文
0 0
- SetUnhandledExceptionFilter
- SetUnhandledExceptionFilter
- SetUnhandledExceptionFilter
- SetUnhandledExceptionFilter
- SetUnhandledExceptionFilter
- SetUnhandledExceptionFilter使用
- disable setunhandledexceptionfilter
- SetUnhandledExceptionFilter + StackWalker
- SetUnhandledExceptionFilter function
- SetUnhandledExceptionFilter 的讨论
- SetUnhandledExceptionFilter和VS2005
- SetUnhandledExceptionFilter函数学习
- SetUnhandledExceptionFilter拦不住的崩溃
- SetUnhandledExceptionFilter函数学习
- SetUnhandledExceptionFilter函数学习
- VS2005中SetUnhandledExceptionFilter函数应用
- VS2005中SetUnhandledExceptionFilter函数应用
- VS2005中SetUnhandledExceptionFilter函数应用
- web静态服务器-epoll
- Hbase报错Master is initializing
- 微信推文代码高亮器
- 13、新手入手树莓派教程--Qt中使用wiringPi来驱动RGB灯、使用opencv打开网络摄像头(代码分享)
- 有关表单提交的类型标签选择
- SetUnhandledExceptionFilter
- 用DataSet操作XML
- HDU Zipper(搜索过的状态标记一下)
- Red Hat Linux 重置root密码
- P2679子串(dp)
- codeforces——D. Shovel Sale
- javascript:异常处理与错误处理
- Markdown学习笔记
- 稚嫩的软件工程师小王:第13工作日——MyBatis