internal NdrBaseStructureTypeReference(NdrParseContext context, NdrFormatCharacter format, BinaryReader reader)
     : base($"Struct_{context.TypeCache.GetNextComplexId()}", format)
 {
     Alignment     = reader.ReadByte();
     MemorySize    = reader.ReadUInt16();
     _base_members = new List <NdrBaseTypeReference>();
 }
 internal NdrUnknownTypeReference(NdrFormatCharacter format) : base(format)
 {
     if (_formats.Add(format))
     {
         System.Diagnostics.Debug.WriteLine(format.ToString());
     }
 }
 internal NdrUnknownTypeReference(NdrFormatCharacter format) : base(format)
 {
     if (_formats.Add(format))
     {
         NdrUtils.WriteLine(format.ToString());
     }
 }
Ejemplo n.º 4
0
 internal NdrVariableExpression(BinaryReader reader)
     : base(NdrExpressionType.FC_EXPR_VAR)
 {
     Format  = (NdrFormatCharacter)reader.ReadByte();
     Offset  = reader.ReadInt16();
     IsValid = true;
 }
Ejemplo n.º 5
0
 internal NdrStructureStringTypeReferece(NdrFormatCharacter format, BinaryReader reader) : base(format)
 {
     ElementSize = reader.ReadByte();
     if (format == NdrFormatCharacter.FC_SSTRING)
     {
         NumberOfElements = reader.ReadUInt16();
     }
 }
 internal NdrPointerTypeReference(NdrParseContext context, NdrFormatCharacter format, BinaryReader reader) : base(format)
 {
     Flags = (NdrPointerFlags)reader.ReadByte();
     if ((Flags & NdrPointerFlags.FC_SIMPLE_POINTER) == NdrPointerFlags.FC_SIMPLE_POINTER)
     {
         Type = new NdrSimpleTypeReference(ReadFormat(reader));
     }
     else
     {
         Type = Read(context, ReadTypeOffset(reader));
     }
 }
Ejemplo n.º 7
0
        internal NdrSimpleArrayTypeReference(NdrParseContext context, NdrFormatCharacter format, BinaryReader reader) : base(context, format, reader)
        {
            if (format == NdrFormatCharacter.FC_SMFARRAY)
            {
                TotalSize = reader.ReadUInt16();
            }
            else
            {
                TotalSize = reader.ReadInt32();
            }

            ReadElementType(context, reader);
        }
        internal NdrConformantStringTypeReference(NdrParseContext context,
                                                  NdrFormatCharacter format, BinaryReader reader) : base(format)
        {
            NdrFormatCharacter padding = (NdrFormatCharacter)reader.ReadByte();

            if (padding == NdrFormatCharacter.FC_STRING_SIZED)
            {
                ConformanceDescriptor = new NdrCorrelationDescriptor(context, reader);
            }
            else
            {
                ConformanceDescriptor = new NdrCorrelationDescriptor();
            }
        }
Ejemplo n.º 9
0
 internal NdrConformantArrayTypeReference(NdrFormatCharacter format, NdrParseContext context,
                                          BinaryReader reader) : base(context, format, reader)
 {
     _element_size         = reader.ReadInt16();
     ConformanceDescriptor = new NdrCorrelationDescriptor(context, reader);
     if (format == NdrFormatCharacter.FC_CVARRAY)
     {
         VarianceDescriptor = new NdrCorrelationDescriptor(context, reader);
     }
     else
     {
         VarianceDescriptor = new NdrCorrelationDescriptor();
     }
     ReadElementType(context, reader);
 }
        internal NdrInterfacePointerTypeReference(NdrParseContext context, BinaryReader reader) : base(NdrFormatCharacter.FC_IP)
        {
            NdrFormatCharacter type = ReadFormat(reader);

            if (type == NdrFormatCharacter.FC_CONSTANT_IID)
            {
                Iid        = new Guid(reader.ReadAll(16));
                IsConstant = true;
            }
            else
            {
                Iid             = NdrNativeUtils.IID_IUnknown;
                IidIsDescriptor = new NdrCorrelationDescriptor(context, reader);
            }
        }
        internal NdrByteCountPointerReferenceType(NdrParseContext context, BinaryReader reader) : base(NdrFormatCharacter.FC_BYTE_COUNT_POINTER)
        {
            NdrFormatCharacter format = (NdrFormatCharacter)reader.ReadByte();

            if (format != NdrFormatCharacter.FC_PAD)
            {
                Type        = new NdrSimpleTypeReference(format);
                Description = new NdrCorrelationDescriptor();
            }
            else
            {
                Description = new NdrCorrelationDescriptor(context, reader);
                Type        = Read(context, ReadTypeOffset(reader));
            }
        }
