From 700a3783ee4912e1000347bcde2116863507fbbd Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 19 Nov 2013 11:14:36 +0000 Subject: * Makefile.in (cygcheck.exe): Link against wininet.dll. (dumper.exe): Link against psapi.dll. * cygcheck.cc (_WIN32_WINNT): Define as 0x0602. (pInternetCloseHandle): Drop pointer. (PRODUCT_UNLICENSED): Drop definition. (PRODUCT_PROFESSIONAL_WMC): Ditto. (package_grep): Delete code loading wininet functions dynamically, just call functions directly. --- winsup/utils/ChangeLog | 11 ++++++++ winsup/utils/Makefile.in | 4 +-- winsup/utils/cygcheck.cc | 62 +++++++-------------------------------------- winsup/utils/module_info.cc | 51 +++---------------------------------- 4 files changed, 26 insertions(+), 102 deletions(-) (limited to 'winsup') diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog index b317a4b86..fff35e2ec 100644 --- a/winsup/utils/ChangeLog +++ b/winsup/utils/ChangeLog @@ -1,3 +1,14 @@ +2013-11-19 Corinna Vinschen + + * Makefile.in (cygcheck.exe): Link against wininet.dll. + (dumper.exe): Link against psapi.dll. + * cygcheck.cc (_WIN32_WINNT): Define as 0x0602. + (pInternetCloseHandle): Drop pointer. + (PRODUCT_UNLICENSED): Drop definition. + (PRODUCT_PROFESSIONAL_WMC): Ditto. + (package_grep): Delete code loading wininet functions dynamically, just + call functions directly. + 2013-11-19 Corinna Vinschen * cygcheck.cc (dump_sysinfo): Distinguish Windows 8 and 8.1, as well diff --git a/winsup/utils/Makefile.in b/winsup/utils/Makefile.in index dc72bebff..7682533a4 100644 --- a/winsup/utils/Makefile.in +++ b/winsup/utils/Makefile.in @@ -86,7 +86,7 @@ mount.exe: path-mount.o # Provide any necessary per-target variable overrides. -cygcheck.exe: MINGW_LDFLAGS += ${ZLIB} -lpsapi -lntdll +cygcheck.exe: MINGW_LDFLAGS += ${ZLIB} -lwininet -lpsapi -lntdll cygcheck.exe: ${CYGCHECK_OBJS} cygpath.o: CXXFLAGS += -fno-threadsafe-statics @@ -108,7 +108,7 @@ CYGWIN_BINS += dumper.exe dumper.o module_info.o parse_pe.o: CXXFLAGS += -I$(top_srcdir)/include dumper.o parse_pe.o: dumper.h dumper.exe: module_info.o parse_pe.o -dumper.exe: CYGWIN_LDFLAGS += -lbfd -lintl -liconv -liberty ${ZLIB} +dumper.exe: CYGWIN_LDFLAGS += -lpsapi -lbfd -lintl -liconv -liberty ${ZLIB} else all: warn_dumper endif diff --git a/winsup/utils/cygcheck.cc b/winsup/utils/cygcheck.cc index 1f72061db..209a7d181 100644 --- a/winsup/utils/cygcheck.cc +++ b/winsup/utils/cygcheck.cc @@ -9,6 +9,7 @@ Cygwin license. Please consult the file "CYGWIN_LICENSE" for details. */ +#define _WIN32_WINNT 0x0602 #define cygwin_internal cygwin_internal_dontuse #include #include @@ -53,10 +54,6 @@ int unique_object_name_opt = 0; static char emptystr[] = ""; -/* This is global because it's used in both internet_display_error as well - as package_grep. */ -BOOL (WINAPI *pInternetCloseHandle) (HINTERNET); - #ifdef __GNUC__ typedef long long longlong; #else @@ -230,7 +227,7 @@ display_internet_error (const char *message, ...) va_start (hptr, message); while ((h = va_arg (hptr, HINTERNET)) != 0) - pInternetCloseHandle (h); + InternetCloseHandle (h); va_end (hptr); return 1; @@ -1498,10 +1495,6 @@ dump_sysinfo () osversion.wServicePackMinor, &prod)) { -#define PRODUCT_UNLICENSED 0xabcdabcd -#ifndef PRODUCT_PROFESSIONAL_WMC -#define PRODUCT_PROFESSIONAL_WMC 0x00000067 -#endif const char *products[] = { /* 0x00000000 */ "", @@ -2114,43 +2107,6 @@ package_grep (char *search) { char buf[1024]; - /* Attempt to dynamically load the necessary WinInet API functions so that - cygcheck can still function on older systems without IE. */ - HMODULE hWinInet; - if (!(hWinInet = LoadLibrary ("wininet.dll"))) - { - fputs ("Unable to locate WININET.DLL. This feature requires Microsoft " - "Internet Explorer v3 or later to function.\n", stderr); - return 1; - } - - /* InternetCloseHandle is used outside this function so it is declared - global. The rest of these functions are only used here, so declare them - and call GetProcAddress for each of them with the following macro. */ - - pInternetCloseHandle = (BOOL (WINAPI *) (HINTERNET)) - GetProcAddress (hWinInet, "InternetCloseHandle"); -#define make_func_pointer(name, ret, args) ret (WINAPI * p##name) args = \ - (ret (WINAPI *) args) GetProcAddress (hWinInet, #name); - make_func_pointer (InternetAttemptConnect, DWORD, (DWORD)); - make_func_pointer (InternetOpenA, HINTERNET, (LPCSTR, DWORD, LPCSTR, LPCSTR, - DWORD)); - make_func_pointer (InternetOpenUrlA, HINTERNET, (HINTERNET, LPCSTR, LPCSTR, - DWORD, DWORD, DWORD)); - make_func_pointer (InternetReadFile, BOOL, (HINTERNET, PVOID, DWORD, PDWORD)); - make_func_pointer (HttpQueryInfoA, BOOL, (HINTERNET, DWORD, PVOID, PDWORD, - PDWORD)); -#undef make_func_pointer - - if(!pInternetCloseHandle || !pInternetAttemptConnect || !pInternetOpenA - || !pInternetOpenUrlA || !pInternetReadFile || !pHttpQueryInfoA) - { - fputs ("Unable to load one or more functions from WININET.DLL. This " - "feature requires Microsoft Internet Explorer v3 or later to " - "function.\n", stderr); - return 1; - } - /* construct the actual URL by escaping */ char *url = (char *) alloca (sizeof (base_url) + strlen ("&arch=x86_64") + strlen (search) * 3); strcpy (url, base_url); @@ -2177,7 +2133,7 @@ package_grep (char *search) #endif /* Connect to the net and open the URL. */ - if (pInternetAttemptConnect (0) != ERROR_SUCCESS) + if (InternetAttemptConnect (0) != ERROR_SUCCESS) { fputs ("An internet connection is required for this function.\n", stderr); return 1; @@ -2185,16 +2141,16 @@ package_grep (char *search) /* Initialize WinInet and attempt to fetch our URL. */ HINTERNET hi = NULL, hurl = NULL; - if (!(hi = pInternetOpenA ("cygcheck", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))) + if (!(hi = InternetOpenA ("cygcheck", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))) return display_internet_error ("InternetOpen() failed", NULL); - if (!(hurl = pInternetOpenUrlA (hi, url, NULL, 0, 0, 0))) + if (!(hurl = InternetOpenUrlA (hi, url, NULL, 0, 0, 0))) return display_internet_error ("unable to contact cygwin.com site, " "InternetOpenUrl() failed", hi, NULL); /* Check the HTTP response code. */ DWORD rc = 0, rc_s = sizeof (DWORD); - if (!pHttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, + if (!HttpQueryInfoA (hurl, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, (void *) &rc, &rc_s, NULL)) return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL); @@ -2209,15 +2165,15 @@ package_grep (char *search) DWORD numread; do { - if (!pInternetReadFile (hurl, (void *) buf, sizeof (buf), &numread)) + if (!InternetReadFile (hurl, (void *) buf, sizeof (buf), &numread)) return display_internet_error ("InternetReadFile failed", hurl, hi, NULL); if (numread) fwrite ((void *) buf, (size_t) numread, 1, stdout); } while (numread); - pInternetCloseHandle (hurl); - pInternetCloseHandle (hi); + InternetCloseHandle (hurl); + InternetCloseHandle (hi); return 0; } diff --git a/winsup/utils/module_info.cc b/winsup/utils/module_info.cc index 12e74de39..1437da421 100644 --- a/winsup/utils/module_info.cc +++ b/winsup/utils/module_info.cc @@ -15,20 +15,6 @@ details. */ #include #include "loadlib.h" -static int psapi_loaded = 0; -static HMODULE psapi_module_handle = NULL; - -typedef BOOL WINAPI (tf_EnumProcessModules) (HANDLE, HMODULE *, DWORD, - LPDWORD); -typedef BOOL WINAPI (tf_GetModuleInformation) (HANDLE, HMODULE, LPMODULEINFO, - DWORD); -typedef DWORD WINAPI (tf_GetModuleFileNameExA) (HANDLE, HMODULE, LPSTR, - DWORD); - -static tf_EnumProcessModules *psapi_EnumProcessModules = NULL; -static tf_GetModuleInformation *psapi_GetModuleInformation = NULL; -static tf_GetModuleFileNameExA *psapi_GetModuleFileNameExA = NULL; - /* Returns full name of Dll, which is loaded by hProcess at BaseAddress. Uses psapi.dll. */ @@ -45,41 +31,14 @@ psapi_get_module_name (HANDLE hProcess, LPVOID BaseAddress) char name_buf[MAX_PATH + 1]; - if (!psapi_loaded || - psapi_EnumProcessModules == NULL || - psapi_GetModuleInformation == NULL || - psapi_GetModuleFileNameExA == NULL) - { - if (psapi_loaded) - goto failed; - psapi_loaded = 1; - psapi_module_handle = LoadLibrary ("psapi.dll"); - if (!psapi_module_handle) - goto failed; - psapi_EnumProcessModules = - (tf_EnumProcessModules *) GetProcAddress (psapi_module_handle, - "EnumProcessModules"); - psapi_GetModuleInformation = - (tf_GetModuleInformation *) GetProcAddress (psapi_module_handle, - "GetModuleInformation"); - psapi_GetModuleFileNameExA = - (tf_GetModuleFileNameExA *) GetProcAddress (psapi_module_handle, - "GetModuleFileNameExA"); - if (psapi_EnumProcessModules == NULL - || psapi_GetModuleInformation == NULL - || psapi_GetModuleFileNameExA == NULL) - goto failed; - } - - ok = (*psapi_EnumProcessModules) (hProcess, - DllHandle, sizeof (HMODULE), &cbNeeded); + ok = EnumProcessModules (hProcess, DllHandle, sizeof (HMODULE), &cbNeeded); if (!ok || !cbNeeded) goto failed; DllHandle = (HMODULE *) malloc (cbNeeded); if (!DllHandle) goto failed; - ok = (*psapi_EnumProcessModules) (hProcess, DllHandle, cbNeeded, &cbNeeded); + ok = EnumProcessModules (hProcess, DllHandle, cbNeeded, &cbNeeded); if (!ok) { free (DllHandle); @@ -88,15 +47,13 @@ psapi_get_module_name (HANDLE hProcess, LPVOID BaseAddress) for (i = 0; i < cbNeeded / sizeof (HMODULE); i++) { - if (!(*psapi_GetModuleInformation) (hProcess, - DllHandle[i], &mi, sizeof (mi))) + if (!GetModuleInformation (hProcess, DllHandle[i], &mi, sizeof (mi))) { free (DllHandle); goto failed; } - len = (*psapi_GetModuleFileNameExA) (hProcess, - DllHandle[i], name_buf, MAX_PATH); + len = GetModuleFileNameExA (hProcess, DllHandle[i], name_buf, MAX_PATH); if (len == 0) { free (DllHandle); -- cgit v1.2.3