Esempio n. 1
0
        public override bool test(ITokenCollection semi)
        {
            string[] dnetlib = { "System", "Microsoft", "Accessibility", "UIAutomationClientsideProviders" };
            Display.displayRules(actionDelegate, "rule  DetectUsing");
            int index;

            semi.find("using", out index);
            ITokenCollection local = Factory.create();

            // create local semiExp with tokens for type and name

            if (index != -1 && (dnetlib.Contains(semi[index + 1]) == false) && semi.size() > index + 1)
            {
                local.add(semi[index]);

                int eqindex;
                semi.find("=", out eqindex);
                if (eqindex != -1)
                {
                    local.add(semi[eqindex + 1]);
                }
                else
                {
                    local.add(semi[index + 1]);
                }

                doActions(local);
                return(true);
            }
            return(false);
        }
    public override bool test(ITokenCollection semi)
    {
      Display.displayRules(actionDelegate, "rule   DetectPublicDeclar");
      int index;
      semi.find(";", out index);
      if (index != -1)
      {
        semi.find("public", out index);
        if (index == -1)
          return true;
        ITokenCollection local = Factory.create();
        // create local semiExp with tokens for type and name
        //local.displayNewLines = false;
        local.add("public "+semi[index+1]).add(semi[index+2]);

        semi.find("=", out index);
        if (index != -1)
        {
          doActions(local);
          return true;
        }
        semi.find("(", out index);
        if(index == -1)
        {
          doActions(local);
          return true;
        }
      }
      return false;
    }
