Inheritance: ICustomAttributeProvider
		public static SignatureHelper GetPropertySigHelper(Module mod, Type returnType, Type[] parameterTypes)
		{
			SignatureHelper sig = new SignatureHelper(mod as ModuleBuilder, Signature.PROPERTY);
			sig.returnType = returnType;
			foreach (Type type in parameterTypes)
			{
				sig.AddArgument(type);
			}
			return sig;
		}
Example #2
0
		public static SignatureHelper GetPropertySigHelper(Module mod, Type returnType, Type[] parameterTypes)
		{
			SignatureHelper sig = new SignatureHelper(mod as ModuleBuilder, Signature.PROPERTY);
			sig.returnType = returnType;
			sig.returnTypeOptionalCustomModifiers = Type.EmptyTypes;
			sig.returnTypeRequiredCustomModifiers = Type.EmptyTypes;
			foreach (Type type in parameterTypes)
			{
				sig.AddArgument(type);
			}
			return sig;
		}
Example #3
0
		internal MissingType(Module module, Type declaringType, string ns, string name)
		{
			this.module = module;
			this.declaringType = declaringType;
			this.ns = ns;
			this.name = name;
		}
		internal static CustomAttributeData CreateDllImportPseudoCustomAttribute(Module module, ImplMapFlags flags, string entryPoint, string dllName, MethodImplAttributes attr)
		{
			Type type = module.universe.System_Runtime_InteropServices_DllImportAttribute;
			ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor(module.universe.System_String);
			List<CustomAttributeNamedArgument> list = new List<CustomAttributeNamedArgument>();
			System.Runtime.InteropServices.CharSet charSet;
			switch (flags & ImplMapFlags.CharSetMask)
			{
				case ImplMapFlags.CharSetAnsi:
					charSet = System.Runtime.InteropServices.CharSet.Ansi;
					break;
				case ImplMapFlags.CharSetUnicode:
					charSet = System.Runtime.InteropServices.CharSet.Unicode;
					break;
				case ImplMapFlags.CharSetAuto:
					charSet = System.Runtime.InteropServices.CharSet.Auto;
					break;
				case ImplMapFlags.CharSetNotSpec:
				default:
					charSet = System.Runtime.InteropServices.CharSet.None;
					break;
			}
			System.Runtime.InteropServices.CallingConvention callingConvention;
			switch (flags & ImplMapFlags.CallConvMask)
			{
				case ImplMapFlags.CallConvCdecl:
					callingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl;
					break;
				case ImplMapFlags.CallConvFastcall:
					callingConvention = System.Runtime.InteropServices.CallingConvention.FastCall;
					break;
				case ImplMapFlags.CallConvStdcall:
					callingConvention = System.Runtime.InteropServices.CallingConvention.StdCall;
					break;
				case ImplMapFlags.CallConvThiscall:
					callingConvention = System.Runtime.InteropServices.CallingConvention.ThisCall;
					break;
				case ImplMapFlags.CallConvWinapi:
					callingConvention = System.Runtime.InteropServices.CallingConvention.Winapi;
					break;
				default:
					callingConvention = 0;
					break;
			}
			AddNamedArgument(list, type, "EntryPoint", entryPoint);
			AddNamedArgument(list, type, "CharSet", module.universe.System_Runtime_InteropServices_CharSet, (int)charSet);
			AddNamedArgument(list, type, "ExactSpelling", (int)flags, (int)ImplMapFlags.NoMangle);
			AddNamedArgument(list, type, "SetLastError", (int)flags, (int)ImplMapFlags.SupportsLastError);
			AddNamedArgument(list, type, "PreserveSig", (int)attr, (int)MethodImplAttributes.PreserveSig);
			AddNamedArgument(list, type, "CallingConvention", module.universe.System_Runtime_InteropServices_CallingConvention, (int)callingConvention);
			AddNamedArgument(list, type, "BestFitMapping", (int)flags, (int)ImplMapFlags.BestFitOn);
			AddNamedArgument(list, type, "ThrowOnUnmappableChar", (int)flags, (int)ImplMapFlags.CharMapErrorOn);
			return new CustomAttributeData(module, constructor, new object[] { dllName }, list);
		}
		// 1) Unresolved Custom Attribute
		internal CustomAttributeData(Module module, int index)
		{
			this.module = module;
			this.customAttributeIndex = index;
			this.declSecurityIndex = -1;
		}
		private static PropertyInfo GetProperty(Module context, Type type, string name, Type propertyType)
		{
			Type org = type;
			for (; type != null && !type.__IsMissing; type = type.BaseType)
			{
				foreach (PropertyInfo property in type.__GetDeclaredProperties())
				{
					if (property.IsPublic && !property.IsStatic && property.Name == name)
					{
						return property;
					}
				}
			}
			// if the property is missing, we stick the missing property on the first missing base type
			if (type == null)
			{
				type = org;
			}
			return type.Module.universe.GetMissingPropertyOrThrow(context, type, name,
				PropertySignature.Create(CallingConventions.Standard | CallingConventions.HasThis, propertyType, null, new PackedCustomModifiers()));
		}
		public static IList<CustomAttributeData> __GetCustomAttributes(Module module, Type attributeType, bool inherit)
		{
			if (module.__IsMissing)
			{
				throw new MissingModuleException((MissingModule)module);
			}
			return GetCustomAttributesImpl(null, module, 0x00000001, attributeType) ?? EmptyList;
		}
		private static Type ReadType(Module context, ByteReader br)
		{
			string typeName = br.ReadString();
			if (typeName == null)
			{
				return null;
			}
			if (typeName.Length > 0 && typeName[typeName.Length - 1] == 0)
			{
				// there are broken compilers that emit an extra NUL character after the type name
				typeName = typeName.Substring(0, typeName.Length - 1);
			}
			return TypeNameParser.Parse(typeName, true).GetType(context.universe, context, true, typeName, true, false);
		}
		private static IList<CustomAttributeNamedArgument> ReadNamedArguments(Module context, ByteReader br, int named, Type type, bool required)
		{
			List<CustomAttributeNamedArgument> list = new List<CustomAttributeNamedArgument>(named);
			for (int i = 0; i < named; i++)
			{
				byte fieldOrProperty = br.ReadByte();
				Type fieldOrPropertyType = ReadFieldOrPropType(context, br);
				if (fieldOrPropertyType.__IsMissing && !required)
				{
					return null;
				}
				string name = br.ReadString();
				CustomAttributeTypedArgument value = ReadFixedArg(context, br, fieldOrPropertyType);
				MemberInfo member;
				switch (fieldOrProperty)
				{
					case 0x53:
						member = GetField(context, type, name, fieldOrPropertyType);
						break;
					case 0x54:
						member = GetProperty(context, type, name, fieldOrPropertyType);
						break;
					default:
						throw new BadImageFormatException();
				}
				list.Add(new CustomAttributeNamedArgument(member, value));
			}
			return list.AsReadOnly();
		}
		private static Type ReadType(Module module, ByteReader br)
		{
			string str = ReadString(br);
			if (str == "")
			{
				return null;
			}
			return module.Assembly.GetType(str) ?? module.universe.GetType(str, true);
		}
