private ICollection <TypeReference> GetEventTypesDependingOn(EventDefinition @event, ILanguage language) { HashSet <TypeReference> typesDependingOn = new HashSet <TypeReference>(); typesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(@event.EventType)); typesDependingOn.UnionWith(AttributesUtilities.GetEventAttributesUsedTypes(@event, language)); if (@event.AddMethod != null) { typesDependingOn.UnionWith(GetMethodTypesDependingOn(@event.AddMethod, language, false)); } if (@event.RemoveMethod != null) { typesDependingOn.UnionWith(GetMethodTypesDependingOn(@event.RemoveMethod, language, false)); } if (@event.InvokeMethod != null) { typesDependingOn.UnionWith(GetMethodTypesDependingOn(@event.InvokeMethod, language, false)); } return(typesDependingOn); }
private ICollection <TypeReference> GetFieldTypesDependingOn(FieldDefinition field) { HashSet <TypeReference> typesDependingOn = new HashSet <TypeReference>(); typesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(field.FieldType)); typesDependingOn.UnionWith(AttributesUtilities.GetFieldAttributesUsedTypes(field)); return(typesDependingOn); }
private IEnumerable <ICustomAttribute> WriteMethodFieldsAsAttributes(MethodDefinition method) { List <ICustomAttribute> attributes = new List <ICustomAttribute>(); // write [DllImport(dllName,CharSet=CharSet.*)] attribute if (method.HasPInvokeInfo) { attributes.Add(AttributesUtilities.GetMethodDllImportAttribute(method)); } return(attributes); }
private IEnumerable <ICustomAttribute> WriteMethodFieldsAsAttributes(MethodDefinition method) { V_0 = new List <ICustomAttribute>(); if (method.get_HasPInvokeInfo()) { V_0.Add(AttributesUtilities.GetMethodDllImportAttribute(method)); } if (method.get_HasImplAttributes() && AttributesUtilities.ShouldWriteMethodImplAttribute(method)) { V_0.Add(AttributesUtilities.GetMethodImplAttribute(method)); } return(V_0); }
private IEnumerable <ICustomAttribute> WriteFieldDefinitionFieldsAsAttributes(FieldDefinition member) { V_0 = new List <ICustomAttribute>(); if (member.get_IsNotSerialized()) { V_0.Add(AttributesUtilities.GetFieldNotSerializedAttribute(member)); } if (member.get_DeclaringType().get_IsExplicitLayout()) { V_0.Add(AttributesUtilities.GetFieldFieldOffsetAttribute(member)); } return(V_0); }
private IEnumerable <ICustomAttribute> WriteTypeDefinitionFieldsAsAttributes(TypeDefinition member) { V_0 = new List <ICustomAttribute>(); if (member.get_IsSerializable()) { V_0.Add(AttributesUtilities.GetTypeSerializableAttribute(member)); } if (member.get_IsExplicitLayout()) { V_0.Add(AttributesUtilities.GetTypeExplicitLayoutAttribute(member)); } return(V_0); }
private IEnumerable <ICustomAttribute> WriteTypeDefinitionFieldsAsAttributes(TypeDefinition member) { List <ICustomAttribute> attributes = new List <ICustomAttribute>(); //write [Serializable] attribute if (member.IsSerializable) { attributes.Add(AttributesUtilities.GetTypeSerializableAttribute(member)); } //write [StructLayout(LayoutKind.Explicit)] attribute if (member.IsExplicitLayout) { attributes.Add(AttributesUtilities.GetTypeExplicitLayoutAttribute(member)); } return(attributes); }
private IEnumerable <ICustomAttribute> WriteFieldDefinitionFieldsAsAttributes(FieldDefinition member) { List <ICustomAttribute> attributes = new List <ICustomAttribute>(); //write [NotSerialized] attribute if (member.IsNotSerialized) { attributes.Add(AttributesUtilities.GetFieldNotSerializedAttribute(member)); } //write [FieldOffset(x)] attribute if (member.DeclaringType.IsExplicitLayout) { attributes.Add(AttributesUtilities.GetFieldFieldOffsetAttribute(member)); } return(attributes); }
private ICollection <TypeReference> GetPropertyTypesDependingOn(PropertyDefinition property, ILanguage language) { HashSet <TypeReference> typesDependingOn = new HashSet <TypeReference>(); typesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(property.PropertyType)); typesDependingOn.UnionWith(AttributesUtilities.GetPropertyAttributesUsedTypes(property, language)); if (property.GetMethod != null) { typesDependingOn.UnionWith(GetMethodTypesDependingOn(property.GetMethod, language, false)); } if (property.SetMethod != null) { typesDependingOn.UnionWith(GetMethodTypesDependingOn(property.SetMethod, language, false)); } return(typesDependingOn); }
private ICollection <TypeReference> GetMethodTypesDependingOn(MethodDefinition method, ILanguage language, bool considerAttributes = true) { HashSet <TypeReference> typesDependingOn = new HashSet <TypeReference>(); if (method.ReturnType != null) { typesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(method.ReturnType)); } if (considerAttributes) { typesDependingOn.UnionWith(AttributesUtilities.GetMethodAttributesUsedTypes(method, language)); } foreach (ParameterDefinition parameter in method.Parameters) { typesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(parameter.ParameterType)); } return(typesDependingOn); }
protected ICollection <string> GetModuleNamespaceUsings(ModuleDefinition module) { ICollection <TypeReference> typesDependingOn = AttributesUtilities.GetModuleAttributesUsedTypes(module); return(GetUsedNamespaces(typesDependingOn)); }
protected ICollection <string> GetAssemblyNamespaceUsings(AssemblyDefinition assembly) { ICollection <TypeReference> typesDependingOn = AttributesUtilities.GetAssemblyAttributesUsedTypes(assembly); return(GetUsedNamespaces(typesDependingOn)); }
private ICollection <TypeReference> GetTypesDependingOn(Dictionary <string, DecompiledType> decompiledTypes, ILanguage language) { HashSet <TypeReference> typesDependingOn = new HashSet <TypeReference>(); foreach (DecompiledType decompiledType in decompiledTypes.Values) { foreach (KeyValuePair <string, DecompiledMember> pair in decompiledType.DecompiledMembers) { if (pair.Value.Context != null) { typesDependingOn.UnionWith(pair.Value.Context.AnalysisResults.TypesDependingOn); if ((pair.Value.Context.Method != null) && (pair.Value.Context.Method.Body != null) && (pair.Value.Context.Method.Body.HasVariables)) { foreach (VariableDefinition localVariable in pair.Value.Context.Method.Body.Variables) { if (!typesDependingOn.Contains(localVariable.VariableType)) { typesDependingOn.Add(localVariable.VariableType); } } } } } if (decompiledType.Type.BaseType != null) { typesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(decompiledType.Type.BaseType)); } if (decompiledType.Type.HasGenericParameters) { foreach (GenericParameter genericParameter in decompiledType.Type.GenericParameters) { if (genericParameter.HasConstraints) { foreach (TypeReference constraint in genericParameter.Constraints) { typesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(constraint)); } } } } foreach (TypeReference reference in decompiledType.Type.Interfaces) { typesDependingOn.UnionWith(Utilities.GetTypeReferenceTypesDepedningOn(reference)); } typesDependingOn.UnionWith(AttributesUtilities.GetTypeAttributesUsedTypes(decompiledType.Type)); List <IMemberDefinition> members = Utilities.GetTypeMembers(decompiledType.Type); foreach (IMemberDefinition member in members) { if (member is MethodDefinition) { MethodDefinition method = member as MethodDefinition; typesDependingOn.UnionWith(GetMethodTypesDependingOn(method, language)); //if (method.IsConstructor) //{ // DecompiledMember decompiledMember; // if (decompiledType.DecompiledMembers.TryGetValue(Utilities.GetMemberUniqueName(method), out decompiledMember)) // { // if (decompiledMember.Context != null && decompiledMember.Context.CtorInvokeExpression != null) // { // DependsOnAnalysisVisitor visitor = new DependsOnAnalysisVisitor(typesDependingOn); // visitor.Visit(decompiledMember.Context.CtorInvokeExpression); // } // } // else // { // throw new Exception("Decompiled member not found in decompiled members cache."); // } //} } if (member is PropertyDefinition) { typesDependingOn.UnionWith(GetPropertyTypesDependingOn(member as PropertyDefinition, language)); } if (member is EventDefinition) { typesDependingOn.UnionWith(GetEventTypesDependingOn(member as EventDefinition, language)); } if (member is FieldDefinition) { typesDependingOn.UnionWith(GetFieldTypesDependingOn(member as FieldDefinition)); } } } return(typesDependingOn); }
public virtual void WriteAssemblyAttributes(AssemblyDefinition assembly, ICollection <string> attributesToIgnore = null) { List <ICustomAttribute> assemblyAttributes = new List <ICustomAttribute>(); securityAttributeToDeclaration = new Dictionary <SecurityAttribute, SecurityDeclaration>(); CustomAttribute assemblyVersionAttribute = AttributesUtilities.GetAssemblyVersionAttribute(assembly); assemblyAttributes.Add(assemblyVersionAttribute); foreach (CustomAttribute attribute in assembly.CustomAttributes) { attribute.Resolve(); assemblyAttributes.Add(attribute); } if (assembly.HasSecurityDeclarations) { foreach (SecurityDeclaration declaration in assembly.SecurityDeclarations) { assemblyAttributes.AddRange(GetSecurityDeclaration(declaration)); } } if (assembly.MainModule.HasExportedTypes) { foreach (ExportedType exportedType in assembly.MainModule.ExportedTypes) { if (!(exportedType.Scope is ModuleReference)) { assemblyAttributes.Add(AttributesUtilities.GetExportedTypeAttribute(exportedType, assembly.MainModule)); } } } assemblyAttributes.Sort((x, y) => CompareAttributes(x, y)); foreach (ICustomAttribute attr in assemblyAttributes) { if (attributesToIgnore != null) { if (attributesToIgnore.Contains(attr.AttributeType.FullName)) { continue; } } if (attr is CustomAttribute) { WriteAssemblyAttribute(attr as CustomAttribute); } else if (attr is SecurityAttribute) { bool b; WriteSecurityAttribute(assembly.MainModule, true, attr as SecurityAttribute, securityAttributeToDeclaration[attr as SecurityAttribute], out b); } } //if (writeUsings) //{ // genericWriter.WriteUsings(); //} //WriteModuleAttributes(assembly.MainModule, analysisData, attributesToIgnore); }
protected ICollection <string> GetAssemblyNamespaceUsings(AssemblyDefinition assembly) { return(this.GetUsedNamespaces(AttributesUtilities.GetAssemblyAttributesUsedTypes(assembly), "")); }
public virtual void WriteAssemblyAttributes(AssemblyDefinition assembly, ICollection <string> attributesToIgnore = null) { V_0 = new List <ICustomAttribute>(); this.securityAttributeToDeclaration = new Dictionary <SecurityAttribute, SecurityDeclaration>(); V_0.Add(AttributesUtilities.GetAssemblyVersionAttribute(assembly)); V_2 = assembly.get_CustomAttributes().GetEnumerator(); try { while (V_2.MoveNext()) { V_3 = V_2.get_Current(); V_3.Resolve(); V_0.Add(V_3); } } finally { V_2.Dispose(); } if (assembly.get_HasSecurityDeclarations()) { V_4 = assembly.get_SecurityDeclarations().GetEnumerator(); try { while (V_4.MoveNext()) { V_5 = V_4.get_Current(); V_0.AddRange(this.GetSecurityDeclaration(V_5)); } } finally { V_4.Dispose(); } } if (assembly.get_MainModule().get_HasExportedTypes()) { V_6 = assembly.get_MainModule().get_ExportedTypes().GetEnumerator(); try { while (V_6.MoveNext()) { V_7 = V_6.get_Current(); if (V_7.get_Scope() as ModuleReference != null) { continue; } V_0.Add(AttributesUtilities.GetExportedTypeAttribute(V_7, assembly.get_MainModule())); } } finally { V_6.Dispose(); } } V_0.Sort(new Comparison <ICustomAttribute>(this.u003cWriteAssemblyAttributesu003eb__18_0)); V_8 = V_0.GetEnumerator(); try { while (V_8.MoveNext()) { V_9 = V_8.get_Current(); if (attributesToIgnore != null && attributesToIgnore.Contains(V_9.get_AttributeType().get_FullName())) { continue; } if (V_9 as CustomAttribute == null) { if (V_9 as SecurityAttribute == null) { continue; } dummyVar0 = this.WriteSecurityAttribute(assembly.get_MainModule(), true, V_9 as SecurityAttribute, this.securityAttributeToDeclaration.get_Item(V_9 as SecurityAttribute), out V_10, false, false); } else { this.WriteAssemblyAttribute(V_9 as CustomAttribute); } } } finally { ((IDisposable)V_8).Dispose(); } return; }