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);
        }
 public bool TryGetDuplicateExport(
     string fullTypeName,
     string memberName,
     out ExportedMethod exportedMethod)
 {
     return(this._DuplicateExportMethodsbyFullName.TryGetValue(AssemblyExports.GetKey(fullTypeName, memberName), out exportedMethod));
 }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        internal void Refresh()
        {
            int num = InputValues.OrdinalsBase;

            MethodsByExportName.Clear();
            _DuplicateExportMethods.Clear();

            var dictionary = new Dictionary <string, DuplicateExports>();

            foreach (ExportedClass exportedClass in ClassesByName.Values)
            {
                var 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++;
                        MethodsByExportName.Add(method.ExportName, method); // #10 :: MemberName -> ExportName + see DeleteExportAttributeParserAction
                        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)));
        }