public DecompilationContext(MethodSpecificContext methodContext, TypeSpecificContext typeContext, ModuleSpecificContext moduleContext, AssemblySpecificContext assemblyContext)
		{
			this.MethodContext = methodContext;
			this.TypeContext = typeContext;
			this.ModuleContext = moduleContext;
			this.AssemblyContext = assemblyContext;
		}
 public override ModuleSpecificContext GetModuleContext(ModuleDefinition module, ILanguage language)
 {
     V_0 = TypeCollisionWriterContextService.moduleContextsLocker;
     V_1 = false;
     try
     {
         Monitor.Enter(V_0, ref V_1);
         if (!this.cacheService.IsModuleContextInCache(module, language, this.renameInvalidMembers))
         {
             V_2 = this.GetModuleNamespaceUsings(module);
             V_3 = this.GetModuleCollisionTypesData(module, language);
             V_4 = this.GetModuleNamespaceHierarchy(module, language);
             V_5 = this.GetRenamedNamespacesMap(module, language);
             V_6 = this.GetMemberRenamingData(module, language);
             V_7 = new ModuleSpecificContext(module, V_2, V_3, V_4, V_5, V_6.get_RenamedMembers(), V_6.get_RenamedMembersMap());
             this.cacheService.AddModuleContextToCache(module, language, this.renameInvalidMembers, V_7);
             V_8 = V_7;
         }
         else
         {
             V_8 = this.cacheService.GetModuleContextFromCache(module, language, this.renameInvalidMembers);
         }
     }
     finally
     {
         if (V_1)
         {
             Monitor.Exit(V_0);
         }
     }
     return(V_8);
 }
Example #3
0
        public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
        {
            TypeDefinition type = Utilities.GetDeclaringTypeOrSelf(member);

            Dictionary <FieldDefinition, PropertyDefinition> fieldToPropertyMap = type.GetFieldToPropertyMap(language);
            IEnumerable <FieldDefinition> propertyFields            = fieldToPropertyMap.Keys;
            HashSet <PropertyDefinition>  autoImplementedProperties = new HashSet <PropertyDefinition>(fieldToPropertyMap.Values);
            HashSet <EventDefinition>     autoImplementedEvents     = GetAutoImplementedEvents(type, language);

            TypeSpecificContext typeContext = new TypeSpecificContext(type)
            {
                AutoImplementedProperties = autoImplementedProperties, AutoImplementedEvents = autoImplementedEvents
            };

            TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member);

            Dictionary <string, string> renamedNamespacesMap = new Dictionary <string, string>();
            MemberRenamingData          memberReanmingData   = GetMemberRenamingData(declaringType.Module, language);

            ModuleSpecificContext moduleContext =
                new ModuleSpecificContext(declaringType.Module, new List <string>(), new Dictionary <string, List <string> >(), new Dictionary <string, HashSet <string> >(),
                                          renamedNamespacesMap, memberReanmingData.RenamedMembers, memberReanmingData.RenamedMembersMap);

            return(new WriterContext(
                       new AssemblySpecificContext(),
                       moduleContext,
                       typeContext,
                       new Dictionary <string, MethodSpecificContext>(),
                       GetDecompiledStatements(member, language, propertyFields)));
        }
		public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
		{
			TypeDefinition type = Utilities.GetDeclaringTypeOrSelf(member);

            Dictionary<FieldDefinition, PropertyDefinition> fieldToPropertyMap = type.GetFieldToPropertyMap(language);
            IEnumerable<FieldDefinition> propertyFields = fieldToPropertyMap.Keys;
            HashSet<PropertyDefinition> autoImplementedProperties = new HashSet<PropertyDefinition>(fieldToPropertyMap.Values);
			HashSet<EventDefinition> autoImplementedEvents = GetAutoImplementedEvents(type);

			TypeSpecificContext typeContext = new TypeSpecificContext(type) { AutoImplementedProperties = autoImplementedProperties, AutoImplementedEvents = autoImplementedEvents };

			TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member);

			Dictionary<string, string> renamedNamespacesMap = new Dictionary<string, string>();
			MemberRenamingData memberReanmingData = GetMemberRenamingData(declaringType.Module, language);

			ModuleSpecificContext moduleContext =
				new ModuleSpecificContext(declaringType.Module, new List<string>(), new Dictionary<string, List<string>>(), new Dictionary<string, HashSet<string>>(), 
					renamedNamespacesMap, memberReanmingData.RenamedMembers, memberReanmingData.RenamedMembersMap);			

			return new WriterContext(
				new AssemblySpecificContext(),
				moduleContext,
				typeContext,
				new Dictionary<string, MethodSpecificContext>(), 
				GetDecompiledStatements(member, language, propertyFields));
		}
        public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
        {
            TypeSpecificContext typeContext;
            DecompiledType      decompiledType;

            if (member is TypeDefinition && member == Utilities.GetOuterMostDeclaringType(member))
            {
                TypeDefinition type = member as TypeDefinition;
                Dictionary <string, DecompiledType> decompiledTypes = GetNestedDecompiledTypes(type, language);

                TypeSpecificContext cachedTypeContext = GetTypeContext(type, language, decompiledTypes);

                typeContext = new TypeSpecificContext(
                    cachedTypeContext.CurrentType,
                    cachedTypeContext.MethodDefinitionToNameMap,
                    cachedTypeContext.BackingFieldToNameMap,
                    cachedTypeContext.UsedNamespaces,
                    new HashSet <string>(),
                    cachedTypeContext.FieldAssignmentData,
                    cachedTypeContext.AutoImplementedProperties,
                    cachedTypeContext.AutoImplementedEvents,
                    cachedTypeContext.ExplicitlyImplementedMembers,
                    cachedTypeContext.ExceptionWhileDecompiling
                    );

                if (!decompiledTypes.TryGetValue(type.FullName, out decompiledType))
                {
                    throw new Exception("Decompiled type not found in decompiled types cache.");
                }
            }
            else
            {
                decompiledType = GetDecompiledType(member, language);
                typeContext    = decompiledType.TypeContext;
            }

            Dictionary <string, MethodSpecificContext> methodContexts       = new Dictionary <string, MethodSpecificContext>();
            Dictionary <string, Statement>             decompiledStatements = new Dictionary <string, Statement>();

            foreach (KeyValuePair <string, DecompiledMember> decompiledPair in decompiledType.DecompiledMembers)
            {
                methodContexts.Add(decompiledPair.Key, decompiledPair.Value.Context);
                decompiledStatements.Add(decompiledPair.Key, decompiledPair.Value.Statement);
            }

            TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member);

            AssemblySpecificContext assemblyContext = GetAssemblyContext(declaringType.Module.Assembly, language);
            ModuleSpecificContext   moduleContext   = GetModuleContext(declaringType.Module, language);

            WriterContext writerContext = new WriterContext(assemblyContext, moduleContext, typeContext, methodContexts, decompiledStatements);

            return(writerContext);
        }
