/// <summary>Returns Forward, Backward State</summary> private State Equal_Forward_Backward(string programStr, bool logToDispay2, Tools tools) { StaticFlow sFlow = new StaticFlow(tools); sFlow.Update(programStr); if (logToDispay2) { Console.WriteLine(sFlow.ToString()); } DynamicFlow dFlow0 = Runner.Construct_DynamicFlow_Forward(sFlow, tools); DynamicFlow dFlow1 = Runner.Construct_DynamicFlow_Backward(sFlow, tools); //Console.WriteLine("Forward:" + tree0.ToString(dFlow0)); //Console.WriteLine("Backward:" + tree1.ToString(dFlow1)); State state0 = dFlow0.EndState; State state1 = dFlow1.EndState; if (logToDispay2) { Console.WriteLine("================================================================="); Console.WriteLine("Forward:"); Console.WriteLine(state0); Console.WriteLine("================================================================="); Console.WriteLine("Backward:"); Console.WriteLine(state1); Console.WriteLine("================================================================="); } TestTools.AreEqual(state0, state1); return(state0); }
public void Test_Runner_Jmp_11() { string programStr = " cmp al, 0 " + Environment.NewLine + " jp label1 " + Environment.NewLine + " mov al, 1 " + Environment.NewLine + " jz label1 " + Environment.NewLine + " mov al, 2 " + Environment.NewLine + "label1: "; Tools tools = CreateTools(); var sFlow = new StaticFlow(tools); sFlow.Update(programStr); if (logToDisplay) { Console.WriteLine(sFlow.ToString()); } tools.StateConfig = sFlow.Create_StateConfig(); var dFlow = Runner.Construct_DynamicFlow_Backward(sFlow, tools); State state = dFlow.EndState; Assert.IsNotNull(state); if (logToDisplay) { Console.WriteLine("state:\n" + state); } TestTools.IsTrue(state.IsConsistent); var branch_Condition_jp = dFlow.Get_Branch_Condition(1); var branch_Condition_jz = dFlow.Get_Branch_Condition(3); if (true) { if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jp, true)); state2.Add(new BranchInfo(branch_Condition_jz, true)); TestTools.AreEqual(Rn.AL, "00000000", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jp, true)); state2.Add(new BranchInfo(branch_Condition_jz, false)); TestTools.AreEqual(Rn.AL, "????????", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jp, false)); state2.Add(new BranchInfo(branch_Condition_jz, true)); TestTools.AreEqual(Rn.AL, "XXXXXXXX", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jp, false)); state2.Add(new BranchInfo(branch_Condition_jz, false)); TestTools.AreEqual(Rn.AL, "00000010", state2); } } }
public void Test_Runner_Jmp_10() { string programStr = " cmp rax, 0 " + Environment.NewLine + " jz label1 " + Environment.NewLine + " mov rax, 1 " + Environment.NewLine + " jz label1 " + Environment.NewLine + " mov rax, 2 " + Environment.NewLine + "label1: "; Tools tools = this.CreateTools(); StaticFlow sFlow = new StaticFlow(tools); sFlow.Update(programStr); if (logToDisplay) { Console.WriteLine(sFlow.ToString()); } tools.StateConfig = sFlow.Create_StateConfig(); DynamicFlow dFlow = Runner.Construct_DynamicFlow_Backward(sFlow, tools); State state = dFlow.EndState; Assert.IsNotNull(state); if (logToDisplay) { Console.WriteLine("state:\n" + state); } TestTools.IsTrue(state.IsConsistent); Microsoft.Z3.BoolExpr branch_Condition_jz1 = dFlow.Get_Branch_Condition(1); Microsoft.Z3.BoolExpr branch_Condition_jz2 = dFlow.Get_Branch_Condition(3); if (true) { if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz1, true)); state2.Add(new BranchInfo(branch_Condition_jz2, true)); TestTools.AreEqual(Rn.RAX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000000", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz1, true)); state2.Add(new BranchInfo(branch_Condition_jz2, false)); TestTools.AreEqual(Rn.RAX, "XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz1, false)); state2.Add(new BranchInfo(branch_Condition_jz2, true)); TestTools.AreEqual(Rn.RAX, "XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX_XXXXXXXX", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz1, false)); state2.Add(new BranchInfo(branch_Condition_jz2, false)); TestTools.AreEqual(Rn.RAX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000010", state2); } } }
public void Test_Runner_Jmp_8() { string programStr = " jz label1 " + Environment.NewLine + " mov rax, 1 " + Environment.NewLine + " jc label1 " + Environment.NewLine + " mov rbx, 2 " + Environment.NewLine + "label1: " + Environment.NewLine + " mov rcx, 3 "; Tools tools = this.CreateTools(); var sFlow = new StaticFlow(tools); sFlow.Update(programStr); if (logToDisplay) { Console.WriteLine(sFlow.ToString()); } tools.StateConfig = sFlow.Create_StateConfig(); var dFlow = Runner.Construct_DynamicFlow_Backward(sFlow, tools); State state = dFlow.EndState; Assert.IsNotNull(state); if (logToDisplay) { Console.WriteLine("state:\n" + state); } TestTools.IsTrue(state.IsConsistent); var branch_Condition_jz = dFlow.Get_Branch_Condition(0); var branch_Condition_jc = dFlow.Get_Branch_Condition(2); if (true) { if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz, true)); TestTools.AreEqual(Rn.RAX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RBX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RCX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000011", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz, false)); TestTools.AreEqual(Rn.RAX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000001", state2); TestTools.AreEqual(Rn.RBX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RCX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000011", state2); } } if (true) { if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jc, true)); TestTools.AreEqual(Rn.RAX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RBX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RCX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000011", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jc, false)); TestTools.AreEqual(Rn.RAX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RBX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RCX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000011", state2); } } if (true) { if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz, true)); state2.Add(new BranchInfo(branch_Condition_jc, true)); TestTools.AreEqual(Rn.RAX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RBX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RCX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000011", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz, true)); state2.Add(new BranchInfo(branch_Condition_jc, false)); TestTools.AreEqual(Rn.RAX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RBX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RCX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000011", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz, false)); state2.Add(new BranchInfo(branch_Condition_jc, true)); TestTools.AreEqual(Rn.RAX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000001", state2); TestTools.AreEqual(Rn.RBX, "????????_????????_????????_????????_????????_????????_????????_????????", state2); TestTools.AreEqual(Rn.RCX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000011", state2); } if (true) { State state2 = new State(state); state2.Add(new BranchInfo(branch_Condition_jz, false)); state2.Add(new BranchInfo(branch_Condition_jc, false)); TestTools.AreEqual(Rn.RAX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000001", state2); TestTools.AreEqual(Rn.RBX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000010", state2); TestTools.AreEqual(Rn.RCX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_00000011", state2); } } }