我可以有任何方法来检测驱动程序签名策略状态吗?

Can I have any way to detect the Driver Signing Policy status?

本文关键字:策略 状态 驱动程序 任何 方法 检测 我可以      更新时间:2023-10-16

我有一个修改过的驱动程序,当驱动程序签名被禁用时必须安装,所以我想检测这个状态以提醒用户重新启动到SafeMode。我尝试了这个命令:Bcdedit.exe -set TESTSIGNING OFF,但是失败了,提示

设置元素数据出错。受安全启动策略保护,不能修改和删除。

嗯. .有什么办法可以做到吗?

————————

PS:事实上,我的笔记本型号是MSI GS70 2PE。我不认为这是一个便宜的,即使是最新发布的GS73也不能支持完整的win10手势。它支持Windows10,但微星确实没有发布最新的驱动程序。如果只是我自己修改和使用,那就不值一提了。但是,我想在论坛上分享它,以帮助其他一般用户使用。

我做错了什么吗?我不明白为什么有人在谈论别的事情。

使用以下代码检测是否启用TESTSIGNING:

#include <Winternl.h>
#pragma comment(lib, "ntdll.lib")

//Check if testsigning is enabled
SYSTEM_CODEINTEGRITY_INFORMATION sci = {0};
ULONG dwcbSz = 0;
sci.Length = sizeof(sci);
if(NtQuerySystemInformation(
    /*SystemCodeIntegrityInformation*/ (SYSTEM_INFORMATION_CLASS)0x67, 
    &sci, 
    sizeof(sci), 
    &dwcbSz) >= 0 &&
    dwcbSz == sizeof(sci))
{
    BOOL bTestsigningEnabled = !!(sci.CodeIntegrityOptions & /*CODEINTEGRITY_OPTION_TESTSIGN*/ 0x2);
    //Note that testsigning will play no role if bit CODEINTEGRITY_OPTION_ENABLED (or 0x1) is not set in sci.CodeIntegrityOptions
}

我宁愿把它包装成一个更好的函数,像这样:

bool IsSystemCodeIntegrityEnabled() {
        typedef NTSTATUS(__stdcall* td_NtQuerySystemInformation)(
                ULONG           SystemInformationClass,
                PVOID           SystemInformation,
                ULONG           SystemInformationLength,
                PULONG          ReturnLength
                );
        struct SYSTEM_CODEINTEGRITY_INFORMATION {
                ULONG Length;
                ULONG CodeIntegrityOptions;
        };
        static td_NtQuerySystemInformation NtQuerySystemInformation = (td_NtQuerySystemInformation)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtQuerySystemInformation");
        SYSTEM_CODEINTEGRITY_INFORMATION Integrity ={ sizeof(SYSTEM_CODEINTEGRITY_INFORMATION), 0 };
        NTSTATUS status = NtQuerySystemInformation(103, &Integrity, sizeof(Integrity), NULL);
        return (NT_SUCCESS(status) && (Integrity.CodeIntegrityOptions & 1));
}