我在学习_achillis的隐藏模块驱动代码时,其中清除PE文件头的函数中MmGetSystemAddressForMdl老是失败,返回错误代码为:0xC0000005。这个问题我搞了二天也没搞定,请大侠帮忙解答一下,万分感谢。函数如下:
VOID ZeroPEHeader(ULONG ImageBase)
{
PIMAGE_DOS_HEADER pDosHeader;
char *pNtHeader;
PIMAGE_OPTIONAL_HEADER pOptinalHeader;
ULONG HeaderSize=0;
PMDL pHeaderMdl;
PVOID NewBuffer;
__try
{
pDosHeader=(PIMAGE_DOS_HEADER)ImageBase;
pNtHeader=(char*)ImageBase+pDosHeader->e_lfanew;
pOptinalHeader=(PIMAGE_OPTIONAL_HEADER)(pNtHeader+4+sizeof(IMAGE_FILE_HEADER));
HeaderSize=pOptinalHeader->SizeOfHeaders;
dprintf("Image Header Size=0x%X\n",HeaderSize);
pHeaderMdl=IoAllocateMdl((PVOID)ImageBase,HeaderSize,FALSE,FALSE,NULL);
dprintf("pHeaderMdl=0x%08X\n",pHeaderMdl);
NewBuffer=MmGetSystemAddressForMdl(pHeaderMdl);
dprintf("NewBuffer=0x%08X\n",NewBuffer);
RtlZeroMemory(NewBuffer,HeaderSize);
MmUnmapLockedPages(NewBuffer,pHeaderMdl);
IoFreeMdl(pHeaderMdl);
//若要针对所有进程,可使用以下方法,此时COW将会失效
/*
WPOFF();
RtlZeroMemory((char*)ImageBase,HeaderSize);
WPON();
*/
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DbgPrint("Error occured while zero pe header.\n");
return ;
}
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!