Пример #1
0
        IEnumerable <T> FindReferencesInAssemblyAndFriends(CancellationToken ct)
        {
            IEnumerable <ModuleDef> modules;

            if (includeAllModules)
            {
                modules = documentService.GetDocuments().Select(a => a.ModuleDef).OfType <ModuleDef>();
            }
            else if (TIAHelper.IsTypeDefEquivalent(analyzedType))
            {
                var analyzedTypes = new List <TypeDef> {
                    analyzedType
                };
                SearchNode.AddTypeEquivalentTypes(documentService, analyzedType, analyzedTypes);
                modules = SearchNode.GetTypeEquivalentModules(analyzedTypes);
            }
            else
            {
                modules = GetModuleAndAnyFriends(analyzedType.Module, ct);
            }
            allModules.AddRange(modules);
            return(allModules.AsParallel().WithCancellation(ct).SelectMany(a => FindReferencesInModule(a, ct)));
        }
Пример #2
0
        internal static HashSet <string> GetFriendAssemblies(IDsDocumentService documentService, ModuleDef mod, out IDsDocument[] modules)
        {
            var asm = mod.Assembly;

            Debug.Assert(!(asm is null));
            var friendAssemblies = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var attribute in asm.CustomAttributes.FindAll("System.Runtime.CompilerServices.InternalsVisibleToAttribute"))
            {
                if (attribute.ConstructorArguments.Count == 0)
                {
                    continue;
                }
                string assemblyName = attribute.ConstructorArguments[0].Value as UTF8String;
                if (assemblyName is null)
                {
                    continue;
                }
                assemblyName = assemblyName.Split(',')[0];
                friendAssemblies.Add(assemblyName);
            }
            modules = documentService.GetDocuments().Where(a => CanIncludeModule(mod, a.ModuleDef)).ToArray();
            foreach (var module in modules)
            {
                Debug.Assert(!(module.ModuleDef is null));
                var asm2 = module.AssemblyDef;
                if (asm2 is null)
                {
                    continue;
                }
                foreach (var attribute in asm2.CustomAttributes.FindAll("System.Runtime.CompilerServices.IgnoresAccessChecksToAttribute"))
                {
                    string assemblyName = attribute.ConstructorArguments[0].Value as UTF8String;
                    if (assemblyName is null)
                    {
                        continue;
                    }
                    assemblyName = assemblyName.Split(',')[0];
                    if (StringComparer.OrdinalIgnoreCase.Equals(asm.Name.String, assemblyName))
                    {
                        friendAssemblies.Add(asm2.Name);
                    }
                }
            }
            return(friendAssemblies);
        }
Пример #3
0
 internal static void AddTypeEquivalentTypes(IDsDocumentService documentService, TypeDef analyzedType, List <TypeDef> analyzedTypes)
 {
     Debug.Assert(analyzedTypes.Count == 1 && analyzedTypes[0] == analyzedType);
     if (!TIAHelper.IsTypeDefEquivalent(analyzedType))
     {
         return;
     }
     foreach (var document in documentService.GetDocuments())
     {
         foreach (var type in GetTypeEquivalentTypes(document.AssemblyDef, document.ModuleDef, analyzedType))
         {
             if (type != analyzedType)
             {
                 analyzedTypes.Add(type);
             }
         }
     }
 }