Beispiel #1
0
        static CorMethodInfo ReadMethodInfo(IMetaDataImport mdi, uint token, CorType type)
        {
            if (mdi == null)
            {
                return(null);
            }

            var name = MDAPI.GetMethodName(mdi, token);

            if (name == null)
            {
                return(null);
            }

            if (!MDAPI.GetMethodAttributes(mdi, token, out var attrs, out var implAttrs))
            {
                return(null);
            }

            var sig = GetMethodSignature(mdi, token);

            if (sig == null)
            {
                return(null);
            }

            bool compilerGeneratedAttribute = GetCompilerGeneratedAttribute(mdi, token);

            return(new CorMethodInfo(type, token, name, sig, attrs, implAttrs, compilerGeneratedAttribute));
        }
Beispiel #2
0
        public static uint GetGlobalStaticConstructor(IMetaDataImport mdi)
        {
            var mdTokens = MDAPI.GetMethodTokens(mdi, 0x02000001);

            foreach (uint mdToken in mdTokens)
            {
                string name = MDAPI.GetMethodName(mdi, mdToken);
                if (name != ".cctor")
                {
                    continue;
                }
                if (!MDAPI.GetMethodAttributes(mdi, mdToken, out var attrs, out var implAttrs))
                {
                    continue;
                }
                if ((attrs & MethodAttributes.RTSpecialName) == 0)
                {
                    continue;
                }
                if ((attrs & MethodAttributes.Static) == 0)
                {
                    continue;
                }

                return(mdToken);
            }

            return(0);
        }
Beispiel #3
0
        /// <summary>
        /// Finds all constructors
        /// </summary>
        /// <returns></returns>
        public CorFunction[] FindConstructors()
        {
            var ctors = new List <CorFunction>();
            var mod   = Module;
            var mdi   = mod?.GetMetaDataInterface <IMetaDataImport>();

            foreach (var mdToken in MDAPI.GetMethodTokens(mdi, token))
            {
                MethodAttributes     attrs;
                MethodImplAttributes implAttrs;
                if (!MDAPI.GetMethodAttributes(mdi, mdToken, out attrs, out implAttrs))
                {
                    continue;
                }
                if ((attrs & MethodAttributes.RTSpecialName) == 0)
                {
                    continue;
                }
                if (MDAPI.GetMethodName(mdi, mdToken) != ".ctor")
                {
                    continue;
                }

                var ctor = mod.GetFunctionFromToken(mdToken);
                Debug.Assert(ctor != null);
                if (ctor != null)
                {
                    ctors.Add(ctor);
                }
            }
            return(ctors.ToArray());
        }
Beispiel #4
0
        /// <summary>
        /// Gets method parameters and method flags
        /// </summary>
        /// <param name="methodAttrs">Method attributes</param>
        /// <param name="methodImplAttrs">Method implementation attributes</param>
        /// <returns></returns>
        public MDParameters GetMDParameters(out MethodAttributes methodAttrs, out MethodImplAttributes methodImplAttrs)
        {
            methodAttrs     = 0;
            methodImplAttrs = 0;
            var mod = Module;

            if (mod == null)
            {
                return(null);
            }
            var mdi = mod.GetMetaDataInterface <IMetaDataImport>();

            if (mdi == null)
            {
                return(null);
            }
            if (!MDAPI.GetMethodAttributes(mdi, Token, out methodAttrs, out methodImplAttrs))
            {
                return(null);
            }
            var name = MDAPI.GetMethodName(mdi, Token);

            if (name == null)
            {
                return(null);
            }
            return(MetaDataUtils.GetParameters(mdi, Token));
        }
Beispiel #5
0
        public void GetAttributes(out MethodImplAttributes implAttributes, out MethodAttributes attributes)
        {
            var mod = Module;
            var mdi = mod == null ? null : mod.GetMetaDataInterface <IMetaDataImport>();

            MDAPI.GetMethodAttributes(mdi, Token, out attributes, out implAttributes);
        }
