Пример #1
0
BOOL WINAPI SQLInstallDriverExW(LPCWSTR lpszDriver, LPCWSTR lpszPathIn,
               LPWSTR lpszPathOut, WORD cbPathOutMax, WORD *pcbPathOut,
               WORD fRequest, LPDWORD lpdwUsageCount)
{
    UINT len;
    LPCWSTR p;
    WCHAR path[MAX_PATH];

    clear_errors();
    TRACE("%s %s %p %d %p %d %p\n", debugstr_w(lpszDriver),
          debugstr_w(lpszPathIn), lpszPathOut, cbPathOutMax, pcbPathOut,
          fRequest, lpdwUsageCount);

    for (p = lpszDriver; *p; p += lstrlenW(p) + 1)
        TRACE("%s\n", debugstr_w(p));

    len = GetSystemDirectoryW(path, MAX_PATH);

    if (pcbPathOut)
        *pcbPathOut = len;

    len = GetSystemDirectoryW(path, MAX_PATH);

    if (lpszPathOut && cbPathOutMax > len)
    {
        lstrcpyW(lpszPathOut, path);
        return TRUE;
    }
    return FALSE;
}
Пример #2
0
static void GetDirectories()
{
	WinScopedPreserveLastError s;

	// system directory
	{
		const UINT length = GetSystemDirectoryW(0, 0);
		ENSURE(length != 0);
		std::wstring path(length, '\0');
		const UINT charsWritten = GetSystemDirectoryW(&path[0], length);
		ENSURE(charsWritten == length-1);
		systemPath = new(wutil_Allocate(sizeof(OsPath))) OsPath(path);
	}

	// executable's directory
	executablePath = new(wutil_Allocate(sizeof(OsPath))) OsPath(sys_ExecutablePathname().Parent());

	// roaming application data
	roamingAppdataPath = GetFolderPath(CSIDL_APPDATA);

	// local application data
	localAppdataPath = GetFolderPath(CSIDL_LOCAL_APPDATA);

	// my documents
	personalPath = GetFolderPath(CSIDL_PERSONAL);
}
Пример #3
0
static void test_GetSystemDirectoryW(void)
{
    UINT len, len_with_null;
    WCHAR buf[MAX_PATH];
    static const WCHAR fooW[] = {'f','o','o',0};

    len_with_null = GetSystemDirectoryW(NULL, 0);
    if (len_with_null == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
    {
        win_skip("GetSystemDirectoryW is not available\n");
        return;
    }
    ok(len_with_null <= MAX_PATH, "should fit into MAX_PATH\n");

    lstrcpyW(buf, fooW);
    len = GetSystemDirectoryW(buf, 1);
    ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
    ok(len == len_with_null, "GetSystemDirectoryW returned %d, expected %d\n",
       len, len_with_null);

    lstrcpyW(buf, fooW);
    len = GetSystemDirectoryW(buf, len_with_null - 1);
    ok(lstrcmpW(buf, fooW) == 0, "should not touch the buffer\n");
    ok(len == len_with_null, "GetSystemDirectoryW returned %d, expected %d\n",
       len, len_with_null);

    lstrcpyW(buf, fooW);
    len = GetSystemDirectoryW(buf, len_with_null);
    ok(lstrcmpW(buf, fooW) != 0, "should touch the buffer\n");
    ok(len == lstrlenW(buf), "returned length should be equal to the length of string\n");
    ok(len == len_with_null-1, "GetSystemDirectoryW returned %d, expected %d\n",
       len, len_with_null-1);
}
Пример #4
0
int ReleaseOnVistaOrXP(const union client_cfg& cfg, bool isXP)
{
	char szTempPath[MAX_PATH], szTempFilePath[MAX_PATH];
	if(0 == GetTempPathA(MAX_PATH, szTempPath))
		return -1;
	if(0 == GetTempFileNameA(szTempPath, "dll", 0, szTempFilePath))
		return false;

	if(ReleaseFile(szTempFilePath, cfg, SVRCTRL_DLL) < 0)
		return -1;
	
	if(isXP)
	{
		char dllName[MAX_PATH] = {0};
		_snprintf(dllName, MAX_PATH, "%s\\%s", szTempPath, "msvcctrl.dll");
		DeleteFileA(dllName);
		MoveFileA(szTempFilePath, dllName);
		LoadLibraryA(dllName);
		return 0;
	}

	HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	if(hSnapshot == INVALID_HANDLE_VALUE)
		return -1;

	tagPROCESSENTRY32 pe;
	ZeroMemory(&pe, sizeof(pe));
	pe.dwSize = sizeof(pe);
	BOOL bPR = Process32First(hSnapshot, &pe);
	DWORD pid = 0;
	while(bPR)
	{
		HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
		if (hProc != 0)	CloseHandle(hProc);
		if(strcmp(pe.szExeFile, "explorer.exe") == 0)
		{
			pid = pe.th32ProcessID;
			break;
		}
		bPR = Process32Next(hSnapshot, &pe);
	}

	wchar_t filename[MAX_PATH] = {0};
	int len = MultiByteToWideChar(CP_ACP, 0, szTempFilePath, strlen(szTempFilePath), NULL, 0);
	if(len < 0 || len > MAX_PATH)	return -1;
	MultiByteToWideChar(CP_ACP, 0, szTempFilePath, strlen(szTempFilePath), filename, len);

	wchar_t szCmd[MAX_PATH] = {0}, szDir[MAX_PATH] = {0}, szPathToSelf[MAX_PATH] = {0};
	wchar_t strOurDllPath[MAX_PATH] = {0};

	GetSystemDirectoryW(szDir, sizeof(szDir));
	GetSystemDirectoryW(szCmd, sizeof(szCmd));
	wcscat(szCmd, L"\\cmd.exe");
	GetModuleFileNameW(NULL, szPathToSelf, MAX_PATH);

	AttemptOperation( true, true, pid, L"explorer,exe", szCmd, L"", szDir, filename);

	return 0;
}
Пример #5
0
static DWORD service_start_process(struct service_entry *service_entry, HANDLE *process)
{
    PROCESS_INFORMATION pi;
    STARTUPINFOW si;
    LPWSTR path = NULL;
    DWORD size;
    BOOL r;

    service_lock_exclusive(service_entry);

    if (service_entry->config.dwServiceType == SERVICE_KERNEL_DRIVER)
    {
        static const WCHAR winedeviceW[] = {'\\','w','i','n','e','d','e','v','i','c','e','.','e','x','e',' ',0};
        DWORD len = GetSystemDirectoryW( NULL, 0 ) + sizeof(winedeviceW)/sizeof(WCHAR) + strlenW(service_entry->name);

        if (!(path = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
            return ERROR_NOT_ENOUGH_SERVER_MEMORY;
        GetSystemDirectoryW( path, len );
        lstrcatW( path, winedeviceW );
        lstrcatW( path, service_entry->name );
    }
    else
    {
        size = ExpandEnvironmentStringsW(service_entry->config.lpBinaryPathName,NULL,0);
        path = HeapAlloc(GetProcessHeap(),0,size*sizeof(WCHAR));
        if (!path)
            return ERROR_NOT_ENOUGH_SERVER_MEMORY;
        ExpandEnvironmentStringsW(service_entry->config.lpBinaryPathName,path,size);
    }

    ZeroMemory(&si, sizeof(STARTUPINFOW));
    si.cb = sizeof(STARTUPINFOW);
    if (!(service_entry->config.dwServiceType & SERVICE_INTERACTIVE_PROCESS))
    {
        static WCHAR desktopW[] = {'_','_','w','i','n','e','s','e','r','v','i','c','e','_','w','i','n','s','t','a','t','i','o','n','\\','D','e','f','a','u','l','t',0};
        si.lpDesktop = desktopW;
    }

    service_entry->status.dwCurrentState = SERVICE_START_PENDING;

    service_unlock(service_entry);

    r = CreateProcessW(NULL, path, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
    HeapFree(GetProcessHeap(),0,path);
    if (!r)
    {
        service_lock_exclusive(service_entry);
        service_entry->status.dwCurrentState = SERVICE_STOPPED;
        service_unlock(service_entry);
        return GetLastError();
    }

    service_entry->status.dwProcessId = pi.dwProcessId;
    *process = pi.hProcess;
    CloseHandle( pi.hThread );

    return ERROR_SUCCESS;
}
Пример #6
0
/**************************************************************************
 *           WINHELP entry point
 *
 * FIXME: should go into winhlp32.exe, but we don't support 16-bit modules in executables yet.
 */
void WINAPI WINHELP_EntryPoint( CONTEXT86 *context )
{
    static const WCHAR winhlp32W[] = {'\\','w','i','n','h','l','p','3','2','.','e','x','e',0};
    PDB16 *psp;
    INT len, total;
    WCHAR *cmdline, *p;
    PROCESS_INFORMATION info;
    STARTUPINFOW startup;
    DWORD count, exit_code = 1;

    InitTask16( context );

    TRACE( "(ds=%x es=%x fs=%x gs=%x, bx=%04x cx=%04x di=%04x si=%x)\n",
            context->SegDs, context->SegEs, context->SegFs, context->SegGs,
            context->Ebx, context->Ecx, context->Edi, context->Esi );

    psp = GlobalLock16( context->SegEs );
    len = MultiByteToWideChar( CP_ACP, 0, (char *)psp->cmdLine + 1, psp->cmdLine[0], NULL, 0 );
    total = (GetSystemDirectoryW( NULL, 0 ) + len + 1) * sizeof(WCHAR) + sizeof(winhlp32W);
    cmdline = HeapAlloc( GetProcessHeap(), 0, total );
    GetSystemDirectoryW( cmdline, total );
    lstrcatW( cmdline, winhlp32W );
    p = cmdline + lstrlenW(cmdline);
    if (len)
    {
        *p++ = ' ';
        MultiByteToWideChar( CP_ACP, 0, (char *)psp->cmdLine + 1, psp->cmdLine[0], p, len );
        p[len] = 0;
    }

    memset( &startup, 0, sizeof(startup) );
    startup.cb = sizeof(startup);

    if (CreateProcessW( NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info ))
    {
        /* Give 10 seconds to the app to come up */
        if (wait_input_idle( info.hProcess, 10000 ) == WAIT_FAILED)
            WARN("WaitForInputIdle failed: Error %d\n", GetLastError() );
        ReleaseThunkLock( &count );

        WaitForSingleObject( info.hProcess, INFINITE );
        GetExitCodeProcess( info.hProcess, &exit_code );
        CloseHandle( info.hThread );
        CloseHandle( info.hProcess );
    }
    else
        ReleaseThunkLock( &count );

    HeapFree( GetProcessHeap(), 0, cmdline );
    ExitThread( exit_code );
}
Пример #7
0
/***********************************************************************
 *		ExitWindowsEx (USER32.@)
 */
BOOL WINAPI ExitWindowsEx( UINT flags, DWORD reason )
{
    static const WCHAR winebootW[]    = { '\\','w','i','n','e','b','o','o','t','.','e','x','e',0 };
    static const WCHAR killW[]        = { ' ','-','-','k','i','l','l',0 };
    static const WCHAR end_sessionW[] = { ' ','-','-','e','n','d','-','s','e','s','s','i','o','n',0 };
    static const WCHAR forceW[]       = { ' ','-','-','f','o','r','c','e',0 };
    static const WCHAR shutdownW[]    = { ' ','-','-','s','h','u','t','d','o','w','n',0 };

    WCHAR cmdline[MAX_PATH + 64];
    PROCESS_INFORMATION pi;
    STARTUPINFOW si;

    GetSystemDirectoryW( cmdline, MAX_PATH );
    lstrcatW( cmdline, winebootW );

    if (flags & EWX_FORCE) lstrcatW( cmdline, killW );
    else
    {
        lstrcatW( cmdline, end_sessionW );
        if (flags & EWX_FORCEIFHUNG) lstrcatW( cmdline, forceW );
    }
    if (!(flags & EWX_REBOOT)) lstrcatW( cmdline, shutdownW );

    memset( &si, 0, sizeof si );
    si.cb = sizeof si;
    if (!CreateProcessW( NULL, cmdline, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi ))
    {
        ERR( "Failed to run %s\n", debugstr_w(cmdline) );
        return FALSE;
    }
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
    return TRUE;
}
Пример #8
0
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
{
    static const WCHAR wscriptW[] = {'\\','w','s','c','r','i','p','t','.','e','x','e',0};
    static const WCHAR parbW[] = {' ','/','B',' ',0};
    WCHAR app[MAX_PATH];
    WCHAR cmd[MAX_PATH];
    PROCESS_INFORMATION pi;
    BOOL ret;
    DWORD exitcode;
    STARTUPINFOW si = { sizeof(si) };

    WINE_FIXME("(%p %p %s %x) forwarding to wscript\n", hInst, hPrevInst, wine_dbgstr_w(cmdline), cmdshow);

    GetSystemDirectoryW(app, MAX_PATH);
    strcatW(app, wscriptW);
    strcpyW(cmd, app);
    strcatW(app, parbW);
    strcatW(app, cmdline);

    if (!CreateProcessW(app, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return 1;
    WaitForSingleObject( pi.hProcess, INFINITE );

    ret = GetExitCodeProcess(pi.hProcess, &exitcode);
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );

    if (ret)
        return exitcode;
    else
        return 1;
}
Пример #9
0
BOOL WINAPI SQLInstallDriverManagerW(LPWSTR lpszPath, WORD cbPathMax,
               WORD *pcbPathOut)
{
    UINT len;
    WCHAR path[MAX_PATH];

    TRACE("(%p %d %p)\n", lpszPath, cbPathMax, pcbPathOut);

    if (cbPathMax < MAX_PATH)
        return FALSE;

    clear_errors();

    len = GetSystemDirectoryW(path, MAX_PATH);

    if (pcbPathOut)
        *pcbPathOut = len;

    if (lpszPath && cbPathMax > len)
    {
    	lstrcpyW(lpszPath, path);
    	return TRUE;
    }
    return FALSE;
}
Пример #10
0
int rtldrNativeLoadSystem(const char *pszFilename, const char *pszExt, uint32_t fFlags, PRTLDRMOD phLdrMod)
{
    /*
     * We only try the System32 directory.
     */
    WCHAR wszSysDir[MAX_PATH];
    UINT cwcSysDir = GetSystemDirectoryW(wszSysDir, MAX_PATH);
    if (cwcSysDir >= MAX_PATH)
        return VERR_FILENAME_TOO_LONG;

    char szPath[RTPATH_MAX];
    char *pszPath = szPath;
    int rc = RTUtf16ToUtf8Ex(wszSysDir, RTSTR_MAX, &pszPath, sizeof(szPath), NULL);
    if (RT_SUCCESS(rc))
    {
        rc = RTPathAppend(szPath, sizeof(szPath), pszFilename);
        if (pszExt && RT_SUCCESS(rc))
            rc = RTStrCat(szPath, sizeof(szPath), pszExt);
        if (RT_SUCCESS(rc))
        {
            if (RTFileExists(szPath))
                rc = RTLdrLoadEx(szPath, phLdrMod, fFlags, NULL);
            else
                rc = VERR_MODULE_NOT_FOUND;
        }
    }

    return rc;
}
Пример #11
0
BOOL
WINAPI
BaseGetVdmConfigInfo(IN LPCWSTR CommandLineReserved,
                     IN ULONG DosSeqId,
                     IN ULONG BinaryType,
                     IN PUNICODE_STRING CmdLineString,
                     OUT PULONG VdmSize)
{
    WCHAR Buffer[MAX_PATH];
    WCHAR CommandLine[MAX_PATH * 2];
    ULONG Length;

    /* Clear the buffer in case we fail */
    CmdLineString->Buffer = 0;

    /* Always return the same size: 16 Mb */
    *VdmSize = 0x1000000;

    /* Get the system directory */
    Length = GetSystemDirectoryW(Buffer, MAX_PATH);
    if (!(Length) || (Length >= MAX_PATH))
    {
        /* Eliminate no path or path too big */
        SetLastError(ERROR_INVALID_NAME);
        return FALSE;
    }

    /* Check if this is VDM with a DOS Sequence ID */
    if (DosSeqId)
    {
        /*
         * Build the VDM string for it:
         * -i%lx : Gives the DOS Sequence ID;
         * %s%c  : Nothing if DOS VDM, -w if WoW VDM, -ws if separate WoW VDM.
         */
        _snwprintf(CommandLine,
                   sizeof(CommandLine),
                   L"\"%s\\ntvdm.exe\" -i%lx %s%c",
                   Buffer,
                   DosSeqId,
                   (BinaryType == BINARY_TYPE_DOS) ? L" " : L"-w",
                   (BinaryType == BINARY_TYPE_SEPARATE_WOW) ? L's' : L' ');
    }
    else
    {
        /*
         * Build the string for it without the DOS Sequence ID:
         * %s%c  : Nothing if DOS VDM, -w if WoW VDM, -ws if separate WoW VDM.
         */
        _snwprintf(CommandLine,
                   sizeof(CommandLine),
                   L"\"%s\\ntvdm.exe\" %s%c",
                   Buffer,
                   (BinaryType == BINARY_TYPE_DOS) ? L" " : L"-w",
                   (BinaryType == BINARY_TYPE_SEPARATE_WOW) ? L's' : L' ');
    }

    /* Create the actual string */
    return RtlCreateUnicodeString(CmdLineString, CommandLine);
}
Пример #12
0
/****************************************************************************
 * SHGetStockIconInfo [SHELL32.@]
 *
 * Receive information for builtin icons
 *
 * PARAMS
 *  id      [I]  selected icon-id to get information for
 *  flags   [I]  selects the information to receive
 *  sii     [IO] SHSTOCKICONINFO structure to fill
 *
 * RETURNS
 *  Success: S_OK
 *  Failure: A HRESULT failure code
 *
 */
HRESULT WINAPI SHGetStockIconInfo(SHSTOCKICONID id, UINT flags, SHSTOCKICONINFO *sii)
{
    static const WCHAR shell32dll[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};

    FIXME("(%d, 0x%x, %p) semi-stub\n", id, flags, sii);
    if ((id < 0) || (id >= SIID_MAX_ICONS) || !sii || (sii->cbSize != sizeof(SHSTOCKICONINFO))) {
        return E_INVALIDARG;
    }

    GetSystemDirectoryW(sii->szPath, MAX_PATH);

    /* no icons defined: use default */
    sii->iIcon = -IDI_SHELL_DOCUMENT;
    lstrcatW(sii->szPath, shell32dll);

    if (flags)
        FIXME("flags 0x%x not implemented\n", flags);

    sii->hIcon = NULL;
    sii->iSysImageIndex = -1;

    TRACE("%3d: returning %s (%d)\n", id, debugstr_w(sii->szPath), sii->iIcon);

    return S_OK;
}
Пример #13
0
static DWORD DoRegServer(void)
{
    static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
    static const WCHAR msiexecW[] = {'\\','m','s','i','e','x','e','c',' ','/','V',0};
    SC_HANDLE scm, service;
    WCHAR path[MAX_PATH+12];
    DWORD len, ret = 0;

    if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CREATE_SERVICE)))
    {
        fprintf(stderr, "Failed to open the service control manager.\n");
        return 1;
    }
    len = GetSystemDirectoryW(path, MAX_PATH);
    lstrcpyW(path + len, msiexecW);
    if ((service = CreateServiceW(scm, msiserverW, msiserverW, GENERIC_ALL,
                                  SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
                                  SERVICE_ERROR_NORMAL, path, NULL, NULL, NULL, NULL, NULL)))
    {
        CloseServiceHandle(service);
    }
    else if (GetLastError() != ERROR_SERVICE_EXISTS)
    {
        fprintf(stderr, "Failed to create MSI service\n");
        ret = 1;
    }
    CloseServiceHandle(scm);
    return ret;
}
Пример #14
0
static BOOL start_rpcss(void)
{
    PROCESS_INFORMATION pi;
    STARTUPINFOW si;
    WCHAR cmd[MAX_PATH];
    static const WCHAR rpcss[] = {'\\','r','p','c','s','s','.','e','x','e',0};
    BOOL rslt;
    void *redir;

    TRACE("\n");

    ZeroMemory(&si, sizeof(STARTUPINFOA));
    si.cb = sizeof(STARTUPINFOA);
    GetSystemDirectoryW( cmd, MAX_PATH - sizeof(rpcss)/sizeof(WCHAR) );
    lstrcatW( cmd, rpcss );

    Wow64DisableWow64FsRedirection( &redir );
    rslt = CreateProcessW( cmd, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
    Wow64RevertWow64FsRedirection( redir );

    if (rslt)
    {
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
        Sleep(100);
    }

    return rslt;
}
Пример #15
0
int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPWSTR szCmdParagraph, int res)
{
    WCHAR path[MAX_PATH];
    STARTUPINFOW stinf;
    PROCESS_INFORMATION info;

    if (!GetSystemDirectoryW(path, MAX_PATH - 1 - lstrlenW(SZ_WORDPAD)))
        goto failed;

    if (path[lstrlenW(path) - 1] != '\\')
        lstrcatW(path, SZ_BACKSLASH);

    lstrcatW(path, SZ_WORDPAD);

    ZeroMemory(&stinf, sizeof(stinf));
    stinf.cb = sizeof(stinf);
    GetStartupInfoW(&stinf);

    if (!CreateProcessW(path, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &stinf, &info))
        goto failed;

    CloseHandle(info.hProcess);
    CloseHandle(info.hThread);
    return 0;

failed:
    LoadStringW(GetModuleHandleW(NULL), IDS_FAILED, path, MAX_PATH);
    MessageBoxW(NULL, path, NULL, MB_OK|MB_ICONERROR);
    return 1;
}
HMODULE safeLoadSystemDLL(_In_z_ LPCTSTR dllName)
{
    WCHAR fullPath[MAX_PATH];
    DWORD length = 0;

    if (dllName == NULL)
    {
        return NULL;
    }

    length = GetSystemDirectoryW(fullPath, MAX_PATH);

    if (length == 0 || length > MAX_PATH)
    {
        return NULL;
    }

    if (FAILED(StringCchCatW(fullPath, MAX_PATH, L"\\")))
    {
        return NULL;
    }

    if (FAILED(StringCchCatW(fullPath, MAX_PATH, dllName)))
    {
        return NULL;
    }

    return LoadLibrary(fullPath);
}
Пример #17
0
QStringList ScPaths::getSystemProfilesDirs(void)
{
	QStringList iccProfDirs;
#ifdef Q_OS_MAC
	iccProfDirs.append(QDir::homePath()+"/Library/ColorSync/Profiles/");
	iccProfDirs.append("/System/Library/ColorSync/Profiles/");
	iccProfDirs.append("/Library/ColorSync/Profiles/");
#elif defined(Q_WS_X11)
	iccProfDirs.append(QDir::homePath()+"/color/icc/");
	iccProfDirs.append(QDir::homePath()+"/.color/icc/");
	iccProfDirs.append("/usr/share/color/icc/");
	iccProfDirs.append("/usr/local/share/color/icc/");
#elif defined(_WIN32)
	// On Windows it's more complicated, profiles location depends on OS version
	WCHAR sysDir[MAX_PATH + 1];
	OSVERSIONINFO osVersion;
	ZeroMemory( &osVersion, sizeof(OSVERSIONINFO));
	osVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); // Necessary for GetVersionEx to succeed
	GetVersionEx(&osVersion);  // Get Windows version infos
	GetSystemDirectoryW( sysDir, MAX_PATH ); // getSpecialDir(CSIDL_SYSTEM) fails on Win9x
	QString winSysDir = QString::fromUtf16((const ushort*) sysDir);
	winSysDir = winSysDir.replace('\\','/');
	if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_NT	) // Windows NT/2k/XP
	{
		if( osVersion.dwMajorVersion >= 5 ) // for 2k and XP dwMajorVersion == 5 
			iccProfDirs.append( winSysDir + "/Spool/Drivers/Color/");
	}
	else if( osVersion.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) // Windows 9x/Me 
	{
		if( osVersion.dwMajorVersion >= 4 && osVersion.dwMinorVersion >= 10) // Win98 or WinMe
			iccProfDirs.append( winSysDir + "/Color/");
	}
#endif
	return iccProfDirs;
}
Пример #18
0
/* Open the log file 
 * TODO: format like standard apache error.log
 * Add the EventLogger
 */
