コード例 #1
0
 internal NdrProcedureHandleParameter(NdrParamAttributes attributes,
                                      NdrBaseTypeReference type, int offset, bool explicit_handle, NdrHandleParamFlags flags)
     : base(attributes, 0, type, offset)
 {
     Flags    = flags;
     Explicit = explicit_handle;
 }
コード例 #2
0
        internal static NdrBaseTypeReference Read(NdrParseContext context, int ofs)
        {
            if (ofs < 0)
            {
                return(null);
            }

            IntPtr type_ofs = context.TypeDesc + ofs;

            if (context.TypeCache.Cache.ContainsKey(type_ofs))
            {
                return(context.TypeCache.Cache[type_ofs]);
            }

            // Add a pending refence type, this is used only if the current type refers to itself (or indirectly).
            NdrIndirectTypeReference ref_type = new NdrIndirectTypeReference();

            context.TypeCache.Cache.Add(type_ofs, ref_type);

            NdrBaseTypeReference ret = Read(context, GetReader(context, ofs));

            ref_type.FixupType(ret);
            // Replace type cache entry with real value.
            context.TypeCache.Cache[type_ofs] = ret;
            return(ret);
        }
コード例 #3
0
 internal NdrProcedureParameter(NdrParamAttributes attributes, int server_alloc_size, NdrBaseTypeReference type, int offset)
 {
     Attributes      = attributes;
     ServerAllocSize = server_alloc_size;
     Type            = type;
     Offset          = offset;
 }
コード例 #4
0
        private void ReadTypes(IntPtr midl_type_pickling_info_ptr, IntPtr midl_stub_desc_ptr, IEnumerable <int> fmt_offsets)
        {
            if (midl_type_pickling_info_ptr == IntPtr.Zero)
            {
                throw new ArgumentException("Must specify the MIDL_TYPE_PICKLING_INFO pointer");
            }

            if (midl_stub_desc_ptr == IntPtr.Zero)
            {
                throw new ArgumentException("Must specify the MIDL_STUB_DESC pointer");
            }

            var pickle_info = _reader.ReadStruct <MIDL_TYPE_PICKLING_INFO>(midl_type_pickling_info_ptr);

            if (pickle_info.Version != 0x33205054)
            {
                throw new ArgumentException($"Unsupported picking type version {pickle_info.Version:X}");
            }

            var             flags     = pickle_info.Flags.HasFlag(MidlTypePicklingInfoFlags.NewCorrDesc) ? NdrInterpreterOptFlags2.HasNewCorrDesc : 0;
            MIDL_STUB_DESC  stub_desc = _reader.ReadStruct <MIDL_STUB_DESC>(midl_stub_desc_ptr);
            NdrParseContext context   = new NdrParseContext(_type_cache, null, stub_desc, stub_desc.pFormatTypes, stub_desc.GetExprDesc(_reader),
                                                            flags, _reader, NdrParserFlags.IgnoreUserMarshal);

            foreach (var i in fmt_offsets)
            {
                NdrBaseTypeReference.Read(context, i);
            }
        }
 internal NdrProcedureHandleParameter(NdrParamAttributes attributes,
                                      NdrBaseTypeReference type, int offset, bool explicit_handle, NdrHandleParamFlags flags, bool generic)
     : base(attributes, 0, type, offset, string.Empty)
 {
     Flags    = flags;
     Explicit = explicit_handle;
     Generic  = generic;
 }
コード例 #6
0
 internal static NdrBaseTypeReference GetIndirectType(NdrBaseTypeReference base_type)
 {
     if (base_type is NdrIndirectTypeReference type)
     {
         return(type.RefType);
     }
     return(base_type);
 }
 internal NdrUserMarshalTypeReference(NdrParseContext context, BinaryReader reader)
     : base(NdrFormatCharacter.FC_USER_MARSHAL)
 {
     Flags                     = (NdrUserMarshalFlags)(reader.ReadByte() & 0xF0);
     QuadrupleIndex            = reader.ReadUInt16();
     UserTypeMemorySite        = reader.ReadUInt16();
     TransmittedTypeBufferSize = reader.ReadUInt16();
     Type = Read(context, ReadTypeOffset(reader));
 }
