Skip to content

Commit 49e652b

Browse files
RatinCNtkreuzer
authored andcommitted
[NTOS:PS] Implement ProcessImageFileNameWin32 information class
1 parent 805d4c7 commit 49e652b

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

ntoskrnl/include/internal/ps_i.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ static const INFORMATION_CLASS_INFO PsProcessInfoClass[] =
341341
/* ProcessImageFileNameWin32 */
342342
IQS_SAME
343343
(
344-
CHAR,
345-
CHAR,
346-
ICIF_NONE
344+
UNICODE_STRING,
345+
ULONG,
346+
ICIF_QUERY | ICIF_QUERY_SIZE_VARIABLE
347347
),
348348

349349
/* ProcessImageFileMapping */

ntoskrnl/ps/query.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,76 @@ NtQueryInformationProcess(
748748
break;
749749
}
750750

751+
#if (NTDDI_VERSION >= NTDDI_VISTA) || (DLL_EXPORT_VERSION >= _WIN32_WINNT_VISTA)
752+
case ProcessImageFileNameWin32:
753+
{
754+
PFILE_OBJECT FileObject;
755+
POBJECT_NAME_INFORMATION ObjectNameInformation;
756+
757+
/* Reference the process */
758+
Status = ObReferenceObjectByHandle(ProcessHandle,
759+
PROCESS_QUERY_INFORMATION, // FIXME: Use PROCESS_QUERY_LIMITED_INFORMATION if implemented
760+
PsProcessType,
761+
PreviousMode,
762+
(PVOID*)&Process,
763+
NULL);
764+
if (!NT_SUCCESS(Status))
765+
{
766+
break;
767+
}
768+
769+
/* Get the image path */
770+
Status = PsReferenceProcessFilePointer(Process, &FileObject);
771+
ObDereferenceObject(Process);
772+
if (!NT_SUCCESS(Status))
773+
{
774+
break;
775+
}
776+
Status = IoQueryFileDosDeviceName(FileObject, &ObjectNameInformation);
777+
ObDereferenceObject(FileObject);
778+
if (!NT_SUCCESS(Status))
779+
{
780+
break;
781+
}
782+
783+
/* Determine return length and output */
784+
Length = sizeof(UNICODE_STRING) + ObjectNameInformation->Name.MaximumLength;
785+
if (Length <= ProcessInformationLength)
786+
{
787+
_SEH2_TRY
788+
{
789+
PUNICODE_STRING ImageName = (PUNICODE_STRING)ProcessInformation;
790+
ImageName->Length = ObjectNameInformation->Name.Length;
791+
ImageName->MaximumLength = ObjectNameInformation->Name.MaximumLength;
792+
if (ObjectNameInformation->Name.MaximumLength)
793+
{
794+
ImageName->Buffer = (PWSTR)(ImageName + 1);
795+
RtlCopyMemory(ImageName->Buffer,
796+
ObjectNameInformation->Name.Buffer,
797+
ObjectNameInformation->Name.MaximumLength);
798+
}
799+
else
800+
{
801+
ASSERT(ImageName->Length == 0);
802+
ImageName->Buffer = NULL;
803+
}
804+
}
805+
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
806+
{
807+
Status = _SEH2_GetExceptionCode();
808+
}
809+
_SEH2_END;
810+
}
811+
else
812+
{
813+
Status = STATUS_INFO_LENGTH_MISMATCH;
814+
}
815+
ExFreePool(ObjectNameInformation);
816+
817+
break;
818+
}
819+
#endif /* (NTDDI_VERSION >= NTDDI_VISTA) || (DLL_EXPORT_VERSION >= _WIN32_WINNT_VISTA) */
820+
751821
case ProcessDebugFlags:
752822

753823
if (ProcessInformationLength != sizeof(ULONG))

0 commit comments

Comments
 (0)