Пример #1
0
        public void Test_MemZ3_Forward_SetGet0()
        {
            StateConfig stateConfig = new StateConfig();

            stateConfig.Set_All_Off();
            stateConfig.RAX = true;
            stateConfig.RBX = true;
            stateConfig.Mem = true;

            State   state = this.CreateState(stateConfig);
            Context ctx   = state.Ctx;
            Tools   tools = state.Tools;

            BitVecExpr address1 = Tools.Calc_Effective_Address("qword ptr[rax]", state.HeadKey, tools, ctx);
            BitVecExpr value1   = state.Create(Rn.RBX);

            using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools))
            {
                updateState.Set_Mem(address1, value1);
                state.Update_Forward(updateState);
            }
            BitVecExpr value2 = state.Create_Mem(address1, 8);

            if (LogToDisplay)
            {
                Console.WriteLine("value1 = " + value1);
                Console.WriteLine("value2 = " + value2);
                Console.WriteLine(state);
            }
            Assert.AreEqual(Tv.ONE, state.EqualValues(value1, value2));
        }
Пример #2
0
        public void Test_MemZ3_Forward_Eq1()
        {
            StateConfig stateConfig = new StateConfig();

            stateConfig.Set_All_Off();
            stateConfig.RAX = true;
            stateConfig.RBX = true;
            stateConfig.RCX = true;
            stateConfig.Mem = true;

            State   state = this.CreateState(stateConfig);
            Context ctx   = state.Ctx;
            Tools   tools = state.Tools;

            using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools))
            {
                // updateState.Set(Rn.RAX, 20);
                updateState.Set(Rn.RBX, 10);
                updateState.Set(Rn.RCX, 5);
                state.Update_Forward(updateState);
            }
            // TestTools.AreEqual(Rn.RAX, 20, state);
            AsmTestTools.AreEqual(Rn.RBX, 10, state);
            AsmTestTools.AreEqual(Rn.RCX, 5, state);

            BitVecExpr address1 = Tools.Calc_Effective_Address("qword ptr[rax + 2 * rbx + 10]", state.HeadKey, tools, ctx);
            BitVecExpr address2 = Tools.Calc_Effective_Address("qword ptr[rax + 4 * rcx + 10]", state.HeadKey, tools, ctx);

            Tv equalAddresses = state.EqualValues(address1, address2);

            if (LogToDisplay)
            {
                Console.WriteLine("equalAddresses=" + equalAddresses);
                Console.WriteLine("address1 = " + address1);
                Console.WriteLine("address2 = " + address2);
                Console.WriteLine(state);
            }
            AsmTestTools.AreEqual(Tv.ONE, equalAddresses);

            BitVecExpr value1 = state.Create(Rn.R8);

            using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools))
            {
                updateState.Set_Mem(address1, value1);
                state.Update_Forward(updateState);
            }
            BitVecExpr value2 = state.Create_Mem(address2, 8);

            if (LogToDisplay)
            {
                Console.WriteLine("value1 = " + value1);
                Console.WriteLine("value2 = " + value2);
                Console.WriteLine(state);
            }
            AsmTestTools.AreEqual(Tv.ONE, state.EqualValues(value1, value2));
        }
Пример #3
0
        public void Test_MemZ3_Forward_Eq5()
        {
            StateConfig stateConfig = new StateConfig();

            stateConfig.Set_All_Off();
            stateConfig.RAX = true;
            stateConfig.RBX = true;
            stateConfig.RCX = true;
            stateConfig.RDX = true;
            stateConfig.Mem = true;

            State   state = this.CreateState(stateConfig);
            Context ctx   = state.Ctx;
            Tools   tools = state.Tools;

            {
                StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools);
                updateState.Set(Rn.RAX, state.Create(Rn.RBX));
                state.Update_Forward(updateState);
            }
            BitVecExpr address1 = Tools.Calc_Effective_Address("byte ptr[rax]", state.HeadKey, tools, ctx);
            BitVecExpr address2 = Tools.Calc_Effective_Address("byte ptr[rbx]", state.HeadKey, tools, ctx);
            BitVecExpr value1a  = state.Create(Rn.CL);
            BitVecExpr value2a  = state.Create(Rn.DL);

            Debug.Assert(value1a.SortSize == value2a.SortSize);
            int nBytes = (int)value1a.SortSize >> 3;

            using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools))
            {
                updateState.Set_Mem(address1, value1a);
                state.Update_Forward(updateState);
            }
            BitVecExpr value1b = state.Create_Mem(address1, nBytes);

            using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools))
            {
                updateState.Set_Mem(address2, value2a);
                state.Update_Forward(updateState);
            }
            BitVecExpr value2b = state.Create_Mem(address2, nBytes);

            if (LogToDisplay)
            {
                Console.WriteLine("value1a = " + value1a);
                Console.WriteLine("value2a = " + value2a);
                Console.WriteLine("value1b = " + value1b);
                Console.WriteLine("value2b = " + value2b);
                Console.WriteLine(state);
            }
            AsmTestTools.AreEqual(Tv.ONE, state.EqualValues(value1a, value1b));
            AsmTestTools.AreEqual(Tv.ONE, state.EqualValues(value2a, value2b));
        }
