今天hook ZwCreateSection 这个函数 搞了半天,老是蓝屏,纠结的我一天没吃饭,哪位高人给看看为啥蓝屏啊?应该咋该啊?
#include "NTDDK.H"
ULONG g_uCr0;
VOID WpOff()
{
ULONG uAttr;
_asm
{
push eax
mov eax,cr0
mov uAttr,eax
and eax,0xfffeffff
mov cr0,eax
pop eax
}
g_uCr0=uAttr;
}
VOID WpOn()
{
_asm
{
push eax
mov eax,g_uCr0
mov cr0,eax
pop eax
}
}
_declspec(naked) my_Function()
{
_asm
{
mov eax,32h
lea edx,[esp+4]
_emit 0xEA
_emit 0xAA
_emit 0xAA
_emit 0xAA
_emit 0xAA
_emit 0x08
_emit 0x00
}
}
VOID Hook_Function()
{
int i;
KIRQL oldIrql;
char *non_page_memory;
PULONG old_Function;
ULONG fan_Address;
UNICODE_STRING functionName;
UCHAR new_code[]={0xEA,0x00,0x00,0x00,0x00,0x08,0x00,0x90,0x90};
RtlInitUnicodeString(&functionName,L"ZwCreateSection");
old_Function=MmGetSystemRoutineAddress(&functionName);
if(!old_Function)
{
return NULL;
}
fan_Address=(ULONG)old_Function+9;
non_page_memory=ExAllocatePool(NonPagedPool,256);
for(i=0;i<256;i++)
{
((unsigned *)non_page_memory)[i]=((unsigned *)my_Function)[i];
}
*((PULONG)(&new_code[1]))=(ULONG)non_page_memory;
for(i=0;i<256;i++)
{
if((PUCHAR)non_page_memory[i]==0xAA &&
(PUCHAR)non_page_memory[i+1]==0xAA &&
(PUCHAR)non_page_memory[i+2]==0xAA &&
(PUCHAR)non_page_memory[i+3]==0xAA )
{
*((PULONG)(&non_page_memory[i]))=fan_Address;
}
}
oldIrql = KeRaiseIrqlToDpcLevel();
WpOff();
for(i=0;i<9;i++)
{
old_Function[i]=new_code[i];
}
WpOn();
KeLowerIrql(oldIrql);
}
my_Unload(PDRIVER_OBJECT pDriverObject)
{
KdPrint(("enter DriverUnload\n"));
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject,PUNICODE_STRING pRegistryPath)
{
pDriverObject->DriverUnload=my_Unload;
Hook_Function();
return STATUS_SUCCESS;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!