Windows 驱动: 消除核心内存的只读保护

本文介绍了一种在Windows NT/2000/XP系统中禁用核心内存保护的方法,通过修改CR0寄存器来实现只读内存区域的可写操作,并提供了重新启用内存保护的代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值