ndr.h (14499B)
1/** 2 * WinPR: Windows Portable Runtime 3 * Network Data Representation (NDR) 4 * 5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20#ifndef WINPR_RPC_NDR_H 21#define WINPR_RPC_NDR_H 22 23#include <winpr/rpc.h> 24#include <winpr/wtypes.h> 25 26#ifndef _WIN32 27 28#define __RPC_WIN32__ 1 29#define TARGET_IS_NT50_OR_LATER 1 30 31typedef union _CLIENT_CALL_RETURN { 32 void* Pointer; 33 LONG_PTR Simple; 34} CLIENT_CALL_RETURN; 35 36typedef struct _RPC_VERSION 37{ 38 unsigned short MajorVersion; 39 unsigned short MinorVersion; 40} RPC_VERSION; 41 42typedef struct _RPC_SYNTAX_IDENTIFIER 43{ 44 GUID SyntaxGUID; 45 RPC_VERSION SyntaxVersion; 46} RPC_SYNTAX_IDENTIFIER, PRPC_SYNTAX_IDENTIFIER; 47 48#define RPC_MGR_EPV void 49 50typedef struct _RPC_MESSAGE 51{ 52 RPC_BINDING_HANDLE Handle; 53 ULONG DataRepresentation; 54 void* Buffer; 55 unsigned int BufferLength; 56 unsigned int ProcNum; 57 PRPC_SYNTAX_IDENTIFIER TransferSyntax; 58 void* RpcInterfaceInformation; 59 void* ReservedForRuntime; 60 RPC_MGR_EPV* ManagerEpv; 61 void* ImportContext; 62 ULONG RpcFlags; 63} RPC_MESSAGE, *PRPC_MESSAGE; 64 65typedef void (*RPC_DISPATCH_FUNCTION)(PRPC_MESSAGE Message); 66 67typedef struct 68{ 69 unsigned int DispatchTableCount; 70 RPC_DISPATCH_FUNCTION* DispatchTable; 71 LONG_PTR Reserved; 72} RPC_DISPATCH_TABLE, *PRPC_DISPATCH_TABLE; 73 74typedef struct _RPC_PROTSEQ_ENDPOINT 75{ 76 unsigned char* RpcProtocolSequence; 77 unsigned char* Endpoint; 78} RPC_PROTSEQ_ENDPOINT, *PRPC_PROTSEQ_ENDPOINT; 79 80typedef struct _RPC_SERVER_INTERFACE 81{ 82 unsigned int Length; 83 RPC_SYNTAX_IDENTIFIER InterfaceId; 84 RPC_SYNTAX_IDENTIFIER TransferSyntax; 85 PRPC_DISPATCH_TABLE DispatchTable; 86 unsigned int RpcProtseqEndpointCount; 87 PRPC_PROTSEQ_ENDPOINT RpcProtseqEndpoint; 88 RPC_MGR_EPV* DefaultManagerEpv; 89 void const* InterpreterInfo; 90 unsigned int Flags; 91} RPC_SERVER_INTERFACE, *PRPC_SERVER_INTERFACE; 92 93typedef struct _RPC_CLIENT_INTERFACE 94{ 95 unsigned int Length; 96 RPC_SYNTAX_IDENTIFIER InterfaceId; 97 RPC_SYNTAX_IDENTIFIER TransferSyntax; 98 PRPC_DISPATCH_TABLE DispatchTable; 99 unsigned int RpcProtseqEndpointCount; 100 PRPC_PROTSEQ_ENDPOINT RpcProtseqEndpoint; 101 ULONG_PTR Reserved; 102 void const* InterpreterInfo; 103 unsigned int Flags; 104} RPC_CLIENT_INTERFACE, *PRPC_CLIENT_INTERFACE; 105 106typedef void* (*GENERIC_BINDING_ROUTINE)(void*); 107typedef void (*GENERIC_UNBIND_ROUTINE)(void*, unsigned char*); 108 109typedef struct _GENERIC_BINDING_ROUTINE_PAIR 110{ 111 GENERIC_BINDING_ROUTINE pfnBind; 112 GENERIC_UNBIND_ROUTINE pfnUnbind; 113} GENERIC_BINDING_ROUTINE_PAIR, *PGENERIC_BINDING_ROUTINE_PAIR; 114 115typedef struct __GENERIC_BINDING_INFO 116{ 117 void* pObj; 118 unsigned int Size; 119 GENERIC_BINDING_ROUTINE pfnBind; 120 GENERIC_UNBIND_ROUTINE pfnUnbind; 121} GENERIC_BINDING_INFO, *PGENERIC_BINDING_INFO; 122 123typedef void (*NDR_RUNDOWN)(void* context); 124typedef void (*NDR_NOTIFY_ROUTINE)(void); 125 126typedef const unsigned char* PFORMAT_STRING; 127 128typedef struct _MIDL_STUB_DESC MIDL_STUB_DESC; 129typedef MIDL_STUB_DESC* PMIDL_STUB_DESC; 130 131typedef struct _MIDL_STUB_MESSAGE 132{ 133 PRPC_MESSAGE RpcMsg; 134 unsigned char* Buffer; 135 unsigned char* BufferStart; 136 unsigned char* BufferEnd; 137 unsigned char* BufferMark; 138 ULONG BufferLength; 139 ULONG MemorySize; 140 unsigned char* Memory; 141 int IsClient; 142 int ReuseBuffer; 143 struct NDR_ALLOC_ALL_NODES_CONTEXT* pAllocAllNodesContext; 144 struct NDR_POINTER_QUEUE_STATE* pPointerQueueState; 145 int IgnoreEmbeddedPointers; 146 unsigned char* PointerBufferMark; 147 unsigned char fBufferValid; 148 unsigned char uFlags; 149 unsigned short Unused2; 150 ULONG_PTR MaxCount; 151 ULONG Offset; 152 ULONG ActualCount; 153 void* (*pfnAllocate)(size_t); 154 void (*pfnFree)(void*); 155 unsigned char* StackTop; 156 unsigned char* pPresentedType; 157 unsigned char* pTransmitType; 158 handle_t SavedHandle; 159 const struct _MIDL_STUB_DESC* StubDesc; 160 struct _FULL_PTR_XLAT_TABLES* FullPtrXlatTables; 161 ULONG FullPtrRefId; 162 ULONG PointerLength; 163 int fInDontFree : 1; 164 int fDontCallFreeInst : 1; 165 int fInOnlyParam : 1; 166 int fHasReturn : 1; 167 int fHasExtensions : 1; 168 int fHasNewCorrDesc : 1; 169 int fUnused : 10; 170 int fUnused2 : 16; 171 ULONG dwDestContext; 172 void* pvDestContext; 173 // NDR_SCONTEXT* SavedContextHandles; 174 long ParamNumber; 175 struct IRpcChannelBuffer* pRpcChannelBuffer; 176 // PARRAY_INFO pArrayInfo; 177 ULONG* SizePtrCountArray; 178 ULONG* SizePtrOffsetArray; 179 ULONG* SizePtrLengthArray; 180 void* pArgQueue; 181 ULONG dwStubPhase; 182 void* LowStackMark; 183 // PNDR_ASYNC_MESSAGE pAsyncMsg; 184 // PNDR_CORRELATION_INFO pCorrInfo; 185 unsigned char* pCorrMemory; 186 void* pMemoryList; 187 // CS_STUB_INFO* pCSInfo; 188 unsigned char* ConformanceMark; 189 unsigned char* VarianceMark; 190 void* BackingStoreLowMark; 191 INT_PTR Unused; 192 struct _NDR_PROC_CONTEXT* pContext; 193 INT_PTR Reserved51_1; 194 INT_PTR Reserved51_2; 195 INT_PTR Reserved51_3; 196 INT_PTR Reserved51_4; 197 INT_PTR Reserved51_5; 198} MIDL_STUB_MESSAGE, *PMIDL_STUB_MESSAGE; 199 200typedef void (*EXPR_EVAL)(struct _MIDL_STUB_MESSAGE*); 201 202typedef void (*XMIT_HELPER_ROUTINE)(PMIDL_STUB_MESSAGE); 203 204typedef struct _XMIT_ROUTINE_QUINTUPLE 205{ 206 XMIT_HELPER_ROUTINE pfnTranslateToXmit; 207 XMIT_HELPER_ROUTINE pfnTranslateFromXmit; 208 XMIT_HELPER_ROUTINE pfnFreeXmit; 209 XMIT_HELPER_ROUTINE pfnFreeInst; 210} XMIT_ROUTINE_QUINTUPLE, *PXMIT_ROUTINE_QUINTUPLE; 211 212typedef ULONG (*USER_MARSHAL_SIZING_ROUTINE)(ULONG*, ULONG, void*); 213typedef unsigned char* (*USER_MARSHAL_MARSHALLING_ROUTINE)(ULONG*, unsigned char*, void*); 214typedef unsigned char* (*USER_MARSHAL_UNMARSHALLING_ROUTINE)(ULONG*, unsigned char*, void*); 215typedef void (*USER_MARSHAL_FREEING_ROUTINE)(ULONG*, void*); 216 217typedef struct _USER_MARSHAL_ROUTINE_QUADRUPLE 218{ 219 USER_MARSHAL_SIZING_ROUTINE pfnBufferSize; 220 USER_MARSHAL_MARSHALLING_ROUTINE pfnMarshall; 221 USER_MARSHAL_UNMARSHALLING_ROUTINE pfnUnmarshall; 222 USER_MARSHAL_FREEING_ROUTINE pfnFree; 223} USER_MARSHAL_ROUTINE_QUADRUPLE; 224 225typedef struct _MALLOC_FREE_STRUCT 226{ 227 void* (*pfnAllocate)(size_t); 228 void (*pfnFree)(void*); 229} MALLOC_FREE_STRUCT; 230 231typedef struct _COMM_FAULT_OFFSETS 232{ 233 short CommOffset; 234 short FaultOffset; 235} COMM_FAULT_OFFSETS; 236 237typedef void* NDR_CS_ROUTINES; 238typedef void* NDR_EXPR_DESC; 239 240struct _MIDL_STUB_DESC 241{ 242 void* RpcInterfaceInformation; 243 void* (*pfnAllocate)(size_t); 244 void (*pfnFree)(void*); 245 246 union { 247 handle_t* pAutoHandle; 248 handle_t* pPrimitiveHandle; 249 PGENERIC_BINDING_INFO pGenericBindingInfo; 250 } IMPLICIT_HANDLE_INFO; 251 252 const NDR_RUNDOWN* apfnNdrRundownRoutines; 253 const GENERIC_BINDING_ROUTINE_PAIR* aGenericBindingRoutinePairs; 254 const EXPR_EVAL* apfnExprEval; 255 const XMIT_ROUTINE_QUINTUPLE* aXmitQuintuple; 256 const unsigned char* pFormatTypes; 257 258 int fCheckBounds; 259 ULONG Version; 260 MALLOC_FREE_STRUCT* pMallocFreeStruct; 261 262 long MIDLVersion; 263 const COMM_FAULT_OFFSETS* CommFaultOffsets; 264 const USER_MARSHAL_ROUTINE_QUADRUPLE* aUserMarshalQuadruple; 265 266 const NDR_NOTIFY_ROUTINE* NotifyRoutineTable; 267 ULONG_PTR mFlags; 268 const NDR_CS_ROUTINES* CsRoutineTables; 269 void* ProxyServerInfo; 270 const NDR_EXPR_DESC* pExprInfo; 271}; 272 273typedef struct 274{ 275 unsigned char FullPtrUsed : 1; 276 unsigned char RpcSsAllocUsed : 1; 277 unsigned char ObjectProc : 1; 278 unsigned char HasRpcFlags : 1; 279 unsigned char IgnoreObjectException : 1; 280 unsigned char HasCommOrFault : 1; 281 unsigned char UseNewInitRoutines : 1; 282 unsigned char Unused : 1; 283} INTERPRETER_FLAGS, *PINTERPRETER_FLAGS; 284 285typedef struct 286{ 287 unsigned short MustSize : 1; 288 unsigned short MustFree : 1; 289 unsigned short IsPipe : 1; 290 unsigned short IsIn : 1; 291 unsigned short IsOut : 1; 292 unsigned short IsReturn : 1; 293 unsigned short IsBasetype : 1; 294 unsigned short IsByValue : 1; 295 unsigned short IsSimpleRef : 1; 296 unsigned short IsDontCallFreeInst : 1; 297 unsigned short SaveForAsyncFinish : 1; 298 unsigned short Unused : 2; 299 unsigned short ServerAllocSize : 3; 300} PARAM_ATTRIBUTES, *PPARAM_ATTRIBUTES; 301 302typedef struct 303{ 304 unsigned char ServerMustSize : 1; 305 unsigned char ClientMustSize : 1; 306 unsigned char HasReturn : 1; 307 unsigned char HasPipes : 1; 308 unsigned char Unused : 1; 309 unsigned char HasAsyncUuid : 1; 310 unsigned char HasExtensions : 1; 311 unsigned char HasAsyncHandle : 1; 312} INTERPRETER_OPT_FLAGS, *PINTERPRETER_OPT_FLAGS; 313 314typedef struct 315{ 316 unsigned char HasNewCorrDesc : 1; 317 unsigned char ClientCorrCheck : 1; 318 unsigned char ServerCorrCheck : 1; 319 unsigned char HasNotify : 1; 320 unsigned char HasNotify2 : 1; 321 unsigned char Unused : 3; 322} INTERPRETER_OPT_FLAGS2, *PINTERPRETER_OPT_FLAGS2; 323 324typedef struct _NDR_CORRELATION_FLAGS 325{ 326 unsigned char Early : 1; 327 unsigned char Split : 1; 328 unsigned char IsIidIs : 1; 329 unsigned char DontCheck : 1; 330 unsigned char Unused : 4; 331} NDR_CORRELATION_FLAGS; 332 333#define FC_ALLOCATE_ALL_NODES 0x01 334#define FC_DONT_FREE 0x02 335#define FC_ALLOCED_ON_STACK 0x03 336#define FC_SIMPLE_POINTER 0x04 337#define FC_POINTER_DEREF 0x05 338 339#define HANDLE_PARAM_IS_VIA_PTR 0x80 340#define HANDLE_PARAM_IS_IN 0x40 341#define HANDLE_PARAM_IS_OUT 0x20 342#define HANDLE_PARAM_IS_RETURN 0x21 343#define NDR_STRICT_CONTEXT_HANDLE 0x08 344#define NDR_CONTEXT_HANDLE_NO_SERIALIZE 0x04 345#define NDR_CONTEXT_HANDLE_SERIALIZE 0x02 346#define NDR_CONTEXT_HANDLE_CANNOT_BE_NULL 0x01 347 348typedef struct 349{ 350 PARAM_ATTRIBUTES Attributes; 351 unsigned short StackOffset; 352 353 union { 354 unsigned char FormatChar; 355 unsigned short Offset; 356 } Type; 357 358} NDR_PARAM; 359 360typedef struct 361{ 362 unsigned char Size; 363 INTERPRETER_OPT_FLAGS2 Flags2; 364 unsigned short ClientCorrHint; 365 unsigned short ServerCorrHint; 366 unsigned short NotifyIndex; 367} NDR_PROC_HEADER_EXTS; 368 369typedef struct _NDR_PROC_HEADER 370{ 371 unsigned char HandleType; 372 INTERPRETER_FLAGS OldOiFlags; 373 unsigned short RpcFlagsLow; 374 unsigned short RpcFlagsHi; 375 unsigned short ProcNum; 376 unsigned short StackSize; 377} NDR_PROC_HEADER, *PNDR_PROC_HEADER; 378 379typedef struct _NDR_OI2_PROC_HEADER 380{ 381 unsigned short ClientBufferSize; 382 unsigned short ServerBufferSize; 383 INTERPRETER_OPT_FLAGS Oi2Flags; 384 unsigned char NumberParams; 385} NDR_OI2_PROC_HEADER, *PNDR_OI2_PROC_HEADER; 386 387typedef enum _NDR_PHASE 388{ 389 NDR_PHASE_SIZE, 390 NDR_PHASE_MARSHALL, 391 NDR_PHASE_UNMARSHALL, 392 NDR_PHASE_FREE 393} NDR_PHASE; 394 395#define FC_NORMAL_CONFORMANCE 0x00 396#define FC_POINTER_CONFORMANCE 0x10 397#define FC_TOP_LEVEL_CONFORMANCE 0x20 398#define FC_CONSTANT_CONFORMANCE 0x40 399#define FC_TOP_LEVEL_MULTID_CONFORMANCE 0x80 400 401/* Type Format Strings: http://msdn.microsoft.com/en-us/library/windows/desktop/aa379093/ */ 402 403#define FC_ZERO 0x00 404#define FC_BYTE 0x01 405#define FC_CHAR 0x02 406#define FC_SMALL 0x03 407#define FC_USMALL 0x04 408#define FC_WCHAR 0x05 409#define FC_SHORT 0x06 410#define FC_USHORT 0x07 411#define FC_LONG 0x08 412#define FC_ULONG 0x09 413#define FC_FLOAT 0x0A 414#define FC_HYPER 0x0B 415#define FC_DOUBLE 0x0C 416#define FC_ENUM16 0x0D 417#define FC_ENUM32 0x0E 418#define FC_IGNORE 0x0F 419#define FC_ERROR_STATUS_T 0x10 420#define FC_RP 0x11 421#define FC_UP 0x12 422#define FC_OP 0x13 423#define FC_FP 0x14 424#define FC_STRUCT 0x15 425#define FC_PSTRUCT 0x16 426#define FC_CSTRUCT 0x17 427#define FC_CPSTRUCT 0x18 428#define FC_CVSTRUCT 0x19 429#define FC_BOGUS_STRUCT 0x1A 430#define FC_CARRAY 0x1B 431#define FC_CVARRAY 0x1C 432#define FC_SMFARRAY 0x1D 433#define FC_LGFARRAY 0x1E 434#define FC_SMVARRAY 0x1F 435#define FC_LGVARRAY 0x20 436#define FC_BOGUS_ARRAY 0x21 437#define FC_C_CSTRING 0x22 438#define FC_C_BSTRING 0x23 439#define FC_C_SSTRING 0x24 440#define FC_C_WSTRING 0x25 441#define FC_CSTRING 0x26 442#define FC_BSTRING 0x27 443#define FC_SSTRING 0x28 444#define FC_WSTRING 0x29 445#define FC_ENCAPSULATED_UNION 0x2A 446#define FC_NON_ENCAPSULATED_UNION 0x2B 447#define FC_BYTE_COUNT_POINTER 0x2C 448#define FC_TRANSMIT_AS 0x2D 449#define FC_REPRESENT_AS 0x2E 450#define FC_IP 0x2F 451#define FC_BIND_CONTEXT 0x30 452#define FC_BIND_GENERIC 0x31 453#define FC_BIND_PRIMITIVE 0x32 454#define FC_AUTO_HANDLE 0x33 455#define FC_CALLBACK_HANDLE 0x34 456#define FC_UNUSED1 0x35 457#define FC_POINTER 0x36 458#define FC_ALIGNM2 0x37 459#define FC_ALIGNM4 0x38 460#define FC_ALIGNM8 0x39 461#define FC_UNUSED2 0x3A 462#define FC_UNUSED3 0x3B 463#define FC_UNUSED4 0x3C 464#define FC_STRUCTPAD1 0x3D 465#define FC_STRUCTPAD2 0x3E 466#define FC_STRUCTPAD3 0x3F 467#define FC_STRUCTPAD4 0x40 468#define FC_STRUCTPAD5 0x41 469#define FC_STRUCTPAD6 0x42 470#define FC_STRUCTPAD7 0x43 471#define FC_STRING_SIZED 0x44 472#define FC_UNUSED5 0x45 473#define FC_NO_REPEAT 0x46 474#define FC_FIXED_REPEAT 0x47 475#define FC_VARIABLE_REPEAT 0x48 476#define FC_FIXED_OFFSET 0x49 477#define FC_VARIABLE_OFFSET 0x4A 478#define FC_PP 0x4B 479#define FC_EMBEDDED_COMPLEX 0x4C 480#define FC_IN_PARAM 0x4D 481#define FC_IN_PARAM_BASETYPE 0x4E 482#define FC_IN_PARAM_NO_FREE_INST 0x4F 483#define FC_IN_OUT_PARAM 0x50 484#define FC_OUT_PARAM 0x51 485#define FC_RETURN_PARAM 0x52 486#define FC_RETURN_PARAM_BASETYPE 0x53 487#define FC_DEREFERENCE 0x54 488#define FC_DIV_2 0x55 489#define FC_MULT_2 0x56 490#define FC_ADD_1 0x57 491#define FC_SUB_1 0x58 492#define FC_CALLBACK 0x59 493#define FC_CONSTANT_IID 0x5A 494#define FC_END 0x5B 495#define FC_PAD 0x5C 496#define FC_SPLIT_DEREFERENCE 0x74 497#define FC_SPLIT_DIV_2 0x75 498#define FC_SPLIT_MULT_2 0x76 499#define FC_SPLIT_ADD_1 0x77 500#define FC_SPLIT_SUB_1 0x78 501#define FC_SPLIT_CALLBACK 0x79 502#define FC_HARD_STRUCT 0xB1 503#define FC_TRANSMIT_AS_PTR 0xB2 504#define FC_REPRESENT_AS_PTR 0xB3 505#define FC_USER_MARSHAL 0xB4 506#define FC_PIPE 0xB5 507#define FC_BLKHOLE 0xB6 508#define FC_RANGE 0xB7 509#define FC_INT3264 0xB8 510#define FC_UINT3264 0xB9 511#define FC_END_OF_UNIVERSE 0xBA 512 513#define NdrFcShort(s) (byte)(s & 0xFF), (byte)(s >> 8) 514 515#define NdrFcLong(s) \ 516 (byte)(s & 0xFF), (byte)((s & 0x0000FF00) >> 8), (byte)((s & 0x00FF0000) >> 16), (byte)(s >> 24) 517 518typedef void (*NDR_TYPE_SIZE_ROUTINE)(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, 519 PFORMAT_STRING pFormat); 520typedef void (*NDR_TYPE_MARSHALL_ROUTINE)(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, 521 unsigned char FormatChar); 522typedef void (*NDR_TYPE_UNMARSHALL_ROUTINE)(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, 523 unsigned char FormatChar); 524typedef void (*NDR_TYPE_FREE_ROUTINE)(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, 525 PFORMAT_STRING pFormat); 526 527#ifdef __cplusplus 528extern "C" 529{ 530#endif 531 532 WINPR_API CLIENT_CALL_RETURN NdrClientCall2(PMIDL_STUB_DESC pStubDescriptor, 533 PFORMAT_STRING pFormat, ...); 534 535#ifdef __cplusplus 536} 537#endif 538 539#endif 540 541#endif /* WINPR_RPC_NDR_H */