internal static void GetMarshalAs(ConstArray nativeType, out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string safeArrayUserDefinedSubType, out UnmanagedType arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie, out int iidParamIndex)
 {
     int num;
     int num2;
     int num3;
     _GetMarshalAs(nativeType.Signature, nativeType.Length, out num, out num2, out safeArrayUserDefinedSubType, out num3, out sizeParamIndex, out sizeConst, out marshalType, out marshalCookie, out iidParamIndex);
     unmanagedType = (UnmanagedType) num;
     safeArraySubType = (VarEnum) num2;
     arraySubType = (UnmanagedType) num3;
 }
 internal static void ParseAttributeArguments(ConstArray attributeBlob, ref CustomAttributeCtorParameter[] customAttributeCtorParameters, ref CustomAttributeNamedParameter[] customAttributeNamedParameters, RuntimeModule customAttributeModule)
 {
     if (customAttributeModule == null)
     {
         throw new ArgumentNullException("customAttributeModule");
     }
     if ((customAttributeCtorParameters.Length != 0) || (customAttributeNamedParameters.Length != 0))
     {
         ParseAttributeArguments(attributeBlob.Signature, attributeBlob.Length, ref customAttributeCtorParameters, ref customAttributeNamedParameters, (RuntimeAssembly) customAttributeModule.Assembly);
     }
 }
 internal static unsafe void ParseAttributeArguments(ConstArray attributeBlob, ref CustomAttributeCtorParameter[] customAttributeCtorParameters, ref CustomAttributeNamedParameter[] customAttributeNamedParameters, Module customAttributeModule)
 {
     if (customAttributeModule == null)
     {
         throw new ArgumentNullException("customAttributeModule");
     }
     if (customAttributeNamedParameters == null)
     {
         customAttributeNamedParameters = new CustomAttributeNamedParameter[0];
     }
     CustomAttributeCtorParameter[] parameterArray = customAttributeCtorParameters;
     CustomAttributeNamedParameter[] customAttributeTypedArgument = customAttributeNamedParameters;
     ParseAttributeArguments(attributeBlob.Signature, attributeBlob.Length, ref parameterArray, ref customAttributeTypedArgument, (IntPtr) customAttributeModule.Assembly.AssemblyHandle.Value);
     customAttributeCtorParameters = parameterArray;
     customAttributeNamedParameters = customAttributeTypedArgument;
 }
 public ConstArray GetFieldMarshal(int fieldToken)
 {
     ConstArray fieldMarshal = new ConstArray();
     _GetFieldMarshal(this.m_metadataImport2, out MetadataArgs.Skip, fieldToken, ref fieldMarshal);
     return fieldMarshal;
 }
 private static extern void _GetMemberRefProps(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int memberTokenRef, out ConstArray signature);
 private static extern void _GetSignatureFromToken(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int methodToken, ref ConstArray signature);
Exemple #7
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static void ParseAttributeArguments(ConstArray attributeBlob, 
            ref CustomAttributeCtorParameter[] customAttributeCtorParameters,
            ref CustomAttributeNamedParameter[] customAttributeNamedParameters,
            RuntimeModule customAttributeModule)
        {
            if (customAttributeModule == null)
                throw new ArgumentNullException("customAttributeModule");
            Contract.EndContractBlock();

            Contract.Assert(customAttributeCtorParameters != null);
            Contract.Assert(customAttributeNamedParameters != null);

            if (customAttributeCtorParameters.Length != 0 || customAttributeNamedParameters.Length != 0)
            {
                unsafe
                {
                    ParseAttributeArguments(
                        attributeBlob.Signature,
                        (int)attributeBlob.Length,
                        ref customAttributeCtorParameters,
                        ref customAttributeNamedParameters,
                        (RuntimeAssembly)customAttributeModule.Assembly);
                }
            }
        }
 private static extern void _GetCustomAttributeProps(IntPtr scope, 
     int customAttributeToken, 
     out int constructorToken, 
     out ConstArray signature);
 private static extern void _GetSignatureFromToken(IntPtr scope, 
     int methodToken, 
     ref ConstArray signature);
Exemple #10
0
 private static extern void _GetSignatureFromToken(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int methodToken, ref ConstArray signature);
Exemple #11
0
        public unsafe void GetPropertyProps(int mdToken, out void *name, out PropertyAttributes propertyAttributes, out ConstArray signature)
        {
            int   num;
            void *voidPtr;

            _GetPropertyProps(this.m_metadataImport2, out MetadataArgs.Skip, mdToken, &voidPtr, out num, out signature);
            name = voidPtr;
            propertyAttributes = (PropertyAttributes)num;
        }
