aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGraham Bloice <graham.bloice@trihedral.com>2018-03-01 00:01:45 +0000
committerGraham Bloice <graham.bloice@trihedral.com>2018-03-01 22:32:04 +0000
commitbf4c2fd82b30d8b088fcb1235263dce9173d4cd7 (patch)
treee1488d70ee99709e6fb89ef80d5ab4aa9c198433
parent92bb9ec9da549991f402082794638a4458e77a81 (diff)
Windows: Remove cruft for unsupported versons
Remove all the existing LoadDLL\GetProcAddress combinations that allowed conditional Win32 API usage if supported on the running OS version. All the required functions are present in the versions we support. Change-Id: Ibc43e51cefcd1c7562d4e251784362509f224ed6 Reviewed-on: https://code.wireshark.org/review/26215 Petri-Dish: Graham Bloice <graham.bloice@trihedral.com> Tested-by: Petri Dish Buildbot Reviewed-by: Graham Bloice <graham.bloice@trihedral.com>
-rw-r--r--caputils/capture_win_ifnames.c115
-rw-r--r--ui/qt/CMakeLists.txt4
-rw-r--r--ui/qt/packet_list.cpp15
-rw-r--r--wsutil/file_util.c48
-rw-r--r--wsutil/os_version_info.c24
-rw-r--r--wsutil/privileges.c19
6 files changed, 54 insertions, 171 deletions
diff --git a/caputils/capture_win_ifnames.c b/caputils/capture_win_ifnames.c
index 2d237daee3..92b22b95d5 100644
--- a/caputils/capture_win_ifnames.c
+++ b/caputils/capture_win_ifnames.c
@@ -218,109 +218,42 @@ gboolean IsWindowsVistaOrLater()
char *
get_interface_friendly_name_from_device_guid(__in GUID *guid)
{
- HMODULE hIPHlpApi;
- HRESULT status;
- WCHAR wName[NDIS_IF_MAX_STRING_SIZE + 1];
HRESULT hr;
- gboolean fallbackToUnpublishedApi=TRUE;
- gboolean haveInterfaceFriendlyName=FALSE;
- int size;
- char *name;
-
- /* Load the ip helper api DLL */
- hIPHlpApi = LoadLibrary(TEXT("iphlpapi.dll"));
- if (hIPHlpApi == NULL) {
- /* Load failed - DLL should always be available in XP+*/
- return NULL;
- }
/* Need to convert an Interface GUID to the interface friendly name (e.g. "Local Area Connection")
* The functions required to do this all reside within iphlpapi.dll
- * - The preferred approach is to use published API functions (Available since Windows Vista)
- * - We do however fallback to trying undocumented API if the published API is not available (Windows XP/2k3 scenario)
*/
- if(IsWindowsVistaOrLater()){
- /* Published API function prototypes (for Windows Vista/Windows Server 2008+) */
- typedef NETIO_STATUS (WINAPI *ProcAddr_CIG2L) (__in CONST GUID *InterfaceGuid, __out PNET_LUID InterfaceLuid);
- typedef NETIO_STATUS (WINAPI *ProcAddr_CIL2A) ( __in CONST NET_LUID *InterfaceLuid,__out_ecount(Length) PWSTR InterfaceAlias, __in SIZE_T Length);
-
- /* Attempt to do the conversion using Published API functions */
- ProcAddr_CIG2L proc_ConvertInterfaceGuidToLuid=(ProcAddr_CIG2L) GetProcAddress(hIPHlpApi, "ConvertInterfaceGuidToLuid");
- if(proc_ConvertInterfaceGuidToLuid!=NULL){
- ProcAddr_CIL2A Proc_ConvertInterfaceLuidToAlias=(ProcAddr_CIL2A) GetProcAddress(hIPHlpApi, "ConvertInterfaceLuidToAlias");
- if(Proc_ConvertInterfaceLuidToAlias!=NULL){
- /* we have our functions ready to go, attempt to convert interface guid->luid->friendlyname */
- NET_LUID InterfaceLuid;
- hr = proc_ConvertInterfaceGuidToLuid(guid, &InterfaceLuid);
- if(hr==NO_ERROR){
- /* guid->luid success */
- hr = Proc_ConvertInterfaceLuidToAlias(&InterfaceLuid, wName, NDIS_IF_MAX_STRING_SIZE+1);
-
- if(hr==NO_ERROR){
- /* luid->friendly name success */
- haveInterfaceFriendlyName=TRUE; /* success */
- }else{
- /* luid->friendly name failed */
- fallbackToUnpublishedApi=FALSE;
+ NET_LUID InterfaceLuid;
+ hr = ConvertInterfaceGuidToLuid(guid, &InterfaceLuid);
+ if(hr == NO_ERROR) {
+ /* guid->luid success */
+ WCHAR wName[NDIS_IF_MAX_STRING_SIZE + 1];
+ hr = ConvertInterfaceLuidToAlias(&InterfaceLuid, wName, NDIS_IF_MAX_STRING_SIZE+1);
+ if(hr == NO_ERROR) {
+ /* luid->friendly name success */
+
+ /* Get the required buffer size, and then convert the string
+ * from UTF-16 to UTF-8. */
+ int size;
+ char *name;
+ size = WideCharToMultiByte(CP_UTF8, 0, wName, -1, NULL, 0, NULL, NULL);
+ if(size != 0) {
+ name = (char *) g_malloc(size);
+ if (name != NULL) {
+ size = WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, size, NULL, NULL);
+ if(size != 0) {
+ return name;
}
- }else{
- fallbackToUnpublishedApi=FALSE;
+ /* Failed, clean up the allocation */
+ g_free(name);
}
-
- }
- }
- }
-
-
- if(fallbackToUnpublishedApi && !haveInterfaceFriendlyName){
- /* Didn't manage to get the friendly name using published api functions
- * (most likely cause wireshark is running on Windows XP/Server 2003)
- * Retry using nhGetInterfaceNameFromGuid (an older unpublished API function) */
- typedef HRESULT (WINAPI *ProcAddr_nhGINFG) (__in GUID *InterfaceGuid, __out PCWSTR InterfaceAlias, __inout DWORD *LengthAddress, wchar_t *a4, wchar_t *a5);
-
- ProcAddr_nhGINFG Proc_nhGetInterfaceNameFromGuid = NULL;
- Proc_nhGetInterfaceNameFromGuid = (ProcAddr_nhGINFG) GetProcAddress(hIPHlpApi, "NhGetInterfaceNameFromGuid");
- if (Proc_nhGetInterfaceNameFromGuid!= NULL) {
- wchar_t *p4=NULL, *p5=NULL;
- DWORD NameSize;
-
- /* testing of nhGetInterfaceNameFromGuid indicates the unpublished API function expects the 3rd parameter
- * to be the available space in bytes (as compared to wchar's) available in the second parameter buffer
- * to receive the friendly name (in unicode format) including the space for the nul termination.*/
- NameSize = sizeof(wName);
-
- /* do the guid->friendlyname lookup */
- status = Proc_nhGetInterfaceNameFromGuid(guid, wName, &NameSize, p4, p5);
-
- if(status==0){
- haveInterfaceFriendlyName=TRUE; /* success */
}
}
}
- /* we have finished with iphlpapi.dll - release it */
- FreeLibrary(hIPHlpApi);
-
- if(!haveInterfaceFriendlyName){
- /* failed to get the friendly name, nothing further to do */
- return NULL;
- }
-
- /* Get the required buffer size, and then convert the string
- * from UTF-16 to UTF-8. */
- size=WideCharToMultiByte(CP_UTF8, 0, wName, -1, NULL, 0, NULL, NULL);
- name=(char *) g_malloc(size);
- if (name == NULL){
- return NULL;
- }
- size=WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, size, NULL, NULL);
- if(size==0){
- /* bytes written == 0, indicating some form of error*/
- g_free(name);
- return NULL;
- }
- return name;
+ /* Failed to get a name */
+ return NULL;
}
/*
diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt
index e4c827427f..1f70cf2f1f 100644
--- a/ui/qt/CMakeLists.txt
+++ b/ui/qt/CMakeLists.txt
@@ -697,6 +697,10 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.0.2")
)
endif()
+if (WIN32)
+ target_link_libraries(qtui "UxTheme.lib")
+endif()
+
#
# Editor modelines - http://www.wireshark.org/tools/modelines.html
#
diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp
index dd2582227d..5934523c5b 100644
--- a/ui/qt/packet_list.cpp
+++ b/ui/qt/packet_list.cpp
@@ -69,6 +69,7 @@
#ifdef Q_OS_WIN
#include "wsutil/file_util.h"
#include <QSysInfo>
+#include <Uxtheme.h>
#endif
// To do:
@@ -264,18 +265,8 @@ PacketList::PacketList(QWidget *parent) :
#ifdef Q_OS_WIN // && Qt version >= 4.8.6
if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {
- // See if we're running Vista or 7 and we have a theme applied.
- HMODULE uxtheme_lib = (HMODULE) ws_load_library("uxtheme.dll");
-
- if (uxtheme_lib) {
- typedef BOOL (WINAPI *IsAppThemedHandler)(void);
- typedef BOOL (WINAPI *IsThemeActiveHandler)(void);
-
- IsAppThemedHandler PIsAppThemed = (IsAppThemedHandler) GetProcAddress(uxtheme_lib, "IsAppThemed");
- IsThemeActiveHandler PIsThemeActive = (IsThemeActiveHandler) GetProcAddress(uxtheme_lib, "IsThemeActive");
- if (PIsAppThemed && PIsAppThemed() && PIsThemeActive && PIsThemeActive()) {
- style_inactive_selected = false;
- }
+ if (IsAppThemed() && IsThemeActive()) {
+ style_inactive_selected = false;
}
}
#endif
diff --git a/wsutil/file_util.c b/wsutil/file_util.c
index 346176065f..fad4fd287e 100644
--- a/wsutil/file_util.c
+++ b/wsutil/file_util.c
@@ -497,35 +497,25 @@ ws_init_dll_search_path()
unsigned int retval;
SC_HANDLE h_scm, h_serv;
- typedef BOOL (WINAPI *SetDllDirectoryHandler)(LPCTSTR);
- SetDllDirectoryHandler PSetDllDirectory;
- HMODULE kernel32_handle;
-
- kernel32_handle = GetModuleHandle(_T("kernel32.dll"));
- if (kernel32_handle != NULL) {
- PSetDllDirectory = (SetDllDirectoryHandler) GetProcAddress(kernel32_handle, "SetDllDirectoryW");
- if (PSetDllDirectory) {
- dll_dir_set = PSetDllDirectory(_T(""));
- if (dll_dir_set) {
- /* Do not systematically add Npcap path as long as we favor WinPcap over Npcap. */
- h_scm = OpenSCManager(NULL, NULL, 0);
- if (h_scm) {
- h_serv = OpenService(h_scm, _T("npf"), SC_MANAGER_CONNECT|SERVICE_QUERY_STATUS);
- if (h_serv) {
- CloseServiceHandle(h_serv);
- npf_found = TRUE;
- }
- CloseServiceHandle(h_scm);
- }
- if (!npf_found) {
- /* npf service was not found, so WinPcap is not (properly) installed.
- Add Npcap folder to libraries search path. */
- retval = GetSystemDirectoryW(npcap_path_w, MAX_PATH);
- if (0 < retval && retval <= MAX_PATH) {
- wcscat_s(npcap_path_w, MAX_PATH, L"\\Npcap");
- dll_dir_set = PSetDllDirectory(npcap_path_w);
- }
- }
+ dll_dir_set = SetDllDirectory(_T(""));
+ if (dll_dir_set) {
+ /* Do not systematically add Npcap path as long as we favor WinPcap over Npcap. */
+ h_scm = OpenSCManager(NULL, NULL, 0);
+ if (h_scm) {
+ h_serv = OpenService(h_scm, _T("npf"), SC_MANAGER_CONNECT|SERVICE_QUERY_STATUS);
+ if (h_serv) {
+ CloseServiceHandle(h_serv);
+ npf_found = TRUE;
+ }
+ CloseServiceHandle(h_scm);
+ }
+ if (!npf_found) {
+ /* npf service was not found, so WinPcap is not (properly) installed.
+ Add Npcap folder to libraries search path. */
+ retval = GetSystemDirectoryW(npcap_path_w, MAX_PATH);
+ if (0 < retval && retval <= MAX_PATH) {
+ wcscat_s(npcap_path_w, MAX_PATH, L"\\Npcap");
+ dll_dir_set = SetDllDirectory(npcap_path_w);
}
}
}
diff --git a/wsutil/os_version_info.c b/wsutil/os_version_info.c
index 44c00397f8..b9aeaf2477 100644
--- a/wsutil/os_version_info.c
+++ b/wsutil/os_version_info.c
@@ -28,10 +28,6 @@
#include <wsutil/os_version_info.h>
-#ifdef _WIN32
-typedef void (WINAPI *nativesi_func_ptr)(LPSYSTEM_INFO);
-#endif
-
/*
* Handles the rather elaborate process of getting OS version information
* from macOS (we want the macOS version, not the Darwin version, the latter
@@ -190,10 +186,8 @@ void
get_os_version_info(GString *str)
{
#if defined(_WIN32)
- HMODULE kernel_dll_handle;
OSVERSIONINFOEX info;
SYSTEM_INFO system_info;
- nativesi_func_ptr nativesi_func;
#elif defined(HAVE_SYS_UTSNAME_H)
struct utsname name;
#endif
@@ -228,21 +222,9 @@ get_os_version_info(GString *str)
}
memset(&system_info, '\0', sizeof system_info);
- /* Look for and use the GetNativeSystemInfo() function if available to get the correct processor
- * architecture even when running 32-bit Wireshark in WOW64 (x86 emulation on 64-bit Windows) */
- kernel_dll_handle = GetModuleHandle(_T("kernel32.dll"));
- if (kernel_dll_handle == NULL) {
- /*
- * XXX - get the failure reason.
- */
- g_string_append(str, "unknown Windows version");
- return;
- }
- nativesi_func = (nativesi_func_ptr)GetProcAddress(kernel_dll_handle, "GetNativeSystemInfo");
- if(nativesi_func)
- nativesi_func(&system_info);
- else
- GetSystemInfo(&system_info);
+ /* Look for and use the GetNativeSystemInfo() function to get the correct processor architecture
+ * even when running 32-bit Wireshark in WOW64 (x86 emulation on 64-bit Windows) */
+ GetNativeSystemInfo(&system_info);
switch (info.dwPlatformId) {
diff --git a/wsutil/privileges.c b/wsutil/privileges.c
index 5ce48850c6..e1fef22026 100644
--- a/wsutil/privileges.c
+++ b/wsutil/privileges.c
@@ -31,14 +31,6 @@
void
init_process_policies(void)
{
- HMODULE kernel32Handle;
- typedef BOOL (WINAPI *SetProcessDEPPolicyHandler)(DWORD);
- SetProcessDEPPolicyHandler PSetProcessDEPPolicy;
-
-#ifndef PROCESS_DEP_ENABLE
-#define PROCESS_DEP_ENABLE 1
-#endif
-
/*
* If we have SetProcessDEPPolicy(), turn "data execution
* prevention" on - i.e., if the MMU lets you set execute
@@ -48,17 +40,8 @@ init_process_policies(void)
* we don't care (we did our best), so we don't check for
* errors.
*
- * XXX - if the GetModuleHandle() call fails, should we report
- * an error? That "shouldn't happen" - it's the equivalent
- * of libc.{so,sl,a} or libSystem.dylib being missing on UN*X.
*/
- kernel32Handle = GetModuleHandle(_T("kernel32.dll"));
- if (kernel32Handle != NULL) {
- PSetProcessDEPPolicy = (SetProcessDEPPolicyHandler) GetProcAddress(kernel32Handle, "SetProcessDEPPolicy");
- if (PSetProcessDEPPolicy) {
- PSetProcessDEPPolicy(PROCESS_DEP_ENABLE);
- }
- }
+ SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
}
/*