Example #11
0
 public static IList <CustomAttributeData> __GetCustomAttributes(Module module, Type attributeType, bool inherit)
 {
     return(module.GetCustomAttributesData(attributeType));
 }
Example #12
0
        internal static CustomAttributeData CreateDllImportPseudoCustomAttribute(Module module, ImplMapFlags flags, string entryPoint, string dllName, MethodImplAttributes attr)
        {
            Type            type        = module.universe.System_Runtime_InteropServices_DllImportAttribute;
            ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor(module.universe.System_String);
            List <CustomAttributeNamedArgument> list = new List <CustomAttributeNamedArgument>();

            System.Runtime.InteropServices.CharSet charSet;
            switch (flags & ImplMapFlags.CharSetMask)
            {
            case ImplMapFlags.CharSetAnsi:
                charSet = System.Runtime.InteropServices.CharSet.Ansi;
                break;

            case ImplMapFlags.CharSetUnicode:
                charSet = System.Runtime.InteropServices.CharSet.Unicode;
                break;

            case ImplMapFlags.CharSetAuto:
#if NETSTANDARD
                charSet = (System.Runtime.InteropServices.CharSet) 4;
#else
                charSet = System.Runtime.InteropServices.CharSet.Auto;
#endif
                break;

            case ImplMapFlags.CharSetNotSpec:
            default:
#if NETSTANDARD
                charSet = (System.Runtime.InteropServices.CharSet) 1;
#else
                charSet = System.Runtime.InteropServices.CharSet.None;
#endif
                break;
            }
            System.Runtime.InteropServices.CallingConvention callingConvention;
            switch (flags & ImplMapFlags.CallConvMask)
            {
            case ImplMapFlags.CallConvCdecl:
                callingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl;
                break;

            case ImplMapFlags.CallConvFastcall:
#if NETSTANDARD
                callingConvention = (System.Runtime.InteropServices.CallingConvention) 5;
#else
                callingConvention = System.Runtime.InteropServices.CallingConvention.FastCall;
#endif
                break;

            case ImplMapFlags.CallConvStdcall:
                callingConvention = System.Runtime.InteropServices.CallingConvention.StdCall;
                break;

            case ImplMapFlags.CallConvThiscall:
                callingConvention = System.Runtime.InteropServices.CallingConvention.ThisCall;
                break;

            case ImplMapFlags.CallConvWinapi:
                callingConvention = System.Runtime.InteropServices.CallingConvention.Winapi;
                break;

            default:
                callingConvention = 0;
                break;
            }
            AddNamedArgument(list, type, "EntryPoint", entryPoint);
            AddNamedArgument(list, type, "CharSet", module.universe.System_Runtime_InteropServices_CharSet, (int)charSet);
            AddNamedArgument(list, type, "ExactSpelling", (int)flags, (int)ImplMapFlags.NoMangle);
            AddNamedArgument(list, type, "SetLastError", (int)flags, (int)ImplMapFlags.SupportsLastError);
            AddNamedArgument(list, type, "PreserveSig", (int)attr, (int)MethodImplAttributes.PreserveSig);
            AddNamedArgument(list, type, "CallingConvention", module.universe.System_Runtime_InteropServices_CallingConvention, (int)callingConvention);
            AddNamedArgument(list, type, "BestFitMapping", (int)flags, (int)ImplMapFlags.BestFitOn);
            AddNamedArgument(list, type, "ThrowOnUnmappableChar", (int)flags, (int)ImplMapFlags.CharMapErrorOn);
            return(new CustomAttributeData(module, constructor, new object[] { dllName }, list));
        }
