예제 #1
0
		internal CustomAttributeData(ConstructorInfo constructor, object[] args, List<CustomAttributeNamedArgument> namedArguments)
		{
			this.lazyConstructor = constructor;
			MethodSignature sig = constructor.MethodSignature;
			List<CustomAttributeTypedArgument> list = new List<CustomAttributeTypedArgument>();
			for (int i = 0; i < args.Length; i++)
			{
				list.Add(new CustomAttributeTypedArgument(sig.GetParameterType(i), args[i]));
			}
			lazyConstructorArguments = list.AsReadOnly();
			if (namedArguments == null)
			{
				this.lazyNamedArguments = Empty<CustomAttributeNamedArgument>.Array;
			}
			else
			{
				this.lazyNamedArguments = namedArguments.AsReadOnly();
			}
		}
예제 #2
0
		internal CustomAttributeData(Assembly asm, ConstructorInfo constructor, ByteReader br)
		{
			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(asm, br, constructor);
				lazyNamedArguments = ReadNamedArguments(asm, br, br.ReadUInt16(), constructor.DeclaringType);
			}
		}
예제 #3
0
        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));
            }
        }
예제 #4
0
		private CustomAttributeData(ConstructorInfo constructor, int securityAction, IList<CustomAttributeNamedArgument> namedArguments)
		{
			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.lazyNamedArguments = namedArguments;
		}
		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();
		}
예제 #6
0
 void ReadConstructorArguments(StringBuilder sb, ByteReader br, ConstructorInfo constructor, int level)
 {
     bool first = true;
     foreach (var parameter in constructor.GetParameters())
     {
         if (!first)
         {
             AppendNewLine(sb, level);
         }
         first = false;
         ReadFixedArg(sb, br, parameter.ParameterType);
     }
 }
예제 #7
0
 static void Process(ConstructorInfo ctorInfo)
 {
     foreach (var attr in ctorInfo.__GetCustomAttributes (TypeManager.AttributeType, false))
         if (attr.AttributeType.FullName == "Mono.Embedding.ThunkAttribute")
             Process(ctorInfo, TypeManager.VoidType, attr);
 }
		// 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 ConstructorInfo GetSerializationConstructor()
			{
				if (baseSerializationCtor == null)
				{
					baseSerializationCtor = Serialization.AddAutomagicSerializationToWorkaroundBaseClass(typeBuilder, wrapper.BaseTypeWrapper.GetSerializationConstructor());
				}
				return baseSerializationCtor;
			}
