Esempio n. 1
0
        public override bool test(CSsemi.CSemiExp semi, string filename)
        {
            if (semi[semi.count - 1] != "{")
            {
                return(false);
            }
            int index = semi.FindFirst("(");

            List <Elem> table = RepositoryForOutput.storageForOutput_;

            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            try
            {
                if (index > 0 && !isSpecialToken(semi[index - 1]))
                {
                    for (int i = index - 1; i < semi.count; i++)
                    {
                        foreach (Elem e in table)
                        {
                            if ((e.name.Equals(semi[i])) && !(e.type.Equals("function")) && !(e.type.Equals("namespace")))
                            {
                                local.Add("Using").Add(semi[i]).Add(e.filename).Add(e.namespacename);
                                doActions(local, filename);
                                return(false);
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return(false);
        }
        public override bool test(CSsemi.CSemiExp semi, string file)
        {
            try
            {
                if (semi[semi.count - 1] != "{")
                {
                    return(false);
                }

                int index = semi.FindFirst("(");
                if (index > 0 && !isSpecialToken(semi[index - 1]))
                {
                    List <Elem> output = OutputRepository.output_;

                    foreach (Elem e in output)
                    {
                        for (int i = 0; i < semi.count - 1; i++)
                        {
                            if (e.name.Equals(semi[i]) && !e.type.Equals("namespace") && !e.type.Equals("function"))
                            {
                                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                                local.Add("Using").Add(semi[i]);
                                doActions(local, file);
                                return(true);
                            }
                        }
                    }
                }
            }
            catch { }
            return(false);
        }
Esempio n. 3
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            string[] SpecialToken = { "if", "else", "for", "foreach", "while", "catch", "try", "finally", "switch", "do" };
            int      index        = -1;

            foreach (string stoken in SpecialToken)
            {
                int tempindex = semi.Contains(stoken);
                if (tempindex != -1)
                {
                    index = Math.Max(index, tempindex);
                }
            }
            int index2 = semi.FindFirst("{");

            if (index != -1 && index2 != -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("Scope").Add(semi[index]);
                doActions(local);
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            string[] SpecialToken = { "if", "else", "for", "foreach", "while", "switch", "case", "do", "break" };
            int      index        = -1;
            int      index2       = 0;

            CSsemi.CSemiExp local = new CSsemi.CSemiExp();
            bool            flag  = false;

            foreach (string stoken in SpecialToken)
            {
                index  = semi.Contains(stoken);
                index2 = semi.FindFirst("{");
                if (index != -1 && index2 == -1)
                {
                    local = new CSsemi.CSemiExp();
                    // local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("Scope").Add(semi[index]);
                    doActions(local);
                    flag = false;
                }
            }
            if (flag)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int indexCL = semi.Contains("class");
            int indexIF = semi.Contains("interface");

            int index  = Math.Max(indexCL, indexIF);
            int index2 = semi.FindFirst(":");

            if (index != -1 && index2 != -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add(semi[index + 1]).Add(semi[index + 3]);
                doActionsInheritance(local);

                int multiInheritCount = semi.FindAll(",");
                while (multiInheritCount > 0)
                {
                    index2 = index2 + 2;
                    local  = new CSsemi.CSemiExp();
                    local.displayNewLines = false;
                    local.Add(semi[index + 1]).Add(semi[index2 + 1]);
                    doActionsInheritance(local);
                    multiInheritCount--;
                }

                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int brIndex = semi.Contains("{");

            if (brIndex != -1)
            {
                return(false);
            }
            int hashIndex = semi.Contains("#");

            if (hashIndex != -1)
            {
                return(false);
            }

            int index = semi.FindFirst("(");

            if (index > 0 && DetectFunction.isSpecialToken(semi[index - 1]))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // create local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("control").Add("anonymous");
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
        //----< get right of equal from semi expression >------------------------------
        static public CSsemi.CSemiExp GetRightOfEqual(CSsemi.CSemiExp s)
        {
            CSsemi.CSemiExp newSemi = new CSsemi.CSemiExp();

            int index = s.FindFirst("=");
            if (index != -1)
            {
                if (index + 1 < s.count)
                {
                    for (int i = index + 1; i < s.count; i++)
                    {
                        newSemi.Add(s[i]);
                    }
                }
            }
            else
            {
                for (int i = 0; i < s.count; i++)
                {
                    newSemi.Add(s[i]);
                }
            }

            return newSemi;
        }
Esempio n. 8
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectFunction");

            if (semi[semi.count - 1] != "{")
            {
                return(false);
            }

            int index = semi.FindFirst("(");

            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                Repository rep = Repository.getInstance();

                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("function").Add(semi[index - 1]);
                doActions(local);

                if (!rep.isFirstPass)
                {
                    /////////////////////////////////////////////////////////////////
                    //
                    // Parse function parameters to look for class dependencies
                    //
                    /////////////////////////////////////////////////////////////////
                    CSsemi.CSemiExp parameters = TokenHelper.GetFunctionParameters(semi);
                    for (int i = 0; i < TokenHelper.GetNumberOfParameters(parameters); i++)
                    {
                        parameters = TokenHelper.RemoveNewLines(parameters);
                        parameters = TokenHelper.RemoveIndicies(parameters);
                        parameters = TokenHelper.RemoveGenerics(parameters);
                        List <string> l = TokenHelper.GetFunctionParameterAtIndex(parameters, i);

                        foreach (CClassInfo ci in rep.parsedData.classList)
                        {
                            if (semi.Contains(ci.className) != -1)
                            {
                                if (rep.stack.count < 2)
                                {
                                    break;
                                }

                                string ns = rep.stack[0].name;                   // namespace
                                string cl = rep.stack[1].name;                   // class
                                string fn = rep.stack[rep.stack.count - 1].name; // function

                                CClassInfo    currentClassInfo    = rep.parsedData.getClassInfo(cl);
                                CFunctionInfo currentFunctioninfo = rep.parsedData.getClassFunctionInfo(cl, fn);

                                currentFunctioninfo.addDependency(l[l.Count - 2]);
                            }
                        }
                    }
                }

                return(true);
            }
            return(false);
        }
Esempio n. 9
0
        //----< get function parameters from semi expression >------------
        static public CSsemi.CSemiExp GetFunctionParameters(CSsemi.CSemiExp s)
        {
            CSsemi.CSemiExp newSemi = new CSsemi.CSemiExp();

            int index = s.FindFirst("(");
            if (index != -1)
            {
                for (int i = index; i < s.count; i++)
                {
                    if (s[i] == ")")
                    {
                        break;
                    }

                    if (s[i] != "(")
                    {
                        newSemi.Add(s[i]);
                    }
                }
            }

            //newSemi = CombineNamespace(newSemi);

            return newSemi;
        }
Esempio n. 10
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            if (semi[semi.count - 1] != "{")
            {
                return(false);
            }
            int indexOpen = semi.FindFirst("(");

            if (indexOpen > 0 && !isSpecialToken(semi[indexOpen - 1]))
            {
                int             indexClose = semi.FindFirst(")");
                CSsemi.CSemiExp local      = new CSsemi.CSemiExp();
                local.Add("function").Add(semi[indexOpen - 1]);

                for (int i = indexOpen + 1; i < indexClose; i++)
                {
                    // Handle When out ref keywords are used
                    // This assumes that the Type name resides just after the open bracket or ,
                    if ((semi[i - 1] == "(" || semi[i - 1] == ","))
                    {
                        string usedType;
                        if (isParameterModifier(semi[i]))
                        {
                            usedType = semi[i + 1];
                        }
                        else
                        {
                            usedType = semi[i];
                        }

                        local.Add("Using").Add(usedType);
                    }
                }
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 11
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int         index       = -1;
            int         braIndex    = -1;
            int         newIndex    = -1;
            int         strIndex    = -1;
            int         eqlIndex    = -1;
            int         otherIndex  = -1;
            int         otherIndex2 = -1;
            Repository  rep         = Repository.getInstance();
            List <Elem> temp        = rep.locations;

            foreach (Elem e in temp)
            {
                if (e.type.Equals("class"))
                {
                    index    = semi.Contains(e.name);
                    braIndex = semi.Contains("{");
                    newIndex = semi.Contains("new");
                }

                if (index != -1 && newIndex != -1 && braIndex == -1)
                {
                    CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                    // local semiExp with tokens for type and name
                    local.displayNewLines = false;
                    local.Add("Aggregation").Add(semi[index + 1]).Add(semi[index]);
                    doActions(local);
                    return(true);
                }
            }

            strIndex    = semi.FindFirst("string");
            eqlIndex    = semi.Contains("=");
            otherIndex  = semi.Contains("<");
            otherIndex2 = semi.Contains("[");

            if (strIndex != -1 && eqlIndex != -1 && otherIndex2 == -1 && otherIndex == -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("Aggregation").Add(semi[strIndex]).Add(semi[strIndex + 1]);
                doActions(local);
                return(true);
            }

            return(false);
        }
Esempio n. 12
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            if (semi[semi.count - 1] != ";")
            {
                return(false);
            }

            int index = semi.FindFirst("(");

            if (index > 0 && isSpecialToken(semi[index - 1]))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("braceless").Add(semi[index - 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 13
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Repository repo_ = Repository.getInstance();
            int        index = semi.FindFirst("new");

            if (index != -1)
            {
                string          currclassName = DetectParentClass.getClassName(repo_.semi.lineCount);
                CSsemi.CSemiExp local         = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add(semi[index + 1]).Add(semi[index - 2]).Add(currclassName);
                doActionsAggregation(local);
                return(true);
            }

            return(false);
        }
Esempio n. 14
0
        public override bool test(CSsemi.CSemiExp semi, string filename)
        {
            if (semi[semi.count - 1] != "{")
            {
                return(false);
            }

            int index = semi.FindFirst("(");

            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("function").Add(semi[index - 1]);
                doActions(local, filename);
                return(true);
            }
            return(false);
        }
Esempio n. 15
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectFunction");
            if (semi[semi.count - 1] != "{")
            {
                return(false);
            }

            int index = semi.FindFirst("(");

            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.Add("function").Add(semi[index - 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 16
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            int openBrace = semi.Contains(";");

            if (openBrace == -1)
            {
                return(false);
            }
            int index = semi.FindFirst("new");

            if (index > 0)
            {
                string          className = semi[index + 1];
                CSsemi.CSemiExp local     = new CSsemi.CSemiExp();
                local.Add("Aggregate").Add(className);
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 17
0
        //----< get class inhertitance from semi expression >------------
        static public CSsemi.CSemiExp GetInheritance(CSsemi.CSemiExp s)
        {
            CSsemi.CSemiExp newSemi = new CSsemi.CSemiExp();

            int index = s.FindFirst(":");
            if (index != -1)
            {
                if (index + 1 < s.count)
                {
                    for (int i = index + 1; i < s.count; i++)
                    {
                        if (s[i] != "{")
                        {
                            newSemi.Add(s[i]);
                        }
                    }
                }
            }

            return newSemi;
        }