* Makefile.in (cygcheck.exe): Link against psapi.dll.

* bloda.cc: Change include section to work with Mingw64 headers.
	Include psapi.h.  Use SystemProcessInformation instead of
	SystemProcessesAndThreadsInformation throughout and add define for
	w32api headers.  Ditto for PSYSTEM_PROCESS_INFORMATION vs.
	PSYSTEM_PROCESSES.
	(system_module_list): New type to replace SYSTEM_MODULE_INFORMATION.
	Change usage throughout accordingly.
	(get_module_list): Fetch module list using PSAPI functions
	EnumDeviceDrivers and GetDeviceDriverBaseNameA.
	* cygcheck.cc (max): Define as __max if not defined already.
	(alloca): Only define if not defined already.
	(handle_unique_object_name): Use explicit sharing flags rather than
	FILE_SHARE_VALID_FLAGS which officially is only available in DDK
	headers.
	(PRODUCT_ULTIMATE_E): Only define if not defined already.
	* dump_setup.cc: Change include section to work with Mingw64 headers.
	(NtQueryAttributesFile): Drop NTOSAPI aka DECLSPEC_IMPORT.
	* strace.cc: Change include section to work with Mingw64 headers.
	(alloca): Only define if not defined already.
This commit is contained in:
Corinna Vinschen 2012-07-11 16:41:51 +00:00
parent 4a4f6f949c
commit 6e1e3bb8e5
6 changed files with 113 additions and 43 deletions

View File

@ -1,3 +1,26 @@
2012-07-11 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (cygcheck.exe): Link against psapi.dll.
* bloda.cc: Change include section to work with Mingw64 headers.
Include psapi.h. Use SystemProcessInformation instead of
SystemProcessesAndThreadsInformation throughout and add define for
w32api headers. Ditto for PSYSTEM_PROCESS_INFORMATION vs.
PSYSTEM_PROCESSES.
(system_module_list): New type to replace SYSTEM_MODULE_INFORMATION.
Change usage throughout accordingly.
(get_module_list): Fetch module list using PSAPI functions
EnumDeviceDrivers and GetDeviceDriverBaseNameA.
* cygcheck.cc (max): Define as __max if not defined already.
(alloca): Only define if not defined already.
(handle_unique_object_name): Use explicit sharing flags rather than
FILE_SHARE_VALID_FLAGS which officially is only available in DDK
headers.
(PRODUCT_ULTIMATE_E): Only define if not defined already.
* dump_setup.cc: Change include section to work with Mingw64 headers.
(NtQueryAttributesFile): Drop NTOSAPI aka DECLSPEC_IMPORT.
* strace.cc: Change include section to work with Mingw64 headers.
(alloca): Only define if not defined already.
2012-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygpath.cc: Change including headers to allow building against

View File

@ -74,7 +74,7 @@ path-mount.o: path.cc
mount.exe: path-mount.o
# Provide any necessary per-target variable overrides.
cygcheck.exe: MINGW_LDFLAGS += -lntdll
cygcheck.exe: MINGW_LDFLAGS += -lpsapi -lntdll
cygpath.exe: ALL_LDFLAGS += -lcygwin -luserenv -lntdll
cygpath.exe: CXXFLAGS += -fno-threadsafe-statics
ps.exe: ALL_LDFLAGS += -lcygwin -lpsapi -lntdll

View File

