加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

winapi – 如何在不获取WER对话框的情况下在Windows-7上崩溃进程

发布时间:2020-12-14 04:04:55 所属栏目:Windows 来源:网络整理
导读:是否可以在 Windows-7上崩溃常规用户模式进程而无需获取Windows错误报告(WER)对话框? (当WER正常启用且未应用特定标志时.) 注意:我对禁用WER不感兴趣,我对WER未启动的崩溃场景感兴趣,尽管它应该和Windows“默默地”终止应用程序. 在Windows XP上,编写一个C
是否可以在 Windows-7上崩溃常规用户模式进程而无需获取Windows错误报告(WER)对话框? (当WER正常启用且未应用特定标志时.)

注意:我对禁用WER不感兴趣,我对WER未启动的崩溃场景感兴趣,尽管它应该和Windows“默默地”终止应用程序.

在Windows XP上,编写一个C或C应用程序(在用户模式下)是非常简单的,它会以这样的方式混淆自己的地址空间:当最终引发访问冲突(或其他未处理的Win32异常)时,Windows XP将只是默默地终止进程而不通知用户:

...
void stackbreaker() {
    printf("%sn",__FUNCTION__);
    // global/static buffer
    static char buf[128] = "In a hole in the ground there lived a hobbit. And it burrowed through your stack. It even built a round door into you function.";
    // Get address on the stack
    char local;
    char* stack = &local;
    // nuke the stack:
    memcpy(stack - 64,buf,sizeof(buf));
    // Kaboom. No user defined unhandled exception filter will be called. Stack nuked.
    // Process will terminate silently on Windows XP.
    // But on Windows-7 you still get the WER dialog.
}
...

在一个简单的C项目中调用上述函数(在发布模式下 – 在测试时注意那些编译器优化 – 而不是在调试器下运行)将:

>在XP下静默终止进程.
>在Windows-7下显示WER崩溃对话框.
>旁白:在任何情况下都不会调用您自己的未处理异常过滤器,即使您通过SetUnhandledExceptionFilter设置了一个

我现在想知道的是 – 在Windows 7下 – 是否已经实现了WER机制,我总是在我的应用程序中获得崩溃[a]的错误对话框,或者即使在Windows 7中是否存在进程损坏情况,这会阻止WER对话框弹出?

我会添加一些读数:

Windows via C/C++ (5th ed by Richter,Nasarre)书中,他们描述了“错误过程”中发生的事情(第711页):

  1. Exception filters.
  2. kernel detects unhandled exception
  3. blocking ALPC call to Wer Service
  4. WER reporting kicks in.

现在,他们指出Win7与Windows XP的不同之处(引用本书第710页:)

… Starting with Windows Vista,the UnhandledExceptionFilter function no longer sends an error report to MS’ servers. Instead. The kernel detects that the exception is not handled by the user-mode thread (Step 4)…

因此,这意味着,在Vista及以上版本中,“崩溃”的过程完全没有任何办法可以阻止WER进入.我试图确认或反驳这一点.

[a]:显然,通过调用各种* exit或terminate *函数之一,可以很容易地“杀死”一个进程而没有任何痕迹.问题是,如果你可以排除这样的终止原因,(怎么样)可能会以一种阻止WER对话框显示的方式在Win7上“崩溃”用户模式进程.

我看了一下我的Windows Internals版本,但是在这个主题上没有太多可说的.在早期版本中,Windows错误报告例程发生在崩溃线程的上下文中.这意味着如果堆栈被删除(如您的示例中所示),则可能无法运行.

在Vista及更高版本中,它在崩溃的线程外部运行.此外,内核本身负责在进程崩溃时(通过高级本地过程调用)通知WER.

据Windows Internals称,这些变化解决了消失的流程问题.我只能听取他们的意见.显然,如果WER服务本身受损(或停止),您仍然会发生无声崩溃.

编辑

从Windows Internals,第5版,第122页:

Until Windows Vista,all the [WER] operations we’ve described had to occur within the crashing thread’s context… In certain types of crashes … the unhandled exception filter itself crashed. This “silent process death” was not logged anywhere. … Windows Vista and later versions improved the WER mechanism by performing this work externally from the crashed thread,if the unhandled exception filter itself crashes.

页面124:

…all Windows processes now have an error port that is actually an ALPC port object registered by the WER service. The kernel … will use this port to send a message to the WER service,which will then analyze the crashing process. … This solves all the problems of silent process death…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读