Example #13
0
 // 1) Unresolved Custom Attribute
 internal CustomAttributeData(Module module, int index)
 {
     this.module = module;
     this.customAttributeIndex = index;
     this.declSecurityIndex    = -1;
 }
Example #14
0
 internal static List <CustomAttributeData> GetCustomAttributesImpl(List <CustomAttributeData> list, Module module, int token, Type attributeType)
 {
     foreach (int i in module.CustomAttribute.Filter(token))
     {
         if (attributeType == null)
         {
             if (list == null)
             {
                 list = new List <CustomAttributeData>();
             }
             list.Add(new CustomAttributeData(module, i));
         }
         else
         {
             if (attributeType.IsAssignableFrom(module.ResolveMethod(module.CustomAttribute.records[i].Type).DeclaringType))
             {
                 if (list == null)
                 {
                     list = new List <CustomAttributeData>();
                 }
                 list.Add(new CustomAttributeData(module, i));
             }
         }
     }
     return(list);
 }
Example #15
0
 public static IList <CustomAttributeData> GetCustomAttributes(Module module)
 {
     return(__GetCustomAttributes(module, null, false));
 }
Example #16
0
        private static CustomAttributeTypedArgument ReadFixedArg(Module context, ByteReader br, Type type)
        {
            Universe u = context.universe;

            if (type == u.System_String)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadString()));
            }
            else if (type == u.System_Boolean)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadByte() != 0));
            }
            else if (type == u.System_Char)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadChar()));
            }
            else if (type == u.System_Single)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadSingle()));
            }
            else if (type == u.System_Double)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadDouble()));
            }
            else if (type == u.System_SByte)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadSByte()));
            }
            else if (type == u.System_Int16)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt16()));
            }
            else if (type == u.System_Int32)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt32()));
            }
            else if (type == u.System_Int64)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadInt64()));
            }
            else if (type == u.System_Byte)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadByte()));
            }
            else if (type == u.System_UInt16)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt16()));
            }
            else if (type == u.System_UInt32)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt32()));
            }
            else if (type == u.System_UInt64)
            {
                return(new CustomAttributeTypedArgument(type, br.ReadUInt64()));
            }
            else if (type == u.System_Type)
            {
                return(new CustomAttributeTypedArgument(type, ReadType(context, br)));
            }
            else if (type == u.System_Object)
            {
                return(ReadFixedArg(context, br, ReadFieldOrPropType(context, br)));
            }
            else if (type.IsArray)
            {
                int length = br.ReadInt32();
                if (length == -1)
                {
                    return(new CustomAttributeTypedArgument(type, null));
                }
                Type elementType = type.GetElementType();
                CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length];
                for (int i = 0; i < length; i++)
                {
                    array[i] = ReadFixedArg(context, br, elementType);
                }
                return(new CustomAttributeTypedArgument(type, array));
            }
            else if (type.IsEnum)
            {
                return(new CustomAttributeTypedArgument(type, ReadFixedArg(context, br, type.GetEnumUnderlyingTypeImpl()).Value));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Example #17
0
        private static Type ReadFieldOrPropType(Module context, ByteReader br)
        {
            Universe u = context.universe;

            switch (br.ReadByte())
            {
            case Signature.ELEMENT_TYPE_BOOLEAN:
                return(u.System_Boolean);

            case Signature.ELEMENT_TYPE_CHAR:
                return(u.System_Char);

            case Signature.ELEMENT_TYPE_I1:
                return(u.System_SByte);

            case Signature.ELEMENT_TYPE_U1:
                return(u.System_Byte);

            case Signature.ELEMENT_TYPE_I2:
                return(u.System_Int16);

            case Signature.ELEMENT_TYPE_U2:
                return(u.System_UInt16);

            case Signature.ELEMENT_TYPE_I4:
                return(u.System_Int32);

            case Signature.ELEMENT_TYPE_U4:
                return(u.System_UInt32);

            case Signature.ELEMENT_TYPE_I8:
                return(u.System_Int64);

            case Signature.ELEMENT_TYPE_U8:
                return(u.System_UInt64);

            case Signature.ELEMENT_TYPE_R4:
                return(u.System_Single);

            case Signature.ELEMENT_TYPE_R8:
                return(u.System_Double);

            case Signature.ELEMENT_TYPE_STRING:
                return(u.System_String);

            case Signature.ELEMENT_TYPE_SZARRAY:
                return(ReadFieldOrPropType(context, br).MakeArrayType());

            case 0x55:
                return(ReadType(context, br));

            case 0x50:
                return(u.System_Type);

            case 0x51:
                return(u.System_Object);

            default:
                throw new BadImageFormatException();
            }
        }
Example #18
0
 // 4) Pseudo Custom Attribute, .NET 1.x declarative security
 internal CustomAttributeData(Module module, ConstructorInfo constructor, object[] args, List <CustomAttributeNamedArgument> namedArguments)
     : this(module, constructor, WrapConstructorArgs(args, constructor.MethodSignature), namedArguments)
 {
 }
		internal static bool ReadFieldMarshal(Module module, int token, out FieldMarshal fm)
		{
			fm = new FieldMarshal();
			foreach (int i in module.FieldMarshal.Filter(token))
			{
				ByteReader blob = module.GetBlob(module.FieldMarshal.records[i].NativeType);
				fm.UnmanagedType = (UnmanagedType)blob.ReadCompressedUInt();
				if (fm.UnmanagedType == UnmanagedType.LPArray)
				{
					fm.ArraySubType = (UnmanagedType)blob.ReadCompressedUInt();
					if (fm.ArraySubType == NATIVE_TYPE_MAX)
					{
						fm.ArraySubType = null;
					}
					if (blob.Length != 0)
					{
						fm.SizeParamIndex = (short)blob.ReadCompressedUInt();
						if (blob.Length != 0)
						{
							fm.SizeConst = blob.ReadCompressedUInt();
							if (blob.Length != 0 && blob.ReadCompressedUInt() == 0)
							{
								fm.SizeParamIndex = null;
							}
						}
					}
				}
				else if (fm.UnmanagedType == UnmanagedType.SafeArray)
				{
					if (blob.Length != 0)
					{
						fm.SafeArraySubType = (VarEnum)blob.ReadCompressedUInt();
						if (blob.Length != 0)
						{
							fm.SafeArrayUserDefinedSubType = ReadType(module, blob);
						}
					}
				}
				else if (fm.UnmanagedType == UnmanagedType.ByValArray)
				{
					fm.SizeConst = blob.ReadCompressedUInt();
					if (blob.Length != 0)
					{
						fm.ArraySubType = (UnmanagedType)blob.ReadCompressedUInt();
					}
				}
				else if (fm.UnmanagedType == UnmanagedType.ByValTStr)
				{
					fm.SizeConst = blob.ReadCompressedUInt();
				}
				else if (fm.UnmanagedType == UnmanagedType.Interface
					|| fm.UnmanagedType == UnmanagedType.IDispatch
					|| fm.UnmanagedType == UnmanagedType.IUnknown)
				{
					if (blob.Length != 0)
					{
						fm.IidParameterIndex = blob.ReadCompressedUInt();
					}
				}
				else if (fm.UnmanagedType == UnmanagedType.CustomMarshaler)
				{
					blob.ReadCompressedUInt();
					blob.ReadCompressedUInt();
					fm.MarshalType = ReadString(blob);
					fm.MarshalCookie = ReadString(blob);

					TypeNameParser parser = TypeNameParser.Parse(fm.MarshalType, false);
					if (!parser.Error)
					{
						fm.MarshalTypeRef = parser.GetType(module.universe, module, false, fm.MarshalType, false, false);
					}
				}
				return true;
			}
			return false;
		}
Example #20
0
 public bool __TryGetImplMap(out ImplMapFlags mappingFlags, out string importName, out string importScope)
 {
     return(Module.__TryGetImplMap(GetCurrentToken(), out mappingFlags, out importName, out importScope));
 }
		private static CustomAttributeTypedArgument ReadFixedArg(Module context, ByteReader br, Type type)
		{
			Universe u = context.universe;
			if (type == u.System_String)
			{
				return new CustomAttributeTypedArgument(type, br.ReadString());
			}
			else if (type == u.System_Boolean)
			{
				return new CustomAttributeTypedArgument(type, br.ReadByte() != 0);
			}
			else if (type == u.System_Char)
			{
				return new CustomAttributeTypedArgument(type, br.ReadChar());
			}
			else if (type == u.System_Single)
			{
				return new CustomAttributeTypedArgument(type, br.ReadSingle());
			}
			else if (type == u.System_Double)
			{
				return new CustomAttributeTypedArgument(type, br.ReadDouble());
			}
			else if (type == u.System_SByte)
			{
				return new CustomAttributeTypedArgument(type, br.ReadSByte());
			}
			else if (type == u.System_Int16)
			{
				return new CustomAttributeTypedArgument(type, br.ReadInt16());
			}
			else if (type == u.System_Int32)
			{
				return new CustomAttributeTypedArgument(type, br.ReadInt32());
			}
			else if (type == u.System_Int64)
			{
				return new CustomAttributeTypedArgument(type, br.ReadInt64());
			}
			else if (type == u.System_Byte)
			{
				return new CustomAttributeTypedArgument(type, br.ReadByte());
			}
			else if (type == u.System_UInt16)
			{
				return new CustomAttributeTypedArgument(type, br.ReadUInt16());
			}
			else if (type == u.System_UInt32)
			{
				return new CustomAttributeTypedArgument(type, br.ReadUInt32());
			}
			else if (type == u.System_UInt64)
			{
				return new CustomAttributeTypedArgument(type, br.ReadUInt64());
			}
			else if (type == u.System_Type)
			{
				return new CustomAttributeTypedArgument(type, ReadType(context, br));
			}
			else if (type == u.System_Object)
			{
				return ReadFixedArg(context, br, ReadFieldOrPropType(context, br));
			}
			else if (type.IsArray)
			{
				int length = br.ReadInt32();
				if (length == -1)
				{
					return new CustomAttributeTypedArgument(type, null);
				}
				Type elementType = type.GetElementType();
				CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length];
				for (int i = 0; i < length; i++)
				{
					array[i] = ReadFixedArg(context, br, elementType);
				}
				return new CustomAttributeTypedArgument(type, array);
			}
			else if (type.IsEnum)
			{
				return new CustomAttributeTypedArgument(type, ReadFixedArg(context, br, type.GetEnumUnderlyingTypeImpl()).Value);
			}
			else
			{
				throw new InvalidOperationException();
			}
		}