Ejemplo n.º 12
0
        internal NdrVaryingArrayTypeReference(NdrParseContext context, NdrFormatCharacter format, BinaryReader reader)
            : base(context, format, reader)
        {
            if (format == NdrFormatCharacter.FC_SMVARRAY)
            {
                TotalSize        = reader.ReadUInt16();
                NumberofElements = reader.ReadUInt16();
            }
            else
            {
                TotalSize        = reader.ReadInt32();
                NumberofElements = reader.ReadInt32();
            }

            _element_size      = reader.ReadUInt16();
            VarianceDescriptor = new NdrCorrelationDescriptor(context, reader);
            ReadElementType(context, reader);
        }
Ejemplo n.º 13
0
        internal NdrUnionTypeReference(NdrFormatCharacter format, NdrParseContext context, BinaryReader reader)
            : base($"Union_{context.TypeCache.GetNextComplexId()}", format)
        {
            int switch_type = reader.ReadByte();

            if (NonEncapsulated)
            {
                SwitchType  = (NdrFormatCharacter)switch_type;
                Correlation = new NdrCorrelationDescriptor(context, reader);
                Arms        = new NdrUnionArms(context, ReadTypeOffset(reader));
            }
            else
            {
                SwitchIncrement = (switch_type >> 4) & 0xF;
                SwitchType      = (NdrFormatCharacter)(switch_type & 0xF);
                Correlation     = new NdrCorrelationDescriptor();
                Arms            = new NdrUnionArms(context, reader);
            }
        }
        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);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        string INdrFormatterInternal.SimpleTypeToName(NdrFormatCharacter format)
        {
            switch (format)
            {
            case NdrFormatCharacter.FC_BYTE:
            case NdrFormatCharacter.FC_USMALL:
                return("uint8_t");

            case NdrFormatCharacter.FC_SMALL:
            case NdrFormatCharacter.FC_CHAR:
                return("int8_t");

            case NdrFormatCharacter.FC_WCHAR:
                return("wchar_t");

            case NdrFormatCharacter.FC_SHORT:
                return("int16_t");

            case NdrFormatCharacter.FC_USHORT:
                return("uint16_t");

            case NdrFormatCharacter.FC_LONG:
                return("int64_t");

            case NdrFormatCharacter.FC_ULONG:
                return("uint64_t");

            case NdrFormatCharacter.FC_FLOAT:
                return("float");

            case NdrFormatCharacter.FC_HYPER:
                return("int64_t");

            case NdrFormatCharacter.FC_DOUBLE:
                return("double");

            case NdrFormatCharacter.FC_INT3264:
                return("intptr_t");

            case NdrFormatCharacter.FC_UINT3264:
                return("uintptr_t");

            case NdrFormatCharacter.FC_C_WSTRING:
            case NdrFormatCharacter.FC_WSTRING:
                return("wchar_t");

            case NdrFormatCharacter.FC_C_CSTRING:
            case NdrFormatCharacter.FC_CSTRING:
                return("char");

            case NdrFormatCharacter.FC_ENUM16:
                return("/* ENUM16 */ uint16_t");

            case NdrFormatCharacter.FC_ENUM32:
                return("/* ENUM32 */ uint32_t");

            case NdrFormatCharacter.FC_SYSTEM_HANDLE:
                return("HANDLE");

            case NdrFormatCharacter.FC_AUTO_HANDLE:
            case NdrFormatCharacter.FC_CALLBACK_HANDLE:
            case NdrFormatCharacter.FC_BIND_CONTEXT:
            case NdrFormatCharacter.FC_BIND_PRIMITIVE:
            case NdrFormatCharacter.FC_BIND_GENERIC:
                return("handle_t");

            case NdrFormatCharacter.FC_ERROR_STATUS_T:
                return("uint");
            }

            return($"{format}");
        }
 internal NdrSimpleTypeReference(NdrFormatCharacter format)
     : base(format)
 {
 }
        internal static NdrBaseTypeReference Read(NdrParseContext context, BinaryReader reader)
        {
            NdrFormatCharacter format = (NdrFormatCharacter)reader.ReadByte();

            // Loop to consume padding values.
            while (true)
            {
                switch (format)
                {
                case NdrFormatCharacter.FC_BYTE:
                case NdrFormatCharacter.FC_CHAR:
                case NdrFormatCharacter.FC_SMALL:
                case NdrFormatCharacter.FC_USMALL:
                case NdrFormatCharacter.FC_WCHAR:
                case NdrFormatCharacter.FC_SHORT:
                case NdrFormatCharacter.FC_USHORT:
                case NdrFormatCharacter.FC_LONG:
                case NdrFormatCharacter.FC_ULONG:
                case NdrFormatCharacter.FC_FLOAT:
                case NdrFormatCharacter.FC_HYPER:
                case NdrFormatCharacter.FC_DOUBLE:
                case NdrFormatCharacter.FC_ENUM16:
                case NdrFormatCharacter.FC_ENUM32:
                case NdrFormatCharacter.FC_ERROR_STATUS_T:
                case NdrFormatCharacter.FC_INT3264:
                case NdrFormatCharacter.FC_UINT3264:
                    return(new NdrSimpleTypeReference(format));

                case NdrFormatCharacter.FC_END:
                    return(null);

                case NdrFormatCharacter.FC_OP:
                case NdrFormatCharacter.FC_UP:
                case NdrFormatCharacter.FC_RP:
                case NdrFormatCharacter.FC_FP:
                    return(new NdrPointerTypeReference(context, format, reader));

                case NdrFormatCharacter.FC_IP:
                    return(new NdrInterfacePointerTypeReference(context, reader));

                case NdrFormatCharacter.FC_C_CSTRING:
                case NdrFormatCharacter.FC_C_BSTRING:
                case NdrFormatCharacter.FC_C_WSTRING:
                    return(new NdrConformantStringTypeReference(context, format, reader));

                case NdrFormatCharacter.FC_CSTRING:
                case NdrFormatCharacter.FC_BSTRING:
                case NdrFormatCharacter.FC_WSTRING:
                    return(new NdrStringTypeReference(format, reader));

                case NdrFormatCharacter.FC_C_SSTRING:
                    return(new NdrConformantStructureStringTypeReference(context, reader));

                case NdrFormatCharacter.FC_SSTRING:
                    return(new NdrStructureStringTypeReference(reader));

                case NdrFormatCharacter.FC_USER_MARSHAL:
                    return(FixupUserMarshal(context, new NdrUserMarshalTypeReference(context, reader)));

                case NdrFormatCharacter.FC_EMBEDDED_COMPLEX:
                    reader.ReadByte();     // Padding
                    return(Read(context, ReadTypeOffset(reader)));

                case NdrFormatCharacter.FC_STRUCT:
                    return(FixupSimpleStructureType(new NdrSimpleStructureTypeReference(context, reader)));

                case NdrFormatCharacter.FC_PSTRUCT:
                    return(new NdrSimpleStructureWithPointersTypeReference(context, reader));

                case NdrFormatCharacter.FC_CSTRUCT:
                case NdrFormatCharacter.FC_CVSTRUCT:
                    return(new NdrConformantStructureTypeReference(format, context, reader));

                case NdrFormatCharacter.FC_BOGUS_STRUCT:
                    return(new NdrBogusStructureTypeReference(context, format, reader));

                case NdrFormatCharacter.FC_FORCED_BOGUS_STRUCT:
                    return(new NdrBogusStructureTypeReference(context, format, reader));

                case NdrFormatCharacter.FC_PP:
                    return(new NdrPointerInfoTypeReference(context, reader));

                case NdrFormatCharacter.FC_SMFARRAY:
                case NdrFormatCharacter.FC_LGFARRAY:
                    return(new NdrSimpleArrayTypeReference(context, format, reader));

                case NdrFormatCharacter.FC_CARRAY:
                case NdrFormatCharacter.FC_CVARRAY:
                    return(new NdrConformantArrayTypeReference(format, context, reader));

                case NdrFormatCharacter.FC_BOGUS_ARRAY:
                    return(new NdrBogusArrayTypeReference(context, reader));

                case NdrFormatCharacter.FC_SMVARRAY:
                case NdrFormatCharacter.FC_LGVARRAY:
                    return(new NdrVaryingArrayTypeReference(context, format, reader));

                case NdrFormatCharacter.FC_RANGE:
                    return(new NdrRangeTypeReference(reader));

                case NdrFormatCharacter.FC_ENCAPSULATED_UNION:
                case NdrFormatCharacter.FC_NON_ENCAPSULATED_UNION:
                    return(new NdrUnionTypeReference(format, context, reader));

                // Skipping padding types.
                case NdrFormatCharacter.FC_PAD:
                    break;

                case NdrFormatCharacter.FC_STRUCTPAD1:
                case NdrFormatCharacter.FC_STRUCTPAD2:
                case NdrFormatCharacter.FC_STRUCTPAD3:
                case NdrFormatCharacter.FC_STRUCTPAD4:
                case NdrFormatCharacter.FC_STRUCTPAD5:
                case NdrFormatCharacter.FC_STRUCTPAD6:
                case NdrFormatCharacter.FC_STRUCTPAD7:
                    return(new NdrStructurePaddingTypeReference(format));

                case NdrFormatCharacter.FC_IGNORE:
                    return(new NdrIgnoreTypeReference());

                case NdrFormatCharacter.FC_SYSTEM_HANDLE:
                    return(new NdrSystemHandleTypeReference(reader));

                case NdrFormatCharacter.FC_AUTO_HANDLE:
                case NdrFormatCharacter.FC_CALLBACK_HANDLE:
                case NdrFormatCharacter.FC_BIND_CONTEXT:
                case NdrFormatCharacter.FC_BIND_PRIMITIVE:
                case NdrFormatCharacter.FC_BIND_GENERIC:
                    return(new NdrHandleTypeReference(format));

                case NdrFormatCharacter.FC_PIPE:
                    return(new NdrPipeTypeReference(context, reader));

                case NdrFormatCharacter.FC_SUPPLEMENT:
                    return(new NdrSupplementTypeReference(context, reader));

                case NdrFormatCharacter.FC_BYTE_COUNT_POINTER:
                    return(new NdrByteCountPointerReferenceType(context, reader));

                default:
                    return(new NdrUnknownTypeReference(format));
                }

                format = (NdrFormatCharacter)reader.ReadByte();
            }
        }
 protected NdrBaseTypeReference(NdrFormatCharacter format)
 {
     Format = format;
 }
 internal NdrComplexTypeReference(string name, NdrFormatCharacter format) : base(format)
 {
     Name = name;
 }
 internal NdrStructurePaddingTypeReference(NdrFormatCharacter format) : base(format)
 {
 }
 internal NdrConformantStructureTypeReference(NdrFormatCharacter format, NdrParseContext context, BinaryReader reader)
     : base(context, format, reader)
 {
     ConformantArray = Read(context, ReadTypeOffset(reader));
     ReadMemberInfo(context, reader);
 }
        internal string SimpleTypeToName(NdrFormatCharacter format)
        {
            switch (format)
            {
            case NdrFormatCharacter.FC_BYTE:
            case NdrFormatCharacter.FC_SMALL:
                return("byte");

            case NdrFormatCharacter.FC_CHAR:
                return("sbyte");

            case NdrFormatCharacter.FC_WCHAR:
                return("wchar_t");

            case NdrFormatCharacter.FC_SHORT:
                return("short");

            case NdrFormatCharacter.FC_USHORT:
                return("ushort");

            case NdrFormatCharacter.FC_LONG:
                return("int");

            case NdrFormatCharacter.FC_ULONG:
                return("uint");

            case NdrFormatCharacter.FC_FLOAT:
                return("float");

            case NdrFormatCharacter.FC_HYPER:
                return("long");

            case NdrFormatCharacter.FC_DOUBLE:
                return("double");

            case NdrFormatCharacter.FC_INT3264:
                return("IntPtr");

            case NdrFormatCharacter.FC_UINT3264:
                return("UIntPtr");

            case NdrFormatCharacter.FC_C_WSTRING:
            case NdrFormatCharacter.FC_WSTRING:
                return("wchar_t");

            case NdrFormatCharacter.FC_C_CSTRING:
            case NdrFormatCharacter.FC_CSTRING:
                return("char");

            case NdrFormatCharacter.FC_ENUM16:
                return("/* ENUM16 */ int");

            case NdrFormatCharacter.FC_ENUM32:
                return("/* ENUM32 */ int");

            case NdrFormatCharacter.FC_SYSTEM_HANDLE:
                return("HANDLE");

            case NdrFormatCharacter.FC_AUTO_HANDLE:
            case NdrFormatCharacter.FC_CALLBACK_HANDLE:
            case NdrFormatCharacter.FC_BIND_CONTEXT:
            case NdrFormatCharacter.FC_BIND_PRIMITIVE:
            case NdrFormatCharacter.FC_BIND_GENERIC:
                return("handle_t");
            }

            return(String.Format("{0}", format));
        }