Example #6
0
        public virtual void WriteAssemblyAttributes(AssemblyDefinition assembly, IWriterContextService writerContextService, bool writeUsings = false, ICollection <string> attributesToIgnore = null)
        {
            AssemblySpecificContext assemblyContext = writerContextService.GetAssemblyContext(assembly, Language);

            SetAssemblyContext(assemblyContext);

            ModuleSpecificContext mainModuleContext = writerContextService.GetModuleContext(assembly.MainModule, Language);

            SetModuleContext(mainModuleContext);

            WriteAssemblyAttributesInternal(assembly, assemblyContext.AssemblyNamespaceUsings, mainModuleContext.ModuleNamespaceUsings, writeUsings, attributesToIgnore);
        }
Example #7
0
        public virtual void WriteModuleAttributes(ModuleDefinition module, IWriterContextService writerContextService, bool writeUsings = false, ICollection <string> attributesToIgnore = null)
        {
            AssemblySpecificContext assemblyContext = new AssemblySpecificContext();

            SetAssemblyContext(assemblyContext);

            ModuleSpecificContext moduleContext = writerContextService.GetModuleContext(module, Language);

            SetModuleContext(moduleContext);


            WriteModuleAttributesInternal(module, moduleContext.ModuleNamespaceUsings, writeUsings, attributesToIgnore);
        }
        private WriterContext GetWriterContextForType(TypeDefinition type, ILanguage language)
        {
            TypeDefinition outerMostDeclaringType = Utilities.GetOuterMostDeclaringType(type);

            Dictionary <string, DecompiledType> decompiledTypes;

            if (this.cacheService.AreNestedDecompiledTypesInCache(outerMostDeclaringType, language, this.renameInvalidMembers))
            {
                decompiledTypes = this.cacheService.GetNestedDecompiledTypesFromCache(outerMostDeclaringType, language, this.renameInvalidMembers);
            }
            else
            {
                decompiledTypes = GetNestedDecompiledTypes(outerMostDeclaringType, language);
                this.cacheService.AddNestedDecompiledTypesToCache(outerMostDeclaringType, language, this.renameInvalidMembers, decompiledTypes);
            }

            TypeSpecificContext typeContext = GetTypeContext(outerMostDeclaringType, language, decompiledTypes);

            AddTypeContextsToCache(decompiledTypes, outerMostDeclaringType, language);

            Dictionary <string, MethodSpecificContext> methodContexts       = new Dictionary <string, MethodSpecificContext>();
            Dictionary <string, Statement>             decompiledStatements = new Dictionary <string, Statement>();

            DecompiledType decompiledType;

            if (!decompiledTypes.TryGetValue(type.FullName, out decompiledType))
            {
                throw new Exception("Decompiled type missing from DecompiledTypes cache.");
            }
            else
            {
                // If members were taken from the cache, generated filter methods must be added to decompiled type.
                if (typeContext.GeneratedFilterMethods.Count > 0)
                {
                    AddGeneratedFilterMethodsToDecompiledType(decompiledType, typeContext, language);
                }

                foreach (DecompiledMember decompiledMember in decompiledType.DecompiledMembers.Values)
                {
                    methodContexts.Add(decompiledMember.MemberFullName, decompiledMember.Context);
                    decompiledStatements.Add(decompiledMember.MemberFullName, decompiledMember.Statement);
                }
            }

            AssemblySpecificContext assemblyContext = GetAssemblyContext(outerMostDeclaringType.Module.Assembly, language);
            ModuleSpecificContext   moduleContext   = GetModuleContext(outerMostDeclaringType.Module, language);

            WriterContext writerContext = new WriterContext(assemblyContext, moduleContext, typeContext, methodContexts, decompiledStatements);

            return(writerContext);
        }
Example #9
0
 public override ModuleSpecificContext GetModuleContext(ModuleDefinition module, ILanguage language)
 {
     if (this.cacheService.IsModuleContextInCache(module, language, this.renameInvalidMembers))
     {
         return(this.cacheService.GetModuleContextFromCache(module, language, this.renameInvalidMembers));
     }
     V_0 = this.GetModuleNamespaceUsings(module);
     V_1 = new Dictionary <string, List <string> >();
     V_2 = new Dictionary <string, HashSet <string> >();
     V_3 = new Dictionary <string, string>();
     V_4 = this.GetMemberRenamingData(module, language);
     V_5 = new ModuleSpecificContext(module, V_0, V_1, V_2, V_3, V_4.get_RenamedMembers(), V_4.get_RenamedMembersMap());
     this.cacheService.AddModuleContextToCache(module, language, this.renameInvalidMembers, V_5);
     return(V_5);
 }
Example #10
0
 public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
 {
     V_0             = Utilities.GetDeclaringTypeOrSelf(member);
     stackVariable4  = V_0.GetFieldToPropertyMap(language);
     V_1             = stackVariable4.get_Keys();
     V_2             = new HashSet <PropertyDefinition>(stackVariable4.get_Values());
     V_3             = this.GetAutoImplementedEvents(V_0, language);
     stackVariable13 = new TypeSpecificContext(V_0);
     stackVariable13.set_AutoImplementedProperties(V_2);
     stackVariable13.set_AutoImplementedEvents(V_3);
     V_4 = stackVariable13;
     V_5 = Utilities.GetDeclaringTypeOrSelf(member);
     V_6 = new Dictionary <string, string>();
     V_7 = this.GetMemberRenamingData(V_5.get_Module(), language);
     V_8 = new ModuleSpecificContext(V_5.get_Module(), new List <string>(), new Dictionary <string, List <string> >(), new Dictionary <string, HashSet <string> >(), V_6, V_7.get_RenamedMembers(), V_7.get_RenamedMembersMap());
     return(new WriterContext(new AssemblySpecificContext(), V_8, V_4, new Dictionary <string, MethodSpecificContext>(), this.GetDecompiledStatements(member, language, V_1)));
 }
        public override ModuleSpecificContext GetModuleContext(ModuleDefinition module, ILanguage language)
        {
            if (this.cacheService.IsModuleContextInCache(module, language, this.renameInvalidMembers))
            {
                return(this.cacheService.GetModuleContextFromCache(module, language, this.renameInvalidMembers));
            }

            ICollection <string> moduleNamespaceUsings = GetModuleNamespaceUsings(module);
            Dictionary <string, List <string> >    collisionTypesData   = new Dictionary <string, List <string> >();
            Dictionary <string, HashSet <string> > namesapceHieararchy  = new Dictionary <string, HashSet <string> >();
            Dictionary <string, string>            renamedNamespacesMap = new Dictionary <string, string>();
            MemberRenamingData memberRenamingData = GetMemberRenamingData(module, language);

            ModuleSpecificContext moduleContext =
                new ModuleSpecificContext(module, moduleNamespaceUsings, collisionTypesData, namesapceHieararchy, renamedNamespacesMap, memberRenamingData.RenamedMembers, memberRenamingData.RenamedMembersMap);

            this.cacheService.AddModuleContextToCache(module, language, this.renameInvalidMembers, moduleContext);

            return(moduleContext);
        }
        public override ModuleSpecificContext GetModuleContext(ModuleDefinition module, ILanguage language)
        {
            if (this.cacheService.IsModuleContextInCache(module, language, this.renameInvalidMembers))
            {
                return this.cacheService.GetModuleContextFromCache(module, language, this.renameInvalidMembers);
            }

            ICollection<string> moduleNamespaceUsings = GetModuleNamespaceUsings(module);
            Dictionary<string, List<string>> collisionTypesData = new Dictionary<string, List<string>>();
            Dictionary<string, HashSet<string>> namesapceHieararchy = new Dictionary<string, HashSet<string>>();
            Dictionary<string, string> renamedNamespacesMap = new Dictionary<string, string>();
            MemberRenamingData memberRenamingData = GetMemberRenamingData(module, language);

            ModuleSpecificContext moduleContext =
                new ModuleSpecificContext(module, moduleNamespaceUsings, collisionTypesData, namesapceHieararchy, renamedNamespacesMap, memberRenamingData.RenamedMembers, memberRenamingData.RenamedMembersMap);

            this.cacheService.AddModuleContextToCache(module, language, this.renameInvalidMembers, moduleContext);

            return moduleContext;
        }
		public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
		{
			AssemblySpecificContext assemblyContext = new AssemblySpecificContext();
			ModuleSpecificContext moduleContext = new ModuleSpecificContext();
			TypeSpecificContext typeContext = new TypeSpecificContext(Utilities.GetDeclaringTypeOrSelf(member));

			DecompiledType decompiledType = GetDecompiledType(member, language);

			Dictionary<string, MethodSpecificContext> methodContexts = new Dictionary<string, MethodSpecificContext>();
			Dictionary<string, Statement> decompiledStatements = new Dictionary<string, Statement>();

			foreach (KeyValuePair<string, DecompiledMember> decompiledPair in decompiledType.DecompiledMembers)
			{
				methodContexts.Add(decompiledPair.Key, decompiledPair.Value.Context);
				decompiledStatements.Add(decompiledPair.Key, decompiledPair.Value.Statement);
			}

			WriterContext writerContext = new WriterContext(assemblyContext, moduleContext, typeContext, methodContexts, decompiledStatements);

			return writerContext;
		}
        public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
        {
            AssemblySpecificContext assemblyContext = new AssemblySpecificContext();
            ModuleSpecificContext   moduleContext   = new ModuleSpecificContext();
            TypeSpecificContext     typeContext     = new TypeSpecificContext(Utilities.GetDeclaringTypeOrSelf(member));

            DecompiledType decompiledType = GetDecompiledType(member, language);

            Dictionary <string, MethodSpecificContext> methodContexts       = new Dictionary <string, MethodSpecificContext>();
            Dictionary <string, Statement>             decompiledStatements = new Dictionary <string, Statement>();

            foreach (KeyValuePair <string, DecompiledMember> decompiledPair in decompiledType.DecompiledMembers)
            {
                methodContexts.Add(decompiledPair.Key, decompiledPair.Value.Context);
                decompiledStatements.Add(decompiledPair.Key, decompiledPair.Value.Statement);
            }

            WriterContext writerContext = new WriterContext(assemblyContext, moduleContext, typeContext, methodContexts, decompiledStatements);

            return(writerContext);
        }
Example #15
0
 public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
 {
     V_0            = new AssemblySpecificContext();
     V_1            = new ModuleSpecificContext();
     V_2            = new TypeSpecificContext(Utilities.GetDeclaringTypeOrSelf(member));
     stackVariable8 = this.GetDecompiledType(member, language);
     V_3            = new Dictionary <string, MethodSpecificContext>();
     V_4            = new Dictionary <string, Statement>();
     V_5            = stackVariable8.get_DecompiledMembers().GetEnumerator();
     try
     {
         while (V_5.MoveNext())
         {
             V_6 = V_5.get_Current();
             V_3.Add(V_6.get_Key(), V_6.get_Value().get_Context());
             V_4.Add(V_6.get_Key(), V_6.get_Value().get_Statement());
         }
     }
     finally
     {
         ((IDisposable)V_5).Dispose();
     }
     return(new WriterContext(V_0, V_1, V_2, V_3, V_4));
 }
Example #16
0
 protected override void SetModuleContext(ModuleSpecificContext moduleContext)
 {
     writer.InternalModuleContext = moduleContext;
 }
 public void AddModuleContextToCache(ModuleDefinition module, ILanguage language, bool renameInvalidMembers, ModuleSpecificContext moduleContext)
 {
     V_0 = this.GetModuleKey(module, language, renameInvalidMembers);
     if (ProjectGenerationDecompilationCacheService.moduleContextsCache.ContainsKey(V_0))
     {
         throw new Exception("Key already in ModuleContextsCache");
     }
     ProjectGenerationDecompilationCacheService.moduleContextsCache.Add(V_0, moduleContext);
     return;
 }
        public void AddModuleContextToCache(ModuleDefinition module, ILanguage language, bool renameInvalidMembers, ModuleSpecificContext moduleContext)
        {
            string moduleKey = GetModuleKey(module, language, renameInvalidMembers);

            if (moduleContextsCache.ContainsKey(moduleKey))
            {
                throw new Exception("Key already in ModuleContextsCache");
            }

            moduleContextsCache.Add(moduleKey, moduleContext);
        }