예제 #10
0
        private static void LoadAll()
        {
            // Types
            function  = Load(typeof(TotemFunction));
            value     = Load(typeof(TotemValue));
            tstring   = Load(typeof(TotemString));
            arguments = Load(typeof(TotemArguments));
            parameter = Load(typeof(TotemParameter));
            @bool     = Load(typeof(TotemBool));
            map       = Load(typeof(TotemMap));
            array     = Load(typeof(TotemArray));
            scope     = Load(typeof(TotemFunction.ScopeWrapper));

            arr_parameters = Load(typeof(TotemParameter[]));
            sys_bool       = Load(typeof(bool));

            // Methods
            value_val = Load(typeof(TotemValue)).GetProperty("ByTotemValue").GetGetMethod();

            function_run       = Load(typeof(TotemFunction)).GetMethod("TotemRun", r.BindingFlags.NonPublic | r.BindingFlags.Instance);
            execute            = Load(typeof(TotemValue)).GetMethod("Execute");
            function_ctor      = Load(typeof(TotemFunction)).GetConstructor(r.BindingFlags.NonPublic | r.BindingFlags.Instance, null, new IKType[] { Load(typeof(TotemScope)), Load(typeof(string)), Load(typeof(TotemParameter[])) }, null);
            function_local_set = Load(typeof(TotemFunction)).GetMethod("LocalSet", r.BindingFlags.NonPublic | r.BindingFlags.Instance);
            function_local_get = Load(typeof(TotemFunction)).GetMethod("LocalGet", r.BindingFlags.NonPublic | r.BindingFlags.Instance);
            function_local_dec = Load(typeof(TotemFunction)).GetMethod("LocalDec", r.BindingFlags.NonPublic | r.BindingFlags.Instance);
            function_env       = Load(typeof(TotemFunction)).GetProperty("Scope", r.BindingFlags.NonPublic | r.BindingFlags.Instance).GetGetMethod(true);

            arguments_ctor = Load(typeof(TotemArguments)).GetConstructor(IKType.EmptyTypes);
            arguments_add  = Load(typeof(TotemArguments)).GetMethod("Add", r.BindingFlags.Public | r.BindingFlags.Instance | r.BindingFlags.DeclaredOnly);

            number_ctor_long = Load(typeof(TotemNumber)).GetConstructor(new IKType[] { Load(typeof(long)) });

            string_ctor = Load(typeof(TotemString)).GetConstructor(new IKType[] { Load(typeof(string)) });

            parameter_ctor = Load(typeof(TotemParameter)).GetConstructor(new IKType[] { Load(typeof(string)), Load(typeof(TotemValue)) });

            undefined = Load(typeof(TotemValue)).GetProperty("Undefined").GetGetMethod();
            @null     = Load(typeof(TotemValue)).GetProperty("Null").GetGetMethod();

            value_add        = Load(typeof(TotemValue)).GetMethod("op_Addition", r.BindingFlags.Static | r.BindingFlags.Public);
            value_sub        = Load(typeof(TotemValue)).GetMethod("op_Subtraction", r.BindingFlags.Static | r.BindingFlags.Public);
            value_mul        = Load(typeof(TotemValue)).GetMethod("op_Multiply", r.BindingFlags.Static | r.BindingFlags.Public);
            value_div        = Load(typeof(TotemValue)).GetMethod("op_Division", r.BindingFlags.Static | r.BindingFlags.Public);
            value_eq         = Load(typeof(TotemValue)).GetMethod("op_Equality", r.BindingFlags.Static | r.BindingFlags.Public);
            value_neq        = Load(typeof(TotemValue)).GetMethod("op_Inequality", r.BindingFlags.Static | r.BindingFlags.Public);
            value_lt         = Load(typeof(TotemValue)).GetMethod("op_LessThan", r.BindingFlags.Static | r.BindingFlags.Public);
            value_gt         = Load(typeof(TotemValue)).GetMethod("op_GreaterThan", r.BindingFlags.Static | r.BindingFlags.Public);
            value_lte        = Load(typeof(TotemValue)).GetMethod("op_LessThanOrEqual", r.BindingFlags.Static | r.BindingFlags.Public);
            value_gte        = Load(typeof(TotemValue)).GetMethod("op_GreaterThanOrEqual", r.BindingFlags.Static | r.BindingFlags.Public);
            value_incr       = Load(typeof(TotemValue)).GetMethod("op_Increment", r.BindingFlags.Static | r.BindingFlags.Public);
            value_decr       = Load(typeof(TotemValue)).GetMethod("op_Decrement", r.BindingFlags.Static | r.BindingFlags.Public);
            value_istrue     = Load(typeof(TotemValue)).GetMethod("op_Explicit", r.BindingFlags.Static | r.BindingFlags.Public, null, r.CallingConventions.Standard, new IKType[] { Load(typeof(TotemValue)) }, null);
            value_lookup_get = Load(typeof(TotemValue)).GetProperty("Item", value, new IKType[] { value }).GetGetMethod();
            value_lookup_set = Load(typeof(TotemValue)).GetProperty("Item", value, new IKType[] { value }).GetSetMethod();

            scope_ctor = Load(typeof(TotemFunction.ScopeWrapper)).GetConstructor(new IKType[] { Load(typeof(TotemFunction)) });

            dispose = Load(typeof(IDisposable)).GetMethod("Dispose");

            get_prop = Load(typeof(TotemValue)).GetMethod("GetProp");
            set_prop = Load(typeof(TotemValue)).GetMethod("SetProp");

            bool_ctor = Load(typeof(TotemBool)).GetConstructor(new IKType[] { Load(typeof(bool)) });

            map_ctor = map.GetConstructor(IKType.EmptyTypes);
            map_add  = map.GetMethod("AddItem");

            array_ctor = array.GetConstructor(IKType.EmptyTypes);
            array_add  = array.GetMethod("AddItem");
        }
예제 #11
0
		internal static void ReadDeclarativeSecurity(Assembly asm, List<CustomAttributeData> list, int action, ByteReader br)
		{
			Universe u = asm.universe;
			if (br.PeekByte() == '.')
			{
				br.ReadByte();
				int count = br.ReadCompressedInt();
				for (int j = 0; j < count; j++)
				{
					Type type = ReadType(asm, br);
					ConstructorInfo constructor;
					if (type == u.System_Security_Permissions_HostProtectionAttribute && action == (int)System.Security.Permissions.SecurityAction.LinkDemand)
					{
						constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
					}
					else
					{
						constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { u.System_Security_Permissions_SecurityAction }, null);
					}
					// LAMESPEC there is an additional length here (probably of the named argument list)
					ByteReader slice = br.Slice(br.ReadCompressedInt());
					// LAMESPEC the count of named arguments is a compressed integer (instead of UInt16 as NumNamed in custom attributes)
					list.Add(new CustomAttributeData(constructor, action, ReadNamedArguments(asm, slice, slice.ReadCompressedInt(), type)));
				}
			}
			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.GetConstructor(new Type[] { u.System_Security_Permissions_SecurityAction });
				List<CustomAttributeNamedArgument> args = new List<CustomAttributeNamedArgument>();
				args.Add(new CustomAttributeNamedArgument(u.System_Security_Permissions_PermissionSetAttribute.GetProperty("XML"),
					new CustomAttributeTypedArgument(u.System_String, xml)));
				list.Add(new CustomAttributeData(constructor, action, args));
			}
		}