Example #22
0
		public static IList<CustomAttributeData> __GetCustomAttributes(Module module, Type attributeType, bool inherit)
		{
			return module.GetCustomAttributesData(attributeType);
		}
		private static IList<CustomAttributeTypedArgument> ReadConstructorArguments(Module context, ByteReader br, ConstructorInfo constructor)
		{
			MethodSignature sig = constructor.MethodSignature;
			int count = sig.GetParameterCount();
			List<CustomAttributeTypedArgument> list = new List<CustomAttributeTypedArgument>(count);
			for (int i = 0; i < count; i++)
			{
				list.Add(ReadFixedArg(context, br, sig.GetParameterType(i)));
			}
			return list.AsReadOnly();
		}
		internal static CustomAttributeData CreateFieldOffsetPseudoCustomAttribute(Module module, int offset)
		{
			Type type = module.universe.System_Runtime_InteropServices_FieldOffsetAttribute;
			ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor(module.universe.System_Int32);
			return new CustomAttributeData(module, constructor, new object[] { offset }, null);
		}
		private static FieldInfo GetField(Module context, Type type, string name, Type fieldType)
		{
			Type org = type;
			for (; type != null && !type.__IsMissing; type = type.BaseType)
			{
				foreach (FieldInfo field in type.__GetDeclaredFields())
				{
					if (field.IsPublic && !field.IsStatic && field.Name == name)
					{
						return field;
					}
				}
			}
			// if the field is missing, we stick the missing field on the first missing base type
			if (type == null)
			{
				type = org;
			}
			FieldSignature sig = FieldSignature.Create(fieldType, new CustomModifiers());
			return type.FindField(name, sig)
				?? type.Module.universe.GetMissingFieldOrThrow(context, type, name, sig);
		}
		internal static CustomAttributeData CreatePreserveSigPseudoCustomAttribute(Module module)
		{
			Type type = module.universe.System_Runtime_InteropServices_PreserveSigAttribute;
			ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor();
			return new CustomAttributeData(module, constructor, Empty<object>.Array, null);
		}
		public static IList<CustomAttributeData> GetCustomAttributes(Module module)
		{
			return __GetCustomAttributes(module, null, false);
		}
		// 4) Pseudo Custom Attribute, .NET 1.x declarative security
		internal CustomAttributeData(Module module, ConstructorInfo constructor, object[] args, List<CustomAttributeNamedArgument> namedArguments)
			: this(module, constructor, WrapConstructorArgs(args, constructor.MethodSignature), namedArguments)
		{
		}
		internal static List<CustomAttributeData> GetCustomAttributesImpl(List<CustomAttributeData> list, Module module, int token, Type attributeType)
		{
			foreach (int i in module.CustomAttribute.Filter(token))
			{
				if (attributeType == null)
				{
					if (list == null)
					{
						list = new List<CustomAttributeData>();
					}
					list.Add(new CustomAttributeData(module, i));
				}
				else
				{
					if (attributeType.IsAssignableFrom(module.ResolveMethod(module.CustomAttribute.records[i].Type).DeclaringType))
					{
						if (list == null)
						{
							list = new List<CustomAttributeData>();
						}
						list.Add(new CustomAttributeData(module, i));
					}
				}
			}
			return list;
		}
		// 4) Pseudo Custom Attribute, .NET 1.x declarative security or result of CustomAttributeBuilder.ToData()
		internal CustomAttributeData(Module module, ConstructorInfo constructor, List<CustomAttributeTypedArgument> constructorArgs, List<CustomAttributeNamedArgument> namedArguments)
		{
			this.module = module;
			this.customAttributeIndex = -1;
			this.declSecurityIndex = -1;
			this.lazyConstructor = constructor;
			lazyConstructorArguments = constructorArgs.AsReadOnly();
			if (namedArguments == null)
			{
				this.lazyNamedArguments = Empty<CustomAttributeNamedArgument>.Array;
			}
			else
			{
				this.lazyNamedArguments = namedArguments.AsReadOnly();
			}
		}
		internal static CustomAttributeData CreateMarshalAsPseudoCustomAttribute(Module module, FieldMarshal fm)
		{
			Type typeofMarshalAs = module.universe.System_Runtime_InteropServices_MarshalAsAttribute;
			Type typeofUnmanagedType = module.universe.System_Runtime_InteropServices_UnmanagedType;
			Type typeofVarEnum = module.universe.System_Runtime_InteropServices_VarEnum;
			Type typeofType = module.universe.System_Type;
			List<CustomAttributeNamedArgument> named = new List<CustomAttributeNamedArgument>();
			AddNamedArgument(named, typeofMarshalAs, "ArraySubType", typeofUnmanagedType, (int)(fm.ArraySubType ?? 0));
			AddNamedArgument(named, typeofMarshalAs, "SizeParamIndex", module.universe.System_Int16, fm.SizeParamIndex ?? 0);
			AddNamedArgument(named, typeofMarshalAs, "SizeConst", module.universe.System_Int32, fm.SizeConst ?? 0);
			AddNamedArgument(named, typeofMarshalAs, "IidParameterIndex", module.universe.System_Int32, fm.IidParameterIndex ?? 0);
			AddNamedArgument(named, typeofMarshalAs, "SafeArraySubType", typeofVarEnum, (int)(fm.SafeArraySubType ?? 0));
			if (fm.SafeArrayUserDefinedSubType != null)
			{
				AddNamedArgument(named, typeofMarshalAs, "SafeArrayUserDefinedSubType", typeofType, fm.SafeArrayUserDefinedSubType);
			}
			if (fm.MarshalType != null)
			{
				AddNamedArgument(named, typeofMarshalAs, "MarshalType", module.universe.System_String, fm.MarshalType);
			}
			if (fm.MarshalTypeRef != null)
			{
				AddNamedArgument(named, typeofMarshalAs, "MarshalTypeRef", module.universe.System_Type, fm.MarshalTypeRef);
			}
			if (fm.MarshalCookie != null)
			{
				AddNamedArgument(named, typeofMarshalAs, "MarshalCookie", module.universe.System_String, fm.MarshalCookie);
			}
			ConstructorInfo constructor = typeofMarshalAs.GetPseudoCustomAttributeConstructor(typeofUnmanagedType);
			return new CustomAttributeData(module, constructor, new object[] { (int)fm.UnmanagedType }, named);
		}
		// 3) Pre-resolved Custom Attribute
		internal CustomAttributeData(Assembly asm, ConstructorInfo constructor, ByteReader br)
		{
			this.module = asm.ManifestModule;
			this.customAttributeIndex = -1;
			this.declSecurityIndex = -1;
			this.lazyConstructor = constructor;
			if (br.Length == 0)
			{
				// it's legal to have an empty blob
				lazyConstructorArguments = Empty<CustomAttributeTypedArgument>.Array;
				lazyNamedArguments = Empty<CustomAttributeNamedArgument>.Array;
			}
			else
			{
				if (br.ReadUInt16() != 1)
				{
					throw new BadImageFormatException();
				}
				lazyConstructorArguments = ReadConstructorArguments(module, br, constructor);
				lazyNamedArguments = ReadNamedArguments(module, br, br.ReadUInt16(), constructor.DeclaringType, true);
			}
		}
