protected void AddDecompiledMemberToDecompiledType(CachedDecompiledMember decompiledMember, DecompiledType decompiledType) { if (!decompiledType.DecompiledMembers.ContainsKey(decompiledMember.Member.MemberFullName)) { decompiledType.DecompiledMembers.Add(decompiledMember.Member.MemberFullName, decompiledMember.Member); } }
internal IList <VueData> GetComponentData() { var dataList = new List <VueData>(); foreach (var field in DecompiledType.GetFields(f => f.Accessibility.HasFlag(ICSharpCode.Decompiler.TypeSystem.Accessibility.Public) && !f.IsStatic)) { dataList.Add(ToVueField(field)); } var fieldProps = DeclarationSyntax .DescendantNodes() .OfType <PropertyDeclarationSyntax>() .Where(p => !p.AccessorList.Accessors.Any(accessor => accessor.Body != null)); foreach (var prop in fieldProps) { dataList.Add(new VueData { Name = prop.Identifier.ValueText, Value = SystemType.GetProperty(prop.Identifier.ValueText).GetValue(_instance) }); } return(dataList); }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { TypeDefinition declaringType = member is TypeDefinition ? member as TypeDefinition : member.DeclaringType; DecompiledType decompiledType = new DecompiledType(declaringType); if (member is MethodDefinition) { MethodDefinition method = member as MethodDefinition; DecompiledMember decompiledMember = Utilities.TryGetDecompiledMember(method, decompiledType.TypeContext, language); decompiledType.DecompiledMembers.Add(method.FullName, decompiledMember); } else if (member is PropertyDefinition) { PropertyDefinition propertyDefinition = (member as PropertyDefinition); if (propertyDefinition.GetMethod != null) { DecompiledMember decompiledMember = Utilities.TryGetDecompiledMember(propertyDefinition.GetMethod, decompiledType.TypeContext, language); decompiledType.DecompiledMembers.Add(propertyDefinition.GetMethod.FullName, decompiledMember); } if (propertyDefinition.SetMethod != null) { DecompiledMember decompiledMember = Utilities.TryGetDecompiledMember(propertyDefinition.SetMethod, decompiledType.TypeContext, language); decompiledType.DecompiledMembers.Add(propertyDefinition.SetMethod.FullName, decompiledMember); } } else { throw new NotSupportedException("FrameworkFolderWriterContext service supports only methods and properties."); } return(decompiledType); }
protected void AddGeneratedFilterMethodsToDecompiledType(DecompiledType decompiledType, TypeSpecificContext context, ILanguage language) { foreach (GeneratedMethod generatedMethod in context.GeneratedFilterMethods) { CachedDecompiledMember member = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(generatedMethod.Method), generatedMethod.Body, generatedMethod.Context)); AddDecompiledMemberToDecompiledType(member, decompiledType); } }
internal IList <VueMethod> GetComponentMethods() { var methods = new List <VueMethod>(); foreach (var method in DecompiledType.GetMethods(m => m.DeclaringType.DirectBaseTypes.Any(c => c.FullName == typeof(VueModel).FullName))) { methods.Add(ToVueMethod(method)); } return(methods); }
protected void DecompileMember(MethodDefinition method, ILanguage language, DecompiledType decompiledType) { if (method.get_IsConstructor() && !method.get_IsStatic() && method.get_HasBody()) { this.DecompileConstructorChain(method, language, decompiledType); return; } this.AddDecompiledMemberToDecompiledType(this.GetDecompiledMember(method, language, decompiledType), decompiledType); return; }
protected void DecompileMember(MethodDefinition method, ILanguage language, DecompiledType decompiledType) { if (method.IsConstructor && !method.IsStatic && method.HasBody) { DecompileConstructorChain(method, language, decompiledType); return; } CachedDecompiledMember decompiledMember = GetDecompiledMember(method, language, decompiledType); AddDecompiledMemberToDecompiledType(decompiledMember, decompiledType); //UpdateTypeContext(decompiledType.TypeContext, decompiledMember); }
protected CachedDecompiledMember GetDecompiledMember(MethodDefinition method, ILanguage language, DecompiledType decompiledType) { if (method.Body == null) { return new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(method), null, null)); } if (this.cacheService.IsDecompiledMemberInCache(method, language, this.renameInvalidMembers)) { return this.cacheService.GetDecompiledMemberFromCache(method, language, this.renameInvalidMembers); } CachedDecompiledMember decompiledMember = DecompileMethod(language, method, decompiledType.TypeContext); this.cacheService.AddDecompiledMemberToCache(method, language, this.renameInvalidMembers, decompiledMember); return decompiledMember; }
private TypeSpecificContext GetTypeContext(DecompiledType decompiledType, ILanguage language) { V_1 = decompiledType.get_Type(); if (!this.cacheService.IsTypeContextInCache(V_1, language, this.renameInvalidMembers)) { V_0 = decompiledType.get_TypeContext(); this.cacheService.AddTypeContextToCache(V_1, language, this.renameInvalidMembers, V_0); } else { if (decompiledType.get_TypeContext().get_GeneratedFilterMethods().get_Count() > 0) { this.cacheService.ReplaceCachedTypeContext(V_1, language, this.renameInvalidMembers, decompiledType.get_TypeContext()); } V_0 = this.cacheService.GetTypeContextFromCache(V_1, language, this.renameInvalidMembers); } return(V_0); }
internal IList <VueMethod> GetComponentLifecycleHooks() { var methods = new List <VueMethod>(); foreach (var method in DecompiledType.GetMethods()) { if (!VueModel.LifeCycleMethodsNameMapping.TryGetValue(method.Name, out var hookName)) { continue; } if (method.DeclaringType.Name == nameof(VueModel)) { continue; } var vueMethod = ToVueMethod(method); vueMethod.Name = hookName; methods.Add(vueMethod); } return(methods); }
protected void AddGeneratedFilterMethodsToDecompiledType(DecompiledType decompiledType, TypeSpecificContext context, ILanguage language) { V_0 = context.get_GeneratedFilterMethods().GetEnumerator(); try { while (V_0.MoveNext()) { V_1 = V_0.get_Current(); V_2 = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(V_1.get_Method()), V_1.get_Body(), V_1.get_Context())); this.AddDecompiledMemberToDecompiledType(V_2, decompiledType); } } finally { if (V_0 != null) { V_0.Dispose(); } } return; }
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); }
internal IList <VueComputed> GetComponentComputed() { var computed = new List <VueComputed>(); foreach (var property in DecompiledType.GetProperties()) { var compilation = GetSyntaxTree(property); if (compilation.Members.First() is PropertyDeclarationSyntax prop) { if (!prop.AccessorList.Accessors.Any(accessor => accessor.Body != null)) { continue; } } computed.Add(new VueComputed { Name = property.Name, Body = compilation }); } return(computed); }
private void RemoveBaseCtorInvocationStatements(CachedDecompiledMember decompiledMember, DecompiledType decompiledType) { MethodSpecificContext methodContext = decompiledMember.Member.Context; //value types chained constructors? if (methodContext== null || !methodContext.Method.IsConstructor || methodContext.Method.IsStatic || methodContext.CtorInvokeExpression == null) { return; } BlockStatement methodBody = decompiledMember.Member.Statement as BlockStatement; if (methodBody == null) // it might have been an exception { return; } else if (methodBody.Statements.Count == 1 && methodBody.Statements[0] is UnsafeBlockStatement) { methodBody = methodBody.Statements[0] as UnsafeBlockStatement; } TypeSpecificContext typeContext = decompiledType.TypeContext; if (typeContext.FieldInitializationFailed && typeContext.BaseCtorInvocators.Contains(methodContext.Method)) { methodContext.CtorInvokeExpression = null; } else { /// all statements before the constructor invocation should be removed for (int i = 0; i < methodBody.Statements.Count; i++) { if (methodBody.Statements[i].CodeNodeType == Ast.CodeNodeType.ExpressionStatement && ((methodBody.Statements[i] as ExpressionStatement).Expression.CodeNodeType == Ast.CodeNodeType.ThisCtorExpression || (methodBody.Statements[i] as ExpressionStatement).Expression.CodeNodeType == Ast.CodeNodeType.BaseCtorExpression)) { RemoveFirstStatements(methodBody.Statements, i + 1); return; } } throw new Exception("Constructor invocation not found."); } }
private TypeSpecificContext GetTypeContext(DecompiledType decompiledType, ILanguage language) { TypeSpecificContext typeContext; TypeDefinition type = decompiledType.Type; if (this.cacheService.IsTypeContextInCache(type, language, this.renameInvalidMembers)) { if (decompiledType.TypeContext.GeneratedFilterMethods.Count > 0) { this.cacheService.ReplaceCachedTypeContext(type, language, this.renameInvalidMembers, decompiledType.TypeContext); } typeContext = this.cacheService.GetTypeContextFromCache(type, language, this.renameInvalidMembers); } else { typeContext = decompiledType.TypeContext; this.cacheService.AddTypeContextToCache(type, language, this.renameInvalidMembers, typeContext); } return typeContext; }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { if (member as TypeDefinition != null) { stackVariable3 = member as TypeDefinition; } else { stackVariable3 = member.get_DeclaringType(); } V_0 = new DecompiledType(stackVariable3); if (member as MethodDefinition == null) { if (member as PropertyDefinition == null) { throw new NotSupportedException("FrameworkFolderWriterContext service supports only methods and properties."); } V_3 = member as PropertyDefinition; if (V_3.get_GetMethod() != null) { V_4 = Utilities.TryGetDecompiledMember(V_3.get_GetMethod(), V_0.get_TypeContext(), language); V_0.get_DecompiledMembers().Add(V_3.get_GetMethod().get_FullName(), V_4); } if (V_3.get_SetMethod() != null) { V_5 = Utilities.TryGetDecompiledMember(V_3.get_SetMethod(), V_0.get_TypeContext(), language); V_0.get_DecompiledMembers().Add(V_3.get_SetMethod().get_FullName(), V_5); } } else { V_1 = member as MethodDefinition; V_2 = Utilities.TryGetDecompiledMember(V_1, V_0.get_TypeContext(), language); V_0.get_DecompiledMembers().Add(V_1.get_FullName(), V_2); } this.AddGeneratedFilterMethodsToDecompiledType(V_0, V_0.get_TypeContext(), language); return(V_0); }
private TypeSpecificContext GetTypeContext(DecompiledType decompiledType, ILanguage language) { TypeSpecificContext typeContext; TypeDefinition type = decompiledType.Type; if (this.cacheService.IsTypeContextInCache(type, language, this.renameInvalidMembers)) { if (decompiledType.TypeContext.GeneratedFilterMethods.Count > 0) { this.cacheService.ReplaceCachedTypeContext(type, language, this.renameInvalidMembers, decompiledType.TypeContext); } typeContext = this.cacheService.GetTypeContextFromCache(type, language, this.renameInvalidMembers); } else { typeContext = decompiledType.TypeContext; this.cacheService.AddTypeContextToCache(type, language, this.renameInvalidMembers, typeContext); } return(typeContext); }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { TypeDefinition declaringType = member is TypeDefinition ? member as TypeDefinition : member.DeclaringType; DecompiledType decompiledType = new DecompiledType(declaringType); if (member is MethodDefinition) { MethodDefinition method = member as MethodDefinition; DecompiledMember decompiledMember = Utilities.TryGetDecompiledMember(method, decompiledType.TypeContext, language); decompiledType.DecompiledMembers.Add(method.FullName, decompiledMember); } else if (member is PropertyDefinition) { PropertyDefinition propertyDefinition = (member as PropertyDefinition); if (propertyDefinition.GetMethod != null) { DecompiledMember decompiledMember = Utilities.TryGetDecompiledMember(propertyDefinition.GetMethod, decompiledType.TypeContext, language); decompiledType.DecompiledMembers.Add(propertyDefinition.GetMethod.FullName, decompiledMember); } if (propertyDefinition.SetMethod != null) { DecompiledMember decompiledMember = Utilities.TryGetDecompiledMember(propertyDefinition.SetMethod, decompiledType.TypeContext, language); decompiledType.DecompiledMembers.Add(propertyDefinition.SetMethod.FullName, decompiledMember); } } else { throw new NotSupportedException("FrameworkFolderWriterContext service supports only methods and properties."); } AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language); return decompiledType; }
private void MergeConstructorsTypeContexts(List<CachedDecompiledMember> allConstructors, DecompiledType decompiledType) { if (allConstructors == null || allConstructors.Count == 0) { return; } for (int j = 0; j < allConstructors.Count; j++) { // context can be null, if the constructor has no body if (allConstructors[j].Member.Context != null && allConstructors[j].Member.Context.IsBaseConstructorInvokingConstructor) { decompiledType.TypeContext.BaseCtorInvocators.Add(allConstructors[j].Member.Context.Method); } } int i = 0; Dictionary<string, InitializationAssignment> combinedDictionary = new Dictionary<string, InitializationAssignment>(); for (; i < allConstructors.Count; i++) { if (allConstructors[i].Member.Context != null && allConstructors[i].Member.Context.IsBaseConstructorInvokingConstructor) { /// at least one constructor will call the base's ctor combinedDictionary = new Dictionary<string, InitializationAssignment>(allConstructors[i].FieldAssignmentData); break; } } for (; i < allConstructors.Count; i++) { CachedDecompiledMember constructor = allConstructors[i]; if (constructor.Member.Context == null || !constructor.Member.Context.IsBaseConstructorInvokingConstructor) { continue; } if (constructor.FieldAssignmentData.Count != combinedDictionary.Count) { // merge should fail decompiledType.TypeContext.FieldInitializationFailed = true; decompiledType.TypeContext.AssignmentData = new Dictionary<string, InitializationAssignment>(); return; } foreach (KeyValuePair<string, InitializationAssignment> pair in constructor.FieldAssignmentData) { if (combinedDictionary.ContainsKey(pair.Key) && combinedDictionary[pair.Key].AssignmentExpression.Equals(pair.Value.AssignmentExpression)) { continue; } // merge should fail otherwise decompiledType.TypeContext.FieldInitializationFailed = true; decompiledType.TypeContext.AssignmentData = new Dictionary<string, InitializationAssignment>(); return; } } decompiledType.TypeContext.AssignmentData = combinedDictionary; }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member); DecompiledType decompiledType = new DecompiledType(declaringType); Queue <IMemberDefinition> decompilationQueue = new Queue <IMemberDefinition>(); decompilationQueue.Enqueue(member); while (decompilationQueue.Count > 0) { IMemberDefinition currentMember = decompilationQueue.Dequeue(); if (currentMember is TypeDefinition && currentMember == member) { TypeDefinition currentType = (currentMember as TypeDefinition); List <IMemberDefinition> members = Utilities.GetTypeMembers(currentType, language, propertyFields: decompiledType.TypeContext.GetFieldToPropertyMap(language).Keys); foreach (IMemberDefinition typeMember in members) { decompilationQueue.Enqueue(typeMember); } } if (currentMember is MethodDefinition) { DecompileMember(currentMember as MethodDefinition, language, decompiledType); } if (currentMember is EventDefinition) { EventDefinition eventDefinition = (currentMember as EventDefinition); AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(eventDefinition, language); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedEvents.Add(eventDefinition); } if (eventDefinition.AddMethod != null) { DecompileMember(eventDefinition.AddMethod, language, decompiledType); } if (eventDefinition.RemoveMethod != null) { DecompileMember(eventDefinition.RemoveMethod, language, decompiledType); } if (eventDefinition.InvokeMethod != null) { DecompileMember(eventDefinition.InvokeMethod, language, decompiledType); } } if (currentMember is PropertyDefinition) { PropertyDefinition propertyDefinition = (currentMember as PropertyDefinition); CachedDecompiledMember getMethod; CachedDecompiledMember setMethod; bool isAutoImplemented; PropertyDecompiler propertyDecompiler = new PropertyDecompiler(propertyDefinition, language, this.renameInvalidMembers, this.cacheService, decompiledType.TypeContext); propertyDecompiler.ExceptionThrown += OnExceptionThrown; propertyDecompiler.Decompile(out getMethod, out setMethod, out isAutoImplemented); propertyDecompiler.ExceptionThrown -= OnExceptionThrown; if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (getMethod != null) { AddDecompiledMemberToDecompiledType(getMethod, decompiledType); } if (setMethod != null) { AddDecompiledMemberToDecompiledType(setMethod, decompiledType); } foreach (MethodDefinition exceptionWhileDecompiling in propertyDecompiler.ExceptionsWhileDecompiling) { this.ExceptionsWhileDecompiling.Add(exceptionWhileDecompiling); } } if (currentMember is FieldDefinition) { FieldDefinition currentField = currentMember as FieldDefinition; /// Decompile all the constructors, that can set default values to the field. /// For instance fields decompile only instance constructors. /// For static fields decompile only static constructors. foreach (MethodDefinition method in currentMember.DeclaringType.Methods) { if (method.IsConstructor && currentField.IsStatic == method.IsStatic) { DecompileConstructorChain(method, language, decompiledType); break; } } } } decompiledType.TypeContext.ExplicitlyImplementedMembers = GetExplicitlyImplementedInterfaceMethods(declaringType, language); AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language); return(decompiledType); }
private TypeSpecificContext CreateTypeContext(TypeDefinition type, ILanguage language, Dictionary <string, DecompiledType> decompiledTypes, DecompiledType decompiledCurrentType) { ICollection <TypeReference> typesDependingOn = GetTypesDependingOn(decompiledTypes, language); ICollection <string> usedNamespaces = GetUsedNamespaces(typesDependingOn, type.Namespace); ICollection <string> visibleMembersNames = GetTypeVisibleMembersNames(type, language, decompiledTypes); ExplicitlyImplementedMembersCollection explicitlyImplementedInterfaceMethods = GetExplicitlyImplementedInterfaceMethods(type, language); return(new TypeSpecificContext( type, decompiledCurrentType.TypeContext.MethodDefinitionToNameMap, decompiledCurrentType.TypeContext.BackingFieldToNameMap, usedNamespaces, visibleMembersNames, decompiledCurrentType.TypeContext.AssignmentData, GetAutoImplementedProperties(decompiledTypes), GetAutoImplementedEvents(decompiledTypes), explicitlyImplementedInterfaceMethods, this.ExceptionsWhileDecompiling, decompiledCurrentType.TypeContext.GeneratedFilterMethods, decompiledCurrentType.TypeContext.GeneratedMethodDefinitionToNameMap )); }
private static void AddAssignmentDataToDecompiledType(CachedDecompiledMember decompiledMember, DecompiledType decompiledType) { if (!decompiledType.TypeContext.FieldInitializationFailed) { foreach (KeyValuePair <string, InitializationAssignment> pair in decompiledMember.FieldAssignmentData) { if (!decompiledType.TypeContext.AssignmentData.ContainsKey(pair.Key)) { decompiledType.TypeContext.AssignmentData.Add(pair.Key, pair.Value); } else if (!decompiledType.TypeContext.AssignmentData[pair.Key].AssignmentExpression.Equals(pair.Value.AssignmentExpression)) { decompiledType.TypeContext.FieldInitializationFailed = true; decompiledType.TypeContext.AssignmentData = new Dictionary <string, InitializationAssignment>(); return; } } } }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member); DecompiledType decompiledType = new DecompiledType(declaringType); Queue <IMemberDefinition> decompilationQueue = new Queue <IMemberDefinition>(); decompilationQueue.Enqueue(member); while (decompilationQueue.Count > 0) { IMemberDefinition currentMember = decompilationQueue.Dequeue(); if (currentMember is TypeDefinition && currentMember == member) { TypeDefinition currentType = (currentMember as TypeDefinition); List <IMemberDefinition> members = Utilities.GetTypeMembers(currentType); foreach (IMemberDefinition typeMember in members) { decompilationQueue.Enqueue(typeMember); } } if (currentMember is MethodDefinition) { DecompileMember(currentMember as MethodDefinition, language, decompiledType); } if (currentMember is EventDefinition) { EventDefinition eventDefinition = (currentMember as EventDefinition); AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(eventDefinition); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedEvents.Add(eventDefinition); } if (eventDefinition.AddMethod != null) { DecompileMember(eventDefinition.AddMethod, language, decompiledType); } if (eventDefinition.RemoveMethod != null) { DecompileMember(eventDefinition.RemoveMethod, language, decompiledType); } if (eventDefinition.InvokeMethod != null) { DecompileMember(eventDefinition.InvokeMethod, language, decompiledType); } } if (currentMember is PropertyDefinition) { PropertyDefinition propertyDefinition = (currentMember as PropertyDefinition); AutoImplementedPropertyMatcher matcher = new AutoImplementedPropertyMatcher(propertyDefinition); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (propertyDefinition.GetMethod != null) { DecompileMember(propertyDefinition.GetMethod, language, decompiledType); } if (propertyDefinition.SetMethod != null) { DecompileMember(propertyDefinition.SetMethod, language, decompiledType); } } if (currentMember is FieldDefinition) { FieldDefinition currentField = currentMember as FieldDefinition; /// Decompile all the constructors, that can set default values to the field. /// For instance fields decompile only instance constructors. /// For static fields decompile only static constructors. foreach (MethodDefinition method in currentMember.DeclaringType.Methods) { if (method.IsConstructor && currentField.IsStatic == method.IsStatic) { DecompileConstructorChain(method, language, decompiledType); break; } } } } decompiledType.TypeContext.ExplicitlyImplementedMembers = GetExplicitlyImplementedInterfaceMethods(declaringType, language); return(decompiledType); }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { V_0 = Utilities.GetDeclaringTypeOrSelf(member); V_1 = new DecompiledType(V_0); V_2 = new Queue <IMemberDefinition>(); V_2.Enqueue(member); Label0: while (V_2.get_Count() > 0) { V_3 = V_2.Dequeue(); if (V_3 as TypeDefinition != null && (object)V_3 == (object)member) { V_4 = Utilities.GetTypeMembers(V_3 as TypeDefinition, language, true, null, null, null, V_1.get_TypeContext().GetFieldToPropertyMap(language).get_Keys()).GetEnumerator(); try { while (V_4.MoveNext()) { V_5 = V_4.get_Current(); V_2.Enqueue(V_5); } } finally { ((IDisposable)V_4).Dispose(); } } if (V_3 as MethodDefinition != null) { this.DecompileMember(V_3 as MethodDefinition, language, V_1); } if (V_3 as EventDefinition != null) { V_6 = V_3 as EventDefinition; if ((new AutoImplementedEventMatcher(V_6, language)).IsAutoImplemented()) { dummyVar0 = V_1.get_TypeContext().get_AutoImplementedEvents().Add(V_6); } if (V_6.get_AddMethod() != null) { this.DecompileMember(V_6.get_AddMethod(), language, V_1); } if (V_6.get_RemoveMethod() != null) { this.DecompileMember(V_6.get_RemoveMethod(), language, V_1); } if (V_6.get_InvokeMethod() != null) { this.DecompileMember(V_6.get_InvokeMethod(), language, V_1); } } if (V_3 as PropertyDefinition != null) { V_7 = V_3 as PropertyDefinition; stackVariable52 = new PropertyDecompiler(V_7, language, this.renameInvalidMembers, this.cacheService, V_1.get_TypeContext()); stackVariable52.add_ExceptionThrown(new EventHandler <Exception>(this.OnExceptionThrown)); stackVariable52.Decompile(out V_8, out V_9, out V_10); stackVariable52.remove_ExceptionThrown(new EventHandler <Exception>(this.OnExceptionThrown)); if (V_10) { dummyVar1 = V_1.get_TypeContext().get_AutoImplementedProperties().Add(V_7); } if (V_8 != null) { this.AddDecompiledMemberToDecompiledType(V_8, V_1); } if (V_9 != null) { this.AddDecompiledMemberToDecompiledType(V_9, V_1); } V_11 = stackVariable52.get_ExceptionsWhileDecompiling().GetEnumerator(); try { while (V_11.MoveNext()) { V_12 = V_11.get_Current(); this.get_ExceptionsWhileDecompiling().Add(V_12); } } finally { if (V_11 != null) { V_11.Dispose(); } } } if (V_3 as FieldDefinition == null) { continue; } V_13 = V_3 as FieldDefinition; V_14 = V_3.get_DeclaringType().get_Methods().GetEnumerator(); try { while (V_14.MoveNext()) { V_15 = V_14.get_Current(); if (!V_15.get_IsConstructor() || V_13.get_IsStatic() != V_15.get_IsStatic()) { continue; } this.DecompileConstructorChain(V_15, language, V_1); goto Label0; } } finally { V_14.Dispose(); } } V_1.get_TypeContext().set_ExplicitlyImplementedMembers(this.GetExplicitlyImplementedInterfaceMethods(V_0, language)); this.AddGeneratedFilterMethodsToDecompiledType(V_1, V_1.get_TypeContext(), language); return(V_1); }
private TypeSpecificContext CreateTypeContext(TypeDefinition type, ILanguage language, Dictionary <string, DecompiledType> decompiledTypes, DecompiledType decompiledCurrentType) { V_0 = this.GetTypesDependingOn(decompiledTypes, language); V_1 = this.GetUsedNamespaces(V_0, type.get_Namespace()); V_2 = this.GetTypeVisibleMembersNames(type, language, decompiledTypes); V_3 = this.GetExplicitlyImplementedInterfaceMethods(type, language); return(new TypeSpecificContext(type, decompiledCurrentType.get_TypeContext().get_MethodDefinitionToNameMap(), decompiledCurrentType.get_TypeContext().get_BackingFieldToNameMap(), V_1, V_2, decompiledCurrentType.get_TypeContext().get_AssignmentData(), this.GetAutoImplementedProperties(decompiledTypes), this.GetAutoImplementedEvents(decompiledTypes), V_3, this.get_ExceptionsWhileDecompiling(), decompiledCurrentType.get_TypeContext().get_GeneratedFilterMethods(), decompiledCurrentType.get_TypeContext().get_GeneratedMethodDefinitionToNameMap())); }
protected void DecompileConstructorChain(MethodDefinition method, ILanguage language, DecompiledType decompiledType) { if (this.cacheService.IsDecompiledMemberInCache(method, language, this.renameInvalidMembers)) { ///all constructors have already been decompiled. CachedDecompiledMember decompiledMember = this.cacheService.GetDecompiledMemberFromCache(method, language, this.renameInvalidMembers); AddDecompiledMemberToDecompiledType(decompiledMember, decompiledType); AddAssignmentDataToDecompiledType(decompiledMember, decompiledType); return; } if (method.Body == null) { CachedDecompiledMember methodCache = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(method), null, null)); this.cacheService.AddDecompiledMemberToCache(method, language, this.renameInvalidMembers, methodCache); return; } CachedDecompiledMember originalConstructor = DecompileMethod(language, method, decompiledType.TypeContext.ShallowPartialClone()); List<CachedDecompiledMember> allConstructors = new List<CachedDecompiledMember>(); TypeDefinition declaringType = method.DeclaringType; if (!method.IsStatic) { foreach (MethodDefinition constructor in declaringType.Methods) { if (!constructor.IsConstructor || constructor.FullName == originalConstructor.Member.MemberFullName || constructor.IsStatic) { continue; } if (constructor.Body == null) { CachedDecompiledMember methodCache = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(constructor), null, null)); allConstructors.Add(methodCache); } else { allConstructors.Add(DecompileMethod(language, constructor, decompiledType.TypeContext.ShallowPartialClone())); } } allConstructors.Add(originalConstructor); MergeConstructorsTypeContexts(allConstructors, decompiledType); foreach (CachedDecompiledMember constructor in allConstructors) { if (!(language is IntermediateLanguage)) { // there are no such statements in IL RemoveBaseCtorInvocationStatements(constructor, decompiledType); } if (constructor.Member.Context == null) { var methodDefinition = decompiledType.Type.Methods.First(x => x.FullName == constructor.Member.MemberFullName); if (!this.cacheService.IsDecompiledMemberInCache(methodDefinition, language, this.renameInvalidMembers)) { this.cacheService.AddDecompiledMemberToCache(methodDefinition, language, this.renameInvalidMembers, constructor); } } else { if (!this.cacheService.IsDecompiledMemberInCache(constructor.Member.Context.Method, language, this.renameInvalidMembers)) { this.cacheService.AddDecompiledMemberToCache(constructor.Member.Context.Method, language, this.renameInvalidMembers, constructor); } } AddDecompiledMemberToDecompiledType(constructor, decompiledType); //UpdateTypeContext(decompiledType.TypeContext, constructor); } } }
protected void DecompileConstructorChain(MethodDefinition method, ILanguage language, DecompiledType decompiledType) { if (this.cacheService.IsDecompiledMemberInCache(method, language, this.renameInvalidMembers)) { V_3 = this.cacheService.GetDecompiledMemberFromCache(method, language, this.renameInvalidMembers); this.AddDecompiledMemberToDecompiledType(V_3, decompiledType); BaseWriterContextService.AddAssignmentDataToDecompiledType(V_3, decompiledType); return; } if (method.get_Body() == null) { V_4 = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(method), null, null)); this.cacheService.AddDecompiledMemberToCache(method, language, this.renameInvalidMembers, V_4); return; } V_0 = this.DecompileMethod(language, method, decompiledType.get_TypeContext().ShallowPartialClone()); V_1 = new List <CachedDecompiledMember>(); V_2 = method.get_DeclaringType(); if (!method.get_IsStatic()) { V_5 = V_2.get_Methods().GetEnumerator(); try { while (V_5.MoveNext()) { V_6 = V_5.get_Current(); if (!V_6.get_IsConstructor() || String.op_Equality(V_6.get_FullName(), V_0.get_Member().get_MemberFullName()) || V_6.get_IsStatic()) { continue; } if (V_6.get_Body() != null) { V_1.Add(this.DecompileMethod(language, V_6, decompiledType.get_TypeContext().ShallowPartialClone())); } else { V_7 = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(V_6), null, null)); V_1.Add(V_7); } } } finally { V_5.Dispose(); } V_1.Add(V_0); this.MergeConstructorsTypeContexts(V_1, decompiledType); V_8 = V_1.GetEnumerator(); try { while (V_8.MoveNext()) { V_9 = new BaseWriterContextService.u003cu003ec__DisplayClass15_0(); V_9.constructor = V_8.get_Current(); if (language as IntermediateLanguage == null) { this.RemoveBaseCtorInvocationStatements(V_9.constructor, decompiledType); } if (V_9.constructor.get_Member().get_Context() != null) { if (!this.cacheService.IsDecompiledMemberInCache(V_9.constructor.get_Member().get_Context().get_Method(), language, this.renameInvalidMembers)) { this.cacheService.AddDecompiledMemberToCache(V_9.constructor.get_Member().get_Context().get_Method(), language, this.renameInvalidMembers, V_9.constructor); } } else { V_10 = decompiledType.get_Type().get_Methods().First <MethodDefinition>(new Func <MethodDefinition, bool>(V_9.u003cDecompileConstructorChainu003eb__0)); if (!this.cacheService.IsDecompiledMemberInCache(V_10, language, this.renameInvalidMembers)) { this.cacheService.AddDecompiledMemberToCache(V_10, language, this.renameInvalidMembers, V_9.constructor); } } this.AddDecompiledMemberToDecompiledType(V_9.constructor, decompiledType); } } finally { ((IDisposable)V_8).Dispose(); } } return; }
private static void AddAssignmentDataToDecompiledType(CachedDecompiledMember decompiledMember, DecompiledType decompiledType) { if (!decompiledType.get_TypeContext().get_FieldInitializationFailed()) { V_0 = decompiledMember.get_FieldAssignmentData().GetEnumerator(); try { while (V_0.MoveNext()) { V_1 = V_0.get_Current(); if (decompiledType.get_TypeContext().get_AssignmentData().ContainsKey(V_1.get_Key())) { if (decompiledType.get_TypeContext().get_AssignmentData().get_Item(V_1.get_Key()).get_AssignmentExpression().Equals(V_1.get_Value().get_AssignmentExpression())) { continue; } decompiledType.get_TypeContext().set_FieldInitializationFailed(true); decompiledType.get_TypeContext().set_AssignmentData(new Dictionary <string, InitializationAssignment>()); goto Label0; } else { decompiledType.get_TypeContext().get_AssignmentData().Add(V_1.get_Key(), V_1.get_Value()); } } } finally { ((IDisposable)V_0).Dispose(); } } Label0: return; }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member); DecompiledType decompiledType = new DecompiledType(declaringType); Queue<IMemberDefinition> decompilationQueue = new Queue<IMemberDefinition>(); decompilationQueue.Enqueue(member); while (decompilationQueue.Count > 0) { IMemberDefinition currentMember = decompilationQueue.Dequeue(); if (currentMember is TypeDefinition && currentMember == member) { TypeDefinition currentType = (currentMember as TypeDefinition); List<IMemberDefinition> members = Utilities.GetTypeMembers(currentType, language, propertyFields: decompiledType.TypeContext.GetFieldToPropertyMap(language).Keys); foreach (IMemberDefinition typeMember in members) { decompilationQueue.Enqueue(typeMember); } } if (currentMember is MethodDefinition) { DecompileMember(currentMember as MethodDefinition, language, decompiledType); } if (currentMember is EventDefinition) { EventDefinition eventDefinition = (currentMember as EventDefinition); AutoImplementedEventMatcher matcher = new AutoImplementedEventMatcher(eventDefinition, language); bool isAutoImplemented = matcher.IsAutoImplemented(); if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedEvents.Add(eventDefinition); } if (eventDefinition.AddMethod != null) { DecompileMember(eventDefinition.AddMethod, language, decompiledType); } if (eventDefinition.RemoveMethod != null) { DecompileMember(eventDefinition.RemoveMethod, language, decompiledType); } if (eventDefinition.InvokeMethod != null) { DecompileMember(eventDefinition.InvokeMethod, language, decompiledType); } } if (currentMember is PropertyDefinition) { PropertyDefinition propertyDefinition = (currentMember as PropertyDefinition); CachedDecompiledMember getMethod; CachedDecompiledMember setMethod; bool isAutoImplemented; PropertyDecompiler propertyDecompiler = new PropertyDecompiler(propertyDefinition, language, this.renameInvalidMembers, this.cacheService, decompiledType.TypeContext); propertyDecompiler.ExceptionThrown += OnExceptionThrown; propertyDecompiler.Decompile(out getMethod, out setMethod, out isAutoImplemented); propertyDecompiler.ExceptionThrown -= OnExceptionThrown; if (isAutoImplemented) { decompiledType.TypeContext.AutoImplementedProperties.Add(propertyDefinition); } if (getMethod != null) { AddDecompiledMemberToDecompiledType(getMethod, decompiledType); } if (setMethod != null) { AddDecompiledMemberToDecompiledType(setMethod, decompiledType); } foreach (MethodDefinition exceptionWhileDecompiling in propertyDecompiler.ExceptionsWhileDecompiling) { this.ExceptionsWhileDecompiling.Add(exceptionWhileDecompiling); } } if (currentMember is FieldDefinition) { FieldDefinition currentField = currentMember as FieldDefinition; /// Decompile all the constructors, that can set default values to the field. /// For instance fields decompile only instance constructors. /// For static fields decompile only static constructors. foreach (MethodDefinition method in currentMember.DeclaringType.Methods) { if (method.IsConstructor && currentField.IsStatic == method.IsStatic) { DecompileConstructorChain(method, language, decompiledType); break; } } } } decompiledType.TypeContext.ExplicitlyImplementedMembers = GetExplicitlyImplementedInterfaceMethods(declaringType, language); AddGeneratedFilterMethodsToDecompiledType(decompiledType, decompiledType.TypeContext, language); return decompiledType; }
protected void DecompileConstructorChain(MethodDefinition method, ILanguage language, DecompiledType decompiledType) { if (this.cacheService.IsDecompiledMemberInCache(method, language, this.renameInvalidMembers)) { ///all constructors have already been decompiled. CachedDecompiledMember decompiledMember = this.cacheService.GetDecompiledMemberFromCache(method, language, this.renameInvalidMembers); AddDecompiledMemberToDecompiledType(decompiledMember, decompiledType); return; } if (method.Body == null) { CachedDecompiledMember methodCache = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(method), null, null)); this.cacheService.AddDecompiledMemberToCache(method, language, this.renameInvalidMembers, methodCache); return; } CachedDecompiledMember originalConstructor = DecompileMethod(language, method, decompiledType.TypeContext.ShallowPartialClone()); List <CachedDecompiledMember> allConstructors = new List <CachedDecompiledMember>(); TypeDefinition declaringType = method.DeclaringType; if (!method.IsStatic) { foreach (MethodDefinition constructor in declaringType.Methods) { if (!constructor.IsConstructor || constructor.FullName == originalConstructor.Member.MemberFullName || constructor.IsStatic) { continue; } if (constructor.Body == null) { CachedDecompiledMember methodCache = new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(constructor), null, null)); allConstructors.Add(methodCache); } else { allConstructors.Add(DecompileMethod(language, constructor, decompiledType.TypeContext.ShallowPartialClone())); } } allConstructors.Add(originalConstructor); MergeConstructorsTypeContexts(allConstructors, decompiledType); foreach (CachedDecompiledMember constructor in allConstructors) { if (!(language is IntermediateLanguage)) { // there are no such statements in IL RemoveBaseCtorInvocationStatements(constructor, decompiledType); } if (constructor.Member.Context == null) { var methodDefinition = decompiledType.Type.Methods.First(x => x.FullName == constructor.Member.MemberFullName); if (!this.cacheService.IsDecompiledMemberInCache(methodDefinition, language, this.renameInvalidMembers)) { this.cacheService.AddDecompiledMemberToCache(methodDefinition, language, this.renameInvalidMembers, constructor); } } else { if (!this.cacheService.IsDecompiledMemberInCache(constructor.Member.Context.Method, language, this.renameInvalidMembers)) { this.cacheService.AddDecompiledMemberToCache(constructor.Member.Context.Method, language, this.renameInvalidMembers, constructor); } } AddDecompiledMemberToDecompiledType(constructor, decompiledType); //UpdateTypeContext(decompiledType.TypeContext, constructor); } } }
protected CachedDecompiledMember GetDecompiledMember(MethodDefinition method, ILanguage language, DecompiledType decompiledType) { if (method.Body == null) { return(new CachedDecompiledMember(new DecompiledMember(Utilities.GetMemberUniqueName(method), null, null))); } if (this.cacheService.IsDecompiledMemberInCache(method, language, this.renameInvalidMembers)) { return(this.cacheService.GetDecompiledMemberFromCache(method, language, this.renameInvalidMembers)); } CachedDecompiledMember decompiledMember = DecompileMethod(language, method, decompiledType.TypeContext); this.cacheService.AddDecompiledMemberToCache(method, language, this.renameInvalidMembers, decompiledMember); return(decompiledMember); }
protected void AddDecompiledMemberToDecompiledType(CachedDecompiledMember decompiledMember, DecompiledType decompiledType) { if (!decompiledType.get_DecompiledMembers().ContainsKey(decompiledMember.get_Member().get_MemberFullName())) { decompiledType.get_DecompiledMembers().Add(decompiledMember.get_Member().get_MemberFullName(), decompiledMember.get_Member()); } return; }
private void MergeConstructorsTypeContexts(List <CachedDecompiledMember> allConstructors, DecompiledType decompiledType) { if (allConstructors == null || allConstructors.Count == 0) { return; } for (int j = 0; j < allConstructors.Count; j++) { // context can be null, if the constructor has no body if (allConstructors[j].Member.Context != null && allConstructors[j].Member.Context.IsBaseConstructorInvokingConstructor) { decompiledType.TypeContext.BaseCtorInvocators.Add(allConstructors[j].Member.Context.Method); } } int i = 0; Dictionary <string, FieldInitializationAssignment> combinedDictionary = new Dictionary <string, FieldInitializationAssignment>(); for (; i < allConstructors.Count; i++) { if (allConstructors[i].Member.Context != null && allConstructors[i].Member.Context.IsBaseConstructorInvokingConstructor) { /// at least one constructor will call the base's ctor combinedDictionary = new Dictionary <string, FieldInitializationAssignment>(allConstructors[i].FieldAssignmentData); break; } } for (; i < allConstructors.Count; i++) { CachedDecompiledMember constructor = allConstructors[i]; if (constructor.Member.Context == null || !constructor.Member.Context.IsBaseConstructorInvokingConstructor) { continue; } if (constructor.FieldAssignmentData.Count != combinedDictionary.Count) { // merge should fail decompiledType.TypeContext.FieldInitializationFailed = true; decompiledType.TypeContext.FieldAssignmentData = new Dictionary <string, FieldInitializationAssignment>(); return; } foreach (KeyValuePair <string, FieldInitializationAssignment> pair in constructor.FieldAssignmentData) { if (combinedDictionary.ContainsKey(pair.Key) && combinedDictionary[pair.Key].AssignmentExpression.Equals(pair.Value.AssignmentExpression)) { continue; } // merge should fail otherwise decompiledType.TypeContext.FieldInitializationFailed = true; decompiledType.TypeContext.FieldAssignmentData = new Dictionary <string, FieldInitializationAssignment>(); return; } } decompiledType.TypeContext.FieldAssignmentData = combinedDictionary; }
private static void AddAssignmentDataToDecompiledType(CachedDecompiledMember decompiledMember, DecompiledType decompiledType) { if (!decompiledType.TypeContext.FieldInitializationFailed) { foreach (KeyValuePair<string, InitializationAssignment> pair in decompiledMember.FieldAssignmentData) { if (!decompiledType.TypeContext.AssignmentData.ContainsKey(pair.Key)) { decompiledType.TypeContext.AssignmentData.Add(pair.Key, pair.Value); } else if (!decompiledType.TypeContext.AssignmentData[pair.Key].AssignmentExpression.Equals(pair.Value.AssignmentExpression)) { decompiledType.TypeContext.FieldInitializationFailed = true; decompiledType.TypeContext.AssignmentData = new Dictionary<string, InitializationAssignment>(); return; } } } }
private void RemoveBaseCtorInvocationStatements(CachedDecompiledMember decompiledMember, DecompiledType decompiledType) { MethodSpecificContext methodContext = decompiledMember.Member.Context; //value types chained constructors? if (methodContext == null || !methodContext.Method.IsConstructor || methodContext.Method.IsStatic || methodContext.CtorInvokeExpression == null) { return; } BlockStatement methodBody = decompiledMember.Member.Statement as BlockStatement; if (methodBody == null) // it might have been an exception { return; } else if (methodBody.Statements.Count == 1 && methodBody.Statements[0] is UnsafeBlockStatement) { methodBody = methodBody.Statements[0] as UnsafeBlockStatement; } TypeSpecificContext typeContext = decompiledType.TypeContext; if (typeContext.FieldInitializationFailed && typeContext.BaseCtorInvocators.Contains(methodContext.Method)) { methodContext.CtorInvokeExpression = null; } else { /// all statements before the constructor invocation should be removed for (int i = 0; i < methodBody.Statements.Count; i++) { if (methodBody.Statements[i].CodeNodeType == Ast.CodeNodeType.ExpressionStatement && ((methodBody.Statements[i] as ExpressionStatement).Expression.CodeNodeType == Ast.CodeNodeType.ThisCtorExpression || (methodBody.Statements[i] as ExpressionStatement).Expression.CodeNodeType == Ast.CodeNodeType.BaseCtorExpression)) { RemoveFirstStatements(methodBody.Statements, i + 1); return; } } throw new Exception("Constructor invocation not found."); } }
private TypeSpecificContext CreateTypeContext(TypeDefinition type, ILanguage language, Dictionary<string, DecompiledType> decompiledTypes, DecompiledType decompiledCurrentType) { ICollection<TypeReference> typesDependingOn = GetTypesDependingOn(decompiledTypes, language); ICollection<string> usedNamespaces = GetUsedNamespaces(typesDependingOn, type.Namespace); ICollection<string> visibleMembersNames = GetTypeVisibleMembersNames(type, language); ExplicitlyImplementedMembersCollection explicitlyImplementedInterfaceMethods = GetExplicitlyImplementedInterfaceMethods(type, language); return new TypeSpecificContext( type, decompiledCurrentType.TypeContext.MethodDefinitionToNameMap, decompiledCurrentType.TypeContext.BackingFieldToNameMap, usedNamespaces, visibleMembersNames, decompiledCurrentType.TypeContext.AssignmentData, GetAutoImplementedProperties(decompiledTypes), GetAutoImplementedEvents(decompiledTypes), explicitlyImplementedInterfaceMethods, this.ExceptionsWhileDecompiling, decompiledCurrentType.TypeContext.GeneratedFilterMethods, decompiledCurrentType.TypeContext.GeneratedMethodDefinitionToNameMap ); }