internal static T QueryInformation <T>(this ProcessThread thread, ThreadInformationType informationType) where T : unmanaged { using var threadHandle = Kernel32.OpenThread(AccessMask.SpecificRightsAll | AccessMask.StandardRightsAll, false, thread.Id); if (threadHandle.IsInvalid) { throw new Win32Exception(); } Span <byte> informationBytes = stackalloc byte[Unsafe.SizeOf <T>()]; var status = Ntdll.NtQueryInformationThread(threadHandle, informationType, out informationBytes[0], informationBytes.Length, IntPtr.Zero); if (status != NtStatus.Success) { throw new Win32Exception(Ntdll.RtlNtStatusToDosError(status)); } return(MemoryMarshal.Read <T>(informationBytes)); }
internal static extern NtStatus NtQueryInformationThread(SafeThreadHandle threadHandle, ThreadInformationType informationType, out byte information, int informationSize, IntPtr returnLength);