⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cygcheck.cc

📁 cygwin, 著名的在win32下模拟unix操作系统的东东
💻 CC
📖 第 1 页 / 共 3 页
字号:
/* cygcheck.cc   Copyright 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.   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>#include <sys/time.h>#include <ctype.h>#include <windows.h>#include "cygwin/include/sys/cygwin.h"#include "cygwin/include/mntent.h"#include "cygwin/include/getopt.h"int verbose = 0;int registry = 0;int sysinfo = 0;int givehelp = 0;int keycheck = 0;int check_setup = 0;#ifdef __GNUC__typedef long long longlong;#elsetypedef __int64 longlong;#endifvoid dump_setup (int, char **, bool);static const char version[] = "$Revision: 1.29 $";static const char *known_env_vars[] = {  "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};struct{  const char *name;  int missing_is_good;}static common_apps[] = {  {"bash", 0},  {"cat", 0},  {"cpp", 1},  {"find", 0},  {"gcc", 0},  {"gdb", 0},  {"ld", 0},  {"ls", 0},  {"make", 0},  {"sh", 0},  {0, 0}};static int num_paths = 0, max_paths = 0;static char **paths = 0;/* * keyeprint() is used to report failure modes */static intkeyeprint (const char *name){  fprintf (stderr, "cygcheck: %s failed: %lu\n", name, GetLastError ());  return 1;}static voidadd_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);  if (paths[num_paths] == NULL)    {      keyeprint ("add_path: malloc()");      return;    }  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++;}static voidinit_paths (){  char tmp[4000], *sl;  add_path ((char *) ".", 1);	/* to be replaced later */  add_path ((char *) ".", 1);	/* the current directory */  if (GetSystemDirectory (tmp, 4000))    add_path (tmp, strlen (tmp));  else    keyeprint ("init_paths: GetSystemDirectory()");  sl = strrchr (tmp, '\\');  if (sl)    {      strcpy (sl, "\\SYSTEM");      add_path (tmp, strlen (tmp));    }  GetWindowsDirectory (tmp, 4000);  add_path (tmp, strlen (tmp));  char *wpath = getenv ("PATH");  if (wpath)    {      char *b, *e;      b = wpath;      while (1)	{	  for (e = b; *e && *e != ';'; e++);	  add_path (b, e - b);	  if (!*e)	    break;	  b = e + 1;	}    }  else    printf ("WARNING: PATH is not set at all!\n");}static char *find_on_path (char *file, char *default_extension,	      int showall = 0, int search_sysdirs = 0){  static char rv[4000];  char tmp[4000], *ptr = rv;  if (file == NULL)    {      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;    }  if (strchr (file, ':') || strchr (file, '\\') || strchr (file, '/'))    return file;  if (strchr (file, '.'))    default_extension = (char *) "";  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);	  if (GetFileAttributes (ptr) != (DWORD) - 1)	    {	      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	3struct Did{  Did *next;  char *file;  int state;};static Did *did = 0;static Did *already_did (char *file){  Did *d;  for (d = did; d; d = d->next)    if (strcasecmp (d->file, file) == 0)      return d;  d = (Did *) malloc (sizeof (Did));  d->file = strdup (file);  d->next = did;  d->state = DID_NEW;  did = d;  return d;}static intget_word (HANDLE fh, int offset){  short rv;  unsigned r;  if (SetFilePointer (fh, offset, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER      && GetLastError () != NO_ERROR)    keyeprint ("get_word: SetFilePointer()");  if (!ReadFile (fh, &rv, 2, (DWORD *) &r, 0))    keyeprint ("get_word: Readfile()");  return rv;}static intget_dword (HANDLE fh, int offset){  int rv;  unsigned r;  if (SetFilePointer (fh, offset, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER      && GetLastError () != NO_ERROR)    keyeprint ("get_word: SetFilePointer()");  if (!ReadFile (fh, &rv, 4, (DWORD *) &r, 0))    keyeprint ("get_dword: Readfile()");  return rv;}struct Section{  char name[8];  int virtual_size;  int virtual_address;  int size_of_raw_data;  int pointer_to_raw_data;};static intrva_to_offset (int rva, char *sections, int nsections, int *sz){  int i;  if (sections == NULL)    {      keyeprint ("rva_to_offset: NULL passed for sections");      return 0;    }  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{  unsigned characteristics;  unsigned timestamp;  unsigned forwarder_chain;  unsigned name_rva;  unsigned iat_rva;};static void track_down (char *file, char *suffix, int lvl);#define CYGPREFIX (sizeof ("%%% Cygwin ") - 1)static voidcygwin_info (HANDLE h){  char *buf, *bufend, *buf_start = NULL;  const char *hello = "    Cygwin DLL version info:\n";  DWORD size = GetFileSize (h, NULL);  DWORD n;  if (size == 0xffffffff)    return;  buf_start = buf = (char *) calloc (1, size + 1);  if (buf == NULL)    {      keyeprint ("cygwin_info: malloc()");      return;    }  (void) SetFilePointer (h, 0, NULL, FILE_BEGIN);  if (!ReadFile (h, buf, size, &n, NULL))    {      free (buf_start);      return;    }  static char dummy[] = "\0\0\0\0\0\0\0";  char *dll_major = dummy;  bufend = buf + size;  while (buf < bufend)    if ((buf = (char *) memchr (buf, '%', bufend - buf)) == NULL)      break;    else if (strncmp ("%%% Cygwin ", buf, CYGPREFIX) != 0)      buf++;    else      {	char *p = strchr (buf += CYGPREFIX, '\n');	if (!p)	  break;	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);	    sprintf (pbuf, "DLL version: %d.%d.%.*s", maj, min, len - 11,		     buf + 11);	    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);	hello = "";      }  if (!*hello)    puts ("");  free (buf_start);  return;}static voiddll_info (const char *path, HANDLE fh, int lvl, int recurse){  DWORD junk;  int i;  int pe_header_offset = get_dword (fh, 0x3c);  int opthdr_ofs = pe_header_offset + 4 + 20;  unsigned short v[6];  if (path == NULL)    {      keyeprint ("dll_info: NULL passed for path");      return;    }  if (SetFilePointer (fh, opthdr_ofs + 40, 0, FILE_BEGIN) ==      INVALID_SET_FILE_POINTER && GetLastError () != NO_ERROR)    keyeprint ("dll_info: SetFilePointer()");  if (!ReadFile (fh, &v, sizeof (v), &junk, 0))    keyeprint ("dll_info: Readfile()");  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");  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);  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()");  if (verbose && num_entries >= 1 && export_size > 0)    {      int expsz;      int expbase = rva_to_offset (export_rva, sections, nsections, &expsz);      if (expbase)	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -