Process monitoring CreateProcessNotifyRoutineEx

馋奶兔 提交于 2019-12-12 13:29:47

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/20502929/process-monitoring-createprocessnotifyroutineex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!