コード例 #8
0
        private static void UpdateComplexTypes(Dictionary <NdrComplexTypeReference, UserDefinedTypeInformation> complex_types,
                                               TypeInformation type_info, NdrBaseTypeReference type_reference)
        {
            var udt     = GetUDTType(type_info);
            var complex = GetComplexType(type_reference);

            if (udt != null && complex != null && !complex_types.ContainsKey(complex))
            {
                complex_types[complex] = udt;
            }
        }
コード例 #9
0
        private static NdrComplexTypeReference GetComplexType(NdrBaseTypeReference type_reference)
        {
            if (type_reference is NdrPointerTypeReference pointer_type)
            {
                return(GetComplexType(pointer_type.Type));
            }

            if (type_reference is NdrBaseArrayTypeReference array_type)
            {
                return(GetComplexType(array_type.ElementType));
            }

            return(type_reference as NdrComplexTypeReference);
        }
コード例 #10
0
        internal void ReadElementType(NdrParseContext context, BinaryReader reader)
        {
            NdrBaseTypeReference type = Read(context, reader);

            if (type is NdrPointerInfoTypeReference pointer_layout)
            {
                PointerLayout = pointer_layout;
                ElementType   = Read(context, reader);
            }
            else
            {
                ElementType = type;
            }
        }
コード例 #11
0
 internal NdrProcedureParameter(NdrParseContext context, BinaryReader reader)
 {
     Attributes = (NdrParamAttributes)reader.ReadUInt16();
     Offset     = reader.ReadUInt16();
     if ((Attributes & NdrParamAttributes.IsBasetype) == 0)
     {
         int type_ofs = reader.ReadUInt16();
         Type = NdrBaseTypeReference.Read(context, type_ofs);
     }
     else
     {
         Type = new NdrBaseTypeReference((NdrFormatCharacter)reader.ReadByte());
         // Remove padding.
         reader.ReadByte();
     }
 }
        internal NdrBogusStructureTypeReference(NdrParseContext context, NdrFormatCharacter format, BinaryReader reader)
            : base(context, format, reader)
        {
            ConformantArray = Read(context, ReadTypeOffset(reader));
            int pointer_ofs = ReadTypeOffset(reader);

            ReadMemberInfo(context, reader);
            if (pointer_ofs >= 0)
            {
                BinaryReader pointer_reader = GetReader(context, pointer_ofs);
                for (int i = 0; i < _base_members.Count; ++i)
                {
                    if (_base_members[i].Format == NdrFormatCharacter.FC_POINTER)
                    {
                        _base_members[i] = Read(context, reader);
                    }
                }
            }
        }
コード例 #13
0
        internal NdrProcedureParameter(NdrParseContext context, BinaryReader reader)
        {
            ushort attr = reader.ReadUInt16();

            Attributes      = (NdrParamAttributes)(attr & ~ServerAllocSizeMask);
            ServerAllocSize = (attr & ServerAllocSizeMask) >> 10;
            Offset          = reader.ReadUInt16();
            if ((Attributes & NdrParamAttributes.IsBasetype) == 0)
            {
                int type_ofs = reader.ReadUInt16();
                Type = NdrBaseTypeReference.Read(context, type_ofs);
            }
            else
            {
                Type = new NdrBaseTypeReference((NdrFormatCharacter)reader.ReadByte());
                // Remove padding.
                reader.ReadByte();
            }
        }
コード例 #14
0
        private void ReadTypes(IntPtr midl_type_pickling_info_ptr, IntPtr fmt_str_ptr, IEnumerable <int> fmt_offsets)
        {
            var pickle_info = _reader.ReadStruct <MIDL_TYPE_PICKLING_INFO>(midl_type_pickling_info_ptr);

            if (pickle_info.Version != 0x33205054)
            {
                throw new ArgumentException($"Unsupported picking type version {pickle_info.Version:X}");
            }
            int desc_size = 4;

            if ((pickle_info.Flags & MidlTypePicklingInfoFlags.NewCorrDesc) != 0)
            {
                desc_size = 6;
                // TODO: Might need to support extended correlation descriptors.
            }
            NdrParseContext context = new NdrParseContext(_type_cache, null, new MIDL_STUB_DESC(), fmt_str_ptr, desc_size, _reader, NdrParserFlags.IgnoreUserMarshal);

            foreach (var i in fmt_offsets)
            {
                NdrBaseTypeReference.Read(context, i);
            }
        }
