From 02b4ce4fcd8ec334ebfecf8dae31b8cc58066eff Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Sat, 21 Jan 2006 17:36:05 +0000 Subject: [PATCH] don't read the image file name from the Peb in NtQueryInformationProcess (class ProcessImageFileName), use the section object instead svn path=/trunk/; revision=20962 --- reactos/ntoskrnl/ps/process.c | 3 + reactos/ntoskrnl/ps/query.c | 140 ++++++++-------------------------- 2 files changed, 33 insertions(+), 110 deletions(-) diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index b2d6e61c7c0..2f0ea4f1f49 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -320,6 +320,9 @@ PspCreateProcess(OUT PHANDLE ProcessHandle, Process->DebugPort = pDebugPort; Process->ExceptionPort = pExceptionPort; + /* Save the pointer to the section object */ + Process->SectionObject = SectionObject; + /* Setup the Lock Event */ DPRINT("Initialzing Process Lock\n"); KeInitializeEvent(&Process->LockEvent, SynchronizationEvent, FALSE); diff --git a/reactos/ntoskrnl/ps/query.c b/reactos/ntoskrnl/ps/query.c index 9641831b4b3..ae39db081d3 100644 --- a/reactos/ntoskrnl/ps/query.c +++ b/reactos/ntoskrnl/ps/query.c @@ -427,133 +427,53 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle, case ProcessImageFileName: { - /* - * We DO NOT return the file name stored in the EPROCESS structure. - * Propably if we can't find a PEB or ProcessParameters structure for the - * process! - */ - if(Process->Peb != NULL) - { - PRTL_USER_PROCESS_PARAMETERS ProcParams = NULL; - UNICODE_STRING LocalDest; - BOOLEAN Attached; ULONG ImagePathLen = 0; + PSECTION_OBJECT Section; PUNICODE_STRING DstPath = (PUNICODE_STRING)ProcessInformation; + PWSTR SrcBuffer = NULL, DstBuffer = (PWSTR)(DstPath + 1); - /* we need to attach to the process to make sure we're in the right context! */ - Attached = Process != PsGetCurrentProcess(); - - if(Attached) - KeAttachProcess(&Process->Pcb); + Section = (PSECTION_OBJECT)Process->SectionObject; - _SEH_TRY + if (Section != NULL && Section->FileObject != NULL) { - ProcParams = Process->Peb->ProcessParameters; - ImagePathLen = ProcParams->ImagePathName.Length; - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); + /* FIXME - check for SEC_IMAGE and/or SEC_FILE instead + of relying on FileObject being != NULL? */ + SrcBuffer = Section->FileObject->FileName.Buffer; + if (SrcBuffer != NULL) + { + ImagePathLen = Section->FileObject->FileName.Length; + } } - _SEH_END; - if(NT_SUCCESS(Status)) + if(ProcessInformationLength < sizeof(UNICODE_STRING) + ImagePathLen + sizeof(WCHAR)) { - if(ProcessInformationLength < sizeof(UNICODE_STRING) + ImagePathLen + sizeof(WCHAR)) - { Status = STATUS_INFO_LENGTH_MISMATCH; - } - else - { - PWSTR StrSource = NULL; - - RtlZeroMemory(&LocalDest, sizeof(LocalDest)); - - /* create a DstPath structure on the stack */ + } + else + { _SEH_TRY { - LocalDest.Length = ImagePathLen; - LocalDest.MaximumLength = ImagePathLen + sizeof(WCHAR); - LocalDest.Buffer = (PWSTR)(DstPath + 1); - - /* save a copy of the pointer to the source buffer */ - StrSource = ProcParams->ImagePathName.Buffer; + /* copy the string manually, don't use RtlCopyUnicodeString with DstPath! */ + DstPath->Length = ImagePathLen; + DstPath->MaximumLength = ImagePathLen + sizeof(WCHAR); + DstPath->Buffer = DstBuffer; + if (ImagePathLen != 0) + { + RtlCopyMemory(DstBuffer, + SrcBuffer, + ImagePathLen); + } + DstBuffer[ImagePathLen / sizeof(WCHAR)] = L'\0'; + + Status = STATUS_SUCCESS; } _SEH_HANDLE { - Status = _SEH_GetExceptionCode(); + Status = _SEH_GetExceptionCode(); } _SEH_END; - - if(NT_SUCCESS(Status)) - { - /* now, let's allocate some anonymous memory to copy the string to. - we can't just copy it to the buffer the caller pointed as it might - be user memory in another context */ - PWSTR PathCopy = ExAllocatePool(PagedPool, LocalDest.Length + sizeof(WCHAR)); - if(PathCopy != NULL) - { - /* make a copy of the buffer to the temporary buffer */ - _SEH_TRY - { - RtlCopyMemory(PathCopy, StrSource, LocalDest.Length); - PathCopy[LocalDest.Length / sizeof(WCHAR)] = L'\0'; - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - - /* detach from the process */ - if(Attached) - KeDetachProcess(); - - /* only copy the string back to the caller if we were able to - copy it into the temporary buffer! */ - if(NT_SUCCESS(Status)) - { - /* now let's copy the buffer back to the caller */ - _SEH_TRY - { - *DstPath = LocalDest; - RtlCopyMemory(LocalDest.Buffer, PathCopy, LocalDest.Length + sizeof(WCHAR)); - if (ReturnLength) - { - *ReturnLength = sizeof(UNICODE_STRING) + LocalDest.Length + sizeof(WCHAR); - } - } - _SEH_HANDLE - { - Status = _SEH_GetExceptionCode(); - } - _SEH_END; - } - - /* we're done with the copy operation, free the temporary kernel buffer */ - ExFreePool(PathCopy); - - /* we need to bail because we're already detached from the process */ - break; - } - else - { - Status = STATUS_INSUFFICIENT_RESOURCES; - } - } - } } - - /* don't forget to detach from the process!!! */ - if(Attached) - KeDetachProcess(); - } - else - { - /* FIXME - what to do here? */ - Status = STATUS_UNSUCCESSFUL; - } - break; + break; } case ProcessCookie: -- 2.17.1