コード例 #1
0
        private static byte[] InvokeRpc(RpcHandle handle, Guid iid, byte[] input)
        {
            Log.Verbose("InvokeRpc on {0}, sending {1} bytes", handle.Handle, input.Length);
            Ptr <MIDL_STUB_DESC> pStub;

            if (!handle.GetPtr(out pStub))
            {
                pStub =
                    handle.CreatePtr(new MIDL_STUB_DESC(handle, handle.Pin(new RPC_CLIENT_INTERFACE(iid)),
                                                        RpcApi.TYPE_FORMAT,
                                                        false));
            }
            int    szResponse = 0;
            IntPtr response, result;

            using (Ptr <byte[]> pInputBuffer = new Ptr <byte[]>(input))
            {
                if (RpcApi.Is64BitProcess)
                {
                    try
                    {
                        result = NdrClientCall2x64(pStub.Handle, RpcApi.FUNC_FORMAT_PTR.Handle, handle.Handle,
                                                   input.Length,
                                                   pInputBuffer.Handle, out szResponse, out response);
                    }
                    catch (SEHException ex)
                    {
                        RpcException.Assert(ex.ErrorCode);
                        throw;
                    }
                }
                else
                {
                    using (Ptr <Int32[]> pStack32 = new Ptr <Int32[]>(new Int32[10]))
                    {
                        pStack32.Data[0] = handle.Handle.ToInt32();
                        pStack32.Data[1] = input.Length;
                        pStack32.Data[2] = pInputBuffer.Handle.ToInt32();
                        pStack32.Data[3] = pStack32.Handle.ToInt32() + (sizeof(int) * 6);
                        pStack32.Data[4] = pStack32.Handle.ToInt32() + (sizeof(int) * 8);
                        pStack32.Data[5] = 0; //reserved
                        pStack32.Data[6] = 0; //output: int dwSizeResponse
                        pStack32.Data[8] = 0; //output: byte* lpResponse

                        try
                        {
                            result = NdrClientCall2x86(pStub.Handle, RpcApi.FUNC_FORMAT_PTR.Handle, pStack32.Handle);
                        }
                        catch (SEHException ex)
                        {
                            RpcException.Assert(ex.ErrorCode);
                            throw;
                        }

                        szResponse = pStack32.Data[6];
                        response   = new IntPtr(pStack32.Data[8]);
                    }
                }
                GC.KeepAlive(pInputBuffer);
            }
            RpcException.Assert(result.ToInt32());
            Log.Verbose("InvokeRpc.InvokeRpc response on {0}, recieved {1} bytes", handle.Handle, szResponse);
            byte[] output = new byte[szResponse];
            if (szResponse > 0 && response != IntPtr.Zero)
            {
                Marshal.Copy(response, output, 0, output.Length);
            }
            RpcApi.Free(response);

            return(output);
        }
コード例 #2
0
        private static void BindingFromStringBinding(RpcHandle handle, String bindingString)
        {
            RpcError result = RpcBindingFromStringBinding(bindingString, out handle.Handle);

            RpcException.Assert(result);
        }