Hi there. The following code works fine but when a process is closed, I BSOD the PC ?
Even if I use try/ __try and except / __except. It looks like it crashes when Initializing OBJECT_ATTRIBUTES or when calling ZwOpenProcess…
Can you please help me, thank you.
NTSTATUS onExec(HANDLE ParentId,HANDLE ProcessId,BOOLEAN Create)
{
HANDLE hProcess=0;
NTSTATUS nRet;
KdPrint( ("WILH!OnExec()!\n") );
if( Create == TRUE && ParentId !=NULL && ProcessId!=NULL)
{
CLIENT_ID pClientId={0};
pClientId.UniqueProcess = (HANDLE)ProcessId;
pClientId.UniqueThread = 0 ;
//OBJECT_ATTRIBUTES pObjectAttributes={0};
// PUNICODE_STRING name;
//RtlIniUnicodeString(&name,L"hProcess");
//InitializeObjectAttributes(&pObjectAttributes,&name,OBJ_INHERIT | OBJ_KERNEL_HANDLE,ProcessId,NULL);
nRet = ZwOpenProcess(&hProcess,PROCESS_ALL_ACCESS,NULL,&pClientId);
if( hProcess && nRet == STATUS_SUCCESS)
{
nRet = ZwTerminateProcess(hProcess,STATUS_SUCCESS);
KdPrint( ("WILH!onExec: ZwTermianteProcess() returned: 0x%X\n",nRet) );
}
if( hProcess && nRet == STATUS_SUCCESS)
{
ZwClose(hProcess);
}
}
else
{
KdPrint( ("WILH!OnExec():Process terminated !\n"));
}
return STATUS_SUCCESS;
}
The code won’t be like that, meaning it won’t just terminate every process that starts up. I am just simply testing it.