void CtxClose( /* [out][in] */ PCTXTYPE __RPC_FAR *pphContext) { RPC_BINDING_HANDLE _Handle = 0; RPC_MESSAGE _RpcMessage; MIDL_STUB_MESSAGE _StubMsg; if(!pphContext) { RpcRaiseException(RPC_X_NULL_REF_POINTER); } RpcTryFinally { NdrClientInitializeNew( ( PRPC_MESSAGE )&_RpcMessage, ( PMIDL_STUB_MESSAGE )&_StubMsg, ( PMIDL_STUB_DESC )&hello_StubDesc, 2); if(*pphContext != 0) { _Handle = NDRCContextBinding(( NDR_CCONTEXT )*pphContext);; } _StubMsg.BufferLength = 20U; NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle ); NdrClientContextMarshall( ( PMIDL_STUB_MESSAGE )&_StubMsg, ( NDR_CCONTEXT )*pphContext, 0); NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer ); if ( (_RpcMessage.DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION ) NdrConvert( (PMIDL_STUB_MESSAGE) &_StubMsg, (PFORMAT_STRING) &__MIDL_ProcFormatString.Format[14] ); NdrClientContextUnmarshall( ( PMIDL_STUB_MESSAGE )&_StubMsg, ( NDR_CCONTEXT __RPC_FAR * )pphContext, _Handle); } RpcFinally { NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg ); } RpcEndFinally }
/*********************************************************************** * NdrProxyInitialize [RPCRT4.@] */ void WINAPI NdrProxyInitialize(void *This, PRPC_MESSAGE pRpcMsg, PMIDL_STUB_MESSAGE pStubMsg, PMIDL_STUB_DESC pStubDescriptor, unsigned int ProcNum) { TRACE("(%p,%p,%p,%p,%d)\n", This, pRpcMsg, pStubMsg, pStubDescriptor, ProcNum); NdrClientInitializeNew(pRpcMsg, pStubMsg, pStubDescriptor, ProcNum); StdProxy_GetChannel(This, &pStubMsg->pRpcChannelBuffer); IRpcChannelBuffer_GetDestCtx(pStubMsg->pRpcChannelBuffer, &pStubMsg->dwDestContext, &pStubMsg->pvDestContext); TRACE("channel=%p\n", pStubMsg->pRpcChannelBuffer); }
void CtxHello( /* [in] */ PCTXTYPE phContext) { RPC_BINDING_HANDLE _Handle = 0; RPC_MESSAGE _RpcMessage; MIDL_STUB_MESSAGE _StubMsg; RpcTryFinally { NdrClientInitializeNew( ( PRPC_MESSAGE )&_RpcMessage, ( PMIDL_STUB_MESSAGE )&_StubMsg, ( PMIDL_STUB_DESC )&hello_StubDesc, 1); if(phContext != 0) { _Handle = NDRCContextBinding(( NDR_CCONTEXT )phContext);; } else { RpcRaiseException(RPC_X_SS_IN_NULL_CONTEXT); } _StubMsg.BufferLength = 20U; NdrGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, _Handle ); NdrClientContextMarshall( ( PMIDL_STUB_MESSAGE )&_StubMsg, ( NDR_CCONTEXT )phContext, 1); NdrSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer ); } RpcFinally { NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg ); } RpcEndFinally }
void MyRemoteProc( /* [in] */ int param1, /* [out] */ int __RPC_FAR outArray[ 100 ]) { RPC_MESSAGE _RpcMessage; MIDL_STUB_MESSAGE _StubMsg; RpcTryFinally { NdrClientInitializeNew( ( PRPC_MESSAGE )&_RpcMessage, ( PMIDL_STUB_MESSAGE )&_StubMsg, ( PMIDL_STUB_DESC )&MyInterface_StubDesc, 0); _StubMsg.BufferLength = 4U; NdrNsGetBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg, _StubMsg.BufferLength, MyInterface__MIDL_AutoBindHandle ); *(( int __RPC_FAR * )_StubMsg.Buffer)++ = param1; NdrNsSendReceive( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR *) _StubMsg.Buffer, (RPC_BINDING_HANDLE __RPC_FAR *) &MyInterface__MIDL_AutoBindHandle ); if ( (_RpcMessage.DataRepresentation & 0X0000FFFFUL) != NDR_LOCAL_DATA_REPRESENTATION ) NdrConvert( (PMIDL_STUB_MESSAGE) &_StubMsg, (PFORMAT_STRING) &__MIDL_ProcFormatString.Format[0] ); NdrFixedArrayUnmarshall( (PMIDL_STUB_MESSAGE) &_StubMsg, (unsigned char __RPC_FAR * __RPC_FAR *)&outArray, (PFORMAT_STRING) &__MIDL_TypeFormatString.Format[2], (unsigned char)0 ); } RpcFinally { NdrFreeBuffer( (PMIDL_STUB_MESSAGE) &_StubMsg ); } RpcEndFinally }
CLIENT_CALL_RETURN NdrClientCall(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING pFormat, void** stackTop, void** fpuStack) { RPC_MESSAGE rpcMsg; unsigned short procNum; unsigned short stackSize; unsigned char numberParams; unsigned char handleType; MIDL_STUB_MESSAGE stubMsg; INTERPRETER_FLAGS flags; INTERPRETER_OPT_FLAGS optFlags; INTERPRETER_OPT_FLAGS2 extFlags; NDR_PROC_HEADER* procHeader; NDR_OI2_PROC_HEADER* oi2ProcHeader; CLIENT_CALL_RETURN client_call_return; procNum = stackSize = numberParams = 0; procHeader = (NDR_PROC_HEADER*) &pFormat[0]; client_call_return.Pointer = NULL; handleType = procHeader->HandleType; flags = procHeader->OldOiFlags; procNum = procHeader->ProcNum; stackSize = procHeader->StackSize; pFormat += sizeof(NDR_PROC_HEADER); /* The Header: http://msdn.microsoft.com/en-us/library/windows/desktop/aa378707/ */ /* Procedure Header Descriptor: http://msdn.microsoft.com/en-us/library/windows/desktop/aa374387/ */ /* Handles: http://msdn.microsoft.com/en-us/library/windows/desktop/aa373932/ */ printf("Oi Header: HandleType: 0x%02X OiFlags: 0x%02X ProcNum: %d StackSize: 0x%04X\n", handleType, *((unsigned char*) &flags), (unsigned short) procNum, (unsigned short) stackSize); if (handleType > 0) { /* implicit handle */ printf("Implicit Handle\n"); oi2ProcHeader = (NDR_OI2_PROC_HEADER*) &pFormat[0]; pFormat += sizeof(NDR_OI2_PROC_HEADER); } else { /* explicit handle */ printf("Explicit Handle\n"); oi2ProcHeader = (NDR_OI2_PROC_HEADER*) &pFormat[6]; pFormat += sizeof(NDR_OI2_PROC_HEADER) + 6; } optFlags = oi2ProcHeader->Oi2Flags; numberParams = oi2ProcHeader->NumberParams; printf("Oi2 Header: Oi2Flags: 0x%02X, NumberParams: %d ClientBufferSize: %d ServerBufferSize: %d\n", *((unsigned char*) &optFlags), (unsigned char) numberParams, oi2ProcHeader->ClientBufferSize, oi2ProcHeader->ServerBufferSize); printf("Oi2Flags: "); NdrPrintOptFlags(optFlags); printf("\n"); NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDescriptor, procNum); if (optFlags.HasExtensions) { NDR_PROC_HEADER_EXTS* extensions = (NDR_PROC_HEADER_EXTS*) pFormat; pFormat += extensions->Size; extFlags = extensions->Flags2; printf("Extensions: Size: %d, flags2: 0x%02X\n", extensions->Size, *((unsigned char*) &extensions->Flags2)); #ifdef __x86_64__ if (extensions->Size > sizeof(*extensions) && fpuStack) { int i; unsigned short fpuMask = *(unsigned short*) (extensions + 1); for (i = 0; i < 4; i++, fpuMask >>= 2) { switch (fpuMask & 3) { case 1: *(float*) &stackTop[i] = *(float*) &fpuStack[i]; break; case 2: *(double*) &stackTop[i] = *(double*) &fpuStack[i]; break; } } }