Ejemplo n.º 1
0
        private void ReadGenericInstanceSignature(BinaryReader reader, IGenericParametersProvider provider, GenericInstanceType type)
        {
            uint number = ReadCompressedUInt32(reader);

            //provider.GenericParameters = new GenericParameter[number];
            type.GenericArguments = new TypeReference[number];

            for (int i = 0; i < number; i++)
                type.GenericArguments[i] = ReadTypeReference(reader,(ElementType)reader.ReadByte(), provider);
        }
Ejemplo n.º 2
0
		private IEnumerable<string> GenericsFrom(IGenericArgumentsProvider genericArgumentsProvider, IGenericParametersProvider genericParametersProvider)
		{
			if (genericArgumentsProvider != null)
				return FormatTypes(genericArgumentsProvider.GenericArguments);

			if (genericParametersProvider != null)
				return genericParametersProvider.GenericParameters.Select(p => p.Name);

			return null;
		}
Ejemplo n.º 3
0
        internal TypeReference ReadTypeReference(BinaryReader reader, ElementType type, IGenericParametersProvider provider)
        {
            switch (type)
            {
                case ElementType.Void:
                    return netheader.TypeSystem.Void;
                case ElementType.I:
                    return netheader.TypeSystem.IntPtr;
                case ElementType.I1:
                    return netheader.TypeSystem.Int8;
                case ElementType.I2:
                    return netheader.TypeSystem.Int16;
                case ElementType.I4:
                    return netheader.TypeSystem.Int32;
                case ElementType.I8:
                    return netheader.TypeSystem.Int64;
                case ElementType.U:
                    return netheader.TypeSystem.UIntPtr;
                case ElementType.U1:
                    return netheader.TypeSystem.UInt8;
                case ElementType.U2:
                    return netheader.TypeSystem.UInt16;
                case ElementType.U4:
                    return netheader.TypeSystem.UInt32;
                case ElementType.U8:
                    return netheader.TypeSystem.UInt64;
                case ElementType.Object:
                    return netheader.TypeSystem.Object;
                case ElementType.R4:
                    return netheader.TypeSystem.Single;
                case ElementType.R8:
                    return netheader.TypeSystem.Double;
                case ElementType.String:
                    return netheader.TypeSystem.String;
                case ElementType.Char:
                    return netheader.TypeSystem.Char;
                case ElementType.Type:
                    return netheader.TypeSystem.Type;
                case ElementType.Boolean:
                    return netheader.TypeSystem.Boolean;
                case ElementType.Ptr:
                    return new PointerType(ReadTypeReference(reader,(ElementType)reader.ReadByte(), provider));
                case ElementType.MVar:
                    uint token = ReadCompressedUInt32(reader);
                    if (provider != null && provider.GenericParameters != null && provider.GenericParameters.Length > token)
                        return provider.GenericParameters[token];
                    else
                        return new GenericParamReference((int)token, new TypeReference() { name = "MVar", elementType = ElementType.MVar, @namespace = "", netheader = this.netheader });

                case ElementType.Var:
                    token =ReadCompressedUInt32(reader);
                    if (provider != null && provider is MemberReference)
                    {
                        var member = provider as MemberReference;
                        if (member.DeclaringType is IGenericParametersProvider)
                        {
                            var genericprovider = (IGenericParametersProvider)member.DeclaringType;
                            if (genericprovider.GenericParameters != null)
                                return genericprovider.GenericParameters[token];
                        }
                    }
                    return new GenericParamReference((int)token, new TypeReference() { name = "Var", elementType = ElementType.Var, @namespace = "", netheader = this.netheader });

                    break;
                case ElementType.Array:

                    return ReadArrayType(reader);

                case ElementType.SzArray:
                    return new ArrayType(ReadTypeReference(reader,(ElementType)reader.ReadByte(), provider));
                case ElementType.Class:
                    return (TypeReference)netheader.TablesHeap.tablereader.TypeDefOrRef.GetMember((int)ReadCompressedUInt32(reader));
                case ElementType.ValueType:
                    TypeReference typeRef = (TypeReference)netheader.TablesHeap.tablereader.TypeDefOrRef.GetMember((int)ReadCompressedUInt32(reader));
                    typeRef.IsValueType = true;
                    return typeRef;
                case ElementType.ByRef:
                    return new ByReferenceType(ReadTypeReference(reader, (ElementType)reader.ReadByte(), provider));
                case ElementType.Pinned:
                    return new PinnedType(ReadTypeReference(reader, (ElementType)reader.ReadByte(), provider));
                case ElementType.GenericInst:
                    bool flag = reader.ReadByte() == 0x11;
                    TypeReference reference2 = ReadTypeToken(reader);
                    GenericInstanceType instance = new GenericInstanceType(reference2);
                     this.ReadGenericInstanceSignature(reader,reference2, instance);
                    if (flag)
                    {
                        instance.IsValueType = true;

                    }
                    return instance;
            }
            return new TypeReference() { name = type.ToString(), @namespace = "" , netheader = this.netheader};
        }
