public bool TryGetDuplicateExport(
     string fullTypeName,
     string memberName,
     out ExportedMethod exportedMethod)
 {
     return(this._DuplicateExportMethodsbyFullName.TryGetValue(AssemblyExports.GetKey(fullTypeName, memberName), out exportedMethod));
 }
示例#2
0
        public AssemblyExports ExtractExports(
            AssemblyDefinition assemblyDefinition,
            ExtractExportHandler exportFilter)
        {
            IList <TypeDefinition> typeDefinitionList = this.TraverseNestedTypes((ICollection <TypeDefinition>)assemblyDefinition.Modules.SelectMany <ModuleDefinition, TypeDefinition>((Func <ModuleDefinition, IEnumerable <TypeDefinition> >)(m => (IEnumerable <TypeDefinition>)m.Types)).ToList <TypeDefinition>());
            AssemblyExports        result             = new AssemblyExports()
            {
                InputValues = this.InputValues
            };

            foreach (TypeDefinition td in (IEnumerable <TypeDefinition>)typeDefinitionList)
            {
                List <ExportedMethod> exportMethods = new List <ExportedMethod>();
                foreach (MethodDefinition method in td.Methods)
                {
                    TypeDefinition typeRefCopy = td;
                    this.CheckForExportedMethods((Func <ExportedMethod>)(() => new ExportedMethod(this.GetExportedClass(typeRefCopy, result))), exportFilter, exportMethods, method);
                }
                foreach (ExportedMethod exportedMethod in exportMethods)
                {
                    this.GetExportedClass(td, result).Methods.Add(exportedMethod);
                }
            }
            result.Refresh();
            return(result);
        }
示例#3
0
        public bool SafeExtractExports(string fileName, Stream stream)
        {
            AssemblyExports exports = this.ExtractExports(fileName);
            bool            flag;

            if (exports.Count == 0)
            {
                flag = false;
            }
            else
            {
                new BinaryFormatter().Serialize(stream, (object)exports);
                flag = true;
            }
            return(flag);
        }
示例#4
0
        private ExportedClass GetExportedClass(TypeDefinition td, AssemblyExports result)
        {
            ExportedClass exportedClass;

            if (!result.ClassesByName.TryGetValue(td.FullName, out exportedClass))
            {
                TypeDefinition typeDefinition = td;
                while (!typeDefinition.HasGenericParameters && typeDefinition.IsNested)
                {
                    typeDefinition = typeDefinition.DeclaringType;
                }
                exportedClass = new ExportedClass(td.FullName, typeDefinition.HasGenericParameters);
                result.ClassesByName.Add(exportedClass.FullTypeName, exportedClass);
            }
            return(exportedClass);
        }
        internal void Refresh()
        {
            int num = 0;

            this.MethodsByExportName.Clear();
            this._DuplicateExportMethods.Clear();
            Dictionary <string, DuplicateExports> dictionary = new Dictionary <string, DuplicateExports>();

            foreach (ExportedClass exportedClass in this.ClassesByName.Values)
            {
                List <ExportedMethod> exportedMethodList = new List <ExportedMethod>(exportedClass.Methods.Count);
                foreach (ExportedMethod method in exportedClass.Methods)
                {
                    DuplicateExports duplicateExports;
                    if (!dictionary.TryGetValue(method.ExportName, out duplicateExports))
                    {
                        method.VTableOffset = num++;
                        this.MethodsByExportName.Add(method.MemberName, method);
                        dictionary.Add(method.ExportName, new DuplicateExports(method));
                    }
                    else
                    {
                        exportedMethodList.Add(method);
                        duplicateExports.Duplicates.Add(method);
                    }
                }
                ExportedClass exportClassCopy = exportedClass;
                exportedMethodList.ForEach((Action <ExportedMethod>)(m => exportClassCopy.Methods.Remove(m)));
                exportedClass.Refresh();
            }
            foreach (DuplicateExports duplicateExports in dictionary.Values)
            {
                if (duplicateExports.Duplicates.Count > 0)
                {
                    this._DuplicateExportMethods.Add(duplicateExports);
                    foreach (ExportedMethod duplicate in (IEnumerable <ExportedMethod>)duplicateExports.Duplicates)
                    {
                        this._DuplicateExportMethodsbyFullName.Add(AssemblyExports.GetKey(duplicate.ExportedClass.FullTypeName, duplicate.MemberName), duplicate);
                    }
                }
            }
            this._DuplicateExportMethods.Sort((Comparison <DuplicateExports>)((l, r) => string.CompareOrdinal(l.UsedExport.ExportName, r.UsedExport.ExportName)));
        }