public void Test_Runner_Mem_Merge_1() { Tools tools = this.CreateTools(); tools.StateConfig.Set_All_Off(); tools.StateConfig.RAX = true; tools.StateConfig.RBX = true; tools.StateConfig.ZF = true; tools.StateConfig.mem = true; tools.Quiet = true; string programStr = " jz label1 " + Environment.NewLine + " mov byte ptr[rax], 10 " + Environment.NewLine + " jmp label2 " + Environment.NewLine + "label1: " + Environment.NewLine + " mov byte ptr[rax], 20 " + Environment.NewLine + "label2: " + Environment.NewLine + " mov bl, byte ptr[rax] "; var sFlow = new StaticFlow(tools); sFlow.Update(programStr); var dFlow = Runner.Construct_DynamicFlow_Backward(sFlow, tools); State state = dFlow.EndState; State state3 = new State(state); State state4 = new State(state); var branch_Condition = dFlow.Get_Branch_Condition(0); state3.Add(new BranchInfo(branch_Condition, true)); if (logToDisplay) { Console.WriteLine("state3:\n" + state3); } TestTools.AreEqual(Rn.BL, 10, state3); state4.Add(new BranchInfo(branch_Condition, false)); if (logToDisplay) { Console.WriteLine("state4:\n" + state4); } TestTools.AreEqual(Rn.BL, 20, state4); }
public void Test_StaticFlow_IsLoopMergePoint_1() { string programStr = " mov rax, 10 ;line 0 " + Environment.NewLine + "label1: ;line 1 " + Environment.NewLine + " mov rbx, 1 ;line 2 " + Environment.NewLine + " dec rax ;line 3 " + Environment.NewLine + " jnz label1 ;line 4 " + Environment.NewLine + " mov rcx, 1 ;line 5 "; StaticFlow flow = new StaticFlow(new Tools()); flow.Update(programStr, false); if (LogToDisplay) { Console.WriteLine(flow); } { (bool isLoopMergePoint, int loopLineNumber) = flow.Is_Loop_Merge_Point(0); Assert.IsFalse(isLoopMergePoint); } { (bool isLoopMergePoint, int loopLineNumber) = flow.Is_Loop_Merge_Point(1); Assert.IsTrue(isLoopMergePoint); // Assert.IsFalse(v.BranchToExitLoop); } { (bool isLoopMergePoint, int loopLineNumber) = flow.Is_Loop_Merge_Point(2); Assert.IsFalse(isLoopMergePoint); } { (bool isLoopMergePoint, int loopLineNumber) = flow.Is_Loop_Merge_Point(3); Assert.IsFalse(isLoopMergePoint); } { (bool isLoopMergePoint, int loopLineNumber) = flow.Is_Loop_Merge_Point(4); Assert.IsFalse(isLoopMergePoint); } { (bool isLoopMergePoint, int loopLineNumber) = flow.Is_Loop_Merge_Point(5); Assert.IsFalse(isLoopMergePoint); } }
public void Test_StaticFlow_IsLoopBranchPoint_1() { string programStr = " mov rax, 10 ;line 0 " + Environment.NewLine + "label1: ;line 1 " + Environment.NewLine + " mov rbx, 1 ;line 2 " + Environment.NewLine + " dec rax ;line 3 " + Environment.NewLine + " jnz label1 ;line 4 " + Environment.NewLine + " mov rcx, 1 ;line 5 "; StaticFlow flow = new StaticFlow(new Tools()); flow.Update(programStr); if (logToDisplay) { Console.WriteLine(flow); } { var v = flow.Is_Loop_Branch_Point(0); Assert.IsFalse(v.IsLoopBranchPoint); } { var v = flow.Is_Loop_Branch_Point(1); Assert.IsFalse(v.IsLoopBranchPoint); } { var v = flow.Is_Loop_Branch_Point(2); Assert.IsFalse(v.IsLoopBranchPoint); } { var v = flow.Is_Loop_Branch_Point(3); Assert.IsFalse(v.IsLoopBranchPoint); } { var v = flow.Is_Loop_Branch_Point(4); Assert.IsTrue(v.IsLoopBranchPoint); Assert.IsFalse(v.BranchToExitLoop); } { var v = flow.Is_Loop_Branch_Point(5); Assert.IsFalse(v.IsLoopBranchPoint); } }
public void Test_Runner_Loop_1() { Tools tools = CreateTools(); tools.StateConfig.Set_All_Off(); tools.StateConfig.RAX = true; tools.StateConfig.RBX = true; tools.StateConfig.ZF = true; tools.Quiet = true; bool logToDisplay2 = false; string programStr = " mov rbx, 0 " + Environment.NewLine + " mov rax, 0x3 " + Environment.NewLine + "label1: " + Environment.NewLine + " inc rbx " + Environment.NewLine + " dec rax " + Environment.NewLine + " jnz label1 "; var sFlow = new StaticFlow(tools); sFlow.Update(programStr); if (logToDisplay2) { Console.WriteLine(sFlow); } var dFlow = Runner.Construct_DynamicFlow_Forward(sFlow, tools); if (false) { State state = dFlow.EndState; if (logToDisplay2) { Console.WriteLine(state); } TestTools.AreEqual(Rn.RAX, 0, state); TestTools.AreEqual(Rn.RBX, 3, state); } else { Assert.Inconclusive("TODO"); } }
public void Test_Runner_Loop_2() { Tools tools = this.CreateTools(); tools.StateConfig.Set_All_Off(); tools.StateConfig.RAX = true; tools.StateConfig.ZF = true; tools.Quiet = false; bool logToDisplay2 = true; string programStr = " mov rax, 0x2 " + Environment.NewLine + "label1: dec rax " + Environment.NewLine + " jnz label1 "; StaticFlow sFlow = new StaticFlow(tools); sFlow.Update(programStr); if (logToDisplay2) { Console.WriteLine(sFlow); } DynamicFlow dFlow = Runner.Construct_DynamicFlow_Backward(sFlow, tools); if (false) { // backward State state = dFlow.EndState; if (logToDisplay2) { Console.WriteLine(state); } TestTools.AreEqual(Rn.RAX, 0, state); } else { Assert.Inconclusive("TODO"); } }
public void Test_StaticFlow_HasCodePath_1() { string programStr = " mov rax, 10 ;line 0 " + Environment.NewLine + "label1: ;line 1 " + Environment.NewLine + " mov rbx, 1 ;line 2 " + Environment.NewLine + " dec rax ;line 3 " + Environment.NewLine + " jnz label1 ;line 4 " + Environment.NewLine + " mov rcx, 1 ;line 5 "; StaticFlow flow = new StaticFlow(new Tools()); flow.Update(programStr, false); if (logToDisplay) { Console.WriteLine(flow); } Assert.IsTrue(flow.HasCodePath(1, 4)); Assert.IsFalse(flow.HasCodePath(5, 4)); Assert.IsFalse(flow.HasCodePath(1, 0)); }
public void Test_Runner_Mem_3() { Tools tools = CreateTools(); // test is slow (9min - 17min) tools.StateConfig.Set_All_Off(); tools.StateConfig.RAX = true; tools.StateConfig.RBX = true; tools.StateConfig.RCX = true; tools.StateConfig.mem = true; tools.Quiet = true; bool logToDisplay2 = false;// logToDisplay; string programStr = " mov qword ptr[0], 10 " + Environment.NewLine + " mov qword ptr[10], 20 " + Environment.NewLine + " mov rbx, qword ptr [rax] " + Environment.NewLine + " mov rcx, qword ptr [rbx] "; var sFlow = new StaticFlow(tools); sFlow.Update(programStr); var dFlow = Runner.Construct_DynamicFlow_Backward(sFlow, tools); State state0 = dFlow.Create_States_Before(0, 0); State state = dFlow.EndState; var rax = state0.Create(Rn.RAX).Translate(state.Ctx); state.Frozen = false; state.Add(new BranchInfo(state.Ctx.MkEq(rax, state.Ctx.MkBV(0, 64)), true)); if (logToDisplay2) { Console.WriteLine("Forward:\n" + state); } TestTools.AreEqual(Rn.RAX, 0, state); TestTools.AreEqual(Rn.RBX, 10, state); TestTools.AreEqual(Rn.RCX, 20, state); }
public void Test_Runner_Mem_1() { Tools tools = CreateTools(); tools.StateConfig.Set_All_Off(); tools.StateConfig.RAX = true; tools.StateConfig.RCX = true; tools.StateConfig.RDX = true; tools.StateConfig.mem = true; string programStr = " mov rcx, 20 " + Environment.NewLine + " mov qword ptr[rax], rcx " + Environment.NewLine + " mov rdx, qword ptr[rax] "; var sFlow = new StaticFlow(tools); sFlow.Update(programStr); var dFlow = Runner.Construct_DynamicFlow_Backward(sFlow, tools); State state = dFlow.EndState; TestTools.AreEqual(Rn.RCX, 20, state); TestTools.AreEqual(Rn.RDX, 20, state); }
public void Test_StaticFlow_IsMergePoint_1() { string programStr = " mov rax, 10 ;line 0 " + Environment.NewLine + "label1: ;line 1 " + Environment.NewLine + " mov rbx, 1 ;line 2 " + Environment.NewLine + " dec rax ;line 3 " + Environment.NewLine + " jnz label1 ;line 4 " + Environment.NewLine + " mov rcx, 1 ;line 5 "; StaticFlow flow = new StaticFlow(new Tools()); flow.Update(programStr, false); if (logToDisplay) { Console.WriteLine(flow); } Assert.IsFalse(flow.Is_Merge_Point(0)); Assert.IsTrue(flow.Is_Merge_Point(1)); Assert.IsFalse(flow.Is_Merge_Point(2)); Assert.IsFalse(flow.Is_Merge_Point(3)); Assert.IsFalse(flow.Is_Merge_Point(4)); Assert.IsFalse(flow.Is_Merge_Point(5)); }
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_StaticFlow_Forward_2() { // test StaticFlow with removal of empty lines string programStr = " jz label1 ;line 0 " + Environment.NewLine + " mov rax, 10 ;line 1 " + Environment.NewLine + " jmp label2 ;line 2 " + Environment.NewLine + "label1: ;line 3 " + Environment.NewLine + " mov rax, 20 ;line 4 " + Environment.NewLine + "label2: ;line 5 " + Environment.NewLine + " mov rbx, rax ;line 6 " + Environment.NewLine + " jz label3 ;line 7 " + Environment.NewLine + "label3: ;line 8 "; StaticFlow sFlow = new StaticFlow(new Tools()); bool removeEmptyLines = true; sFlow.Update(programStr, removeEmptyLines); if (logToDisplay) { Console.WriteLine(sFlow); } #region Retrieve Data var n0 = sFlow.Get_Next_LineNumber(0); var n1 = sFlow.Get_Next_LineNumber(1); var n2 = sFlow.Get_Next_LineNumber(2); var n3 = sFlow.Get_Next_LineNumber(3); var n4 = sFlow.Get_Next_LineNumber(4); var n5 = sFlow.Get_Next_LineNumber(5); var n6 = sFlow.Get_Next_LineNumber(6); var n7 = sFlow.Get_Next_LineNumber(7); var n8 = sFlow.Get_Next_LineNumber(8); var n9 = sFlow.Get_Next_LineNumber(9); // var n10 = sFlow.Get_Next_LineNumber(10); Console.WriteLine("n0 = " + string.Join(",", n0)); Console.WriteLine("n1 = " + string.Join(",", n1)); Console.WriteLine("n2 = " + string.Join(",", n2)); Console.WriteLine("n3 = " + string.Join(",", n3)); Console.WriteLine("n4 = " + string.Join(",", n4)); Console.WriteLine("n5 = " + string.Join(",", n5)); Console.WriteLine("n6 = " + string.Join(",", n6)); Console.WriteLine("n7 = " + string.Join(",", n7)); Console.WriteLine("n8 = " + string.Join(",", n8)); Console.WriteLine("n9 = " + string.Join(",", n9)); // Console.WriteLine("n10 = " + string.Join(",", n10)); var p0 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(0)); var p1 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(1)); var p2 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(2)); var p3 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(3)); var p4 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(4)); var p5 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(5)); var p6 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(6)); var p7 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(7)); var p8 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(8)); var p9 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(9)); //var p10 = new List<(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(10)); Console.WriteLine("p0 = " + string.Join(",", p0)); Console.WriteLine("p1 = " + string.Join(",", p1)); Console.WriteLine("p2 = " + string.Join(",", p2)); Console.WriteLine("p3 = " + string.Join(",", p3)); Console.WriteLine("p4 = " + string.Join(",", p4)); Console.WriteLine("p5 = " + string.Join(",", p5)); Console.WriteLine("p6 = " + string.Join(",", p6)); Console.WriteLine("p7 = " + string.Join(",", p7)); Console.WriteLine("p8 = " + string.Join(",", p8)); Console.WriteLine("p9 = " + string.Join(",", p9)); //Console.WriteLine("p10 = " + string.Join(",", p10)); #endregion #region Test Next Assert.AreEqual(9, sFlow.NLines); Assert.AreEqual((1, 4), n0); Assert.AreEqual((2, -1), n1); Assert.AreEqual((-1, 6), n2); Assert.AreEqual((-1, -1), n3); Assert.AreEqual((6, -1), n4); Assert.AreEqual((-1, -1), n5); Assert.AreEqual((7, -1), n6); Assert.AreEqual((9, 9), n7); Assert.AreEqual((-1, -1), n8); Assert.AreEqual((-1, -1), n9); //Assert.AreEqual((-1, -1), n10); #endregion #region Test Previous Assert.AreEqual(0, p0.Count); Assert.AreEqual(1, p1.Count); Assert.AreEqual(1, p2.Count); Assert.AreEqual(0, p3.Count); Assert.AreEqual(1, p4.Count); Assert.AreEqual(0, p5.Count); Assert.AreEqual(2, p6.Count); Assert.AreEqual(1, p7.Count); Assert.AreEqual(0, p8.Count); Assert.AreEqual(2, p9.Count); //Assert.AreEqual(2, p10.Count); Assert.AreEqual((0, false), p1[0]); Assert.AreEqual((1, false), p2[0]); Assert.AreEqual((0, true), p4[0]); Assert.AreEqual((2, true), p6[0]); Assert.AreEqual((4, false), p6[1]); Assert.AreEqual((6, false), p7[0]); //Assert.AreEqual((7, false), p10[0]); //Assert.AreEqual((7, true), p10[1]); #endregion }
public void Test_StaticFlow_Forward_1() { // test StaticFlow with no removal of empty lines string programStr = " jz label1 ;line 0 " + Environment.NewLine + " mov rax, 10 ;line 1 " + Environment.NewLine + " jmp label2 ;line 2 " + Environment.NewLine + "label1: ;line 3 " + Environment.NewLine + " mov rax, 20 ;line 4 " + Environment.NewLine + "label2: ;line 5 " + Environment.NewLine + " mov rbx, rax ;line 6 " + Environment.NewLine + " jz label3 ;line 7 " + Environment.NewLine + "label3: ;line 8 "; StaticFlow sFlow = new StaticFlow(new Tools()); bool removeEmptyLines = false; sFlow.Update(programStr, removeEmptyLines); if (logToDisplay) { Console.WriteLine(sFlow); } Assert.AreEqual(9, sFlow.NLines); Assert.AreEqual((1, 3), sFlow.Get_Next_LineNumber(0)); Assert.AreEqual((2, -1), sFlow.Get_Next_LineNumber(1)); Assert.AreEqual((-1, 5), sFlow.Get_Next_LineNumber(2)); Assert.AreEqual((4, -1), sFlow.Get_Next_LineNumber(3)); Assert.AreEqual((5, -1), sFlow.Get_Next_LineNumber(4)); Assert.AreEqual((6, -1), sFlow.Get_Next_LineNumber(5)); Assert.AreEqual((7, -1), sFlow.Get_Next_LineNumber(6)); Assert.AreEqual((8, 8), sFlow.Get_Next_LineNumber(7)); Assert.AreEqual((9, -1), sFlow.Get_Next_LineNumber(8)); var p0 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(0)); var p1 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(1)); var p2 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(2)); var p3 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(3)); var p4 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(4)); var p5 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(5)); var p6 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(6)); var p7 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(7)); var p8 = new List <(int LineNumber, bool IsBranch)>(sFlow.Get_Prev_LineNumber(8)); Assert.AreEqual(0, p0.Count); Assert.AreEqual(1, p1.Count); Assert.AreEqual(1, p2.Count); Assert.AreEqual(1, p3.Count); Assert.AreEqual(1, p4.Count); Assert.AreEqual(2, p5.Count); Assert.AreEqual(1, p6.Count); Assert.AreEqual(1, p7.Count); Assert.AreEqual(2, p8.Count); Assert.AreEqual((0, false), p1[0]); Assert.AreEqual((1, false), p2[0]); Assert.AreEqual((0, true), p3[0]); Assert.AreEqual((3, false), p4[0]); Assert.AreEqual((2, true), p5[0]); Assert.AreEqual((4, false), p5[1]); Assert.AreEqual((5, false), p6[0]); Assert.AreEqual((6, false), p7[0]); Assert.AreEqual((7, false), p8[0]); Assert.AreEqual((7, true), p8[1]); }
public void Test_DynamicFlow_Forward_1() { Tools tools = CreateTools(); tools.StateConfig.Set_All_Off(); tools.StateConfig.RAX = true; tools.StateConfig.RBX = true; tools.Quiet = true; tools.ShowUndefConstraints = false; string programStr = " mov rax, 0 ; line 0 " + Environment.NewLine + " mov rbx, 10 ; line 1 " + Environment.NewLine + " mov rbx, rax ; line 2 "; var sFlow = new StaticFlow(tools); sFlow.Update(programStr); if (logToDisplay) { Console.WriteLine(sFlow); } if (true) { DynamicFlow dFlow = Runner.Construct_DynamicFlow_Forward(sFlow, tools); if (logToDisplay) { Console.WriteLine(dFlow.ToString(sFlow)); } { int lineNumber = 0; IList <State> states_Before = new List <State>(dFlow.Create_States_Before(lineNumber)); Assert.AreEqual(1, states_Before.Count); State state_Before = states_Before[0]; IList <State> states_After = new List <State>(dFlow.Create_States_After(lineNumber)); Assert.AreEqual(1, states_After.Count); State state_After = states_After[0]; if (logToDisplay) { Console.WriteLine("Tree_Forward: Before lineNumber " + lineNumber + " \"" + sFlow.Get_Line_Str(lineNumber) + "\", we know:\n" + state_Before); } TestTools.AreEqual(Rn.RAX, "????????.????????.????????.????????.????????.????????.????????.????????", state_Before); TestTools.AreEqual(Rn.RBX, "????????.????????.????????.????????.????????.????????.????????.????????", state_Before); if (logToDisplay) { Console.WriteLine("Tree_Forward: After lineNumber " + lineNumber + " \"" + sFlow.Get_Line_Str(lineNumber) + "\", we know:\n" + state_After); } TestTools.AreEqual(Rn.RAX, 0, state_After); TestTools.AreEqual(Rn.RBX, "????????.????????.????????.????????.????????.????????.????????.????????", state_After); } { int lineNumber = 1; IList <State> states_Before = new List <State>(dFlow.Create_States_Before(lineNumber)); Assert.AreEqual(1, states_Before.Count); State state_Before = states_Before[0]; IList <State> states_After = new List <State>(dFlow.Create_States_After(lineNumber)); Assert.AreEqual(1, states_After.Count); State state_After = states_After[0]; if (logToDisplay) { Console.WriteLine("Tree_Forward: Before lineNumber " + lineNumber + " \"" + sFlow.Get_Line_Str(lineNumber) + "\", we know:\n" + state_Before); } TestTools.AreEqual(Rn.RAX, 0, state_Before); TestTools.AreEqual(Rn.RBX, "????????.????????.????????.????????.????????.????????.????????.????????", state_Before); if (logToDisplay) { Console.WriteLine("Tree_Forward: After lineNumber " + lineNumber + " \"" + sFlow.Get_Line_Str(lineNumber) + "\", we know:\n" + state_After); } TestTools.AreEqual(Rn.RAX, 0, state_After); TestTools.AreEqual(Rn.RBX, 10, state_After); } { int lineNumber = 2; IList <State> states_Before = new List <State>(dFlow.Create_States_Before(lineNumber)); Assert.AreEqual(1, states_Before.Count); State state_Before = states_Before[0]; IList <State> states_After = new List <State>(dFlow.Create_States_After(lineNumber)); Assert.AreEqual(1, states_After.Count); State state_After = states_After[0]; if (logToDisplay) { Console.WriteLine("Tree_Forward: Before lineNumber " + lineNumber + " \"" + sFlow.Get_Line_Str(lineNumber) + "\", we know:\n" + state_Before); } TestTools.AreEqual(Rn.RAX, 0, state_Before); TestTools.AreEqual(Rn.RBX, 10, state_Before); if (logToDisplay) { Console.WriteLine("Tree_Forward: After lineNumber " + lineNumber + " \"" + sFlow.Get_Line_Str(lineNumber) + "\", we know:\n" + state_After); } TestTools.AreEqual(Rn.RAX, 0, state_After); TestTools.AreEqual(Rn.RBX, 0, state_After); } } }
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_5() { string programStr = " jz label1 " + Environment.NewLine + " mov rax, 10 " + Environment.NewLine + " jmp label2 " + Environment.NewLine + "label1: " + Environment.NewLine + " mov rax, 20 " + Environment.NewLine + "label2: "; Tools tools = this.CreateTools(); StaticFlow sFlow = new StaticFlow(tools); sFlow.Update(programStr); tools.StateConfig = sFlow.Create_StateConfig(); //var dFlow = Runner.Construct_DynamicFlow_Backward(sFlow, tools); DynamicFlow dFlow = Runner.Construct_DynamicFlow_Forward(sFlow, tools); bool logToDisplay2 = true; tools.Quiet = true;// !logToDisplay2; State state = dFlow.EndState; Assert.IsNotNull(state); if (logToDisplay2) { Console.WriteLine("state:\n" + state); } TestTools.IsTrue(state.IsConsistent); TestTools.AreEqual(Rn.RAX, "00000000_00000000_00000000_00000000_00000000_00000000_00000000_000????0", state); Microsoft.Z3.BoolExpr branch_Condition = dFlow.Get_Branch_Condition(0); if (logToDisplay2) { Console.WriteLine("Branch Condition:" + branch_Condition); } { State state2a = new State(state); state2a.Add(new BranchInfo(branch_Condition, true)); if (logToDisplay2) { Console.WriteLine("state with ZF = true:\n" + state2a); } TestTools.IsTrue(state2a.IsConsistent); TestTools.AreEqual(Rn.RAX, 10, state2a); // TODO why is 10 / 20 reversed? } { State state2b = new State(state); state2b.Add(new BranchInfo(branch_Condition, false)); if (logToDisplay2) { Console.WriteLine("state with ZF = false:\n" + state2b); } TestTools.IsTrue(state2b.IsConsistent); TestTools.AreEqual(Rn.RAX, 20, state2b); } }
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); } } }