Example #1
0
        internal AssemblyCache(SymbolTable symbols, AssemblyDefinition assembly, Rule.KeepAliveCallback callback)
        {
            DBC.Pre(symbols != null, "symbols is null");
            DBC.Pre(assembly != null, "assembly is null");

            Profile.Start("AssemblyCache ctor");
            m_symbols  = symbols;
            m_assembly = assembly;

            // For some reason we have to force the Mdb assembly to load. If we don't it
            // isn't found.
            Unused.Value = typeof(Mono.Cecil.Mdb.MdbFactory);

            foreach (ModuleDefinition module in assembly.Modules)
            {
                try
                {
                    module.LoadSymbols();
                }
                catch
                {
                    Console.Error.WriteLine("Couldn't load symbols so there will be no file or line numbers.");
                }

                // Note that if the type is generic it will be listed once with a name like SomeType`1
                // where the number of the number of generic arguments.
                foreach (TypeDefinition type in module.Types)
                {
                    DoCheckForPublics(type);

                    TypeKey key = new TypeKey(type);
                    if (!m_types.ContainsKey(key))
                    {
                        m_types.Add(key, type);
                    }
                    else if (!type.FullName.Contains("CompilerGenerated"))
                    {
                        m_types[key] = type;                                                                                    // replace Database`1/<>c__CompilerGenerated5 with Database`1
                    }
                    Log.DebugLine(this, "adding {0}", type.FullName);
                    if (callback != null)
                    {
                        callback(string.Format("adding {0}", type.Name));
                    }

                    List <MethodInfo> ml = new List <MethodInfo>();
                    DoAddMethods(symbols, type, type.Constructors, ml);
                    DoAddMethods(symbols, type, type.Methods, ml);
                    m_typeMethods.Add(type, ml);
                }
            }

            DoLoadDependentAssemblies(callback);

            Profile.Stop("AssemblyCache ctor");
        }
Example #2
0
        private void DoLoadDependentAssemblies(Rule.KeepAliveCallback callback)
        {
            foreach (ModuleDefinition module in m_assembly.Modules)
            {
                foreach (AssemblyNameReference assemblyName in module.AssemblyReferences)
                {
                    Log.InfoLine(this, "loading dependent assembly '{0}'", assemblyName);

                    try
                    {
                        AssemblyDefinition subAssembly = m_assembly.Resolver.Resolve(assemblyName);
                        m_depedent.Add(subAssembly);

                        foreach (ModuleDefinition subModule in subAssembly.Modules)
                        {
                            foreach (TypeDefinition type in subModule.Types)
                            {
                                if (!m_externalTypes.ContainsKey(type.FullName))
                                {
//									Log.InfoLine(true, "   {0} {1}", type.FullName, type.MetadataToken);
                                    m_externalTypes.Add(type.FullName, type);

                                    if (callback != null)
                                    {
                                        callback(string.Format("adding {0}", type.Name));
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.ErrorLine(this, "failed to load dependent assembly '{0}'", assemblyName);
                        Log.ErrorLine(this, e);
                    }
                }
            }
        }
Example #3
0
 /// <remarks>Callback will be called periodically as types and methods are checked. Smokey
 /// uses this with a watchdog class to ensure no rule falls into an infinite loop.</remarks>
 public AnalyzeAssembly(Rule.KeepAliveCallback callback)
 {
     m_callback = callback;
     m_checker  = new CheckItem(callback);
 }
Example #4
0
 public CheckItem(Rule.KeepAliveCallback callback)
 {
     m_callback   = callback;
     m_dispatcher = new RuleDispatcher(this);
 }