Exemplo n.º 1
0
        public void TestBase16Encode()
        {
            string     bek    = @"
function E(x)=ite(x < 10, x + 48, x + 55);
program base16encode(input){ 
  replace {
    @""[\0-\xFF]""  ==> [E(#0 >> 4),E(#0 & 0xF)];
  }
}
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);
            var        test   = BekConverter.BekToSTb(solver, bek).ExploreBools();
            //test.ToST().ShowGraph();

            StringBuilder sb = new StringBuilder();

            test.ToJS(x => { sb.AppendLine(x); return; });

            var meth = test.Compile();

            var res = meth.Apply("012");

            Assert.AreEqual <string>("303132", res);

            res = meth.Apply("\0\x01\x02\x03");
            Assert.AreEqual <string>("00010203", res);
        }
Exemplo n.º 2
0
        public void TestHtmlDecode1b()
        {
            string     bek    = @"
program B(input){replace{
    ""&#00;""       ==> ""&#00;""; //dont decode
    ""&#[0-9]{2};"" ==> [(10*(#2-48))+(#3-48)];  //decode
    ""&#$"" ==> ""&#"";  //keep
    else            ==> [#0]; //default
  };
}
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);
            var        test   = BekConverter.BekToSTb(solver, bek).ExploreBools();

            var css = solver.CharSetProvider;

            StringBuilder sb = new StringBuilder();

            test.ToJS(x => { sb.AppendLine(x); return; });

            var meth = test.Compile();

            var res = meth.Apply("&&#00;&#38;&#");

            Assert.AreEqual <string>("&&#00;&&#", res);

            var res2 = meth.Apply(res);

            Assert.AreEqual <string>(res, res2);
        }
Exemplo n.º 3
0
        public void TestBase64Encode()
        {
            string     bek    = @"

function E(x)=(ite(x<=25,x+65,ite(x<=51,x+71,ite(x<=61,x-4,ite(x==62,'+','/')))));

program base64encode(_){ 
  replace {
    @""[\0-\xFF]{3}""  ==> [E(Bits(7,2,#0)), E((Bits(1,0,#0)<<4)|Bits(7,4,#1)), E((Bits(3,0,#1)<<2)|Bits(7,6,#2)), E(Bits(5,0,#2))];
    @""[\0-\xFF]{2}$"" ==> [E(Bits(7,2,#0)), E((Bits(1,0,#0)<<4)|Bits(7,4,#1)), E(Bits(3,0,#1)<<2), '='];
    @""[\0-\xFF]$""    ==> [E(Bits(7,2,#0)), E(Bits(1,0,#0)<<4), '=', '='];
  }
}
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);
            var        test   = BekConverter.BekToSTb(solver, bek).ExploreBools();
            //test.ToST().ShowGraph();

            StringBuilder sb = new StringBuilder();

            test.ToJS(x => { sb.AppendLine(x); return; });

            var meth = test.Compile();

            Assert.AreEqual <string>("TWFu", meth.Apply("Man"));
        }
Exemplo n.º 4
0
        public void TestBase64Decode()
        {
            string     bek    = @"
function D(x)=(ite(x=='/',63,ite(x=='+',62,ite(x<='9',x+4,ite(x<='Z',x-65,x-71)))));
program base64decode(_){ 
  replace {
    ""[a-zA-Z0-9+/]{4}""   ==> [(D(#0)<<2)|bits(5,4,D(#1)), (bits(3,0,D(#1))<<4)|bits(5,2,D(#2)), (bits(1,0,D(#2))<<6)|D(#3)];
    ""[a-zA-Z0-9+/]{3}=$"" ==> [(D(#0)<<2)|bits(5,4,D(#1)), (bits(3,0,D(#1))<<4)|bits(5,2,D(#2))];
    ""[a-zA-Z0-9+/]{2}==$""==> [(D(#0)<<2)|bits(5,4,D(#1))];
  }
}
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);

            var x = solver.MkVar(1, solver.IntSort);

            Console.WriteLine(((IntSymbol)x.FuncDecl.Name).Int);

            var test = BekConverter.BekToSTb(solver, bek).ExploreBools();
            //test.ToST().ShowGraph();

            var meth = test.Compile();

            Assert.AreEqual <string>("Man", meth.Apply("TWFu"));
        }
Exemplo n.º 5
0
        public void Test_a2b_Error()
        {
            string     bek    = @"
program a2b(_){ 
  replace {
     ""a"" ==> ""b""; 
  };
}";
            Z3Provider solver = new Z3Provider();
            var        st     = BekConverter.BekToSTb(solver, bek).ExploreBools();
            var        meth   = st.Compile();

            try
            {
                meth.Apply("a_a_a___");
                Assert.IsTrue(false);
            }
            catch (Exception e)
            {
                Assert.AreEqual <string>("a2b", e.Message);
            }
            var res = meth.Apply("aaa");

            Assert.AreEqual <string>("bbb", res);
        }
Exemplo n.º 6
0
        public void TestHtmlEncodeStrictJSgen()
        {
            string bek = @"
function H(x) = ite((0 <= x) && (x <= 9), x + 48, x + 55);
program HtmlEncode(_){ 
  replace {
    ""<""   ==> ""&lt;"";
    "">""   ==> ""&gt;"";
    ""\x22""==> ""&quot;"";
    ""&""   ==> ""&amp;"";
    ""\'""  ==> ""&apos;"";
    //encode all control and non ascii chars
    @""[\x01-\x0F]""          ==> ['&','#','X', H(#0), ';']; //do not encode \0
    @""[\x10-\x1F\x7F-\xFF]"" ==> ['&','#','X', H(#0 >> 4), H(#0 & 0xF), ';'];
    @""[\u0100-\u0FFF]""      ==> ['&','#','X', H(#0 >> 8), H((#0 >> 4) & 0xF), H(#0 & 0xF), ';'];
    @""[\u1000-\uFFFF]""      ==> ['&','#','X', H(#0 >> 12), H((#0 >> 8) & 0xF), H((#0 >> 4) & 0xF), H(#0 & 0xF), ';'];
    else ==> [#0];
}}
";
            //fixed HtmlDecode patterns

            StringBuilder sb     = new StringBuilder(bek);
            Z3Provider    solver = new Z3Provider(BitWidth.BV16);
            var           test   = BekConverter.BekToSTb(solver, sb.ToString());
            var           test1  = test.ExploreBools();
            //test1.ToST().ShowGraph();

            //test1.ToJS("../../../GeneratedCodeSamples/HtmlEncodeStrict.html", true);
        }
Exemplo n.º 7
0
        public void TestDigitToCode()
        {
            string digit  = "\"[0-9]\"";
            string bek1   = @"
function dec(x)=(x-48);
program ToUpper1(w) {
   return iter(c in w) {
      case (c in " + digit + @"):
         yield(dec(c));
      case (true):
         yield();
   };
}
";
            string bek2   = @"
program ToUpper2(w) {
   return iter(c in w) {
      case (c in " + digit + @"):
         yield(c - '0');
      case (true):
         yield();
   };
}
";
            var    solver = new Z3Provider();
            var    st1    = BekConverter.BekToST(solver, bek1);
            var    st2    = BekConverter.BekToST(solver, bek2);
            bool   eq     = st1.Eq1(st2);

            Assert.IsTrue(eq);
        }
Exemplo n.º 8
0
        public void TestBitvectorOps()
        {
            string noop = @"

program noop(w) {
   return iter(c in w) {
      case (c <= 0xFF):
         yield((((c >> 4) & 0xF) << 4)|(c & 0xF));
      case (true):
         yield(c);
      };
}
";

            string triv   = @"

program triv(w) {
   return iter(c in w) {
      case (true):
         yield(c);
      };
}
";
            var    solver = new Z3Provider();
            var    A      = BekConverter.BekToST(solver, noop);
            var    B      = BekConverter.BekToST(solver, triv);
            bool   equiv  = A.Eq1(B);

            Assert.IsTrue(equiv);
            //A.ShowGraph();
        }
Exemplo n.º 9
0
        public void TestLocalFunc()
        {
            string     pgm    = @"

function bar(x, y) = (y + x);
function foo(x) = bar(x,1);

program incr(w) {
   return iter(c in w) {
      case(((foo(c)-1)==c)&&true||false):
         yield(c + 0 + 1);
      };
}
";
            Z3Provider solver = new Z3Provider();
            var        st     = BekConverter.BekToST(solver, pgm);

            Assert.AreEqual(1, st.StateCount);
            var moves = new List <Move <Rule <Expr> > >(st.GetNonFinalMovesFrom(st.InitialState));

            Assert.AreEqual(1, moves.Count);
            var move = moves[0];

            Assert.AreEqual(solver.True, move.Label.Guard);
        }
Exemplo n.º 10
0
        public void TestSanitize()
        {
            string     pgm    = @"
program sanitize(t) {
return iter(c in t)[ b := false; d := '$'; ]
     {
       case (!b && ((c == '\'') || (c == '\" + "\"" + @"'))) :
	     b := false; yield ('\\', c); 
       case (c == '\\') : b := !b; yield (c);     
       case (true)  : b := false; yield (c);
     };
}";
            Z3Provider solver = new Z3Provider();
            var        st1    = BekConverter.BekToST(solver, pgm).ExploreBools();

            //st1.ShowGraph();

            var st = st1 + st1;

            st.Simplify();

            //st.ShowGraph();

            var sft = st.ExploreBools();

            //sft.ShowGraph();

            Assert.IsTrue(sft.Eq1(st1));

            Assert.AreEqual <int>(2, sft.StateCount);
        }
Exemplo n.º 11
0
        public void TestCharIn2()
        {
            string alpha = @"

program alpha(w) {
   return iter(c in w) {
      case(c in " + "\"[a-d]\"" + @"):
	     yield('x');
      case(true):
         yield(c);
      };
}
";

            string     beta   = @"

program beta(w) {
   return iter(c in w) {
      case((c >= 'a') && (c <= 'z')):
	     yield('y');
      };
}
";
            Z3Provider solver = new Z3Provider();
            var        aST    = BekConverter.BekToST(solver, alpha);
            var        bST    = BekConverter.BekToST(solver, beta);
            bool       equiv  = STModel.Eq1(aST, bST);

            Assert.IsFalse(equiv);

            //aST.ShowGraph();
            //bST.ShowGraph();
        }
Exemplo n.º 12
0
        public void Test_a2b()
        {
            string     bek    = @"
program a2b(_){replace{""a"" ==> ""bb""; else ==> [#0];};}
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);
            var        test   = BekConverter.BekToSTb(solver, bek).ExploreBools();

            var css = solver.CharSetProvider;

            StringBuilder sb = new StringBuilder();

            test.ToJS(x => { sb.AppendLine(x); return; });

            var meth = test.Compile();
            //test.ShowGraph();

            var res = meth.Apply("aaac");

            Assert.AreEqual <string>("bbbbbbc", res);

            var res2 = meth.Apply(res);

            Assert.AreEqual <string>(res, res2);
        }
Exemplo n.º 13
0
        public void TestEndAnchor()
        {
            string     bek    = @"
program sample(_){ 
  replace {
    ""ab$"" ==> ""123="";
    ""a$""  ==> ""12=="";
}}
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);
            var        test   = BekConverter.BekToSTb(solver, bek);
            var        test1  = test.ExploreBools();
            //test1.ShowGraph();
            var meth = test1.Compile();

            //just test on couple of samples
            Assert.AreEqual <string>("123=", meth.Apply("ab"));
            Assert.AreEqual <string>("12==", meth.Apply("a"));
            //must throw in other cases
            try
            {
                meth.Apply("abab");
                Assert.Fail("meth did not throw an excetion");
            }
            catch (Exception e)
            {
                Assert.AreEqual <string>("sample_B", e.Message);
            }
        }
Exemplo n.º 14
0
        public void TestRegexEscaping()
        {
            string     bek    = @"
program RegexEscape(_){ replace {
  ""\t"" ==> ""\\t"";
  ""\n"" ==> ""\\n"";
  ""\f"" ==> ""\\f"";
  ""\r"" ==> ""\\r"";
  @""(\ |\#|\$|\(|\)|\*|\+|\.|\?|\[|\\|\^|\{|\|)"" ==> ['\\',#0];
  else ==> [#0];
}}
//==
//js(RegexEscape);
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);
            var        stb    = BekConverter.BekToSTb(solver, bek);
            var        st     = stb.ExploreBools().ToST();
            //st.ShowGraph();
            var meth = st.STb.Compile();

            //st.STb.ToJS("../../../GeneratedCodeSamples/RegexEscape.html", true);

            //just test on couple of samples
            Assert.AreEqual <string>(@"\\\.\$xabc\^", meth.Apply(@"\.$xabc^"));
            Assert.AreEqual <string>(@"\(\)\[]\{}\?\.\|", meth.Apply(@"()[]{}?.|"));
        }
Exemplo n.º 15
0
        public void TestRaiseStmt()
        {
            string     pgm    = @"
program dummy(t) { 
  return iter(c in t) [r := 0;]{
    case (c > 'z'): 
      r := 0;
      yield (c + 1);
    case (c < '9'):
      raise E1;
    case (c < 'z'):
      r := 1;
      yield (c + c);
    case (true):
      raise E2;
    }end{
    case(r == 0):
      yield('h','e','l','l','o');
    case(true):
      raise E3;
    }; 
}";
            Z3Provider solver = new Z3Provider();
            var        stb    = BekConverter.BekToSTb(solver, pgm);
            //stb.ShowGraph();
            //stb.ToST().ShowGraph();
            //stb.ToST().Explore().ShowGraph();
        }
Exemplo n.º 16
0
 public void TestDecodeDigitPairs()
 {
     Z3Provider solver = new Z3Provider();
     var st = BekConverter.BekFileToSTb(solver, sampleDir + "bek/DecodeDigitPairs.bek");
     //st.ShowGraph();
     var f1 = st.Explore();                        //convert to SFT by exploring the register
     //f1.ToCSt("../../../src/Bek.Query.Tests/DecodeDigitPairs.cs", "", "Experiments", "DecodeDigitPairs");
     //f1.ToDot("../../../src/Bek.Query.Tests/DecodeDigitPairs.dot");
     //f1.ShowGraph();
     var f = f1.ToST();
     var fof = f + f;                             //functional composition
     bool idempotent = f.Eq1(fof);                //check idempotence
     if (!idempotent)
     {
         var w = f.Diff(fof);                     //find a witness where f and fof differ
         string input = w.Input.StringValue;      // e.g. "5555"
         string output1 = w.Output1.StringValue;  // e.g. f("5555") == "77"
         string output2 = w.Output2.StringValue;  // e.g. f(f("5555")) == "M"
         Console.WriteLine("not idempotent, witness: {0}, {1}, {2}", input, output1, output2);
     }
     else
     {
         Console.WriteLine("idempotent");
     }
 }
Exemplo n.º 17
0
        public void TestSTbComposition3()
        {
            string     pgm    = @"
function HS(x) = ((55296 <= x) && (x <= 56319));
function LS(x) = ((56320 <= x) && (x <= 57343));
program Fix(t) { 
  return iter(c in t)[q0 := true; r := 0;] {
    case (q0): 
      if (HS(c)) {r := c;q0:=false;}
      else {
        if (LS(c)) { yield(0xFFFD); r:=0;}
        else {yield(c); r:=0;}
      }
    case (true):
      if (HS(c)) {yield(0xFFFD); r := c;}
      else { 
        if (LS(c)) {yield(r,c); r:=0; q0:=true;}
        else {yield(0xFFFD,c); r:=0; q0:=true;}
      }
    } end {
   case (!q0):
      yield (0xFFFD);
};
}";
            Z3Provider solver = new Z3Provider();
            var        A      = BekConverter.BekToSTb(solver, pgm).ExploreBools();
            //A.ShowGraph();
            var AA   = A.Compose(A);
            var AAAA = AA.Compose(AA);
            //AA.ShowGraph();
            var C = AAAA.Simplify(3);
            // AAs.ShowGraph();
        }
Exemplo n.º 18
0
        public void TestSTbSimplify0()
        {
            string     pgm    = @"
program test(input){
  return iter(c in input)[q := true; r := 0;]
  {
    case (q): 
      r := r + c;
      q := false;
    case (!q):
      r := 0;
      q := true;
    end case (true):
      yield(r);
  };
}
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);
            var        dec    = BekConverter.BekToSTb(solver, pgm);
            var        st     = dec.ExploreBools();
            var        sts    = st.Simplify();

            Assert.AreEqual <int>(2, st.StateCount);
            var st_st = st.Compose(st).ExploreBools();

            Assert.AreEqual <int>(2, st_st.StateCount);
        }
Exemplo n.º 19
0
        public void TestSTbComposition0()
        {
            string     pgm    = @"
program A(t) { 
  return iter(c in t)[q := 0;] {
    case ((q == 0) && (c == 'a')): 
        yield (c); 
        q:= 1;
   case ((q == 1) && (c == 'a')): 
      yield (c+1);
      q := 0;
  case ((q == 1) && (c == 'b')): 
      yield (c); 
      q:= 1;
  case (true):
      raise error;
    } end {
   case (q == 1):
      raise error;
};
}";
            Z3Provider solver = new Z3Provider();
            var        A      = BekConverter.BekToSTb(solver, pgm).ExploreBools();
            var        AA     = A.Compose(A);
            var        AAs    = AA.Simplify();

            var A_exe = A.Compile();
            var s     = A_exe.Apply("aaaa");

            Assert.AreEqual <string>("abab", s);
        }
Exemplo n.º 20
0
        public void TestSTbComposition2()
        {
            string     pgm    = @"
program A(t) { 
  return iter(c in t)[b := false; r := 0;] {
    case (b): 
      if (r == c) {yield();}
      else {yield(c); r:= c;}
    case (true):
      r := c; b := true; 
      yield(c);
    } end {
   case (true):
      yield ();
};
}";
            Z3Provider solver = new Z3Provider();
            var        A      = BekConverter.BekToSTb(solver, pgm).ExploreBools();
            //A.ShowGraph();
            var AA = A.Compose(A);
            //AA.ShowGraph();

            var A_exe = A.Compile();
            var s     = A_exe.Apply("00001111122333");

            Assert.AreEqual <string>("0123", s);

            var AA_exe = AA.Compile();
            var s2     = AA_exe.Apply("00001111122333");

            Assert.AreEqual <string>("0123", s2);
        }
Exemplo n.º 21
0
        public void TestExplore1()
        {
            string     pgm    = @"
program IfThenElseSample(t) { 
  return iter(c in t) [r := 0; s := 0;]{
    case ((c >= 'A') && (c <= 'B')): 
      if (c < 'B') {
        yield (c+1);
      } else {
        yield (c,c);
        r := 1;
      }
    case(true):
      raise E1;
    } end {
    case (r == 0):
      raise E2;
    case (true):
      yield ();
    };
}";
            Z3Provider solver = new Z3Provider();
            var        stb    = BekConverter.BekToSTb(solver, pgm);
            //stb.ToST().ShowGraph(1);
            var sft = stb.Explore();

            //sft.ToST().ShowGraph(1);
            Assert.AreEqual <int>(2, sft.StateCount);
            CheckFullEquivalence(sft.ToST(), stb.ToST());
        }
Exemplo n.º 22
0
 public void TestSFTwithPC()
 {
     var solver = new Z3Provider();
     var d      = System.Environment.CurrentDirectory;
     var stb    = BekConverter.BekFileToSTb(solver, sampleDir + "bek/decode.bek").ExploreBools();
     //stb.ShowGraph(10);
 }
Exemplo n.º 23
0
        public void TestIfThenElseStmt()
        {
            string     pgm    = @"
program IfThenElseSampleTmp(t) { 
  return iter(c in t) [r := 0;]{
    case (c > 10): 
      if (c < 20) {
        yield (c+1);
      } else {
        yield (c-1);
        r := 1;
      }
    case(true):
      raise X;
    } end {
    case (r == 0):
      raise Y;
    case (true):
      yield ();
    };
}";
            Z3Provider solver = new Z3Provider();
            var        stb    = BekConverter.BekToSTb(solver, pgm);
            //stb.Explore().ShowGraph();
            //stb.ShowGraph();
            //stb.ToST().ShowGraph();
            //stb.Explore().ShowGraph();
        }
Exemplo n.º 24
0
        //[TestMethod]
        public void TestCssEncode5()
        {
            var solver = new Z3Provider();
            var stb    = BekConverter.BekFileToSTb(solver, sampleDir + "bek/CssEncode5.bek");
            //stb.Explore().ShowGraph();
            var st = stb.ToST();
            //st.ShowGraph(10);
            var sft = st.Explore();
            //sft.ShowGraph(10);

            //just to get longer input strings
            var restr = sft.RestrictDomain("(.){3,}$");

            restr.Simplify();
            //restr.ShowGraph(10);

            restr.AssertTheory();

            Expr inputConst  = solver.MkFreshConst("input", sft.InputListSort);
            Expr outputConst = solver.MkFreshConst("output", sft.OutputListSort);

            solver.MainSolver.Assert(restr.MkAccept(inputConst, outputConst));

            int okCnt     = 0;
            int error0Cnt = 0;
            int error1Cnt = 0;

            //validate correctness for some values against the actual CssEncode
            //TBD: validate also exceptional behavior
            int K = 10;

            for (int i = 0; i < K; i++)
            {
                var    model  = solver.MainSolver.GetModel(solver.True, inputConst, outputConst);
                string input  = model[inputConst].StringValue;
                string output = model[outputConst].StringValue;

                Assert.IsFalse(string.IsNullOrEmpty(input));
                Assert.IsFalse(string.IsNullOrEmpty(output));
                if ((input != ""))
                {
                    char lastChar = '\0'; //output[output.Length - 1];

                    try
                    {
                        var output_expected = System.Web.Security.AntiXss.AntiXssEncoder.CssEncode(input);
                        Assert.AreEqual <string>(output_expected, output);
                        okCnt += 1;
                    }
                    catch (Exception)
                    {
                        Assert.AreEqual <char>('\0', lastChar);
                        error0Cnt += 1;
                    }
                }
                //exclude this solution, before picking the next one
                solver.MainSolver.Assert(solver.MkNeq(inputConst, model[inputConst].Value));
            }
            Assert.AreEqual(K, okCnt);
        }
Exemplo n.º 25
0
        public void TestEq1_a()
        {
            string     bek1   = @"
program decode(input) {
  return iter(c in input)[pc := 0;]{
    case ((pc == 0) && (c == 'a')) :                   
      pc := 1; 
      yield (c,c+1);
    case ((pc == 1) && ((c == 'b'))) : 
      pc := 1;          
      yield (c,c); 
    case ((pc == 1) && (c == 'a')) : 
      pc := 2;          
      yield (c);
    case (true):
      raise Error;
} end {
    case (pc == 2):
      yield ('a');
    case (true):
      raise Error;
};
}
";
            string     bek2   = @" 
program decode(input) {
  return iter(c in input)[pc := 0;]{
    case ((pc == 0) && (c == 'a')) :                   
      pc := 1; 
      yield (c);
    case ((pc == 1) && ((c == 'b'))) : 
      pc := 1;          
      yield (c,c); 
    case ((pc == 1) && (c == 'a')) : 
      pc := 2;          
      yield (c+1,c);
    case (true):
      raise Error;
} end { 
    case (pc == 2):
      yield ('a');
    case (true):
      raise Error;
};
}
";
            Z3Provider solver = new Z3Provider(BitWidth.BV16);

            Func <IEnumerable <Expr>, string> GetString = w =>
            {
                return(new String(Array.ConvertAll(new List <Expr>(w).ToArray(), x => (char)solver.GetNumeralInt(x))));
            };

            var A = BekConverter.BekToSTb(solver, bek1).ExploreBools().ToST().Explore();
            var B = BekConverter.BekToSTb(solver, bek2).ExploreBools().ToST().Explore();

            var witness = A.Neq1(B);

            Assert.IsNull(witness);
        }
Exemplo n.º 26
0
        internal STModel GetST(Identifier name)
        {
            STModel st = null;

            if (stMap.TryGetValue(name.Name, out st))
            {
                return(st);
            }
            else
            {
                BekProgram prog = null;
                if (bekMap.TryGetValue(name.Name, out prog))
                {
                    if (converter == null)  //same local functions for all bek programs
                    {
                        converter = BekConverter.MkBekToSTbConverter(solver, prog.ast.funcs, prog.ast.name);
                    }

                    st               = converter.Convert(prog).ExploreBools().ToST();
                    st.Name          = name.Name;
                    stMap[name.Name] = st;
                    return(st);
                }
                else
                {
                    throw new QueryParseException(name.Line, name.Pos, string.Format("Undefined transducer: {0}", name));
                }
            }
        }
Exemplo n.º 27
0
 public void TestDecodeDigitPairsDotGen()
 {
     Z3Provider solver = new Z3Provider();
     var stb = BekConverter.BekFileToSTb(solver, sampleDir + "bek/DecodeDigitPairs.bek");
     stb.ToDot("DecodeDigitPairs.dot");
     var sft = stb.Explore();
     sft.ToDot("DecodeDigitPairs_F.dot");
 }
Exemplo n.º 28
0
 public void TestCssEncodeDomainDotGen()
 {
     Z3Provider solver = new Z3Provider();
     var stb = BekConverter.BekFileToSTb(solver, sampleDir + "bek/CssEncode.bek");
     var sfa = stb.ToST().ToSFA().Determinize().Minimize();
     Assert.AreEqual<int>(2, sfa.StateCount);
     sfa.SaveAsDot("CssEncode_Dom.dot");
     //sfa.ShowGraph();
 }
Exemplo n.º 29
0
 public void TestCssEncodeBekRoundtrip()
 {
     Z3Provider solver = new Z3Provider();
     var stb = BekConverter.BekFileToSTb(solver, sampleDir + "bek/CssEncode.bek");
     var sb = new StringBuilder();
     stb.ToBek(sb);
     var stb2 = BekConverter.BekToSTb(solver, sb.ToString());
     CheckFullEquivalence(stb, stb2);
 }
Exemplo n.º 30
0
 public void TestHtmlDecode()
 {
     int        k      = 3134 % 100;
     int        foo    = 0xff41;
     Z3Provider solver = new Z3Provider();
     var        stb    = BekConverter.BekFileToSTb(solver, sampleDir + "bek/HtmlDecode.bek");
     var        st     = stb.ExploreBools().ToST();
     //st.ShowGraph();
 }