@ -11,10 +11,23 @@
#define cygwin_internal cygwin_internal_dontuse
#include <stdio.h>
#include <assert.h>
#define WIN32_NO_STATUS /* Disable status codes in winnt.h since we include
ntstatus.h for extended status codes below. */
#include <windows.h>
#include <ntdef.h>
#include <ddk/ntstatus.h>
#include <ddk/ntapi.h>
#undef WIN32_NO_STATUS
#include <psapi.h>
#ifndef __MINGW64_VERSION_MAJOR
# include <ntdef.h>
# include <ddk/ntstatus.h>
# include <ddk/ntapi.h>
# define SystemProcessInformation SystemProcessesAndThreadsInformation
# define PSYSTEM_PROCESS_INFORMATION PSYSTEM_PROCESSES
# define ImageName ProcessName
# define NextEntryOffset NextEntryDelta
#else
# include <winternl.h>
# include <ntstatus.h>
#endif
#undef cygwin_internal
#undef DEBUGGING
@ -108,68 +121,77 @@ static struct bad_app_info big_list_of_dodgy_apps[] =
static const size_t num_of_dodgy_apps = sizeof (big_list_of_dodgy_apps) / sizeof (big_list_of_dodgy_apps[0]);
static PSYSTEM_PROCESSES
struct system_module_list
{
LONG count;
PVOID *pid;
PCHAR *name;
};
static PSYSTEM_PROCESS_INFORMATION
get_process_list (void)
{
int n_procs = 0x100;
PSYSTEM_PROCESSES pslist = (PSYSTEM_PROCESSES) malloc (n_procs * sizeof *pslist);
PSYSTEM_PROCESS_INFORMATION pslist = (PSYSTEM_PROCESS_INFORMATION) malloc (n_procs * sizeof *pslist);
while (NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
while (NtQuerySystemInformation (SystemProcessInformation,
pslist, n_procs * sizeof *pslist, 0) == STATUS_INFO_LENGTH_MISMATCH)
{
n_procs *= 2;
free (pslist);
pslist = (PSYSTEM_PROCESSES) malloc (n_procs * sizeof *pslist);
pslist = (PSYSTEM_PROCESS_INFORMATION) malloc (n_procs * sizeof *pslist);
}
return pslist;
}
static PSYSTEM_MODULE_INFORMATION
static system_module_list *
get_module_list (void)
{
int modsize = 0x1000;
PSYSTEM_MODULE_INFORMATION modlist = (PSYSTEM_MODULE_INFORMATION) malloc (modsize);
while (NtQuerySystemInformation (SystemModuleInformation,
modlist, modsize, NULL) == STATUS_INFO_LENGTH_MISMATCH)
DWORD modsize = 0;
system_module_list *modlist = (system_module_list *)
calloc (1, sizeof (system_module_list));
while (!EnumDeviceDrivers (modlist->pid, modsize, &modsize))
{
modsize *= 2;
free (modlist);
modlist = (PSYSTEM_MODULE_INFORMATION) malloc (modsize);
free (modlist->pid);
free (modlist->name);
modlist->count = modsize / sizeof (PVOID);
modlist->pid = (PVOID *) calloc (modlist->count, sizeof (PVOID));
modlist->name = (PCHAR *) calloc (modlist->count, sizeof (PCHAR));
}
for (int i = 0; i < modlist->count; ++i)
{
modlist->name[0] = (PCHAR) calloc (256, sizeof (CHAR));
GetDeviceDriverBaseNameA (modlist->pid[i], modlist->name[i], 256);
}
return modlist;
}
static bool
find_process_in_list (PSYSTEM_PROCESSES pslist, PUNICODE_STRING psname)
find_process_in_list (PSYSTEM_PROCESS_INFORMATION pslist, PUNICODE_STRING psname)
{
while (1)
{
if (pslist->ProcessName.Length && pslist->ProcessName.Buffer)
if (pslist->ImageName.Length && pslist->ImageName.Buffer)
{
dbg_printf (("%S\n", pslist->ProcessName.Buffer));
if (!_wcsicmp (pslist->ProcessName.Buffer, psname->Buffer))
dbg_printf (("%S\n", pslist->ImageName.Buffer));
if (!_wcsicmp (pslist->ImageName.Buffer, psname->Buffer))
return true;
}
if (!pslist->NextEntryDelta)
if (!pslist->NextEntryOffset)
break;
pslist = (PSYSTEM_PROCESSES)(pslist->NextEntryDelta + (char *)pslist);
pslist = (PSYSTEM_PROCESS_INFORMATION)(pslist->NextEntryOffset + (char *)pslist);
};
return false;
}
static bool
find_module_in_list (PSYSTEM_MODULE_INFORMATION modlist, const char * const modname)
find_module_in_list (system_module_list * modlist, const char * const modname)
{
PSYSTEM_MODULE_INFORMATION_ENTRY modptr = &modlist->Module[0];
DWORD count = modlist->Count;
while (count--)
for (int i = 0; i < modlist->count; ++i)
{
dbg_printf (("name '%s' offset %d ", &modptr->ImageName[0], modptr->PathLength));
dbg_printf (("= '%s'\n", &modptr->ImageName[modptr->PathLength]));
if (!_stricmp (&modptr->ImageName[modptr->PathLength], modname))
dbg_printf (("name '%s' ", modlist->name[i]));
if (!_stricmp (modlist->name[i], modname))
return true;
modptr++;
}
return false;
}
@ -233,7 +255,7 @@ expand_path (const char *path, char *outbuf)
}
static bool
detect_dodgy_app (const struct bad_app_det *det, PSYSTEM_PROCESSES pslist, PSYSTEM_MODULE_INFORMATION modlist)
detect_dodgy_app (const struct bad_app_det *det, PSYSTEM_PROCESS_INFORMATION pslist, system_module_list * modlist)
{
HANDLE fh;
HKEY hk;
@ -334,8 +356,8 @@ void
dump_dodgy_apps (int verbose)
{
size_t i, n_det = 0;
PSYSTEM_PROCESSES pslist;
PSYSTEM_MODULE_INFORMATION modlist;
PSYSTEM_PROCESS_INFORMATION pslist;
system_module_list * modlist;
/* Read system info for detect testing. */
pslist = get_process_list ();
@ -404,6 +426,9 @@ dump_dodgy_apps (int verbose)
}
/* Tidy up allocations. */
free (pslist);
free (modlist);
for (int i = 0; i < modlist->count; ++i)
free (modlist->name[i]);
free (modlist->name);
free (modlist->pid);
}

