コード例 #1
0
        private void LoadPatterns()
        {
            _dummyCodes = new List<Pattern>();

            foreach (string line in this.Lines)
            {
                if (line.Equals(NOP_INVALID_POP, StringComparison.OrdinalIgnoreCase))
                {
                    _nopInvalidPop = true;
                    continue;
                }

                string[] opCodeGroupStr = line.Split(new char[] { ';' });
                OpCodeGroup[] opCodeGroups = new OpCodeGroup[opCodeGroupStr.Length];
                
                bool checkReference = false;

                for (int i = 0; i < opCodeGroupStr.Length; i++)
                {
                    string str = opCodeGroupStr[i];
                    opCodeGroups[i] = new OpCodeGroup(str);

                    if (str.StartsWith("~"))
                    {
                        checkReference = true;
                        str = str.Substring(1);
                    }

                    if (str.StartsWith("*"))
                    {
                        opCodeGroups[i].ExactMatch = true;
                        str = str.Substring(1);
                    }
                    else
                    {
                        opCodeGroups[i].ExactMatch = false;
                    }

                    if (str.StartsWith("!"))
                    {
                        opCodeGroups[i].ToNop = false;
                        str = str.Substring(1);
                    }
                    else
                    {
                        opCodeGroups[i].ToNop = true;
                    }

                    //if (str.StartsWith("~"))
                    //{
                    //    opCodeGroups[i].CheckReference = true;
                    //    str = str.Substring(1);
                    //}
                    //else
                    //{
                    //    opCodeGroups[i].CheckReference = false;
                    //}

                    if (str.StartsWith("[") && str.EndsWith("]"))
                    {
                        opCodeGroups[i].Optional = true;
                        opCodeGroups[i].OpCodes = str.Substring(1, str.Length - 2).Split(new char[] { ',' });
                    }
                    else
                    {
                        opCodeGroups[i].Optional = false;
                        int p = str.IndexOf(":");
                        if (p > 0)
                        {
                            opCodeGroups[i].Expression = str.Substring(p + 1);
                            str = str.Substring(0, p);
                        }
                        else
                        {
                            opCodeGroups[i].Expression = null;
                        }
                        opCodeGroups[i].OpCodes = str.Split(new char[] { ',' });
                    }

                }

                _dummyCodes.Add(new Pattern(line, opCodeGroups, checkReference));
            }
        }
コード例 #2
0
        //public bool IsExceptionHandlerEnd(Instruction ins, ExceptionHandler eh)
        //{
        //    if (IsEqual(ins, eh.TryEnd) ||
        //        //IsEqual(ins, eh.FilterEnd) ||
        //        IsEqual(ins, eh.HandlerEnd)
        //        )
        //    {
        //        return true;
        //    }

        //    return false;
        //}

        private bool IsInstructionMatch(Instruction ins, OpCodeGroup opCodeGroup, Collection<Instruction> instructions)
        {
            bool match = false;
            string name = ins.OpCode.Name;
            string[] opCodes = opCodeGroup.OpCodes;
            for (int i = 0; i < opCodes.Length; i++)
            {
                if (opCodeGroup.ExactMatch)
                {
                    if (name.Equals(opCodes[i]))
                    {
                        match = true;
                        break;
                    }
                }
                else
                {
                    if (name.StartsWith(opCodes[i]))
                    {
                        match = true;
                        break;
                    }
                }
            }
            if (match && opCodeGroup.HasExpression)
            {
                if (!opCodeGroup.EvalExpression(ins, instructions))
                {
                    match = false;
                }
            }
            return match;
        }
コード例 #3
0
        public Pattern(string text, OpCodeGroup[] opCodeGroups, bool checkReference)
        {
            Text = text;
            CheckReference = checkReference;

            if (opCodeGroups == null || opCodeGroups.Length < 1)
            {
                throw new ApplicationException("Invalid Pattern: " + (text == null ? String.Empty : text));
            }

            OpCodeGroups = opCodeGroups;
            MaxLength = opCodeGroups.Length;
            MinLength = MaxLength;
            for (int i = 0; i < MaxLength; i++)
            {
                if (opCodeGroups[i].Optional)
                    MinLength--;
            }
        }
コード例 #4
0
        private void LoadPatterns()
        {
            _dummyCodes = new List <Pattern>();

            foreach (string line in this.Lines)
            {
                if (line.Equals(NOP_INVALID_POP, StringComparison.OrdinalIgnoreCase))
                {
                    _nopInvalidPop = true;
                    continue;
                }

                string[]      opCodeGroupStr = line.Split(new char[] { ';' });
                OpCodeGroup[] opCodeGroups   = new OpCodeGroup[opCodeGroupStr.Length];

                bool checkReference = false;

                for (int i = 0; i < opCodeGroupStr.Length; i++)
                {
                    string str = opCodeGroupStr[i];
                    opCodeGroups[i] = new OpCodeGroup(str);

                    if (str.StartsWith("~"))
                    {
                        checkReference = true;
                        str            = str.Substring(1);
                    }

                    if (str.StartsWith("*"))
                    {
                        opCodeGroups[i].ExactMatch = true;
                        str = str.Substring(1);
                    }
                    else
                    {
                        opCodeGroups[i].ExactMatch = false;
                    }

                    if (str.StartsWith("!"))
                    {
                        opCodeGroups[i].ToNop = false;
                        str = str.Substring(1);
                    }
                    else
                    {
                        opCodeGroups[i].ToNop = true;
                    }

                    //if (str.StartsWith("~"))
                    //{
                    //    opCodeGroups[i].CheckReference = true;
                    //    str = str.Substring(1);
                    //}
                    //else
                    //{
                    //    opCodeGroups[i].CheckReference = false;
                    //}

                    if (str.StartsWith("[") && str.EndsWith("]"))
                    {
                        opCodeGroups[i].Optional = true;
                        opCodeGroups[i].OpCodes  = str.Substring(1, str.Length - 2).Split(new char[] { ',' });
                    }
                    else
                    {
                        opCodeGroups[i].Optional = false;
                        int p = str.IndexOf(":");
                        if (p > 0)
                        {
                            opCodeGroups[i].Expression = str.Substring(p + 1);
                            str = str.Substring(0, p);
                        }
                        else
                        {
                            opCodeGroups[i].Expression = null;
                        }
                        opCodeGroups[i].OpCodes = str.Split(new char[] { ',' });
                    }
                }

                _dummyCodes.Add(new Pattern(line, opCodeGroups, checkReference));
            }
        }