在很多机器上 SSDT 表是不可写的,写即导致机器无提示崩溃重启。这是需要去除核心内存的写保护:
//----------------------------------------------------------------------
//
// 设置核心内存访问保护
//
//----------------------------------------------------------------------
//
// SpinLock protection
//
static KSPIN_LOCK gs_mmProtectionSpinLock;
static KIRQL gs_OldIrql;
static ULONG CR0VALUE = 0;
//
// initialize the global data structures, when the driver is loading
//
NTSTATUS
mmProtection_LoadInit()
{
//
KeInitializeSpinLock(&gs_mmProtectionSpinLock);
return STATUS_SUCCESS;
}
/*++
Routine Description:
禁用Windows NT/2000/XP的内存保护,使只读内存区可写
Arguments:
Return Value:
--*/
void mmDisableProtection()
{
KeAcquireSpinLock(&gs_mmProtectionSpinLock, &gs_OldIrql); //--------{{
__asm
{
mov eax, cr0
mov CR0VALUE, eax
and eax, 0xFFFEFFFF
mov cr0, eax
}
}
/*++
Routine Description:
恢复Windows NT/2000/XP的内存保护
Arguments:
Return Value:
--*/
void mmEnableProtection()
{
__asm
{
mov eax, CR0VALUE
mov cr0, eax
}
KeReleaseSpinLock(&gs_mmProtectionSpinLock, gs_OldIrql); //--------}}
}