HI
I have registered for process create notification through PsSetCreateProceeNotify and in my callback, I have the below code to retrieve the process parameters (imageName and cmdLine).
try {
NTSTATUS ret;
extension = gpDeviceObject->DeviceExtension;
ret = PsLookupProcessByProcessId(ProcessId, &pProcess);
if(NT_SUCCESS(ret)) {
if(NULL != pProcess) {
KPROCESS* pKProc = (KPROCESS*)pProcess;
pPEB = PsGetProcessPeb(pProcess);
if(NULL != pPEB) {
DWORD dwImageLength = 0, dwCmdLineLength = 0;
NTSTATUS ntStatus = 0;
PKAPC_STATE pAPCState = NULL;
pAPCState = ExAllocatePoolWithTag(NonPagedPool,sizeof(KAPC_STATE),‘cpak’);
KeStackAttachProcess(pProcess,pAPCState);
dwImageLength = ((pPEB->ProcessParameters->ImagePathName.Length > 255*sizeof(WCHAR)) ? 255*sizeof(WCHAR): pPEB->ProcessParameters->ImagePathName.Length);
dwCmdLineLength = ((pPEB->ProcessParameters->CommandLine.Length > 255*sizeof(WCHAR)) ? 255*sizeof(WCHAR): pPEB->ProcessParameters->CommandLine.Length);
RtlCopyMemory(imagePathW, pPEB->ProcessParameters->ImagePathName.Buffer, dwImageLength);
RtlCopyMemory(cmdLineW, pPEB->ProcessParameters->CommandLine.Buffer, dwCmdLineLength);
KeUnstackDetachProcess(pAPCState);
ExFreePool(pAPCState);
}
ObDereferenceObject(pProcess);
}
}
} except(EXCEPTION_EXECUTE_HANDLER) {
}
This works fine on Vista and Win7 32/64bit platforms but fails on XP 32bit with bugcheck INVALID_PROCESS_ATTACH_ATTEMPT. Could someone explain me what am I doing wrong in the above code.
Thanks
Ramananda