Ejemplo n.º 1
0
bool InstallDllToSystem32(char *src_dirname, char *src_filename, char *dst_filename)
{
	char system32[MAX_PATH];
	char src_fullpath[MAX_PATH];
	char dst_fullpath[MAX_PATH];

	SeStrCpy(src_fullpath, sizeof(src_fullpath), src_dirname);
	SeStrCat(src_fullpath, sizeof(src_fullpath), "\\");
	SeStrCat(src_fullpath, sizeof(src_fullpath), src_filename);

	if (Is64BitCode() || IsWow64() == false)
	{
		GetSystemDirectoryA(system32, sizeof(system32));
	}
	else
	{
		GetSystemWow64DirectoryA(system32, sizeof(system32));
	}

	SeStrCpy(dst_fullpath, sizeof(dst_fullpath), system32);
	SeStrCat(dst_fullpath, sizeof(dst_fullpath), "\\");
	SeStrCat(dst_fullpath, sizeof(dst_fullpath), dst_filename);

	if (IsWin10PcapFile(dst_fullpath) == false)
	{
		char dst_backup[MAX_PATH];
		SeStrCpy(dst_backup, sizeof(dst_backup), dst_fullpath);
		SeStrCat(dst_backup, sizeof(dst_backup), ".bak");

		CopyFileA(dst_fullpath, dst_backup, false);
	}

LABEL_RETRY:
	if (CopyFileA(src_fullpath, dst_fullpath, false) == false)
	{
		char tmp[MAX_SIZE];

		wsprintfA(tmp,
			"The installation of the DLL file to the path \"%s\" failed.\r\n\r\n"
			"Make sure that there are no running programs using WinPcap DLL.",
			dst_fullpath);

		if (MessageBoxA(NULL, tmp, INSTALLER_TITLE, MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY)
		{
			goto LABEL_RETRY;
		}

		return false;
	}

	return true;
}
Ejemplo n.º 2
0
std::string PathImpl::systemImpl()
{
	char buffer[MAX_PATH];
	DWORD n = GetSystemDirectoryA(buffer, sizeof(buffer));
	if (n > 0 && n < sizeof(buffer))
	{
		std::string result(buffer, n);
		if (result[n - 1] != '\\')
			result.append("\\");
		return result;
	}
	else throw SystemException("Cannot get system directory");
}
Ejemplo n.º 3
0
HMODULE LoadLibrarySystem(const std::string& library_name, std::string* out_path)
{
	std::unique_ptr<char[]> system_directory(new char[MAX_PATH]);
	GetSystemDirectoryA(system_directory.get(), MAX_PATH);

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

	if (out_path)
		*out_path = lib_path;

	return LoadLibraryA(lib_path.c_str());
}
Ejemplo n.º 4
0
/**
 * Loads a system DLL.
 *
 * @returns Module handle or NULL
 * @param   pszName             The DLL name.
 */
static HMODULE loadSystemDll(const char *pszName)
{
    char   szPath[MAX_PATH];
    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
    size_t cbName  = strlen(pszName) + 1;
    if (cchPath + 1 + cbName > sizeof(szPath))
    {
        SetLastError(ERROR_FILENAME_EXCED_RANGE);
        return NULL;
    }
    szPath[cchPath] = '\\';
    memcpy(&szPath[cchPath + 1], pszName, cbName);
    return LoadLibraryA(szPath);
}
Ejemplo n.º 5
0
// Load necessary library
// --------------------------------------+
void SDLLP::LoadLibrary(const char* library)
{
	Log("[SDLLP] Loading library '%s'.", library);

	CHAR mPath[MAX_PATH];

	GetSystemDirectoryA(mPath, MAX_PATH);
	strcat_s(mPath, "\\");
	strcat_s(mPath, library);

	mLibraries[library] = ::LoadLibraryA(mPath);

	if (!IsLibraryLoaded(library)) Log("[SDLLP] Unable to load library '%s'.", library);
}
Ejemplo n.º 6
0
void * _stdcall FakeDirect3DCreate (UINT version) {
	void * ret = 0;
	if (Initialized) ret = CreateD3DWrapper (version);
	if (ret) return ret;

	//not morrowind or hook failed, so load the real d3d8 dll
	HMODULE d3ddll = 0;
	D3DProc func = 0;
	char Path [MAX_PATH];
	GetSystemDirectoryA (Path, MAX_PATH);
	strcat_s (Path, MAX_PATH, "\\d3d8.dll");
	d3ddll = LoadLibraryA (Path);
	func = (D3DProc) GetProcAddress (d3ddll, "Direct3DCreate8");
	return (func) (version);
}
Ejemplo n.º 7
0
/* Test dirid values */
static void test_dirid(void)
{
    char expected[MAX_PATH];

    check_dirid(DIRID_NULL, "");

    GetWindowsDirectoryA(expected, MAX_PATH);
    check_dirid(DIRID_WINDOWS, expected);

    GetSystemDirectoryA(expected, MAX_PATH);
    check_dirid(DIRID_SYSTEM, expected);

    strcat(expected, "\\unknown");
    check_dirid(40, expected);
}
Ejemplo n.º 8
0
/// <summary>
/// <c>GetDirectXVersion</c>
/// </summary>
/// <remarks>
/// </remarks>
/// <returns></returns>
PSTR __stdcall GetDirectXVersion(void)
{
	static char Buffer[64];
	char Buffer2[256];
	sprintf_s(Buffer, _countof(Buffer),
		"%u.%02u.%02u.%04u", // "%d.%02d.%02d.%04d",
		(uint16_t)DXdwVersion, HIWORD(DXdwVersion), HIWORD(DXdwRevision), (uint16_t)DXdwRevision);
	if (DXdwVersion == 0x40005 && DXdwRevision == 155)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 5.0)");
	if (DXdwVersion == 0x40005 && DXdwRevision == 0x10640)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 5.2)");
	if (DXdwVersion == 0x40006 && DXdwRevision == 318)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 6.0)");
	if (DXdwVersion == 0x40006 && DXdwRevision == 0x201B4)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 6.1)");
	if (DXdwVersion == 0x40006 && DXdwRevision == 0x30206)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 6.2)");
	if (DXdwVersion == 0x40007 && DXdwRevision == 166)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 7 Beta 1)");
	if (DXdwVersion == 0x40007 && DXdwRevision == 201)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 7 Beta 2)");
	if (DXdwVersion == 0x40007 && DXdwRevision == 224)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 7 Build 224)");
	if (DXdwVersion == 0x40007 && DXdwRevision == 242)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 7 RC3)");
	if (DXdwVersion == 0x40007 && DXdwRevision == 700)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 7.0)");
	if (DXdwVersion == 0x40007 && DXdwRevision == 716)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 7.0a)");
	if (DXdwVersion == 0x40007 && DXdwRevision == 7096)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 7.1)");
	if (DXdwVersion == 0x40008 && DXdwRevision == 183)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 8 RC0)");
	if (DXdwVersion == 0x40008 && DXdwRevision == 219)
		strcat_s(Buffer, _countof(Buffer), " (DirectX 8 RC1)");
	if (DXdwVersion == 0x40008)
	{
		if (DXdwRevision == 400)
		{
			strcat_s(Buffer, _countof(Buffer), " (DirectX 8.0)");
			GetSystemDirectoryA(Buffer2, 0x100u);
			strcat_s(Buffer2, _countof(Buffer2), "\\ddraw.dll");
			if (gos_FileSize(Buffer2) == 0x71800 || gos_FileSize(Buffer2) == 0xEF200)
				strcat_s(Buffer, _countof(Buffer), " DEBUG DLL's");
		}
	}
	return Buffer;
}
Ejemplo n.º 9
0
/**************************************************************************
 *  CreateCPanelEnumList()
 */