コード例 #15
0
        internal static NdrBaseTypeReference ReadArmType(NdrParseContext context, BinaryReader reader)
        {
            ushort type = reader.ReadUInt16();

            if ((type & 0x8F00) == 0x8000)
            {
                return(new NdrSimpleTypeReference((NdrFormatCharacter)(type & 0xFF)));
            }
            else if (type == 0)
            {
                return(new NdrSimpleTypeReference(NdrFormatCharacter.FC_ZERO));
            }
            else if (type == 0xFFFF)
            {
                return(null);
            }
            else
            {
                reader.BaseStream.Position = reader.BaseStream.Position - 2;
                return(NdrBaseTypeReference.Read(context, NdrBaseTypeReference.ReadTypeOffset(reader)));
            }
        }
 internal void FixupLateBoundTypes()
 {
     MemberType = NdrBaseTypeReference.GetIndirectType(MemberType);
 }
 internal NdrStructureMember(NdrBaseTypeReference member_type, int offset, string name)
 {
     MemberType = member_type;
     Offset     = offset;
     Name       = name;
 }
 internal NdrPointerInfoInstance(NdrParseContext context, BinaryReader reader)
 {
     OffsetInMemory = reader.ReadInt16();
     OffsetInBuffer = reader.ReadInt16();
     PointerType    = NdrBaseTypeReference.Read(context, reader) as NdrPointerTypeReference;
 }
 internal NdrConformantStructureTypeReference(NdrFormatCharacter format, NdrParseContext context, BinaryReader reader)
     : base(context, format, reader)
 {
     ConformantArray = Read(context, ReadTypeOffset(reader));
     ReadMemberInfo(context, reader);
 }
コード例 #20
0
 internal NdrProcedureParameter(NdrParamAttributes attributes, NdrBaseTypeReference type, int offset)
 {
     Attributes = attributes;
     Type       = type;
     Offset     = offset;
 }
コード例 #21
0
 internal NdrUnionArms(NdrParseContext context, int ofs)
     : this(context, NdrBaseTypeReference.GetReader(context, ofs))
 {
 }