Exemple #12
0
 private static extern unsafe void _GetPropertyProps(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int mdToken, void **name, out int propertyAttributes, out ConstArray signature);
        private static unsafe bool FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, ref Assembly lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, bool mustBeInheritable, object[] attributes, IList derivedAttributes, out RuntimeType attributeType, out IRuntimeMethodInfo ctor, out bool ctorHasParameters, out bool isVarArg)
        {
            ctor              = null;
            attributeType     = null;
            ctorHasParameters = false;
            isVarArg          = false;
            IntPtr ptr1 = (IntPtr)(((void *)caRecord.blob.Signature) + caRecord.blob.Length);

            attributeType = decoratedModule.ResolveType(scope.GetParentToken((int)caRecord.tkCtor), null, null) as RuntimeType;
            if (!attributeFilterType.IsAssignableFrom(attributeType))
            {
                return(false);
            }
            if (!AttributeUsageCheck(attributeType, mustBeInheritable, attributes, derivedAttributes))
            {
                return(false);
            }
            RuntimeAssembly targetAssembly = (RuntimeAssembly)attributeType.Assembly;
            RuntimeAssembly assembly       = (RuntimeAssembly)decoratedModule.Assembly;

            if ((targetAssembly != lastAptcaOkAssembly) && !RuntimeAssembly.AptcaCheck(targetAssembly, assembly))
            {
                return(false);
            }
            lastAptcaOkAssembly = assembly;
            ConstArray methodSignature = scope.GetMethodSignature(caRecord.tkCtor);

            isVarArg          = (methodSignature[0] & 5) != 0;
            ctorHasParameters = methodSignature[1] != 0;
            if (ctorHasParameters)
            {
                ctor = ModuleHandle.ResolveMethodHandleInternal(decoratedModule.GetNativeHandle(), (int)caRecord.tkCtor);
            }
            else
            {
                ctor = attributeType.GetTypeHandleInternal().GetDefaultConstructor();
                if ((ctor == null) && !attributeType.IsValueType)
                {
                    throw new MissingMethodException(".ctor");
                }
            }
            if (ctor == null)
            {
                if (!attributeType.IsVisible && !attributeType.TypeHandle.IsVisibleFromModule(decoratedModule))
                {
                    return(false);
                }
                return(true);
            }
            if (RuntimeMethodHandle.IsVisibleFromModule(ctor, decoratedModule))
            {
                return(true);
            }
            MetadataToken token = new MetadataToken();

            if (decoratedToken.IsParamDef)
            {
                token = new MetadataToken(scope.GetParentToken((int)decoratedToken));
                token = new MetadataToken(scope.GetParentToken((int)token));
            }
            else if ((decoratedToken.IsMethodDef || decoratedToken.IsProperty) || (decoratedToken.IsEvent || decoratedToken.IsFieldDef))
            {
                token = new MetadataToken(scope.GetParentToken((int)decoratedToken));
            }
            else if (decoratedToken.IsTypeDef)
            {
                token = decoratedToken;
            }
            return(token.IsTypeDef && RuntimeMethodHandle.IsVisibleFromType(ctor, decoratedModule.ModuleHandle.ResolveTypeHandle((int)token)));
        }
        public unsafe void GetPropertyProps(int mdToken, out void *name, out PropertyAttributes propertyAttributes, out ConstArray signature)
        {
            void *ptr;
            int   num;

            MetadataImport._GetPropertyProps(this.m_metadataImport2, mdToken, &ptr, out num, out signature);
            name = ptr;
            propertyAttributes = (PropertyAttributes)num;
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal static void GetMarshalAs(ConstArray nativeType, 
            out UnmanagedType unmanagedType, out VarEnum safeArraySubType, out string safeArrayUserDefinedSubType, 
            out UnmanagedType arraySubType, out int sizeParamIndex, out int sizeConst, out string marshalType, out string marshalCookie,
            out int iidParamIndex)
        {
            int _unmanagedType, _safeArraySubType, _arraySubType;

            _GetMarshalAs(nativeType.Signature, (int)nativeType.Length,
                out _unmanagedType, out _safeArraySubType, out safeArrayUserDefinedSubType, 
                out _arraySubType, out sizeParamIndex, out sizeConst, out marshalType, out marshalCookie,
                out iidParamIndex);
            unmanagedType = (UnmanagedType)_unmanagedType;
            safeArraySubType = (VarEnum)_safeArraySubType;
            arraySubType = (UnmanagedType)_arraySubType;
        }
 [System.Security.SecurityCritical]  // auto-generated
 public unsafe void GetPropertyProps(int mdToken, out void* name, out PropertyAttributes propertyAttributes, out ConstArray signature) 
 { 
     int _propertyAttributes; 
     void* _name;
     _GetPropertyProps(m_metadataImport2, mdToken, &_name, out _propertyAttributes, out signature); 
     name = _name;
     propertyAttributes = (PropertyAttributes)_propertyAttributes;
 }
Exemple #17
0
 private static extern void _GetMemberRefProps(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int memberTokenRef, out ConstArray signature);
 private static extern void _GetMemberRefProps(IntPtr scope, 
     int memberTokenRef, 
     out ConstArray signature);
Exemple #19
0
 private static extern void _GetCustomAttributeProps(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int customAttributeToken, out int constructorToken, out ConstArray signature);
 private static extern void _GetFieldMarshal(IntPtr scope, 
     int fieldToken, 
     ref ConstArray fieldMarshal);
Exemple #21
0
 public void GetCustomAttributeProps(int customAttributeToken, out int constructorToken, out ConstArray signature)
 {
     _GetCustomAttributeProps(this.m_metadataImport2, out MetadataArgs.Skip, customAttributeToken, out constructorToken, out signature);
 }
Exemple #22
0
        public override MemberInfo?ResolveMember(
            int metadataToken,
            Type[]?genericTypeArguments,
            Type[]?genericMethodArguments
            )
        {
            MetadataToken tk = new MetadataToken(metadataToken);

            if (tk.IsProperty)
            {
                throw new ArgumentException(SR.InvalidOperation_PropertyInfoNotAvailable);
            }

            if (tk.IsEvent)
            {
                throw new ArgumentException(SR.InvalidOperation_EventInfoNotAvailable);
            }

            if (tk.IsMethodSpec || tk.IsMethodDef)
            {
                return(ResolveMethod(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsFieldDef)
            {
                return(ResolveField(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsTypeRef || tk.IsTypeDef || tk.IsTypeSpec)
            {
                return(ResolveType(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsMemberRef)
            {
                if (!MetadataImport.IsValidToken(tk))
                {
                    throw new ArgumentOutOfRangeException(
                              nameof(metadataToken),
                              SR.Format(SR.Argument_InvalidToken, tk, this)
                              );
                }

                ConstArray sig = MetadataImport.GetMemberRefProps(tk);
                unsafe
                {
                    if (*(MdSigCallingConvention *)sig.Signature == MdSigCallingConvention.Field)
                    {
                        return(ResolveField(tk, genericTypeArguments, genericMethodArguments));
                    }
                    else
                    {
                        return(ResolveMethod(tk, genericTypeArguments, genericMethodArguments));
                    }
                }
            }

            throw new ArgumentException(
                      SR.Format(SR.Argument_ResolveMember, tk, this),
                      nameof(metadataToken)
                      );
        }
Exemple #23
0
 private static extern void _GetFieldMarshal(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int fieldToken, ref ConstArray fieldMarshal);
Exemple #24
0
 public ConstArray GetSignatureFromToken(int token)
 {
     ConstArray signature = new ConstArray();
     _GetSignatureFromToken(this.m_metadataImport2, out MetadataArgs.Skip, token, ref signature);
     return signature;
 }
Exemple #25
0
        public override FieldInfo?ResolveField(int metadataToken, Type[]?genericTypeArguments, Type[]?genericMethodArguments)
        {
            try
            {
                MetadataToken tk = new MetadataToken(metadataToken);

                if (!MetadataImport.IsValidToken(tk))
                {
                    throw new ArgumentOutOfRangeException(nameof(metadataToken),
                                                          SR.Format(SR.Argument_InvalidToken, tk, this));
                }

                RuntimeTypeHandle[]? typeArgs   = null;
                RuntimeTypeHandle[]? methodArgs = null;
                if (genericTypeArguments?.Length > 0)
                {
                    typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
                }
                if (genericMethodArguments?.Length > 0)
                {
                    methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
                }

                ModuleHandle moduleHandle = new ModuleHandle(this);
                if (!tk.IsFieldDef)
                {
                    if (!tk.IsMemberRef)
                    {
                        throw new ArgumentException(SR.Format(SR.Argument_ResolveField, tk, this),
                                                    nameof(metadataToken));
                    }

                    unsafe
                    {
                        ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                        if (*(MdSigCallingConvention *)sig.Signature != MdSigCallingConvention.Field)
                        {
                            throw new ArgumentException(SR.Format(SR.Argument_ResolveField, tk, this),
                                                        nameof(metadataToken));
                        }
                    }
                }

                IRuntimeFieldInfo fieldHandle = moduleHandle.ResolveFieldHandle(metadataToken, typeArgs, methodArgs).GetRuntimeFieldInfo();

                RuntimeType declaringType = RuntimeFieldHandle.GetApproxDeclaringType(fieldHandle.Value);

                if (declaringType.IsGenericType || declaringType.IsArray)
                {
                    int tkDeclaringType = ModuleHandle.GetMetadataImport(this).GetParentToken(metadataToken);
                    declaringType = (RuntimeType)ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
                }

                return(RuntimeType.GetFieldInfo(declaringType, fieldHandle));
            }
            catch (MissingFieldException)
            {
                return(ResolveLiteralField(metadataToken, genericTypeArguments, genericMethodArguments));
            }
            catch (BadImageFormatException e)
            {
                throw new ArgumentException(SR.Argument_BadImageFormatExceptionResolve, e);
            }
        }
Exemple #26
0
 private static extern void _GetCustomAttributeProps(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int customAttributeToken, out int constructorToken, out ConstArray signature);
        internal static void ParseAttributeArguments(ConstArray attributeBlob, 
            ref CustomAttributeCtorParameter[] customAttributeCtorParameters,
            ref CustomAttributeNamedParameter[] customAttributeNamedParameters,
            Module customAttributeModule)
        {
            if (customAttributeModule == null)
                throw new ArgumentNullException("customAttributeModule");

            if (customAttributeNamedParameters == null)
                customAttributeNamedParameters = new CustomAttributeNamedParameter[0];

            CustomAttributeCtorParameter[] _customAttributeCtorParameters = customAttributeCtorParameters;
            CustomAttributeNamedParameter[] _customAttributeNamedParameters = customAttributeNamedParameters;

            unsafe 
            {
                ParseAttributeArguments(
                    attributeBlob.Signature, 
                    (int)attributeBlob.Length, 
                    ref _customAttributeCtorParameters, 
                    ref _customAttributeNamedParameters,
                    (IntPtr)customAttributeModule.Assembly.AssemblyHandle.Value);
            }

            customAttributeCtorParameters = _customAttributeCtorParameters;
            customAttributeNamedParameters = _customAttributeNamedParameters;
        }
Exemple #28
0
 private static extern void _GetFieldMarshal(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int fieldToken, ref ConstArray fieldMarshal);
Exemple #29
0
 private static extern void _GetSignatureFromToken(
     IntPtr scope,
     int methodToken,
     ref ConstArray signature
     );
Exemple #30
0
 private static extern void _GetMemberRefProps(
     IntPtr scope,
     int memberTokenRef,
     out ConstArray signature
     );
Exemple #31
0
 private static extern void _GetCustomAttributeProps(
     IntPtr scope,
     int customAttributeToken,
     out int constructorToken,
     out ConstArray signature
     );
 private unsafe static extern void _GetPropertyProps(IntPtr scope, 
     int mdToken, void** name, out int propertyAttributes, out ConstArray signature);
Exemple #33
0
 private static extern void _GetFieldMarshal(
     IntPtr scope,
     int fieldToken,
     ref ConstArray fieldMarshal
     );
        [System.Security.SecurityCritical]  // auto-generated
        public ConstArray GetSigOfMethodDef(int methodToken)
        {
            ConstArray signature = new ConstArray();

            _GetSigOfMethodDef(m_metadataImport2, methodToken, ref signature);

            return signature;
        }
Exemple #35
0
 private static extern unsafe void _GetPropertyProps(IntPtr scope,
                                                     int mdToken, void **name, out int propertyAttributes, out ConstArray signature);
        [System.Security.SecurityCritical]  // auto-generated
        public ConstArray GetSignatureFromToken(int token)
        {
            ConstArray signature = new ConstArray();

            _GetSignatureFromToken(m_metadataImport2, token, ref signature);

            return signature;
        }
Exemple #37
0
        public unsafe void GetPropertyProps(int mdToken, out void *name, out PropertyAttributes propertyAttributes, out ConstArray signature)
        {
            int   _propertyAttributes;
            void *_name;

            _GetPropertyProps(m_metadataImport2, mdToken, &_name, out _propertyAttributes, out signature);
            name = _name;
            propertyAttributes = (PropertyAttributes)_propertyAttributes;
        }
        [System.Security.SecurityCritical]  // auto-generated
        public ConstArray GetMemberRefProps(int memberTokenRef)
        {
            ConstArray signature = new ConstArray();
            
            _GetMemberRefProps(m_metadataImport2, memberTokenRef, out signature);

            return signature;
        }
Exemple #39
0
 private static extern unsafe void _GetPropertyProps(IntPtr scope, out MetadataArgs.SkipAddresses skipAddresses, int mdToken, void** name, out int propertyAttributes, out ConstArray signature);
 [System.Security.SecurityCritical]  // auto-generated
 public void GetCustomAttributeProps( 
     int customAttributeToken, 
     out int constructorToken, 
     out ConstArray signature)
 {
     _GetCustomAttributeProps(m_metadataImport2, customAttributeToken, 
         out constructorToken, out signature);
 }
Exemple #41
0
 public unsafe void GetPropertyProps(int mdToken, out void* name, out PropertyAttributes propertyAttributes, out ConstArray signature)
 {
     int num;
     void* voidPtr;
     _GetPropertyProps(this.m_metadataImport2, out MetadataArgs.Skip, mdToken, &voidPtr, out num, out signature);
     name = voidPtr;
     propertyAttributes = (PropertyAttributes) num;
 }
        [System.Security.SecurityCritical]  // auto-generated
        public ConstArray GetFieldMarshal(int fieldToken)
        {
            ConstArray fieldMarshal = new ConstArray();

            _GetFieldMarshal(m_metadataImport2, fieldToken, ref fieldMarshal);

            return fieldMarshal;
        }
Exemple #43
0
 public ConstArray GetSigOfMethodDef(int methodToken)
 {
     ConstArray signature = new ConstArray();
     _GetSigOfMethodDef(this.m_metadataImport2, out MetadataArgs.Skip, methodToken, ref signature);
     return signature;
 }
Exemple #44
0
 [System.Security.SecurityCritical]  // auto-generated
 private static void ParseAttributeUsageAttribute(
     ConstArray ca, out AttributeTargets targets, out bool inherited, out bool allowMultiple)
 {
     int _targets;
     _ParseAttributeUsageAttribute(ca.Signature, ca.Length, out _targets, out inherited, out allowMultiple);
     targets = (AttributeTargets)_targets;
 }
Exemple #45
0
        public override MethodBase?ResolveMethod(
            int metadataToken,
            Type[]?genericTypeArguments,
            Type[]?genericMethodArguments
            )
        {
            try
            {
                MetadataToken tk = new MetadataToken(metadataToken);
                if (!tk.IsMethodDef && !tk.IsMethodSpec)
                {
                    if (!tk.IsMemberRef)
                    {
                        throw new ArgumentException(
                                  SR.Format(SR.Argument_ResolveMethod, tk, this),
                                  nameof(metadataToken)
                                  );
                    }
                    unsafe
                    {
                        ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                        if (*(MdSigCallingConvention *)sig.Signature == MdSigCallingConvention.Field)
                        {
                            throw new ArgumentException(
                                      SR.Format(SR.Argument_ResolveMethod, tk, this),
                                      nameof(metadataToken)
                                      );
                        }
                    }
                }

                RuntimeTypeHandle[]? typeArgs   = null;
                RuntimeTypeHandle[]? methodArgs = null;
                if (genericTypeArguments?.Length > 0)
                {
                    typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
                }
                if (genericMethodArguments?.Length > 0)
                {
                    methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
                }

                ModuleHandle       moduleHandle = new ModuleHandle(this);
                IRuntimeMethodInfo methodHandle = moduleHandle
                                                  .ResolveMethodHandle(tk, typeArgs, methodArgs)
                                                  .GetMethodInfo();

                Type declaringType = RuntimeMethodHandle.GetDeclaringType(methodHandle);

                if (declaringType.IsGenericType || declaringType.IsArray)
                {
                    MetadataToken tkDeclaringType = new MetadataToken(
                        MetadataImport.GetParentToken(tk)
                        );

                    if (tk.IsMethodSpec)
                    {
                        tkDeclaringType = new MetadataToken(
                            MetadataImport.GetParentToken(tkDeclaringType)
                            );
                    }

                    declaringType = ResolveType(
                        tkDeclaringType,
                        genericTypeArguments,
                        genericMethodArguments
                        );
                }

                return(RuntimeType.GetMethodBase(declaringType as RuntimeType, methodHandle));
            }
            catch (BadImageFormatException e)
            {
                throw new ArgumentException(SR.Argument_BadImageFormatExceptionResolve, e);
            }
        }