static BOOL CreateCPanelEnumList(IEnumIDListImpl *list, DWORD dwFlags)
{
    CHAR szPath[MAX_PATH];
    WIN32_FIND_DATAA wfd;
    HANDLE hFile;

    TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);

    /* enumerate control panel folders */
    if (dwFlags & SHCONTF_FOLDERS)
        SHELL_RegisterCPanelFolders(list, HKEY_LOCAL_MACHINE,
                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace");

    /* enumerate the control panel applets */
    if (dwFlags & SHCONTF_NONFOLDERS)
    {
        LPSTR p;

        GetSystemDirectoryA(szPath, MAX_PATH);
        p = PathAddBackslashA(szPath);
        strcpy(p, "*.cpl");

        TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n", list, debugstr_a(szPath));
        hFile = FindFirstFileA(szPath, &wfd);

        if (hFile != INVALID_HANDLE_VALUE)
        {
            do
            {
                if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
                    continue;

                if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
                    strcpy(p, wfd.cFileName);
                    SHELL_RegisterCPanelApp(list, szPath);
                }
            } while(FindNextFileA(hFile, &wfd));
            FindClose(hFile);
        }

        SHELL_RegisterRegistryCPanelApps(list, HKEY_LOCAL_MACHINE,
                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
        SHELL_RegisterRegistryCPanelApps(list, HKEY_CURRENT_USER,
                "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
    }
    return TRUE;
}
Ejemplo n.º 10
0
static BOOL install_cab(LPCWSTR file_name)
{
    HMODULE advpack;
    char install_dir[MAX_PATH];
    HRESULT (WINAPI *pExtractFilesA)(LPCSTR,LPCSTR,DWORD,LPCSTR,LPVOID,DWORD);
    LPSTR file_name_a;
    DWORD res;
    HRESULT hres;

    static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};

    TRACE("(%s)\n", debugstr_w(file_name));

    GetSystemDirectoryA(install_dir, sizeof(install_dir));
    strcat(install_dir, "\\gecko\\");
    res = CreateDirectoryA(install_dir, NULL);
    if(!res && GetLastError() != ERROR_ALREADY_EXISTS) {
        ERR("Could not create directory: %08u\n", GetLastError());
        return FALSE;
    }

    strcat(install_dir, GECKO_VERSION);
    res = CreateDirectoryA(install_dir, NULL);
    if(!res && GetLastError() != ERROR_ALREADY_EXISTS) {
        ERR("Could not create directory: %08u\n", GetLastError());
        return FALSE;
    }

    advpack = LoadLibraryW(wszAdvpack);
    pExtractFilesA = (void *)GetProcAddress(advpack, "ExtractFiles");

    /* FIXME: Use unicode version (not yet implemented) */
    file_name_a = heap_strdupWtoA(file_name);
    hres = pExtractFilesA(file_name_a, install_dir, 0, NULL, NULL, 0);
    FreeLibrary(advpack);
    heap_free(file_name_a);
    if(FAILED(hres)) {
        ERR("Could not extract package: %08x\n", hres);
        clean_up();
        return FALSE;
    }

    set_registry(install_dir);
    clean_up();

    return TRUE;
}
Ejemplo n.º 11
0
bool UninstallDllFromSystem32(char *dst_filename)
{
	char system32[MAX_PATH];
	char dst_fullpath[MAX_PATH];
	char bak_fullpath[MAX_PATH];
	bool ret;

	if (Is64BitCode() || IsWow64() == false)
	{
		GetSystemDirectoryA(system32, sizeof(system32));
	}
	else
	{
		GetSystemWow64DirectoryA(system32, sizeof(system32));
	}

	SeStrCpy(dst_fullpath, sizeof(dst_fullpath), system32);
	SeStrCat(dst_fullpath, sizeof(dst_fullpath), "\\");
	SeStrCat(dst_fullpath, sizeof(dst_fullpath), dst_filename);

	SeStrCpy(bak_fullpath, sizeof(bak_fullpath), dst_fullpath);
	SeStrCat(bak_fullpath, sizeof(bak_fullpath), ".bak");

LABEL_RETRY:
	ret = DeleteFileA(dst_fullpath);
	if (ret == false)
	{
		char tmp[MAX_SIZE];

		wsprintfA(tmp,
			"Deleting the file \"%s\" failed.\r\n\r\n"
			"Make sure that there are no running programs using WinPcap DLL.",
			dst_fullpath);

		if (MessageBoxA(NULL, tmp, INSTALLER_TITLE, MB_ICONEXCLAMATION | MB_SYSTEMMODAL | MB_RETRYCANCEL) == IDRETRY)
		{
			goto LABEL_RETRY;
		}
		return false;
	}

	MoveFileA(bak_fullpath, dst_fullpath);

	return true;
}
Ejemplo n.º 12
0
HRESULT _stdcall FakeDirectInputCreate (HINSTANCE a, DWORD b, REFIID c, void ** d, void * e) {
	void * ret = 0;

	HMODULE dinput8dll = NULL;	//Handle to the real dinput dll
	DInputProc func = NULL;		//Handle to the real create dinput8 function

	char Path [MAX_PATH];
	GetSystemDirectoryA (Path, MAX_PATH);
	strcat_s (Path, 256, "\\dinput8.dll");
	dinput8dll = ::LoadLibraryA (Path);
	func = (DInputProc) GetProcAddress (dinput8dll, "DirectInput8Create");
	HRESULT hr = (func) (a, b, c, &ret, e);
	if (hr != S_OK) return hr;

	if (!Initialized) *d = ret;
	else *d = CreateInputWrapper (ret);
	return S_OK;
}
Ejemplo n.º 13
0
std::string get_sysinfo()
{
#ifdef _WIN32

	std::ostringstream oss;
	LPSTR filePath = new char[MAX_PATH];
	UINT blockSize;
	VS_FIXEDFILEINFO *fixedFileInfo;

	GetSystemDirectoryA(filePath, MAX_PATH);
	PathAppendA(filePath, "kernel32.dll");

	DWORD dwVersionSize = GetFileVersionInfoSizeA(filePath, NULL);
	LPBYTE lpVersionInfo = new BYTE[dwVersionSize];

	GetFileVersionInfoA(filePath, 0, dwVersionSize, lpVersionInfo);
	VerQueryValueA(lpVersionInfo, "\\", (LPVOID *)&fixedFileInfo, &blockSize);

	oss << "Windows/"
		<< HIWORD(fixedFileInfo->dwProductVersionMS) << '.' // Major
		<< LOWORD(fixedFileInfo->dwProductVersionMS) << '.' // Minor
		<< HIWORD(fixedFileInfo->dwProductVersionLS) << ' '; // Build

	#ifdef _WIN64
	oss << "x86_64";
	#else
	BOOL is64 = FALSE;
	if (IsWow64Process(GetCurrentProcess(), &is64) && is64)
		oss << "x86_64"; // 32-bit app on 64-bit OS
	else
		oss << "x86";
	#endif

	delete[] lpVersionInfo;
	delete[] filePath;

	return oss.str();
#else
	struct utsname osinfo;
	uname(&osinfo);
	return std::string(osinfo.sysname) + "/"
		+ osinfo.release + " " + osinfo.machine;
#endif
}
Ejemplo n.º 14
0
bool __stdcall Initialize(void)
{
    char Root[MAX_PATH];
    GetSystemDirectoryA(Root, MAX_PATH);
    #ifdef _MSC_VER
        strcat_s(Root, "\\d3d9.dll");
    #else
        strcat(Root, "\\d3d9.dll");
    #endif

    OriginalDX = new Library(Root);
	try
	{
	    OriginalDX->FunctionAddress(d3d9.D3DPERF_BeginEvent, "D3DPERF_BeginEvent");
	    OriginalDX->FunctionAddress(d3d9.D3DPERF_EndEvent, "D3DPERF_EndEvent");
	    OriginalDX->FunctionAddress(d3d9.D3DPERF_GetStatus, "D3DPERF_GetStatus");
	    OriginalDX->FunctionAddress(d3d9.D3DPERF_QueryRepeatFrame, "D3DPERF_QueryRepeatFrame");
	    OriginalDX->FunctionAddress(d3d9.D3DPERF_SetMarker, "D3DPERF_SetMarker");
	    OriginalDX->FunctionAddress(d3d9.D3DPERF_SetOptions, "D3DPERF_SetOptions");
	    OriginalDX->FunctionAddress(d3d9.D3DPERF_SetRegion, "D3DPERF_SetRegion");
	    OriginalDX->FunctionAddress(d3d9.DebugSetLevel, "DebugSetLevel");
	    OriginalDX->FunctionAddress(d3d9.DebugSetMute, "DebugSetMute");
	    //OriginalDX->FunctionAddress(d3d9.Direct3D9EnableMaximizedWindowedModeShim, "Direct3D9EnableMaximizedWindowedModeShim");
		OriginalDX->FunctionAddress(d3d9.Direct3DCreate9, "Direct3DCreate9");
		OriginalDX->FunctionAddress(d3d9.Direct3DShaderValidatorCreate9, "Direct3DShaderValidatorCreate9");
		OriginalDX->FunctionAddress(d3d9.PSGPError, "PSGPError");
		OriginalDX->FunctionAddress(d3d9.PSGPSampleTexture, "PSGPSampleTexture");
		OriginalDX->FunctionAddress(d3d9.Direct3DCreate9Ex, "Direct3DCreate9Ex");
	}
	catch(std::exception &e)
	{
	    //MessageBox(nullptr, e.what(), "ERROR!", 0);

	    CONSOLE_SCREEN_BUFFER_INFO Info;
	    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
        GetConsoleScreenBufferInfo(hStdout, &Info);
        int Attributes = Info.wAttributes;
	    SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_INTENSITY);
	    std::printf("\n\nDirect-X ERROR:  %s\n\n\n", e.what());
	    SetConsoleTextAttribute(hStdout, Attributes);
	}
	return true;
}
Ejemplo n.º 15
0
static
BOOL load_xinput_dll(HINSTANCE instance)
{
	char sysdir[MAX_PATH];
	char modname[MAX_PATH];
	UINT sysdir_len;
	DWORD modname_len;
	DWORD namepos;
	char *dllpath;
	
	sysdir_len = GetSystemDirectoryA(sysdir, MAX_PATH);
	if (sysdir_len == 0 || sysdir_len >= MAX_PATH) return FALSE;
	
	modname_len = GetModuleFileNameA(instance, modname, MAX_PATH);
	if (!modname_len) return FALSE;

	namepos = cheap_find_last_of(modname, '\\');
	dllpath = lstrcatA(sysdir, &modname[namepos]);
	if (!dllpath) return FALSE;

	XInput.dll = LoadLibraryA(dllpath);
	if (!XInput.dll) return FALSE;

	XInput.GetState = (t_XInputGetState)GetProcAddress(XInput.dll, "XInputGetState");
	XInput.SetState = (t_XInputSetState)GetProcAddress(XInput.dll, "XInputSetState");
	XInput.GetCapabilities = (t_XInputGetCapabilities)GetProcAddress(XInput.dll, "XInputGetCapabilities");
	XInput.Enable = (t_XInputEnable)GetProcAddress(XInput.dll, "XInputEnable");
	XInput.GetDSoundAudioDeviceGuids = (t_XInputGetDSoundAudioDeviceGuids)GetProcAddress(XInput.dll, "XInputGetDSoundAudioDeviceGuids");
	XInput.GetBatteryInformation = (t_XInputGetBatteryInformation)GetProcAddress(XInput.dll, "XInputGetBatteryInformation");
	XInput.GetKeystroke = (t_XInputGetKeystroke)GetProcAddress(XInput.dll, "XInputGetKeystroke");
	XInput.GetAudioDeviceIds = (t_XInputGetAudioDeviceIds)GetProcAddress(XInput.dll, "XInputGetAudioDeviceIds");

	XInput.GetStateEx = (t_XInputGetStateEx)GetProcAddress(XInput.dll, (LPCSTR)100);
	XInput.WaitForGuideButton = (t_XInputWaitForGuideButton)GetProcAddress(XInput.dll, (LPCSTR)101);
	XInput.CancelGuideButtonWait = (t_XInputCancelGuideButtonWait)GetProcAddress(XInput.dll, (LPCSTR)102);
	XInput.PowerOffController = (t_XInputPowerOffController)GetProcAddress(XInput.dll, (LPCSTR)103);
	XInput.GetBaseBusInformation = (t_XInputGetBaseBusInformation)GetProcAddress(XInput.dll, (LPCSTR)104);
	XInput.GetCapabilitiesEx = (t_XInputGetCapabilitiesEx)GetProcAddress(XInput.dll, (LPCSTR)108);

	return TRUE;
}
Ejemplo n.º 16
0
/*----------------------------------------------------------------------------*/ 
void	TImm::Init()
{
    CHAR szPath[MAX_PATH+1];
    
	if( GetSystemDirectoryA( szPath, MAX_PATH+1 ) ) 
	{
		strcat_s( szPath, "\\imm32.dll" );
		m_hDllImm32 = LoadLibraryA( szPath );
		if( m_hDllImm32 )
		{
			_ImmLockIMC		= (INPUTCONTEXT*(WINAPI *)( HIMC ))
				GetProcAddress( m_hDllImm32, "ImmLockIMC" );
			_ImmUnlockIMC	= (BOOL(WINAPI *)( HIMC ))
				GetProcAddress( m_hDllImm32, "ImmUnlockIMC" );
			_ImmLockIMCC	= (LPVOID(WINAPI *)( HIMCC ))
				GetProcAddress( m_hDllImm32, "ImmLockIMCC" );
			_ImmUnlockIMCC	= (BOOL(WINAPI *)( HIMCC ))
				GetProcAddress( m_hDllImm32, "ImmUnlockIMCC" );
		}
	}
}
Ejemplo n.º 17
0
static void test_GetDiskInfoA(void)
{
    BOOL ret;
    DWORD error, cluster_size;
    DWORDLONG free, total;
    char path[MAX_PATH], *p;

    GetSystemDirectoryA(path, MAX_PATH);
    if ((p = strchr(path, '\\'))) *++p = 0;

    ret = GetDiskInfoA(path, &cluster_size, &free, &total);
    ok(ret, "GetDiskInfoA failed %u\n", GetLastError());

    ret = GetDiskInfoA(path, &cluster_size, &free, NULL);
    ok(ret, "GetDiskInfoA failed %u\n", GetLastError());

    ret = GetDiskInfoA(path, &cluster_size, NULL, NULL);
    ok(ret, "GetDiskInfoA failed %u\n", GetLastError());

    ret = GetDiskInfoA(path, NULL, NULL, NULL);
    ok(ret, "GetDiskInfoA failed %u\n", GetLastError());

    SetLastError(0xdeadbeef);
    strcpy(p, "\\non\\existing\\path");
    ret = GetDiskInfoA(path, NULL, NULL, NULL);
    error = GetLastError();
    ok(!ret ||
       broken(ret), /* < IE7 */
       "GetDiskInfoA succeeded\n");
    ok(error == ERROR_PATH_NOT_FOUND ||
       broken(error == 0xdeadbeef), /* < IE7 */
       "got %u expected ERROR_PATH_NOT_FOUND\n", error);

    SetLastError(0xdeadbeef);
    ret = GetDiskInfoA(NULL, NULL, NULL, NULL);
    error = GetLastError();
    ok(!ret, "GetDiskInfoA succeeded\n");
    ok(error == ERROR_INVALID_PARAMETER, "got %u expected ERROR_INVALID_PARAMETER\n", error);
}
Ejemplo n.º 18
0
PVOID LoadCodePageData(ULONG Code)
{
    char filename[MAX_PATH], sysdir[MAX_PATH];
    HANDLE hFile;
    PVOID Data = NULL;
    GetSystemDirectoryA(sysdir, MAX_PATH);

    if (Code != -1)
       sprintf(filename, "%s\\c_%lu.nls", sysdir, Code);
    else
        sprintf(filename, "%s\\l_intl.nls", sysdir);

    hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    if (hFile != INVALID_HANDLE_VALUE)
    {
        DWORD dwRead;
        DWORD dwFileSize = GetFileSize(hFile, NULL);
        Data = malloc(dwFileSize);
        ReadFile(hFile, Data, dwFileSize, &dwRead, NULL);
        CloseHandle(hFile);
    }
    return Data;
}
Ejemplo n.º 19
0
	bool install() {
		char winDir[MAX_PATH];
		GetSystemDirectoryA(winDir,sizeof(winDir));
		strcat(winDir,"\\msiexec.exe");
		std::string tmp(m_msiFile.length(),'0');
		std::copy(m_msiFile.begin(),m_msiFile.end(),tmp.begin());
		std::string param(std::string("/I \"") 
			+ tmp + "\" REINSTALLMODE=vomus REINSTALL=ALL");
		ProcessStarter msiexec(winDir,param);
		return msiexec.Run(true);
/*		MsiSetInternalUI(INSTALLUILEVEL_FULL,0);
		UINT retCode = MsiReinstallProduct(prodCode, 
				REINSTALLMODE_FILEREPLACE |
				REINSTALLMODE_MACHINEDATA|
				REINSTALLMODE_USERDATA |
				REINSTALLMODE_SHORTCUT |
				REINSTALLMODE_PACKAGE); 
		if (retCode == ERROR_UNKNOWN_PRODUCT) {
			const wchar_t *pack = m_msiFile.c_str();
			retCode = MsiInstallProduct(pack,L"ACTION=INSTALL");
			}*/
//		return retCode == ERROR_SUCCESS;
		}
