简体   繁体   中英

Process monitoring CreateProcessNotifyRoutineEx

I'm developing a driver for monitoring process creation, I wrote a simple code to do it. I use the PsSetCreateProcessNotifyRoutineEx . But this doesn't work ! I exactly following Microsoft help on this link

#include <ntddk.h>

NTSTATUS DriverEntry(
    IN PDRIVER_OBJECT DriverObject,  
    IN PUNICODE_STRING RegistryPath
    );

VOID UnloadRoutine(
    IN PDRIVER_OBJECT DriverObject
    );

VOID CreateProcessNotifyEx(
    __inout   PEPROCESS Process,
    __in      HANDLE ProcessId,
    __in_opt  PPS_CREATE_NOTIFY_INFO CreateInfo
);



VOID CreateProcessNotifyEx(
    __inout   PEPROCESS Process,
    __in      HANDLE ProcessId,
    __in_opt  PPS_CREATE_NOTIFY_INFO CreateInfo

)
{
    if (CreateInfo)
    {
        if(CreateInfo->FileOpenNameAvailable==TRUE)
        {
            DbgPrintEx( 
                DPFLTR_IHVDRIVER_ID,  
                DPFLTR_INFO_LEVEL,
                "PID : 0x%X (%d)  ImageName :%wZ CmdLine : %wZ \n",
                ProcessId,ProcessId,
                CreateInfo->ImageFileName,
                CreateInfo->CommandLine
                );
        }
    }

}


VOID UnloadRoutine(IN PDRIVER_OBJECT DriverObject)
{
    PsSetCreateProcessNotifyRoutineEx((PCREATE_PROCESS_NOTIFY_ROUTINE_EX)  CreateProcessNotifyEx, TRUE);
    DbgPrintEx( DPFLTR_IHVDRIVER_ID,  DPFLTR_INFO_LEVEL,"Unloaded\n");
}

NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,  IN PUNICODE_STRING RegistryPath)
{

    NTSTATUS status = PsSetCreateProcessNotifyRoutineEx((PCREATE_PROCESS_NOTIFY_ROUTINE_EX)CreateProcessNotifyEx, FALSE);
  if(!NT_SUCCESS(status))
  {
     DbgPrintEx( DPFLTR_IHVDRIVER_ID,  DPFLTR_ERROR_LEVEL,"Faild to PsSetCreateProcessNotifyRoutineEx .status : 0x%X \n",status);
  }
    DriverObject->DriverUnload = UnloadRoutine;
     DbgPrintEx( DPFLTR_IHVDRIVER_ID,  DPFLTR_INFO_LEVEL,"Load\n");

    return STATUS_SUCCESS; 

}

This drive load and run correctly but when run a program(new process), Doesn't happen any thing and can't register PsSetCreateProcessNotifyRoutineEx and i got 0xC0000022 Error (Access Denied). 在此输入图像描述

Any idea ?

Always i have to find my answer ;)

For passing this problem only need to add this value LINKER_FLAGS=/integritycheck to SOURCE file !

Before :

TARGETNAME=ProcView
TARGETPATH=.
TARGETTYPE=DRIVER

SOURCES=ProcView.c

Now :

TARGETNAME=ProcView
TARGETPATH=.
TARGETTYPE=DRIVER
LINKER_FLAGS=/integritycheck
SOURCES=ProcView.c

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM