예제 #1
0
 public void UpdateMethodHeaderInfo(DumpedMethod dm, MethodBodyHeader mbHeader)
 {
     dm.mhFlags          = mbHeader.flags;
     dm.mhMaxStack       = mbHeader.maxStack;
     dm.mhCodeSize       = dm.code == null ? 0 : (uint)dm.code.Length;
     dm.mhLocalVarSigTok = mbHeader.localVarSigTok;
 }
예제 #2
0
        static MethodBodyHeader ParseMethodBody2(IBinaryReader reader, out byte[] code, out byte[] extraSections)
        {
            var mbHeader = new MethodBodyHeader();

            uint codeOffset;
            byte b = Peek(reader);

            if ((b & 3) == 2)
            {
                mbHeader.flags          = 2;
                mbHeader.maxStack       = 8;
                mbHeader.codeSize       = (uint)(reader.ReadByte() >> 2);
                mbHeader.localVarSigTok = 0;
                codeOffset = 1;
            }
            else if ((b & 7) == 3)
            {
                mbHeader.flags = reader.ReadUInt16();
                codeOffset     = (uint)(4 * (mbHeader.flags >> 12));
                if (codeOffset != 12)
                {
                    throw new InvalidMethodBody();
                }
                mbHeader.maxStack = reader.ReadUInt16();
                mbHeader.codeSize = reader.ReadUInt32();
                if (mbHeader.codeSize > int.MaxValue)
                {
                    throw new InvalidMethodBody();
                }
                mbHeader.localVarSigTok = reader.ReadUInt32();
                if (mbHeader.localVarSigTok != 0 && (mbHeader.localVarSigTok >> 24) != 0x11)
                {
                    throw new InvalidMethodBody();
                }
            }
            else
            {
                throw new InvalidMethodBody();
            }

            if (mbHeader.codeSize + codeOffset > reader.Length)
            {
                throw new InvalidMethodBody();
            }
            code = reader.ReadBytes((int)mbHeader.codeSize);

            if ((mbHeader.flags & 8) != 0)
            {
                extraSections = ReadExtraSections2(reader);
            }
            else
            {
                extraSections = null;
            }

            return(mbHeader);
        }
예제 #3
0
        static MethodBodyHeader parseMethodBody2(BinaryReader reader, out byte[] code, out byte[] extraSections)
        {
            var mbHeader = new MethodBodyHeader();

            uint codeOffset;

            switch (peek(reader) & 3)
            {
            case 2:
                mbHeader.flags          = 2;
                mbHeader.maxStack       = 8;
                mbHeader.codeSize       = (uint)(reader.ReadByte() >> 2);
                mbHeader.localVarSigTok = 0;
                codeOffset = 1;
                break;

            case 3:
                mbHeader.flags = reader.ReadUInt16();
                codeOffset     = (uint)(4 * (mbHeader.flags >> 12));
                if (codeOffset != 12)
                {
                    throw new InvalidMethodBody();
                }
                mbHeader.maxStack = reader.ReadUInt16();
                mbHeader.codeSize = reader.ReadUInt32();
                if (mbHeader.codeSize > int.MaxValue)
                {
                    throw new InvalidMethodBody();
                }
                mbHeader.localVarSigTok = reader.ReadUInt32();
                if (mbHeader.localVarSigTok != 0 && (mbHeader.localVarSigTok >> 24) != 0x11)
                {
                    throw new InvalidMethodBody();
                }
                break;

            default:
                throw new InvalidMethodBody();
            }

            if (mbHeader.codeSize + codeOffset > reader.BaseStream.Length)
            {
                throw new InvalidMethodBody();
            }
            code = reader.ReadBytes((int)mbHeader.codeSize);

            if ((mbHeader.flags & 8) != 0)
            {
                extraSections = readExtraSections2(reader);
            }
            else
            {
                extraSections = null;
            }

            return(mbHeader);
        }
예제 #4
0
		static MethodBodyHeader ParseMethodBody2(IBinaryReader reader, out byte[] code, out byte[] extraSections) {
			var mbHeader = new MethodBodyHeader();

			uint codeOffset;
			byte b = Peek(reader);
			if ((b & 3) == 2) {
				mbHeader.flags = 2;
				mbHeader.maxStack = 8;
				mbHeader.codeSize = (uint)(reader.ReadByte() >> 2);
				mbHeader.localVarSigTok = 0;
				codeOffset = 1;
			}
			else if ((b & 7) == 3) {
				mbHeader.flags = reader.ReadUInt16();
				codeOffset = (uint)(4 * (mbHeader.flags >> 12));
				if (codeOffset != 12)
					throw new InvalidMethodBody();
				mbHeader.maxStack = reader.ReadUInt16();
				mbHeader.codeSize = reader.ReadUInt32();
				if (mbHeader.codeSize > int.MaxValue)
					throw new InvalidMethodBody();
				mbHeader.localVarSigTok = reader.ReadUInt32();
				if (mbHeader.localVarSigTok != 0 && (mbHeader.localVarSigTok >> 24) != 0x11)
					throw new InvalidMethodBody();
			}
			else
				throw new InvalidMethodBody();

			if (mbHeader.codeSize + codeOffset > reader.Length)
				throw new InvalidMethodBody();
			code = reader.ReadBytes((int)mbHeader.codeSize);

			if ((mbHeader.flags & 8) != 0)
				extraSections = ReadExtraSections2(reader);
			else
				extraSections = null;

			return mbHeader;
		}
예제 #5
0
        static MethodBodyHeader parseMethodBody2(BinaryReader reader, out byte[] code, out byte[] extraSections)
        {
            var mbHeader = new MethodBodyHeader();

            uint codeOffset;
            switch (peek(reader) & 3) {
            case 2:
                mbHeader.flags = 2;
                mbHeader.maxStack = 8;
                mbHeader.codeSize = (uint)(reader.ReadByte() >> 2);
                mbHeader.localVarSigTok = 0;
                codeOffset = 1;
                break;

            case 3:
                mbHeader.flags = reader.ReadUInt16();
                codeOffset = (uint)(4 * (mbHeader.flags >> 12));
                if (codeOffset != 12)
                    throw new InvalidMethodBody();
                mbHeader.maxStack = reader.ReadUInt16();
                mbHeader.codeSize = reader.ReadUInt32();
                if (mbHeader.codeSize > int.MaxValue)
                    throw new InvalidMethodBody();
                mbHeader.localVarSigTok = reader.ReadUInt32();
                if (mbHeader.localVarSigTok != 0 && (mbHeader.localVarSigTok >> 24) != 0x11)
                    throw new InvalidMethodBody();
                break;

            default:
                throw new InvalidMethodBody();
            }

            if (mbHeader.codeSize + codeOffset > reader.BaseStream.Length)
                throw new InvalidMethodBody();
            code = reader.ReadBytes((int)mbHeader.codeSize);

            if ((mbHeader.flags & 8) != 0)
                extraSections = readExtraSections2(reader);
            else
                extraSections = null;

            return mbHeader;
        }
예제 #6
0
		public void UpdateMethodHeaderInfo(DumpedMethod dm, MethodBodyHeader mbHeader) {
			dm.mhFlags = mbHeader.flags;
			dm.mhMaxStack = mbHeader.maxStack;
			dm.mhCodeSize = dm.code == null ? 0 : (uint)dm.code.Length;
			dm.mhLocalVarSigTok = mbHeader.localVarSigTok;
		}