Пример #1
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected sealed override void ParseSignature(SignatureReader reader)
        {
            byte value = reader.ReadByte();

            // Check for instance signature
            if (HAS_THIS == (value & HAS_THIS))
            {
                HasThis = true;
            }

            if (HAS_EXPLICIT_THIS == (value & HAS_EXPLICIT_THIS))
            {
                HasExplicitThis = true;
            }

            if (GENERIC == (value & GENERIC))
            {
                MethodCallingConvention = MethodCallingConvention.Generic;
                GenericParameterCount   = reader.ReadCompressedInt32();
            }
            else if (VARARG == (value & VARARG))
            {
                MethodCallingConvention = MethodCallingConvention.VarArg;
            }
            else if (C == (value & C))
            {
            }
            else if (STDCALL == (value & STDCALL))
            {
            }
            else if (THISCALL == (value & THISCALL))
            {
            }
            else if (FASTCALL == (value & FASTCALL))
            {
            }
            else if ((value & 0x1F) != 0x00)
            {
                throw new InvalidOperationException(@"Invalid method definition signature.");
            }

            // Number of parameters
            int paramCount = reader.ReadCompressedInt32();

            Parameters = new SigType[paramCount];

            // Read the return type
            ReturnType = SigType.ParseTypeSignature(reader);

            // Read all parameters
            for (int i = 0; i < paramCount; i++)
            {
                Parameters[i] = SigType.ParseTypeSignature(reader);
            }
        }
Пример #2
0
        /// <summary>
        /// Parses the generic instance.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseGenericInstance(SignatureReader reader)
        {
            TypeSigType    originalType;
            CilElementType type = (CilElementType)reader.ReadByte();

            switch (type)
            {
            case CilElementType.Class:
                originalType = ParseClassSignature(reader);
                break;

            case CilElementType.ValueType:
                originalType = ParseValueType(reader);
                break;

            default:
                throw new InvalidOperationException(@"Invalid signature type.");
            }

            int genArgCount = reader.ReadCompressedInt32();

            SigType[] genArgs = new SigType[genArgCount];
            for (int i = 0; i < genArgCount; i++)
            {
                genArgs[i] = ParseTypeSignature(reader);
            }

            return(new GenericInstSigType(originalType, genArgs));
        }
Пример #3
0
        /// <summary>
        /// Parses the MVar.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseMVar(SignatureReader reader)
        {
            int methodVariableIndex = reader.ReadCompressedInt32();

            return(new MVarSigType(methodVariableIndex));
            //return context.GetGenericMethodArgument(methodVariableIndex);
        }
Пример #4
0
        /// <summary>
        /// Parses the var.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseVar(SignatureReader reader)
        {
            int typeVariableIndex = reader.ReadCompressedInt32();

            return(new VarSigType(typeVariableIndex));
            //return context.GetGenericTypeArgument(typeVariableIndex);
        }
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override void ParseSignature(SignatureReader reader)
        {
            if (reader.ReadByte() != 0x0A)
                throw new InvalidOperationException(@"Invalid signature.");

            int genArgCount = reader.ReadCompressedInt32();
            types = new SigType[genArgCount];
            for (int i = 0; i < genArgCount; i++)
                types[i] = SigType.ParseTypeSignature(reader);
        }
Пример #6
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override void ParseSignature(SignatureReader reader)
        {
            if (reader.ReadByte() != 0x0A)
            {
                throw new InvalidOperationException(@"Invalid signature.");
            }

            int genArgCount = reader.ReadCompressedInt32();

            Types = new SigType[genArgCount];
            for (int i = 0; i < genArgCount; i++)
            {
                Types[i] = SigType.ParseTypeSignature(reader);
            }
        }
Пример #7
0
        /// <summary>
        /// Parses the array signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseArraySignature(SignatureReader reader)
        {
            SigType elementType = ParseTypeSignature(reader);
            int     rank, count;

            int[] sizes, lowerBounds;

            rank  = reader.ReadCompressedInt32();
            count = reader.ReadCompressedInt32();
            sizes = new int[count];
            for (int i = 0; i < count; i++)
            {
                sizes[i] = reader.ReadCompressedInt32();
            }

            count       = reader.ReadCompressedInt32();
            lowerBounds = new int[count];
            for (int i = 0; i < count; i++)
            {
                lowerBounds[i] = reader.ReadCompressedInt32();
            }

            return(new ArraySigType(elementType, rank, sizes, lowerBounds));
        }
