Пример #1
0
        public Method(CLRMetaDataParser parser)
        {
            m_offsetToInstruction = new Dictionary<uint, uint>();
            m_instructionToOffset = new List<uint>();

            byte headByte = parser.ReadU8();
            uint codeSize;
            bool haveSections;

            int format = (headByte & 0x3);
            if (format == CorILMethod_TinyFormat)
            {
                // Tiny format (II.25.4.2)
                codeSize = ((uint)headByte >> 2);

                MaxStack = 8;
                haveSections = false;
            }
            else if (format == CorILMethod_FatFormat)
            {
                // Fat format (II.25.4.3)
                byte highByte = parser.ReadU8();
                uint flagsAndSize = ((uint)headByte | ((uint)highByte << 8));

                uint headerSizeInDWords = (flagsAndSize >> 12) & 0xf;

                if (headerSizeInDWords != 3)
                    throw new ParseFailedException("Unsupported method format");
                MaxStack = parser.ReadU16();
                codeSize = parser.ReadU32();
                CLRStandAloneSigRow localSig = (CLRStandAloneSigRow)parser.ReadFatToken();
                if (localSig != null)
                    LocalVarSig = new CLRSigLocalVarSig(new CLRSignatureParser(localSig.Signature, parser.Tables));

                haveSections = ((flagsAndSize & CorILMethod_MoreSects) != 0);
            }
            else
                throw new ParseFailedException("Invalid IL method format");

            ParseCode(parser, codeSize);

            List<MethodDataSection> sections = new List<MethodDataSection>();
            while (haveSections)
            {
                parser.Align(4);
                sections.Add(MethodDataSection.Parse(parser, m_offsetToInstruction, out haveSections));
            }
            Sections = sections.ToArray();
        }