Example #1
0
/* 初始化全局变量 */
unsigned WINAPI init_global_env(void * pParam)
{
	BOOL diff = read_appint(L"General", L"Nocompatete") > 0;
	if ( read_appkey(L"General",L"PortableDataPath",appdata_path,sizeof(appdata_path)) )
	{ 
		/* 如果ini文件里的appdata设置路径为相对路径 */
		if (appdata_path[1] != L':')
		{
			PathToCombineW(appdata_path,VALUE_LEN);
		}
		/* 处理localdata变量 */
		if ( !read_appkey(L"Env",L"TmpDataPath",localdata_path,sizeof(appdata_path)) )
		{
			wcsncpy(localdata_path,appdata_path,VALUE_LEN);
		}
		/* 修正相对路径问题 */
		if (localdata_path[1] != L':')
		{
			PathToCombineW(localdata_path,VALUE_LEN);
		}
		/* 为appdata建立目录 */
		charTochar(appdata_path);
		wcsncat(appdata_path,L"\\AppData",VALUE_LEN);
		SHCreateDirectoryExW(NULL,appdata_path,NULL);
		/* 为localdata建立目录 */
		charTochar(localdata_path);
		wcsncat(localdata_path,L"\\LocalAppData\\Temp\\Fx",VALUE_LEN);
		SHCreateDirectoryExW(NULL,localdata_path,NULL);
		if ( diff )
		{
			WaitWriteFile(appdata_path);
		}
	}
	return (unsigned)diff;
}
Example #2
0
int WINAPI get_parameters(LPWSTR wdir, LPWSTR lpstrCmd, DWORD len)
{
    int		ret = -1;
    LPWSTR	lp = NULL;
    WCHAR   temp[VALUE_LEN+1]   = {0};
    WCHAR   m_para[VALUE_LEN+1] = {0};
    if ( read_appkey(L"attach",L"ExPath",temp,sizeof(temp)) )
    {
        wdir[0] = L'\0';
        lp =  StrChrW(temp,L',');
        if (isdigit(temp[wcslen(temp)-1])&&lp)
        {
            ret = temp[wcslen(temp)-1] - L'0';
            temp[lp-temp] = L'\0';
            lp =  StrChrW(temp,L' ');
            /* 如果第三方进程存在参数,工作目录设为浏览器主进程所在目录 */
            if ( lp )
            {
                temp[lp-temp] = L'\0';
                _snwprintf(m_para,VALUE_LEN,L" "L"%ls",lp+1);
                if ( !GetCurrentWorkDir(wdir,len) )
                {
                    wdir[0] = L'\0';
                }
            }
            _snwprintf(lpstrCmd,len,L"%ls",temp);
            if ( lpstrCmd[0] == L'.' || lpstrCmd[0] == L'%' )
            {
                PathToCombineW(lpstrCmd,VALUE_LEN);
            }
            wcsncat(lpstrCmd,m_para,len);
            if ( wcslen(wdir) == 0 )
            {
                _snwprintf(wdir,len,L"%ls",lpstrCmd);
                if ( !PathRemoveFileSpecW(wdir) )
                {
                    wdir[0] = L'\0';
                }
            }
        }
    }
    return ret;
}
Example #3
0
/* 必须使用进程依赖crt的wputenv函数追加环境变量 */
unsigned WINAPI SetPluginPath(void * pParam)
{
    typedef			int (__cdecl *_pwrite_env)(LPCWSTR envstring);
    int				ret = 0;
    HMODULE			hCrt =NULL;
    _pwrite_env		write_env = NULL;
    char			msvc_crt[CRT_LEN+1] = {0};
    LPWSTR			lpstring;
    if ( !find_msvcrt(msvc_crt,CRT_LEN) )
    {
        return (0);
    }
    if ( (hCrt = GetModuleHandleA(msvc_crt)) == NULL )
    {
        return (0);
    }
    if ( profile_path[1] != L':' )
    {
        if (!ini_ready(profile_path,MAX_PATH))
        {
            return (0);
        }
    }
    write_env = (_pwrite_env)GetProcAddress(hCrt,"_wputenv");
    if ( write_env == NULL )
    {
        return (0);
    }
    if ( (lpstring = (LPWSTR)SYS_MALLOC(MAX_ENV_SIZE)) == NULL )
    {
        return (0);
    }
    if ( (ret = GetPrivateProfileSectionW(L"Env", lpstring, MAX_ENV_SIZE-1, profile_path)) > 0 )
    {
        LPWSTR	strKey = lpstring;
        while(*strKey != L'\0')
        {
            if ( stristrW(strKey, L"NpluginPath") )
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"NpluginPath",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    PathToCombineW(lpfile, VALUE_LEN);
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_PLUGIN_PATH=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if ( stristrW(strKey, L"VimpPentaHome") )
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"VimpPentaHome",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    if (lpfile[1] != L':')
                    {
                        WCHAR vimp_path[VALUE_LEN+1] = {0};
                        charTochar(lpfile);
                        if ( PathCombineW(vimp_path,portable_data_path,lpfile) )
                        {
                            int n = _snwprintf(lpfile,VALUE_LEN,L"%ls",vimp_path);
                            lpfile[n] = L'\0';
                        }
                    }
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"HOME=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if	(stristrW(strKey, L"MOZ_GMP_PATH"))
            {
                WCHAR lpfile[VALUE_LEN+1];
                if ( read_appkey(L"Env",L"MOZ_GMP_PATH",lpfile,sizeof(lpfile)) )
                {
                    WCHAR env_string[VALUE_LEN+1] = {0};
                    PathToCombineW(lpfile, VALUE_LEN);
                    if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_GMP_PATH=",lpfile) > 0)
                    {
                        ret = write_env( (LPCWSTR)env_string );
                    }
                }
            }
            else if	(stristrW(strKey, L"TmpDataPath"))
            {
                /* the PATH environment variable does not exist */
            }
            else
            {
                ret = write_env( (LPCWSTR)strKey );
            }
            strKey += wcslen(strKey)+1;
        }
    }
    SYS_FREE(lpstring);
    return (1);
}
Example #4
0
BOOL WINAPI in_whitelist(LPCWSTR lpfile)
{
	WCHAR *moz_processes[] = {L"", L"plugin-container.exe", L"plugin-hang-ui.exe", L"webapprt-stub.exe",
							  L"webapp-uninstaller.exe",L"WSEnable.exe",L"uninstall\\helper.exe",
							  L"crashreporter.exe",L"CommandExecuteHandler.exe",L"maintenanceservice.exe",
							  L"maintenanceservice_installer.exe",L"updater.exe"
							 };
	static  WCHAR white_list[EXCLUDE_NUM][VALUE_LEN+1];
	int		i = sizeof(moz_processes)/sizeof(moz_processes[0]);
	LPCWSTR pname = lpfile;
	BOOL    ret = FALSE;
	if (lpfile[0] == L'"')
	{
		pname = &lpfile[1];
	}
	/* 遍历白名单一次,只需遍历一次 */
	ret = stristrW(white_list[1],L"plugin-container.exe") != NULL;
	if ( !ret )
	{
		/* firefox目录下进程的路径 */
		int num;
		WCHAR temp[VALUE_LEN+1];
		GetModuleFileNameW(NULL,temp,VALUE_LEN);
		wcsncpy(white_list[0],(LPCWSTR)temp,VALUE_LEN);
		PathRemoveFileSpecW(temp);
		for(num=1; num<i; ++num)
		{
			_snwprintf(white_list[num],VALUE_LEN,L"%ls\\%ls", temp, moz_processes[num]);
		}
		ret = foreach_section(L"whitelist", &white_list[num], EXCLUDE_NUM-num);
	}
	if ( (ret = !ret) == FALSE )
	{
		/* 核对白名单 */
		for ( i=0; i<EXCLUDE_NUM ; i++ )
		{
			if (wcslen(white_list[i]) == 0)
			{
				continue;
			}
			if ( StrChrW(white_list[i],L'*') || StrChrW(white_list[i],L'?') )
			{
				if ( PathMatchSpecW(pname,white_list[i]) )
				{
					ret = TRUE;
					break;
				}
			}
			else if (white_list[i][1] != L':')
			{
				PathToCombineW(white_list[i],VALUE_LEN);
			}
			if (_wcsnicmp(white_list[i],pname,wcslen(white_list[i]))==0)
			{
				ret = TRUE;
				break;
			}
		}
	}
	return ret;
}
Example #5
0
/* 必须使用进程依赖crt的wputenv函数追加环境变量 */
unsigned WINAPI SetPluginPath(void * pParam)
{
	typedef			int (__cdecl *_pwrite_env)(LPCWSTR envstring);
	int				ret = 0;
	HMODULE			hCrt =NULL;
	_pwrite_env		write_env = NULL;
	char			msvc_crt[CRT_LEN+1] = {0};
	LPWSTR			lpstring;
	if ( !find_msvcrt(msvc_crt,CRT_LEN) )
	{
		return ((unsigned)ret);
	}
	if ( (hCrt = GetModuleHandleA(msvc_crt)) == NULL )
	{
		return ((unsigned)ret);
	}
	if ( profile_path[1] != L':' )
	{
		if (!ini_ready(profile_path,MAX_PATH))
		{
			return ((unsigned)ret);
		}
	}
	write_env = (_pwrite_env)GetProcAddress(hCrt,"_wputenv");
	if ( write_env )
	{
		if ( (lpstring = (LPWSTR)SYS_MALLOC(MAX_ENV_SIZE)) != NULL )
		{
			if ( (ret = GetPrivateProfileSectionW(L"Env", lpstring, MAX_ENV_SIZE-1, profile_path)) > 0 )
			{
				LPWSTR	strKey = lpstring;
				while(*strKey != L'\0') 
				{
					if ( stristrW(strKey, L"NpluginPath") )
					{
						WCHAR lpfile[VALUE_LEN+1];
						if ( read_appkey(L"Env",L"NpluginPath",lpfile,sizeof(lpfile)) )
						{
							WCHAR env_string[VALUE_LEN+1] = {0};
							PathToCombineW(lpfile, VALUE_LEN);
							if ( _snwprintf(env_string,VALUE_LEN,L"%ls%ls",L"MOZ_PLUGIN_PATH=",lpfile) > 0)
							{
								ret = write_env( (LPCWSTR)env_string );
							}
						}
					}
					else if	(stristrW(strKey, L"TmpDataPath"))
					{
						;
					}
					else
					{
						ret = write_env( (LPCWSTR)strKey );
					}
					strKey += wcslen(strKey)+1;
				}
			}
			SYS_FREE(lpstring);
		}
	}
	return ( (unsigned)ret );
}