View File

@ -30,7 +30,13 @@
#undef cygwin_internal
#include "loadlib.h"
#ifndef max
#define max __max
#endif
#ifndef alloca
#define alloca __builtin_alloca
#endif
int verbose = 0;
int registry = 0;
@ -1314,7 +1320,7 @@ handle_unique_object_name (int opt, char *path)
if (opt == CO_SHOW_UON)
{
access = GENERIC_READ;
share = FILE_SHARE_VALID_FLAGS;
share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
protect = PAGE_READONLY;
mapping = FILE_MAP_READ;
}
@ -1447,7 +1453,9 @@ dump_sysinfo ()
&prod))
{
#define PRODUCT_UNLICENSED 0xabcdabcd
#ifndef PRODUCT_ULTIMATE_E
#define PRODUCT_ULTIMATE_E 0x00000047
#endif
const char *products[] =
{
/* 0x00000000 */ "",

View File

@ -8,7 +8,6 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@ -17,9 +16,18 @@ details. */
#include <io.h>
#include <sys/stat.h>
#include <errno.h>
#define WIN32_NO_STATUS /* Disable status codes in winnt.h since we include
ntstatus.h for extended status codes below. */
#include <windows.h>
#undef WIN32_NO_STATUS
#ifndef __MINGW64_VERSION_MAJOR
# include <ddk/ntapi.h>
# include <ddk/winddk.h>
#else
# include <winternl.h>
# include <ntstatus.h>
#endif
#include "path.h"
#include <ddk/ntapi.h>
#include <ddk/winddk.h>
#if 0
#include "zlib.h"
#endif
@ -265,8 +273,8 @@ transform_chars (PWCHAR path, PWCHAR path_end)
*path = tfx_chars[*path];
}
extern "C" NTOSAPI NTAPI NTSTATUS NtQueryAttributesFile(
POBJECT_ATTRIBUTES, PFILE_BASIC_INFORMATION);
extern "C" NTAPI NTSTATUS NtQueryAttributesFile (POBJECT_ATTRIBUTES,
PFILE_BASIC_INFORMATION);
/* This function checks for file existance and fills the stat structure
with only the required mode info. We're using a native NT function

View File

@ -11,6 +11,12 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include <windows.h>
#ifndef __MINGW64_VERSION_MAJOR
#include "ddk/ntapi.h"
#else
#include <winternl.h>
#endif
#define cygwin_internal cygwin_internal_dontuse
#include <stdio.h>
#include <fcntl.h>
@ -19,7 +25,6 @@ details. */
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#include <signal.h>
#include <errno.h>
#include "cygwin/include/sys/strace.h"
@ -28,10 +33,11 @@ details. */
#include "path.h"
#undef cygwin_internal
#include "loadlib.h"
#include "ddk/ntapi.h"
/* we *know* we're being built with GCC */
#ifndef alloca
#define alloca __builtin_alloca
#endif
static const char *pgm;
static int forkdebug = 1;