代码如下:
ULONG g_ntopenkey;
ULONG g_jmp_orig_ntopenkey;
UCHAR g_orig_funcode[5];
void FilterNtOpenKey()
{
KdPrint(("%s", (char*) PsGetCurrentProcess + 0x174));
}
__declspec (naked) void NewNtOpenKey()
{
__asm
{
call FilterNtOpenKey
pop eax
mov edi,edi
push ebp
mov ebp, esp
jmp g_jmp_orig_ntopenkey
}
}
void HookNtOpenKey()
{
ULONG u_jmp_temp;
UCHAR jmp_code[5];
g_ntopenkey = KeServiceDescriptorTable.ServiceTableBase[119];
g_jmp_orig_ntopenkey = g_ntopenkey+5;
//计算跳转地址
u_jmp_temp = (ULONG)NewNtOpenKey - g_ntopenkey - 5;
jmp_code[0] = 0XE8; //call
//写入跳跳地址
*(ULONG*)&jmp_code[1] = u_jmp_temp;
PageprotectOff();
//保存原来和前面5个字节
RtlCopyMemory(g_orig_funcode,(PVOID)g_ntopenkey,5);
//写入Hook后的5个字节
RtlCopyMemory((PVOID)g_ntopenkey,jmp_code,5);
PageprotectOn();
}
void UnHookOpenKey()
{
PageprotectOff();
RtlCopyMemory((PVOID)g_ntopenkey, g_orig_funcode,5);
PageprotectOn();
}
void HookUnLoad(PDRIVER_OBJECT pDriverObject)
{
UnHookOpenKey();
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriver,PUNICODE_STRING Reg_Path)
{
HookNtOpenKey();
g_ntopenkey = KeServiceDescriptorTable.ServiceTableBase[119];
pDriver->DriverUnload = HookUnLoad;
return STATUS_SUCCESS;
}
运行环境XP SP2,想Hook NTOpenKey,其SSDT编号为119.但是总是蓝屏,求教大侠,错在哪里了。
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!