2000-02-18 03:38:33 +08:00
|
|
|
/* cygcheck.cc
|
|
|
|
|
2003-03-01 11:38:19 +08:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-09-19 11:48:19 +08:00
|
|
|
#include <sys/time.h>
|
2002-09-18 01:13:21 +08:00
|
|
|
#include <ctype.h>
|
2003-03-01 11:38:19 +08:00
|
|
|
#include <io.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <windows.h>
|
2003-03-01 11:38:19 +08:00
|
|
|
#include "path.h"
|
2003-09-11 10:56:40 +08:00
|
|
|
#include <getopt.h>
|
2002-01-29 11:08:42 +08:00
|
|
|
#include "cygwin/include/sys/cygwin.h"
|
2002-01-29 10:28:44 +08:00
|
|
|
#include "cygwin/include/mntent.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int verbose = 0;
|
|
|
|
int registry = 0;
|
|
|
|
int sysinfo = 0;
|
|
|
|
int givehelp = 0;
|
2000-09-29 19:20:53 +08:00
|
|
|
int keycheck = 0;
|
2001-11-11 14:07:36 +08:00
|
|
|
int check_setup = 0;
|
2003-09-12 00:24:26 +08:00
|
|
|
int dump_only = 0;
|
2003-08-16 04:26:11 +08:00
|
|
|
int find_package = 0;
|
|
|
|
int list_package = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
typedef long long longlong;
|
|
|
|
#else
|
|
|
|
typedef __int64 longlong;
|
|
|
|
#endif
|
|
|
|
|
2001-11-12 08:14:27 +08:00
|
|
|
void dump_setup (int, char **, bool);
|
2003-08-16 04:26:11 +08:00
|
|
|
void package_find (int, char **);
|
|
|
|
void package_list (int, char **);
|
2001-11-11 14:07:36 +08:00
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static const char version[] = "$Revision$";
|
|
|
|
|
|
|
|
static const char *known_env_vars[] = {
|
2000-02-18 03:38:33 +08:00
|
|
|
"c_include_path",
|
|
|
|
"compiler_path",
|
|
|
|
"cxx_include_path",
|
|
|
|
"cygwin",
|
|
|
|
"cygwin32",
|
|
|
|
"dejagnu",
|
|
|
|
"expect",
|
|
|
|
"gcc_default_options",
|
|
|
|
"gcc_exec_prefix",
|
|
|
|
"home",
|
|
|
|
"ld_library_path",
|
|
|
|
"library_path",
|
|
|
|
"login",
|
|
|
|
"lpath",
|
|
|
|
"make_mode",
|
|
|
|
"makeflags",
|
|
|
|
"path",
|
|
|
|
"pwd",
|
|
|
|
"strace",
|
|
|
|
"tcl_library",
|
|
|
|
"user",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2000-10-28 13:00:00 +08:00
|
|
|
struct
|
|
|
|
{
|
2000-02-18 03:38:33 +08:00
|
|
|
const char *name;
|
|
|
|
int missing_is_good;
|
2000-10-28 13:00:00 +08:00
|
|
|
}
|
2002-03-07 11:13:17 +08:00
|
|
|
static common_apps[] = {
|
2003-02-07 12:51:26 +08:00
|
|
|
{"awk", 0},
|
2000-10-28 13:39:38 +08:00
|
|
|
{"bash", 0},
|
|
|
|
{"cat", 0},
|
2003-02-07 12:51:26 +08:00
|
|
|
{"cp", 0},
|
2000-10-28 13:39:38 +08:00
|
|
|
{"cpp", 1},
|
|
|
|
{"find", 0},
|
|
|
|
{"gcc", 0},
|
|
|
|
{"gdb", 0},
|
2003-02-07 12:51:26 +08:00
|
|
|
{"grep", 0},
|
2000-10-28 13:39:38 +08:00
|
|
|
{"ld", 0},
|
|
|
|
{"ls", 0},
|
|
|
|
{"make", 0},
|
2003-02-07 12:51:26 +08:00
|
|
|
{"mv", 0},
|
|
|
|
{"rm", 0},
|
|
|
|
{"sed", 0},
|
2000-10-28 13:39:38 +08:00
|
|
|
{"sh", 0},
|
2003-02-07 12:51:26 +08:00
|
|
|
{"tar", 0},
|
2000-10-28 13:39:38 +08:00
|
|
|
{0, 0}
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static int num_paths = 0, max_paths = 0;
|
|
|
|
static char **paths = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-12-16 12:53:30 +08:00
|
|
|
/*
|
|
|
|
* keyeprint() is used to report failure modes
|
|
|
|
*/
|
2002-02-28 00:10:17 +08:00
|
|
|
static int
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint (const char *name)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "cygcheck: %s failed: %lu\n", name, GetLastError ());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-02-18 03:38:33 +08:00
|
|
|
add_path (char *s, int maxlen)
|
|
|
|
{
|
|
|
|
if (num_paths >= max_paths)
|
|
|
|
{
|
|
|
|
max_paths += 10;
|
|
|
|
if (paths)
|
|
|
|
paths = (char **) realloc (paths, max_paths * sizeof (char *));
|
|
|
|
else
|
|
|
|
paths = (char **) malloc (max_paths * sizeof (char *));
|
|
|
|
}
|
|
|
|
paths[num_paths] = (char *) malloc (maxlen + 1);
|
2000-12-16 12:53:30 +08:00
|
|
|
if (paths[num_paths] == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("add_path: malloc()");
|
|
|
|
return;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
memcpy (paths[num_paths], s, maxlen);
|
|
|
|
paths[num_paths][maxlen] = 0;
|
|
|
|
char *e = paths[num_paths] + strlen (paths[num_paths]);
|
|
|
|
if (e[-1] == '\\' && e[-2] != ':')
|
|
|
|
*--e = 0;
|
|
|
|
for (int i = 1; i < num_paths; i++)
|
|
|
|
if (strcasecmp (paths[num_paths], paths[i]) == 0)
|
|
|
|
return;
|
|
|
|
num_paths++;
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-02-18 03:38:33 +08:00
|
|
|
init_paths ()
|
|
|
|
{
|
|
|
|
char tmp[4000], *sl;
|
2000-10-28 13:00:00 +08:00
|
|
|
add_path ((char *) ".", 1); /* to be replaced later */
|
|
|
|
add_path ((char *) ".", 1); /* the current directory */
|
2000-12-16 12:53:30 +08:00
|
|
|
if (GetSystemDirectory (tmp, 4000))
|
|
|
|
add_path (tmp, strlen (tmp));
|
|
|
|
else
|
|
|
|
keyeprint ("init_paths: GetSystemDirectory()");
|
2000-02-18 03:38:33 +08:00
|
|
|
sl = strrchr (tmp, '\\');
|
|
|
|
if (sl)
|
|
|
|
{
|
|
|
|
strcpy (sl, "\\SYSTEM");
|
|
|
|
add_path (tmp, strlen (tmp));
|
|
|
|
}
|
|
|
|
GetWindowsDirectory (tmp, 4000);
|
|
|
|
add_path (tmp, strlen (tmp));
|
|
|
|
|
2001-11-11 11:06:59 +08:00
|
|
|
char *wpath = getenv ("PATH");
|
|
|
|
if (wpath)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-11-11 11:06:59 +08:00
|
|
|
char *b, *e;
|
2000-02-18 03:38:33 +08:00
|
|
|
b = wpath;
|
|
|
|
while (1)
|
|
|
|
{
|
2001-11-11 11:06:59 +08:00
|
|
|
for (e = b; *e && *e != ';'; e++);
|
2000-02-18 03:38:33 +08:00
|
|
|
add_path (b, e - b);
|
|
|
|
if (!*e)
|
|
|
|
break;
|
|
|
|
b = e + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf ("WARNING: PATH is not set at all!\n");
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static char *
|
2000-02-18 03:38:33 +08:00
|
|
|
find_on_path (char *file, char *default_extension,
|
|
|
|
int showall = 0, int search_sysdirs = 0)
|
|
|
|
{
|
|
|
|
static char rv[4000];
|
|
|
|
char tmp[4000], *ptr = rv;
|
|
|
|
|
2003-03-01 11:38:19 +08:00
|
|
|
if (!file)
|
2000-12-16 12:53:30 +08:00
|
|
|
{
|
|
|
|
keyeprint ("find_on_path: NULL pointer for file");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (default_extension == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("find_on_path: NULL pointer for default_extension");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (strchr (file, ':') || strchr (file, '\\') || strchr (file, '/'))
|
2003-03-01 11:38:19 +08:00
|
|
|
return cygpath (file, NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (strchr (file, '.'))
|
2000-10-28 13:00:00 +08:00
|
|
|
default_extension = (char *) "";
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < num_paths; i++)
|
|
|
|
{
|
|
|
|
if (!search_sysdirs && (i == 0 || i == 2 || i == 3))
|
|
|
|
continue;
|
|
|
|
if (i == 0 || !search_sysdirs || strcasecmp (paths[i], paths[0]))
|
|
|
|
{
|
|
|
|
sprintf (ptr, "%s\\%s%s", paths[i], file, default_extension);
|
2000-12-16 12:53:30 +08:00
|
|
|
if (GetFileAttributes (ptr) != (DWORD) - 1)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (showall)
|
|
|
|
printf ("Found: %s\n", ptr);
|
|
|
|
if (ptr == tmp && verbose)
|
|
|
|
printf ("Warning: %s hides %s\n", rv, ptr);
|
|
|
|
ptr = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr == tmp)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DID_NEW 1
|
|
|
|
#define DID_ACTIVE 2
|
|
|
|
#define DID_INACTIVE 3
|
|
|
|
|
|
|
|
struct Did
|
|
|
|
{
|
|
|
|
Did *next;
|
|
|
|
char *file;
|
|
|
|
int state;
|
|
|
|
};
|
2002-02-28 00:10:17 +08:00
|
|
|
static Did *did = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static Did *
|
2000-02-18 03:38:33 +08:00
|
|
|
already_did (char *file)
|
|
|
|
{
|
|
|
|
Did *d;
|
|
|
|
for (d = did; d; d = d->next)
|
|
|
|
if (strcasecmp (d->file, file) == 0)
|
|
|
|
return d;
|
2002-01-18 10:57:10 +08:00
|
|
|
d = (Did *) malloc (sizeof (Did));
|
2000-02-18 03:38:33 +08:00
|
|
|
d->file = strdup (file);
|
|
|
|
d->next = did;
|
|
|
|
d->state = DID_NEW;
|
|
|
|
did = d;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static int
|
2000-02-18 03:38:33 +08:00
|
|
|
get_word (HANDLE fh, int offset)
|
|
|
|
{
|
|
|
|
short rv;
|
|
|
|
unsigned r;
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
if (SetFilePointer (fh, offset, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER
|
|
|
|
&& GetLastError () != NO_ERROR)
|
|
|
|
keyeprint ("get_word: SetFilePointer()");
|
|
|
|
|
2002-03-07 11:13:17 +08:00
|
|
|
if (!ReadFile (fh, &rv, 2, (DWORD *) &r, 0))
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint ("get_word: Readfile()");
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static int
|
2000-02-18 03:38:33 +08:00
|
|
|
get_dword (HANDLE fh, int offset)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
unsigned r;
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
if (SetFilePointer (fh, offset, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER
|
|
|
|
&& GetLastError () != NO_ERROR)
|
|
|
|
keyeprint ("get_word: SetFilePointer()");
|
|
|
|
|
2002-03-07 11:13:17 +08:00
|
|
|
if (!ReadFile (fh, &rv, 4, (DWORD *) &r, 0))
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint ("get_dword: Readfile()");
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Section
|
|
|
|
{
|
|
|
|
char name[8];
|
|
|
|
int virtual_size;
|
|
|
|
int virtual_address;
|
|
|
|
int size_of_raw_data;
|
|
|
|
int pointer_to_raw_data;
|
|
|
|
};
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static int
|
2000-02-18 03:38:33 +08:00
|
|
|
rva_to_offset (int rva, char *sections, int nsections, int *sz)
|
|
|
|
{
|
|
|
|
int i;
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
if (sections == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("rva_to_offset: NULL passed for sections");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
for (i = 0; i < nsections; i++)
|
|
|
|
{
|
|
|
|
Section *s = (Section *) (sections + i * 40);
|
|
|
|
#if 0
|
|
|
|
printf ("%08x < %08x < %08x ? %08x\n",
|
|
|
|
s->virtual_address, rva,
|
|
|
|
s->virtual_address + s->virtual_size, s->pointer_to_raw_data);
|
|
|
|
#endif
|
|
|
|
if (rva >= s->virtual_address
|
|
|
|
&& rva < s->virtual_address + s->virtual_size)
|
|
|
|
{
|
|
|
|
if (sz)
|
|
|
|
*sz = s->virtual_address + s->virtual_size - rva;
|
|
|
|
return rva - s->virtual_address + s->pointer_to_raw_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0; /* punt */
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ExpDirectory
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
int timestamp;
|
|
|
|
short major_ver;
|
|
|
|
short minor_ver;
|
|
|
|
int name_rva;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ImpDirectory
|
2000-10-28 13:00:00 +08:00
|
|
|
{
|
|
|
|
unsigned characteristics;
|
|
|
|
unsigned timestamp;
|
|
|
|
unsigned forwarder_chain;
|
|
|
|
unsigned name_rva;
|
|
|
|
unsigned iat_rva;
|
|
|
|
};
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void track_down (char *file, char *suffix, int lvl);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-06-25 11:18:54 +08:00
|
|
|
#define CYGPREFIX (sizeof ("%%% Cygwin ") - 1)
|
|
|
|
static void
|
|
|
|
cygwin_info (HANDLE h)
|
|
|
|
{
|
2000-12-16 12:53:30 +08:00
|
|
|
char *buf, *bufend, *buf_start = NULL;
|
2000-06-25 11:18:54 +08:00
|
|
|
const char *hello = " Cygwin DLL version info:\n";
|
|
|
|
DWORD size = GetFileSize (h, NULL);
|
|
|
|
DWORD n;
|
|
|
|
|
|
|
|
if (size == 0xffffffff)
|
|
|
|
return;
|
|
|
|
|
2000-12-16 12:53:30 +08:00
|
|
|
buf_start = buf = (char *) calloc (1, size + 1);
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("cygwin_info: malloc()");
|
|
|
|
return;
|
|
|
|
}
|
2000-06-25 11:18:54 +08:00
|
|
|
|
|
|
|
(void) SetFilePointer (h, 0, NULL, FILE_BEGIN);
|
|
|
|
if (!ReadFile (h, buf, size, &n, NULL))
|
2000-12-16 12:53:30 +08:00
|
|
|
{
|
|
|
|
free (buf_start);
|
|
|
|
return;
|
|
|
|
}
|
2000-06-25 11:18:54 +08:00
|
|
|
|
2002-01-22 11:17:59 +08:00
|
|
|
static char dummy[] = "\0\0\0\0\0\0\0";
|
|
|
|
char *dll_major = dummy;
|
2000-06-25 11:18:54 +08:00
|
|
|
bufend = buf + size;
|
|
|
|
while (buf < bufend)
|
|
|
|
if ((buf = (char *) memchr (buf, '%', bufend - buf)) == NULL)
|
2000-10-28 13:00:00 +08:00
|
|
|
break;
|
2000-06-25 11:18:54 +08:00
|
|
|
else if (strncmp ("%%% Cygwin ", buf, CYGPREFIX) != 0)
|
2000-10-28 13:00:00 +08:00
|
|
|
buf++;
|
2000-06-25 11:18:54 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
char *p = strchr (buf += CYGPREFIX, '\n');
|
2000-12-16 12:53:30 +08:00
|
|
|
if (!p)
|
|
|
|
break;
|
2001-11-11 11:06:59 +08:00
|
|
|
if (strncasecmp (buf, "dll major:", 10) == 0)
|
|
|
|
{
|
|
|
|
dll_major = buf + 11;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
char *s, pbuf[80];
|
|
|
|
int len;
|
|
|
|
len = 1 + p - buf;
|
|
|
|
if (strncasecmp (buf, "dll minor:", 10) != 0)
|
|
|
|
s = buf;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char c = dll_major[1];
|
|
|
|
dll_major[1] = '\0';
|
|
|
|
int maj = atoi (dll_major);
|
|
|
|
dll_major[1] = c;
|
|
|
|
int min = atoi (dll_major + 1);
|
2002-03-07 11:13:17 +08:00
|
|
|
sprintf (pbuf, "DLL version: %d.%d.%.*s", maj, min, len - 11,
|
|
|
|
buf + 11);
|
2001-11-11 11:06:59 +08:00
|
|
|
len = strlen (s = pbuf);
|
|
|
|
}
|
|
|
|
if (strncmp (s, "dll", 3) == 0)
|
|
|
|
memcpy (s, "DLL", 3);
|
|
|
|
else if (strncmp (s, "api", 3) == 0)
|
|
|
|
memcpy (s, "API", 3);
|
|
|
|
else if (islower (*s))
|
|
|
|
*s = toupper (*s);
|
|
|
|
fprintf (stdout, "%s %.*s", hello, len, s);
|
2000-06-25 11:18:54 +08:00
|
|
|
hello = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!*hello)
|
|
|
|
puts ("");
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
free (buf_start);
|
2000-06-25 11:18:54 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-06-25 11:18:54 +08:00
|
|
|
dll_info (const char *path, HANDLE fh, int lvl, int recurse)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
DWORD junk;
|
|
|
|
int i;
|
|
|
|
int pe_header_offset = get_dword (fh, 0x3c);
|
|
|
|
int opthdr_ofs = pe_header_offset + 4 + 20;
|
|
|
|
unsigned short v[6];
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("dll_info: NULL passed for path");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-07 11:13:17 +08:00
|
|
|
if (SetFilePointer (fh, opthdr_ofs + 40, 0, FILE_BEGIN) ==
|
|
|
|
INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR)
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint ("dll_info: SetFilePointer()");
|
|
|
|
|
|
|
|
if (!ReadFile (fh, &v, sizeof (v), &junk, 0))
|
|
|
|
keyeprint ("dll_info: Readfile()");
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (verbose)
|
|
|
|
printf (" - os=%d.%d img=%d.%d sys=%d.%d\n",
|
|
|
|
v[0], v[1], v[2], v[3], v[4], v[5]);
|
|
|
|
else
|
|
|
|
printf ("\n");
|
2000-12-16 12:53:30 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int num_entries = get_dword (fh, opthdr_ofs + 92);
|
|
|
|
int export_rva = get_dword (fh, opthdr_ofs + 96);
|
|
|
|
int export_size = get_dword (fh, opthdr_ofs + 100);
|
|
|
|
int import_rva = get_dword (fh, opthdr_ofs + 104);
|
|
|
|
int import_size = get_dword (fh, opthdr_ofs + 108);
|
|
|
|
|
|
|
|
int nsections = get_word (fh, pe_header_offset + 4 + 2);
|
|
|
|
char *sections = (char *) malloc (nsections * 40);
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
if (SetFilePointer (fh, pe_header_offset + 4 + 20 +
|
|
|
|
get_word (fh, pe_header_offset + 4 + 16), 0,
|
|
|
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER
|
|
|
|
&& GetLastError () != NO_ERROR)
|
|
|
|
keyeprint ("dll_info: SetFilePointer()");
|
|
|
|
|
|
|
|
if (!ReadFile (fh, sections, nsections * 40, &junk, 0))
|
|
|
|
keyeprint ("dll_info: Readfile()");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (verbose && num_entries >= 1 && export_size > 0)
|
|
|
|
{
|
|
|
|
int expsz;
|
|
|
|
int expbase = rva_to_offset (export_rva, sections, nsections, &expsz);
|
2000-12-16 12:53:30 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (expbase)
|
|
|
|
{
|
2002-03-07 11:13:17 +08:00
|
|
|
if (SetFilePointer (fh, expbase, 0, FILE_BEGIN) ==
|
|
|
|
INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR)
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint ("dll_info: SetFilePointer()");
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
unsigned char *exp = (unsigned char *) malloc (expsz);
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
if (!ReadFile (fh, exp, expsz, &junk, 0))
|
|
|
|
keyeprint ("dll_info: Readfile()");
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
ExpDirectory *ed = (ExpDirectory *) exp;
|
|
|
|
int ofs = ed->name_rva - export_rva;
|
|
|
|
struct tm *tm = localtime ((const time_t *) &(ed->timestamp));
|
|
|
|
if (tm->tm_year < 60)
|
|
|
|
tm->tm_year += 2000;
|
|
|
|
if (tm->tm_year < 200)
|
|
|
|
tm->tm_year += 1900;
|
|
|
|
printf ("%*c", lvl + 2, ' ');
|
|
|
|
printf ("\"%s\" v%d.%d ts=", exp + ofs,
|
|
|
|
ed->major_ver, ed->minor_ver);
|
|
|
|
printf ("%d/%d/%d %d:%02d\n",
|
|
|
|
tm->tm_year, tm->tm_mon + 1, tm->tm_mday,
|
|
|
|
tm->tm_hour, tm->tm_min);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_entries >= 2 && import_size > 0 && recurse)
|
|
|
|
{
|
|
|
|
int impsz;
|
|
|
|
int impbase = rva_to_offset (import_rva, sections, nsections, &impsz);
|
|
|
|
if (impbase)
|
|
|
|
{
|
2002-03-07 11:13:17 +08:00
|
|
|
if (SetFilePointer (fh, impbase, 0, FILE_BEGIN) ==
|
|
|
|
INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR)
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint ("dll_info: SetFilePointer()");
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
unsigned char *imp = (unsigned char *) malloc (impsz);
|
2000-12-16 12:53:30 +08:00
|
|
|
if (imp == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("dll_info: malloc()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ReadFile (fh, imp, impsz, &junk, 0))
|
|
|
|
keyeprint ("dll_info: Readfile()");
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
ImpDirectory *id = (ImpDirectory *) imp;
|
|
|
|
for (i = 0; id[i].name_rva; i++)
|
|
|
|
{
|
|
|
|
/* int ofs = id[i].name_rva - import_rva; */
|
|
|
|
track_down ((char *) imp + id[i].name_rva - import_rva,
|
|
|
|
(char *) ".dll", lvl + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-06-25 11:18:54 +08:00
|
|
|
if (strstr (path, "\\cygwin1.dll"))
|
|
|
|
cygwin_info (fh);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-02-18 03:38:33 +08:00
|
|
|
track_down (char *file, char *suffix, int lvl)
|
|
|
|
{
|
2000-12-16 12:53:30 +08:00
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("track_down: malloc()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (suffix == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("track_down: malloc()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
char *path = find_on_path (file, suffix, 0, 1);
|
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
printf ("Error: could not find %s\n", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Did *d = already_did (file);
|
|
|
|
switch (d->state)
|
|
|
|
{
|
|
|
|
case DID_NEW:
|
|
|
|
break;
|
|
|
|
case DID_ACTIVE:
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (lvl)
|
|
|
|
printf ("%*c", lvl, ' ');
|
|
|
|
printf ("%s", path);
|
|
|
|
printf (" (recursive)\n");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case DID_INACTIVE:
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (lvl)
|
|
|
|
printf ("%*c", lvl, ' ');
|
|
|
|
printf ("%s", path);
|
|
|
|
printf (" (already done)\n");
|
|
|
|
}
|
|
|
|
return;
|
2000-12-16 12:53:30 +08:00
|
|
|
default:
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lvl)
|
|
|
|
printf ("%*c", lvl, ' ');
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
printf ("%s not found\n", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("%s", path);
|
|
|
|
|
2000-10-28 13:00:00 +08:00
|
|
|
HANDLE fh =
|
|
|
|
CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
if (fh == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
printf (" - Cannot open\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->state = DID_ACTIVE;
|
|
|
|
|
2000-06-25 11:18:54 +08:00
|
|
|
dll_info (path, fh, lvl, 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
d->state = DID_INACTIVE;
|
2000-12-16 12:53:30 +08:00
|
|
|
if (!CloseHandle (fh))
|
|
|
|
keyeprint ("track_down: CloseHandle()");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-02-18 03:38:33 +08:00
|
|
|
ls (char *f)
|
|
|
|
{
|
|
|
|
HANDLE h = CreateFile (f, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
|
|
|
BY_HANDLE_FILE_INFORMATION info;
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
if (!GetFileInformationByHandle (h, &info))
|
|
|
|
keyeprint ("ls: GetFileInformationByHandle()");
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
SYSTEMTIME systime;
|
2000-12-16 12:53:30 +08:00
|
|
|
|
|
|
|
if (!FileTimeToSystemTime (&info.ftLastWriteTime, &systime))
|
|
|
|
keyeprint ("ls: FileTimeToSystemTime()");
|
2000-02-18 03:38:33 +08:00
|
|
|
printf ("%5dk %04d/%02d/%02d %s",
|
|
|
|
(((int) info.nFileSizeLow) + 512) / 1024,
|
2000-10-28 13:00:00 +08:00
|
|
|
systime.wYear, systime.wMonth, systime.wDay, f);
|
2000-06-25 11:18:54 +08:00
|
|
|
dll_info (f, h, 16, 0);
|
2000-12-16 12:53:30 +08:00
|
|
|
if (!CloseHandle (h))
|
|
|
|
keyeprint ("ls: CloseHandle()");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-02-18 03:38:33 +08:00
|
|
|
cygcheck (char *app)
|
|
|
|
{
|
|
|
|
char *papp = find_on_path (app, (char *) ".exe", 1, 0);
|
|
|
|
if (!papp)
|
|
|
|
{
|
|
|
|
printf ("Error: could not find %s\n", app);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char *s = strdup (papp);
|
|
|
|
char *sl = 0, *t;
|
|
|
|
for (t = s; *t; t++)
|
|
|
|
if (*t == '/' || *t == '\\' || *t == ':')
|
|
|
|
sl = t;
|
|
|
|
if (sl == 0)
|
|
|
|
paths[0] = (char *) ".";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*sl = 0;
|
|
|
|
paths[0] = s;
|
|
|
|
}
|
|
|
|
did = 0;
|
|
|
|
track_down (papp, (char *) ".exe", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
|
|
|
struct RegInfo
|
2000-10-28 13:00:00 +08:00
|
|
|
{
|
|
|
|
RegInfo *prev;
|
|
|
|
char *name;
|
|
|
|
HKEY key;
|
|
|
|
};
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-02-18 03:38:33 +08:00
|
|
|
show_reg (RegInfo * ri, int nest)
|
|
|
|
{
|
|
|
|
if (!ri)
|
|
|
|
return;
|
|
|
|
show_reg (ri->prev, 1);
|
|
|
|
if (nest)
|
|
|
|
printf ("%s\\", ri->name);
|
|
|
|
else
|
|
|
|
printf ("%s\n", ri->name);
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-02-18 03:38:33 +08:00
|
|
|
scan_registry (RegInfo * prev, HKEY hKey, char *name, int cygnus)
|
|
|
|
{
|
|
|
|
RegInfo ri;
|
|
|
|
ri.prev = prev;
|
|
|
|
ri.name = name;
|
|
|
|
ri.key = hKey;
|
|
|
|
|
|
|
|
char *cp;
|
|
|
|
for (cp = name; *cp; cp++)
|
|
|
|
if (strncasecmp (cp, "cygnus", 6) == 0)
|
|
|
|
cygnus = 1;
|
|
|
|
|
|
|
|
DWORD num_subkeys, max_subkey_len, num_values;
|
|
|
|
DWORD max_value_len, max_valdata_len, i;
|
|
|
|
if (RegQueryInfoKey (hKey, 0, 0, 0, &num_subkeys, &max_subkey_len, 0,
|
|
|
|
&num_values, &max_value_len, &max_valdata_len, 0, 0)
|
|
|
|
!= ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
char tmp[400];
|
|
|
|
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError (),
|
2000-10-28 13:00:00 +08:00
|
|
|
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), tmp, 400, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
printf ("RegQueryInfoKey: %s\n", tmp);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cygnus)
|
|
|
|
{
|
|
|
|
show_reg (&ri, 0);
|
2000-12-16 12:53:30 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
char *value_name = (char *) malloc (max_value_len + 1);
|
2000-12-16 12:53:30 +08:00
|
|
|
if (value_name == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("scan_registry: malloc()");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
char *value_data = (char *) malloc (max_valdata_len + 1);
|
2000-12-16 12:53:30 +08:00
|
|
|
if (value_data == NULL)
|
|
|
|
{
|
|
|
|
keyeprint ("scan_registry: malloc()");
|
|
|
|
return;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
for (i = 0; i < num_values; i++)
|
|
|
|
{
|
|
|
|
DWORD dlen = max_valdata_len + 1;
|
|
|
|
DWORD nlen = max_value_len + 1;
|
|
|
|
DWORD type;
|
|
|
|
RegEnumValue (hKey, i, value_name, &nlen, 0,
|
|
|
|
&type, (BYTE *) value_data, &dlen);
|
|
|
|
{
|
|
|
|
printf (" %s = ", i ? value_name : "(default)");
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case REG_DWORD:
|
|
|
|
printf ("0x%08x\n", *(unsigned *) value_data);
|
|
|
|
break;
|
|
|
|
case REG_EXPAND_SZ:
|
|
|
|
case REG_SZ:
|
|
|
|
printf ("`%s'\n", value_data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf ("(unsupported type)\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (value_name);
|
|
|
|
free (value_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *subkey_name = (char *) malloc (max_subkey_len + 1);
|
|
|
|
for (i = 0; i < num_subkeys; i++)
|
|
|
|
{
|
2000-10-28 13:00:00 +08:00
|
|
|
if (RegEnumKey (hKey, i, subkey_name, max_subkey_len + 1) ==
|
|
|
|
ERROR_SUCCESS)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HKEY sKey;
|
2001-11-12 08:14:27 +08:00
|
|
|
if (RegOpenKeyEx (hKey, subkey_name, 0, KEY_READ, &sKey)
|
2000-02-18 03:38:33 +08:00
|
|
|
== ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
scan_registry (&ri, sKey, subkey_name, cygnus);
|
2000-12-16 12:53:30 +08:00
|
|
|
if (RegCloseKey (sKey) != ERROR_SUCCESS)
|
|
|
|
keyeprint ("scan_registry: RegCloseKey()");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (subkey_name);
|
|
|
|
}
|
|
|
|
|
2003-03-01 11:38:19 +08:00
|
|
|
void
|
|
|
|
pretty_id (const char *s, char *cygwin, size_t cyglen)
|
|
|
|
{
|
|
|
|
char *groups[16384];
|
|
|
|
|
|
|
|
strcpy (cygwin + cyglen++, " ");
|
|
|
|
strcpy (cygwin + cyglen, s);
|
|
|
|
putenv (cygwin);
|
|
|
|
|
|
|
|
char *id = cygpath ("/bin/id.exe", NULL);
|
2003-09-11 10:56:40 +08:00
|
|
|
for (char *p = id; (p = strchr (p, '/')); p++)
|
2003-03-01 11:38:19 +08:00
|
|
|
*p = '\\';
|
|
|
|
|
|
|
|
if (access (id, X_OK))
|
2003-10-18 01:19:31 +08:00
|
|
|
fprintf (stderr, "`id' program not found\n");
|
2003-03-01 11:38:19 +08:00
|
|
|
|
|
|
|
FILE *f = popen (id, "rt");
|
|
|
|
|
|
|
|
char buf[16384];
|
|
|
|
fgets (buf, sizeof (buf), f);
|
2003-06-13 10:36:12 +08:00
|
|
|
char *uid = strtok (buf, ")") + strlen ("uid=");
|
|
|
|
char *gid = strtok (NULL, ")") + strlen ("gid=") + 1;
|
2003-03-01 11:38:19 +08:00
|
|
|
char **ng;
|
|
|
|
size_t sz = 0;
|
|
|
|
for (ng = groups; (*ng = strtok (NULL, ",")); ng++)
|
|
|
|
{
|
|
|
|
char *p = strchr (*ng, '\n');
|
|
|
|
if (p)
|
|
|
|
*p = '\0';
|
|
|
|
if (ng == groups)
|
2003-06-13 10:36:12 +08:00
|
|
|
*ng += strlen (" groups=");
|
2003-03-01 11:38:19 +08:00
|
|
|
size_t len = strlen (*ng);
|
|
|
|
if (sz < len)
|
|
|
|
sz = len;
|
|
|
|
}
|
|
|
|
|
2003-06-13 10:36:12 +08:00
|
|
|
printf ("\nOutput from %s (%s)\n", id, s);
|
2003-09-11 10:56:40 +08:00
|
|
|
size_t szmaybe = strlen ("UID: ") + strlen (uid);
|
2003-03-01 11:38:19 +08:00
|
|
|
if (sz < szmaybe)
|
|
|
|
sz = szmaybe;
|
|
|
|
sz += 1;
|
|
|
|
int n = 80 / (int) sz;
|
|
|
|
sz = -sz;
|
2003-06-13 10:36:12 +08:00
|
|
|
ng[0] += strlen ("groups=");
|
|
|
|
printf ("UID: %.*s) GID: %s)\n", sz + (sizeof ("UID: ") - 1), uid, gid);
|
2003-03-01 11:38:19 +08:00
|
|
|
int i = 0;
|
|
|
|
for (char **g = groups; g < ng; g++)
|
|
|
|
{
|
|
|
|
if (i < n)
|
|
|
|
i++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
puts ("");
|
|
|
|
}
|
|
|
|
if (++i <= n && g != (ng - 1))
|
|
|
|
printf ("%*s ", sz, *g);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf ("%s\n", *g);
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2000-02-18 03:38:33 +08:00
|
|
|
dump_sysinfo ()
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
char tmp[4000];
|
|
|
|
time_t now;
|
2000-06-25 11:18:54 +08:00
|
|
|
char *found_cygwin_dll;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-12-12 06:51:01 +08:00
|
|
|
printf ("\nCygwin Win95/NT Configuration Diagnostics\n");
|
2000-02-18 03:38:33 +08:00
|
|
|
time (&now);
|
|
|
|
printf ("Current System Time: %s\n", ctime (&now));
|
|
|
|
|
|
|
|
OSVERSIONINFO osversion;
|
|
|
|
osversion.dwOSVersionInfoSize = sizeof (osversion);
|
2000-12-16 12:53:30 +08:00
|
|
|
if (!GetVersionEx (&osversion))
|
|
|
|
keyeprint ("dump_sysinfo: GetVersionEx()");
|
2000-02-18 03:38:33 +08:00
|
|
|
char *osname = (char *) "unknown OS";
|
|
|
|
switch (osversion.dwPlatformId)
|
|
|
|
{
|
|
|
|
case VER_PLATFORM_WIN32s:
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "32s";
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32_WINDOWS:
|
|
|
|
switch (osversion.dwMinorVersion)
|
|
|
|
{
|
|
|
|
case 0:
|
2002-03-07 11:13:17 +08:00
|
|
|
if (strchr (osversion.szCSDVersion, 'C'))
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "95 OSR2";
|
2001-11-10 01:18:36 +08:00
|
|
|
else
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "95";
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2001-11-10 01:18:36 +08:00
|
|
|
case 10:
|
2002-03-07 11:13:17 +08:00
|
|
|
if (strchr (osversion.szCSDVersion, 'A'))
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "98 SE";
|
2001-11-10 01:18:36 +08:00
|
|
|
else
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "98";
|
2001-11-10 01:18:36 +08:00
|
|
|
break;
|
|
|
|
case 90:
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "ME";
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
default:
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "9X";
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32_NT:
|
2001-11-10 01:18:36 +08:00
|
|
|
if (osversion.dwMajorVersion == 5)
|
|
|
|
{
|
2001-11-13 01:55:52 +08:00
|
|
|
BOOL more_info = FALSE;
|
|
|
|
OSVERSIONINFOEX osversionex;
|
|
|
|
osversionex.dwOSVersionInfoSize = sizeof (osversionex);
|
2002-03-07 11:13:17 +08:00
|
|
|
if (GetVersionEx ((OSVERSIONINFO *) &osversionex))
|
2001-11-13 01:55:52 +08:00
|
|
|
more_info = TRUE;
|
2001-11-10 01:18:36 +08:00
|
|
|
if (osversion.dwMinorVersion == 0)
|
2001-11-13 01:55:52 +08:00
|
|
|
{
|
|
|
|
if (!more_info)
|
|
|
|
osname = (char *) "2000";
|
2001-11-13 04:21:43 +08:00
|
|
|
else if (osversionex.wProductType == VER_NT_SERVER
|
2002-03-07 11:13:17 +08:00
|
|
|
|| osversionex.wProductType ==
|
|
|
|
VER_NT_DOMAIN_CONTROLLER)
|
|
|
|
{
|
|
|
|
if (osversionex.wSuiteMask &VER_SUITE_DATACENTER)
|
2001-11-13 04:21:43 +08:00
|
|
|
osname = (char *) "2000 Datacenter Server";
|
|
|
|
else if (osversionex.wSuiteMask & VER_SUITE_ENTERPRISE)
|
|
|
|
osname = (char *) "2000 Advanced Server";
|
|
|
|
else
|
|
|
|
osname = (char *) "2000 Server";
|
2002-03-07 11:13:17 +08:00
|
|
|
}
|
2001-11-13 01:55:52 +08:00
|
|
|
else
|
2002-03-07 11:13:17 +08:00
|
|
|
osname = (char *) "2000 Professional";
|
2001-11-13 01:55:52 +08:00
|
|
|
}
|
2001-11-10 01:18:36 +08:00
|
|
|
else
|
2001-11-13 01:55:52 +08:00
|
|
|
{
|
|
|
|
if (!more_info)
|
|
|
|
osname = (char *) "XP";
|
2001-11-13 04:21:43 +08:00
|
|
|
else if (osversionex.wProductType == VER_NT_SERVER
|
2002-03-07 11:13:17 +08:00
|
|
|
|| osversionex.wProductType ==
|
|
|
|
VER_NT_DOMAIN_CONTROLLER)
|
|
|
|
{
|
2001-11-13 04:21:43 +08:00
|
|
|
if (osversionex.wSuiteMask & VER_SUITE_ENTERPRISE)
|
|
|
|
osname = (char *) ".NET Enterprise Server";
|
|
|
|
else
|
|
|
|
osname = (char *) ".NET Server";
|
|
|
|
}
|
2001-11-13 01:55:52 +08:00
|
|
|
else if (osversionex.wSuiteMask & VER_SUITE_PERSONAL)
|
2002-03-07 11:13:17 +08:00
|
|
|
osname = (char *) "XP Home Edition";
|
2001-11-13 01:55:52 +08:00
|
|
|
else
|
2002-03-07 11:13:17 +08:00
|
|
|
osname = (char *) "XP Professional";
|
|
|
|
|
2001-11-13 01:55:52 +08:00
|
|
|
}
|
2002-03-07 11:13:17 +08:00
|
|
|
}
|
2001-11-10 01:18:36 +08:00
|
|
|
else
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "NT";
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
default:
|
2001-11-13 01:55:52 +08:00
|
|
|
osname = (char *) "??";
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-11-13 05:55:39 +08:00
|
|
|
printf ("Windows %s Ver %lu.%lu Build %lu %s\n\n", osname,
|
|
|
|
osversion.dwMajorVersion, osversion.dwMinorVersion,
|
|
|
|
osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ?
|
2002-03-07 11:13:17 +08:00
|
|
|
osversion.dwBuildNumber : (osversion.dwBuildNumber & 0xffff),
|
2001-11-13 05:55:39 +08:00
|
|
|
osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ?
|
2002-03-07 11:13:17 +08:00
|
|
|
osversion.szCSDVersion : "");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
printf ("Path:");
|
|
|
|
char *s = getenv ("PATH"), *e;
|
|
|
|
char sep = strchr (s, ';') ? ';' : ':';
|
|
|
|
int count_path_items = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
for (e = s; *e && *e != sep; e++);
|
|
|
|
printf ("\t%.*s\n", e - s, s);
|
|
|
|
count_path_items++;
|
|
|
|
if (!*e)
|
|
|
|
break;
|
|
|
|
s = e + 1;
|
|
|
|
}
|
|
|
|
|
2003-03-01 11:38:19 +08:00
|
|
|
fflush (stdout);
|
|
|
|
|
2003-03-25 09:20:04 +08:00
|
|
|
char *cygwin = getenv ("CYGWIN");
|
|
|
|
if (cygwin)
|
|
|
|
cygwin -= strlen ("CYGWIN=");
|
|
|
|
else
|
|
|
|
cygwin = const_cast <char *> ("CYGWIN=");
|
2003-03-01 11:38:19 +08:00
|
|
|
size_t cyglen = strlen (cygwin);
|
|
|
|
cygwin = strcpy ((char *) malloc (cyglen + sizeof (" nontsec")), cygwin);
|
|
|
|
pretty_id ("nontsec", cygwin, cyglen);
|
|
|
|
pretty_id ("ntsec", cygwin, cyglen);
|
|
|
|
cygwin[cyglen] = 0;
|
|
|
|
putenv (cygwin);
|
|
|
|
|
2000-12-16 12:53:30 +08:00
|
|
|
if (!GetSystemDirectory (tmp, 4000))
|
|
|
|
keyeprint ("dump_sysinfo: GetSystemDirectory()");
|
2000-02-18 03:38:33 +08:00
|
|
|
printf ("\nSysDir: %s\n", tmp);
|
2000-12-16 12:53:30 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
GetWindowsDirectory (tmp, 4000);
|
|
|
|
printf ("WinDir: %s\n\n", tmp);
|
|
|
|
|
|
|
|
|
|
|
|
if (givehelp)
|
|
|
|
printf ("Here's some environment variables that may affect cygwin:\n");
|
|
|
|
for (i = 0; environ[i]; i++)
|
|
|
|
{
|
|
|
|
char *eq = strchr (environ[i], '=');
|
|
|
|
if (!eq)
|
|
|
|
continue;
|
|
|
|
/* int len = eq - environ[i]; */
|
|
|
|
for (j = 0; known_env_vars[j]; j++)
|
|
|
|
{
|
|
|
|
*eq = 0;
|
|
|
|
if (strcmp (environ[i], "PATH") == 0)
|
|
|
|
continue; /* we handle this one specially */
|
|
|
|
if (strcasecmp (environ[i], known_env_vars[j]) == 0)
|
|
|
|
printf ("%s = `%s'\n", environ[i], eq + 1);
|
|
|
|
*eq = '=';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
if (givehelp)
|
|
|
|
printf ("Here's the rest of your environment variables:\n");
|
|
|
|
for (i = 0; environ[i]; i++)
|
|
|
|
{
|
|
|
|
int found = 0;
|
|
|
|
char *eq = strchr (environ[i], '=');
|
|
|
|
if (!eq)
|
|
|
|
continue;
|
|
|
|
/* int len = eq - environ[i]; */
|
|
|
|
for (j = 0; known_env_vars[j]; j++)
|
|
|
|
{
|
|
|
|
*eq = 0;
|
|
|
|
if (strcasecmp (environ[i], known_env_vars[j]) == 0)
|
|
|
|
found = 1;
|
|
|
|
*eq = '=';
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
*eq = 0;
|
|
|
|
printf ("%s = `%s'\n", environ[i], eq + 1);
|
|
|
|
*eq = '=';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (registry)
|
|
|
|
{
|
|
|
|
if (givehelp)
|
|
|
|
printf ("Scanning registry for keys with `Cygnus' in them...\n");
|
|
|
|
#if 0
|
|
|
|
/* big and not generally useful */
|
|
|
|
scan_registry (0, HKEY_CLASSES_ROOT, (char *) "HKEY_CLASSES_ROOT", 0);
|
|
|
|
#endif
|
|
|
|
scan_registry (0, HKEY_CURRENT_CONFIG,
|
|
|
|
(char *) "HKEY_CURRENT_CONFIG", 0);
|
|
|
|
scan_registry (0, HKEY_CURRENT_USER, (char *) "HKEY_CURRENT_USER", 0);
|
|
|
|
scan_registry (0, HKEY_LOCAL_MACHINE, (char *) "HKEY_LOCAL_MACHINE", 0);
|
|
|
|
#if 0
|
|
|
|
/* the parts we need are duplicated in HKEY_CURRENT_USER anyway */
|
|
|
|
scan_registry (0, HKEY_USERS, (char *) "HKEY_USERS", 0);
|
|
|
|
#endif
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf ("Use `-r' to scan registry\n\n");
|
|
|
|
|
|
|
|
if (givehelp)
|
|
|
|
{
|
|
|
|
printf ("Listing available drives...\n");
|
|
|
|
printf ("Drv Type Size Free Flags Name\n");
|
|
|
|
}
|
2000-10-28 13:00:00 +08:00
|
|
|
int prev_mode =
|
|
|
|
SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
|
2000-02-18 03:38:33 +08:00
|
|
|
int drivemask = GetLogicalDrives ();
|
|
|
|
|
|
|
|
HINSTANCE k32 = LoadLibrary ("kernel32.dll");
|
2000-10-28 13:00:00 +08:00
|
|
|
BOOL (WINAPI * gdfse) (LPCSTR, long long *, long long *, long long *) =
|
2000-02-18 03:38:33 +08:00
|
|
|
(BOOL (WINAPI *) (LPCSTR, long long *, long long *, long long *))
|
2000-10-28 13:00:00 +08:00
|
|
|
GetProcAddress (k32, "GetDiskFreeSpaceExA");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 26; i++)
|
|
|
|
{
|
|
|
|
if (!(drivemask & (1 << i)))
|
|
|
|
continue;
|
|
|
|
char drive[4], name[200], fsname[200];
|
|
|
|
DWORD serno = 0, maxnamelen = 0, flags = 0;
|
|
|
|
name[0] = name[0] = fsname[0] = 0;
|
|
|
|
sprintf (drive, "%c:\\", i + 'a');
|
2000-12-16 12:53:30 +08:00
|
|
|
/* Report all errors, except if the Volume is ERROR_NOT_READY.
|
|
|
|
ERROR_NOT_READY is returned when removeable media drives are empty
|
2002-03-07 11:13:17 +08:00
|
|
|
(CD, floppy, etc.) */
|
|
|
|
if (!GetVolumeInformation
|
|
|
|
(drive, name, sizeof (name), &serno, &maxnamelen, &flags, fsname,
|
|
|
|
sizeof (fsname)) && GetLastError () != ERROR_NOT_READY)
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint ("dump_sysinfo: GetVolumeInformation()");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int dtype = GetDriveType (drive);
|
|
|
|
char drive_type[4] = "unk";
|
|
|
|
switch (dtype)
|
|
|
|
{
|
|
|
|
case DRIVE_REMOVABLE:
|
|
|
|
strcpy (drive_type, "fd ");
|
|
|
|
break;
|
|
|
|
case DRIVE_FIXED:
|
|
|
|
strcpy (drive_type, "hd ");
|
|
|
|
break;
|
|
|
|
case DRIVE_REMOTE:
|
|
|
|
strcpy (drive_type, "net");
|
|
|
|
break;
|
|
|
|
case DRIVE_CDROM:
|
|
|
|
strcpy (drive_type, "cd ");
|
|
|
|
break;
|
|
|
|
case DRIVE_RAMDISK:
|
|
|
|
strcpy (drive_type, "ram");
|
|
|
|
break;
|
2000-12-16 12:53:30 +08:00
|
|
|
default:
|
|
|
|
strcpy (drive_type, "unk");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
long capacity_mb = -1;
|
|
|
|
int percent_full = -1;
|
|
|
|
|
|
|
|
long long free_me = 0ULL, free_bytes = 0ULL, total_bytes = 1ULL;
|
2000-10-28 13:00:00 +08:00
|
|
|
if (gdfse != NULL && gdfse (drive, &free_me, &total_bytes, &free_bytes))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
capacity_mb = total_bytes / (1024L * 1024L);
|
|
|
|
percent_full = 100 - (int) ((100.0 * free_me) / total_bytes);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD spc = 0, bps = 0, fc = 0, tc = 1;
|
|
|
|
if (GetDiskFreeSpace (drive, &spc, &bps, &fc, &tc))
|
|
|
|
{
|
|
|
|
capacity_mb = (spc * bps * tc) / (1024 * 1024);
|
|
|
|
percent_full = 100 - (int) ((100.0 * fc) / tc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("%.2s %s %-6s ", drive, drive_type, fsname);
|
|
|
|
if (capacity_mb >= 0)
|
|
|
|
printf ("%5dMb %3d%% ", (int) capacity_mb, (int) percent_full);
|
|
|
|
else
|
|
|
|
printf (" N/A N/A ");
|
|
|
|
printf ("%s %s %s %s %s %s %s\n",
|
|
|
|
flags & FS_CASE_IS_PRESERVED ? "CP" : " ",
|
|
|
|
flags & FS_CASE_SENSITIVE ? "CS" : " ",
|
|
|
|
flags & FS_UNICODE_STORED_ON_DISK ? "UN" : " ",
|
|
|
|
flags & FS_PERSISTENT_ACLS ? "PA" : " ",
|
|
|
|
flags & FS_FILE_COMPRESSION ? "FC" : " ",
|
|
|
|
flags & FS_VOL_IS_COMPRESSED ? "VC" : " ",
|
|
|
|
#if 0
|
|
|
|
flags & FILE_SUPPORTS_ENCRYPTION ? "EN" : " ",
|
|
|
|
flags & FILE_SUPPORTS_OBJECT_IDS ? "OI" : " ",
|
|
|
|
flags & FILE_SUPPORTS_REPARSE_POINTS ? "RP" : " ",
|
|
|
|
flags & FILE_SUPPORTS_SPARSE_FILES ? "SP" : " ",
|
|
|
|
flags & FILE_VOLUME_QUOTAS ? "QU" : " ",
|
|
|
|
#endif
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
|
2000-12-16 12:53:30 +08:00
|
|
|
if (!FreeLibrary (k32))
|
|
|
|
keyeprint ("dump_sysinfo: FreeLibrary()");
|
2000-02-18 03:38:33 +08:00
|
|
|
SetErrorMode (prev_mode);
|
|
|
|
if (givehelp)
|
|
|
|
{
|
|
|
|
printf ("fd=floppy, hd=hard drive, cd=CD-ROM, net=Network Share\n");
|
|
|
|
printf ("CP=Case Preserving, CS=Case Sensitive, UN=Unicode\n");
|
2000-10-28 13:00:00 +08:00
|
|
|
printf
|
|
|
|
("PA=Persistent ACLS, FC=File Compression, VC=Volume Compression\n");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
|
2002-01-22 11:17:59 +08:00
|
|
|
unsigned ml_fsname = 4, ml_dir = 7, ml_type = 6;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-11-11 11:06:59 +08:00
|
|
|
struct mntent *mnt;
|
|
|
|
setmntent (0, 0);
|
|
|
|
while ((mnt = getmntent (0)))
|
|
|
|
{
|
2002-01-22 11:17:59 +08:00
|
|
|
unsigned n = (int) strlen (mnt->mnt_fsname);
|
2001-11-11 11:06:59 +08:00
|
|
|
if (ml_fsname < n)
|
|
|
|
ml_fsname = n;
|
|
|
|
n = (int) strlen (mnt->mnt_dir);
|
|
|
|
if (ml_dir < n)
|
|
|
|
ml_dir = n;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (givehelp)
|
|
|
|
{
|
2000-10-28 13:00:00 +08:00
|
|
|
printf
|
|
|
|
("Mount entries: these map POSIX directories to your NT drives.\n");
|
|
|
|
printf ("%-*s %-*s %-*s %s\n", ml_fsname, "-NT-", ml_dir, "-POSIX-",
|
2000-02-18 03:38:33 +08:00
|
|
|
ml_type, "-Type-", "-Flags-");
|
|
|
|
}
|
|
|
|
|
|
|
|
setmntent (0, 0);
|
|
|
|
while ((mnt = getmntent (0)))
|
|
|
|
{
|
|
|
|
printf ("%-*s %-*s %-*s %s\n",
|
|
|
|
ml_fsname, mnt->mnt_fsname,
|
2000-10-28 13:00:00 +08:00
|
|
|
ml_dir, mnt->mnt_dir, ml_type, mnt->mnt_type, mnt->mnt_opts);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
add_path ((char *) "\\bin", 4); /* just in case */
|
|
|
|
|
|
|
|
if (givehelp)
|
2000-10-28 13:00:00 +08:00
|
|
|
printf
|
|
|
|
("Looking to see where common programs can be found, if at all...\n");
|
2000-02-18 03:38:33 +08:00
|
|
|
for (i = 0; common_apps[i].name; i++)
|
|
|
|
if (!find_on_path ((char *) common_apps[i].name, (char *) ".exe", 1, 0))
|
2000-10-28 13:00:00 +08:00
|
|
|
{
|
|
|
|
if (common_apps[i].missing_is_good)
|
|
|
|
printf ("Not Found: %s (good!)\n", common_apps[i].name);
|
|
|
|
else
|
|
|
|
printf ("Not Found: %s\n", common_apps[i].name);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
if (givehelp)
|
|
|
|
printf ("Looking for various Cygnus DLLs... (-v gives version info)\n");
|
|
|
|
for (i = 0; i < num_paths; i++)
|
|
|
|
{
|
|
|
|
WIN32_FIND_DATA ffinfo;
|
|
|
|
sprintf (tmp, "%s/*.*", paths[i]);
|
|
|
|
HANDLE ff = FindFirstFile (tmp, &ffinfo);
|
|
|
|
int found = (ff != INVALID_HANDLE_VALUE);
|
2000-06-25 11:18:54 +08:00
|
|
|
found_cygwin_dll = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
while (found)
|
|
|
|
{
|
|
|
|
char *f = ffinfo.cFileName;
|
|
|
|
if (strcasecmp (f + strlen (f) - 4, ".dll") == 0)
|
|
|
|
{
|
|
|
|
if (strncasecmp (f, "cyg", 3) == 0)
|
|
|
|
{
|
|
|
|
sprintf (tmp, "%s\\%s", paths[i], f);
|
2000-06-25 11:18:54 +08:00
|
|
|
if (strcasecmp (f, "cygwin1.dll") == 0)
|
|
|
|
found_cygwin_dll = strdup (tmp);
|
|
|
|
else
|
|
|
|
ls (tmp);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
found = FindNextFile (ff, &ffinfo);
|
|
|
|
}
|
2000-06-25 11:18:54 +08:00
|
|
|
if (found_cygwin_dll)
|
|
|
|
{
|
|
|
|
ls (found_cygwin_dll);
|
|
|
|
free (found_cygwin_dll);
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
FindClose (ff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static int
|
2000-09-29 19:20:53 +08:00
|
|
|
check_keys ()
|
|
|
|
{
|
|
|
|
HANDLE h = CreateFileA ("CONIN$", GENERIC_READ | GENERIC_WRITE,
|
2000-10-28 13:00:00 +08:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
2000-09-29 19:20:53 +08:00
|
|
|
|
|
|
|
if (h == INVALID_HANDLE_VALUE || h == NULL)
|
2000-12-16 12:53:30 +08:00
|
|
|
return (keyeprint ("check_key: Opening CONIN$"));
|
2000-09-29 19:20:53 +08:00
|
|
|
|
|
|
|
DWORD mode;
|
|
|
|
|
|
|
|
if (!GetConsoleMode (h, &mode))
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint ("check_keys: GetConsoleMode()");
|
2000-09-29 19:20:53 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mode &= ~ENABLE_PROCESSED_INPUT;
|
|
|
|
if (!SetConsoleMode (h, mode))
|
2000-12-16 12:53:30 +08:00
|
|
|
keyeprint ("check_keys: GetConsoleMode()");
|
2000-09-29 19:20:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs ("\nThis key check works only in a console window,", stderr);
|
|
|
|
fputs (" _NOT_ in a terminal session!\n", stderr);
|
|
|
|
fputs ("Abort with Ctrl+C if in a terminal session.\n\n", stderr);
|
|
|
|
fputs ("Press `q' to exit.\n", stderr);
|
|
|
|
|
|
|
|
INPUT_RECORD in, prev_in;
|
|
|
|
|
|
|
|
// Drop first <RETURN> key
|
|
|
|
ReadConsoleInput (h, &in, 1, &mode);
|
|
|
|
|
|
|
|
memset (&in, 0, sizeof in);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
prev_in = in;
|
|
|
|
if (!ReadConsoleInput (h, &in, 1, &mode))
|
2000-10-28 13:00:00 +08:00
|
|
|
keyeprint ("ReadConsoleInput");
|
2000-09-29 19:20:53 +08:00
|
|
|
|
|
|
|
if (!memcmp (&in, &prev_in, sizeof in))
|
2000-10-28 13:00:00 +08:00
|
|
|
continue;
|
2000-09-29 19:20:53 +08:00
|
|
|
|
|
|
|
switch (in.EventType)
|
2000-10-28 13:00:00 +08:00
|
|
|
{
|
|
|
|
case KEY_EVENT:
|
|
|
|
printf ("%s %ux VK: 0x%02x VS: 0x%02x A: 0x%02x CTRL: ",
|
|
|
|
in.Event.KeyEvent.bKeyDown ? "Pressed " : "Released",
|
|
|
|
in.Event.KeyEvent.wRepeatCount,
|
|
|
|
in.Event.KeyEvent.wVirtualKeyCode,
|
|
|
|
in.Event.KeyEvent.wVirtualScanCode,
|
|
|
|
(unsigned char) in.Event.KeyEvent.uChar.AsciiChar);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & CAPSLOCK_ON ?
|
|
|
|
"CL " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY ?
|
|
|
|
"EK " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_ALT_PRESSED ?
|
|
|
|
"LA " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & LEFT_CTRL_PRESSED ?
|
|
|
|
"LC " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & NUMLOCK_ON ?
|
|
|
|
"NL " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_ALT_PRESSED ?
|
|
|
|
"RA " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & RIGHT_CTRL_PRESSED ?
|
|
|
|
"RC " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & SCROLLLOCK_ON ?
|
|
|
|
"SL " : "-- ", stdout);
|
|
|
|
fputs (in.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED ?
|
|
|
|
"SH " : "-- ", stdout);
|
|
|
|
fputc ('\n', stdout);
|
|
|
|
break;
|
|
|
|
|
2000-12-16 12:53:30 +08:00
|
|
|
default:
|
|
|
|
break;
|
2000-10-28 13:00:00 +08:00
|
|
|
}
|
2000-09-29 19:20:53 +08:00
|
|
|
}
|
|
|
|
while (in.EventType != KEY_EVENT ||
|
2000-10-28 13:00:00 +08:00
|
|
|
in.Event.KeyEvent.bKeyDown != FALSE ||
|
|
|
|
in.Event.KeyEvent.uChar.AsciiChar != 'q');
|
2000-09-29 19:20:53 +08:00
|
|
|
|
|
|
|
CloseHandle (h);
|
|
|
|
return 0;
|
|
|
|
}
|
2000-10-28 13:00:00 +08:00
|
|
|
|
2002-02-28 00:10:17 +08:00
|
|
|
static void
|
2002-03-07 11:13:17 +08:00
|
|
|
usage (FILE * stream, int status)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-02-28 00:10:17 +08:00
|
|
|
fprintf (stream, "\
|
2003-04-27 05:52:03 +08:00
|
|
|
Usage: cygcheck [OPTIONS] [PROGRAM...]\n\
|
|
|
|
Check system information or PROGRAM library dependencies\n\
|
|
|
|
\n\
|
2003-08-16 04:26:11 +08:00
|
|
|
-c, --check-setup check packages installed via setup.exe\n\
|
2003-09-12 00:24:26 +08:00
|
|
|
-d, --dump-only no integrity checking of package contents (requires -c)\n\
|
2003-08-16 04:26:11 +08:00
|
|
|
-s, --sysinfo system information (not with -k)\n\
|
2003-09-12 00:24:26 +08:00
|
|
|
-v, --verbose verbose output (indented) (for -[cfls] or programs)\n\
|
2003-08-16 04:26:11 +08:00
|
|
|
-r, --registry registry search (requires -s)\n\
|
|
|
|
-k, --keycheck perform a keyboard check session (not with -[scfl])\n\
|
|
|
|
-f, --find-package find installed packages containing files (not with -[cl])\n\
|
|
|
|
-l, --list-package list the contents of installed packages (not with -[cf])\n\
|
|
|
|
-h, --help give help about the info (not with -[cfl])\n\
|
|
|
|
-V, --version output version information and exit\n\
|
2002-02-28 00:10:17 +08:00
|
|
|
You must at least give either -s or -k or a program name\n");
|
|
|
|
exit (status);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-09-29 19:20:53 +08:00
|
|
|
struct option longopts[] = {
|
2001-11-11 14:07:36 +08:00
|
|
|
{"check-setup", no_argument, NULL, 'c'},
|
2003-09-12 00:24:26 +08:00
|
|
|
{"dump-only", no_argument, NULL, 'd'},
|
2000-10-28 13:00:00 +08:00
|
|
|
{"sysinfo", no_argument, NULL, 's'},
|
|
|
|
{"registry", no_argument, NULL, 'r'},
|
|
|
|
{"verbose", no_argument, NULL, 'v'},
|
|
|
|
{"keycheck", no_argument, NULL, 'k'},
|
2003-08-16 04:26:11 +08:00
|
|
|
{"find-package", no_argument, NULL, 'f'},
|
|
|
|
{"list-package", no_argument, NULL, 'l'},
|
2000-10-28 13:00:00 +08:00
|
|
|
{"help", no_argument, NULL, 'h'},
|
2002-03-07 11:06:28 +08:00
|
|
|
{"version", no_argument, 0, 'V'},
|
2000-10-28 13:00:00 +08:00
|
|
|
{0, no_argument, NULL, 0}
|
2000-09-29 19:20:53 +08:00
|
|
|
};
|
2000-10-28 13:39:38 +08:00
|
|
|
|
2003-09-12 00:24:26 +08:00
|
|
|
static char opts[] = "cdfhklrsvV";
|
2002-02-28 00:10:17 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
print_version ()
|
|
|
|
{
|
|
|
|
const char *v = strchr (version, ':');
|
|
|
|
int len;
|
|
|
|
if (!v)
|
|
|
|
{
|
|
|
|
v = "?";
|
|
|
|
len = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v += 2;
|
|
|
|
len = strchr (v, ' ') - v;
|
|
|
|
}
|
|
|
|
printf ("\
|
|
|
|
cygcheck version %.*s\n\
|
|
|
|
System Checker for Cygwin\n\
|
2003-03-04 13:30:50 +08:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.\n\
|
2002-09-16 03:24:37 +08:00
|
|
|
Compiled on %s\n\
|
|
|
|
", len, v, __DATE__);
|
2002-02-28 00:10:17 +08:00
|
|
|
}
|
2000-09-29 19:20:53 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2000-09-29 19:20:53 +08:00
|
|
|
while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 's':
|
2000-10-28 13:00:00 +08:00
|
|
|
sysinfo = 1;
|
|
|
|
break;
|
2001-11-11 14:07:36 +08:00
|
|
|
case 'c':
|
|
|
|
check_setup = 1;
|
|
|
|
break;
|
2003-09-12 00:24:26 +08:00
|
|
|
case 'd':
|
|
|
|
dump_only = 1;
|
|
|
|
break;
|
2000-09-29 19:20:53 +08:00
|
|
|
case 'r':
|
2000-10-28 13:00:00 +08:00
|
|
|
registry = 1;
|
|
|
|
break;
|
2000-09-29 19:20:53 +08:00
|
|
|
case 'v':
|
2000-10-28 13:00:00 +08:00
|
|
|
verbose = 1;
|
|
|
|
break;
|
2000-09-29 19:20:53 +08:00
|
|
|
case 'k':
|
2000-10-28 13:00:00 +08:00
|
|
|
keycheck = 1;
|
|
|
|
break;
|
2003-08-16 04:26:11 +08:00
|
|
|
case 'f':
|
|
|
|
find_package = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
list_package = 1;
|
|
|
|
break;
|
2000-09-29 19:20:53 +08:00
|
|
|
case 'h':
|
2000-10-28 13:00:00 +08:00
|
|
|
givehelp = 1;
|
|
|
|
break;
|
2002-02-28 00:10:17 +08:00
|
|
|
case 'V':
|
|
|
|
print_version ();
|
2002-03-07 11:13:17 +08:00
|
|
|
exit (0);
|
2000-09-29 19:20:53 +08:00
|
|
|
default:
|
2002-02-28 00:10:17 +08:00
|
|
|
usage (stderr, 1);
|
2000-10-28 13:00:00 +08:00
|
|
|
/*NOTREACHED*/}
|
2000-09-29 19:20:53 +08:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2002-02-28 00:25:30 +08:00
|
|
|
if (argc == 0 && !sysinfo && !keycheck && !check_setup)
|
2002-03-07 11:13:17 +08:00
|
|
|
if (givehelp)
|
|
|
|
usage (stdout, 0);
|
|
|
|
else
|
|
|
|
usage (stderr, 1);
|
2000-09-29 19:20:53 +08:00
|
|
|
|
2003-08-16 04:26:11 +08:00
|
|
|
if ((check_setup || sysinfo || find_package || list_package) && keycheck)
|
|
|
|
usage (stderr, 1);
|
|
|
|
|
|
|
|
if ((find_package || list_package) && check_setup)
|
|
|
|
usage (stderr, 1);
|
|
|
|
|
2003-09-12 00:24:26 +08:00
|
|
|
if (dump_only && !check_setup)
|
|
|
|
usage (stderr, 1);
|
|
|
|
|
2003-08-16 04:26:11 +08:00
|
|
|
if (find_package && list_package)
|
2002-02-28 00:10:17 +08:00
|
|
|
usage (stderr, 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-09-29 19:20:53 +08:00
|
|
|
if (keycheck)
|
2000-10-28 13:00:00 +08:00
|
|
|
return check_keys ();
|
2000-09-29 19:20:53 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
init_paths ();
|
|
|
|
|
2003-08-16 04:26:11 +08:00
|
|
|
/* FIXME: Add help for check_setup and {list,find}_package */
|
|
|
|
if (argc >= 1 && givehelp && !check_setup && !find_package && !list_package)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-08-16 04:26:11 +08:00
|
|
|
printf("Here is where the OS will find your program%s, and which dlls\n",
|
|
|
|
argc > 1 ? "s" : "");
|
|
|
|
printf ("will be used for it. Use -v to see DLL version info\n");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (!sysinfo)
|
|
|
|
printf ("\n");
|
|
|
|
}
|
|
|
|
|
2001-11-11 14:07:36 +08:00
|
|
|
if (check_setup)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-09-12 00:24:26 +08:00
|
|
|
dump_setup (verbose, argv, !dump_only);
|
2003-08-16 04:26:11 +08:00
|
|
|
}
|
|
|
|
else if (find_package)
|
|
|
|
{
|
|
|
|
package_find (verbose, argv);
|
|
|
|
}
|
|
|
|
else if (list_package)
|
|
|
|
{
|
|
|
|
package_list (verbose, argv);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-11-11 14:07:36 +08:00
|
|
|
else
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
{
|
2003-08-16 04:26:11 +08:00
|
|
|
if (i)
|
|
|
|
puts ("");
|
2001-11-11 14:07:36 +08:00
|
|
|
cygcheck (argv[i]);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (sysinfo)
|
2001-11-11 14:16:18 +08:00
|
|
|
{
|
|
|
|
dump_sysinfo ();
|
|
|
|
if (!check_setup)
|
|
|
|
{
|
2001-11-13 05:28:32 +08:00
|
|
|
puts ("");
|
2001-11-12 08:14:27 +08:00
|
|
|
dump_setup (verbose, NULL, false);
|
2001-11-11 14:16:18 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-08-16 04:26:11 +08:00
|
|
|
if (!givehelp)
|
|
|
|
puts ("Use -h to see help about each section");
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|