这段代码会蓝屏的,但:
if(virtualAddr>0x1000000) //填这么多足够破坏进程数据了
break;
这个判断极大降低了蓝屏的概率,但填这么多其实是不够的。大部分程序默认加载地址是0x00400000,所以对大部分程序有效,但是有些别有用心的一小撮程序改掉加载地址后就无效了。
正确的清0代码如下:(出自DebugMan)
VOID ZeroIt(PEPROCESS pProcess){
ULONG start,tmp;
KAPC_STATE kapc;
PHYSICAL_ADDRESS physicalAddr;
KeStackAttachProcess(pProcess,&kapc);
for(start=0x00010000;start< 0x60000000;start+=0x1000){
physicalAddr = MmGetPhysicalAddress((PVOID)start);
if( physicalAddr.HighPart > g_PhysicalPage.HighPart )
continue;
if( physicalAddr.HighPart == g_PhysicalPage.HighPart &&
physicalAddr.LowPart >= g_PhysicalPage.LowPart )
continue;
if ( !(physicalAddr.HighPart | physicalAddr.LowPart) )
continue;
if(start!=(ULONG)MmGetVirtualForPhysical(physicalAddr))
continue;
__asm {
cli;
mov eax,cr0;
and eax,not 10000h;
mov cr0,eax;
}
__try{
RtlZeroMemory( (PVOID)start, 0x1000);
}__except(1){
}
__asm {
mov eax,cr0
or eax,10000h
mov cr0,eax
sti
}
}
KeUnstackDetachProcess (&kapc);
}