示例#1
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));
        }
示例#2
0
        /// <summary>
        /// FieldSignature signature is indexed by the Field.Signature column
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override void ParseSignature(SignatureReader reader)
        {
            if (Field != reader.ReadByte())
            {
                throw new InvalidOperationException(@"Invalid method definition signature.");
            }

            base.ParseSignature(reader);
        }
示例#3
0
        /// <summary>
        /// FieldSignature signature is indexed by the Field.Signature column
        /// </summary>
        /// <param name="reader">The reader.</param>
        protected override void ParseSignature(SignatureReader reader)
        {
            if (Field != reader.ReadByte())
            {
                throw new InvalidOperationException(@"Invalid method definition signature.");
            }

            base.ParseSignature(reader);
        }
        /// <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);
        }
        /// <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);
            }
        }
示例#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 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);
                }
            }
        }
示例#9
0
        /// <summary>
        /// Parses the type signature.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        public static SigType ParseTypeSignature(SignatureReader reader)
        {
            CilElementType type = (CilElementType)reader.ReadByte();

            switch (type)
            {
            case CilElementType.Void:
                return(BuiltInSigType.Void);

            case CilElementType.Boolean:
                return(BuiltInSigType.Boolean);

            case CilElementType.Char:
                return(BuiltInSigType.Char);

            case CilElementType.I1:
                return(BuiltInSigType.SByte);

            case CilElementType.U1:
                return(BuiltInSigType.Byte);

            case CilElementType.I2:
                return(BuiltInSigType.Int16);

            case CilElementType.U2:
                return(BuiltInSigType.UInt16);

            case CilElementType.I4:
                return(BuiltInSigType.Int32);

            case CilElementType.U4:
                return(BuiltInSigType.UInt32);

            case CilElementType.I8:
                return(BuiltInSigType.Int64);

            case CilElementType.U8:
                return(BuiltInSigType.UInt64);

            case CilElementType.R4:
                return(BuiltInSigType.Single);

            case CilElementType.R8:
                return(BuiltInSigType.Double);

            case CilElementType.String:
                return(BuiltInSigType.String);

            case CilElementType.Object:
                return(BuiltInSigType.Object);

            case CilElementType.I:
                return(BuiltInSigType.IntPtr);

            case CilElementType.U:
                return(BuiltInSigType.UIntPtr);

            case CilElementType.TypedByRef:
                return(BuiltInSigType.TypedByRef);

            case CilElementType.Array:
                return(ParseArraySignature(reader));

            case CilElementType.Class:
                return(ParseClassSignature(reader));

            case CilElementType.FunctionPtr:
                return(ParseFunctionPointer(reader));

            case CilElementType.GenericInst:
                return(ParseGenericInstance(reader));

            case CilElementType.MVar:
                return(ParseMVar(reader));

            case CilElementType.Ptr:
                return(ParsePointer(reader));

            case CilElementType.SZArray:
                return(ParseSZArraySignature(reader));

            case CilElementType.ValueType:
                return(ParseValueType(reader));

            case CilElementType.Var:
                return(ParseVar(reader));

            case CilElementType.ByRef:
                return(ParseReference(reader));

            default:
                throw new NotSupportedException(@"Unsupported CIL element type: " + type);
            }
        }
示例#10
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);
        }
示例#11
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);
        }
示例#12
0
 /// <summary>
 /// Parses the type signature.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <returns></returns>
 public static SigType ParseTypeSignature(SignatureReader reader)
 {
     CilElementType type = (CilElementType)reader.ReadByte();
     switch (type)
     {
         case CilElementType.Void: return BuiltInSigType.Void;
         case CilElementType.Boolean: return BuiltInSigType.Boolean;
         case CilElementType.Char: return BuiltInSigType.Char;
         case CilElementType.I1: return BuiltInSigType.SByte;
         case CilElementType.U1: return BuiltInSigType.Byte;
         case CilElementType.I2: return BuiltInSigType.Int16;
         case CilElementType.U2: return BuiltInSigType.UInt16;
         case CilElementType.I4: return BuiltInSigType.Int32;
         case CilElementType.U4: return BuiltInSigType.UInt32;
         case CilElementType.I8: return BuiltInSigType.Int64;
         case CilElementType.U8: return BuiltInSigType.UInt64;
         case CilElementType.R4: return BuiltInSigType.Single;
         case CilElementType.R8: return BuiltInSigType.Double;
         case CilElementType.String: return BuiltInSigType.String;
         case CilElementType.Object: return BuiltInSigType.Object;
         case CilElementType.I: return BuiltInSigType.IntPtr;
         case CilElementType.U: return BuiltInSigType.UIntPtr;
         case CilElementType.TypedByRef: return BuiltInSigType.TypedByRef;
         case CilElementType.Array: return ParseArraySignature(reader);
         case CilElementType.Class: return ParseClassSignature(reader);
         case CilElementType.FunctionPtr: return ParseFunctionPointer(reader);
         case CilElementType.GenericInst: return ParseGenericInstance(reader);
         case CilElementType.MVar: return ParseMVar(reader);
         case CilElementType.Ptr: return ParsePointer(reader);
         case CilElementType.SZArray: return ParseSZArraySignature(reader);
         case CilElementType.ValueType: return ParseValueType(reader);
         case CilElementType.Var: return ParseVar(reader);
         case CilElementType.ByRef: return ParseReference(reader);
         default: throw new NotSupportedException(@"Unsupported CIL element type: " + type);
     }
 }