Ejemplo n.º 1
0
		DmdType ReadType(bool canReturnNull) {
			var name = ReadUTF8String();
			if (canReturnNull && name == null)
				return null;
			var type = DmdTypeNameParser.Parse(module, name ?? string.Empty, genericTypeArguments);
			if ((object)type == null)
				throw new CABlobParserException("Could not parse type");
			return type;
		}
Ejemplo n.º 2
0
        DmdType?ReadType(bool canReturnNull)
        {
            var name = ReadUTF8String();

            if (canReturnNull && name is null)
            {
                return(null);
            }
            var type = DmdTypeNameParser.Parse(module, name ?? string.Empty, genericTypeArguments);

            if (type is null)
            {
                throw new CABlobParserException("Could not parse type");
            }
            return(type);
        }
Ejemplo n.º 3
0
        public override DmdType GetType(string typeName, DmdGetTypeOptions options)
        {
            if (typeName == null)
            {
                throw new ArgumentNullException(nameof(typeName));
            }

            var resolver = new TypeDefResolver(this, (options & DmdGetTypeOptions.IgnoreCase) != 0);
            var type     = DmdTypeNameParser.Parse(resolver, typeName);

            if ((object)type != null)
            {
                return(appDomain.Intern(type, DmdMakeTypeOptions.NoResolve));
            }

            if ((options & DmdGetTypeOptions.ThrowOnError) != 0)
            {
                throw new TypeNotFoundException(typeName);
            }
            return(null);
        }
Ejemplo n.º 4
0
 public static void ParseAssemblyName(string asmFullName, out string?name, out Version?version, out string?cultureName, out DmdAssemblyNameFlags flags, out byte[]?publicKey, out byte[]?publicKeyToken, out DmdAssemblyHashAlgorithm hashAlgorithm)
 {
     if (asmFullName is null)
     {
         throw new ArgumentNullException(nameof(asmFullName));
     }
     try {
         using (var parser = new DmdTypeNameParser((DmdModule?)null, asmFullName, null))
             parser.ReadAssemblyRef(out name, out version, out cultureName, out flags, out publicKey, out publicKeyToken, out hashAlgorithm);
         return;
     }
     catch {
     }
     name           = null;
     version        = null;
     cultureName    = null;
     flags          = 0;
     publicKey      = null;
     publicKeyToken = null;
     hashAlgorithm  = 0;
 }
Ejemplo n.º 5
0
        // Reads the new (.NET 2.0+) DeclSecurity blob format
        DmdCustomAttributeData[] ReadBinaryFormat(SecurityAction action)
        {
            int numAttrs = (int)reader.ReadCompressedUInt32();

            DmdCustomAttributeData[]? res = new DmdCustomAttributeData[numAttrs];

            IList <DmdType>?genericTypeArguments = null;
            int             w = 0;

            for (int i = 0; i < numAttrs; i++)
            {
                var name = ReadUTF8String();
                var type = DmdTypeNameParser.ParseThrow(module, name ?? string.Empty, genericTypeArguments);
                reader.ReadCompressedUInt32();                // int blobLength
                int numNamedArgs = (int)reader.ReadCompressedUInt32();
                var namedArgs    = DmdCustomAttributeReader.ReadNamedArguments(module, reader, type, numNamedArgs, genericTypeArguments);
                if (namedArgs is null)
                {
                    throw new IOException();
                }
                var(ctor, ctorArguments) = GetConstructor(type, action);
                Debug.Assert(!(ctor is null));
                if (ctor is null)
                {
                    continue;
                }
                res[w++] = new DmdCustomAttributeData(ctor, ctorArguments, namedArgs, isPseudoCustomAttribute: false);
            }
            if (res.Length != w)
            {
                if (w == 0)
                {
                    return(Array.Empty <DmdCustomAttributeData>());
                }
                Array.Resize(ref res, w);
            }

            return(res !);
        }
Ejemplo n.º 6
0
        DmdMarshalType Read()
        {
            const int DEFAULT = 0;

            try {
                var           nativeType = (UnmanagedType)reader.ReadByte();
                UnmanagedType nt;
                int           size;
                switch (nativeType)
                {
                case UnmanagedType.ByValTStr:
                    size = CanRead ? (int)reader.ReadCompressedUInt32() : DEFAULT;
                    return(DmdMarshalType.CreateFixedSysString(size));

                case UnmanagedType.SafeArray:
                    var vt      = CanRead ? (VarEnum)reader.ReadCompressedUInt32() : DEFAULT;
                    var udtName = CanRead ? ReadUTF8String() : null;
                    var udtRef  = udtName == null ? null : DmdTypeNameParser.Parse(module, udtName, genericTypeArguments);
                    return(DmdMarshalType.CreateSafeArray(vt, udtRef));

                case UnmanagedType.ByValArray:
                    size = CanRead ? (int)reader.ReadCompressedUInt32() : DEFAULT;
                    nt   = CanRead ? (UnmanagedType)reader.ReadCompressedUInt32() : DEFAULT;
                    return(DmdMarshalType.CreateFixedArray(size, nt));

                case UnmanagedType.LPArray:
                    nt = CanRead ? (UnmanagedType)reader.ReadCompressedUInt32() : DEFAULT;
                    int paramNum = CanRead ? (int)reader.ReadCompressedUInt32() : DEFAULT;
                    size = CanRead ? (int)reader.ReadCompressedUInt32() : DEFAULT;
                    bool      hasFlags = CanRead;
                    int       flags    = hasFlags ? (int)reader.ReadCompressedUInt32() : DEFAULT;
                    const int ntaSizeParamIndexSpecified = 1;
                    if (hasFlags && (flags & ntaSizeParamIndexSpecified) == 0)
                    {
                        paramNum = 0;
                    }
                    return(DmdMarshalType.CreateArray(nt, (short)paramNum, size));

                case UnmanagedType.CustomMarshaler:
                    var guid              = ReadUTF8String();
                    var nativeTypeName    = ReadUTF8String();
                    var custMarshalerName = ReadUTF8String();
                    var cmRef             = DmdTypeNameParser.Parse(module, custMarshalerName, genericTypeArguments);
                    var cookie            = ReadUTF8String();
                    return(DmdMarshalType.CreateCustomMarshaler(custMarshalerName, cmRef, cookie));

                case UnmanagedType.IUnknown:
                case UnmanagedType.IDispatch:
                case UnmanagedType.Interface:
                    int iidParamIndex = CanRead ? (int)reader.ReadCompressedUInt32() : DEFAULT;
                    return(DmdMarshalType.CreateInterface(nativeType, iidParamIndex));

                default:
                    return(DmdMarshalType.Create(nativeType));
                }
            }
            catch (ArgumentException) {
            }
            catch (IOException) {
            }
            return(null);
        }
Ejemplo n.º 7
0
 public static DmdType ParseThrow(ITypeDefResolver typeDefResolver, string typeFullName, IList <DmdType>?genericTypeArguments)
 {
     using (var parser = new DmdTypeNameParser(typeDefResolver, typeFullName, genericTypeArguments))
         return(parser.ParseCore());
 }
Ejemplo n.º 8
0
 public static DmdType ParseThrow(DmdModule ownerModule, string typeFullName, IList <DmdType>?genericTypeArguments)
 {
     using (var parser = new DmdTypeNameParser(ownerModule, typeFullName, genericTypeArguments))
         return(parser.ParseCore());
 }