kernel32: Reimplement GetProcessVersion() in kernelbase.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-05-26 13:23:33 +02:00
parent 54a7e592e4
commit fc173ccca8
4 changed files with 25 additions and 57 deletions

View File

@ -793,7 +793,7 @@
# @ stub GetProcessorSystemCycleTime
@ stdcall -import GetProcessTimes(long ptr ptr ptr ptr)
# @ stub GetProcessUserModeExceptionPolicy
@ stdcall GetProcessVersion(long)
@ stdcall -import GetProcessVersion(long)
@ stdcall GetProcessWorkingSetSize(long ptr ptr)
@ stdcall -import GetProcessWorkingSetSizeEx(long ptr ptr ptr)
@ stdcall -import GetProductInfo(long long long long ptr)

View File

@ -451,61 +451,6 @@ BOOL WINAPI GetProcessAffinityMask( HANDLE hProcess, PDWORD_PTR process_mask, PD
}
/***********************************************************************
* GetProcessVersion (KERNEL32.@)
*/
DWORD WINAPI GetProcessVersion( DWORD pid )
{
HANDLE process;
NTSTATUS status;
PROCESS_BASIC_INFORMATION pbi;
SIZE_T count;
PEB peb;
IMAGE_DOS_HEADER dos;
IMAGE_NT_HEADERS nt;
DWORD ver = 0;
if (!pid || pid == GetCurrentProcessId())
{
IMAGE_NT_HEADERS *pnt;
if ((pnt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress )))
return ((pnt->OptionalHeader.MajorSubsystemVersion << 16) |
pnt->OptionalHeader.MinorSubsystemVersion);
return 0;
}
process = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, FALSE, pid);
if (!process) return 0;
status = NtQueryInformationProcess(process, ProcessBasicInformation, &pbi, sizeof(pbi), NULL);
if (status) goto err;
status = NtReadVirtualMemory(process, pbi.PebBaseAddress, &peb, sizeof(peb), &count);
if (status || count != sizeof(peb)) goto err;
memset(&dos, 0, sizeof(dos));
status = NtReadVirtualMemory(process, peb.ImageBaseAddress, &dos, sizeof(dos), &count);
if (status || count != sizeof(dos)) goto err;
if (dos.e_magic != IMAGE_DOS_SIGNATURE) goto err;
memset(&nt, 0, sizeof(nt));
status = NtReadVirtualMemory(process, (char *)peb.ImageBaseAddress + dos.e_lfanew, &nt, sizeof(nt), &count);
if (status || count != sizeof(nt)) goto err;
if (nt.Signature != IMAGE_NT_SIGNATURE) goto err;
ver = MAKELONG(nt.OptionalHeader.MinorSubsystemVersion, nt.OptionalHeader.MajorSubsystemVersion);
err:
CloseHandle(process);
if (status != STATUS_SUCCESS)
SetLastError(RtlNtStatusToDosError(status));
return ver;
}
/***********************************************************************
* SetProcessWorkingSetSize [KERNEL32.@]
* Sets the min/max working set sizes for a specified process.

View File

@ -636,7 +636,7 @@
@ stdcall GetProcessPriorityBoost(long ptr)
@ stdcall GetProcessShutdownParameters(ptr ptr)
@ stdcall GetProcessTimes(long ptr ptr ptr ptr)
@ stdcall GetProcessVersion(long) kernel32.GetProcessVersion
@ stdcall GetProcessVersion(long)
@ stdcall GetProcessWorkingSetSizeEx(long ptr ptr ptr)
# @ stub GetProcessorSystemCycleTime
@ stdcall GetProductInfo(long long long long ptr)

View File

@ -814,6 +814,29 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetProcessTimes( HANDLE process, FILETIME *create,
}
/***********************************************************************
* GetProcessVersion (kernelbase.@)
*/
DWORD WINAPI DECLSPEC_HOTPATCH GetProcessVersion( DWORD pid )
{
SECTION_IMAGE_INFORMATION info;
NTSTATUS status;
HANDLE process;
if (pid && pid != GetCurrentProcessId())
{
if (!(process = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, pid ))) return 0;
status = NtQueryInformationProcess( process, ProcessImageInformation, &info, sizeof(info), NULL );
CloseHandle( process );
}
else status = NtQueryInformationProcess( GetCurrentProcess(), ProcessImageInformation,
&info, sizeof(info), NULL );
if (!set_ntstatus( status )) return 0;
return MAKELONG( info.SubsystemVersionLow, info.SubsystemVersionHigh );
}
/***********************************************************************
* GetProcessWorkingSetSizeEx (kernelbase.@)
*/