Example #33
0
		private static void ResolvedMissingMember(Module requestingModule, MemberInfo member)
		{
			if (requestingModule != null && member is Type)
			{
				IssueMessage(Message.UnableToResolveType, requestingModule.Name, ((Type)member).FullName, member.Module.FullyQualifiedName);
			}
		}
		internal static void ReadDeclarativeSecurity(Module module, int index, List<CustomAttributeData> list)
		{
			Universe u = module.universe;
			Assembly asm = module.Assembly;
			int action = module.DeclSecurity.records[index].Action;
			ByteReader br = module.GetBlob(module.DeclSecurity.records[index].PermissionSet);
			if (br.PeekByte() == '.')
			{
				br.ReadByte();
				int count = br.ReadCompressedUInt();
				for (int j = 0; j < count; j++)
				{
					Type type = ReadType(module, br);
					ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor(u.System_Security_Permissions_SecurityAction);
					// LAMESPEC there is an additional length here (probably of the named argument list)
					byte[] blob = br.ReadBytes(br.ReadCompressedUInt());
					list.Add(new CustomAttributeData(asm, constructor, action, blob, index));
				}
			}
			else
			{
				// .NET 1.x format (xml)
				char[] buf = new char[br.Length / 2];
				for (int i = 0; i < buf.Length; i++)
				{
					buf[i] = br.ReadChar();
				}
				string xml = new String(buf);
				ConstructorInfo constructor = u.System_Security_Permissions_PermissionSetAttribute.GetPseudoCustomAttributeConstructor(u.System_Security_Permissions_SecurityAction);
				List<CustomAttributeNamedArgument> args = new List<CustomAttributeNamedArgument>();
				args.Add(new CustomAttributeNamedArgument(GetProperty(null, u.System_Security_Permissions_PermissionSetAttribute, "XML", u.System_String),
					new CustomAttributeTypedArgument(u.System_String, xml)));
				list.Add(new CustomAttributeData(asm.ManifestModule, constructor, new object[] { action }, args));
			}
		}
