Esempio n. 1
0
        /// <summary>
        /// Reads a single COM interface marshal descriptor from the provided input stream.
        /// </summary>
        /// <param name="type">The type of COM interface marshaller to read.</param>
        /// <param name="reader">The input stream.</param>
        /// <returns>The descriptor.</returns>
        public static ComInterfaceMarshalDescriptor FromReader(NativeType type, ref BinaryStreamReader reader)
        {
            var result = new ComInterfaceMarshalDescriptor(type);

            if (reader.TryReadCompressedUInt32(out uint value))
            {
                result.IidParameterIndex = (int)value;
            }

            return(result);
        }
        /// <summary>
        /// Reads a marshal descriptor signature from the provided input stream.
        /// </summary>
        /// <param name="parentModule">The module that defines the marshal descriptor</param>
        /// <param name="reader">The input stream.</param>
        /// <returns>The marshal descriptor.</returns>
        public static MarshalDescriptor FromReader(ModuleDefinition parentModule, ref BinaryStreamReader reader)
        {
            var nativeType = (NativeType)reader.ReadByte();
            MarshalDescriptor descriptor = nativeType switch
            {
                NativeType.SafeArray => SafeArrayMarshalDescriptor.FromReader(parentModule, ref reader),
                NativeType.FixedArray => FixedArrayMarshalDescriptor.FromReader(ref reader),
                NativeType.LPArray => LPArrayMarshalDescriptor.FromReader(ref reader),
                NativeType.CustomMarshaller => CustomMarshalDescriptor.FromReader(parentModule, ref reader),
                NativeType.FixedSysString => FixedSysStringMarshalDescriptor.FromReader(ref reader),
                NativeType.Interface => ComInterfaceMarshalDescriptor.FromReader(nativeType, ref reader),
                NativeType.IDispatch => ComInterfaceMarshalDescriptor.FromReader(nativeType, ref reader),
                NativeType.IUnknown => ComInterfaceMarshalDescriptor.FromReader(nativeType, ref reader),
                _ => new SimpleMarshalDescriptor(nativeType)
            };

            descriptor.ExtraData = reader.ReadToEnd();
            return(descriptor);
        }