自己去网上找个hook引擎来替换下面这个吧,硬盘不小心被我格了。。。
#include <ntddk.h>
#include "InlineHook.h"
typedef NTSTATUS (*ZWTERMINATEPROCESS)(
IN HANDLE ProcessHandle,
IN NTSTATUS ExitStatus);
ZWTERMINATEPROCESS OldZwTerminateProcess;
int ZwTerminateProcessPatchCodeLen = 0;
#pragma LOCKEDCODE
PVOID ZwTerminateProcessRet;
int iProcess = FALSE;
#pragma LOCKEDCODE
__declspec(naked) NTSTATUS ZwTerminateProcessHookZone(,...)
{
_asm
{
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
_emit 0x90;
jmp [ZwTerminateProcessRet];
}
}
NTSTATUS DriverUnload(
IN PDRIVER_OBJECT DriverObject
)
{
if (iProcess == TRUE)
{
UnHookApi(L"ZwTerminateProcess",FALSE,0,(PVOID)ZwTerminateProcessHookZone,ZwTerminateProcessPatchCodeLen);
}
DbgPrint("驱动已经被卸载了\n");
return STATUS_SUCCESS;
}
NTSTATUS
NewZwTerminateProcess(
IN HANDLE ProcessHandle,
IN NTSTATUS ExitStatus
)
{
NTSTATUS status;
DbgPrint("Hook Success\n");
OldZwTerminateProcess = (ZWTERMINATEPROCESS)ZwTerminateProcessHookZone;
status = OldZwTerminateProcess(ProcessHandle,ExitStatus);
if( NT_SUCCESS(status))
{
return status;
}
return status;
}
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
int bRet;
DbgPrint("驱动已经加载了\n");
DbgPrint("Hello World\n");
DriverObject->DriverUnload = DriverUnload;
bRet = HookApi((DWORD)NewZwTerminateProcess,L"ZwTerminateProcess",FALSE,0,(PVOID)ZwTerminateProcessHookZone,&ZwTerminateProcessPatchCodeLen,&ZwTerminateProcessRet);
if(!bRet)
{
DbgPrint("hook ZwTerminateProcess failed\n");
}else{
iProcess = TRUE;
}
return STATUS_SUCCESS;
}