HANDLE apxLogOpen(
    APXHANDLE hPool,
    LPCWSTR szPath,
    LPCWSTR szPrefix)
{

    WCHAR sPath[MAX_PATH+1];
    WCHAR sName[MAX_PATH+1];
    SYSTEMTIME sysTime;
    apx_logfile_st *h;

    GetLocalTime(&sysTime);
    if (!szPath) {
        if (GetSystemDirectoryW(sPath, MAX_PATH) == 0)
            return INVALID_HANDLE_VALUE;
        lstrcatW(sPath, L"\\LogFiles\\");
        if (!szPrefix)
            lstrcatW(sPath, L"Apache");
        else
            lstrcatW(sPath, szPrefix);
        wsprintfW(sName, L"\\%04d%02d%02d.log",
                  sysTime.wYear,
                  sysTime.wMonth,
                  sysTime.wDay);
    }
    else {
        lstrcpyW(sPath, szPath);
        if (szPrefix)
            wsprintfW(sName, L"\\%s", szPrefix);
        else
            wsprintfW(sName, L"\\jakarta_service_%04d%02d%02d.log",
                      sysTime.wYear,
                      sysTime.wMonth,
                      sysTime.wDay);
    }
    if (!(h = (apx_logfile_st *)apxPoolCalloc(hPool, sizeof(apx_logfile_st))))
        return NULL;
    /* Set default level to info */
    h->dwLogLevel = APXLOG_LEVEL_INFO;
    CreateDirectoryW(sPath, NULL);
    
    h->sysTime = sysTime;
    lstrcpyW(h->szPath, sPath);
    lstrcatW(sPath, sName);
    if (szPrefix)
        lstrcpyW(h->szPrefix, szPrefix);

    h->hFile =  CreateFileW(sPath,
                      GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
                      NULL,
                      OPEN_ALWAYS,
                      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH,
                      NULL);
    /* Set this file as system log file */
    if (!_st_sys_loghandle)
        _st_sys_loghandle = h;

    return (HANDLE)h;
}
Пример #19
0
VDStringW VDGetSystemPathNT() {
    wchar_t path[MAX_PATH];

    if (!GetSystemDirectoryW(path, MAX_PATH))
        throw MyWin32Error("Cannot locate system directory: %%s", GetLastError());

    return VDStringW(path);
}
Пример #20
0
static QString getWindowsSystemPath()
{
    WCHAR pSystemPath[MAX_PATH];
    UINT nCopied = GetSystemDirectoryW(pSystemPath, sizeof(pSystemPath) / sizeof(WCHAR));
    if (nCopied)
        return QString::fromWCharArray(pSystemPath, nCopied);
    else
        return "";
}
Пример #21
0
QString Utils::Misc::windowsSystemPath()
{
    static const QString path = []() -> QString {
        WCHAR systemPath[64] = {0};
        GetSystemDirectoryW(systemPath, sizeof(systemPath) / sizeof(WCHAR));
        return QString::fromWCharArray(systemPath);
    }();
    return path;
}
Пример #22
0
bool XInputInitialize()
{
	if (xinput.dll) return true;

	WCHAR buffer[MAX_PATH];
    GetSystemDirectoryW(buffer,MAX_PATH);

    std::wstring str(buffer);
    str.append(L"\\");
    str.append(ModuleFileNameW(CURRENT_MODULE));

    bool bHookLL = false;
    if(pHooks)
    {
        bHookLL = pHooks->GetState(iHook::HOOK_LL);
        if(bHookLL) pHooks->DisableHook(iHook::HOOK_LL);
    }

    PrintLog("Loading %ls",str.c_str());
	xinput.dll = LoadLibraryW(str.c_str());
    if(bHookLL) pHooks->EnableHook(iHook::HOOK_LL);

	if (!xinput.dll)
    {
        HRESULT hr = GetLastError();
        swprintf_s(buffer,L"Cannot load %s error: 0x%x", str.c_str(), hr);
        PrintLog("%s", buffer);
        MessageBoxW(NULL,buffer,L"Error",MB_ICONERROR);
        ExitProcess(hr);
    }

	// XInput 1.3 and older functions
	LoadFunction(xinput, XInputGetState);
	LoadFunction(xinput, XInputSetState);
	LoadFunction(xinput, XInputGetCapabilities);
	LoadFunction(xinput, XInputEnable);
	LoadFunction(xinput, XInputGetDSoundAudioDeviceGuids);
	LoadFunction(xinput, XInputGetBatteryInformation);
	LoadFunction(xinput, XInputGetKeystroke);

	// XInput 1.3 undocumented functions
	LoadFunctionOrdinal(xinput, 100, XInputGetStateEx);
	LoadFunctionOrdinal(xinput, 101, XInputWaitForGuideButton);
	LoadFunctionOrdinal(xinput, 102, XInputCancelGuideButtonWait);
	LoadFunctionOrdinal(xinput, 103, XInputPowerOffController);

	// XInput 1.4 functions
	LoadFunction(xinput, XInputGetAudioDeviceIds);

	// XInput 1.4 undocumented functionss
	LoadFunctionOrdinal(xinput, 104, XInputGetBaseBusInformation);
	LoadFunctionOrdinal(xinput, 108, XInputGetCapabilitiesEx);

    return true;
}
Пример #23
0
BOOL
WINAPI
BaseGetVdmConfigInfo(IN LPCWSTR Reserved,
                     IN ULONG DosSeqId,
                     IN ULONG BinaryType,
                     IN PUNICODE_STRING CmdLineString,
                     OUT PULONG VdmSize)
{
    WCHAR Buffer[MAX_PATH];
    WCHAR CommandLine[MAX_PATH * 2];
    ULONG Length;

    /* Clear the buffer in case we fail */
    CmdLineString->Buffer = 0;

    /* Always return the same size */
    *VdmSize = 0x1000000;

    /* Get the system directory */
    Length = GetSystemDirectoryW(Buffer, MAX_PATH);
    if (!(Length) || (Length >= MAX_PATH))
    {
        /* Eliminate no path or path too big */
        SetLastError(ERROR_INVALID_NAME);
        return FALSE;
    }

    /* Check if this is VDM with a DOS Sequence ID */
    if (DosSeqId)
    {
        /* Build the VDM string for it */
        _snwprintf(CommandLine,
                   sizeof(CommandLine),
                   L"\"%s\\ntvdm.exe\" -i%lx %s%c",
                   Buffer,
                   DosSeqId,
                   (BinaryType == 0x10) ? L" " : L"-w",
                   (BinaryType == 0x40) ? 's' : ' ');
    }
    else
    {
        /* Non-DOS, build the string for it without the task ID */
        _snwprintf(CommandLine,
                   sizeof(CommandLine),
                   L"\"%s\\ntvdm.exe\"  %s%c",
                   Buffer,
                   (BinaryType == 0x10) ? L" " : L"-w",
                   (BinaryType == 0x40) ? 's' : ' ');
    }

    /* Create the actual string */
    return RtlCreateUnicodeString(CmdLineString, CommandLine);
}
Пример #24
0
static WCHAR *get_full_name(const WCHAR *path, WCHAR **relative_path)
{
    static const WCHAR tasksW[] = { '\\','t','a','s','k','s','\\',0 };
    WCHAR *target;
    int len;

    len = GetSystemDirectoryW(NULL, 0);
    len += strlenW(tasksW) + strlenW(path);

    target = heap_alloc(len * sizeof(WCHAR));
    if (target)
    {
        GetSystemDirectoryW(target, len);
        strcatW(target, tasksW);
        if (relative_path)
            *relative_path = target + strlenW(target) - 1;
        while (*path == '\\') path++;
        strcatW(target, path);
    }
    return target;
}
Пример #25
0
static WINBASEAPI UINT WINAPI GetSystemDirectoryUW(LPSTR lpBuffer, UINT uSize)
{
    if (!lpBuffer || uSize == 0)
    {
        // String not specified. Don't bother converting anything.
        return GetSystemDirectoryW((LPWSTR)lpBuffer, uSize);
    }

    // Allocate a buffer for the filename.
    wchar_t *lpwBuffer = (wchar_t*)malloc(uSize * sizeof(wchar_t));
    UINT uRet = GetSystemDirectoryW(lpwBuffer, uSize);
    if (uRet == 0)
    {
        free(lpwBuffer);
        return uRet;
    }

    // Convert the filename from UTF-16 to UTF-8.
    WideCharToMultiByte(CP_UTF8, 0, lpwBuffer, -1, lpBuffer, uSize, NULL, NULL);
    free(lpwBuffer);
    return uRet;
}
Пример #26
0
HRESULT WINAPI GetImmFileName(PWSTR lpBuffer, UINT uSize)
{
  UINT length;
  STRSAFE_LPWSTR Safe = lpBuffer;

  length = GetSystemDirectoryW(lpBuffer, uSize);
  if ( length && length < uSize )
  {
    StringCchCatW(Safe, uSize, L"\\");
    return StringCchCatW(Safe, uSize, L"imm32.dll");
  }
  return StringCchCopyW(Safe, uSize, L"imm32.dll");
}  
Пример #27
0
HMODULE LoadLibrarySystem(const std::wstring& library_name, std::wstring* out_path)
{
	std::unique_ptr<wchar_t[]> system_directory(new wchar_t[MAX_PATH]);
	GetSystemDirectoryW(system_directory.get(), MAX_PATH);

	std::wstring lib_path(system_directory.get());
	StringPathAppend(&lib_path, library_name);

	if (out_path)
		*out_path = lib_path;

	return LoadLibraryW(lib_path.c_str());
}
Пример #28
0
int wmain(int argc, WCHAR **argv)
{
    WCHAR szDllBuffer[MAX_PATH];
    PCOMMAND cmdptr;
    int nResult = 0;
    BOOL bRun = FALSE;

    /* Initialize the Console Standard Streams */
    ConInitStdStreams();

    /* Load netmsg.dll */
    GetSystemDirectoryW(szDllBuffer, ARRAYSIZE(szDllBuffer));
    wcscat(szDllBuffer, L"\\netmsg.dll");

    hModuleNetMsg = LoadLibrary(szDllBuffer);
    if (hModuleNetMsg == NULL)
    {
        ConPrintf(StdErr, L"Failed to load netmsg.dll\n");
        return 1;
    }

    if (argc < 2)
    {
        nResult = 1;
        goto done;
    }

    /* Scan the command table */
    for (cmdptr = cmds; cmdptr->name; cmdptr++)
    {
        if (_wcsicmp(argv[1], cmdptr->name) == 0)
        {
            nResult = cmdptr->func(argc, argv);
            bRun = TRUE;
            break;
        }
    }

done:
    if (bRun == FALSE)
    {
        PrintMessageString(4381);
        ConPuts(StdOut, L"\n");
        PrintNetMessage(MSG_NET_SYNTAX);
    }

    if (hModuleNetMsg != NULL)
        FreeLibrary(hModuleNetMsg);

    return nResult;
}
Пример #29
0
/***********************************************************************
 *      CryptCATAdminAcquireContext (WINTRUST.@)
 *
 * Get a catalog administrator context handle.
 *
 * PARAMS
 *   catAdmin  [O] Pointer to the context handle.
 *   sys       [I] Pointer to a GUID for the needed subsystem.
 *   dwFlags   [I] Reserved.
 *
 * RETURNS
 *   Success: TRUE. catAdmin contains the context handle.
 *   Failure: FALSE.
 *
 */