Ejemplo n.º 20
0
static void GetPluginNames()
{
    char csSystemDir[_MAX_PATH];
    GetSystemDirectoryA(csSystemDir, sizeof(csSystemDir) - 50);

    // E.g. "C:\WINDOWS\System32\beidcardplugins\"
    std::string csPluginsDir = csSystemDir + std::string("\\") +
                               EIDMW_PLUGINS_DIR + std::string("\\");
    std::string strSearchFor = csPluginsDir + std::string("*.dll");
    const char *csSearchFor = strSearchFor.c_str();

    struct _finddata_t c_file;
    intptr_t hFile = _findfirst(csSearchFor, &c_file);
    if (hFile != -1)
    {
        int iFindRes;
        do
        {
            // On Windows, card plugins are linked to the CAL.
            // So emulation plugins need to be used with the emulation CAL,
            // and 'normal' plugins need to be used with the 'normal' CAL.
#ifdef CAL_EMULATION
            if (strstr(c_file.name, "Emulation") != NULL)
                AddPluginName(c_file.name, csPluginsDir + c_file.name);
#else
            if (strstr(c_file.name, "Emulation") == NULL)
                AddPluginName(c_file.name, csPluginsDir + c_file.name);
#endif
            iFindRes = _findnext(hFile, &c_file);
        }
        while (iFindRes == 0);

        _findclose(hFile);
    }

    m_bPluginNamesOK = true;
}
Ejemplo n.º 21
0
static void testLoadLibraryEx(void)
{
    CHAR path[MAX_PATH];
    HMODULE hmodule;
    HANDLE hfile;
    BOOL ret;

    hfile = CreateFileA("testfile.dll", GENERIC_READ | GENERIC_WRITE,
                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                        NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    ok(hfile != INVALID_HANDLE_VALUE, "Expected a valid file handle\n");

    /* NULL lpFileName */
    if (is_unicode_enabled)
    {
        SetLastError(0xdeadbeef);
        hmodule = LoadLibraryExA(NULL, NULL, 0);
        ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
        ok(GetLastError() == ERROR_MOD_NOT_FOUND ||
           GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
           "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_PARAMETER, got %d\n",
           GetLastError());
    }
    else
        win_skip("NULL filename crashes on WinMe\n");

    /* empty lpFileName */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA("", NULL, 0);
    ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
    ok(GetLastError() == ERROR_MOD_NOT_FOUND ||
       GetLastError() == ERROR_DLL_NOT_FOUND, /* win9x */
       "Expected ERROR_MOD_NOT_FOUND or ERROR_DLL_NOT_FOUND, got %d\n",
       GetLastError());

    /* hFile is non-NULL */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA("testfile.dll", hfile, 0);
    ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
    todo_wine
    {
        ok(GetLastError() == ERROR_SHARING_VIOLATION ||
           GetLastError() == ERROR_INVALID_PARAMETER || /* win2k3 */
           GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */
           "Unexpected last error, got %d\n", GetLastError());
    }

    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA("testfile.dll", (HANDLE)0xdeadbeef, 0);
    ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
    todo_wine
    {
        ok(GetLastError() == ERROR_SHARING_VIOLATION ||
           GetLastError() == ERROR_INVALID_PARAMETER || /* win2k3 */
           GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */
           "Unexpected last error, got %d\n", GetLastError());
    }

    /* try to open a file that is locked */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA("testfile.dll", NULL, 0);
    ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
    todo_wine
    {
        ok(GetLastError() == ERROR_SHARING_VIOLATION ||
           GetLastError() == ERROR_FILE_NOT_FOUND, /* win9x */
           "Expected ERROR_SHARING_VIOLATION or ERROR_FILE_NOT_FOUND, got %d\n",
           GetLastError());
    }

    /* lpFileName does not matter */
    if (is_unicode_enabled)
    {
        SetLastError(0xdeadbeef);
        hmodule = LoadLibraryExA(NULL, hfile, 0);
        ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
        ok(GetLastError() == ERROR_MOD_NOT_FOUND ||
           GetLastError() == ERROR_INVALID_PARAMETER, /* win2k3 */
           "Expected ERROR_MOD_NOT_FOUND or ERROR_INVALID_PARAMETER, got %d\n",
           GetLastError());
    }

    CloseHandle(hfile);

    /* load empty file */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA("testfile.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
    ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
    todo_wine
    {
        ok(GetLastError() == ERROR_FILE_INVALID ||
           GetLastError() == ERROR_BAD_FORMAT, /* win9x */
           "Expected ERROR_FILE_INVALID or ERROR_BAD_FORMAT, got %d\n",
           GetLastError());
    }

    DeleteFileA("testfile.dll");

    GetSystemDirectoryA(path, MAX_PATH);
    if (path[lstrlenA(path) - 1] != '\\')
        lstrcatA(path, "\\");
    lstrcatA(path, "kernel32.dll");

    /* load kernel32.dll with an absolute path */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA(path, NULL, LOAD_LIBRARY_AS_DATAFILE);
    ok(hmodule != 0, "Expected valid module handle\n");
    ok(GetLastError() == 0xdeadbeef ||
       GetLastError() == ERROR_SUCCESS, /* win9x */
       "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError());

    /* try invalid file handle */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA(path, (HANDLE)0xdeadbeef, 0);
    if (!hmodule)  /* succeeds on xp and older */
        ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());

    CloseHandle(hmodule);

    /* load kernel32.dll with no path */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA("kernel32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
    ok(hmodule != 0, "Expected valid module handle\n");
    ok(GetLastError() == 0xdeadbeef ||
       GetLastError() == ERROR_SUCCESS, /* win9x */
       "Expected 0xdeadbeef or ERROR_SUCCESS, got %d\n", GetLastError());

    CloseHandle(hmodule);

    GetCurrentDirectoryA(MAX_PATH, path);
    if (path[lstrlenA(path) - 1] != '\\')
        lstrcatA(path, "\\");
    lstrcatA(path, "kernel32.dll");

    /* load kernel32.dll with an absolute path that does not exist */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA(path, NULL, LOAD_LIBRARY_AS_DATAFILE);
    todo_wine
    {
        ok(hmodule == 0, "Expected 0, got %p\n", hmodule);
    }
    ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
       broken(GetLastError() == ERROR_INVALID_HANDLE),  /* nt4 */
       "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());

    /* Free the loaded dll when its the first time this dll is loaded
       in process - First time should pass, second fail */
    SetLastError(0xdeadbeef);
    hmodule = LoadLibraryExA("comctl32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE);
    ok(hmodule != 0, "Expected valid module handle\n");

    SetLastError(0xdeadbeef);
    ret = FreeLibrary(hmodule);
    ok(ret, "Expected to be able to free the module, failed with %d\n", GetLastError());
    SetLastError(0xdeadbeef);
    ret = FreeLibrary(hmodule);
    ok(!ret, "Unexpected ability to free the module, failed with %d\n", GetLastError());

    CloseHandle(hmodule);

}
Ejemplo n.º 22
0
static void test_CreateDirectoryA(void)
{
    char tmpdir[MAX_PATH];
    WCHAR curdir[MAX_PATH];
    BOOL ret;

    ret = CreateDirectoryA(NULL, NULL);
    ok(ret == FALSE && (GetLastError() == ERROR_PATH_NOT_FOUND ||
                        GetLastError() == ERROR_INVALID_PARAMETER),
       "CreateDirectoryA(NULL): ret=%d err=%d\n", ret, GetLastError());

    ret = CreateDirectoryA("", NULL);
    ok(ret == FALSE && (GetLastError() == ERROR_BAD_PATHNAME ||
                        GetLastError() == ERROR_PATH_NOT_FOUND),
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());

    ret = GetSystemDirectoryA(tmpdir, MAX_PATH);
    ok(ret < MAX_PATH, "System directory should fit into MAX_PATH\n");

    GetCurrentDirectoryW(MAX_PATH, curdir);
    ret = SetCurrentDirectoryA(tmpdir);
    ok(ret == TRUE, "could not chdir to the System directory\n");

    ret = CreateDirectoryA(".", NULL);
    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());


    ret = CreateDirectoryA("..", NULL);
    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());

    GetTempPathA(MAX_PATH, tmpdir);
    tmpdir[3] = 0; /* truncate the path */
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == FALSE && (GetLastError() == ERROR_ALREADY_EXISTS ||
                        GetLastError() == ERROR_ACCESS_DENIED),
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());

    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE,       "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == FALSE && GetLastError() == ERROR_ALREADY_EXISTS,
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());

    ret = RemoveDirectoryA(tmpdir);
    ok(ret == TRUE,
       "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());


    lstrcatA(tmpdir, "?");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
			GetLastError() == ERROR_PATH_NOT_FOUND),
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
    RemoveDirectoryA(tmpdir);

    tmpdir[lstrlenA(tmpdir) - 1] = '*';
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == FALSE && (GetLastError() == ERROR_INVALID_NAME ||
			GetLastError() == ERROR_PATH_NOT_FOUND),
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
    RemoveDirectoryA(tmpdir);

    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me/Please Remove Me");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND, 
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
    RemoveDirectoryA(tmpdir);

    /* Test behavior with a trailing dot.
     * The directory should be created without the dot.
     */
    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me.");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE,
       "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    lstrcatA(tmpdir, "/Please Remove Me");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE,
       "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
    ret = RemoveDirectoryA(tmpdir);
    ok(ret == TRUE,
       "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me");
    ret = RemoveDirectoryA(tmpdir);
    ok(ret == TRUE,
       "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    /* Test behavior with two trailing dots.
     * The directory should be created without the trailing dots.
     */
    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me..");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE,
       "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    lstrcatA(tmpdir, "/Please Remove Me");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE || /* On Win98 */
       (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
    if (ret == TRUE)
    {
        ret = RemoveDirectoryA(tmpdir);
        ok(ret == TRUE,
           "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
    }

    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me");
    ret = RemoveDirectoryA(tmpdir);
    ok(ret == TRUE,
       "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    /* Test behavior with a trailing space.
     * The directory should be created without the trailing space.
     */
    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me ");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE,
       "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    lstrcatA(tmpdir, "/Please Remove Me");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE || /* On Win98 */
       (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
    if (ret == TRUE)
    {
        ret = RemoveDirectoryA(tmpdir);
        ok(ret == TRUE,
           "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
    }

    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me");
    ret = RemoveDirectoryA(tmpdir);
    ok(ret == TRUE,
       "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    /* Test behavior with a trailing space.
     * The directory should be created without the trailing spaces.
     */
    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me  ");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE,
       "CreateDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());

    lstrcatA(tmpdir, "/Please Remove Me");
    ret = CreateDirectoryA(tmpdir, NULL);
    ok(ret == TRUE || /* On Win98 */
       (ret == FALSE && GetLastError() == ERROR_PATH_NOT_FOUND), /* On NT! */
       "CreateDirectoryA(%s): ret=%d err=%d\n", tmpdir, ret, GetLastError());
    if (ret == TRUE)
    {
        ret = RemoveDirectoryA(tmpdir);
        ok(ret == TRUE,
           "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
    }

    GetTempPathA(MAX_PATH, tmpdir);
    lstrcatA(tmpdir, "Please Remove Me");
    ret = RemoveDirectoryA(tmpdir);
    ok(ret == TRUE,
       "RemoveDirectoryA(%s) failed err=%d\n", tmpdir, GetLastError());
    SetCurrentDirectoryW(curdir);
}
Ejemplo n.º 23
0
bool ProcessStarter::run( bool forceRun )
{
	OSVERSIONINFO version = {sizeof(OSVERSIONINFO)};

	GetVersionEx(&version);
	if ((version.dwMajorVersion == 5 && version.dwMinorVersion == 0 ) && !forceRun) { //dont need this on XP/Win2K 
		d->log << "not being forced to run .." << std::endl;
		return false;
		}

	PHANDLE primaryToken = 0;
	try {
		if ((version.dwMajorVersion == 5) && (version.dwMinorVersion == 0) ) //win2K
			primaryToken = d->GetCurrentUserTokenOld();
		else
			primaryToken = d->GetCurrentUserToken();
	} catch(std::exception &ex) {
		d->log << "exception :" << ex.what() << std::endl;
		}
    if (primaryToken == 0)
    {
		d->log << "primtok = 0" << std::endl;
		if (!forceRun) 
	        return false;

    }

	STARTUPINFO StartupInfo;
    PROCESS_INFORMATION processInfo;
	memset(&StartupInfo,0,sizeof(StartupInfo));
    StartupInfo.cb = sizeof(StartupInfo);
	if (version.dwMajorVersion <= 5)
		StartupInfo.lpDesktop = L"winsta0\\default";
#if 0
	char winDir[260];
	GetSystemDirectoryA(winDir,sizeof(winDir));
	QString command = QString( "\"%1\\cmd.exe\" /C \"%2 %3\"" )
		.arg( winDir, d->processPath, d->arguments.join( " " ) );
#else
	QString command = d->processPath;
	if( !d->arguments.isEmpty() )
		command += " " + d->arguments.join( " " );
#endif
	d->log << "command:'" << command.toStdString() << "'" << std::endl;

    void* lpEnvironment = NULL;
	if (!forceRun)
	{
		BOOL resultEnv = CreateEnvironmentBlock(&lpEnvironment, *primaryToken, TRUE);
		if (resultEnv == 0)
			long nError = GetLastError();                                
		d->log << "CreateEnvironmentBlock ok" << std::endl;
	}

	BOOL result;
	if (!primaryToken)
	{
		result = CreateProcessW(0, (WCHAR*)command.utf16(),
			NULL,NULL,
			FALSE, CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT, 
			lpEnvironment, 0, &StartupInfo, &processInfo);
	}
	else
	{
		d->log << "creating as user " << std::endl;
		result = CreateProcessAsUserW(*primaryToken, 0, (WCHAR*)command.utf16(),
			NULL,NULL,
			FALSE, CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT, 
			lpEnvironment, 0, &StartupInfo, &processInfo);
	}

	if (result != FALSE)
		d->log << "launched PID=" << processInfo.dwProcessId << std::endl;
	else
	{
		d->log << "didnt launch" << std::endl;
		d->log << "CreateProcessAsUserW " << result << " err 0x"
			<< std::hex << std::setfill('0') << std::setw(8) << GetLastError() << std::endl;
	}
    if (!forceRun) 
		CloseHandle(primaryToken);
    return (result != FALSE);
}
Ejemplo n.º 24
0
BOOL APIENTRY DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
			// get system path
			if (GetSystemDirectoryA(g_system32_path, MAX_PATH - 1))
			{
#ifdef WS2
				sprintf(g_wsock32orig_path, "%s\\ws2_32.dll", g_system32_path);
#else
				sprintf(g_wsock32orig_path, "%s\\wsock32.dll", g_system32_path);
#endif
			}
			// load original library
			if (!g_wsock32orig && strlen(g_wsock32orig_path))
			{
				g_wsock32orig = LoadLibraryA(g_wsock32orig_path);
			}
			// get functions addr
			if (g_wsock32orig)
			{
				for (size_t i = 0; i < F_COUNT; i++)
				{
					g_f_addr[i] = (void *)GetProcAddress(g_wsock32orig, g_f_name[i]);
				}
			} else
			{
				for (size_t i = 0; i < F_COUNT; i++)
				{
					g_f_addr[i] = NULL;
				}
			}
			if (GetModuleFileName(hInstDLL, g_ini_path, MAX_PATH - 1))
			{
				size_t ini_path_size = strlen(g_ini_path);
				while (ini_path_size >= 0)
				{
					if (g_ini_path[ini_path_size] == '\\')
					{
						ini_path_size++;
						break;
					}
					ini_path_size--;
				}
				g_ini_path[ini_path_size] = '\0';
				strcat(g_ini_path, "azimuth.conf");
			}
			if (GetModuleFileName(hInstDLL, g_hosts_path, MAX_PATH - 1))
			{
				size_t hosts_path_size = strlen(g_hosts_path);
				while (hosts_path_size >= 0)
				{
					if (g_hosts_path[hosts_path_size] == '\\')
					{
						hosts_path_size++;
						break;
					}
					hosts_path_size--;
				}
				g_hosts_path[hosts_path_size] = '\0';
				strcat(g_hosts_path, "hosts");
			}
			conf_init();
			hbn_init();
            break;

        case DLL_THREAD_ATTACH:
            break;

        case DLL_THREAD_DETACH:
            break;

        case DLL_PROCESS_DETACH:

			// free original library
			if (g_wsock32orig)
			{
				FreeLibrary(g_wsock32orig);
				g_wsock32orig = NULL;
			}
			hbn_deinit();
			conf_deinit();
            break;
    }
    return TRUE;
}
Ejemplo n.º 25
0
static void test_find_file(void)
{
    DWORD ret;
    UINT dwCur, dwOut ;
    char appdir[MAX_PATH];
    char curdir[MAX_PATH];
    char filename[MAX_PATH];
    char outBuf[MAX_PATH];
    char windir[MAX_PATH];
    static CHAR empty[]    = "",
               regedit[] = "regedit",
               regedit_exe[] = "regedit.exe";

    memset(appdir, 0, MAX_PATH);
    memset(windir, 0, MAX_PATH);

    dwCur=MAX_PATH;
    dwOut=MAX_PATH;
    memset(curdir, 0, MAX_PATH);
    memset(outBuf, 0, MAX_PATH);
    ret = VerFindFileA(0, regedit, empty, empty, curdir, &dwCur, outBuf, &dwOut);
    switch(ret) {
    case 0L:
    ok(dwCur == 1, "Wrong length of buffer for current location: "
       "got %d(%s) expected 1\n", dwCur, curdir);
    ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
       "got %d(%s) expected 1\n", dwOut, outBuf);
        break;
    case VFF_BUFFTOOSMALL:
        ok(dwCur == MAX_PATH, "Wrong length of buffer for current location: "
           "got %d(%s) expected MAX_PATH\n", dwCur, curdir);
        ok(dwOut == MAX_PATH, "Wrong length of buffer for the recommended installation location: "
           "got %d(%s) expected MAX_PATH\n", dwOut, outBuf);
        break;
    default:
        ok(0, "Got unexpected return value %x\n", ret);
    }

    if(!GetWindowsDirectoryA(windir, MAX_PATH))
        trace("GetWindowsDirectoryA failed\n");
    else {
        sprintf(appdir, "%s\\regedit.exe", windir);
        if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(appdir))
            trace("GetFileAttributesA(%s) failed\n", appdir);
        else {
            dwCur=MAX_PATH;
            dwOut=MAX_PATH;
            memset(curdir, 0, MAX_PATH);
            memset(outBuf, 0, MAX_PATH);
            ret = VerFindFileA(0, regedit_exe, empty, empty, curdir, &dwCur, outBuf, &dwOut);
            switch(ret) {
            case VFF_CURNEDEST:
                ok(dwCur == 1 + strlen(windir), "Wrong length of buffer for current location: "
               "got %d(%s) expected %d\n", dwCur, curdir, lstrlenA(windir)+1);
            ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
               "got %d(%s) expected 1\n", dwOut, outBuf);
                break;
            case VFF_BUFFTOOSMALL:
                ok(dwCur == MAX_PATH, "Wrong length of buffer for current location: "
                   "got %d(%s) expected MAX_PATH\n", dwCur, curdir);
                ok(dwOut == MAX_PATH, "Wrong length of buffer for the recommended installation location: "
                   "got %d(%s) expected MAX_PATH\n", dwOut, outBuf);
                break;
            default:
                todo_wine ok(0, "Got unexpected return value %x\n", ret);
            }

            dwCur=MAX_PATH;
            dwOut=MAX_PATH;
            memset(curdir, 0, MAX_PATH);
            memset(outBuf, 0, MAX_PATH);
            ret = VerFindFileA(0, regedit_exe, NULL, NULL, curdir, &dwCur, outBuf, &dwOut);
            switch(ret) {
            case VFF_CURNEDEST:
                ok(dwCur == 1 + strlen(windir), "Wrong length of buffer for current location: "
               "got %d(%s) expected %d\n", dwCur, curdir, lstrlenA(windir)+1);
            ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
               "got %d(%s) expected 1\n", dwOut, outBuf);
                break;
            case VFF_BUFFTOOSMALL:
                ok(dwCur == MAX_PATH, "Wrong length of buffer for current location: "
                   "got %d(%s) expected MAX_PATH\n", dwCur, curdir);
                ok(dwOut == MAX_PATH, "Wrong length of buffer for the recommended installation location: "
                   "got %d(%s) expected MAX_PATH\n", dwOut, outBuf);
                break;
            default:
                todo_wine ok(0, "Got unexpected return value %x\n", ret);
            }
        }
    }
    if(!GetModuleFileNameA(NULL, filename, MAX_PATH) ||
       !GetSystemDirectoryA(windir, MAX_PATH) ||
       !GetTempPathA(MAX_PATH, appdir))
        trace("GetModuleFileNameA, GetSystemDirectoryA or GetTempPathA failed\n");
    else {
        char *p = strrchr(filename, '\\');
        if(p) {
            *(p++) ='\0';
            SetCurrentDirectoryA(filename);
            memmove(filename, p, 1 + strlen(p));
        }

        dwCur=MAX_PATH;
        dwOut=MAX_PATH;
        memset(outBuf, 0, MAX_PATH);
        memset(curdir, 0, MAX_PATH);
        ret = VerFindFileA(0, filename, NULL, NULL, curdir, &dwCur, outBuf, &dwOut);
        switch(ret) {
        case VFF_CURNEDEST:
        ok(dwOut == 1, "Wrong length of buffer for the recommended installation location"
           "got %d(%s) expected 1\n", dwOut, outBuf);
            break;
        case VFF_BUFFTOOSMALL:
            ok(dwOut == MAX_PATH, "Wrong length of buffer for the recommended installation location"
               "got %d(%s) expected MAX_PATH\n", dwOut, outBuf);
            break;
        default:
            todo_wine ok(0, "Got unexpected return value %x\n", ret);
        }

        dwCur=MAX_PATH;
        dwOut=MAX_PATH;
        memset(outBuf, 0, MAX_PATH);
        memset(curdir, 0, MAX_PATH);
        ret = VerFindFileA(VFFF_ISSHAREDFILE, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut);
        todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret);
        ok(dwOut == 1 + strlen(windir), "Wrong length of buffer for current location: "
           "got %d(%s) expected %d\n", dwOut, outBuf, lstrlenA(windir)+1);

        dwCur=MAX_PATH;
        dwOut=MAX_PATH;
        memset(outBuf, 0, MAX_PATH);
        memset(curdir, 0, MAX_PATH);
        ret = VerFindFileA(0, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut);
        todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %x expected VFF_CURNEDEST\n", ret);
        ok(dwOut == 1 + strlen(appdir), "Wrong length of buffer for current location: "
           "got %d(%s) expected %d\n", dwOut, outBuf, lstrlenA(appdir)+1);
    }
}
Ejemplo n.º 26
0
Archivo: query.c Proyecto: bilboed/wine
static void test_SetupGetTargetPath(void)
{
    char buffer[MAX_PATH], inf_filename[MAX_PATH];
    char destfile[MAX_PATH];
    DWORD required;
    HINF hinf;
    INFCONTEXT ctx;
    BOOL ret;

    lstrcpyA(inf_filename, CURR_DIR);
    lstrcatA(inf_filename, "\\");
    lstrcatA(inf_filename, "test.inf");

    create_inf_file(inf_filename, inf_data1, sizeof(inf_data1) - 1);

    hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
    ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");

    ctx.Inf = hinf;
    ctx.CurrentInf = hinf;
    ctx.Section = 7;
    ctx.Line = 0;

    required = 0;

    ret = SetupGetTargetPathA(hinf, &ctx, NULL, buffer, sizeof(buffer), &required);
    ok(ret, "SetupGetTargetPathA failed\n");
    ok(required == 10, "unexpected required size: %d\n", required);
    /* Retrieve the system drive from the windows directory.
     * (%SystemDrive% is not available on Win9x)
     */
    lstrcpyA(destfile, WIN_DIR);
    destfile[3] = '\0';
    lstrcatA(destfile, "LANCOM");
    ok(!lstrcmpiA(destfile, buffer), "unexpected result string: %s\n", buffer);

    SetupCloseInfFile(hinf);
    DeleteFileA(inf_filename);

    create_inf_file(inf_filename, inf_data3, sizeof(inf_data3) - 1);

    hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
    ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");

    required = 0;

    ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
    ok(ret, "SetupGetTargetPathA failed\n");

    lstrcpyA(destfile, WIN_DIR);

    ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
    ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);

    SetupCloseInfFile(hinf);
    DeleteFileA(inf_filename);

    create_inf_file(inf_filename, inf_data4, sizeof(inf_data4) - 1);

    hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
    ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");

    required = 0;

    ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.System32.Files", buffer, sizeof(buffer), &required);
    ok(ret, "SetupGetTargetPathA failed\n");

    GetSystemDirectoryA(destfile, MAX_PATH);

    ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
    ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);

    SetupCloseInfFile(hinf);
    DeleteFileA(inf_filename);

    create_inf_file(inf_filename, inf_data5, sizeof(inf_data5) - 1);

    hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
    ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");

    required = 0;

    ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
    ok(ret, "SetupGetTargetPathA failed\n");

    lstrcpyA(destfile, WIN_DIR);

    ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
    ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);

    SetupCloseInfFile(hinf);
    DeleteFileA(inf_filename);

    create_inf_file(inf_filename, inf_data6, sizeof(inf_data6) - 1);

    hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
    ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");

    required = 0;

    ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
    ok(ret, "SetupGetTargetPathA failed\n");

    lstrcpyA(destfile, WIN_DIR);

    ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
    ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);

    SetupCloseInfFile(hinf);
    DeleteFileA(inf_filename);
}
Ejemplo n.º 27
0
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID)
{
	if (dwReason == DLL_PROCESS_ATTACH)
	{
#ifdef _AFX_OLE_IMPL
		BOOL bRegister = !coreDLL.bInitialized;

		// shared initialization
		AFX_MODULE_STATE* pModuleState = _AfxGetOleModuleState();
		pModuleState->m_hCurrentInstanceHandle = hInstance;
		pModuleState->m_hCurrentResourceHandle = hInstance;
		pModuleState->m_pClassInit = pModuleState->m_classList.GetHead();
		pModuleState->m_pFactoryInit = pModuleState->m_factoryList.GetHead();
#endif

		// initialize this DLL's extension module
		VERIFY(AfxInitExtensionModule(coreDLL, hInstance));

#ifdef _AFX_OLE_IMPL
		AfxWinInit(hInstance, NULL, &afxChNil, 0);

		// Register class factories in context of private module state
		if (bRegister)
			COleObjectFactory::RegisterAll();
#endif

#ifdef _AFX_OLE_IMPL
		// restore previously-saved module state
		VERIFY(AfxSetModuleState(AfxGetThreadState()->m_pPrevModuleState) ==
			_AfxGetOleModuleState());
		DEBUG_ONLY(AfxGetThreadState()->m_pPrevModuleState = NULL);
#endif

		// wire up this DLL into the resource chain
		CDynLinkLibrary* pDLL = new CDynLinkLibrary(coreDLL, TRUE);
		ASSERT(pDLL != NULL);
		pDLL->m_factoryList.m_pHead = NULL;

		// load language specific DLL
		// the DLL must be in the "system directory"
		static const char szPrefix[] = "\\MFC42";
		static const char szLOC[] = "LOC";
		static const char szDLL[] = ".DLL";
		char szLangDLL[_MAX_PATH+14]; // Note: 8.3 name
		GetSystemDirectoryA(szLangDLL, _countof(szLangDLL));
		lstrcatA(szLangDLL, szPrefix);

		// try MFC42LOC.DLL
		lstrcatA(szLangDLL, szLOC);
		lstrcatA(szLangDLL, szDLL);
		HINSTANCE hLangDLL = LoadLibraryA(szLangDLL);
		AFX_MODULE_STATE* pState = AfxGetModuleState();
		pState->m_appLangDLL = hLangDLL;

#ifdef _AFX_OLE_IMPL
		// copy it to the private OLE state too
		pModuleState->m_appLangDLL = hLangDLL;
#endif
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		// free language specific DLL
		AFX_MODULE_STATE* pState = AfxGetModuleState();
		if (pState->m_appLangDLL != NULL)
		{
			::FreeLibrary(pState->m_appLangDLL);
			pState->m_appLangDLL = NULL;
		}

		// free the DLL info blocks
		CDynLinkLibrary* pDLL;
		while ((pDLL = pState->m_libraryList) != NULL)
			delete pDLL;
		ASSERT(pState->m_libraryList.IsEmpty());

		// cleanup module state for this process
		AfxTermExtensionModule(coreDLL);

#ifdef _AFX_OLE_IMPL
		// set module state for cleanup
		ASSERT(AfxGetThreadState()->m_pPrevModuleState == NULL);
		AfxGetThreadState()->m_pPrevModuleState =
			AfxSetModuleState(_AfxGetOleModuleState());
#endif

		// cleanup module state in OLE private module state
		AfxTermExtensionModule(coreDLL, TRUE);

		// free any local data for this process/thread
		AfxTermLocalData(NULL, TRUE);
	}
	else if (dwReason == DLL_THREAD_DETACH)
	{
		AfxTermThread();
	}

	return TRUE;    // ok
}
Ejemplo n.º 28
0
/// <summary>
/// <c>InitLibraries</c>
/// </summary>
/// <remarks>
/// </remarks>
/// <returns></returns>
void __stdcall InitLibraries(void)
{
	PCSTR pszFormat;
	PCSTR pszMessage;
	size_t nBufferSize;
	char szAssetsPathMessage[MAX_PATH * 2];
	bool bbladepath1;
	bool bbladepath2;
	// char szDdrawMessage[MAX_PATH * 2];
	char szDirectXVersionMessage2[128];
	char szDirectXVersionMessage1[128];
	char szDsetupMessage[MAX_PATH * 2];
	HMODULE hModule_dsetup;
	char szAssetsPath[MAX_PATH];
	PDIRECTXSETUPGETVERSION pDirectXSetupGetVersion;
#if _CONSIDERED_OBSOLETE
	OSVERSIONINFOA VersionInformation;
	char szDirBuffer[MAX_PATH];
	char szInstallMessage[256];
#endif
	gos_MathExceptions(false, false);
	// C6031: Return value ignored: 'CoInitialize'
	CoInitialize(nullptr);
	// dsetup.dll
	strcpy_s(szAssetsPath, _countof(szAssetsPath), AssetsDirectory2);
	strcat_s(szAssetsPath, _countof(szAssetsPath), "\\dsetup.dll");
	hModule_dsetup = LoadLibraryA(szAssetsPath);
	if (hModule_dsetup == nullptr)
	{
		strcpy_s(szAssetsPath, _countof(szAssetsPath), AssetsDirectory1);
		strcat_s(szAssetsPath, _countof(szAssetsPath), "\\assets\\binaries\\dsetup.dll");
		hModule_dsetup = LoadLibraryA(szAssetsPath);
		if (hModule_dsetup == nullptr)
		{
			// pszFormat = gos_GetResourceString(gLanguageDLL, 10051u);
			pszFormat = "Cannot find dsetup.dll in %s\\assets\\binaries or %s, "
						"this file is required";
			sprintf_s(szDsetupMessage, _countof(szDsetupMessage), pszFormat, AssetsDirectory1,
				AssetsDirectory2);
			MessageBoxA(nullptr, szDsetupMessage, ApplicationName, MB_ICONEXCLAMATION);
			status = AfterExit;
			_exit(EXIT_FAILURE);
		}
	}
	pDirectXSetupGetVersion = reinterpret_cast<PDIRECTXSETUPGETVERSION>(
		GetProcAddress(hModule_dsetup, "DirectXSetupGetVersion"));
	if (pDirectXSetupGetVersion == nullptr ||
		pDirectXSetupGetVersion(&DXdwVersion, &DXdwRevision) == 0)
	{
		DXdwVersion  = 0;
		DXdwRevision = 0;
	}
	FreeLibrary(hModule_dsetup);
	// ddraw.dll
	if (gDirectX7)
	{
		if ((WindowsNT == false) &&
			((DXdwVersion < 7) || ((DXdwVersion == 7) && (DXdwRevision < 716))))
		{
			pszFormat  = "Requires DirectX 7.0a or later, found %s";
			pszMessage = GetDirectXVersion();
			sprintf_s(szDirectXVersionMessage1, _countof(szDirectXVersionMessage1), pszFormat,
				pszMessage);
			MessageBoxA(nullptr, szDirectXVersionMessage1, ApplicationName, MB_ICONEXCLAMATION);
			status = AfterExit;
			_exit(EXIT_FAILURE);
		}
	}
	else
	{
		if ((DXdwVersion < 8) || ((DXdwVersion == 8) && (DXdwRevision < 400)))
		{
			// pszFormat = gos_GetResourceString(gLanguageDLL, 10030u);	//
			// language.dll : "Requires DirectX 8 or later, found %s"
			pszFormat  = "Requires DirectX 8 or later, found %s";
			pszMessage = GetDirectXVersion();
			sprintf_s(szDirectXVersionMessage2, _countof(szDirectXVersionMessage2), pszFormat,
				pszMessage);
			MessageBoxA(nullptr, szDirectXVersionMessage2, ApplicationName, MB_ICONEXCLAMATION);
			status = AfterExit;
			_exit(EXIT_FAILURE);
		}
	}
	if (gNoBlade == true)
	{
		LibBlade = LoadLibraryA("ddraw.dll");
		if (LibBlade == nullptr)
		{
			// pszMessage = gos_GetResourceString(gLanguageDLL, 10031u);
			pszMessage = "Cannot find ddraw.dll, this file is required";
			// sprintf_s(szDdrawMessage, _countof(szDdrawMessage), pszMessage);
			MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
			status = AfterExit;
			_exit(EXIT_FAILURE);
		}
		_DirectDrawCreateEx =
			reinterpret_cast<PDIRECTDRAWCREATEEX>(GetProcAddress(LibBlade, "DirectDrawCreateEx"));
		_DirectDrawEnumerate = reinterpret_cast<PDIRECTDRAWENUMERATEA>(
			GetProcAddress(LibBlade, "DirectDrawEnumerateA"));
		_DirectDrawEnumerateEx = reinterpret_cast<PDIRECTDRAWENUMERATEEXA>(
			GetProcAddress(LibBlade, "DirectDrawEnumerateExA"));
		g_pGetDXVB = nullptr;
		if ((_DirectDrawCreateEx == nullptr) || (_DirectDrawEnumerate == nullptr) ||
			/* typo bug (_DirectDrawEnumerate == nullptr)*/
			(_DirectDrawEnumerateEx == nullptr))
		{
			pszMessage = "Cannot find ddraw functions";
			MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
			status = AfterExit;
			_exit(EXIT_FAILURE);
		}
	}
	else
	{
		// this special dll must surely be considered obsolete whatever the
		// advantages there were to use a custom ddraw library.
		bbladepath2 = false;
		bbladepath1 = true;
		strcpy_s(BladePath, _countof(BladePath), AssetsDirectory2);
		strcat_s(BladePath, _countof(BladePath), "\\bladed.dll");
		LibBlade = LoadLibraryA(BladePath);
		if (LibBlade == nullptr)
		{
			strcpy_s(BladePath, _countof(BladePath), AssetsDirectory1);
			strcat_s(BladePath, _countof(BladePath), "\\assets\\binaries\\bladed.dll");
			LibBlade = LoadLibraryA(BladePath);
			if (LibBlade == nullptr)
			{
				if (strlen(AssetsDirectory2) >= 16)
				{
					nBufferSize = strlen(AssetsDirectory2);
					if (!_strnicmp(
							&AssetsDirectory2[nBufferSize - 16], "\\assets\\binaries", 0x10u))
						bbladepath2 = true;
				}
				bbladepath1 = false;
				strcpy_s(BladePath, _countof(BladePath), AssetsDirectory2);
				strcat_s(BladePath, _countof(BladePath), "\\blade.dll");
				LibBlade = LoadLibraryA(BladePath);
				if (LibBlade == nullptr)
				{
					strcpy_s(BladePath, _countof(BladePath), AssetsDirectory1);
					strcat_s(BladePath, _countof(BladePath), "\\assets\\binaries\\blade.dll");
					LibBlade	= LoadLibraryA(BladePath);
					bbladepath2 = true;
					if (LibBlade == nullptr)
					{
						// pszFormat = gos_GetResourceString(gLanguageDLL,
						// 10033u);
						pszFormat = "Cannot find blade.dll in "
									"%s\\assets\\binaries or %s, this file is "
									"required";
						sprintf_s(szAssetsPathMessage, _countof(szAssetsPathMessage), pszFormat,
							AssetsDirectory1, AssetsDirectory2);
						MessageBoxA(
							nullptr, szAssetsPathMessage, ApplicationName, MB_ICONEXCLAMATION);
						status = AfterExit;
						_exit(EXIT_FAILURE);
					}
				}
			}
		}
		if ((bbladepath2 == false) && _stricmp(ApplicationName, "Test Blade"))
		{
			if (bbladepath1 == true)
			{
				if (InternalFunctionPause("Warning, '%s' was used", BladePath))
					ENTER_DEBUGGER;
			}
			else
			{
				if (gos_DoesFileExist("assets\\binaries") &&
					InternalFunctionPause("Warning, '%s' was used", BladePath))
					ENTER_DEBUGGER;
			}
		}
		_DirectDrawCreateEx =
			reinterpret_cast<PDIRECTDRAWCREATEEX>(GetProcAddress(LibBlade, "DirectDrawCreateEx"));
		_DirectDrawEnumerate = reinterpret_cast<PDIRECTDRAWENUMERATEA>(
			GetProcAddress(LibBlade, "DirectDrawEnumerateA"));
		_DirectDrawEnumerateEx = reinterpret_cast<PDIRECTDRAWENUMERATEEXA>(
			GetProcAddress(LibBlade, "DirectDrawEnumerateExA"));
		g_pGetDXVB = reinterpret_cast<GETDXFUNC>(GetProcAddress(LibBlade, "GetDXVB"));
		if ((_DirectDrawCreateEx == nullptr) || (_DirectDrawEnumerate == nullptr) ||
			/* typo bug (_DirectDrawEnumerate == nullptr)*/
			(_DirectDrawEnumerateEx == nullptr) || (g_pGetDXVB == nullptr))
		{
			pszMessage = "Cannot find Blade functions";
			MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
			status = AfterExit;
			_exit(EXIT_FAILURE);
		}
	}
	// ijl10.dll
	strcpy_s(szAssetsPath, _countof(szAssetsPath), AssetsDirectory2);
	strcat_s(szAssetsPath, _countof(szAssetsPath), "\\ijl10.dll");
	LibJpeg = LoadLibraryA(szAssetsPath);
	if (LibJpeg == nullptr)
	{
		strcpy_s(szAssetsPath, _countof(szAssetsPath), AssetsDirectory1);
		strcat_s(szAssetsPath, _countof(szAssetsPath), "\\assets\\binaries\\ijl10.dll");
		LibJpeg = LoadLibraryA(szAssetsPath);
	}
	if (LibJpeg)
	{
		_ijlInit  = reinterpret_cast<PIJLINIT>(GetProcAddress(LibJpeg, "ijlInit"));
		_ijlFree  = reinterpret_cast<PIJLFREE>(GetProcAddress(LibJpeg, "ijlFree"));
		_ijlRead  = reinterpret_cast<PIJLREAD>(GetProcAddress(LibJpeg, "ijlRead"));
		_ijlWrite = reinterpret_cast<PIJLWRITE>(GetProcAddress(LibJpeg, "ijlWrite"));
	}
	// dsound.dll
	LibDsound = LoadLibraryA("dsound.dll");
	if (LibDsound == nullptr)
	{
		// pszMessage = gos_GetResourceString(gLanguageDLL, 10036u);
		pszMessage = "Cannot load DirectSound dll";
		MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
		status = AfterExit;
		_exit(EXIT_FAILURE);
	}
	_DirectSoundCreate =
		reinterpret_cast<PDIRECTSOUNDCREATE>(GetProcAddress(LibDsound, "DirectSoundCreate"));
	_DirectSoundEnumerate = reinterpret_cast<PDIRECTSOUNDENUMERATEA>(
		GetProcAddress(LibDsound, "DirectSoundEnumerateA"));
	if ((_DirectSoundCreate == nullptr) && (_DirectSoundEnumerate == nullptr))
	{
		pszMessage = "Cannot find DirectSound functions";
		MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
		status = AfterExit;
		_exit(EXIT_FAILURE);
	}
	// dinput.dll
	LibDinput = LoadLibraryA("dinput.dll");
	if (LibDinput == nullptr)
	{
		// pszMessage = gos_GetResourceString(gLanguageDLL, 10038u);
		pszMessage = "Cannot load DirectInput dll";
		MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
		status = AfterExit;
		_exit(EXIT_FAILURE);
	}
	_DirectInputCreateEx =
		reinterpret_cast<PDIRECTINPUTCREATEEX>(GetProcAddress(LibDinput, "DirectInputCreateEx"));
	if (_DirectInputCreateEx == nullptr)
	{
		pszMessage = "Cannot find DirectInput functions";
		MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
		status = AfterExit;
		_exit(EXIT_FAILURE);
	}
	// imm32.dll
	LibIME = LoadLibraryA("imm32.dll");
	if (LibIME)
	{
		_ImmGetContext = reinterpret_cast<PIMMGETCONTEXT>(GetProcAddress(LibIME, "ImmGetContext"));
		_ImmReleaseContext =
			reinterpret_cast<PIMMRELEASECONTEXT>(GetProcAddress(LibIME, "ImmReleaseContext"));
		_ImmAssociateContext =
			reinterpret_cast<PIMMASSOCIATECONTEXT>(GetProcAddress(LibIME, "ImmAssociateContext"));
		_ImmGetCompositionString = reinterpret_cast<PIMMGETCOMPOSITIONSTRINGA>(
			GetProcAddress(LibIME, "ImmGetCompositionStringA"));
		_ImmGetOpenStatus =
			reinterpret_cast<PIMMGETOPENSTATUS>(GetProcAddress(LibIME, "ImmGetOpenStatus"));
		_ImmSetOpenStatus =
			reinterpret_cast<PIMMSETOPENSTATUS>(GetProcAddress(LibIME, "ImmSetOpenStatus"));
		_ImmGetConversionStatus = reinterpret_cast<PIMMGETCONVERSIONSTATUS>(
			GetProcAddress(LibIME, "ImmGetConversionStatus"));
		_ImmGetCandidateList =
			reinterpret_cast<PIMMGETCANDIDATELISTA>(GetProcAddress(LibIME, "ImmGetCandidateListA"));
		_ImmGetVirtualKey =
			reinterpret_cast<PIMMGETVIRTUALKEY>(GetProcAddress(LibIME, "ImmGetVirtualKey"));
		_ImmLockIMC	= reinterpret_cast<PIMMLOCKIMC>(GetProcAddress(LibIME, "ImmLockIMC"));
		_ImmUnlockIMC  = reinterpret_cast<PIMMUNLOCKIMC>(GetProcAddress(LibIME, "ImmUnlockIMCC"));
		_ImmLockIMCC   = reinterpret_cast<PIMMLOCKIMCC>(GetProcAddress(LibIME, "ImmLockIMCC"));
		_ImmUnlockIMCC = reinterpret_cast<PIMMUNLOCKIMCC>(GetProcAddress(LibIME, "ImmUnlockIMC"));
		_ImmGetDefaultIMEWnd =
			reinterpret_cast<PIMMGETDEFAULTIMEWND>(GetProcAddress(LibIME, "ImmGetDefaultIMEWnd"));
		_ImmGetIMEFileName =
			reinterpret_cast<PIMMGETIMEFILENAME>(GetProcAddress(LibIME, "ImmGetIMEFileNameA"));
		_ImmNotifyIME = reinterpret_cast<PIMMNOTIFYIME>(GetProcAddress(LibIME, "ImmNotifyIME"));
		_ImmSetConversionStatus = reinterpret_cast<PIMMSETCONVERSIONSTATUS>(
			GetProcAddress(LibIME, "ImmSetConversionStatus"));
		_ImmSimulateHotKey =
			reinterpret_cast<PIMMSIMULATEHOTKEY>(GetProcAddress(LibIME, "ImmSimulateHotKey"));
		_ImmIsIME = reinterpret_cast<PIMMISIME>(GetProcAddress(LibIME, "ImmIsIME"));
	}
	// psapi.dll
	if (WindowsNT)
		LibPSAPI = LoadLibraryA("psapi.dll");
	else
		LibPSAPI = nullptr;
	if (LibPSAPI)
	{
		_EmptyWorkingSet =
			reinterpret_cast<PEMPTYWORKINGSET>(GetProcAddress(LibPSAPI, "EmptyWorkingSet"));
		_InitializeProcessForWsWatch = reinterpret_cast<PINITIALIZEPROCESSFORWSWATCH>(
			GetProcAddress(LibPSAPI, "InitializeProcessForWsWatch"));
		_GetWsChanges = reinterpret_cast<PGETWSCHANGES>(GetProcAddress(LibPSAPI, "GetWsChanges"));
		_GetMappedFileName =
			reinterpret_cast<PGETMAPPEDFILENAMEA>(GetProcAddress(LibPSAPI, "GetMappedFileNameA"));
	}
	// ws2_32.dll
	if (Environment.NetworkGame || gEnableGosView)
	{
		LibWinSock = LoadLibraryA("ws2_32.dll");
		if (LibWinSock == nullptr)
			LibWinSock = LoadLibraryA("wsock32.dll");
		if (LibWinSock)
		{
			_accept = reinterpret_cast<PACCEPT>(GetProcAddress(LibWinSock, "accept"));
			_bind   = reinterpret_cast<PBIND>(GetProcAddress(LibWinSock, "bind"));
			_closesocket =
				reinterpret_cast<PCLOSESOCKET>(GetProcAddress(LibWinSock, "closesocket"));
			_gethostbyname =
				reinterpret_cast<PGETHOSTBYNAME>(GetProcAddress(LibWinSock, "gethostbyname"));
			_gethostname =
				reinterpret_cast<PGETHOSTNAME>(GetProcAddress(LibWinSock, "gethostname"));
			_getservbyname =
				reinterpret_cast<PGETSERVBYNAME>(GetProcAddress(LibWinSock, "getservbyname"));
			_htonl		= reinterpret_cast<PHTONL>(GetProcAddress(LibWinSock, "htonl"));
			_htons		= reinterpret_cast<PHTONS>(GetProcAddress(LibWinSock, "htons"));
			_inet_addr  = reinterpret_cast<PINET_ADDR>(GetProcAddress(LibWinSock, "inet_addr"));
			_listen		= reinterpret_cast<PLISTEN>(GetProcAddress(LibWinSock, "listen"));
			_ntohl		= reinterpret_cast<PNTOHL>(GetProcAddress(LibWinSock, "ntohl"));
			_recv		= reinterpret_cast<PRECV>(GetProcAddress(LibWinSock, "recv"));
			_recvfrom   = reinterpret_cast<PRECVFROM>(GetProcAddress(LibWinSock, "recvfrom"));
			_send		= reinterpret_cast<PSEND>(GetProcAddress(LibWinSock, "send"));
			_sendto		= reinterpret_cast<PSENDTO>(GetProcAddress(LibWinSock, "sendto"));
			_socket		= reinterpret_cast<PSOCKET>(GetProcAddress(LibWinSock, "socket"));
			_WSACleanup = reinterpret_cast<PWSACLEANUP>(GetProcAddress(LibWinSock, "WSACleanup"));
			_WSAGetLastError =
				reinterpret_cast<PWSAGETLASTERROR>(GetProcAddress(LibWinSock, "WSAGetLastError"));
			_WSAStartup = reinterpret_cast<PWSASTARTUP>(GetProcAddress(LibWinSock, "WSAStartup"));
		}
	}
	// amstream.dll quartz.dll msadp32.acm
	LibAmstream = LoadLibraryA("amstream.dll");
	LibQuartz   = LoadLibraryA("quartz.dll");
	LibMSADP32  = LoadLibraryA("msadp32.acm");
	if ((LibAmstream == nullptr) || (LibQuartz == nullptr))
	{
		// pszMessage = gos_GetResourceString(gLanguageDLL, 10040u);
		pszMessage = "DirectX Media not installed";
		MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
		status = AfterExit;
		_exit(EXIT_FAILURE);
	}
	if (LibMSADP32 == nullptr)
	{
		// pszMessage = gos_GetResourceString(gLanguageDLL, 10042Au);
		pszMessage = "Microsoft audio compression not installed";
		MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
		status = AfterExit;
		_exit(EXIT_FAILURE);
	}
	// NOTE: useless code => meant to be moved up?
	if (LibAmstream == nullptr)
	{
		nBufferSize = strlen("amstream.dll  - Version 6.01");
		pszMessage  = GetDLLInfo("amstream.dll", 0);
		if (strncmp(pszMessage, "amstream.dll  - Version 6.01", nBufferSize) < 0)
		{
			// pszMessage = gos_GetResourceString(gLanguageDLL, 10043u);
			pszMessage = "Please install DirectX Media 6.0 or later";
			MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
			status = AfterExit;
			_exit(EXIT_FAILURE);
		}
	}
	_AMGetErrorText =
		reinterpret_cast<PAMGETERRORTEXTA>(GetProcAddress(LibQuartz, "AMGetErrorTextA"));
	if (_AMGetErrorText == nullptr)
	{
		pszMessage = "Cannot find DirectShow functions";
		MessageBoxA(nullptr, pszMessage, ApplicationName, MB_ICONEXCLAMATION);
		status = AfterExit;
		_exit(EXIT_FAILURE);
	}
#if _CONSIDERED_OBSOLETE
	// Windows 9X vmcpd.vxd
	VersionInformation.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
	GetVersionExA(&VersionInformation);
	if (WindowsNT == false)
	{
		if (HasKatmai)
		{
			if (LOWORD(VersionInformation.dwBuildNumber) == 1998)
			{
				GetSystemDirectoryA(szDirBuffer, MAX_PATH);
				strcat(szDirBuffer, "\\vmm32\\vmcpd.vxd");
				if (gos_DoesFileExist(szDirBuffer) == false)
				{
					strcpy_s(szInstallMessage, _countof(szInstallMessage),
						"You need to install \"vmcpd.vxd\" This can be found "
						"in DirectX 7.0 SDK \"DXF\\extras\\win98 piii dbg\" "
						"folder.");
					if (OnNetwork == true)
						strcat_s(szInstallMessage, _countof(szInstallMessage),
							"\n\n(Microsoft Internal) - This can be found at "
							"\\\\dxrelease\\release\\dx7\\DXF\\extras\\win98 "
							"piii dbg");
					MessageBoxA(nullptr, szInstallMessage, ApplicationName, MB_ICONEXCLAMATION);
				}
			}
		}
	}
#endif
	// odbc32.dll
	LibODBC = LoadLibraryA("odbc32.dll");
	if (LibODBC)
	{
		_SQLAllocHandle =
			reinterpret_cast<PSQLALLOCHANDLE>(GetProcAddress(LibODBC, "SQLAllocHandle"));
		_SQLBindCol = reinterpret_cast<PSQLBINDCOL>(GetProcAddress(LibODBC, "SQLBindCol"));
		_SQLBindParameter =
			reinterpret_cast<PSQLBINDPARAMETER>(GetProcAddress(LibODBC, "SQLBindParameter"));
		_SQLDisconnect = reinterpret_cast<PSQLDISCONNECT>(GetProcAddress(LibODBC, "SQLDisconnect"));
		_SQLDriverConnect =
			reinterpret_cast<PSQLDRIVERCONNECT>(GetProcAddress(LibODBC, "SQLDriverConnect"));
		_SQLExecDirect = reinterpret_cast<PSQLEXECDIRECT>(GetProcAddress(LibODBC, "SQLExecDirect"));
		_SQLFetch	  = reinterpret_cast<PSQLFETCH>(GetProcAddress(LibODBC, "SQLFetch"));
		_SQLFreeHandle = reinterpret_cast<PSQLFREEHANDLE>(GetProcAddress(LibODBC, "SQLFreeHandle"));
		_SQLFreeStmt   = reinterpret_cast<PSQLFREESTMT>(GetProcAddress(LibODBC, "SQLFreeStmt"));
		_SQLGetDiagField =
			reinterpret_cast<PSQLGETDIAGFIELD>(GetProcAddress(LibODBC, "SQLGetDiagField"));
		_SQLGetDiagRec = reinterpret_cast<PSQLGETDIAGREC>(GetProcAddress(LibODBC, "SQLGetDiagRec"));
		_SQLNumResultCols =
			reinterpret_cast<PSQLNUMRESULTCOLS>(GetProcAddress(LibODBC, "SQLNumResultCols"));
		_SQLSetEnvAttr = reinterpret_cast<PSQLSETENVATTR>(GetProcAddress(LibODBC, "SQLSetEnvAttr"));
	}
	gos_MathExceptions(true, false);
}
Ejemplo n.º 29
0
	CHAR* GetSystemDirA()
	{
		static CHAR currPath[MAX_PATH*2]={0};
		GetSystemDirectoryA(currPath,sizeof(currPath));
		return currPath;
	}