Beispiel #6
0
        public MethodAttributes GetAttributes()
        {
            MethodImplAttributes implAttributes;
            MethodAttributes     attributes;

            MDAPI.GetMethodAttributes(Module?.GetMetaDataInterface <IMetaDataImport>(), Token, out attributes, out implAttributes);
            return(attributes);
        }
Beispiel #7
0
        public MethodAttributes GetAttributes()
        {
            MethodImplAttributes implAttributes;
            MethodAttributes     attributes;
            var mod = Module;
            var mdi = mod == null ? null : mod.GetMetaDataInterface <IMetaDataImport>();

            MDAPI.GetMethodAttributes(mdi, Token, out attributes, out implAttributes);
            return(attributes);
        }
Beispiel #8
0
        void InitNameAndAttributes_NoLock()
        {
            var  mdi   = readerModule.MetaDataImport;
            uint token = OriginalToken.Raw;

            Name = Utils.GetUTF8String(MDAPI.GetUtf8Name(mdi, OriginalToken.Raw), MDAPI.GetMethodName(mdi, token) ?? string.Empty);
            MDAPI.GetMethodAttributes(mdi, token, out var attrs, out var implAttrs);
            Attributes         = attrs;
            ImplAttributes     = implAttrs;
            origAttributes     = attrs;
            origImplAttributes = implAttrs;
        }
Beispiel #9
0
        unsafe static CorPropertyInfo ReadPropertyInfo(IMetaDataImport mdi, uint token, CorType type)
        {
            if (mdi == null)
            {
                return(null);
            }

            var name = MDAPI.GetPropertyName(mdi, token);

            if (name == null)
            {
                return(null);
            }
            if (!MDAPI.GetPropertyGetterSetter(mdi, token, out uint mdGetter, out uint mdSetter))
            {
                return(null);
            }

            var getSig = GetMethodSignature(mdi, mdGetter);
            var setSig = GetMethodSignature(mdi, mdSetter);

            if (getSig == null)
            {
                return(null);
            }
            if (getSig.ParamsAfterSentinel != null)
            {
                return(null);
            }
            if (getSig.GenParamCount != 0)
            {
                return(null);
            }
            if (getSig.Params.Count != 0)
            {
                return(null);
            }
            if (getSig.RetType.RemovePinnedAndModifiers().GetElementType() == ElementType.Void)
            {
                return(null);
            }

            if (setSig != null && setSig.ParamsAfterSentinel != null)
            {
                setSig = null;
            }
            if (setSig != null && setSig.GenParamCount != 0)
            {
                setSig = null;
            }
            if (setSig != null && setSig.Params.Count != 1)
            {
                setSig = null;
            }
            if (setSig != null && setSig.RetType.RemovePinnedAndModifiers().GetElementType() != ElementType.Void)
            {
                setSig = null;
            }

            if (setSig != null && getSig.HasThis != setSig.HasThis)
            {
                setSig = null;
            }
            if (setSig != null && !Equals(getSig.RetType.RemovePinnedAndModifiers(), setSig.Params[0].RemovePinnedAndModifiers()))
            {
                setSig = null;
            }

            if (setSig == null)
            {
                mdSetter = 0;
            }

            if (!MDAPI.GetMethodAttributes(mdi, mdGetter, out var getMethodAttrs, out var getMethodImplAttrs))
            {
                return(null);
            }

            var browseState = GetDebuggerBrowsableState(mdi, token);

            return(new CorPropertyInfo(type, token, mdGetter, mdSetter, name, getSig, setSig, getMethodAttrs, browseState));
        }
Beispiel #10
0
 public void GetAttributes(out MethodImplAttributes implAttributes, out MethodAttributes attributes) =>
 MDAPI.GetMethodAttributes(Module?.GetMetaDataInterface <IMetaDataImport>(), Token, out attributes, out implAttributes);