예제 #1
0
        public void VisitCallGraph(CallGraph graph)
        {
            string        details = string.Empty;
            List <string> chain   = new List <string>();

            foreach (MethodReference method in m_dispatcher.ClassifyMethod.ThreadRoots())
            {
                chain.Clear();
                m_visited.Clear();
                if (DoFoundBadSetter(graph, method, chain))
                {
                    details = string.Format("{0}{1}{1}{2}", ListExtensions.Accumulate(
                                                chain, string.Empty,
                                                (s, e) => s.Length > 0 ? s + " -> " + Environment.NewLine + e : e),
                                            Environment.NewLine, details);
                }
            }

            details = details.Trim();
            if (details.Length > 0)
            {
                Log.DebugLine(this, details);
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
            }
        }
예제 #2
0
 public void VisitAssembly(AssemblyDefinition assembly)
 {
     if (assembly.SecurityDeclarations.Count == 0)
     {
         Reporter.AssemblyFailed(assembly, CheckID, string.Empty);
     }
 }
예제 #3
0
        public void VisitModule(ModuleDefinition module)
        {
            Log.DebugLine(this, "-----------------------------------");
            Log.DebugLine(this, "{0}", module.Name);

            foreach (AssemblyNameReference reference in module.AssemblyReferences)
            {
                Log.DebugLine(this, "references {0}", reference.Name);
                if (reference.Name == "System.Windows.Forms")
                {
                    MethodDefinition main = module.Assembly.EntryPoint;
                    if (main != null)
                    {
                        Log.DebugLine(this, "{0}", main);

                        bool foundSTA = main.CustomAttributes.Has("STAThreadAttribute");
                        if (!foundSTA)
                        {
                            Log.DebugLine(this, "no STAThread");
                            Reporter.AssemblyFailed(module.Assembly, CheckID, string.Empty);
                        }
                    }
                }
            }
        }
예제 #4
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            if (m_methods.Count > 0)
            {
                Log.TraceLine(this, "{0} methods were not called", m_methods.Count);
                CompareNames comparer = new CompareNames();
                m_methods.Sort(comparer);

                StringBuilder builder = new StringBuilder();
                builder.AppendLine("Methods: ");
                for (int i = 0; i < m_methods.Count; ++i)
                {
                    builder.Append(m_methods[i].ToString());
                    if (i + 1 < m_methods.Count)
                    {
                        builder.AppendLine();
                    }
                }

                string details = builder.ToString();

                Log.TraceLine(this, details);
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
            }
        }
        public void VisitAssembly(AssemblyDefinition assembly)
        {
            Log.DebugLine(this, "-----------------------------------");
            Log.DebugLine(this, "checking {0}", assembly.Name);

            if (Aspell.Instance != null)
            {
                string details = string.Empty;
                foreach (CustomAttribute attr in assembly.CustomAttributes)
                {
                    foreach (object o in attr.ConstructorParameters)
                    {
                        string text = o.ToString();
                        Unused.Value = CheckSpelling.Text(text, ref details);
                    }
                }

                if (details.Length > 0)
                {
                    details = "Words: " + details;
                    Log.DebugLine(this, details);
                    Reporter.AssemblyFailed(assembly, CheckID, details);
                }
            }
        }
예제 #6
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            string details = string.Empty;

            foreach (KeyValuePair <string, List <string> > entry in m_table)
            {
                if (entry.Value.Count > 4)
                {
                    string prefix = DoGetPrefix(entry.Key, entry.Value);
                    if (prefix != null)
                    {
                        if (details.Length > 0)
                        {
                            details += Environment.NewLine;
                        }
                        details += string.Format("{0} classes use \"{1}\"", entry.Key, prefix);
                    }
                }
            }

            if (details.Length > 0)
            {
                Log.DebugLine(this, details);
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
            }
        }
예제 #7
0
        public void VisitGraph(CallGraph graph)
        {
            string bad = string.Empty;

            // Iterate over each method in the assembly,
            foreach (KeyValuePair <MethodReference, List <MethodReference> > entry in graph.Entries())
            {
                // if it does not have a security demand then,
                MethodInfo info = Cache.FindMethod(entry.Key);
                if (info != null && info.Method.ExternallyVisible(Cache) && !DoHasSecurityDemand(info.Method))
                {
                    foreach (MethodReference callee in entry.Value)
                    {
                        // if it's calling a method with a link demand then
                        // we have a problem. Note that we won't find the
                        // method info if the callee is in a different assembly.
                        info = Cache.FindMethod(callee);
                        if (info != null && DoHasLinkDemand(info.Method))
                        {
                            Log.DebugLine(this, "bad: {0}", info.Method);
                            bad = string.Format("{0} {1}", bad, info.Method);
                        }
                    }
                }
            }

            if (bad.Length > 0)
            {
                string details = "Methods: " + bad;
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
            }
        }
