private bool SearchForSPFeatureReceiverClass(ModuleNode module)
        {
            bool flag = false;

            try
            {
                MetadataCollection <TypeNode> .Enumerator enumerator = module.Types.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    TypeNode current = enumerator.Current;
                    if ((((current != null) && (current is ClassNode)) && (null != current.BaseType)) && current.BaseType.FullName.Equals("Microsoft.SharePoint.SPFeatureReceiver"))
                    {
                        flag = true;
                        this.VisitClass(current as ClassNode);
                        return(flag);
                    }
                }
            }
            catch (NullReferenceException exception)
            {
                Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointTimerjobImplementationCheck:SearchForSPFeatureReceiverClass() - " + exception.Message);
            }
            return(flag);
        }
Esempio n. 2
0
        public override ProblemCollection Check(Member member)
        {
            string     str        = string.Empty;
            Resolution resolution = null;
            int        num        = 0;
            string     fullName   = string.Empty;
            string     str3       = string.Empty;

            try
            {
                if (this.m_listSPDeprecatedAPIStore.Count.Equals(0))
                {
                    this.FillSPDeprecatedAPIStore();
                }
                if (member is Microsoft.FxCop.Sdk.Method)
                {
                    Microsoft.FxCop.Sdk.Method method = member as Microsoft.FxCop.Sdk.Method;
                    MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        Instruction current = enumerator.Current;
                        foreach (SPDeprecatedAPIStore store in this.m_listSPDeprecatedAPIStore)
                        {
                            if (current.Value is Local)
                            {
                                fullName = (current.Value as Local).Type.FullName;
                                str3     = store.Namespace + "." + store.APIType;
                                if (fullName.Equals(str3) || fullName.Contains("Microsoft.SharePoint.Portal"))
                                {
                                    resolution = base.GetResolution(new string[] { method.ToString(), fullName, store.Message });
                                    base.Problems.Add(new Problem(resolution, Convert.ToString(num)));
                                    num++;
                                    fullName = string.Empty;
                                    str3     = string.Empty;
                                    break;
                                }
                            }
                            else if ((current.Value is Microsoft.FxCop.Sdk.Method) && (null != (current.Value as Microsoft.FxCop.Sdk.Method).DeclaringMember))
                            {
                                str      = (current.Value as Microsoft.FxCop.Sdk.Method).DeclaringMember.DeclaringType.FullName;
                                fullName = (current.Value as Microsoft.FxCop.Sdk.Method).DeclaringMember.FullName;
                                if ((str.Equals(store.Namespace) && fullName.Equals(store.APIType)) || fullName.Contains("Microsoft.SharePoint.Portal"))
                                {
                                    resolution = base.GetResolution(new string[] { method.ToString(), fullName, store.Message });
                                    base.Problems.Add(new Problem(resolution, Convert.ToString(num)));
                                    num++;
                                    str      = string.Empty;
                                    fullName = string.Empty;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointDeprecatedAPICheck:Check() - " + exception.Message);
            }
            return(base.Problems);
        }
Esempio n. 3
0
        public override ProblemCollection Check(Member member)
        {
            string      str2;
            Method      method      = member as Method;
            int         num         = 0;
            Instruction instruction = null;
            int         num2        = 0;

            try
            {
                if (null != method)
                {
                    MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        Instruction current = enumerator.Current;
                        if ((current.Value != null) && current.Value.ToString().Contains("SPQuery.set_RowLimit"))
                        {
                            instruction = method.Instructions[num - 1];
                            if (null != instruction.Value)
                            {
                                if (instruction.OpCode.ToString().Contains(OpCode.Ldloc.ToString()))
                                {
                                    this.m_sGetValueName = (instruction.Value as Local).Name.Name;
                                    this.VisitMethod(method);
                                }
                                else if (instruction.OpCode.ToString().Contains(OpCode.Ldfld.ToString()))
                                {
                                    this.m_sGetValueName = (instruction.Value as Member).Name.Name;
                                    this.VisitClass(method.DeclaringType as ClassNode);
                                }
                                else if (instruction.OpCode.ToString().Contains(OpCode.Ldsfld.ToString()))
                                {
                                    this.m_sGetValueName = (instruction.Value as Member).Name.Name;
                                    this.VisitModule(method.DeclaringType.DeclaringModule);
                                }
                                else
                                {
                                    this.m_iValue = Convert.ToInt32(instruction.Value.ToString());
                                }
                                this.m_bValueFound = false;
                            }
                        }
                        if ((this.m_iValue < 1) || (this.m_iValue > 0x7d0))
                        {
                            num2++;
                            string name = string.Empty;
                            if (null != (method.Instructions[num - 2].Value as Local))
                            {
                                name = (method.Instructions[num - 2].Value as Local).Name.Name;
                            }
                            else if (null != (method.Instructions[num - 2].Value as Parameter))
                            {
                                name = (method.Instructions[num - 2].Value as Parameter).Name.Name;
                            }
                            else if (null != (method.Instructions[num - 2].Value as Member))
                            {
                                name = (method.Instructions[num - 2].Value as Member).Name.Name;
                            }
                            Resolution resolution = base.GetResolution(new string[] { name, method.Name.Name, method.DeclaringType.Name.Name, Convert.ToString(this.m_iValue) });
                            base.Problems.Add(new Problem(resolution, Convert.ToString(num2)));
                            this.m_iValue = 1;
                        }
                        num++;
                    }
                }
            }
            catch (NullReferenceException exception)
            {
                str2 = string.Empty;
                Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointCustomRowLimitValueCheck:Check() - " + exception.Message);
            }
            catch (Exception exception2)
            {
                str2 = string.Empty;
                Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointCustomRowLimitValueCheck:Check() - " + exception2.Message);
            }
            return(base.Problems);
        }
 public void VisitWebpartMethod(Method method)
 {
     try
     {
         bool       flag       = false;
         bool       flag2      = false;
         bool       flag3      = false;
         int        num        = 0;
         Resolution resolution = null;
         MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator();
         while (enumerator.MoveNext())
         {
             Problem     problem;
             Instruction current = enumerator.Current;
             if (!flag)
             {
                 if (current.OpCode.Equals(OpCode.Call) || current.OpCode.Equals(OpCode.Callvirt))
                 {
                     resolution = new Resolution("SPMonitoredScope is absent in {0} Webpart", new string[] { method.FullName });
                     problem    = new Problem(resolution, current.SourceContext, Convert.ToString(this.iStringIdForProblem))
                     {
                         Certainty    = 90,
                         FixCategory  = FixCategories.NonBreaking,
                         MessageLevel = MessageLevel.Warning
                     };
                     base.Problems.Add(problem);
                     this.iStringIdForProblem++;
                     return;
                 }
                 if (current.OpCode.Equals(OpCode.Newobj))
                 {
                     if (current.Value.ToString().Contains("Microsoft.SharePoint.Utilities.SPMonitoredScope"))
                     {
                         flag = true;
                         continue;
                     }
                     resolution = new Resolution("SPMonitoredScope is absent in {0} Webpart", new string[] { method.FullName });
                     problem    = new Problem(resolution, current.SourceContext, Convert.ToString(this.iStringIdForProblem))
                     {
                         Certainty    = 90,
                         FixCategory  = FixCategories.NonBreaking,
                         MessageLevel = MessageLevel.Warning
                     };
                     base.Problems.Add(problem);
                     this.iStringIdForProblem++;
                     return;
                 }
             }
             if (current.OpCode.Equals(OpCode._Try) && flag)
             {
                 flag2 = true;
                 num++;
             }
             if (((current.OpCode.Equals(OpCode._EndTry) && flag) && flag2) && (num > 0))
             {
                 num--;
                 if (num == 0)
                 {
                     flag2 = false;
                     flag3 = true;
                 }
             }
             if ((flag3 && (current.OpCode.Equals(OpCode.Call) || current.OpCode.Equals(OpCode.Callvirt))) && !current.Value.ToString().Contains("System.IDisposable.Dispose"))
             {
                 resolution = new Resolution("SPMonitoredScope is absent in {0} Webpart", new string[] { method.FullName });
                 problem    = new Problem(resolution, current.SourceContext, Convert.ToString(this.iStringIdForProblem))
                 {
                     Certainty    = 90,
                     FixCategory  = FixCategories.NonBreaking,
                     MessageLevel = MessageLevel.Warning
                 };
                 base.Problems.Add(problem);
                 this.iStringIdForProblem++;
                 return;
             }
         }
     }
     catch (Exception exception)
     {
         Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointMonitorScopeWebpartCheckVisitWebpartMethod" + exception.Message);
     }
 }
Esempio n. 5
0
        public override ProblemCollection Check(Member member)
        {
            string     str        = string.Empty;
            Resolution resolution = null;
            string     fullName   = string.Empty;
            string     str3       = string.Empty;

            try
            {
                if (this.m_listSPDeprecatedAPIStore.Count.Equals(0))
                {
                    this.FillSPDeprecatedAPIStore();
                }
                if (member is Microsoft.FxCop.Sdk.Method)
                {
                    Microsoft.FxCop.Sdk.Method method = member as Microsoft.FxCop.Sdk.Method;
                    MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        Instruction current = enumerator.Current;
                        foreach (SPClaimsTypesToBeChecked checked2 in this.m_listSPDeprecatedAPIStore)
                        {
                            Problem problem;
                            if (current.Value is Local)
                            {
                                Local local = current.Value as Local;
                                fullName = (current.Value as Local).Type.FullName;
                                str3     = checked2.Namespace + "." + checked2.APIType;
                                if (fullName.Equals(str3))
                                {
                                    resolution = new Resolution("This rule is applicable only to SharePoint 2010 customizations. {0}", new string[] { checked2.Message });
                                    problem    = new Problem(resolution, current.SourceContext)
                                    {
                                        Certainty    = 90,
                                        FixCategory  = FixCategories.NonBreaking,
                                        Id           = this.GetNextId(),
                                        MessageLevel = MessageLevel.Warning
                                    };
                                    base.Problems.Add(problem);
                                    fullName = string.Empty;
                                    str3     = string.Empty;
                                    break;
                                }
                            }
                            else
                            {
                                if (null == (current.Value as Microsoft.FxCop.Sdk.Method))
                                {
                                    break;
                                }
                                Microsoft.FxCop.Sdk.Method method2 = current.Value as Microsoft.FxCop.Sdk.Method;
                                fullName = this.GetOnlyTheMethodName(method2.FullName);
                                str3     = checked2.Namespace + "." + checked2.APIType;
                                if (fullName.Equals(str3))
                                {
                                    resolution = new Resolution("This rule is applicable only to SharePoint 2010 customizations. {0}", new string[] { checked2.Message });
                                    problem    = new Problem(resolution, current.SourceContext)
                                    {
                                        Certainty    = 90,
                                        FixCategory  = FixCategories.NonBreaking,
                                        Id           = this.GetNextId(),
                                        MessageLevel = MessageLevel.Warning
                                    };
                                    base.Problems.Add(problem);
                                    str      = string.Empty;
                                    fullName = string.Empty;
                                    break;
                                }
                                MetadataCollection <Parameter> .Enumerator enumerator3 = method2.Parameters.GetEnumerator();
                                while (enumerator3.MoveNext())
                                {
                                    Parameter parameter = enumerator3.Current;
                                    fullName = parameter.Type.FullName;
                                    str3     = checked2.Namespace + "." + checked2.APIType;
                                    if (fullName.Equals(str3))
                                    {
                                        resolution = new Resolution("This rule is applicable only to SharePoint 2010 customizations. {0}", new string[] { checked2.Message });
                                        problem    = new Problem(resolution, current.SourceContext)
                                        {
                                            Certainty    = 90,
                                            FixCategory  = FixCategories.NonBreaking,
                                            Id           = this.GetNextId(),
                                            MessageLevel = MessageLevel.Warning
                                        };
                                        base.Problems.Add(problem);
                                        str      = string.Empty;
                                        fullName = string.Empty;
                                    }
                                }
                            }
                        }
                    }
                    this.VisitStatements(method.Body.Statements);
                }
            }
            catch (Exception exception)
            {
                Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointDeprecatedAPICheck:Check() - " + exception.Message);
            }
            return(base.Problems);
        }
Esempio n. 6
0
        public override ProblemCollection Check(ModuleNode module)
        {
            string str;

            try
            {
                Resolution namedResolution = null;
                int        num             = 0;
                MetadataCollection <TypeNode> .Enumerator enumerator = module.Types.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    TypeNode current = enumerator.Current;
                    if (current is ClassNode)
                    {
                        MetadataCollection <Member> .Enumerator enumerator2 = current.Members.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            Member member = enumerator2.Current;
                            if (member.FullName.Contains("CS$<>9__CachedAnonymousMethodDelegate") && ((Field)member).Type.ToString().Contains("Microsoft.SharePoint.SPSecurity+CodeToRunElevated"))
                            {
                                string[] strArray             = member.FullName.Split(new char[] { '_' });
                                int      DelegateMethodNumber = int.Parse(strArray[2].Substring(0x1d), NumberStyles.AllowHexSpecifier);
                                DelegateMethodNumber--;
                                Member member2 = (from t in current.Members
                                                  where t.FullName.Contains("b__" + Convert.ToString(DelegateMethodNumber, 0x10))
                                                  select t).FirstOrDefault <Member>();
                                string[] source = "SCardSvr,SNMPTRAP".Split(new char[] { ',' });
                                Method   method = member2 as Method;
                                if (null != method)
                                {
                                    for (short i = 0; i < method.Instructions.Count; i = (short)(i + 1))
                                    {
                                        Instruction instruction = method.Instructions[i];
                                        if (null != instruction.Value)
                                        {
                                            if (instruction.OpCode.ToString().Equals("Call") || instruction.OpCode.ToString().Equals("Callvirt"))
                                            {
                                                if (((instruction.Value.ToString().Equals("System.IO.Directory.Delete") || instruction.Value.ToString().Equals("System.IO.DirectoryInfo.Delete")) || instruction.Value.ToString().Equals("System.IO.File.Delete")) || instruction.Value.ToString().Equals("System.IO.FileSystemInfo.Delete"))
                                                {
                                                    namedResolution = this.GetNamedResolution("FileDeleteOperationCheck", new string[] { instruction.Value.ToString() });
                                                    base.Problems.Add(new Problem(namedResolution, Convert.ToString(num)));
                                                    num++;
                                                }
                                                if (instruction.Value.ToString().Equals("Microsoft.Office.Server.UserProfiles.UserProfileManager.RemoveUserProfile"))
                                                {
                                                    namedResolution = this.GetNamedResolution("ProfileDeleteOperationCheck", new string[] { method.Name.ToString() });
                                                    base.Problems.Add(new Problem(namedResolution, Convert.ToString(num)));
                                                    num++;
                                                }
                                            }
                                            if (((instruction.OpCode.ToString().Equals("Newobj") && instruction.Value.ToString().Contains("System.ServiceProcess.ServiceController(")) && method.Instructions[i - 1].OpCode.ToString().Equals("Ldstr")) && source.Contains <string>(method.Instructions[i - 1].Value.ToString()))
                                            {
                                                namedResolution = this.GetNamedResolution("ServiceOperationCheck", new string[] { method.Instructions[i - 1].Value.ToString() });
                                                base.Problems.Add(new Problem(namedResolution, Convert.ToString(num)));
                                                num++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (NullReferenceException exception)
            {
                str = string.Empty;
                Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SharePointMonitorScopeWebpartCheck" + exception.Message);
            }
            catch (Exception exception2)
            {
                str = string.Empty;
                Logging.UpdateLog((CustomRulesResource.ErrorOccured + "SharePointMonitorScopeWebpartCheck") + exception2.InnerException.Message + exception2.Message);
            }
            return(base.Problems);
        }
        public void VisitWebServiceClass(ClassNode classType)
        {
            Method     method     = null;
            Resolution resolution = null;

            MetadataCollection <Member> .Enumerator enumerator = classType.Members.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Member current = enumerator.Current;
                if (null != (current as Method))
                {
                    method = current as Method;
                    for (int i = 0; i < method.Instructions.Count; i++)
                    {
                        Problem problem;
                        if (((null == method.Instructions[i].Value) || (!method.Instructions[i].OpCode.Equals(OpCode.Call) && !method.Instructions[i].OpCode.Equals(OpCode.Callvirt))) || ((!method.Instructions[i].Value.ToString().Contains("System.Data.Common.DbConnection.Open") && !method.Instructions[i].Value.ToString().Contains("System.Data.SqlClient")) && !method.Instructions[i].Value.ToString().Contains("System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke")))
                        {
                            continue;
                        }
                        for (int j = i; j >= 0; j--)
                        {
                            if (method.Instructions[j].OpCode.Equals(OpCode.Callvirt))
                            {
                                if (!method.Instructions[j].Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace"))
                                {
                                    resolution = new Resolution("Please add SPDiagnostics WriteTrace call at start and end of every Web Service call - {0}", new string[] { method.FullName });
                                    problem    = new Problem(resolution, method.Instructions[j].SourceContext, Convert.ToString(this.iStringIdForProblem))
                                    {
                                        Certainty    = 90,
                                        FixCategory  = FixCategories.NonBreaking,
                                        MessageLevel = MessageLevel.Warning
                                    };
                                    base.Problems.Add(problem);
                                    this.iStringIdForProblem++;
                                }
                                break;
                            }
                            if (j == 1)
                            {
                                resolution = new Resolution("Please add SPDiagnostics WriteTrace call at start and end of every Web Service call - {0}", new string[] { method.FullName });
                                problem    = new Problem(resolution, method.Instructions[j].SourceContext, Convert.ToString(this.iStringIdForProblem))
                                {
                                    Certainty    = 90,
                                    FixCategory  = FixCategories.NonBreaking,
                                    MessageLevel = MessageLevel.Warning
                                };
                                base.Problems.Add(problem);
                                this.iStringIdForProblem++;
                                break;
                            }
                        }
                        for (int k = i; k >= method.Instructions.Count; k++)
                        {
                            if (method.Instructions[k].OpCode.Equals(OpCode.Callvirt))
                            {
                                if (!method.Instructions[k].Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace"))
                                {
                                    resolution = new Resolution("Please add SPDiagnostics WriteTrace call at start and end of every Web Service call - {0}", new string[] { method.FullName });
                                    problem    = new Problem(resolution, method.Instructions[k].SourceContext, Convert.ToString(this.iStringIdForProblem))
                                    {
                                        Certainty    = 90,
                                        FixCategory  = FixCategories.NonBreaking,
                                        MessageLevel = MessageLevel.Warning
                                    };
                                    base.Problems.Add(problem);
                                    this.iStringIdForProblem++;
                                }
                                break;
                            }
                            if (k == (method.Instructions.Count - 1))
                            {
                                resolution = new Resolution("Please add SPDiagnostics WriteTrace call at start and end of every Web Service call - {0}", new string[] { method.FullName });
                                problem    = new Problem(resolution, method.Instructions[k].SourceContext, Convert.ToString(this.iStringIdForProblem))
                                {
                                    Certainty    = 90,
                                    FixCategory  = FixCategories.NonBreaking,
                                    MessageLevel = MessageLevel.Warning
                                };
                                base.Problems.Add(problem);
                                this.iStringIdForProblem++;
                                break;
                            }
                        }
                    }
                }
            }
        }
        public void VisitEventReceiverMethod(Method method)
        {
            Resolution resolution = null;

            try
            {
                Problem problem;
                MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Instruction current = enumerator.Current;
                    if (null != current.Value)
                    {
                        if (current.OpCode.Equals(OpCode.Call))
                        {
                            if (current.Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsService.get_Local"))
                            {
                                continue;
                            }
                            resolution = new Resolution("Please add SPDiagnostics WriteTrace call at start and end of Function {0}", new string[] { method.FullName });
                            problem    = new Problem(resolution, current.SourceContext, Convert.ToString(this.iStringIdForProblem))
                            {
                                Certainty    = 90,
                                FixCategory  = FixCategories.NonBreaking,
                                MessageLevel = MessageLevel.Warning
                            };
                            base.Problems.Add(problem);
                            this.iStringIdForProblem++;
                            break;
                        }
                        if (current.OpCode.Equals(OpCode.Callvirt))
                        {
                            if (!current.Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace"))
                            {
                                resolution = new Resolution("Please add SPDiagnostics WriteTrace call at start and end of Function {0}", new string[] { method.FullName });
                                problem    = new Problem(resolution, current.SourceContext, Convert.ToString(this.iStringIdForProblem))
                                {
                                    Certainty    = 90,
                                    FixCategory  = FixCategories.NonBreaking,
                                    MessageLevel = MessageLevel.Warning
                                };
                                base.Problems.Add(problem);
                                this.iStringIdForProblem++;
                            }
                            break;
                        }
                    }
                }
                for (int i = method.Instructions.Count - 1; i >= 0; i--)
                {
                    if (method.Instructions[i].OpCode.Equals(OpCode.Callvirt))
                    {
                        if (!method.Instructions[i].Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace"))
                        {
                            resolution = new Resolution("Please add SPDiagnostics WriteTrace call at start and end of Function {0}", new string[] { method.FullName });
                            problem    = new Problem(resolution, method.Instructions[i].SourceContext, Convert.ToString(this.iStringIdForProblem))
                            {
                                Certainty    = 90,
                                FixCategory  = FixCategories.NonBreaking,
                                MessageLevel = MessageLevel.Warning
                            };
                            base.Problems.Add(problem);
                            this.iStringIdForProblem++;
                        }
                        return;
                    }
                    if (method.Instructions[i].OpCode.Equals(OpCode.Call))
                    {
                        resolution = new Resolution("Please add SPDiagnostics WriteTrace call at start and end of Function {0}", new string[] { method.FullName });
                        problem    = new Problem(resolution, method.Instructions[i].SourceContext, Convert.ToString(this.iStringIdForProblem))
                        {
                            Certainty    = 90,
                            FixCategory  = FixCategories.NonBreaking,
                            MessageLevel = MessageLevel.Warning
                        };
                        base.Problems.Add(problem);
                        this.iStringIdForProblem++;
                        return;
                    }
                }
            }
            catch (Exception exception)
            {
                Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SPDiagnosticsServiceVisitEventReceiverMethod" + exception.Message);
            }
        }
 public override ProblemCollection Check(ModuleNode module)
 {
     if (module is AssemblyNode)
     {
         Resolution resolution;
         Problem    problem;
         MetadataCollection <TypeNode> .Enumerator enumerator = ((AssemblyNode)module).Types.GetEnumerator();
         while (enumerator.MoveNext())
         {
             TypeNode current = enumerator.Current;
             this.Check(current);
         }
         this.PopulateCallers();
         foreach (Method method in this.methodsToProcessFinally.Values)
         {
             if (method.Instructions.Any <Instruction>(t => t.OpCode == OpCode._Catch))
             {
                 bool flag      = false;
                 bool flag2     = false;
                 bool flag4     = false;
                 int  startLine = 0;
                 int  num2      = -1;
                 int  num3      = 0;
                 int  num4      = 0;
                 Stack <SourceContext> stack = new Stack <SourceContext>();
                 MetadataCollection <Instruction> .Enumerator enumerator3 = method.Instructions.GetEnumerator();
                 while (enumerator3.MoveNext())
                 {
                     Instruction instruction = enumerator3.Current;
                     num2++;
                     if (instruction.OpCode == OpCode._Catch)
                     {
                         flag = true;
                         num3++;
                         stack.Push(instruction.SourceContext);
                     }
                     else if (flag)
                     {
                         if (instruction.OpCode == OpCode._EndHandler)
                         {
                             flag2 = true;
                             Instruction instruction2 = method.Instructions[num2 - 1];
                             startLine = instruction2.SourceContext.StartLine;
                             num4++;
                         }
                         if (!flag2)
                         {
                             if ((instruction.OpCode == OpCode.Call) && this.CheckInstructionValue(instruction))
                             {
                                 flag4 = true;
                                 flag2 = true;
                                 num4++;
                             }
                             if ((instruction.OpCode == OpCode.Throw) || (instruction.OpCode == OpCode.Rethrow))
                             {
                                 flag4 = true;
                                 flag2 = true;
                                 num4++;
                             }
                         }
                         if (flag2)
                         {
                             SourceContext sourceContext = stack.Pop();
                             lock (SyncObjectForProblemAddition)
                             {
                                 if (!flag4)
                                 {
                                     string str   = string.Empty;
                                     bool   flag5 = false;
                                     if (string.IsNullOrEmpty(sourceContext.FileName))
                                     {
                                         str = "'[symbols not found to locate the line number]'";
                                     }
                                     else
                                     {
                                         str   = sourceContext.StartLine.ToString();
                                         flag5 = true;
                                     }
                                     resolution = new Resolution("The catch block at line number {0} in method {1} must log to ULS Logs. For ULS logging, please use the TraceEvent sample on MSDN or Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace API in SharePoint 2010.", new string[] { str, method.FullName });
                                     if (flag5)
                                     {
                                         if (!fullyQualifiedResolutionStrings.Contains(resolution.ToString()))
                                         {
                                             problem = new Problem(resolution, sourceContext)
                                             {
                                                 Certainty    = 90,
                                                 FixCategory  = FixCategories.NonBreaking,
                                                 Id           = this.GetNextId(),
                                                 MessageLevel = MessageLevel.Warning
                                             };
                                             base.Problems.Add(problem);
                                             fullyQualifiedResolutionStrings.Add(resolution.ToString());
                                         }
                                     }
                                     else
                                     {
                                         problem = new Problem(resolution, sourceContext)
                                         {
                                             Certainty    = 90,
                                             FixCategory  = FixCategories.NonBreaking,
                                             Id           = this.GetNextId(),
                                             MessageLevel = MessageLevel.Warning
                                         };
                                         base.Problems.Add(problem);
                                     }
                                 }
                             }
                             if (num3 == num4)
                             {
                                 flag = false;
                             }
                             flag2 = false;
                             flag4 = false;
                         }
                     }
                 }
             }
         }
         foreach (Method method in this.methodsThatCallUnsupportedMethodsIndirectly.Values)
         {
             resolution = new Resolution("Method '{0}' calls one or both of the unsupported APIs '{1}' and '{2}' indirectly. For ULS logging, please use the TraceEvent sample on MSDN or Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace API in SharePoint 2010.", new string[] { this.GetOnlyTheMethodName(method.FullName), "Microsoft.Office.Server.Diagnostics.PortalLog.LogString", "Microsoft.Office.Server.Diagnostics.PortalLog.DebugLogString" });
             problem    = new Problem(resolution, method.SourceContext)
             {
                 Certainty    = 90,
                 FixCategory  = FixCategories.NonBreaking,
                 Id           = this.GetNextId(),
                 MessageLevel = MessageLevel.Warning
             };
             base.Problems.Add(problem);
         }
     }
     return(base.Problems);
 }
Esempio n. 10
0
        private bool DoesMethodCallUnsupportedMethods(Method method)
        {
            if (this.methodsThatCallUnsupportedMethodsDirectly.ContainsKey(this.GetOnlyTheMethodName(method.FullName)))
            {
                return(true);
            }
            bool flag = false;

            MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Instruction current = enumerator.Current;
                if ((current.OpCode == OpCode.Call) && (current.Value.ToString().Equals("Microsoft.Office.Server.Diagnostics.PortalLog.LogString") || current.Value.ToString().Equals("Microsoft.Office.Server.Diagnostics.PortalLog.DebugLogString")))
                {
                    string str   = string.Empty;
                    bool   flag2 = false;
                    if (string.IsNullOrEmpty(current.SourceContext.FileName))
                    {
                        str = "'[symbols not found to locate the line number]'";
                    }
                    else
                    {
                        str   = current.SourceContext.StartLine.ToString();
                        flag2 = false;
                    }
                    Resolution resolution = new Resolution("Method '{0}' calls '{1}' at line number {2} which is unsupported. For ULS logging, please use the TraceEvent sample on MSDN or Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace API in SharePoint 2010.", new string[] { this.GetOnlyTheMethodName(method.FullName), current.Value.ToString(), str });
                    lock (SyncObjectForProblemAddition)
                    {
                        Problem problem;
                        if (flag2)
                        {
                            if (!fullyQualifiedResolutionStrings.Contains(resolution.ToString()))
                            {
                                problem = new Problem(resolution, current.SourceContext)
                                {
                                    Certainty    = 90,
                                    FixCategory  = FixCategories.NonBreaking,
                                    Id           = this.GetNextId(),
                                    MessageLevel = MessageLevel.Warning
                                };
                                base.Problems.Add(problem);
                                fullyQualifiedResolutionStrings.Add(resolution.ToString());
                            }
                        }
                        else
                        {
                            problem = new Problem(resolution, current.SourceContext)
                            {
                                Certainty    = 90,
                                FixCategory  = FixCategories.NonBreaking,
                                Id           = this.GetNextId(),
                                MessageLevel = MessageLevel.Warning
                            };
                            base.Problems.Add(problem);
                        }
                        flag = true;
                    }
                }
            }
            return(flag);
        }
Esempio n. 11
0
 public void VisitFeatureReceiverMethod(Method method)
 {
     try
     {
         if (method.Instructions.Any <Instruction>(t => t.OpCode == OpCode._Catch))
         {
             bool flag      = false;
             bool flag2     = false;
             bool flag3     = false;
             bool flag4     = false;
             int  startLine = 0;
             int  num2      = -1;
             int  num3      = 0;
             int  num4      = 0;
             Stack <SourceContext> stack = new Stack <SourceContext>();
             MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 Instruction current = enumerator.Current;
                 num2++;
                 if (current.OpCode == OpCode._Catch)
                 {
                     flag = true;
                     num3++;
                     stack.Push(current.SourceContext);
                 }
                 else if (flag)
                 {
                     if (current.OpCode == OpCode._EndHandler)
                     {
                         flag2 = true;
                         Instruction instruction2 = method.Instructions[num2 - 1];
                         startLine = instruction2.SourceContext.StartLine;
                         num4++;
                     }
                     if (!flag2)
                     {
                         if (((current.OpCode == OpCode.Call) || (current.OpCode == OpCode.Callvirt)) && this.CheckInstructionValue(current))
                         {
                             flag4 = true;
                         }
                         if ((current.OpCode == OpCode.Throw) || (current.OpCode == OpCode.Rethrow))
                         {
                             flag3 = true;
                             flag2 = true;
                             num4++;
                         }
                     }
                     if (flag2)
                     {
                         string        str;
                         bool          flag5;
                         Resolution    resolution;
                         Problem       problem;
                         SourceContext sourceContext = stack.Pop();
                         if (!flag4)
                         {
                             str   = string.Empty;
                             flag5 = false;
                             if (string.IsNullOrEmpty(sourceContext.FileName))
                             {
                                 str = "'[symbols not found to locate the line number]'";
                             }
                             else
                             {
                                 str   = sourceContext.StartLine.ToString();
                                 flag5 = true;
                             }
                             resolution = new Resolution("The catch block at line number {0} in method {1} must log to ULS Logs. For ULS logging, please use the Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace API in SharePoint 2010.", new string[] { str, method.FullName });
                             if (flag5)
                             {
                                 if (!fullyQualifiedResolutionStrings.Contains(resolution.ToString()))
                                 {
                                     problem = new Problem(resolution, sourceContext)
                                     {
                                         Certainty    = 90,
                                         FixCategory  = FixCategories.NonBreaking,
                                         Id           = this.GetNextId(),
                                         MessageLevel = MessageLevel.Warning
                                     };
                                     base.Problems.Add(problem);
                                     fullyQualifiedResolutionStrings.Add(resolution.ToString());
                                 }
                             }
                             else
                             {
                                 problem = new Problem(resolution, sourceContext)
                                 {
                                     Certainty    = 90,
                                     FixCategory  = FixCategories.NonBreaking,
                                     MessageLevel = MessageLevel.Warning
                                 };
                                 base.Problems.Add(problem);
                             }
                         }
                         if (!flag3)
                         {
                             str   = string.Empty;
                             flag5 = false;
                             if (string.IsNullOrEmpty(sourceContext.FileName))
                             {
                                 str = "'[symbols not found to locate the line number]'";
                             }
                             else
                             {
                                 str   = sourceContext.StartLine.ToString();
                                 flag5 = true;
                             }
                             resolution = new Resolution("The catch block at line number {0} in method {1} must throw the exception back to SharePoint.", new string[] { str, method.FullName });
                             if (flag5)
                             {
                                 if (!fullyQualifiedResolutionStrings.Contains(resolution.ToString()))
                                 {
                                     problem = new Problem(resolution, sourceContext)
                                     {
                                         Certainty    = 90,
                                         FixCategory  = FixCategories.NonBreaking,
                                         Id           = this.GetNextId(),
                                         MessageLevel = MessageLevel.Warning
                                     };
                                     base.Problems.Add(problem);
                                     fullyQualifiedResolutionStrings.Add(resolution.ToString());
                                 }
                             }
                             else
                             {
                                 problem = new Problem(resolution, sourceContext)
                                 {
                                     Certainty    = 90,
                                     FixCategory  = FixCategories.NonBreaking,
                                     MessageLevel = MessageLevel.Warning
                                 };
                                 base.Problems.Add(problem);
                             }
                         }
                         if (num3 == num4)
                         {
                             flag = false;
                         }
                         flag2 = false;
                         flag4 = false;
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SPFeatureReceiverMethod" + exception.Message);
     }
 }
Esempio n. 12
0
        private bool VisitFeatureReceiverDiagnosis(Method method)
        {
            bool flag3;
            bool flag  = true;
            bool flag2 = true;

            try
            {
                MetadataCollection <Instruction> .Enumerator enumerator = method.Instructions.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    Instruction current = enumerator.Current;
                    if ((null != current.Value) && (!current.OpCode.Equals(OpCode._Locals) && !current.OpCode.Equals(OpCode.Nop)))
                    {
                        if (current.OpCode.Equals(OpCode.Call))
                        {
                            if (current.Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsService.get_Local") || current.Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.get_Areas"))
                            {
                                continue;
                            }
                            flag = false;
                            break;
                        }
                        if (current.OpCode.Equals(OpCode.Callvirt))
                        {
                            if (!current.Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace"))
                            {
                                flag = false;
                            }
                            break;
                        }
                    }
                }
                for (int i = method.Instructions.Count - 1; i >= 0; i--)
                {
                    if (method.Instructions[i].OpCode.Equals(OpCode.Callvirt))
                    {
                        if (!method.Instructions[i].Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.WriteTrace"))
                        {
                            if (method.Instructions[i].Value.ToString().Contains("Microsoft.SharePoint.Administration.SPDiagnosticsServiceBase.get_Areas"))
                            {
                                continue;
                            }
                            flag2 = false;
                        }
                        goto Label_0255;
                    }
                    if (method.Instructions[i].OpCode.Equals(OpCode.Call))
                    {
                        flag2 = false;
                        goto Label_0255;
                    }
                }
            }
            catch (Exception exception)
            {
                Logging.UpdateLog(CustomRulesResource.ErrorOccured + "SPDiagnosticsServiceVisitFeatureReceiverMethod" + exception.Message);
            }
Label_0255:
            flag3 = false;
            if (flag || flag2)
            {
                flag3 = true;
            }
            return(flag3);
        }
Esempio n. 13
0
        public void VisitFeatureReceiverClass(ClassNode classType)
        {
            Method method = null;
            string str    = string.Empty;
            bool   flag   = false;

            MetadataCollection <Member> .Enumerator enumerator = classType.Members.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Member current = enumerator.Current;
                if (null != (current as Method))
                {
                    method = current as Method;
                    if (((method.Name.Name.Equals("FeatureActivated") || method.Name.Name.Equals("FeatureDeactivating")) || (method.Name.Name.Equals("FeatureInstalled") || method.Name.Name.Equals("FeatureUninstalling"))) || method.Name.Name.Equals("FeatureUpgrading"))
                    {
                        if (this.HasProblem(method))
                        {
                            Problem problem;
                            flag = false;
                            Resolution resolution = new Resolution("The method {0} does not implement a top level try catch block", new string[] { this.GetOnlyTheMethodName(method.FullName) });
                            if (string.IsNullOrEmpty(method.SourceContext.FileName))
                            {
                                str = "'[symbols not found to locate the line number]'";
                            }
                            else
                            {
                                str  = method.SourceContext.StartLine.ToString();
                                flag = true;
                            }
                            if (flag)
                            {
                                if (!fullyQualifiedResolutionStrings.Contains(resolution.ToString()))
                                {
                                    problem = new Problem(resolution, method.SourceContext)
                                    {
                                        Certainty    = 90,
                                        FixCategory  = FixCategories.NonBreaking,
                                        Id           = this.GetNextId(),
                                        MessageLevel = MessageLevel.Warning
                                    };
                                    base.Problems.Add(problem);
                                    fullyQualifiedResolutionStrings.Add(resolution.ToString());
                                }
                            }
                            else
                            {
                                problem = new Problem(resolution, method.SourceContext)
                                {
                                    Certainty    = 90,
                                    FixCategory  = FixCategories.NonBreaking,
                                    Id           = this.GetNextId(),
                                    MessageLevel = MessageLevel.Warning
                                };
                                base.Problems.Add(problem);
                            }
                        }
                        this.VisitFeatureReceiverMethod(method);
                    }
                }
            }
        }