Windows中有没有办法根据Python的需要抛出BSOD?

问题描述 投票:0回答:2

我正在制作一个脚本来测试一些始终运行的软件,我想测试它从 BSOD 的恢复情况。有没有一种方法可以从 python 抛出蓝屏而不调用外部脚本或可执行文件,如 OSR 的 BANG!

windows automated-tests bsod
2个回答
2
投票

有趣的事情。有一个 Windows 内核函数可以做到这一点。

我假设这是预期的行为,因为该功能已经存在

以下 Python 代码将使任何 Windows 计算机在用户模式下崩溃,无需任何额外设置。

from ctypes import windll
from ctypes import c_int
from ctypes import c_uint
from ctypes import c_ulong
from ctypes import POINTER
from ctypes import byref

nullptr = POINTER(c_int)()

windll.ntdll.RtlAdjustPrivilege(
    c_uint(19), 
    c_uint(1), 
    c_uint(0), 
    byref(c_int())
)

windll.ntdll.NtRaiseHardError(
    c_ulong(0xC000007B), 
    c_ulong(0), 
    nullptr, 
    nullptr, 
    c_uint(6), 
    byref(c_uint())
)

0
投票

我希望这有帮助(:

import ctypes
ntdll = ctypes.windll.ntdll
prev_value = ctypes.c_bool()
res = ctypes.c_ulong()
ntdll.RtlAdjustPrivilege(19, True, False, ctypes.byref(prev_value))
if not ntdll.NtRaiseHardError(0xDEADDEAD, 0, 0, 0, 6, ctypes.byref(res)):
    print("BSOD Successfull!")
else:
    print("BSOD Failed...")
© www.soinside.com 2019 - 2024. All rights reserved.