Example #19
0
 protected override void SetModuleContext(ModuleSpecificContext moduleContext)
 {
     this.writer.set_InternalModuleContext(moduleContext);
     return;
 }
		public virtual void AddModuleContextToCache(ModuleDefinition module, ILanguage language, bool renameInvalidMembers, ModuleSpecificContext moduleContext)
		{
			moduleContextsCache.Add(GetModuleKey(module, language, renameInvalidMembers), moduleContext);
		}
		public void AddModuleContextToCache(ModuleDefinition module, ILanguage language, bool renameInvalidMembers, ModuleSpecificContext moduleContext)
		{
			string moduleKey = GetModuleKey(module, language, renameInvalidMembers);

			if (moduleContextsCache.ContainsKey(moduleKey))
			{
				throw new Exception("Key already in ModuleContextsCache");
			}

			moduleContextsCache.Add(moduleKey, moduleContext);
		}
 protected abstract void SetModuleContext(ModuleSpecificContext moduleContext);
 public void AddModuleContextToCache(ModuleDefinition module, ILanguage language, bool renameInvalidMembers, ModuleSpecificContext assemblyContext)
 {
 }
 public virtual void AddModuleContextToCache(ModuleDefinition module, ILanguage language, bool renameInvalidMembers, ModuleSpecificContext moduleContext)
 {
     moduleContextsCache.Add(GetModuleKey(module, language, renameInvalidMembers), moduleContext);
 }
		public void AddModuleContextToCache(ModuleDefinition module, ILanguage language, bool renameInvalidMembers, ModuleSpecificContext assemblyContext)
		{
		}
Example #26
0
 public virtual void AddModuleContextToCache(ModuleDefinition module, ILanguage language, bool renameInvalidMembers, ModuleSpecificContext moduleContext)
 {
     DefaultDecompilationCacheService.moduleContextsCache.Add(this.GetModuleKey(module, language, renameInvalidMembers), moduleContext);
     return;
 }
Example #27
0
 public DecompilationContext(MethodSpecificContext methodContext, TypeSpecificContext typeContext, ModuleSpecificContext moduleContext, AssemblySpecificContext assemblyContext)
 {
     this.MethodContext   = methodContext;
     this.TypeContext     = typeContext;
     this.ModuleContext   = moduleContext;
     this.AssemblyContext = assemblyContext;
 }