https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3d2d957f81dcf5e32d35e3c406271c93b8daaf6e
commit 3d2d957f81dcf5e32d35e3c406271c93b8daaf6e Author: Pierre Schweitzer <pie...@reactos.org> AuthorDate: Thu Nov 29 20:28:06 2018 +0100 Commit: Pierre Schweitzer <pie...@reactos.org> CommitDate: Thu Nov 29 20:36:08 2018 +0100 [IPHLPAPI] Implement GetOwnerModuleFromTcpEntry() CORE-4792 --- dll/win32/iphlpapi/CMakeLists.txt | 2 +- dll/win32/iphlpapi/iphlpapi_main.c | 62 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/dll/win32/iphlpapi/CMakeLists.txt b/dll/win32/iphlpapi/CMakeLists.txt index 72acbf8b13..2b47c61629 100644 --- a/dll/win32/iphlpapi/CMakeLists.txt +++ b/dll/win32/iphlpapi/CMakeLists.txt @@ -29,6 +29,6 @@ add_library(iphlpapi SHARED set_module_type(iphlpapi win32dll UNICODE) target_link_libraries(iphlpapi wine tdilib) -add_importlibs(iphlpapi dhcpcsvc advapi32 ws2_32 msvcrt kernel32 ntdll) +add_importlibs(iphlpapi dhcpcsvc advapi32 psapi ws2_32 msvcrt kernel32 ntdll) add_pch(iphlpapi iphlpapi_private.h SOURCE) add_cd_file(TARGET iphlpapi DESTINATION reactos/system32 FOR all) diff --git a/dll/win32/iphlpapi/iphlpapi_main.c b/dll/win32/iphlpapi/iphlpapi_main.c index 31cf158c6d..023f2fd082 100644 --- a/dll/win32/iphlpapi/iphlpapi_main.c +++ b/dll/win32/iphlpapi/iphlpapi_main.c @@ -2,6 +2,7 @@ * iphlpapi dll implementation * * Copyright (C) 2003 Juan Lang + * 2018 Pierre Schweitzer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -23,6 +24,7 @@ #include <config.h> #include "iphlpapi_private.h" #include <strsafe.h> +#include <psapi.h> WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi); @@ -2292,9 +2294,63 @@ DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf) */ DWORD WINAPI GetOwnerModuleFromTcpEntry( PMIB_TCPROW_OWNER_MODULE pTcpEntry, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize) { - DWORD ret = NO_ERROR; - UNIMPLEMENTED; - return ret; + HANDLE Process; + DWORD FileLen, PathLen; + WCHAR File[MAX_PATH], Path[MAX_PATH]; + PTCPIP_OWNER_MODULE_BASIC_INFO BasicInfo; + + if (pTcpEntry->dwOwningPid == 0) + { + return ERROR_NOT_FOUND; + } + + Process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pTcpEntry->dwOwningPid); + if (Process == NULL) + { + return GetLastError(); + } + + FileLen = GetModuleBaseNameW(Process, NULL, File, MAX_PATH); + if (FileLen != 0) + { + PathLen = GetModuleFileNameExW(Process, NULL, Path, MAX_PATH); + if (PathLen == 0) + { + CloseHandle(Process); + return GetLastError(); + } + + /* Add NULL char */ + ++FileLen; + ++PathLen; + PathLen *= sizeof(WCHAR); + FileLen *= sizeof(WCHAR); + } + else if (GetLastError() == ERROR_PARTIAL_COPY) + { + wcscpy(File, L"System"); + wcscpy(Path, L"System"); + + PathLen = sizeof(L"System"); + FileLen = sizeof(L"System"); + } + + CloseHandle(Process); + + if (*pdwSize < sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + PathLen + FileLen) + { + *pdwSize = sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + PathLen + FileLen; + return ERROR_INSUFFICIENT_BUFFER; + } + + BasicInfo = Buffer; + BasicInfo->pModuleName = (PVOID)((ULONG_PTR)BasicInfo + sizeof(TCPIP_OWNER_MODULE_BASIC_INFO)); + BasicInfo->pModulePath = (PVOID)((ULONG_PTR)BasicInfo->pModuleName + FileLen); + wcscpy(BasicInfo->pModuleName, File); + wcscpy(BasicInfo->pModulePath, Path); + *pdwSize = sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + PathLen + FileLen; + + return NO_ERROR; } static void CreateNameServerListEnumNamesFunc( PWCHAR Interface, PWCHAR Server, PVOID Data)