S.O.L.V.E.D !
Thanks everybody
With the previousMode set to KernelMode, no more access violation
Here's my code :
Assuming the true NtOpenProcess & NtTerminateProcess adresses are known
Code: Select allcase IOCTL_KILL_PID:
{
PDWORD pBufferIn;
NTSTATUS Status;
HANDLE process;
KPROCESSOR_MODE previousMode;
OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId;
ACCESS_MASK DesiredAccess;
pBufferIn = pIrp->AssociatedIrp.SystemBuffer;
DbgPrint("Killing %d\n", pBufferIn[0]);
if (OrigNtTerminateProcess != 0x0 && OrigNtOpenProcess != 0x0)
{
DesiredAccess = PROCESS_TERMINATE;
InitializeObjectAttributes(&ObjectAttributes, NULL, 0, NULL, NULL);
ClientId.UniqueProcess = (HANDLE)pBufferIn[0];
ClientId.UniqueThread = 0;
//---- Switch previous mode ----
previousMode = GetPreviousMode();
SetPreviousMode(KernelMode);
//--------------------------------
Status = ((NTOPENPROCESS) OrigNtOpenProcess)( &process, DesiredAccess, &ObjectAttributes, &ClientId);
if (NT_SUCCESS(Status))
{
retVal = ((NTTERMINATEPROCESS)(OrigNtTerminateProcess)) (process, 0);
pIrp->IoStatus.Information = 1;
ZwClose(process);
}
else
{
DbgPrint("OpenProcess failed 0x%x\n", Status);
retVal = STATUS_UNSUCCESSFUL;
pIrp->IoStatus.Information = 0;
}
//------- Restore previousMode -------
SetPreviousMode(previousMode);
//------------------------------------
}
break;
}