Пример #8
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override void ParseSignature(SignatureReader reader)
        {
            // Check signature identifier
            if (reader.ReadByte() != 0x07)
            {
                throw new ArgumentException("Token doesn't represent a local variable signature.", "token");
            }

            // Retrieve the number of locals
            int count = reader.ReadCompressedInt32();

            if (count != 0)
            {
                Locals = new VariableSignature[count];
                for (int i = 0; i < count; i++)
                {
                    Locals[i] = new VariableSignature(reader);
                }
            }
        }
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override void ParseSignature(SignatureReader reader)
        {
            // Check signature identifier
            if (reader.ReadByte() != 0x07)
                throw new ArgumentException(@"Token doesn't represent a local variable signature.", @"token");

            // Retrieve the number of locals
            int count = reader.ReadCompressedInt32();
            if (count != 0)
            {
                this.locals = new VariableSignature[count];
                for (int i = 0; i < count; i++)
                {
                    locals[i] = new VariableSignature(reader);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Parses the MVar.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseMVar(SignatureReader reader)
        {
            int methodVariableIndex = reader.ReadCompressedInt32();

            return(new MVarSigType(methodVariableIndex));
        }
Пример #11
0
        /// <summary>
        /// Parses the var.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseVar(SignatureReader reader)
        {
            int typeVariableIndex = reader.ReadCompressedInt32();

            return(new VarSigType(typeVariableIndex));
        }
Пример #12
0
        /// <summary>
        /// Parses the signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override sealed void ParseSignature(SignatureReader reader)
        {
            byte value = reader.ReadByte();

            // Check for instance signature
            if (HAS_THIS == (value & HAS_THIS))
            {
                hasThis = true;
            }

            if (HAS_EXPLICIT_THIS == (value & HAS_EXPLICIT_THIS))
            {
                hasExplicitThis = true;
            }

            if (GENERIC == (value & GENERIC))
            {
                callingConvention = CallingConvention.Generic;
                genericParameterCount = reader.ReadCompressedInt32();
            }
            else if (VARARG == (value & VARARG))
            {
                callingConvention = CallingConvention.Vararg;
            }
            else if ((value & 0x1F) != 0x00)
            {
                throw new InvalidOperationException(@"Invalid method definition signature.");
            }

            // Number of parameters
            int paramCount = reader.ReadCompressedInt32();
            parameters = new SigType[paramCount];

            // Read the return type
            returnType = SigType.ParseTypeSignature(reader);

            // Read all parameters
            for (int i = 0; i < paramCount; i++)
                parameters[i] = SigType.ParseTypeSignature(reader);
        }
Пример #13
0
 /// <summary>
 /// Parses the var.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns></returns>
 private static SigType ParseVar(SignatureReader reader)
 {
     int typeVariableIndex = reader.ReadCompressedInt32();
     return new VarSigType(typeVariableIndex);
 }
Пример #14
0
 /// <summary>
 /// Parses the MVar.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns></returns>
 private static SigType ParseMVar(SignatureReader reader)
 {
     int methodVariableIndex = reader.ReadCompressedInt32();
     return new MVarSigType(methodVariableIndex);
 }
Пример #15
0
        /// <summary>
        /// Parses the generic instance.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseGenericInstance(SignatureReader reader)
        {
            TypeSigType originalType;
            CilElementType type = (CilElementType)reader.ReadByte();
            switch (type)
            {
                case CilElementType.Class:
                    originalType = ParseClassSignature(reader);
                    break;

                case CilElementType.ValueType:
                    originalType = ParseValueType(reader);
                    break;

                default:
                    throw new InvalidOperationException(@"Invalid signature type.");
            }

            int genArgCount = reader.ReadCompressedInt32();
            SigType[] genArgs = new SigType[genArgCount];
            for (int i = 0; i < genArgCount; i++)
            {
                genArgs[i] = ParseTypeSignature(reader);
            }

            return new GenericInstSigType(originalType, genArgs);
        }
Пример #16
0
        /// <summary>
        /// Parses the array signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        private static SigType ParseArraySignature(SignatureReader reader)
        {
            SigType elementType = ParseTypeSignature(reader);
            int rank, count;
            int[] sizes, lowerBounds;

            rank = reader.ReadCompressedInt32();
            count = reader.ReadCompressedInt32();
            sizes = new int[count];
            for (int i = 0; i < count; i++)
                sizes[i] = reader.ReadCompressedInt32();

            count = reader.ReadCompressedInt32();
            lowerBounds = new int[count];
            for (int i = 0; i < count; i++)
                lowerBounds[i] = reader.ReadCompressedInt32();

            return new ArraySigType(elementType, rank, sizes, lowerBounds);
        }