在很多機器上 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); //--------}}
}