Ejemplo n.º 30
0
/*
* ldrInit
*
* Purpose:
*
* Initialize loader global variables.
*
*/
BOOL ldrInit(
	DWORD ldrCommand
	)
{
	BOOL		bResult = FALSE, bFound = FALSE, cond = FALSE;
	DWORD		dwSize;
	ULONG		rl = 0, c;
	HKEY		hKey = NULL;
	LRESULT		lRet;
	LONG		rel = 0;
	PVOID		MappedKernel = NULL;
	ULONG_PTR	KernelBase = 0L;
	SIZE_T		ModuleSize;

	PLIST_ENTRY				Head, Next;
	PLDR_DATA_TABLE_ENTRY	Entry;
	PRTL_PROCESS_MODULES	miSpace = NULL;

	CHAR	KernelFullPathName[MAX_PATH * 2];
	TCHAR	szBuffer[MAX_PATH + 1];

	do {

		lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\Oracle\\VirtualBox"), 
			0, KEY_READ, &hKey);
	
		//
		// If key not exists, return FALSE and loader will exit.
		//
		if ((lRet != ERROR_SUCCESS) || (hKey == NULL)) {
			break;
		}

		//
		// If we are not in install mode - leave here.
		//
		if (ldrCommand != TSMI_INSTALL) {
			bResult = TRUE;
			break;
		}

		//
		// Select default patch table.
		//
		g_TsmiPatchDataValue = TsmiPatchDataValue;
		g_TsmiPatchDataValueSize = sizeof(TsmiPatchDataValue);

		//
		// Read VBox version and select proper table.
		//
		RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
		dwSize = MAX_PATH * sizeof(TCHAR);
		lRet = RegQueryValueEx(hKey, TEXT("Version"), NULL, NULL, (LPBYTE)&szBuffer, &dwSize);
		if (lRet != ERROR_SUCCESS) {
			break;
		}

		if (_strcmpi(szBuffer, TEXT("4.3.16")) == 0) {
			g_TsmiPatchDataValue = &TsmiPatchDataValue_4316;
			g_TsmiPatchDataValueSize = sizeof(TsmiPatchDataValue_4316);
		}
		if (_strcmpi(szBuffer, TEXT("4.3.18")) == 0) {
			g_TsmiPatchDataValue = &TsmiPatchDataValue_4318;
			g_TsmiPatchDataValueSize = sizeof(TsmiPatchDataValue_4318);
		}
		if (_strcmpi(szBuffer, TEXT("4.3.20")) == 0) {
			g_TsmiPatchDataValue = &TsmiPatchDataValue_4320;
			g_TsmiPatchDataValueSize = sizeof(TsmiPatchDataValue_4320);
		}
		if (
			(_strcmpi(szBuffer, TEXT("4.3.22")) == 0) ||
			(_strcmpi(szBuffer, TEXT("4.3.24")) == 0)
			)	
		{
			g_TsmiPatchDataValue = &TsmiPatchDataValue_4322_24;
			g_TsmiPatchDataValueSize = sizeof(TsmiPatchDataValue_4322_24);
		}
		if (_strcmpi(szBuffer, TEXT("4.3.26")) == 0) {
			g_TsmiPatchDataValue = &TsmiPatchDataValue_4326;
			g_TsmiPatchDataValueSize = sizeof(TsmiPatchDataValue_4326);
		}

		//
		// Enumerate loaded drivers.
		//
		miSpace = supGetSystemInfo(SystemModuleInformation);
		if (miSpace == NULL) {
			break;
		}
		if (miSpace->NumberOfModules == 0) {
			break;
		}

		//
		// Query system32 folder.
		//
		RtlSecureZeroMemory(KernelFullPathName, sizeof(KernelFullPathName));
		rl = GetSystemDirectoryA(KernelFullPathName, MAX_PATH);
		if (rl == 0) {
			break;
		}
		KernelFullPathName[rl] = (CHAR)'\\';

		//
		// For vista/7 find ntoskrnl.exe
		//
		bFound = FALSE;
		if (g_osv.dwMajorVersion == 6) {
			if (g_osv.dwMinorVersion < 2) {

				_strcpy_a(&KernelFullPathName[rl + 1],
					(const char*)&miSpace->Modules[0].FullPathName[miSpace->Modules[0].OffsetToFileName]);

				KernelBase = (ULONG_PTR)miSpace->Modules[0].ImageBase;
				bFound = TRUE;
			}
		}
		//
		// For 8+, 10 find CI.DLL
		//
		if (bFound == FALSE) {
			_strcpy_a(&KernelFullPathName[rl + 1], CI_DLL);
			for (c = 0; c < miSpace->NumberOfModules; c++)
				if (_strcmpi_a((const char *)&miSpace->Modules[c].FullPathName[miSpace->Modules[c].OffsetToFileName],
					CI_DLL) == 0)
				{
					KernelBase = (ULONG_PTR)miSpace->Modules[c].ImageBase;
					break;
				}
		}

		HeapFree(GetProcessHeap(), 0, miSpace);
		miSpace = NULL;

		//
		// Map ntoskrnl/CI.DLL in our address space.
		//
		MappedKernel = LoadLibraryExA(KernelFullPathName, NULL, DONT_RESOLVE_DLL_REFERENCES);
		if (MappedKernel == NULL) {
			break;
		}

		if (g_osv.dwMajorVersion == 6) {

			// Find g_CiEnabled Vista, Seven
			if (g_osv.dwMinorVersion < 2) {

				// Query module size via PEB loader for bruteforce.
				ModuleSize = 0;
				EnterCriticalSection((PRTL_CRITICAL_SECTION)NtCurrentPeb()->LoaderLock);
				Head = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
				Next = Head->Flink;
				while (Next != Head) {
					Entry = CONTAINING_RECORD(Next, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
					if (Entry->DllBase == MappedKernel) {
						ModuleSize = Entry->SizeOfImage;
						break;
					}
					Next = Next->Flink;
				}
				LeaveCriticalSection((PRTL_CRITICAL_SECTION)NtCurrentPeb()->LoaderLock);

				// Module not found, abort.
				if (ModuleSize == 0) {
					break;
				}
				rel = dsfQueryCiEnabled(&KernelBase, MappedKernel, (DWORD)ModuleSize);
			}
			else {

				// Find g_CiOptions w8+ 
				rel = dsfQueryCiOptions(&KernelBase, MappedKernel);
			}
		}
		else {

			// Otherwise > NT6.x, find g_CiOptions 10+
			rel = dsfQueryCiOptions(&KernelBase, MappedKernel);
		}

		if (rel == 0)
			break;

		g_CiVariable = KernelBase;

		bResult = TRUE;

	} while (cond);

	if (hKey) {
		RegCloseKey(hKey);
	}
	if (miSpace != NULL) {
		HeapFree(GetProcessHeap(), 0, miSpace);
	}
	if (MappedKernel != NULL) {
		FreeLibrary(MappedKernel);
	}

	return bResult;
}