* 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.
This commit is contained in:
parent
e576e42013
commit
700a3783ee
|
@ -1,3 +1,14 @@
|
||||||
|
2013-11-19 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* 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 <corinna@vinschen.de>
|
2013-11-19 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* cygcheck.cc (dump_sysinfo): Distinguish Windows 8 and 8.1, as well
|
* cygcheck.cc (dump_sysinfo): Distinguish Windows 8 and 8.1, as well
|
||||||
|
|
|
@ -86,7 +86,7 @@ mount.exe: path-mount.o
|
||||||
|
|
||||||
# Provide any necessary per-target variable overrides.
|
# 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}
|
cygcheck.exe: ${CYGCHECK_OBJS}
|
||||||
|
|
||||||
cygpath.o: CXXFLAGS += -fno-threadsafe-statics
|
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 module_info.o parse_pe.o: CXXFLAGS += -I$(top_srcdir)/include
|
||||||
dumper.o parse_pe.o: dumper.h
|
dumper.o parse_pe.o: dumper.h
|
||||||
dumper.exe: module_info.o parse_pe.o
|
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
|
else
|
||||||
all: warn_dumper
|
all: warn_dumper
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
||||||
details. */
|
details. */
|
||||||
|
|
||||||
|
#define _WIN32_WINNT 0x0602
|
||||||
#define cygwin_internal cygwin_internal_dontuse
|
#define cygwin_internal cygwin_internal_dontuse
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -53,10 +54,6 @@ int unique_object_name_opt = 0;
|
||||||
|
|
||||||
static char emptystr[] = "";
|
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__
|
#ifdef __GNUC__
|
||||||
typedef long long longlong;
|
typedef long long longlong;
|
||||||
#else
|
#else
|
||||||
|
@ -230,7 +227,7 @@ display_internet_error (const char *message, ...)
|
||||||
|
|
||||||
va_start (hptr, message);
|
va_start (hptr, message);
|
||||||
while ((h = va_arg (hptr, HINTERNET)) != 0)
|
while ((h = va_arg (hptr, HINTERNET)) != 0)
|
||||||
pInternetCloseHandle (h);
|
InternetCloseHandle (h);
|
||||||
va_end (hptr);
|
va_end (hptr);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -1498,10 +1495,6 @@ dump_sysinfo ()
|
||||||
osversion.wServicePackMinor,
|
osversion.wServicePackMinor,
|
||||||
&prod))
|
&prod))
|
||||||
{
|
{
|
||||||
#define PRODUCT_UNLICENSED 0xabcdabcd
|
|
||||||
#ifndef PRODUCT_PROFESSIONAL_WMC
|
|
||||||
#define PRODUCT_PROFESSIONAL_WMC 0x00000067
|
|
||||||
#endif
|
|
||||||
const char *products[] =
|
const char *products[] =
|
||||||
{
|
{
|
||||||
/* 0x00000000 */ "",
|
/* 0x00000000 */ "",
|
||||||
|
@ -2114,43 +2107,6 @@ package_grep (char *search)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
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 */
|
/* construct the actual URL by escaping */
|
||||||
char *url = (char *) alloca (sizeof (base_url) + strlen ("&arch=x86_64") + strlen (search) * 3);
|
char *url = (char *) alloca (sizeof (base_url) + strlen ("&arch=x86_64") + strlen (search) * 3);
|
||||||
strcpy (url, base_url);
|
strcpy (url, base_url);
|
||||||
|
@ -2177,7 +2133,7 @@ package_grep (char *search)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Connect to the net and open the URL. */
|
/* 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);
|
fputs ("An internet connection is required for this function.\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -2185,16 +2141,16 @@ package_grep (char *search)
|
||||||
|
|
||||||
/* Initialize WinInet and attempt to fetch our URL. */
|
/* Initialize WinInet and attempt to fetch our URL. */
|
||||||
HINTERNET hi = NULL, hurl = NULL;
|
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);
|
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, "
|
return display_internet_error ("unable to contact cygwin.com site, "
|
||||||
"InternetOpenUrl() failed", hi, NULL);
|
"InternetOpenUrl() failed", hi, NULL);
|
||||||
|
|
||||||
/* Check the HTTP response code. */
|
/* Check the HTTP response code. */
|
||||||
DWORD rc = 0, rc_s = sizeof (DWORD);
|
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))
|
(void *) &rc, &rc_s, NULL))
|
||||||
return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL);
|
return display_internet_error ("HttpQueryInfo() failed", hurl, hi, NULL);
|
||||||
|
|
||||||
|
@ -2209,15 +2165,15 @@ package_grep (char *search)
|
||||||
DWORD numread;
|
DWORD numread;
|
||||||
do
|
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);
|
return display_internet_error ("InternetReadFile failed", hurl, hi, NULL);
|
||||||
if (numread)
|
if (numread)
|
||||||
fwrite ((void *) buf, (size_t) numread, 1, stdout);
|
fwrite ((void *) buf, (size_t) numread, 1, stdout);
|
||||||
}
|
}
|
||||||
while (numread);
|
while (numread);
|
||||||
|
|
||||||
pInternetCloseHandle (hurl);
|
InternetCloseHandle (hurl);
|
||||||
pInternetCloseHandle (hi);
|
InternetCloseHandle (hi);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,20 +15,6 @@ details. */
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
#include "loadlib.h"
|
#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.
|
/* Returns full name of Dll, which is loaded by hProcess at BaseAddress.
|
||||||
Uses psapi.dll. */
|
Uses psapi.dll. */
|
||||||
|
|
||||||
|
@ -45,41 +31,14 @@ psapi_get_module_name (HANDLE hProcess, LPVOID BaseAddress)
|
||||||
|
|
||||||
char name_buf[MAX_PATH + 1];
|
char name_buf[MAX_PATH + 1];
|
||||||
|
|
||||||
if (!psapi_loaded ||
|
ok = EnumProcessModules (hProcess, DllHandle, sizeof (HMODULE), &cbNeeded);
|
||||||
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);
|
|
||||||
|
|
||||||
if (!ok || !cbNeeded)
|
if (!ok || !cbNeeded)
|
||||||
goto failed;
|
goto failed;
|
||||||
DllHandle = (HMODULE *) malloc (cbNeeded);
|
DllHandle = (HMODULE *) malloc (cbNeeded);
|
||||||
if (!DllHandle)
|
if (!DllHandle)
|
||||||
goto failed;
|
goto failed;
|
||||||
ok = (*psapi_EnumProcessModules) (hProcess, DllHandle, cbNeeded, &cbNeeded);
|
ok = EnumProcessModules (hProcess, DllHandle, cbNeeded, &cbNeeded);
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
free (DllHandle);
|
free (DllHandle);
|
||||||
|
@ -88,15 +47,13 @@ psapi_get_module_name (HANDLE hProcess, LPVOID BaseAddress)
|
||||||
|
|
||||||
for (i = 0; i < cbNeeded / sizeof (HMODULE); i++)
|
for (i = 0; i < cbNeeded / sizeof (HMODULE); i++)
|
||||||
{
|
{
|
||||||
if (!(*psapi_GetModuleInformation) (hProcess,
|
if (!GetModuleInformation (hProcess, DllHandle[i], &mi, sizeof (mi)))
|
||||||
DllHandle[i], &mi, sizeof (mi)))
|
|
||||||
{
|
{
|
||||||
free (DllHandle);
|
free (DllHandle);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = (*psapi_GetModuleFileNameExA) (hProcess,
|
len = GetModuleFileNameExA (hProcess, DllHandle[i], name_buf, MAX_PATH);
|
||||||
DllHandle[i], name_buf, MAX_PATH);
|
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
{
|
{
|
||||||
free (DllHandle);
|
free (DllHandle);
|
||||||
|
|
Loading…
Reference in New Issue