예제 #8
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            if (m_foundAdd && !m_foundOvf)
            {
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, string.Empty);
            }
        }
예제 #9
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            if (m_details.Length > 0)
            {
                m_details = "Asserting: " + m_details;
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, m_details);
            }
        }
예제 #10
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            if (m_callsRun && m_callsExit)
            {
                m_details = "Calls Exit: " + m_details;
                Log.DebugLine(this, m_details);
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, m_details);
            }
        }
예제 #11
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            if (m_foundRun)
            {
                if (!m_foundStyle || !m_foundCompatible)
                {
                    Reporter.AssemblyFailed(Cache.Assembly, CheckID, string.Empty);
                }
            }
        }
예제 #12
0
        public void VisitAsembly(AssemblyDefinition assembly)
        {
            Log.DebugLine(this, "hasGui: {1}, kind: {1}", assembly.IsGui(), assembly.Kind);

            if (assembly.EntryPoint != null && assembly.IsGui())
            {
                if (assembly.Kind != AssemblyKind.Windows)
                {
                    Reporter.AssemblyFailed(assembly, CheckID, string.Empty);
                }
            }
        }
예제 #13
0
 public void VisitAssembly(AssemblyDefinition assembly)
 {
     if (Cache.HasPublicTypes)
     {
         bool foundCLS = assembly.CustomAttributes.Has("CLSCompliantAttribute");
         if (!foundCLS)
         {
             Log.DebugLine(this, "no CLSCompliantAttribute");
             Reporter.AssemblyFailed(assembly, CheckID, string.Empty);
         }
     }
 }
예제 #14
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            if (m_bad.Count > 0)
            {
                string details = "Bad Calls: " + string.Join(Environment.NewLine, m_bad.ToArray());
                Log.DebugLine(this, details);

                Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
            }
        }
예제 #15
0
        // This is visited after methods.
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            DBC.Assert(m_state == State.Calls, "state is {0}", m_state);
            m_state = State.End;

            if (m_types.Count > 0)
            {
                string details = "Unused: " + string.Join(Environment.NewLine, m_types.ToArray());
                Log.DebugLine(this, details);

                Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
            }
        }
예제 #16
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            List <string> bad = new List <string>();

            DoGetMatches(bad, m_namespaces, "Namespaces: ");
            DoGetMatches(bad, m_types, "Types: ");

            if (bad.Count > 0)
            {
                string details = string.Join(Environment.NewLine, bad.ToArray());
                Log.DebugLine(this, details);
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
            }
        }
예제 #17
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            if (Cache.Assembly.EntryPoint != null)
            {
                Log.DebugLine(this, "entry point: {0}", Cache.Assembly.EntryPoint);

                if (m_details.Length != 0)
                {
                    m_details = "Public types: " + m_details;

                    Log.DebugLine(this, m_details);
                    Reporter.AssemblyFailed(Cache.Assembly, CheckID, m_details);
                }
            }
        }
예제 #18
0
        public void VisitGraph(CallGraph graph)
        {
            m_graph = graph;

            // If the assembly is mixed transparent/critical then we may have critical
            // methods.
            if (m_mixed)
            {
                List <string> lines = new List <string>();

                // So, for each method,
                foreach (KeyValuePair <MethodReference, List <MethodReference> > entry in graph.Entries())
                {
                    MethodInfo caller = Cache.FindMethod(entry.Key);
                    if (caller != null)
                    {
                        // if it's public,
                        MethodAttributes access = caller.Method.Attributes & MethodAttributes.MemberAccessMask;
                        if (access == MethodAttributes.Public)
                        {
                            // and transparent,
                            if (!caller.Method.CustomAttributes.Has("SecurityCriticalAttribute"))
                            {
                                // then fail if it calls a non-public critical method.
                                string line = DoIsBad(caller.Method, entry.Value, 1);
                                if (line.Length > 0)
                                {
                                    lines.Add(line);
                                }
                            }
                        }
                    }
                }

                if (lines.Count > 0)
                {
                    string details = string.Join(Environment.NewLine, lines.ToArray());
//					Console.WriteLine(details);
                    Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
                }
            }
        }
