示例#1
0
        private static RPC_SERVER_INTERFACE CreateExplicitBytesServer(RpcHandle handle, Ptr <MIDL_SERVER_INFO> pServer, Guid iid)
        {
            var server = new RPC_SERVER_INTERFACE();

            server.Length      = (uint)Marshal.SizeOf(typeof(RPC_SERVER_INTERFACE));
            server.InterfaceId = new RPC_SYNTAX_IDENTIFIER()
            {
                SyntaxGUID = iid, SyntaxVersion = ExplicitBytesConstants.INTERFACE_VERSION
            };
            server.TransferSyntax = new RPC_SYNTAX_IDENTIFIER()
            {
                SyntaxGUID = SYNTAX.SYNTAX_IID, SyntaxVersion = SYNTAX.SYNTAX_VERSION
            };

            var fnTable = new RPC_DISPATCH_TABLE();

            fnTable.DispatchTableCount = 1;
            fnTable.DispatchTable      =
                handle.Pin(new RPC_DISPATCH_TABLE_Entry()
            {
                DispatchMethod = RpcRuntime.ServerEntry.Handle, Zero = IntPtr.Zero
            });
            fnTable.Reserved = IntPtr.Zero;

            server.DispatchTable           = handle.Pin(fnTable);
            server.RpcProtseqEndpointCount = 0u;
            server.RpcProtseqEndpoint      = IntPtr.Zero;
            server.DefaultManagerEpv       = IntPtr.Zero;
            server.InterpreterInfo         = pServer.Handle;
            server.Flags = 0x04000000u;
            return(server);
        }
        private static Win32Error ResolveBinding(SafeRpcBindingHandle binding, Guid interface_id, Version interface_version)
        {
            RPC_SERVER_INTERFACE ifspec = new RPC_SERVER_INTERFACE();

            ifspec.Length = Marshal.SizeOf(ifspec);
            ifspec.InterfaceId.SyntaxGUID    = interface_id;
            ifspec.InterfaceId.SyntaxVersion = interface_version.ToRpcVersion();

            return(Win32NativeMethods.RpcEpResolveBinding(binding, ref ifspec));
        }
        /// <summary>
        /// Resolve the binding string for this service from the local Endpoint Mapper.
        /// </summary>
        /// <param name="binding">The binding handle.</param>
        /// <param name="interface_id">Interface UUID to lookup.</param>
        /// <param name="interface_version">Interface version lookup.</param>
        /// <remarks>This only will return a valid value if the service is running and registered with the Endpoint Mapper. It can also hang.</remarks>
        /// <returns>The RPC binding string. Empty string if it doesn't exist or the lookup failed.</returns>
        private static string MapBindingToBindingString(NtResult <SafeRpcBindingHandle> binding, Guid interface_id, Version interface_version)
        {
            if (!binding.IsSuccess)
            {
                return(string.Empty);
            }

            RPC_SERVER_INTERFACE ifspec = new RPC_SERVER_INTERFACE();

            ifspec.Length = Marshal.SizeOf(ifspec);
            ifspec.InterfaceId.SyntaxGUID    = interface_id;
            ifspec.InterfaceId.SyntaxVersion = interface_version.ToRpcVersion();

            var result = Win32NativeMethods.RpcEpResolveBinding(binding.Result, ref ifspec);

            if (result != Win32Error.SUCCESS)
            {
                return(string.Empty);
            }

            return(binding.Result.ToString());
        }
        /// <summary>
        /// Resolve the binding string for this service from the the Endpoint Mapper.
        /// </summary>
        /// <param name="protocol_seq">The protocol sequence to lookup.</param>
        /// <param name="network_address">The network address to lookup the endpoint.</param>
        /// <param name="interface_id">Interface UUID to lookup.</param>
        /// <param name="interface_version">Interface version lookup.</param>
        /// <remarks>This only will return a valid value if the service is running and registered with the Endpoint Mapper. It can also hang.</remarks>
        /// <returns>The RPC binding string. Empty string if it doesn't exist or the lookup failed.</returns>
        public static string MapServerToBindingString(string protocol_seq, string network_address, Guid interface_id, Version interface_version)
        {
            using (var binding = SafeRpcBindingHandle.Create(null, protocol_seq, network_address, null, null, false))
            {
                if (!binding.IsSuccess)
                {
                    return(string.Empty);
                }

                RPC_SERVER_INTERFACE ifspec = new RPC_SERVER_INTERFACE();
                ifspec.Length = Marshal.SizeOf(ifspec);
                ifspec.InterfaceId.SyntaxGUID    = interface_id;
                ifspec.InterfaceId.SyntaxVersion = interface_version.ToRpcVersion();

                var result = Win32NativeMethods.RpcEpResolveBinding(binding.Result, ref ifspec);
                if (result != Win32Error.SUCCESS)
                {
                    return(string.Empty);
                }

                return(binding.Result.ToString());
            }
        }
示例#5
0
        /// <summary>
        /// Resolve the binding string for this service from the local Endpoint Mapper.
        /// </summary>
        /// <param name="protocol_seq">The protocol sequence to lookup.</param>
        /// <param name="interface_id">Interface UUID to lookup.</param>
        /// <param name="interface_version">Interface version lookup.</param>
        /// <remarks>This only will return a valid value if the service is running and registered with the Endpoint Mapper. It can also hang.</remarks>
        /// <returns>The RPC binding string. Empty string if it doesn't exist or the lookup failed.</returns>
        public static string MapServerToBindingString(string protocol_seq, Guid interface_id, Version interface_version)
        {
            int result = Win32NativeMethods.RpcBindingFromStringBinding($"{protocol_seq}:", out SafeRpcBindingHandle binding);

            if (result != 0)
            {
                return(string.Empty);
            }
            using (binding) {
                RPC_SERVER_INTERFACE ifspec = new RPC_SERVER_INTERFACE();
                ifspec.Length = Marshal.SizeOf(ifspec);
                ifspec.InterfaceId.SyntaxGUID    = interface_id;
                ifspec.InterfaceId.SyntaxVersion = interface_version.ToRpcVersion();

                result = Win32NativeMethods.RpcEpResolveBinding(binding, ref ifspec);
                if (result != 0)
                {
                    return(string.Empty);
                }

                return(binding.ToString());
            }
        }
示例#6
0
 internal static extern int RpcEpResolveBinding(SafeRpcBindingHandle Binding, ref RPC_SERVER_INTERFACE IfSpec);