예제 #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));
        }
예제 #13
0
        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());
        }
예제 #14
0
			internal ParameterInfoWrapper(ConstructorInfo ctor, ParameterInfo forward)
			{
				this.ctor = ctor;
				this.forward = forward;
			}
예제 #15
0
        IUnresolvedMethod ReadConstructor(ConstructorInfo method, IUnresolvedTypeDefinition parentType, EntityType methodType, IUnresolvedMember accessorOwner)
        {
            if (method == null)
                return null;
            var m = new DefaultUnresolvedMethod(parentType, method.Name);
            m.EntityType = methodType;
            m.AccessorOwner = accessorOwner;
            m.HasBody = method.GetMethodBody () != null;
            var genericArguments = method.GetGenericArguments ();
            if (genericArguments != null) {
                for (int i = 0; i < genericArguments.Length; i++) {
                    if (genericArguments[i].GenericParameterPosition != i)
                        throw new InvalidOperationException("g.Position != i");
                    m.TypeParameters.Add(new DefaultUnresolvedTypeParameter(
                        EntityType.Method, i, genericArguments[i].Name));
                }
                for (int i = 0; i < genericArguments.Length; i++) {
                    var tp = (DefaultUnresolvedTypeParameter)m.TypeParameters[i];
                    AddConstraints(tp, genericArguments[i]);
                    tp.ApplyInterningProvider(interningProvider);
                }
            }
            m.ReturnType = KnownTypeReference.Void;

            if (HasAnyAttributes(method))
                AddAttributes(method, m.Attributes, m.ReturnTypeAttributes);
            TranslateModifiers(method, m);

            foreach (var p in method.GetParameters ()) {
                m.Parameters.Add(ReadParameter(p));
            }

            FinishReadMember(m, method);
            return m;
        }
		// 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)
		{
		}
예제 #17
0
 public IUnresolvedMethod ReadConstructor(ConstructorInfo method, IUnresolvedTypeDefinition parentType, EntityType methodType = EntityType.Method)
 {
     return ReadConstructor(method, parentType, methodType, null);
 }
		// 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;
		}
예제 #19
0
        static bool HasAnyAttributes(ConstructorInfo methodDefinition)
        {
            if (methodDefinition.Attributes.HasFlag (MethodAttributes.PinvokeImpl))
                return true;

            if (methodDefinition.MethodImplementationFlags.HasFlag (MethodImplAttributes.CodeTypeMask))
                return true;
            return methodDefinition.CustomAttributes.Any ();
        }
예제 #20
0
 bool DecodeCABlob(StringBuilder sb, ConstructorInfo constructor, byte[] blob, int level)
 {
     try
     {
         // CustomAttribute
         var br = new ByteReader(blob, 2, blob.Length - 4);
         ReadConstructorArguments(sb, br, constructor, level);
         br = new ByteReader(blob, blob.Length - (br.Length + 2), br.Length + 2);
         int named = br.ReadUInt16();
         if (constructor.GetParameters().Length != 0 && named != 0)
         {
             AppendNewLine(sb, level);
         }
         ReadNamedArguments(sb, br, named, level, false);
         return true;
     }
     catch (IKVM.Reflection.BadImageFormatException) { }
     catch (ArgumentOutOfRangeException) { }
     return false;
 }
예제 #21
0
        void AddAttributes(ConstructorInfo methodDefinition, IList<IUnresolvedAttribute> attributes, IList<IUnresolvedAttribute> returnTypeAttributes)
        {
            var implAttributes = methodDefinition.MethodImplementationFlags;

            #region PreserveSigAttribute
            if (implAttributes == MethodImplAttributes.PreserveSig) {
                attributes.Add(preserveSigAttribute);
                implAttributes = 0;
            }
            #endregion

            #region MethodImplAttribute
            if (implAttributes != MethodImplAttributes.IL) {
                var methodImpl = new DefaultUnresolvedAttribute(methodImplAttributeTypeRef, new[] { methodImplOptionsTypeRef });
                methodImpl.PositionalArguments.Add(CreateSimpleConstantValue(methodImplOptionsTypeRef, (int)implAttributes));
                attributes.Add(interningProvider.Intern(methodImpl));
            }
            #endregion

            AddCustomAttributes(methodDefinition.CustomAttributes, attributes);

            if (methodDefinition.Attributes.HasFlag (MethodAttributes.HasSecurity)) {
                AddSecurityAttributes(CustomAttributeData.__GetDeclarativeSecurity (methodDefinition), attributes);
            }
        }
		internal ConstructorInfoWithReflectedType(Type reflectedType, ConstructorInfo ctor)
		{
			Debug.Assert(reflectedType != ctor.DeclaringType);
			this.reflectedType = reflectedType;
			this.ctor = ctor;
		}
예제 #23
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)
 {
 }