Beispiel #1
0
static BOOL IsValidRunCommand(const TCHAR *pszRunCmd)
{
	TCHAR *buf,*pexe,*pargs;
	TCHAR szFullExe[MAX_PATH],*pszFilePart;
	buf=mir_tstrcpy((TCHAR*)_alloca((mir_tstrlen(pszRunCmd)+1)*sizeof(TCHAR)),pszRunCmd);
	/* split into executable path and arguments */
	if (buf[0]==_T('\"')) {
		pargs=_tcschr(&buf[1],_T('\"'));
		if (pargs!=NULL) *(pargs++)=0;
		pexe=&buf[1];
		if (*pargs==_T(' ')) ++pargs;
	} else {
		pargs=_tcschr(buf,_T(' '));
		if (pargs!=NULL) *pargs=0;
		pexe=buf;
	}
	if (SearchPath(NULL,pexe,_T(".exe"),_countof(szFullExe),szFullExe,&pszFilePart)) {
		if (pszFilePart!=NULL)
			if (!mir_tstrcmpi(pszFilePart,_T("rundll32.exe")) || !mir_tstrcmpi(pszFilePart,_T("rundll.exe"))) {
				/* split into dll path and arguments */
				if (pargs[0]==_T('\"')) {
					++pargs;
					pexe=_tcschr(&pargs[1],_T('\"'));
					if (pexe!=NULL) *pexe=0;
				} else {
					pexe=_tcschr(pargs,_T(','));
					if (pexe!=NULL) *pexe=0;
				}
				return SearchPath(NULL,pargs,_T(".dll"),0,NULL,NULL)!=0;
			}
			return TRUE;
	}
	return FALSE;
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// BindStatusRoutine()
//   Called by BindImageEx() at various points. This is used to determine the
// dependency tree which is later examined by cx_Freeze.
//-----------------------------------------------------------------------------
static BOOL __stdcall BindStatusRoutine(
    IMAGEHLP_STATUS_REASON reason,      // reason called
    PCSTR imageName,                    // name of image being examined
    PCSTR dllName,                      // name of DLL
    ULONG_PTR virtualAddress,           // computed virtual address
    ULONG_PTR parameter)                // parameter (value depends on reason)
{
    char imagePath[MAX_PATH + 1];
    char fileName[MAX_PATH + 1];

    switch (reason) {
        case BindImportModule:
            strcpy(imagePath, imageName);
            PathRemoveFileSpec(imagePath);
            if (!SearchPath(imagePath, dllName, NULL, sizeof(fileName),
                    fileName, NULL)) {
                if (!SearchPath(NULL, dllName, NULL, sizeof(fileName),
                        fileName, NULL))
                    return FALSE;
            }
            Py_INCREF(Py_None);
            if (PyDict_SetItemString(g_ImageNames, fileName, Py_None) < 0)
                return FALSE;
            break;
        default:
            break;
    }

    return TRUE;
}
Beispiel #3
0
int apiSearchPath(LPCWSTR lpPath, LPCWSTR lpFileName, LPCWSTR lpExtension, CEStr& rsPath)
{
	bool bFound = false;
	wchar_t *pszFilePart, *pszBuffer = NULL;
	wchar_t szFind[MAX_PATH+1];

	DWORD nLen = SearchPath(lpPath, lpFileName, lpExtension, countof(szFind), szFind, &pszFilePart);
	if (nLen)
	{
		if (nLen < countof(szFind))
		{
			bFound = true;
			rsPath.Set(szFind);
		}
		else
		{
			// Too long path, allocate more space
			pszBuffer = (wchar_t*)malloc((++nLen)*sizeof(*pszBuffer));
			if (pszBuffer)
			{
				DWORD nLen2 = SearchPath(lpPath, lpFileName, lpExtension, nLen, pszBuffer, &pszFilePart);
				if (nLen2 && (nLen2 < nLen))
				{
					bFound = true;
					rsPath.Set(pszBuffer);
				}
				free(pszBuffer);
			}
		}
	}

	return bFound ? rsPath.GetLen() : 0;
}
Beispiel #4
0
static char *
find_executable_in_path(const char *name, const char *exclude_name, char *path)
{
	path = x_strdup(path);

	// Search the path looking for the first compiler of the right name that
	// isn't us.
	char *saveptr = NULL;
	for (char *tok = strtok_r(path, PATH_DELIM, &saveptr);
	     tok;
	     tok = strtok_r(NULL, PATH_DELIM, &saveptr)) {
#ifdef _WIN32
		char namebuf[MAX_PATH];
		int ret = SearchPath(tok, name, NULL, sizeof(namebuf), namebuf, NULL);
		if (!ret) {
			char *exename = format("%s.exe", name);
			ret = SearchPath(tok, exename, NULL, sizeof(namebuf), namebuf, NULL);
			free(exename);
		}
		(void) exclude_name;
		if (ret) {
			free(path);
			return x_strdup(namebuf);
		}
#else
		struct stat st1, st2;
		char *fname = format("%s/%s", tok, name);
		// Look for a normal executable file.
		if (access(fname, X_OK) == 0 &&
		    lstat(fname, &st1) == 0 &&
		    stat(fname, &st2) == 0 &&
		    S_ISREG(st2.st_mode)) {
			if (S_ISLNK(st1.st_mode)) {
				char *buf = x_realpath(fname);
				if (buf) {
					char *p = basename(buf);
					if (str_eq(p, exclude_name)) {
						// It's a link to "ccache"!
						free(p);
						free(buf);
						continue;
					}
					free(buf);
					free(p);
				}
			}

			// Found it!
			free(path);
			return fname;
		}
		free(fname);
#endif
	}

	free(path);
	return NULL;
}
Beispiel #5
0
static HANDLE
find_file(const char *exec_path, const char *path_var,
	  char *full_fname, DWORD full_len)
{
	HANDLE exec_handle;
	char *fname;
	char *ext;
	DWORD req_len;
	int i;
	static const char *extensions[] =
	  /* Should .com come before no-extension case?  */
	  { ".exe", ".cmd", ".bat", "", ".com", NULL };

	fname = xmalloc(strlen(exec_path) + 5);
	strcpy(fname, exec_path);
	ext = fname + strlen(fname);

	for (i = 0; extensions[i]; i++) {
		strcpy(ext, extensions[i]);
		if (((req_len = SearchPath (path_var, fname, NULL, full_len,
					    full_fname, NULL)) > 0
		     /* For compatibility with previous code, which
			used OpenFile, and with Windows operation in
			general, also look in various default
			locations, such as Windows directory and
			Windows System directory.  Warning: this also
			searches PATH in the Make's environment, which
			might not be what the Makefile wants, but it
			seems to be OK as a fallback, after the
			previous SearchPath failed to find on child's
			PATH.  */
		     || (req_len = SearchPath (NULL, fname, NULL, full_len,
					       full_fname, NULL)) > 0)
		    && req_len <= full_len
		    && (exec_handle =
				CreateFile(full_fname,
					   GENERIC_READ,
					   FILE_SHARE_READ | FILE_SHARE_WRITE,
					   NULL,
					   OPEN_EXISTING,
					   FILE_ATTRIBUTE_NORMAL,
					   NULL)) != INVALID_HANDLE_VALUE) {
			free(fname);
			return(exec_handle);
		}
	}

	free(fname);
	return INVALID_HANDLE_VALUE;
}
Beispiel #6
0
/* Search for EXEC file in DIR.  If EXEC does not have an extension,
   DIR is searched for EXEC with the standard extensions appended.  */
int
search_dir (const char *dir, const char *exec, int bufsize, char *buffer)
{
  const char *exts[] = {".bat", ".cmd", ".exe", ".com"};
  int n_exts = sizeof (exts) / sizeof (char *);
  char *dummy;
  int i, rc;
  const char *pext = strrchr (exec, '\\');

  /* Does EXEC already include an extension?  */
  if (!pext)
    pext = exec;
  pext = strchr (pext, '.');

  /* Search the directory for the program.  */
  if (pext)
    {
      /* SearchPath will not append an extension if the file already
	 has an extension, so we must append it ourselves.  */
      char exec_ext[MAX_PATH], *p;

      p = strcpy (exec_ext, exec) + strlen (exec);

      /* Search first without any extension; if found, we are done.  */
      rc = SearchPath (dir, exec_ext, NULL, bufsize, buffer, &dummy);
      if (rc > 0)
	return rc;

      /* Try the known extensions.  */
      for (i = 0; i < n_exts; i++)
	{
	  strcpy (p, exts[i]);
	  rc = SearchPath (dir, exec_ext, NULL, bufsize, buffer, &dummy);
	  if (rc > 0)
	    return rc;
	}
    }
  else
    {
      for (i = 0; i < n_exts; i++)
	{
	  rc = SearchPath (dir, exec, exts[i], bufsize, buffer, &dummy);
	  if (rc > 0)
	    return rc;
	}
    }

  return 0;
}
Beispiel #7
0
int __stdcall FindCygwinPath(char *CygwinDirectory, char *Dir, int Dirlen)
{
	char file[MAX_PATH], *filename;
	char c;

	/* zero-length string from Inno Setup is NULL */
	if (CygwinDirectory == NULL) {
		goto search_path;
	}

	if (strlen(CygwinDirectory) > 0) {
		if (SearchPath(CygwinDirectory, "bin\\cygwin1", ".dll", sizeof(file), file, &filename) > 0) {
#ifdef EXE
			printf("  %s from CygwinDirectory\n", file);
#endif
			goto found_dll;
		}
	}

search_path:;
	if (SearchPath(NULL, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) {
#ifdef EXE
		printf("  %s from PATH\n", file);
		goto found_dll;
#endif
	}

	for (c = 'C' ; c <= 'Z' ; c++) {
		char tmp[MAX_PATH];
		sprintf(tmp, "%c:\\cygwin\\bin;%c:\\cygwin64\\bin", c, c);
		if (SearchPath(tmp, "cygwin1", ".dll", sizeof(file), file, &filename) > 0) {
#ifdef EXE
			printf("  %s from %c:\\\n", file, c);
#endif
			goto found_dll;
		}
	}

	return 0;

found_dll:;
	memset(Dir, '\0', Dirlen);
	if (Dirlen <= strlen(file) - 16) {
		return 0;
	}
	memcpy(Dir, file, strlen(file) - 16); // delete "\\bin\\cygwin1.dll"
	return 1;
}
CAMLexport char * caml_search_exe_in_path(char * name)
{
  char * fullname, * filepart;
  DWORD pathlen, retcode;

  pathlen = strlen(name) + 1;
  if (pathlen < 256) pathlen = 256;
  while (1) {
    fullname = stat_alloc(pathlen);
    retcode = SearchPath(NULL,              /* use system search path */
			 name,
			 ".exe",            /* add .exe extension if needed */
			 pathlen,
			 fullname,
			 &filepart);
    if (retcode == 0) {
      caml_gc_message(0x100, "%s not found in search path\n",
		      (uintnat) name);
      strcpy(fullname, name);
      break;
    }
    if (retcode < pathlen) break;
    stat_free(fullname);
    pathlen = retcode + 1;
  }
  return fullname;
}
Beispiel #9
0
bool FindListFile(const wchar_t *FileName, StrBuf &output)
{
	StrBuf Path;
	DWORD dwSize;
	StrBuf FullPath;
	GetFullPath(FileName, FullPath);
	StrBuf NtPath;
	FormNtPath(FullPath, NtPath);
	const wchar_t *final=NULL;

	if (GetFileAttributes(NtPath) != INVALID_FILE_ATTRIBUTES)
	{
		output.Grow(FullPath.Size());
		lstrcpy(output, FullPath);
		return true;
	}

	{
		const wchar_t *tmp = FSF.PointToName(Info.ModuleName);
		Path.Grow(tmp-Info.ModuleName+1);
		lstrcpyn(Path,Info.ModuleName,(int)(tmp-Info.ModuleName+1));
		dwSize=SearchPath(Path,FileName,NULL,0,NULL,NULL);

		if (dwSize)
		{
			final = Path;
			goto success;
		}
	}
void CDebugScripts::RefreshList()
{
    int nIndex = m_ScriptList.GetSelectedIndex();

    CPath SearchPath("Scripts", "*");

    if (!SearchPath.FindFirst(CPath::FIND_ATTRIBUTE_ALLFILES))
    {
        return;
    }

    m_ScriptList.SetRedraw(false);
    m_ScriptList.DeleteAllItems();

    do
    {
        stdstr scriptFileName = SearchPath.GetNameExtension();
        m_ScriptList.AddItem(0, 0, scriptFileName.c_str());
    } while (SearchPath.FindNext());

    m_ScriptList.SetRedraw(true);
    m_ScriptList.Invalidate();

    if (nIndex >= 0)
    {
        m_ScriptList.SelectItem(nIndex);
        RefreshStatus();
    }
}
Beispiel #11
0
/*
 * @implemented
 */
void _tsearchenv(const _TCHAR* file,const _TCHAR* var,_TCHAR* path)
{
    _TCHAR* env = _tgetenv(var);
    _TCHAR* x;
    _TCHAR* y;
    _TCHAR* FilePart;

    TRACE(MK_STR(_tsearchenv)"()\n");

    x = _tcschr(env,'=');
    if ( x != NULL ) {
        *x = 0;
        x++;
    }
    y = _tcschr(env,';');
    while ( y != NULL ) {
        *y = 0;
        if ( SearchPath(x,file,NULL,MAX_PATH,path,&FilePart) > 0 ) {
            return;
        }
        x = y+1;
        y = _tcschr(env,';');
    }
    return;
}
Beispiel #12
0
CAMLexport char * caml_search_exe_in_path(char * name)
{
    char * fullname, * filepart;
    size_t fullnamelen;
    DWORD retcode;

    fullnamelen = strlen(name) + 1;
    if (fullnamelen < 256) fullnamelen = 256;
    while (1) {
        fullname = caml_stat_alloc(fullnamelen);
        retcode = SearchPath(NULL,              /* use system search path */
                             name,
                             ".exe",            /* add .exe extension if needed */
                             fullnamelen,
                             fullname,
                             &filepart);
        if (retcode == 0) {
            caml_gc_message(0x100, "%s not found in search path\n",
                            (uintnat) name);
            caml_stat_free(fullname);
            return caml_strdup(name);
        }
        if (retcode < fullnamelen)
            return fullname;
        caml_stat_free(fullname);
        fullnamelen = retcode + 1;
    }
}
Beispiel #13
0
//----------------------------------------------------------------------
//  
// DriverConnect
//
// If under NT 4.0, we need to establish system call hooking in order
// to make the changeover.
//
//----------------------------------------------------------------------
BOOL DriverConnect()
{
	TCHAR		Path[256];
	TCHAR		*File;

	// open the handle to the device
	if( !SearchPath( NULL, SYS_FILE, NULL, sizeof(Path), Path, &File ) ) {

		// that failed, last ditch - try current directory again.
		GetCurrentDirectory( sizeof Path, Path );
		wsprintf( Path+lstrlen(Path), TEXT("\\%s"), SYS_FILE );
	}
	if ( ! LoadDeviceDriver( SYS_NAME, Path, &sys_handle ) )  {

		// unload it in case the driver moved 
		UnloadDeviceDriver( SYS_NAME );

		if ( ! LoadDeviceDriver( SYS_NAME, Path, &sys_handle ) )  {

			printf("Unable to load driver: ");
			PrintError();
			return FALSE;
		}
	}	
	return TRUE;
}
Beispiel #14
0
void CDocument::OnUpdateFileSendMail(CCmdUI* pCmdUI)
{
    ASSERT_VALID(this);

    if (_afxIsMailAvail == (BOOL)-1)
    {
        _afxIsMailAvail = ::GetProfileInt(_T("MAIL"), _T("MAPI"), 0) != 0 &&
                          SearchPath(NULL, _T("MAPI32.DLL"), NULL, 0, NULL, NULL) != 0;
    }

    // enable the Send... menu item if available
    pCmdUI->Enable(_afxIsMailAvail);
    CMenu* pMenu = pCmdUI->m_pMenu;
    if (!_afxIsMailAvail && pMenu != NULL)
    {
        // remove the Send... menu and surrounding separators
        UINT nStateAbove = pMenu->GetMenuState(pCmdUI->m_nIndex-1, MF_BYPOSITION);
        UINT nStateBelow = pMenu->GetMenuState(pCmdUI->m_nIndex+1, MF_BYPOSITION);
        pMenu->RemoveMenu(pCmdUI->m_nIndex, MF_BYPOSITION);
        if (nStateAbove & nStateBelow & MF_SEPARATOR)
        {
            // a separator must be removed since the Send... is gone
            if (nStateAbove != (UINT)-1)
                pMenu->RemoveMenu(pCmdUI->m_nIndex-1, MF_BYPOSITION);
            else if (nStateBelow != (UINT)-1)
                pMenu->RemoveMenu(pCmdUI->m_nIndex, MF_BYPOSITION);
        }
    }
}
Beispiel #15
0
lib_handle      IncSearch( char *name ) {
//=======================================

// Search for a library member.

    lib_handle  lp;

    lp = NULL;
    if( IncludePath != NULL ) {
        lp = SearchPath( IncludePath, name );
    }
    if( lp == NULL && FIncludePath != NULL ) {
        lp = SearchPath( FIncludePath, name );
    }
    return( lp );
}
Beispiel #16
0
static
int init_driver ()
{
	int ls = 0;
	HANDLE hdev;
	SC_HANDLE hsc, hsv;
	char filepath[_MAX_PATH], *cp;
	BOOL res;

	hsc = hsv = NULL;
	res = 0;
	while (1) {
		ls++;

		if(ls >= 4)		/* Could not open, start or register giveio due to any reason. */
			return (-1);

		if(ls >= 3) {	/* Not registered. Register GIVEIO.SYS to the SCM database */
			if(SearchPath(NULL, "giveio.sys", NULL, sizeof(filepath), filepath, &cp) == 0) continue;
			if((hsc = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) != NULL) {
				if((hsv = CreateService(hsc,
										"giveio", "giveio",
										SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE,
										filepath,
										NULL, NULL, NULL, NULL, NULL)) != NULL) {
					CloseServiceHandle(hsv);
				} else {
					if((hsv = OpenService(hsc, "giveio", SERVICE_ALL_ACCESS)) != NULL) {
						DeleteService(hsv);
						CloseServiceHandle(hsv);
						hsv = NULL;
					}
				}
				CloseServiceHandle(hsc);
			}
			if((hsc == NULL) || (hsv == NULL)) continue;
		}

		if(ls >= 2) {	/* Not started. Start GIVEIO */
			if((hsc = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) != NULL) {
				if((hsv = OpenService(hsc, "giveio", SERVICE_ALL_ACCESS)) != NULL) {
					res = StartService(hsv, 0, NULL);
					CloseServiceHandle(hsv);
				}
				CloseServiceHandle(hsc);
			}
			if((hsc == NULL) || (hsv == NULL) || (res == FALSE)) continue;
		}

		/* Open GIVEIO to clear IOPM of this process */
		hdev = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL,
							  OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
		if(hdev == INVALID_HANDLE_VALUE) continue;
		CloseHandle(hdev);
		break;
	} /* while */

	return (0);

}
Beispiel #17
0
int win32_check_for_program (const char *prog)
{
    char tmp[MAXLEN];
    WIN32_FIND_DATA find_data;
    HANDLE hfind;
    int ret = 1;

    if (prog == NULL || *prog == '\0') {
	return 0;
    }

    hfind = FindFirstFile(prog, &find_data);
    if (hfind == INVALID_HANDLE_VALUE) {
	ret = 0;
    }
    FindClose(hfind);

    if (ret == 0) {
	char *p;

	ret = SearchPath(NULL, prog, NULL, MAXLEN, tmp, &p);
    }

    return ret != 0;
}
Beispiel #18
0
bool nglModule::Load()
{
  if (mHandle)
    return false;

  const nglChar* filename = mPath.GetPathName().GetChars();
  if (!filename || !*filename)
  {
    SetError(_T("module"), NGL_MODULE_EPATH);
    return false;
  }

  #define BUFFER_LEN 1023
  DWORD len;
  nglChar buffer[BUFFER_LEN+1];
  nglChar* slash = NULL;

  buffer[BUFFER_LEN] = 0;
  nglString fullpath;

  len = SearchPath (NULL, filename, NULL, BUFFER_LEN, buffer, &slash);
  if (slash)
    *slash = 0;
  fullpath = len > 0 ? buffer : _T("?");
  NGL_DEBUG( NGL_LOG(_T("module"), NGL_LOG_INFO, _T("loading '%s' from folder '%s'"), mPath.GetChars(), fullpath.GetChars()); )
Beispiel #19
0
gchar *
get_texmfcnf(void)
{
	char *env = getenv("TEXMFCNF");
	if (env)
		return g_strdup(env);

#ifdef G_OS_WIN32
	gchar *texmfcnf = NULL;
	TCHAR path[_MAX_PATH];

	if (SearchPath(NULL, "mktexpk", ".exe", _MAX_PATH, path, NULL))
	{
		gchar *sdir, *sdir_parent, *sdir_grandparent;
		const gchar *texmfcnf_fmt = "{%s,%s,%s}{,{/share,}/texmf{-local,}/web2c}";

		sdir = g_path_get_dirname(path);
		sdir_parent = g_path_get_dirname(sdir);
		sdir_grandparent = g_path_get_dirname(sdir_parent);

		texmfcnf = g_strdup_printf(texmfcnf_fmt,
			sdir, sdir_parent, sdir_grandparent);

		g_free(sdir);
		g_free(sdir_parent);
		g_free(sdir_grandparent);
	}
	return texmfcnf;
#else
	return NULL;
#endif
}
Beispiel #20
0
int GetFullPath(const char* FileName, const char* ext, char *Buffer, size_t BufferLength)
{
  int i, Result;
  char *p;
  char dir[PATH_MAX];
  
  for (i=0; i<3; i++)
  {
    switch(i)
    {
    case 0:
      getcwd(dir, sizeof(dir));
      break;
    case 1:
      if (!getenv("DOOMWADDIR"))
        continue;
      strcpy(dir, getenv("DOOMWADDIR"));
      break;
    case 2:
      strcpy(dir, I_DoomExeDir());
      break;
    }

    Result = SearchPath(dir,FileName,ext,BufferLength,Buffer,&p);
    if (Result)
      return Result;
  }

  return false;
}
Beispiel #21
0
void simVerifyTrust(const TCHAR *module, bool must_exist)
{
	TCHAR szModule[MAX_PATH];
	// For some reason VS2005 compiles this wrong, so you get a call to cvs::wide(NULL)
	// HMODULE hModule = GetModuleHandle(module?cvs::wide(module):NULL);
	HMODULE hModule;
	if(module)
		hModule = GetModuleHandle(module);
	else
		hModule = GetModuleHandle(NULL);

	if(!hModule && module)
	{
		if(!SearchPath(NULL,module,_T(".dll"),sizeof(szModule)/sizeof(szModule[0]),szModule,NULL))
		{
			if(must_exist)
			{
				printf("Unable to find %S  - aborting\n",module);
				exit(-1);
				abort();
			}
			return;
		}
	}
	else
		GetModuleFileName(hModule,szModule,sizeof(szModule));

	WINTRUST_FILE_INFO FileData = {sizeof(WINTRUST_FILE_INFO)};
	WINTRUST_DATA WinTrustData = {sizeof(WINTRUST_DATA)};
    FileData.pcwszFilePath = szModule;

    GUID WVTPolicyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2;

    WinTrustData.dwUIChoice = WTD_UI_NONE;
    WinTrustData.dwUnionChoice = WTD_CHOICE_FILE;
    WinTrustData.dwProvFlags = WTD_SAFER_FLAG | WTD_REVOCATION_CHECK_NONE | WTD_CACHE_ONLY_URL_RETRIEVAL;
    WinTrustData.pFile = &FileData;
	WinTrustData.fdwRevocationChecks = WTD_REVOKE_NONE;

    DWORD dwTrustErr = WinVerifyTrust(NULL, &WVTPolicyGUID, &WinTrustData);
	if(dwTrustErr)
	{
		if(dwTrustErr==TRUST_E_NOSIGNATURE)
		{
#ifdef COMMERCIAL_RELEASE
			printf("Trust verification failed for '%S' - image not signed\n",szModule);
#else
			printf("Trust verification failed for '%S' - community image file image not signed\n",szModule);
			return;
#endif
		}
		else if(dwTrustErr==TRUST_E_SUBJECT_NOT_TRUSTED)
			printf("Trust verification failed for '%S' - invalid signature\n",szModule);
		else
			printf("Trust verification failed for '%S' - error %08x\n",szModule,GetLastError());
		exit(-1);
		abort();
	}
}
Beispiel #22
0
//----------------------------------------------------------------------
//  
//  StartMyFaultDriver
//
// Loads and starts the driver.
//
//----------------------------------------------------------------------
LONG StartMyFaultDriver( HWND hDlg )
{
	char	driverPath[MAX_PATH];
	char	systemRoot[MAX_PATH];
	char	path[MAX_PATH];
	WIN32_FIND_DATA findData;
	HANDLE	findHandle;
	char	*file;
	DWORD	error;
	char	msgbuf[MAX_PATH*2];

	//
	// Load the myfault driver
	//
	GetCurrentDirectory( sizeof path, path );
	sprintf( path+lstrlen(path), "\\%s", SYS_FILE );

	findHandle = FindFirstFile( path, &findData );
	if( findHandle == INVALID_HANDLE_VALUE ) {

		if( !SearchPath( NULL, SYS_FILE, NULL, sizeof(path), path, &file ) ) {

			sprintf( msgbuf, "%s was not found.", SYS_FILE );
			return Abort( hDlg, msgbuf, GetLastError() );
		}

	} else FindClose( findHandle );

	if( !GetEnvironmentVariable( "SYSTEMROOT", systemRoot, sizeof(systemRoot))) {

		strcpy( msgbuf, "Could not resolve SYSTEMROOT environment variable" );
		return Abort( hDlg, msgbuf, GetLastError() );
	}
	sprintf( driverPath, "%s\\system32\\drivers\\myfault.sys", systemRoot );
	SetFileAttributes( driverPath, FILE_ATTRIBUTE_NORMAL );
	CopyFile( path, driverPath, FALSE );
	if( !LoadDeviceDriver( SYS_NAME, driverPath, &SysHandle, &error )) {

		if( !CopyFile( path, driverPath, FALSE )) {

			sprintf( msgbuf, "Unable to copy %s to %s\n\n"
				"Make sure that %s is in the current directory.", 
				SYS_NAME, driverPath, SYS_FILE );
			return Abort( hDlg, msgbuf, GetLastError() );
		}
		SetFileAttributes( driverPath, FILE_ATTRIBUTE_NORMAL );
		if( !LoadDeviceDriver( SYS_NAME, driverPath, &SysHandle, &error ) )  {

			UnloadDeviceDriver( SYS_NAME );
			if( !LoadDeviceDriver( SYS_NAME, driverPath, &SysHandle, &error ) )  {

				sprintf( msgbuf, "Error loading %s:", path );
				DeleteFile( driverPath );
				return Abort( hDlg, msgbuf, error );
			}
		}
	}
	return TRUE;
}
Beispiel #23
0
int 
CheckIfFileExists(const char *filepath, const char *filename)
{
	char buf[300];
	LPTSTR b;

	return SearchPath(filepath, filename, NULL, sizeof(buf), buf, &b) > 0;
}
Beispiel #24
0
void win_usr_config_set(char usr_config[PATH_MAX])
{
    usr_config[0] = 0;

    /* Use Windows API call to search for the Windows default user config file. */
    SearchPath(NULL, "avrdude.rc", NULL, PATH_MAX, usr_config, &filename);
    return;
}
Beispiel #25
0
void win_sys_config_set(char sys_config[PATH_MAX])
{
    sys_config[0] = 0;

    /* Use Windows API call to search for the Windows default system config file.*/
    SearchPath(NULL, "avrdude.conf", NULL, PATH_MAX, sys_config, &filename);
    return;
}
DWORD
selectProcessFlag(JNIEnv *env, jstring cmd0)
{
    DWORD newFlag = 0;
    char *exe = (char *)JNU_GetStringPlatformChars(env, cmd0, 0);
    if (exe != NULL) {
        char buf[MAX_PATH];
        char *name;
        DWORD len;
        exe = extractExecutablePath(env, exe);
        if (exe != NULL) {
            /* We are here for Win9x/Me, so the [/] is not the path sep */
            char *p = strrchr(exe, '\\');
            if (p == NULL) {
                len = SearchPath(NULL, exe, EXE_EXT, MAX_PATH, buf, &name);
            } else {
                *p = 0;
                len = SearchPath(exe, p + 1, EXE_EXT, MAX_PATH, buf, &name);
            }
        }

        if (len > 0 && len < MAX_PATH) {
            /* Here the [buf] path is valid and null terminated */
            int fd = _open(buf, _O_RDONLY);
            if (fd != -1) {
                unsigned char buffer[2];
                if (_read(fd, buffer, 2) == 2
                    && buffer[0] == 'M' && buffer[1] == 'Z'
                    && _lseek(fd, 60L, SEEK_SET) == 60L
                    && _read(fd, buffer, 2) == 2)
                {
                    long headerLoc = (long)buffer[1] << 8 | (long)buffer[0];
                    if (_lseek(fd, headerLoc, SEEK_SET) == headerLoc
                        && _read(fd, buffer, 2) == 2
                        && buffer[0] == 'P' && buffer[1] == 'E')
                    {
                        newFlag = DETACHED_PROCESS;
                    }
                }
                _close(fd);
            }
        }
        JNU_ReleaseStringPlatformChars(env, cmd0, exe);
    }
    return newFlag;
}
Beispiel #27
0
void UpdateMPICHd(char *pszFileName)
{
    int error;
    char pszStr[4096];
    char *filename = NULL, *name_part;
    DWORD len;

    len = SearchPath(NULL, "mpichd.dll", NULL, 0, filename, &name_part);

    if (len == 0)
    {
	if (GetWindowsDirectory(pszStr, 4096))
	{
	    strcat(pszStr, "\\system32\\mpichd.dll");
	    if (!MoveFileEx(pszFileName, pszStr, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING))
	    {
		error = GetLastError();
		Translate_Error(error, pszStr);
		err_printf("Unable to move '%s' to '%s'\nError: %s\n", pszFileName, filename, pszStr);
		return;
	    }
	}
	err_printf("unable to find mpichd.dll\n");
	return;
    }

    filename = new char[len*2+2];
    len = SearchPath(NULL, "mpichd.dll", NULL, len*2, filename, &name_part);
    if (len == 0)
    {
	delete filename;
	err_printf("unable to find mpichd.dll\n");
	return;
    }

    if (!MoveFileEx(pszFileName, filename, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING))
    {
	error = GetLastError();
	Translate_Error(error, pszStr);
	err_printf("Unable to move '%s' to '%s'\nError: %s\n", pszFileName, filename, pszStr);
	delete filename;
	return;
    }

    delete filename;
}
Beispiel #28
0
/*
 * This function tries to find a full path to putty.exe by
 * checking, in the order to follow:
 * 1. The directory from which plaunch was started.
 * 2. The current directory.
 * 3. The system directory (usually C:\WINNT\system32 for NT/2k
 *    and C:\WINDOWS\system32 for 95/98/Me/XP).
 * 4. The 16-bit system directory, which is C:\WIN(NT|DOWS)\system.
 * 5. The Windows directory, C:\WIN(NT|DOWS).
 * 6. The directories listed in the PATH environment variable.
 * 7. Well-known directories like C:\Program Files\PuTTY or
 *    C:\Program Files (x86)\TuTTY or a combination.
 * If search was unsuccessful, it tries the same steps for 
 * puttytel.exe. If this search is also unsuccessful, it simply 
 * returns NULL and relies on the user to set the correct path 
 * in the options dialog.
 * UPDATE: now this function first tries to find tutty.exe or
 * tuttytel.exe, then putty.exe or puttytel.exe.
 */
unsigned int get_putty_path(char *buf, unsigned int bufsize)
{
    char *exe[4] = {"tutty.exe", "tuttytel.exe", "putty.exe", "puttytel.exe"};
    int i;

    for (i = 0; i < 4; i++) {
	if (SearchPath(NULL, exe[i], NULL, bufsize, buf, NULL) ||
	    SearchPath("C:\\Program Files (x86)\\PuTTY;"
	    	       "C:\\Program Files (x86)\\TuTTY;"
		       "C:\\Program Files\\PuTTY;"
		       "C:\\Program Files\\TuTTY", 
		       exe[i], NULL, bufsize, buf, NULL))
	    return TRUE;
    };

    return FALSE;
};
Beispiel #29
0
void driver::load(const std::wstring &name) {
	wchar_t path[MAX_PATH + 1], *pathend;

	DWORD ret = SearchPath(NULL, name.c_str(), L".sys", MAX_PATH, path, &pathend);
	if(!ret) throw win32_error("SearchPath");

	load(name, path);
}
Beispiel #30
0
bool FileSearchInDir(LPCWSTR asFilePath, CEStr& rsFound)
{
	// Possibilities
	// a) asFilePath does not contain path, only: "far"
	// b) asFilePath contains path, but without extension: "C:\\Program Files\\Far\\Far"

	LPCWSTR pszSearchFile = asFilePath;
	LPCWSTR pszSlash = wcsrchr(asFilePath, L'\\');
	if (pszSlash)
	{
		if ((pszSlash - asFilePath) >= MAX_PATH)
		{
			// No need to continue, this is invalid path to executable
			return false;
		}

		// C:\Far\Far.exe /w /pC:\Far\Plugins\ConEmu;C:\Far\Plugins.My
		if (!IsFilePath(asFilePath, false))
		{
			return false;
		}

		// Do not allow '/' here
		LPCWSTR pszFwd = wcschr(asFilePath, L'/');
		if (pszFwd != NULL)
		{
			return false;
		}
	}

	wchar_t* pszSearchPath = NULL;
	if (pszSlash)
	{
		if ((pszSearchPath = lstrdup(asFilePath)) != NULL)
		{
			pszSearchFile = pszSlash + 1;
			pszSearchPath[pszSearchFile - asFilePath] = 0;
		}
	}

	// Попытаемся найти "по путям" (%PATH%)
	wchar_t *pszFilePart;
	wchar_t szFind[MAX_PATH+1];
	LPCWSTR pszExt = PointToExt(asFilePath);

	DWORD nLen = SearchPath(pszSearchPath, pszSearchFile, pszExt ? NULL : L".exe", countof(szFind), szFind, &pszFilePart);

	SafeFree(pszSearchPath);

	if (nLen && (nLen < countof(szFind)) && FileExists(szFind))
	{
		// asFilePath will be invalid after .Set
		rsFound.Set(szFind);
		return true;
	}

	return false;
}