Esempio n. 1
0
        public override Block VisitBlock(Block node)
        {
            foreach (Cmd c in node.Cmds)
            {
                AssignCmd ac = c as AssignCmd;
                if (ac == null)
                {
                    continue;
                }
                Utils.Assert(ac.Lhss.Count == 1 && ac.Rhss.Count == 1, "Expected assignments to have 1 lhs and 1 rhs");
                AssignLhs lhs = ac.Lhss.ElementAt(0);
                Expr      rhs = ac.Rhss.ElementAt(0);

                if (!(lhs.Type.IsBv && lhs.DeepAssignedIdentifier.Name.Equals("RSP")))
                {
                    continue;
                }                                                                                    //lhs is RSP
                if (!(rhs is NAryExpr))
                {
                    continue;
                }                                     //rhs is function application
                if (!((NAryExpr)rhs).Fun.FunctionName.Equals("MINUS_64"))
                {
                    continue;
                }                                                                       //rhs is a minus operation
                if (!(((NAryExpr)rhs).Args.ElementAt(0) is IdentifierExpr))
                {
                    continue;
                }                                                                         //1st argument is a id like RHS
                if (!(((NAryExpr)rhs).Args.ElementAt(0) as IdentifierExpr).Name.Equals("RSP"))
                {
                    continue;
                }                                                                                            //1st argument is a id like RHS
                if (!(((NAryExpr)rhs).Args.ElementAt(1) is LiteralExpr))
                {
                    continue;
                }                                                                      //2nd argument is a constant like 384bv64
                if (!((((NAryExpr)rhs).Args.ElementAt(1) as LiteralExpr).Type == BType.GetBvType(64)))
                {
                    continue;
                }                                                                                                    //2nd argument is bitvector literal

                int operand = ((((NAryExpr)rhs).Args.ElementAt(1) as LiteralExpr).asBvConst).Value.ToInt;

                Utils.Assert(blocksWithinNautralLoops.All(x => x.Label != node.Label),
                             "Setting RSP within a loop: " + ac + " at label " + node.Label);

                rsp_subtractions.Add(operand);
            }

            return(base.VisitBlock(node));
        }
Esempio n. 2
0
        public void UninterpretedFunction()
        {
            var FCB      = new Symbooglix.FunctionCallBuilder();
            var funcCall = FCB.CreateCachedUninterpretedFunctionCall(
                "foo",
                BType.Bool, // Return type
                new List <Microsoft.Boogie.Type>()
            {
                BType.GetBvType(32), BType.GetBvType(32)
            }
                );

            Assert.IsNotNull(ExprUtil.AsUninterpretedFunction(funcCall.Func));

            var sb       = GetSimpleBuilder();
            var callFunc = sb.UFC(funcCall, sb.ConstantBV(0, 32), sb.ConstantBV(1, 32));
            var asUF     = ExprUtil.AsUninterpretedFunctionCall(callFunc);

            Assert.IsNotNull(asUF);
        }
        public override Program VisitProgram(Program node)
        {
            this.plus_64   = Utils.FindFunctionInProgram(node, "PLUS_64");
            this.not_1     = Utils.FindFunctionInProgram(node, "NOT_1");
            this.rep_stosb = Utils.FindFunctionInProgram(node, "REP_STOSB");
            this.policy    = Utils.FindFunctionInProgram(node, "policy");

            this.mem = node.GlobalVariables.FirstOrDefault(x => x.Name.Equals("mem"));
            Utils.Assert(this.mem != null, "Could not find mem variable");

            //this has been moved to Bap2Boogie, but let's just have it here as well
            foreach (String name in new List <String>()
            {
                "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15",
                "RAX", "RBX", "RCX", "RDX", "RBP", "RDI", "RSI", "RSP"
            })
            {
                GlobalVariable gv = node.GlobalVariables.FirstOrDefault(x => x.Name.Equals(name));
                if (gv == null) //not found, so let's add it in ourself
                {
                    node.AddTopLevelDeclaration(new GlobalVariable(Token.NoToken,
                                                                   new TypedIdent(Token.NoToken, name, BType.GetBvType(64))));
                }
            }

            foreach (String name in new List <String>()
            {
                "AF", "CF", "OF", "PF", "SF", "ZF"
            })
            {
                GlobalVariable gv = node.GlobalVariables.FirstOrDefault(x => x.Name.Equals(name));
                if (gv == null) //not found, so let's add it in ourself
                {
                    node.AddTopLevelDeclaration(new GlobalVariable(Token.NoToken,
                                                                   new TypedIdent(Token.NoToken, name, BType.GetBvType(1))));
                }
            }

            this.RSP = Utils.FindGlobalVariableInProgram(node, "RSP");
            this.RAX = Utils.FindGlobalVariableInProgram(node, "RAX");
            this.RDI = Utils.FindGlobalVariableInProgram(node, "RDI");
            this.RDX = Utils.FindGlobalVariableInProgram(node, "RDX");
            this.R8  = Utils.FindGlobalVariableInProgram(node, "R8");
            this.R9  = Utils.FindGlobalVariableInProgram(node, "R9");
            this.R10 = Utils.FindGlobalVariableInProgram(node, "R10");
            this.R11 = Utils.FindGlobalVariableInProgram(node, "R11");
            this.RCX = Utils.FindGlobalVariableInProgram(node, "RCX");
            this.CF  = Utils.FindGlobalVariableInProgram(node, "CF");

            foreach (String s in new HashSet <String>()
            {
                Options.funcMemcmp, Options.funcMemcpy, Options.funcMemset, Options.funcSGXFree, Options.funcSGXMalloc
            })
            {
                int location = Int32.Parse(s.ToUpper(), System.Globalization.NumberStyles.HexNumber);
                node.AddTopLevelDeclaration(new Axiom(Token.NoToken,
                                                      new NAryExpr(Token.NoToken, new FunctionCall(this.policy),
                                                                   new List <Expr>()
                {
                    new LiteralExpr(Token.NoToken, BigNum.FromInt(location), 64)
                })));
            }

            return(base.VisitProgram(node));
        }