Ejemplo n.º 4
0
        public TypeReference ReadTypeSignature(uint signature, IGenericParametersProvider provider)
        {
            this.provider = provider;
            TypeReference typeRef = null;
            using (BinaryReader reader = GetBlobReader(signature))
            {
                typeRef=  ReadTypeReference(reader, (ElementType)ReadCompressedUInt32(reader), this.provider);
            }

            return typeRef;
        }
Ejemplo n.º 5
0
        public IMemberSignature ReadMemberRefSignature(uint sig, IGenericParametersProvider provider)
        {
            IMemberSignature signature = null;
            using (BinaryReader reader = GetBlobReader(sig))
            {

                byte flag = reader.ReadByte();

                if (flag == 0x6)
                {
                    FieldSignature fieldsignature = new FieldSignature();
                    fieldsignature.ReturnType = ReadTypeReference(reader, (ElementType)reader.ReadByte(), null);
                    signature = fieldsignature;
                }
                else
                {
                    MethodSignature methodsignature = new MethodSignature();

                    if ((flag & 0x20) != 0)
                    {
                        methodsignature.HasThis = true;
                        flag = (byte)(flag & -33);
                    }
                    if ((flag & 0x40) != 0)
                    {
                        methodsignature.ExplicitThis = true;
                        flag = (byte)(flag & -65);
                    }
                    if ((flag & 0x10) != 0)
                    {
                        uint genericsig = ReadCompressedUInt32(reader);
                    }
                    methodsignature.CallingConvention = (MethodCallingConvention)flag;

                    //if ((flag & 0x10) != 0x0)
                    //{
                    //    uint num2 = ReadCompressedUInt32();
                    //
                    //    List<GenericParameter> generics = new List<GenericParameter>();
                    //    for (int i = 0; i < num2; i++)
                    //    {
                    //    }
                    //
                    //}

                    uint num3 = ReadCompressedUInt32(reader);
                    methodsignature.ReturnType = ReadTypeReference(reader, (ElementType)ReadCompressedUInt32(reader), provider);//ReadTypeSignature((uint)stream.Position);
                    if (num3 != 0)
                    {
                        ParameterReference[] parameters = new ParameterReference[num3];
                        for (int i = 0; i < num3; i++)
                        {
                            parameters[i] = new ParameterReference() { ParameterType = ReadTypeReference(reader, (ElementType)ReadCompressedUInt32(reader), provider) };
                        }
                        methodsignature.Parameters = parameters;
                    }
                    signature = methodsignature;

                }
            }
            return signature;
        }
Ejemplo n.º 6
0
        public TypeReference[] ReadGenericParametersSignature(uint signature, IGenericParametersProvider provider)
        {
            List<TypeReference> types = new List<TypeReference>();
            using (BinaryReader reader = GetBlobReader(signature))
            {

                this.provider = provider;
                if (reader.ReadByte() == 0xa)
                {
                    uint count = ReadCompressedUInt32(reader);
                    for (int i = 0; i < count; i++)
                        types.Add(ReadTypeReference(reader,(ElementType)reader.ReadByte(), provider));
                }
                this.provider = null;
            }
            return types.ToArray();
        }
Ejemplo n.º 7
0
        private IEnumerable <string> GenericsFrom(IGenericArgumentsProvider genericArgumentsProvider, IGenericParametersProvider genericParametersProvider)
        {
            if (genericArgumentsProvider != null)
            {
                return(FormatTypes(genericArgumentsProvider.GenericArguments));
            }

            if (genericParametersProvider != null)
            {
                return(genericParametersProvider.GenericParameters.Select(p => p.Name));
            }

            return(null);
        }