コード例 #22
0
        internal NdrProcedureDefinition(IMemoryReader mem_reader, NdrTypeCache type_cache,
                                        ISymbolResolver symbol_resolver, MIDL_STUB_DESC stub_desc,
                                        IntPtr proc_desc, IntPtr type_desc, IntPtr dispatch_func,
                                        string name)
        {
            BinaryReader        reader       = mem_reader.GetReader(proc_desc);
            NdrFormatCharacter  handle_type  = (NdrFormatCharacter)reader.ReadByte();
            NdrInterpreterFlags old_oi_flags = (NdrInterpreterFlags)reader.ReadByte();

            if ((old_oi_flags & NdrInterpreterFlags.HasRpcFlags) == NdrInterpreterFlags.HasRpcFlags)
            {
                RpcFlags = reader.ReadUInt32();
            }

            ProcNum = reader.ReadUInt16();

            if (string.IsNullOrWhiteSpace(name))
            {
                if (symbol_resolver != null && dispatch_func != IntPtr.Zero)
                {
                    Name = symbol_resolver.GetSymbolForAddress(dispatch_func, false, true);
                }

                Name = Name ?? $"Proc{ProcNum}";
            }
            else
            {
                Name = name;
            }

            StackSize = reader.ReadUInt16();
            if (handle_type == 0)
            {
                // read out handle type.
                handle_type = (NdrFormatCharacter)reader.ReadByte();
                NdrHandleParamFlags flags      = (NdrHandleParamFlags)reader.ReadByte();
                ushort handle_offset           = reader.ReadUInt16();
                NdrBaseTypeReference base_type = new NdrBaseTypeReference(handle_type);
                if (handle_type == NdrFormatCharacter.FC_BIND_PRIMITIVE)
                {
                    flags = flags != 0 ? NdrHandleParamFlags.HANDLE_PARAM_IS_VIA_PTR : 0;
                }
                else if (handle_type == NdrFormatCharacter.FC_BIND_GENERIC)
                {
                    // Remove the size field, we might do something with this later.
                    flags = (NdrHandleParamFlags)((byte)flags & 0xF0);
                    // Read out the remaining data.
                    reader.ReadByte();
                    reader.ReadByte();
                }
                else if (handle_type == NdrFormatCharacter.FC_BIND_CONTEXT)
                {
                    // Read out the remaining data.
                    reader.ReadByte();
                    reader.ReadByte();
                }
                else
                {
                    throw new ArgumentException($"Unsupported explicit handle type {handle_type}");
                }
                Handle = new NdrProcedureHandleParameter(0,
                                                         (flags & NdrHandleParamFlags.HANDLE_PARAM_IS_VIA_PTR) != 0 ? new NdrPointerTypeReference(base_type)
                            : base_type, handle_offset, true, flags);
            }
            else
            {
                Handle = new NdrProcedureHandleParameter(0, new NdrBaseTypeReference(handle_type), 0, false, 0);
            }

            ushort constant_client_buffer_size = reader.ReadUInt16();
            ushort constant_server_buffer_size = reader.ReadUInt16();
            NdrInterpreterOptFlags oi2_flags   = (NdrInterpreterOptFlags)reader.ReadByte();
            int number_of_params = reader.ReadByte();

            HasAsyncHandle = (oi2_flags & NdrInterpreterOptFlags.HasAsyncHandle) != 0;

            NdrProcHeaderExts exts = new NdrProcHeaderExts();

            if ((oi2_flags & NdrInterpreterOptFlags.HasExtensions) == NdrInterpreterOptFlags.HasExtensions)
            {
                int ext_size = reader.ReadByte();
                reader.BaseStream.Position -= 1;
                // Read out extension bytes.
                byte[] extension = reader.ReadAll(ext_size);
                if (Marshal.SizeOf(typeof(NdrProcHeaderExts)) <= ext_size)
                {
                    using (var buffer = new SafeStructureInOutBuffer <NdrProcHeaderExts>(ext_size, false))
                    {
                        buffer.WriteArray(0, extension, 0, ext_size);
                        exts = buffer.Result;
                    }
                }
            }

            int desc_size = 4;

            if ((exts.Flags2 & NdrInterpreterOptFlags2.HasNewCorrDesc) != 0)
            {
                desc_size = 6;
                if ((exts.Flags2 & NdrInterpreterOptFlags2.ExtendedCorrDesc) != 0)
                {
                    desc_size = 16;
                }
            }
            NdrParseContext context         = new NdrParseContext(type_cache, symbol_resolver, stub_desc, type_desc, desc_size, mem_reader);
            List <NdrProcedureParameter> ps = new List <NdrProcedureParameter>();

            bool has_return  = (oi2_flags & NdrInterpreterOptFlags.HasReturn) == NdrInterpreterOptFlags.HasReturn;
            int  param_count = has_return ? number_of_params - 1 : number_of_params;

            for (int param = 0; param < param_count; ++param)
            {
                ps.Add(new NdrProcedureParameter(context, reader));
            }

            if (Handle.Explicit)
            {
                // Insert handle into parameter list at the best location.
                int index = 0;
                while (index < ps.Count)
                {
                    if (ps[index].Offset > Handle.Offset)
                    {
                        ps.Insert(index, Handle);
                        break;
                    }
                    index++;
                }
            }

            Params = ps.AsReadOnly();
            if (has_return)
            {
                ReturnValue = new NdrProcedureParameter(context, reader);
            }
            DispatchFunction = dispatch_func;
        }
コード例 #23
0
 internal NdrPointerTypeReference(NdrBaseTypeReference type)
     : base(NdrFormatCharacter.FC_POINTER)
 {
     Type  = type;
     Flags = NdrPointerFlags.FC_SIMPLE_POINTER;
 }
コード例 #24
0
 internal void FixupType(NdrBaseTypeReference ref_type)
 {
     RefType = ref_type;
 }