Пример #4
0
        public void Test_MemZ3_Forward_Eq6()
        {
            StateConfig stateConfig = new StateConfig();

            stateConfig.Set_All_Off();
            stateConfig.RAX = true;
            stateConfig.RBX = true;
            stateConfig.RCX = true;
            stateConfig.RDX = true;
            stateConfig.Mem = true;

            State   state = this.CreateState(stateConfig);
            Context ctx   = state.Ctx;
            Tools   tools = state.Tools;

            Rn  reg1   = Rn.CL;
            Rn  reg2   = Rn.DL;
            int nBytes = RegisterTools.NBits(reg1) >> 3;

            Debug.Assert(RegisterTools.NBits(reg1) == RegisterTools.NBits(reg2));

            BitVecExpr address1 = Tools.Calc_Effective_Address("qword ptr[rax]", state.HeadKey, tools, ctx);
            BitVecExpr address2 = Tools.Calc_Effective_Address("qword ptr[rbx]", state.HeadKey, tools, ctx);

            BitVecExpr value1 = state.Create_Mem(address1, nBytes);
            BitVecExpr value2 = state.Create_Mem(address2, nBytes);

            Assert.AreNotEqual(value1, value2); // value1 is not equal to value2 simply because rax and rbx are not related yet

            state.Add(new BranchInfo(state.Ctx.MkEq(state.Create(Rn.RAX), state.Create(Rn.RBX)), true));
            // value1 and value2 are now (intuitively) equal; however, the retrieved memory values have not been updated yet to reflect this.

            using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools))
            {
                updateState.Set(reg1, value1);
                updateState.Set(reg2, value2);
                state.Update_Forward(updateState);
            }
            if (LogToDisplay)
            {
                Console.WriteLine("value1 = " + value1);
                Console.WriteLine("value2 = " + value2);
                Console.WriteLine(reg1 + " = " + state.Create(reg1));
                Console.WriteLine(reg2 + " = " + state.Create(reg2));
                Console.WriteLine(state);
            }
            AsmTestTools.AreEqual(Tv.ONE, state.EqualValues(reg1, reg2));
        }
Пример #5
0
        public void Test_MemZ3_Forward_Eq3()
        {
            StateConfig stateConfig = new StateConfig();

            stateConfig.Set_All_Off();
            stateConfig.RAX = true;
            stateConfig.RBX = true;
            stateConfig.RCX = true;
            stateConfig.R8  = true;
            stateConfig.Mem = true;

            State   state = this.CreateState(stateConfig);
            Context ctx   = state.Ctx;
            Tools   tools = state.Tools;

            using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools))
            {
                updateState.Set(Rn.RBX, 10);
                updateState.Set(Rn.RCX, 5);
                state.Update_Forward(updateState);
            }
            BitVecExpr address1 = Tools.Calc_Effective_Address("qword ptr[rax + 2 * rbx + 10]", state.HeadKey, tools, ctx);
            {
                StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools);
                updateState.Set(Rn.RAX, state.Ctx.MkBVAdd(state.Create(Rn.RAX), state.Ctx.MkBV(0, 64)));
                state.Update_Forward(updateState);
            }
            BitVecExpr address2 = Tools.Calc_Effective_Address("qword ptr[rax + 4 * rcx + 10]", state.HeadKey, tools, ctx);

            BitVecExpr value1 = state.Create(Rn.R8B);
            int        nBytes = (int)value1.SortSize >> 3;

            using (StateUpdate updateState = new StateUpdate(state.HeadKey, Tools.CreateKey(tools.Rand), tools))
            {
                updateState.Set_Mem(address1, value1);
                state.Update_Forward(updateState);
            }
            BitVecExpr value2 = state.Create_Mem(address2, nBytes);

            if (LogToDisplay)
            {
                Console.WriteLine("value1 = " + value1);
                Console.WriteLine("value2 = " + value2);
                Console.WriteLine(state);
            }
            AsmTestTools.AreEqual(Tv.ONE, state.EqualValues(value1, value2));
        }