Example #35
0
		internal MissingType(Module module, Type declaringType, string ns, string name)
		{
			this.module = module;
			this.declaringType = declaringType;
			this.ns = ns;
			this.name = name;
			MarkEnumOrValueType(ns, name);

			// HACK we need to handle the Windows Runtime projected types that change from ValueType to Class or v.v.
			if (WindowsRuntimeProjection.IsProjectedValueType(ns, name, module))
			{
				typeFlags |= TypeFlags.ValueType;
			}
			else if (WindowsRuntimeProjection.IsProjectedReferenceType(ns, name, module))
			{
				typeFlags |= TypeFlags.NotValueType;
			}
		}
		// 5) Unresolved declarative security
		internal CustomAttributeData(Assembly asm, ConstructorInfo constructor, int securityAction, byte[] blob, int index)
		{
			this.module = asm.ManifestModule;
			this.customAttributeIndex = -1;
			this.declSecurityIndex = index;
			Universe u = constructor.Module.universe;
			this.lazyConstructor = constructor;
			List<CustomAttributeTypedArgument> list = new List<CustomAttributeTypedArgument>();
			list.Add(new CustomAttributeTypedArgument(u.System_Security_Permissions_SecurityAction, securityAction));
			this.lazyConstructorArguments =  list.AsReadOnly();
			this.declSecurityBlob = blob;
		}
		private static void WriteType(Module module, ByteBuffer bb, Type type)
		{
			WriteString(bb, type.Assembly == module.Assembly ? type.FullName : type.AssemblyQualifiedName);
		}
		private static Type ReadFieldOrPropType(Module context, ByteReader br)
		{
			Universe u = context.universe;
			switch (br.ReadByte())
			{
				case Signature.ELEMENT_TYPE_BOOLEAN:
					return u.System_Boolean;
				case Signature.ELEMENT_TYPE_CHAR:
					return u.System_Char;
				case Signature.ELEMENT_TYPE_I1:
					return u.System_SByte;
				case Signature.ELEMENT_TYPE_U1:
					return u.System_Byte;
				case Signature.ELEMENT_TYPE_I2:
					return u.System_Int16;
				case Signature.ELEMENT_TYPE_U2:
					return u.System_UInt16;
				case Signature.ELEMENT_TYPE_I4:
					return u.System_Int32;
				case Signature.ELEMENT_TYPE_U4:
					return u.System_UInt32;
				case Signature.ELEMENT_TYPE_I8:
					return u.System_Int64;
				case Signature.ELEMENT_TYPE_U8:
					return u.System_UInt64;
				case Signature.ELEMENT_TYPE_R4:
					return u.System_Single;
				case Signature.ELEMENT_TYPE_R8:
					return u.System_Double;
				case Signature.ELEMENT_TYPE_STRING:
					return u.System_String;
				case Signature.ELEMENT_TYPE_SZARRAY:
					return ReadFieldOrPropType(context, br).MakeArrayType();
				case 0x55:
					return ReadType(context, br);
				case 0x50:
					return u.System_Type;
				case 0x51:
					return u.System_Object;
				default:
					throw new BadImageFormatException();
			}
		}
Example #39
0
		internal BuiltinArrayMethod(Module module, Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
			: base(module, arrayClass, methodName, callingConvention, returnType, parameterTypes)
		{
		}
Example #40
0
 public static IList <CustomAttributeData> GetCustomAttributes(Module module)
 {
     return(module.GetCustomAttributesData(null));
 }