예제 #19
0
        public void VisitEnd(EndTesting end)
        {
            Unused.Value = end;

            if (m_downloader.Complete)
            {
                string[] parts = m_downloader.Contents.Trim().Split('.');
                int      newMajor, newMinor;

                if (parts.Length == 2 && int.TryParse(parts[0], out newMajor) && int.TryParse(parts[1], out newMinor))
                {
                    Version installed = Assembly.GetExecutingAssembly().GetName().Version;

                    if (newMajor > installed.Major || (newMajor == installed.Major && newMinor > installed.Minor))
                    {
                        string details = string.Empty;
                        details += "Latest Version:    " + m_downloader.Contents + Environment.NewLine;
                        details += "Installed Version: " + installed.Major + "." + installed.Minor;
                        Log.DebugLine(this, details);

                        Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
                    }
                    else
                    {
                        Log.DebugLine(this, "installed version is OK");
                        Log.DebugLine(this, "installed: {0}", installed);
                        Log.DebugLine(this, "latest: {0}.{1}", newMajor, newMinor);
                    }
                }
                else
                {
                    Log.ErrorLine(this, "Bad download: '{0}'", m_downloader.Contents);
                }
            }
            else
            {
                TimeSpan duration = DateTime.Now - m_startTime;
                Log.WarningLine(this, "NewVersionRule wasn't able to download the version number within {0:0.000} seconds", duration.TotalSeconds);

                m_downloader.Cancel();
            }
        }
예제 #20
0
        public void VisitAssembly(AssemblyDefinition assembly)
        {
            if (assembly.Name.PublicKey == null || assembly.Name.PublicKey.Length == 0)
            {
                Log.DebugLine(this, "{0} has null or zero length public key", assembly.Name.Name);
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, string.Empty);
            }
            else
            {
                foreach (byte b in assembly.Name.PublicKey)
                {
                    if (b != 0)
                    {
                        return;
                    }
                }

                Log.DebugLine(this, "{0} has public key of all zeros", assembly.Name.Name);
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, string.Empty);
            }
        }
예제 #21
0
        public void VisitEnd(EndTypes end)
        {
            Unused.Value = end;

            int maxNames = Settings.Get("maxNamespace", 40);

            string details = string.Empty;

            foreach (KeyValuePair <string, int> entry in m_counts)
            {
                if (entry.Value > maxNames)
                {
                    details = string.Format("{0} has {1} public types. {2}", entry.Key, entry.Value, details);
                }
            }

            if (details.Length > 0)
            {
                Log.DebugLine(this, details);
                Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
            }
        }
예제 #22
0
        public void VisitAssembly(AssemblyDefinition assembly)
        {
            Log.DebugLine(this, "-----------------------------------");
            Log.DebugLine(this, "checking {0}", assembly.Name);

            if (assembly.Name.Version.Major == 0 && assembly.Name.Version.MajorRevision == 0 &&
                assembly.Name.Version.Minor == 0 && assembly.Name.Version.MinorRevision == 0 &&
                assembly.Name.Version.Revision == 0)
            {
                Log.DebugLine(this, "version is zero");
                Reporter.AssemblyFailed(assembly, CheckID, string.Empty);
            }
            else
            {
                bool foundDesc = assembly.CustomAttributes.Has("AssemblyDescriptionAttribute");
                if (!foundDesc)
                {
                    Log.DebugLine(this, "no AssemblyDescriptionAttribute");
                    Reporter.AssemblyFailed(assembly, CheckID, string.Empty);
                }
            }
        }
예제 #23
0
        public void VisitFini(EndTesting end)
        {
            Unused.Value = end;

            if (m_needsCheck)
            {
                List <string> fields = new List <string>();

                foreach (KeyValuePair <FieldReference, State> entry in m_fields)
                {
                    if (entry.Value == State.Defined)
                    {
                        fields.Add(entry.Key.ToString());
                    }
                }

                if (fields.Count > 0)
                {
                    string details = "Fields: " + string.Join(Environment.NewLine, fields.ToArray());
                    Log.DebugLine(this, details);
                    Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
                }
            }
        }
예제 #24
0
        public void VisitCalls(CallGraph graph)
        {
            if (!m_disabled)
            {
                string details = string.Empty;

                IEnumerable <MethodReference> roots = m_dispatcher.ClassifyMethod.ThreadRoots();

                details += DoCheckForUnmarkedRoots(roots);
                if (m_knownRoots.Count > 0)
                {
                    details += DoCheckForUnsafeMethods(graph);
                }
                details += DoCheckForBadSafe(roots);
                details += DoCheckForBadSafeTypes();

                details = details.Trim();
                if (details.Length > 0)
                {
                    Log.DebugLine(this, "Details: {0}", details);
                    Reporter.AssemblyFailed(Cache.Assembly, CheckID, details);
                }
            }
        }