コード例 #1
0
        public override bool Check(TableEntry left, TableEntry right, string[] tokens)
        {
            // tries to match the value of tokens x through y (inclusive) of the LHS with the length of the RHS

            int start = left.Key[0] + X;
            int end = left.Key[0] + Y;

            string[] sublist = Utilities.GetSubArray(tokens, start, end, true);

            int length = Utilities.GetValue(sublist, 0, sublist.Length);

            if (length != right.Key[1])
                return false;
            else
                return true;
        }
コード例 #2
0
ファイル: CYK.cs プロジェクト: bixiu/DEC0DE-forensics
        public static Field[] GetFields(TableEntry root)
        {
            List<Field> fields = new List<Field>();

            foreach (TableEntry child in root.Children)
            {
                if (root.Base == "Field")
                {
                    Field newField = new Field(){Type=root.Children[0].Base,Start=root.Key[0],Length=root.Key[1]};

                    fields.Add(newField);
                }

                fields.AddRange(GetFields(child));
            }

            return fields.ToArray();
        }
コード例 #3
0
ファイル: CYK.cs プロジェクト: bixiu/DEC0DE-forensics
        private void AddEntry(TableEntry entry)
        {
            string entryBase = entry.Rule.LHS.Text;

            if(!_table.ContainsKey(entry.Key))
                _table.Add(entry.Key, new Dictionary<string,TableEntry>());

            // if table already has an entry with the same base, keep the more probable of the two
            if (_table[entry.Key].ContainsKey(entryBase))
            {
                TableEntry oldEntry = _table[entry.Key][entryBase];

                if (oldEntry.Probability < entry.Probability)
                {
                    _table[entry.Key][entry.Base] = entry;

            #if DEBUG
                    Console.WriteLine("OVERWRITING " + oldEntry + " WITH " + entry + " AT " + string.Format("({0},{1})", entry.Key[0], entry.Key[1]));
            #endif
                }

            #if DEBUG
                Console.WriteLine("FAILED TO OVERWRITE " + oldEntry + " WITH " + entry + " AT " + string.Format("({0},{1})", entry.Key[0], entry.Key[1]));
            #endif
            }
            else
            {
                _table[entry.Key].Add(entryBase, entry);

            #if DEBUG
                Console.WriteLine("ADDING " + entry  + " AT " + string.Format("({0},{1})", entry.Key[0], entry.Key[1]));
            #endif
            }

            // handle alias rules (rules of the form A --> B)
            for (int i = 0; i < _grammar.RhsIndex[entry.Base].Count; i++)
            {
                ProductionRule rule = _grammar.RhsIndex[entry.Base][i];

                if (rule.RHS.Length == 1)
                    AddEntry(new TableEntry(entry.Key, rule, new TableEntry[] { entry }));
            }
        }
コード例 #4
0
        public static Field[] GetFields(TableEntry root)
        {
            List <Field> fields = new List <Field>();

            foreach (TableEntry child in root.Children)
            {
                if (root.Base == "Field")
                {
                    Field newField = new Field()
                    {
                        Type = root.Children[0].Base, Start = root.Key[0], Length = root.Key[1]
                    };

                    fields.Add(newField);
                }

                fields.AddRange(GetFields(child));
            }

            return(fields.ToArray());
        }
コード例 #5
0
 public abstract bool Check(TableEntry left, TableEntry right, string[] tokens);
コード例 #6
0
 public abstract bool Check(TableEntry left, TableEntry right, string[] tokens);
コード例 #7
0
        public override bool Check(TableEntry left, TableEntry right, string[] tokens)
        {
            // format: [('range_restrict', [(n, (min, max))])]
            // matches only if the nth field on the rhs of the rule is within the specified value range
            string[] sublist = Utilities.GetSubArray(tokens, left.Key[0],
                left.Key[0] + left.Key[1], true);

            int value = Utilities.GetValue(sublist, Index, Index + 1);

            if (value < Convert.ToInt32(Min) || value > Convert.ToInt32(Max))
                return false;

            return true;
        }
コード例 #8
0
        public override bool Check(TableEntry left, TableEntry right, string[] tokens)
        {
            // matches if length of 2nd element of RHS matches value of 1st element of RHS plus adjustment times multiplier
            int length = Utilities.GetValue(tokens, left.Key[0], left.Key[0] + left.Key[1]);

            if (length != (right.Key[1] + Adjustment) * Multiplier)
                return false;
            else
                return true;
        }