Пример #1
0
DWORD CImplRepairVul::_ThreadFuncInstallImpl()
{
	T_ComInit _init_com_;
	while(!m_bCanceled)
	{
		WaitForSingleObject(m_thinfo.m_hInstallEvent,INFINITE);
		if(m_thinfo.nInstallIndex>=m_arrDownloadItem.GetSize())
		{
			if(m_thinfo.isDownloadDone) // 如果文件已经下载结束 
				break;
			else 
				continue;
		}
		
		BOOL bLastInstallSuccess = FALSE;
		for( int i=m_thinfo.nInstallIndex;i<m_arrDownloadItem.GetSize() && !m_bCanceled;i++)
		{
			T_RepairItem &item = m_arrDownloadItem[i];
			if(item.stateDownload==-1)
				break;
			if(item.stateInstalled!=-1) // 已经安装了 
				continue;
			
			if(!bLastInstallSuccess)
				FixUpdateGarbage();

			m_thinfo.nInstallIndex = i + 1;
			if(item.stateDownload)
			{
				CString strFileName = item.strFilename;
				CString strInstallParam = item.strInstallParam;
#ifdef _DEBUG
				strInstallParam = _T("");
#endif
				_FixSystemRootSpecialPath( item );
				
				BOOL bUserPatcher = FALSE;
				E_InstalledResult res_inst = EINST_FAIL;
				DWORD dwExitCode = 0;
				INT userPatchCode = -1;
				BOOL disableCOM = ( item.type==VTYPE_SOFTLEAK && item.bDisableCOM );		
				Notify(EVulfix_InstallBegin, item.nID, i, m_thinfo.totalNum);	
				if( disableCOM )
				{
					if( m_pCurrentVulfix )
					{
						m_pCurrentVulfix->EnableVulCOM( item.nID, false );
						res_inst = EINST_SUCCESS;
					}
				}
				else
				{
					BOOL bHijacked = FALSE;
					if( !ExecuteFile(strFileName, strInstallParam, dwExitCode, bHijacked) )
						res_inst = EINST_FAIL_EXECUTE;
					else
					{
						BOOL exactInstalled = ERROR_SUCCESS_REBOOT_REQUIRED==dwExitCode || ERROR_SUCCESS_REBOOT_INITIATED==dwExitCode;
						if(!exactInstalled && item.type==VTYPE_OFFICE)
							 exactInstalled = 17025==dwExitCode;

						if( exactInstalled )
							res_inst = EINST_SUCCESS;
						else if( 0x80240017==dwExitCode )
						{
							// Vista 的未找到产品
							// Office 的未找到产品错误码 
							res_inst = EINST_FAIL_NOT_APPLICABLE;
						}
						else
						{
							if(dwExitCode==0)
								res_inst = EINST_SUCCESS_CHECK_FAILED;

							BOOL bMeetCondition = TRUE, bFoundInRegistry = FALSE;

							// 检测条件是否还继续满足 
							if( !item.strCondtion.IsEmpty() )
								bMeetCondition = EvaluateCondition( item.strCondtion );
							CSysEnv& sysEnv = singleton<CSysEnv>::Instance();
							if( item.type==VTYPE_OFFICE||item.type==VTYPE_SOFTLEAK )
							{
								// Office, Software 的检查注册表, 确认安装成功 
								if (sysEnv.m_WinVer >= WINVISTA)
								{
									CWUAUpdateInfoVistaLaterReg vs;
									vs.Init(0);
									bFoundInRegistry = vs.IsUpdateInstalled( item.nID );
								}
								else
								{
									CWUAUpdateInfoXP xp;
									xp.Init(0);
									bFoundInRegistry = xp.IsUpdateInstalled( item.nID );
								}
							}

							BOOL bInstalledCombined = !bMeetCondition || bFoundInRegistry;							
							if(bInstalledCombined)
							{
								res_inst = EINST_SUCCESS_CHECKED;
							}
							else
							{
								if(item.type==VTYPE_OFFICE) // 对office进行自定义安装
								{
									bUserPatcher = TRUE;
									Notify( EVulfix_InstallBeginUser, item.nID, i, dwExitCode);
									userPatchCode = _UserPatch(item);
									if(KPATCHER_OK==userPatchCode)
										res_inst = EINST_SUCCESS;
									else
									{
										res_inst = EINST_FAIL;	// 可能被360 拦截?? 然后就只能忽略了?? 不进行智能忽略!!
										//if(dwExitCode==17031) // 智能忽略
										//	res_inst = EINST_FAIL_NOT_APPLICABLE;
									}				
								}
								else if(item.type==VTYPE_SOFTLEAK)
								{
									if(bMeetCondition)
										res_inst = EINST_FAIL;
								}
							}

							LPCTSTR szFilename = _tcsrchr(strFileName, _T('\\'));
							SHOWMSG(_T("Installed Result: VulType:%d ExitCode:%08x(%d) \
									   \r\nConditionCheck:%d InReg:%d UserPatch:%d(%d)\
									   \r\nInstRes:%d(%d)(Exact:%d)  InstRes2:%d\
									   \r\nFile: %s \r\n")
									   , item.type, dwExitCode, dwExitCode, bMeetCondition, bFoundInRegistry, item.bUserPatcher, userPatchCode, res_inst, res_inst<=EINST_SUCCESS_CHECK_FAILED, exactInstalled, bInstalledCombined, szFilename+1);

							if(res_inst!=EINST_SUCCESS_CHECKED && res_inst!=EINST_SUCCESS)
							{
								if(bHijacked)
									res_inst = EINST_FAIL_HIJACKED;
							}
						}
					}
				}
				if( res_inst==EINST_FAIL_NOT_APPLICABLE )
				{
					m_objIgnore.AutoIgnore(item.nID, TRUE);
					m_objIgnore.SaveIgnoreDB();
				}

				BOOL bInstalled = res_inst<=EINST_SUCCESS_CHECK_FAILED;
				item.stateInstalled = res_inst;
				if( bInstalled )
					++ m_thinfo.nInstSuccess;
				if(bUserPatcher && !bInstalled && userPatchCode==KPATCHER_ERR_FILEBUSY)
					res_inst = EINST_FAIL_FILEBUSY;
				Notify( bInstalled ? EVulfix_InstallEnd : EVulfix_InstallError, item.nID, res_inst, bUserPatcher ? userPatchCode : dwExitCode);

				// 通知WUA 已经被修改了, 使得 Vista 的话, 需要重新的去扫描IUpdate 接口
				if( bInstalled && !disableCOM )
				{
					CWUAUpdateInfoVistaLater &wuaInfo = singleton<CWUAUpdateInfoVistaLater>::Instance();
					wuaInfo.SetWUAModified();
				}
				bLastInstallSuccess = bInstalled;
			}
		}
		
		if( m_bCanceled )
			break; 
		
		if( m_thinfo.isDownloadDone 
			&& m_thinfo.nInstallIndex>=(m_arrDownloadItem.GetSize()-1) )
		{			
			Notify( m_thinfo.totalNum==m_thinfo.nDownSuccess && m_thinfo.nDownSuccess==m_thinfo.nInstSuccess ? EVulfix_Task_Complete : EVulfix_Task_Error, 0, 0, 0);
			break;
		}
	}
Пример #2
0
Tool::OptionsResult Tool::OptionsResult::
Create(
    pbxsetting::Environment const &environment,
    std::string const &workingDirectory,
    std::vector<pbxspec::PBX::PropertyOption::shared_ptr> const &options,
    pbxspec::PBX::FileType::shared_ptr const &fileType,
    std::unordered_set<std::string> const &deletedSettings)
{
    std::vector<std::string> arguments;
    std::unordered_map<std::string, std::string> environmentVariables;
    std::vector<std::string> linkerArgs;

    std::string architecture = environment.resolve("arch");

    for (pbxspec::PBX::PropertyOption::shared_ptr const &option : options) {
        if (deletedSettings.find(option->name()) != deletedSettings.end()) {
            continue;
        }

        if (option->condition() && !EvaluateCondition(*option->condition(), environment)) {
            continue;
        }
        if (option->commandLineCondition() && !EvaluateCondition(*option->commandLineCondition(), environment)) {
            continue;
        }

        if (option->architectures() && std::find(option->architectures()->begin(), option->architectures()->end(), architecture) == option->architectures()->end()) {
            continue;
        }

        if (option->fileTypes() && fileType != nullptr && std::find(option->fileTypes()->begin(), option->fileTypes()->end(), fileType->identifier()) == option->fileTypes()->end()) {
            continue;
        }

        // TODO(grp): Use PropertyOption::conditionFlavors().
        std::string value = environment.resolve(option->name());

        if (option->type() == "Boolean" || option->type() == "bool") {
            bool booleanValue = pbxsetting::Type::ParseBoolean(value);
            ext::optional<pbxsetting::Value> const &flag = (booleanValue ? option->commandLineFlag() : option->commandLineFlagIfFalse());

            if (flag) {
                /* Boolean flags don't get the flag value after, since that would be just YES or NO. */
                arguments.push_back(environment.expand(*flag));
            }
        } else {
            if (!value.empty()) {
                if (option->commandLineFlag()) {
                    pbxsetting::Value const &flag = *option->commandLineFlag();

                    /* Pass both the command line flag and the option value itself. */
                    std::vector<pbxsetting::Value> values = { flag, pbxsetting::Value::Variable("value") };
                    AddOptionArgumentValues(&arguments, environment, workingDirectory, values, option);
                }
            }
        }

        AddOptionValuesArguments(&arguments, environment, workingDirectory, plist::CastTo<plist::Array>(option->values()), value, option);
        AddOptionValuesArguments(&arguments, environment, workingDirectory, plist::CastTo<plist::Array>(option->allowedValues()), value, option);

        if (!value.empty()) {
            /* Pass the prefix then the option value in the same argument. */
            if (option->commandLinePrefixFlag()) {
                pbxsetting::Value const &prefix = *option->commandLinePrefixFlag();
                pbxsetting::Value prefixValue = prefix + pbxsetting::Value::Variable("value");
                AddOptionArgumentValues(&arguments, environment, workingDirectory, { prefixValue }, option);
            }
        }

        AddOptionArgsArguments(&arguments, environment, workingDirectory, option->commandLineArgs(), value, option);
        AddOptionArgsArguments(&linkerArgs, environment, workingDirectory, option->additionalLinkerArgs(), value, option);

        if (option->setValueInEnvironmentVariable()) {
            std::string const &variable = environment.expand(*option->setValueInEnvironmentVariable());
            environmentVariables.insert({ variable, value });
        }

        // TODO(grp): Use PropertyOption::conditionFlavors().
        // TODO(grp): Use PropertyOption::isCommand{Input,Output}().
        // TODO(grp): Use PropertyOption::isInputDependency(), PropertyOption::outputDependencies().
        // TODO(grp): Use PropertyOption::outputsAreSourceFiles().
    }

    return Tool::OptionsResult(arguments, environmentVariables, linkerArgs);
}
// returns FALSE on END command, TRUE otherwise
bool tScriptState::ExecuteCommand(tCommand& cmd)
{
    bool bContinue = TRUE;
    switch(cmd.cmdId)
    {
        case cmdLabel:
            break;
        case cmdGoto:
            {
                ULONG step;
                const tParameter *pParam = cmd.params.GetAt(0);
                if (!FindLabelByName(*pParam, &step))
                {
                    FailCase("Can't find label %s", (LPCSTR)pParam->String());
                }
                else
                {
                    currentCommandIndex = step;
                }
            }
            break;
        case cmdIf:
            {
                bool bTrue = EvaluateCondition(cmd.params[0]->String());
                if (!bTrue)
                {
                    currentCommandIndex = cmd.elseStepForIf;
                }
            }
            break;
        case cmdEnd:
            bContinue = FALSE;
            break;
        case cmdSet:
            {
                ULONG data;
                ULONG value = cmd.params[1]->Value();
                if (!GetVariable(cmd.params[0]->String(), data) || data != value)
                {
                    data = value;
                    SetVariable(cmd.params[0]->String(), data);
                }
            }
            break;
        case cmdAdd:
            {
                ULONG data;
                if (GetVariable(cmd.params[0]->String(), data))
                {
                    data += cmd.params[1]->Value();
                    SetVariable(cmd.params[0]->String(), data);
                }
                else
                {
                    FailCase("Can't add %s", cmd.params[0]->String());
                }
            }
            break;
        case cmdPrepare:
            {
                ULONG data;
                if (GetVariable("use_merged_buffers", data))
                    bUseMergedBuffers = !!data;
                if (GetVariable("use_published_events", data))
                    bUsePublishedIndices = !!data;
                if (GetVariable("use_msix", data))
                    bMSIXUsed = !!data;
                SimulationPrepare();
            }
            break;
        case cmdTxAsync:
            {
                bAsyncTransmit = !!cmd.params[0]->Value();
            }
            break;
        case cmdSend:
            {
                AddTxBuffers(cmd.params[0]->Value(), cmd.params[1]->Value());
            }
            break;
        case cmdTxComplete:
            {
                CompleteTx((int)cmd.params[0]->Value());
            }
            break;
        case cmdTxGet:
            {
                GetTxBuffer(cmd.params[0]->Value());
            }
            break;
        case cmdRxReturn:
            {
                ReturnRxBuffer(cmd.params[0]->Value());
            }
            break;
        case cmdRxReceive:
            {
                RxReceivePacket((UCHAR)cmd.params[0]->Value());
            }
            break;
        case cmdDataGet:
            {
                UCHAR offset, val, res;
                offset = (UCHAR)cmd.params[0]->Value();
                val = (UCHAR)cmd.params[1]->Value();
                res = GetDeviceData(offset);
                if (res != val)
                {
                    FailCase("cmdDataGet(%d) = %d, expected %d", offset, res, val);
                }
            }
            break;
        case cmdDataSet:
            {
                UCHAR offset, val;
                offset = (UCHAR)cmd.params[0]->Value();
                val = (UCHAR)cmd.params[1]->Value();
                SetDeviceData(offset, val);
            }
            break;

        case cmdRxRestart:
            {
                BOOLEAN bExpected = (BOOLEAN)cmd.params[0]->Value();
                BOOLEAN b = RxRestart();
                if (b != bExpected)
                {
                    FailCase("RxRestart: %d, expected %d", b, bExpected);
                }
            }
            break;
        case cmdTxRestart:
            {
                BOOLEAN bExpected = (BOOLEAN)cmd.params[0]->Value();
                BOOLEAN b = TxRestart();
                if (b != bExpected)
                {
                    FailCase("TxRestart: %d, expected %d", b, bExpected);
                }
            }
            break;
        case cmdTxEnableInterrupt:
            {
                TxEnableInterrupt();
            }
            break;
        case cmdTxDisableInterrupt:
            {
                TxDisableInterrupt();
            }
            break;
        case cmdRxEnableInterrupt:
            {
                RxEnableInterrupt();
            }
            break;
        case cmdRxDisableInterrupt:
            {
                RxDisableInterrupt();
            }
            break;
        case cmdRxGet:
            {
                ULONG len;
                GetRxBuffer(&len);
            }
            break;
        case cmdControlRxMode:
            {
                SetRxMode((UCHAR)cmd.params[0]->Value(), cmd.params[1]->Value() != 0);
            }
            break;
        case cmdControlVlanAdd:
            {
                USHORT us = (USHORT)cmd.params[0]->Value();
                VlansAdd(&us, 1);
            }
            break;
        case cmdControlVlanDel:
            {
                USHORT us = (USHORT)cmd.params[0]->Value();
                VlansDel(&us, 1);
            }
            break;
        case cmdControlMacTable:
            {
                SetMacAddresses(cmd.params[0]->Value());
            }
        default:
            result = 1;
            break;
    }
    return bContinue;
}