public void Branch_IfPing() { EngineState s = EngineTests.CreateEngineState(); BranchConditionType type = BranchConditionType.Ping; BranchCondition cond; // According to https://www.iana.org/domains/root/db, root domain .zzz does not exist cond = new BranchCondition(type, false, "aaa.zzz"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "localhost"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "127.0.0.1"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "::1"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "aaa.zzz"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "localhost"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "127.0.0.1"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "::1"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, @"If,Ping,aaa.zzz,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Ping,localhost,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,Ping,127.0.0.1,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,Ping,::1,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,Not,Ping,aaa.zzz,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,Not,Ping,localhost,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,Ping,127.0.0.1,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,Ping,::1,Set,%Dest%,T", "F"); }
public void Branch_IfExistRegMulti() { EngineState s = EngineTests.CreateEngineState(); BranchConditionType type = BranchConditionType.ExistRegMulti; BranchCondition cond; cond = new BranchCondition(type, false, "HKLM", @"SYSTEM\ControlSet001\Control\ServiceGroupOrder", "List", "FSFilter Infrastructure"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "HKLM", @"SYSTEM\ControlSet001\Control\ServiceGroupOrder", "List", "DoesNotExist"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "HKLM", @"SYSTEM\ControlSet001\Control\ServiceProvider\Order", "ExcluedProviders", "EMS"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "HKLM", @"SYSTEM\ControlSet001\Control\ServiceGroupOrder", "List", "FSFilter Infrastructure"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "HKLM", @"SYSTEM\ControlSet001\Control\ServiceGroupOrder", "List", "DoesNotExist"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "HKLM", @"SYSTEM\ControlSet001\Control\ServiceProvider\Order", "ExcluedProviders", "EMS"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, @"If,ExistRegMulti,HKLM,SYSTEM\ControlSet001\Control\ServiceGroupOrder,List,FSFilter#$sInfrastructure,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,ExistRegMulti,HKLM,SYSTEM\ControlSet001\Control\ServiceGroupOrder,List,DoesNotExist,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,ExistRegMulti,HKLM,SYSTEM\ControlSet001\Control\ServiceProvider\Order,ExcluedProviders,EMS,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistRegMulti,HKLM,SYSTEM\ControlSet001\Control\ServiceGroupOrder,List,FSFilter#$sInfrastructure,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistRegMulti,HKLM,SYSTEM\ControlSet001\Control\ServiceGroupOrder,List,DoesNotExist,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,Not,ExistRegMulti,HKLM,SYSTEM\ControlSet001\Control\ServiceProvider\Order,ExcluedProviders,EMS,Set,%Dest%,T", "T"); }
public void Branch_IfExistDir() { EngineState s = EngineTests.CreateEngineState(); BranchCondition cond; BranchConditionType type = BranchConditionType.ExistDir; string winDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows); string invalid = Path.GetTempFileName(); File.Delete(invalid); cond = new BranchCondition(type, false, winDir); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, invalid); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, winDir); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, invalid); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, $"If,ExistDir,{winDir},Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,ExistDir,{invalid},Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,ExistDir,{winDir},Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,ExistDir,{invalid},Set,%Dest%,T", "T"); }
public void Branch_IfExistRegValue() { EngineState s = EngineTests.CreateEngineState(); BranchConditionType type = BranchConditionType.ExistRegValue; BranchCondition cond; cond = new BranchCondition(type, false, "HKLM", @"SOFTWARE\Microsoft\DirectMusic", "GMFilePath"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "HKLM", @"SOFTWARE\Microsoft\DirectNotMusic", "GMFilePath"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "HKLM", @"SOFTWARE\Microsoft\DirectMusic", "NoFilePath"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "HKLM", @"SOFTWARE\Microsoft\DirectMusic", "GMFilePath"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "HKLM", @"SOFTWARE\Microsoft\DirectNotMusic", "GMFilePath"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "HKLM", @"SOFTWARE\Microsoft\DirectMusic", "NoFilePath"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, @"If,ExistRegKey,HKLM,SOFTWARE\Microsoft\DirectMusic,GMFilePath,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,ExistRegValue,HKLM,SOFTWARE\Microsoft\DirectNotMusic,GMFilePath,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,ExistRegValue,HKLM,SOFTWARE\Microsoft\DirectMusic,NoFilePath,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistRegKey,HKLM,SOFTWARE\Microsoft\DirectMusic,GMFilePath,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistRegValue,HKLM,SOFTWARE\Microsoft\DirectNotMusic,GMFilePath,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,Not,ExistRegValue,HKLM,SOFTWARE\Microsoft\DirectMusic,NoFilePath,Set,%Dest%,T", "T"); }
public void Branch_IfEqualX() { EngineState s = EngineTests.CreateEngineState(); BranchCondition cond; BranchConditionType type = BranchConditionType.EqualX; cond = new BranchCondition(type, false, "A", "A"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "A", "B"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "a", "A"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "A", "A"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "A", "B"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "11.1", "11.1.0"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "11.1", "11.1.0"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "10.9", "11.1"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "12", "12"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "11.1.2.9", "11.1.2.3"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "5", "5.0"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "5", "5.1.2600"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); // WB082 does not recognize hex integer representation // PEBakery support hex integer representation cond = new BranchCondition(type, false, "11", "0xC"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "12", "0xC"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "13", "0xC"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Comparison_Template(s, "A", "If,%Src%,EqualX,A,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,EqualX,a,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,EqualX,09,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,EqualX,10,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,EqualX,11,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,===,A,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,===,a,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,===,09,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,===,10,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,===,11,Set,%Dest%,T", "F"); }
public void Branch_IfBiggerEqual() { EngineState s = EngineTests.CreateEngineState(); BranchCondition cond; BranchConditionType type = BranchConditionType.BiggerEqual; cond = new BranchCondition(type, false, "11.1", "11.1.0"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "11.1", "11.1.0"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "10.9", "11.1"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "12", "12"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "11.1.2.9", "11.1.2.3"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "5", "5.0"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "5", "5.1.2600"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); // WB082 will return lexicographic compare result of two strings. // PEBakery will ignore them and treat them as just NotEqual cond = new BranchCondition(type, false, "A", "A"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "A", "B"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "B", "A"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); // WB082 does not recognize hex integer representation // PEBakery support hex integer representation cond = new BranchCondition(type, false, "11", "0xC"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "12", "0xC"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "13", "0xC"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Comparison_Template(s, "A", "If,%Src%,BiggerEqual,A,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,BiggerEqual,a,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,BiggerEqual,09,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,BiggerEqual,10,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,BiggerEqual,11,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,>=,A,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,>=,a,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,>=,09,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,>=,10,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,>=,11,Set,%Dest%,T", "F"); }
public static void Macro(EngineState s, CodeCommand cmd) { CodeInfo_Macro info = cmd.Info as CodeInfo_Macro; if (info == null) { throw new InvalidCodeCommandException("Command [Macro] should have [CodeInfo_Macro]", cmd); } CodeCommand macroCmd; if (s.Macro.MacroDict.ContainsKey(info.MacroType)) { macroCmd = s.Macro.MacroDict[info.MacroType]; macroCmd.RawCode = cmd.RawCode; } else if (s.Macro.LocalDict.ContainsKey(info.MacroType)) { // Try to find [infoMacroType] in [Variables] <- I hate undocumented behaviors! macroCmd = s.Macro.LocalDict[info.MacroType]; macroCmd.RawCode = cmd.RawCode; } else { throw new CodeCommandException($"Invalid Command [{info.MacroType}]", cmd); } Dictionary <int, string> paramDict = new Dictionary <int, string>(); for (int i = 0; i < info.Args.Count; i++) { paramDict[i + 1] = StringEscaper.ExpandSectionParams(s, info.Args[i]); } s.CurSectionParams = paramDict; if (s.LogMacro) { s.InMacro = true; CommandBranch.RunExec(s, macroCmd, true); s.InMacro = false; } else // Do not log macro { s.Logger.Build_Write(s, new LogInfo(LogState.Info, $"Macro [{info.MacroType}] ({cmd.RawCode})", s.CurDepth + 1)); s.Logger.TurnOff.Push(true); CommandBranch.RunExec(s, macroCmd, true); s.Logger.TurnOff.TryPop(out bool dummy); } }
public void Branch_IfExistSection() { EngineState s = EngineTests.CreateEngineState(); BranchCondition cond; BranchConditionType type = BranchConditionType.ExistSection; string tempPath = Path.GetTempFileName(); try { using (StreamWriter w = new StreamWriter(tempPath, false, Encoding.UTF8)) { w.WriteLine("[Hello]"); w.WriteLine("A=1"); w.WriteLine(); w.WriteLine("[World]"); w.WriteLine("B=2"); } cond = new BranchCondition(type, false, tempPath, "Hello"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, tempPath, "PEBakery"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, tempPath, "Hello"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, tempPath, "PEBakery"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, $"If,ExistSection,{tempPath},Hello,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,ExistSection,{tempPath},PEBakery,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,ExistSection,{tempPath},Hello,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,ExistSection,{tempPath},PEBakery,Set,%Dest%,T", "T"); } finally { if (File.Exists(tempPath)) { File.Delete(tempPath); } } }
public void Branch_IfWimExistIndex() { EngineState s = EngineTests.CreateEngineState(); BranchCondition cond; BranchConditionType type = BranchConditionType.WimExistIndex; string srcWim = Path.Combine("%TestBench%", "CommandWim", "MultiImage.wim"); cond = new BranchCondition(type, false, srcWim, "0"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, srcWim, "1"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, srcWim, "2"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, srcWim, "3"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, srcWim, "4"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "0"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "1"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "2"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "3"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "4"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},0,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},1,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},2,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},3,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},4,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},0,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},1,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},2,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},3,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},4,Set,%Dest%,T", "T"); }
private static void CheckAndRunCallback(EngineState s, ref CodeCommand cbCmd, string eventParam, string eventName, bool changeCurrentPlugin = false) { if (cbCmd == null) { return; } s.Logger.Build_Write(s, $"Processing callback of event [{eventName}]"); if (changeCurrentPlugin) { s.CurrentPlugin = cbCmd.Addr.Plugin; } s.CurDepth = 0; if (cbCmd.Type == CodeType.Run || cbCmd.Type == CodeType.Exec) { Debug.Assert(cbCmd.Info.GetType() == typeof(CodeInfo_RunExec)); CodeInfo_RunExec info = cbCmd.Info as CodeInfo_RunExec; if (1 <= info.Parameters.Count) { info.Parameters[0] = eventParam; } else { info.Parameters.Add(eventParam); } CommandBranch.RunExec(s, cbCmd, false, false, true); } else { ExecuteCommand(s, cbCmd); } s.Logger.Build_Write(s, new LogInfo(LogState.Info, $"End of callback [{eventName}]", s.CurDepth)); s.Logger.Build_Write(s, Logger.LogSeperator); cbCmd = null; }
public void Branch_IfExistMacro() { EngineState s = EngineTests.CreateEngineState(); BranchConditionType type = BranchConditionType.ExistMacro; BranchCondition cond; // Test if Unicode can be used in macro name s.Macro.MacroDict["대한"] = CodeParser.ParseStatement("Echo,054-790-6641", EngineTests.DummySectionAddress()); s.Macro.LocalDict["Sonic"] = CodeParser.ParseStatement("Echo,Tails", EngineTests.DummySectionAddress()); s.Variables.SetValue(VarsType.Local, "Tails", "Sonic"); cond = new BranchCondition(type, false, "대한"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "민국"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "Sonic"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "%Tails%"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "대한"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "민국"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "Sonic"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "%Tails%"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, @"If,ExistMacro,대한,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,ExistMacro,민국,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,ExistMacro,Sonic,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,ExistMacro,%Tails%,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,Not,ExistMacro,대한,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistMacro,민국,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,Not,ExistMacro,Sonic,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistMacro,%Tails%,Set,%Dest%,T", "F"); }
public void Branch_IfExistVar() { EngineState s = EngineTests.CreateEngineState(); BranchConditionType type = BranchConditionType.ExistVar; BranchCondition cond; s.Variables.SetValue(VarsType.Fixed, "F", "ixed"); s.Variables.SetValue(VarsType.Fixed, "G", "lobal"); s.Variables.SetValue(VarsType.Fixed, "L", "ocal"); cond = new BranchCondition(type, false, "%F%"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "%G%"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "%L%"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "%N%"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "%F%"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "%G%"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "%L%"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "%N%"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, @"If,ExistVar,%F%,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,ExistVar,%G%,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,ExistVar,%L%,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,ExistVar,%N%,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistVar,%F%,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistVar,%G%,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistVar,%L%,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistVar,%N%,Set,%Dest%,T", "T"); }
public static List <LogInfo> ExecuteCommand(EngineState s, CodeCommand cmd) { List <LogInfo> logs = new List <LogInfo>(); int curDepth = s.CurDepth; if (CodeCommand.DeprecatedCodeType.Contains(cmd.Type)) { logs.Add(new LogInfo(LogState.Warning, $"Command [{cmd.Type}] is deprecated")); } try { switch (cmd.Type) { #region 00 Misc case CodeType.None: logs.Add(new LogInfo(LogState.Ignore, string.Empty)); break; case CodeType.Comment: { if (s.LogComment) { logs.Add(new LogInfo(LogState.Ignore, string.Empty)); } } break; case CodeType.Error: { Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Error)); CodeInfo_Error info = cmd.Info as CodeInfo_Error; logs.Add(new LogInfo(LogState.Error, info.ErrorMessage)); } break; #endregion #region 01 File case CodeType.FileCopy: logs.AddRange(CommandFile.FileCopy(s, cmd)); break; case CodeType.FileDelete: logs.AddRange(CommandFile.FileDelete(s, cmd)); break; case CodeType.FileRename: case CodeType.FileMove: logs.AddRange(CommandFile.FileRename(s, cmd)); break; case CodeType.FileCreateBlank: logs.AddRange(CommandFile.FileCreateBlank(s, cmd)); break; case CodeType.FileSize: logs.AddRange(CommandFile.FileSize(s, cmd)); break; case CodeType.FileVersion: logs.AddRange(CommandFile.FileVersion(s, cmd)); break; case CodeType.DirCopy: logs.AddRange(CommandFile.DirCopy(s, cmd)); break; case CodeType.DirDelete: logs.AddRange(CommandFile.DirDelete(s, cmd)); break; case CodeType.DirMove: logs.AddRange(CommandFile.DirMove(s, cmd)); break; case CodeType.DirMake: logs.AddRange(CommandFile.DirMake(s, cmd)); break; case CodeType.DirSize: logs.AddRange(CommandFile.DirSize(s, cmd)); break; case CodeType.PathMove: logs.AddRange(CommandFile.PathMove(s, cmd)); break; #endregion #region 02 Registry case CodeType.RegHiveLoad: logs.AddRange(CommandRegistry.RegHiveLoad(s, cmd)); break; case CodeType.RegHiveUnload: logs.AddRange(CommandRegistry.RegHiveUnload(s, cmd)); break; case CodeType.RegRead: logs.AddRange(CommandRegistry.RegRead(s, cmd)); break; case CodeType.RegWrite: logs.AddRange(CommandRegistry.RegWrite(s, cmd)); break; case CodeType.RegWriteLegacy: // WB082 Compatibility Shim logs.AddRange(CommandRegistry.RegWriteLegacy(s, cmd)); break; case CodeType.RegDelete: logs.AddRange(CommandRegistry.RegDelete(s, cmd)); break; case CodeType.RegMulti: logs.AddRange(CommandRegistry.RegMulti(s, cmd)); break; case CodeType.RegImport: logs.AddRange(CommandRegistry.RegImport(s, cmd)); break; case CodeType.RegExport: logs.AddRange(CommandRegistry.RegExport(s, cmd)); break; #endregion #region 03 Text case CodeType.TXTAddLine: logs.AddRange(CommandText.TXTAddLine(s, cmd)); break; case CodeType.TXTAddLineOp: logs.AddRange(CommandText.TXTAddLineOp(s, cmd)); break; case CodeType.TXTReplace: logs.AddRange(CommandText.TXTReplace(s, cmd)); break; case CodeType.TXTReplaceOp: logs.AddRange(CommandText.TXTReplaceOp(s, cmd)); break; case CodeType.TXTDelLine: logs.AddRange(CommandText.TXTDelLine(s, cmd)); break; case CodeType.TXTDelLineOp: logs.AddRange(CommandText.TXTDelLineOp(s, cmd)); break; case CodeType.TXTDelSpaces: logs.AddRange(CommandText.TXTDelSpaces(s, cmd)); break; case CodeType.TXTDelEmptyLines: logs.AddRange(CommandText.TXTDelEmptyLines(s, cmd)); break; #endregion #region 04 INI case CodeType.INIRead: logs.AddRange(CommandIni.IniRead(s, cmd)); break; case CodeType.INIReadOp: logs.AddRange(CommandIni.IniReadOp(s, cmd)); break; case CodeType.INIWrite: logs.AddRange(CommandIni.IniWrite(s, cmd)); break; case CodeType.INIWriteOp: logs.AddRange(CommandIni.IniWriteOp(s, cmd)); break; case CodeType.INIDelete: logs.AddRange(CommandIni.IniDelete(s, cmd)); break; case CodeType.INIDeleteOp: logs.AddRange(CommandIni.IniDeleteOp(s, cmd)); break; case CodeType.INIReadSection: logs.AddRange(CommandIni.IniReadSection(s, cmd)); break; case CodeType.INIReadSectionOp: logs.AddRange(CommandIni.IniReadSectionOp(s, cmd)); break; case CodeType.INIAddSection: logs.AddRange(CommandIni.IniAddSection(s, cmd)); break; case CodeType.INIAddSectionOp: logs.AddRange(CommandIni.IniAddSectionOp(s, cmd)); break; case CodeType.INIDeleteSection: logs.AddRange(CommandIni.IniDeleteSection(s, cmd)); break; case CodeType.INIDeleteSectionOp: logs.AddRange(CommandIni.IniDeleteSectionOp(s, cmd)); break; case CodeType.INIWriteTextLine: logs.AddRange(CommandIni.IniWriteTextLine(s, cmd)); break; case CodeType.INIWriteTextLineOp: logs.AddRange(CommandIni.IniWriteTextLineOp(s, cmd)); break; case CodeType.INIMerge: logs.AddRange(CommandIni.IniMerge(s, cmd)); break; #endregion #region 05 Archive case CodeType.Compress: logs.AddRange(CommandArchive.Compress(s, cmd)); break; case CodeType.Decompress: logs.AddRange(CommandArchive.Decompress(s, cmd)); break; case CodeType.Expand: logs.AddRange(CommandArchive.Expand(s, cmd)); break; case CodeType.CopyOrExpand: logs.AddRange(CommandArchive.CopyOrExpand(s, cmd)); break; #endregion #region 06 Network case CodeType.WebGet: case CodeType.WebGetIfNotExist: // Deprecated logs.AddRange(CommandNetwork.WebGet(s, cmd)); break; #endregion #region 07 Plugin case CodeType.ExtractFile: logs.AddRange(CommandPlugin.ExtractFile(s, cmd)); break; case CodeType.ExtractAndRun: logs.AddRange(CommandPlugin.ExtractAndRun(s, cmd)); break; case CodeType.ExtractAllFiles: logs.AddRange(CommandPlugin.ExtractAllFiles(s, cmd)); break; case CodeType.Encode: logs.AddRange(CommandPlugin.Encode(s, cmd)); break; #endregion #region 08 Interface case CodeType.Visible: logs.AddRange(CommandInterface.Visible(s, cmd)); break; case CodeType.VisibleOp: logs.AddRange(CommandInterface.VisibleOp(s, cmd)); break; case CodeType.Message: logs.AddRange(CommandInterface.Message(s, cmd)); break; case CodeType.Echo: logs.AddRange(CommandInterface.Echo(s, cmd)); break; case CodeType.EchoFile: logs.AddRange(CommandInterface.EchoFile(s, cmd)); break; case CodeType.UserInput: logs.AddRange(CommandInterface.UserInput(s, cmd)); break; case CodeType.AddInterface: logs.AddRange(CommandInterface.AddInterface(s, cmd)); break; #endregion #region 09 Hash case CodeType.Hash: logs.AddRange(CommandHash.Hash(s, cmd)); break; #endregion #region 10 String case CodeType.StrFormat: logs.AddRange(CommandString.StrFormat(s, cmd)); break; #endregion #region 11 Math case CodeType.Math: logs.AddRange(CommandMath.Math(s, cmd)); break; #endregion #region 12 System case CodeType.System: logs.AddRange(CommandSystem.SystemCmd(s, cmd)); break; case CodeType.ShellExecute: case CodeType.ShellExecuteEx: case CodeType.ShellExecuteDelete: case CodeType.ShellExecuteSlow: logs.AddRange(CommandSystem.ShellExecute(s, cmd)); break; #endregion #region 13 Branch case CodeType.Run: case CodeType.Exec: CommandBranch.RunExec(s, cmd); break; case CodeType.Loop: CommandBranch.Loop(s, cmd); break; case CodeType.If: CommandBranch.If(s, cmd); break; case CodeType.Else: CommandBranch.Else(s, cmd); break; case CodeType.Begin: throw new InternalParserException("CodeParser Error"); case CodeType.End: throw new InternalParserException("CodeParser Error"); #endregion #region 14 Control case CodeType.Set: logs.AddRange(CommandControl.Set(s, cmd)); break; case CodeType.SetMacro: logs.AddRange(CommandControl.SetMacro(s, cmd)); break; case CodeType.AddVariables: logs.AddRange(CommandControl.AddVariables(s, cmd)); break; case CodeType.Exit: logs.AddRange(CommandControl.Exit(s, cmd)); break; case CodeType.Halt: logs.AddRange(CommandControl.Halt(s, cmd)); break; case CodeType.Wait: logs.AddRange(CommandControl.Wait(s, cmd)); break; case CodeType.Beep: logs.AddRange(CommandControl.Beep(s, cmd)); break; case CodeType.GetParam: logs.AddRange(CommandControl.GetParam(s, cmd)); break; case CodeType.PackParam: logs.AddRange(CommandControl.PackParam(s, cmd)); break; #endregion #region 15 External Macro case CodeType.Macro: CommandMacro.Macro(s, cmd); break; #endregion #region Error // Error default: logs.Add(new LogInfo(LogState.Error, $"Cannot execute [{cmd.Type}] command")); break; #endregion } } catch (CriticalErrorException) { // Stop Building logs.Add(new LogInfo(LogState.CriticalError, "Critical Error!", cmd, curDepth)); throw new CriticalErrorException(); } catch (InvalidCodeCommandException e) { logs.Add(new LogInfo(LogState.Error, e, e.Cmd, curDepth)); } catch (Exception e) { logs.Add(new LogInfo(LogState.Error, e, cmd, curDepth)); } // If ErrorOffCount is on, ignore LogState.Error and LogState.Warning ProcessErrorOff(s, cmd, logs); // Stop build on error if (StopBuildOnError) { if (0 < logs.Count(x => x.State == LogState.Error)) { s.ErrorHaltFlag = true; } } s.Logger.Build_Write(s, LogInfo.AddCommandDepth(logs, cmd, curDepth)); // Increase only if cmd resides in CurrentPlugin. // So if a setion is from Macro, it will not be count. if (!s.ProcessedSectionHashes.Contains(cmd.Addr.Section.GetHashCode()) && s.CurrentPlugin.Equals(cmd.Addr.Plugin)) { s.MainViewModel.BuildPluginProgressBarValue += 1; } // Return logs, used in unit test return(logs); }
public void Branch_IfEqual() { EngineState s = EngineTests.CreateEngineState(); BranchCondition cond; BranchConditionType type = BranchConditionType.Equal; // Equal cond = new BranchCondition(type, false, "A", "A"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "A", "B"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "a", "A"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "A", "A"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "A", "B"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "11.1", "11.1.0"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, "11.1", "11.1.0"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "10.9", "11.1"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "12", "12"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "11.1.2.9", "11.1.2.3"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "5", "5.0"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "5", "5.1.2600"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); // WB082 does not recognize hex integer representation // PEBakery support hex integer representation cond = new BranchCondition(type, false, "11", "0xC"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "12", "0xC"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, "13", "0xC"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); // Test for a bug reported in http://theoven.org/index.php?topic=2271.msg25381#msg25381 cond = new BranchCondition(type, false, "-1", "0"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Comparison_Template(s, "A", "If,%Src%,Equal,A,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,Equal,a,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,Equal,09,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,Equal,10,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,Equal,11,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,==,A,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,==,a,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,==,09,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,==,10,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,==,11,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "A", "If,Not,%Src%,Equal,A,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,NotEqual,a,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,NotEqual,09,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,Not,%Src%,Equal,10,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,Not,%Src%,Equal,11,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,!=,A,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "A", "If,%Src%,!=,a,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,!=,09,Set,%Dest%,T", "T"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,!=,10,Set,%Dest%,T", "F"); BranchCondition_Comparison_Template(s, "10", "If,%Src%,!=,11,Set,%Dest%,T", "T"); }