Ejemplo n.º 23
0
 internal NdrBaseArrayTypeReference(NdrParseContext context, NdrFormatCharacter format, BinaryReader reader) : base(format)
 {
     Alignment = reader.ReadByte();
 }
 internal NdrBaseStringTypeReference(NdrFormatCharacter format) : base(format)
 {
 }
        internal NdrProcedureDefinition(IMemoryReader mem_reader, NdrTypeCache type_cache,
                                        ISymbolResolver symbol_resolver, MIDL_STUB_DESC stub_desc,
                                        IntPtr proc_desc, IntPtr type_desc, NDR_EXPR_DESC expr_desc, IntPtr dispatch_func,
                                        string name, NdrParserFlags parser_flags)
        {
            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 NdrSimpleTypeReference(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, handle_type == NdrFormatCharacter.FC_BIND_GENERIC);
            }
            else
            {
                Handle = new NdrProcedureHandleParameter(0, new NdrSimpleTypeReference(handle_type), 0, false, 0, false);
            }

            ushort constant_client_buffer_size = reader.ReadUInt16();
            ushort constant_server_buffer_size = reader.ReadUInt16();

            InterpreterFlags = (NdrInterpreterOptFlags)reader.ReadByte();
            int number_of_params = reader.ReadByte();

            NdrProcHeaderExts exts = new NdrProcHeaderExts();

            if ((InterpreterFlags & NdrInterpreterOptFlags.HasExtensions) == NdrInterpreterOptFlags.HasExtensions)
            {
                int ext_size = reader.ReadByte();
                reader.BaseStream.Position -= 1;
                // Read out extension bytes.
                byte[] extension = reader.ReadAll(ext_size);
                if (System.Runtime.InteropServices.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;
                    }
                }
            }

            NdrParseContext context         = new NdrParseContext(type_cache, symbol_resolver, stub_desc, type_desc, expr_desc, exts.Flags2, mem_reader, parser_flags);
            List <NdrProcedureParameter> ps = new List <NdrProcedureParameter>();

            bool has_return  = InterpreterFlags.HasFlag(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, $"p{param}"));
            }

            if (Handle.Explicit && !Handle.Generic)
            {
                // 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, "retval");
            }
            DispatchFunction = dispatch_func;
        }
 internal NdrStringTypeReference(NdrFormatCharacter format, BinaryReader reader) : base(format)
 {
     reader.ReadByte(); // Padding.
     StringSize = reader.ReadUInt16();
 }