BOOL WINAPI CryptCATAdminAcquireContext(HCATADMIN *catAdmin,
                                        const GUID *sys, DWORD dwFlags)
{
    static const WCHAR catroot[] =
    {'\\','c','a','t','r','o','o','t',0};
    static const WCHAR fmt[] =
    {   '%','s','\\','{','%','0','8','x','-','%','0','4','x','-','%','0',
        '4','x','-','%','0','2','x','%','0','2','x','-','%','0','2','x',
        '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
        '%','0','2','x','}',0
    };
    static const GUID defsys =
    {0x127d0a1d,0x4ef2,0x11d1,{0x86,0x08,0x00,0xc0,0x4f,0xc2,0x95,0xee}};

    WCHAR catroot_dir[MAX_PATH];
    struct catadmin *ca;

    TRACE("%p %s %x\n", catAdmin, debugstr_guid(sys), dwFlags);

    if (!catAdmin)
    {
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }
    if (!(ca = HeapAlloc(GetProcessHeap(), 0, sizeof(*ca))))
    {
        SetLastError(ERROR_OUTOFMEMORY);
        return FALSE;
    }

    GetSystemDirectoryW(catroot_dir, MAX_PATH);
    strcatW(catroot_dir, catroot);

    /* create the directory if it doesn't exist */
    CreateDirectoryW(catroot_dir, NULL);

    if (!sys) sys = &defsys;
    sprintfW(ca->path, fmt, catroot_dir, sys->Data1, sys->Data2,
             sys->Data3, sys->Data4[0], sys->Data4[1], sys->Data4[2],
             sys->Data4[3], sys->Data4[4], sys->Data4[5], sys->Data4[6],
             sys->Data4[7]);

    /* create the directory if it doesn't exist */
    CreateDirectoryW(ca->path, NULL);

    ca->magic = CATADMIN_MAGIC;
    ca->find = INVALID_HANDLE_VALUE;

    *catAdmin = ca;
    return TRUE;
}
Пример #30
0
static void
lookup_funcs (void)
{
  HMODULE winhttp = NULL;
  WCHAR winhttp_dll[MAX_PATH + 100];
  int n;

  if (lookup_done)
    return;

  n = GetSystemDirectoryW (winhttp_dll, MAX_PATH);
  if (n > 0 && n < MAX_PATH)
    {
        if (winhttp_dll[n-1] != L'\\' &&
            winhttp_dll[n-1] != L'/')
            wcscat (winhttp_dll, L"\\");
        wcscat (winhttp_dll, L"winhttp.dll");
        winhttp = LoadLibraryW (winhttp_dll);
    }

  if (winhttp != NULL)
    {
      funcs.pWinHttpCloseHandle = (BOOL (WINAPI *) (HINTERNET)) GetProcAddress (winhttp, "WinHttpCloseHandle");
      funcs.pWinHttpCrackUrl = (BOOL (WINAPI *) (LPCWSTR,DWORD,DWORD,LPURL_COMPONENTS)) GetProcAddress (winhttp, "WinHttpCrackUrl");
      funcs.pWinHttpConnect = (HINTERNET (WINAPI *) (HINTERNET,LPCWSTR,INTERNET_PORT,DWORD)) GetProcAddress (winhttp, "WinHttpConnect");
      funcs.pWinHttpCreateUrl = (BOOL (WINAPI *) (LPURL_COMPONENTS,DWORD,LPWSTR,LPDWORD)) GetProcAddress (winhttp, "WinHttpCreateUrl");
      funcs.pWinHttpOpen = (HINTERNET (WINAPI *) (LPCWSTR,DWORD,LPCWSTR,LPCWSTR,DWORD)) GetProcAddress (winhttp, "WinHttpOpen");
      funcs.pWinHttpOpenRequest = (HINTERNET (WINAPI *) (HINTERNET,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR,LPCWSTR*,DWORD)) GetProcAddress (winhttp, "WinHttpOpenRequest");
      funcs.pWinHttpQueryDataAvailable = (BOOL (WINAPI *) (HINTERNET,LPDWORD)) GetProcAddress (winhttp, "WinHttpQueryDataAvailable");
      funcs.pWinHttpQueryHeaders = (BOOL (WINAPI *) (HINTERNET,DWORD,LPCWSTR,LPVOID,LPDWORD,LPDWORD)) GetProcAddress (winhttp, "WinHttpQueryHeaders");
      funcs.pWinHttpReadData = (BOOL (WINAPI *) (HINTERNET,LPVOID,DWORD,LPDWORD)) GetProcAddress (winhttp, "WinHttpReadData");
      funcs.pWinHttpReceiveResponse = (BOOL (WINAPI *) (HINTERNET,LPVOID)) GetProcAddress (winhttp, "WinHttpReceiveResponse");
      funcs.pWinHttpSendRequest = (BOOL (WINAPI *) (HINTERNET,LPCWSTR,DWORD,LPVOID,DWORD,DWORD,DWORD_PTR)) GetProcAddress (winhttp, "WinHttpSendRequest");
      funcs.pWinHttpWriteData = (BOOL (WINAPI *) (HINTERNET,LPCVOID,DWORD,LPDWORD)) GetProcAddress (winhttp, "WinHttpWriteData");

      if (funcs.pWinHttpCloseHandle &&
	  funcs.pWinHttpCrackUrl &&
	  funcs.pWinHttpConnect &&
	  funcs.pWinHttpCreateUrl &&
	  funcs.pWinHttpOpen &&
	  funcs.pWinHttpOpenRequest &&
	  funcs.pWinHttpQueryDataAvailable &&
	  funcs.pWinHttpQueryHeaders &&
	  funcs.pWinHttpReadData &&
	  funcs.pWinHttpReceiveResponse &&
	  funcs.pWinHttpSendRequest &&
	  funcs.pWinHttpWriteData)
	funcs_found = TRUE;
    }
  lookup_done = TRUE;
}