if (g_ActivateInfo.bActivated != bActive)
{
if (bActive)
{
KdPrint(("Set PsSetCreateProcessNotifyRoutine\n"));
// Set up callback routines
ntStatus = PsSetCreateProcessNotifyRoutine(ProcessCreateOrTerminateCallback, FALSE);
if (ntStatus != STATUS_SUCCESS)
{
KdPrint(("Set PsSetCreateProcessNotifyRoutine Failed\n"));
return ntStatus;
}
// Setup the global data structure
g_ActivateInfo.bActivated = bActive;
KdPrint(("Set PsSetCreateProcessNotifyRoutine success\n"));
}
else
{
// restore the call back routine, thus givinig chance to the
// user mode application to unload dynamically the driver
ntStatus = PsSetCreateProcessNotifyRoutine(ProcessCreateOrTerminateCallback, TRUE);
if (ntStatus != STATUS_SUCCESS)
return ntStatus;
else
g_ActivateInfo.bActivated = FALSE;
}
ntStatus = STATUS_SUCCESS;
}
return ntStatus;
}
回调函数如下:
VOID ProcessCreateOrTerminateCallback(
IN HANDLE hParentId,
IN HANDLE hProcessId,
IN BOOLEAN bCreate
)
{
NTSTATUS status;
PEPROCESS pEProc;
CHAR *pName; //进程名
ANSI_STRING QQExeName;
ANSI_STRING CurExeName;
KIRQL oldIrql;
if (bCreate)
{
// PsLookupProcessByProcessId routine accepts the process ID of a process
// and returns a referenced pointer to EPROCESS structure of the process.
PsLookupProcessByProcessId(hProcessId, &pEProc);