Esempio n. 3
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectPublicDeclar");
            int index;

            semi.find(";", out index);
            if (index != -1)
            {
                semi.find("public", out index);
                if (index == -1)
                {
                    return(true);
                }
                ITokenCollection local = Factory.create();
                local.add("public " + semi[index + 1]).add(semi[index + 2]);

                semi.find("=", out index);
                if (index != -1)
                {
                    doActions(local);
                    return(true);
                }
                semi.find("(", out index);
                if (index == -1)
                {
                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int i;

            if (semi.find("public", out i) || semi.find("internal", out i))//may not need here
            {
                int indexCL;
                semi.find("class", out indexCL);
                int indexIF;
                semi.find("interface", out indexIF);
                int indexST;
                semi.find("struct", out indexST);
                int indexEN;
                semi.find("enum", out indexEN);
                int index = Math.Max(indexCL, indexIF);
                index = Math.Max(index, indexST);
                if (index != -1 && semi.size() > index + 1)
                {
                    ITokenCollection local = Factory.create();
                    // local semiExp with tokens for type and name
                    local.add(semi[index]).add(semi[index + 1]);
                    doActions(local);
                    return(true);
                }
                return(false);
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectFunction");
            if (semi[semi.size() - 1] != "{")
            {
                return(false);
            }

            int index;

            semi.find("(", out index);
            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                ITokenCollection local = Factory.create();
                local.add("function").add(semi[index - 1]);
                ITokenCollection returnType = GetReturn(semi, semi[index - 1]);
                int i = 0;
                while (i < returnType.size())
                {
                    local.add(returnType[i]);
                    i++;
                }
                ITokenCollection para = getPara(semi);
                int j = 0;
                while (j < para.size())
                {
                    local.add(para[j]);
                    j++;
                }
                doActions(local);
                return(true);
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectFunction");
            if (semi[semi.size() - 1] != "{")
            {
                return(false);
            }

            int index;

            semi.find("(", out index);
            if (index > 0 && !isSpecialToken(semi[index - 1]))
            {
                ITokenCollection local = Factory.create();
                local.add("function").add(semi[index - 1]);
                ITokenCollection returnType = GetReturn(semi, semi[index - 1]);
                int i = 0;
                while (i < returnType.size())
                {
                    local.add(returnType[i]);
                    i++;
                }
                //for (int j = 0; j < local.size(); ++j)
                //{
                //    Console.Write(" {0}", local[j]);
                //}
                //Console.Write("\n");
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 7
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);
        }
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int indexCL = semi.Contains("class");
            int indexIF = semi.Contains("interface");
            int indexST = semi.Contains("struct");
            int indexEN = semi.Contains("enum");


            int index = Math.Max(indexCL, indexIF);

            index = Math.Max(index, indexST);
            index = Math.Max(index, indexEN);

            if (index != -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;
                if (semi[index] == "class" || semi[index] == "interface" || semi[index] == "struct" || semi[index] == "enum")
                {
                    local.Add(semi[index]).Add(semi[index + 1]);
                }
                else
                {
                    local.Add(semi[index]).Add(semi[index + 2]);
                }
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 9
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]);

                //search for all arguments in the function and add to local
                for (int i = index; i < semi.count; i++)
                {
                    if (UserType.userDefinedSet.Contains(semi[i]))
                    {
                        local.Add(semi[i]);
                    }
                }

                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 10
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectUsing");
            int index;

            semi.find("using", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                if (semi[index + 2].Equals("=") && semi[semi.size() - 1].Equals(";"))
                {
                    local.add("alias");
                    local.add(semi[index + 1]);
                    local.add(semi[index + 3]);
                    doActions(local);
                    return(true);
                }
                if (!semi[index + 1].Equals("System"))
                {
                    local.add(semi[index]).add(semi[index + 1]);
                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 11
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int indexCL = semi.Contains("class");
            int indexIF = semi.Contains("interface");
            int indexST = semi.Contains("struct");

            int index = Math.Max(indexCL, indexIF);

            index = Math.Max(index, indexST);
            if (index != -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // local semiExp with tokens for type and name
                local.displayNewLines = false;

                //check for inheritance
                if (semi.Contains(":") != -1)
                {
                    local.userInheritance = true;
                    local.Add(semi[index]).Add(semi[index + 1]).Add(semi[semi.Contains(":") + 1]);
                }
                else
                {
                    local.Add(semi[index]).Add(semi[index + 1]);
                }

                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 12
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            HashSet <string> definedSet = UserType.getUserDefinedSet();

            Display.displayRules(actionDelegate, "rule Detect Inheritance");
            int classIndex = semi.Contains("class");

            if (classIndex != -1)
            {
                //check for inheritance
                int inheritanceIndex = semi.Contains(":");
                if (inheritanceIndex != -1)
                {
                    string inheritedClass = semi[inheritanceIndex + 1];
                    if (definedSet.Contains(inheritedClass))
                    {
                        //do some action
                        Console.Write("inheritance found: " + inheritedClass + "\n");
                        doActions(semi);
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 13
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClass");
            int indexCL;

            semi.find("class", out indexCL);
            int indexIF;

            semi.find("interface", out indexIF);
            int indexST;

            semi.find("struct", out indexST);
            int indexEN;

            semi.find("enum", out indexEN);

            int index = Math.Max(indexCL, indexIF);

            index = Math.Max(index, indexST);
            index = Math.Max(index, indexEN);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                local.add(semi[index]).add(semi[index + 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 14
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectPublicDeclar");
            int index = semi.Contains(";");

            if (index != -1)
            {
                index = semi.Contains("public");
                if (index == -1)
                {
                    return(true);
                }
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // create local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add("public " + semi[index + 1]).Add(semi[index + 2]);

                index = semi.Contains("=");
                if (index != -1)
                {
                    doActions(local);
                    return(true);
                }
                index = semi.Contains("(");
                if (index == -1)
                {
                    doActions(local);
                    return(true);
                }
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Repository repo = Repository.getInstance();

            ITokenCollection local = semi.clone();

            if (local[0] == "using")
            {
                return(false);
            }
            Display.displayRules(actionDelegate, "rule   DetectDeclar");
            int index;

            local.find(";", out index);
            if (index != -1)
            {
                local = compactGeneric(local);
                int pos = 0;
                while (pos < local.size())
                {
                    if (repo.qualTable.contains(local[pos]))
                    {
                        local.remove(pos);
                    }
                    else
                    {
                        ++pos;
                    }
                }

                local.find("=", out index);
                if (index != -1)
                {
                    while (index < local.size() - 1)
                    {
                        local.remove(index);
                    }
                }

                int indexPar;
                local.find("(", out indexPar);
                if (indexPar > -1)
                {
                    return(false);
                }

                if (local.size() == 3)
                {
                    doActions(local);
                    return(false);
                }
                if (local.size() == 5 && local[1] == ".")
                {
                    doActions(local);
                    return(false);
                }
            }
            return(false);
        }
Esempio n. 16
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectInheritance");
            int indexCL;

            semi.find("class", out indexCL);
            int indexIF;

            semi.find("interface", out indexIF);
            int indexC;

            semi.find(":", out indexC);
//            int indexST;
//            semi.find(".", out indexST);
            int indexCM;

            semi.find("=", out indexCM);
            //Console.WriteLine("For \n class {0}\ninterface {1}\n: {2}\n= {3}",indexCL,indexIF,indexC,indexCM);
            int index = Math.Max(indexCL, indexIF);

            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();

                // local semiExp with tokens for type and name

                if (indexC > 0)
                {
                    local.add(semi[index]).add(semi[indexC + 1]);
                }
//                else if(indexST > 0)
//                    local.add(semi[index]).add(semi[indexST - 1]);
                else
                {
                    local.add(semi[index]).add(semi[index + 1]);
                }

                doActions(local);
                return(true);
            }

            else if (indexCM != -1 && (indexCM - 2 > -1) && semi.size() > indexCM + 1)
            {
                string[] ignore = new string[] { "bool", "sbyte", "short", "int", "long", "byte", "ushort", "uint", "ulong", "double", "char", "decimal", "string", "using" };
                if (!ignore.Contains(semi[indexCM - 2]))
                {
                    ITokenCollection local = Factory.create();
                    local.add(semi[indexCM - 1]).add(semi[indexCM - 2]);
                    doActions(local);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 17
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule  DetectComment");
            if (semi.Contains("//") != -1 || semi.Contains("/*") != -1)
            {
                doActions(semi);
                return(true);
            }

            return(false);
        }
Esempio n. 18
0
 public override bool test(ITokenCollection semi)
 {
   Display.displayRules(actionDelegate, "rule   DetectLeavingScope");
   int index;
   semi.find("}", out index);
   if (index != -1)
   {
     doActions(semi);
     return true;
   }
   return false;
 }
Esempio n. 19
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectLeavingScope");
            int index = semi.Contains("}");

            if (index != -1)
            {
                doActions(semi);
                return(true);
            }
            return(false);
        }
Esempio n. 20
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectAnonymousScope");
            int index;

            semi.find("{", out index);
            if (index != -1)
            {
                ITokenCollection local = Factory.create();
                local.add("control").add("anonymous");
                doActions(local);
                return(true);
            }
            return(false);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectDelegates");
            int index;

            semi.find("delegate", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                local.add(semi[index]).add(semi[index + 2]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 22
0
 public override bool test(ITokenCollection semi)
 {
   Display.displayRules(actionDelegate, "rule   DetectNamespace");
   int index;
   semi.find("namespace", out index);
   if (index != -1 && semi.size() > index + 1)
   {
     ITokenCollection local = Factory.create();
     // create local semiExp with tokens for type and name
     local.add(semi[index]).add(semi[index + 1]);
     doActions(local);
     return true;
   }
   return false;
 }
Esempio n. 23
0
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectClassInterfaceStructEnumDelegate");
            int indexCL;

            semi.find("class", out indexCL);
            int indexIF;

            semi.find("interface", out indexIF);
            int indexST;

            semi.find("struct", out indexST);
            int indexEN;

            semi.find("enum", out indexEN);
            int indexDL;

            semi.find("delegate", out indexDL);

            int index = Math.Max(indexCL, indexIF);

            index = Math.Max(index, indexST);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();
                // local semiExp with tokens for type and name
                local.add(semi[index]).add(semi[index + 1]);
                doActions(local);
                return(true);
            }
            else if (indexST > -1 || indexEN > -1)
            {
                ITokenCollection local = Factory.create();
                index = indexST > -1 ? indexST : indexEN;
                local.add(semi[index]).add(semi[index + 1]);
                doActions(local);
                return(true);
            }
            else if (indexDL > -1)
            {
                ITokenCollection local = Factory.create();
                local.add(semi[indexDL]).add(semi[indexDL + 2]);
                doActions(local);
                return(true);
            }

            return(false);
        }
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetecAlias");
            int indexF = semi.Contains("using");
            int indexS = semi.Contains("=");

            if (indexF != -1 && indexS != -1 && (indexS - indexF) == 2)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                local.displayNewLines = false;
                local.Add("Alias").Add(semi[indexF + 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 25
0
        public override bool test(ITokenCollection semi)//Added semi.find function in ITok ss
        {
            Display.displayRules(actionDelegate, "rule   DetectDelegate");
            int index;

            semi.find("delegate", out index);
            if (index != -1 && semi.size() > index + 1)
            {
                ITokenCollection local = Factory.create();//need factory bcoz i dont have semi class but interface ss
                // create local semiExp with tokens for type and name
                local.add(semi[index]).add(semi[index + 2]);
                doActions(local);
                return(true);//Fully satisfied no more parsing required ss
            }
            return(false);
        }
Esempio n. 26
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectAnonymousScope");
            int index = semi.Contains("{");

            if (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. 27
0
        public override bool test(CSsemi.CSemiExp semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectNamespace");
            int index = semi.Contains("namespace");

            if (index != -1)
            {
                CSsemi.CSemiExp local = new CSsemi.CSemiExp();
                // create local semiExp with tokens for type and name
                local.displayNewLines = false;
                local.Add(semi[index]).Add(semi[index + 1]);
                doActions(local);
                return(true);
            }
            return(false);
        }
Esempio n. 28
0
    public override bool test(ITokenCollection semi)
    {
      Display.displayRules(actionDelegate, "rule   DetectFunction");
      if (semi[semi.size() - 1] != "{")
        return false;

      int index;
      semi.find("(", out index);
      if (index > 0 && !isSpecialToken(semi[index - 1]))
      {
        ITokenCollection local = Factory.create();
        local.add("function").add(semi[index - 1]);
        doActions(local);
        return true;
      }
      return false;
    }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule    DetectMember");
            int index;

            semi.find("{", out index);
            if (index < 2)
            {
                return(false);
            }
            string[]      Dec = { "namespace", "class", "interface", "struct", "enum", "(", "]" };
            List <string> acc = new List <string> {
                "public", "private", "internal", "static"
            };

            foreach (string term in Dec)
            {
                if (semi.find(term, out index))
                {
                    return(false);
                }
            }
            semi.find("{", out index);
            Console.WriteLine("index: {0}", index);
            index -= 2;
            while (index >= 0)
            {
                //public List<CsEdge<CsNode<List<CsEdge<string,string>>,A.string>, string>> dummy {;
                if (semi[index] == "<" || semi[index] == ">>" || semi[index] == ">" || semi[index] == "," || acc.Contains(semi[index]))
                {
                    index--; continue;
                }
                ITokenCollection local = Factory.create();
                StringBuilder    temp  = new StringBuilder();
                while (index >= 0 && semi[index] != "<" && semi[index] != ">" && semi[index] != "," && !acc.Contains(semi[index]))
                {
                    temp.Insert(0, semi[index]);
                    index--;
                }
                local.add(temp.ToString());
                Console.WriteLine("This strange thing: {0}", temp.ToString());
                doActions(local);
                index--;
            }
            return(true);
        }
        public override bool test(ITokenCollection semi)
        {
            Display.displayRules(actionDelegate, "rule   DetectUsingNamespace");
            int index;

            if (!semi.find("=", out index) && semi.find("using", out index))
            {
                ITokenCollection local = Factory.create();
                index++;
                while (semi[index] != ";")
                {
                    local.add(semi[index]);
                    index++;
                }
                doActions(local);
                return(true);
            }
            return(false);
        }