Ejemplo n.º 1
0
        TypeSig ReadType()
        {
            var name         = ReadUTF8String();
            var asmRefFinder = new CAAssemblyRefFinder(module);
            var type         = TypeNameParser.ParseAsTypeSigReflection(module, UTF8String.ToSystemStringOrEmpty(name), asmRefFinder);

            if (type == null)
            {
                throw new CABlobParserException("Could not parse type");
            }
            return(type);
        }
Ejemplo n.º 2
0
        TypeSig ReadType(bool canReturnNull)
        {
            var name = ReadUTF8String();

            if (canReturnNull && (object)name == null)
            {
                return(null);
            }
            var asmRefFinder = new CAAssemblyRefFinder(module);
            var type         = TypeNameParser.ParseAsTypeSigReflection(module, UTF8String.ToSystemStringOrEmpty(name), asmRefFinder, gpContext);

            if (type == null)
            {
                throw new CABlobParserException("Could not parse type");
            }
            return(type);
        }
        /// <summary>
        ///     Reads the new (.NET 2.0+) DeclSecurity blob format
        /// </summary>
        /// <returns></returns>
        private ThreadSafe.IList <SecurityAttribute> ReadBinaryFormat()
        {
            var numAttrs = (int)reader.ReadCompressedUInt32();
            var list     = ThreadSafeListCreator.Create <SecurityAttribute>(numAttrs);

            for (var i = 0; i < numAttrs; i++)
            {
                var name = ReadUTF8String();
                // Use CA search rules. Some tools don't write the fully qualified name.
                var attrRef      = TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(name), new CAAssemblyRefFinder(module), gpContext);
                var blobLength   = (int)reader.ReadCompressedUInt32();
                var numNamedArgs = (int)reader.ReadCompressedUInt32();
                var namedArgs    = CustomAttributeReader.ReadNamedArguments(module, reader, numNamedArgs, gpContext);
                if (namedArgs == null)
                {
                    throw new ApplicationException("Could not read named arguments");
                }
                list.Add(new SecurityAttribute(attrRef, namedArgs));
            }

            return(list);
        }
Ejemplo n.º 4
0
        MarshalType Read()
        {
            MarshalType returnValue;

            try {
                var        nativeType = (NativeType)reader.ReadByte();
                NativeType nt;
                int        size;
                switch (nativeType)
                {
                case NativeType.FixedSysString:
                    size        = CanRead() ? (int)reader.ReadCompressedUInt32() : -1;
                    returnValue = new FixedSysStringMarshalType(size);
                    break;

                case NativeType.SafeArray:
                    var vt      = CanRead() ? (VariantType)reader.ReadCompressedUInt32() : VariantType.NotInitialized;
                    var udtName = CanRead() ? ReadUTF8String() : null;
                    var udtRef  = (object)udtName == null ? null : TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(udtName), null, gpContext);
                    returnValue = new SafeArrayMarshalType(vt, udtRef);
                    break;

                case NativeType.FixedArray:
                    size        = CanRead() ? (int)reader.ReadCompressedUInt32() : -1;
                    nt          = CanRead() ? (NativeType)reader.ReadCompressedUInt32() : NativeType.NotInitialized;
                    returnValue = new FixedArrayMarshalType(size, nt);
                    break;

                case NativeType.Array:
                    nt = CanRead() ? (NativeType)reader.ReadCompressedUInt32() : NativeType.NotInitialized;
                    int paramNum = CanRead() ? (int)reader.ReadCompressedUInt32() : -1;
                    size = CanRead() ? (int)reader.ReadCompressedUInt32() : -1;
                    int flags = CanRead() ? (int)reader.ReadCompressedUInt32() : -1;
                    returnValue = new ArrayMarshalType(nt, paramNum, size, flags);
                    break;

                case NativeType.CustomMarshaler:
                    var guid              = ReadUTF8String();
                    var nativeTypeName    = ReadUTF8String();
                    var custMarshalerName = ReadUTF8String();
                    var cmRef             = TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(custMarshalerName), new CAAssemblyRefFinder(module), gpContext);
                    var cookie            = ReadUTF8String();
                    returnValue = new CustomMarshalType(guid, nativeTypeName, cmRef, cookie);
                    break;

                case NativeType.IUnknown:
                case NativeType.IDispatch:
                case NativeType.IntF:
                    int iidParamIndex = CanRead() ? (int)reader.ReadCompressedUInt32() : -1;
                    return(new InterfaceMarshalType(nativeType, iidParamIndex));

                default:
                    returnValue = new MarshalType(nativeType);
                    break;
                }
            }
            catch {
                returnValue = new RawMarshalType(reader.ToArray());
            }

            return(returnValue);
        }