Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

472 lines
12 KiB

  1. //*****************************************************************************
  2. //
  3. // Name: msrpc.h
  4. //
  5. // Description: MSRPC protocol parser.
  6. //
  7. // History:
  8. // 08/1/93 t-glennc Created.
  9. //
  10. //*****************************************************************************
  11. //*****************************************************************************
  12. //
  13. // Copyright (c) 1993 by Microsoft Corp. All rights reserved.
  14. //
  15. //*****************************************************************************
  16. // MSRPC protocol property database identifiers
  17. #define MSRPC_SUMMARY 0x00
  18. #define MSRPC_VERSION 0x01
  19. #define MSRPC_VERSION_MINOR 0x02
  20. #define MSRPC_PTYPE 0x03
  21. #define MSRPC_PFC_FLAGS1 0x04
  22. #define MSRPC_PFC_FLAGS1_BITS 0x05
  23. #define MSRPC_PACKED_DREP 0x06
  24. #define MSRPC_FRAG_LENGTH 0x07
  25. #define MSRPC_AUTH_LENGTH 0x08
  26. #define MSRPC_CALL_ID 0x09
  27. #define MSRPC_MAX_XMIT_FRAG 0x0A
  28. #define MSRPC_MAX_RECV_FRAG 0x0B
  29. #define MSRPC_ASSOC_GROUP_ID 0x0C
  30. #define MSRPC_P_CONTEXT_SUM 0x0D
  31. #define MSRPC_AUTH_VERIFIER 0x0E
  32. #define MSRPC_SEC_ADDR 0x0F
  33. #define MSRPC_PAD 0x10
  34. #define MSRPC_P_RESULT_LIST 0x11
  35. #define MSRPC_PROVIDER_REJECT_REASON 0x12
  36. #define MSRPC_VERSIONS_SUPPORTED 0x13
  37. #define MSRPC_ALLOC_HINT 0x14
  38. #define MSRPC_PRES_CONTEXT_ID 0x15
  39. #define MSRPC_CANCEL_COUNT 0x16
  40. #define MSRPC_RESERVED 0x17
  41. #define MSRPC_STATUS 0x18
  42. #define MSRPC_RESERVED_2 0x19
  43. #define MSRPC_STUB_DATA 0x1A
  44. #define MSRPC_OPNUM 0x1B
  45. #define MSRPC_OBJECT 0x1C
  46. #define MSRPC_PFC_FLAGS2 0x1D
  47. #define MSRPC_PFC_FLAGS2_BITS 0x1E
  48. #define MSRPC_SERIAL_HI 0x1F
  49. #define MSRPC_OBJECT_ID 0x20
  50. #define MSRPC_INTERFACE_ID 0x21
  51. #define MSRPC_ACTIVITY_ID 0x22
  52. #define MSRPC_SERVER_BOOT_TIME 0x23
  53. #define MSRPC_INTERFACE_VER 0x24
  54. #define MSRPC_SEQ_NUM 0x25
  55. #define MSRPC_INTERFACE_HINT 0x26
  56. #define MSRPC_ACTIVITY_HINT 0x27
  57. #define MSRPC_LEN_OF_PACKET_BODY 0x28
  58. #define MSRPC_FRAG_NUM 0x29
  59. #define MSRPC_AUTH_PROTO_ID 0x2A
  60. #define MSRPC_SERIAL_LO 0x2B
  61. #define MSRPC_CANCEL_ID 0x2C
  62. #define MSRPC_SERVER_IS_ACCEPTING 0x2D
  63. #define MSRPC_STATUS_CODE 0x2E
  64. #define MSRPC_WINDOW_SIZE 0x2F
  65. #define MSRPC_MAX_TPDU 0x30
  66. #define MSRPC_MAX_PATH_TPDU 0x31
  67. #define MSRPC_SERIAL_NUM 0x32
  68. #define MSRPC_SELACK_LEN 0x33
  69. #define MSRPC_SELACK 0x34
  70. #define MSRPC_CANCEL_REQUEST_FMT_VER 0x35
  71. #define MSRPC_SEQ_NUMBER 0x36
  72. #define MSRPC_SEC_ADDR_LENGTH 0x37
  73. #define MSRPC_SEC_ADDR_PORT 0x38
  74. #define MSRPC_N_RESULTS 0x39
  75. #define MSRPC_P_RESULTS 0x3A
  76. #define MSRPC_P_CONT_DEF_RESULT 0x3B
  77. #define MSRPC_P_PROVIDER_REASON 0x3C
  78. #define MSRPC_P_TRANSFER_SYNTAX 0x3D
  79. #define MSRPC_IF_UUID 0x3E
  80. #define MSRPC_IF_VERSION 0x3F
  81. #define MSRPC_P_CONTEXT_ELEM 0x40
  82. #define MSRPC_NUM_TRANSFER_SYNTAX 0x41
  83. #define MSRPC_ABSTRACT_IF_UUID 0x42
  84. #define MSRPC_ABSTRACT_IF_VERSION 0x43
  85. #define MSRPC_TRANSFER_IF_UUID 0x44
  86. #define MSRPC_TRANSFER_IF_VERSION 0x45
  87. #define MSRPC_BIND_FRAME_NUMBER 0x46
  88. // MSRPC PDU TYPES
  89. #define MSRPC_PDU_REQUEST 0
  90. #define MSRPC_PDU_PING 1
  91. #define MSRPC_PDU_RESPONSE 2
  92. #define MSRPC_PDU_FAULT 3
  93. #define MSRPC_PDU_WORKING 4
  94. #define MSRPC_PDU_NOCALL 5
  95. #define MSRPC_PDU_REJECT 6
  96. #define MSRPC_PDU_ACK 7
  97. #define MSRPC_PDU_CL_CANCEL 8
  98. #define MSRPC_PDU_FACK 9
  99. #define MSRPC_PDU_CANCEL_ACK 10
  100. #define MSRPC_PDU_BIND 11
  101. #define MSRPC_PDU_BIND_ACK 12
  102. #define MSRPC_PDU_BIND_NAK 13
  103. #define MSRPC_PDU_ALTER_CONTEXT 14
  104. #define MSRPC_PDU_ALTER_CONTEXT_RESP 15
  105. #define MSRPC_PDU_SHUTDOWN 17
  106. #define MSRPC_PDU_CO_CANCEL 18
  107. #define MSRPC_PDU_ORPHANED 19
  108. // MSRPC PDU FLAGS - 1st Set
  109. #define MSRPC_PDU_FLAG_1_RESERVED_01 0x01
  110. #define MSRPC_PDU_FLAG_1_LASTFRAG 0x02
  111. #define MSRPC_PDU_FLAG_1_FRAG 0x04
  112. #define MSRPC_PDU_FLAG_1_NOFACK 0x08
  113. #define MSRPC_PDU_FLAG_1_MAYBE 0x10
  114. #define MSRPC_PDU_FLAG_1_IDEMPOTENT 0x20
  115. #define MSRPC_PDU_FLAG_1_BROADCAST 0x40
  116. #define MSRPC_PDU_FLAG_1_RESERVED_80 0x80
  117. // MSRPC PDU FLAGS - 2nd Set
  118. #define MSRPC_PDU_FLAG_2_RESERVED_01 0x01
  119. #define MSRPC_PDU_FLAG_2_CANCEL_PEND 0x02
  120. #define MSRPC_PDU_FLAG_2_RESERVED_04 0x04
  121. #define MSRPC_PDU_FLAG_2_RESERVED_08 0x08
  122. #define MSRPC_PDU_FLAG_2_RESERVED_10 0x10
  123. #define MSRPC_PDU_FLAG_2_RESERVED_20 0x20
  124. #define MSRPC_PDU_FLAG_2_RESERVED_40 0x40
  125. #define MSRPC_PDU_FLAG_2_RESERVED_80 0x80
  126. // Data Structures of a MSRPC protocol frame
  127. typedef struct _ALTER_CONTEXT
  128. {
  129. WORD MaxXmitFrag;
  130. WORD MaxRecvFrag;
  131. DWORD AssocGroupId;
  132. BYTE PContextElem[];
  133. } ALTER_CONTEXT;
  134. typedef struct _ALTER_CONTEXT_RESP
  135. {
  136. WORD MaxXmitFrag;
  137. WORD MaxRecvFrag;
  138. DWORD AssocGroupId;
  139. BYTE SecAddr[];
  140. } ALTER_CONTEXT_RESP;
  141. typedef struct _BIND
  142. {
  143. WORD MaxXmitFrag;
  144. WORD MaxRecvFrag;
  145. DWORD AssocGroupId;
  146. BYTE PContextElem[];
  147. } BIND;
  148. typedef struct _BIND_ACK
  149. {
  150. WORD MaxXmitFrag;
  151. WORD MaxRecvFrag;
  152. DWORD AssocGroupId;
  153. BYTE SecAddr[];
  154. } BIND_ACK;
  155. typedef struct _BIND_NAK
  156. {
  157. WORD RejectReason;
  158. BYTE Versions[];
  159. } BIND_NAK;
  160. typedef struct _CO_CANCEL
  161. {
  162. BYTE AuthTrailer[];
  163. } CO_CANCEL;
  164. typedef struct _FAULT
  165. {
  166. union
  167. {
  168. DWORD AllocHint;
  169. DWORD StatusCode;
  170. };
  171. WORD PContId;
  172. BYTE CancelCount;
  173. BYTE Reserved;
  174. DWORD Status;
  175. BYTE Reserved2[4];
  176. BYTE Data[];
  177. } FAULT;
  178. typedef struct _ORPHANED
  179. {
  180. BYTE AuthTrailer[];
  181. } ORPHANED;
  182. typedef struct _REQUEST
  183. {
  184. DWORD AllocHint;
  185. WORD PContId;
  186. WORD OpNum;
  187. BYTE Object[16];
  188. BYTE Data[];
  189. } REQUEST;
  190. typedef struct _RESPONSE
  191. {
  192. DWORD AllocHint;
  193. WORD PContId;
  194. BYTE CancelCount;
  195. BYTE Reserved;
  196. BYTE Data[];
  197. } RESPONSE;
  198. typedef struct _SHUTDOWN
  199. {
  200. BYTE Data[];
  201. } SHUTDOWN;
  202. typedef struct _MSRPCCO
  203. {
  204. BYTE Version;
  205. BYTE VersionMinor;
  206. BYTE PType;
  207. BYTE PFCFlags;
  208. BYTE PackedDrep[4];
  209. WORD FragLength;
  210. WORD AuthLength;
  211. DWORD CallID;
  212. union
  213. {
  214. ALTER_CONTEXT AlterContext;
  215. ALTER_CONTEXT_RESP AlterContextResp;
  216. BIND Bind;
  217. BIND_ACK BindAck;
  218. BIND_NAK BindNak;
  219. CO_CANCEL COCancel;
  220. FAULT Fault;
  221. ORPHANED Orphaned;
  222. REQUEST Request;
  223. RESPONSE Response;
  224. SHUTDOWN Shutdown;
  225. };
  226. } MSRPCCO;
  227. typedef MSRPCCO UNALIGNED * LPMSRPCCO;
  228. typedef struct _CL_REQUEST
  229. {
  230. BYTE Data[];
  231. } CL_REQUEST;
  232. typedef struct _PING
  233. {
  234. BYTE Data[];
  235. } PING;
  236. typedef struct _CL_RESPONSE
  237. {
  238. BYTE Data[];
  239. } CL_RESPONSE;
  240. typedef struct _WORKING
  241. {
  242. BYTE Data[];
  243. } WORKING;
  244. typedef struct _NOCALL
  245. {
  246. BYTE Vers;
  247. BYTE Pad1;
  248. WORD WindowSize;
  249. DWORD MaxTPDU;
  250. DWORD MaxPathTPDU;
  251. WORD SerialNumber;
  252. WORD SelAckLen;
  253. DWORD SelAck[];
  254. } NOCALL;
  255. typedef struct _REJECT
  256. {
  257. DWORD StatusCode;
  258. } REJECT;
  259. typedef struct _ACK
  260. {
  261. BYTE Data[];
  262. } ACK;
  263. typedef struct _CL_CANCEL
  264. {
  265. DWORD Vers;
  266. DWORD CancelId;
  267. } CL_CANCEL;
  268. typedef struct _FACK
  269. {
  270. BYTE Vers;
  271. BYTE Pad1;
  272. WORD WindowSize;
  273. DWORD MaxTPDU;
  274. DWORD MaxPathTPDU;
  275. WORD SerialNumber;
  276. WORD SelAckLen;
  277. DWORD SelAck[];
  278. } FACK;
  279. typedef struct _CANCEL_ACK
  280. {
  281. DWORD Vers;
  282. DWORD CancelId;
  283. DWORD ServerIsAccepting;
  284. } CANCEL_ACK;
  285. typedef struct _MSRPCCL
  286. {
  287. BYTE Version;
  288. BYTE PType;
  289. BYTE PFCFlags1;
  290. BYTE PFCFlags2;
  291. BYTE PackedDrep[3];
  292. BYTE SerialNumHi;
  293. BYTE ObjectId[16];
  294. BYTE InterfaceId[16];
  295. BYTE ActivityId[16];
  296. DWORD ServerBootTime;
  297. DWORD InterfaceVersion;
  298. DWORD SeqNum;
  299. WORD OpNum;
  300. WORD InterfaceHint;
  301. WORD ActivityHint;
  302. WORD Length;
  303. WORD FragNum;
  304. BYTE AuthProtoId;
  305. BYTE SerialNumLo;
  306. union
  307. {
  308. CL_REQUEST Request;
  309. PING Ping;
  310. CL_RESPONSE Response;
  311. FAULT Fault;
  312. WORKING Working;
  313. NOCALL NoCall;
  314. REJECT Reject;
  315. ACK Ack;
  316. CL_CANCEL CLCancel;
  317. FACK Fack;
  318. CANCEL_ACK CancelAck;
  319. };
  320. } MSRPCCL;
  321. typedef MSRPCCL UNALIGNED * LPMSRPCCL;
  322. typedef unsigned short p_context_id_t;
  323. typedef struct
  324. {
  325. GUID if_uuid;
  326. unsigned long if_version;
  327. } p_syntax_id_t;
  328. typedef struct
  329. {
  330. p_context_id_t p_cont_id;
  331. unsigned char n_transfer_syn;
  332. unsigned char reserved;
  333. p_syntax_id_t abstract_syntax;
  334. p_syntax_id_t transfer_syntaxes[1];
  335. } p_cont_elem_t;
  336. // Table for tracking IIDs
  337. typedef struct _IID_HANDOFF
  338. {
  339. union
  340. {
  341. BYTE ByteRep[16];
  342. DWORD DwordRep[4];
  343. };
  344. HPROTOCOL hNext;
  345. } IID_HANDOFF;
  346. // We are going to store the BIND frames in a database so that at attach time, we
  347. // can point to who is the BIND frame on requests and responses. CCHeapAlloc routines
  348. // will be used to store the data.
  349. enum BINDTABLESTATE
  350. {
  351. UNINITED,
  352. NORMAL,
  353. FULL
  354. };
  355. typedef struct _BINDENTRY
  356. {
  357. DWORD nFrame;
  358. HFRAME hBindFrame;
  359. } BINDENTRY;
  360. typedef BINDENTRY * LPBINDENTRY;
  361. typedef struct _BINDTABLE
  362. {
  363. DWORD nEntries;
  364. DWORD nAllocated;
  365. DWORD State;
  366. BOOL fCurrentlyLookingBack;
  367. BINDENTRY BindEntry[1];
  368. } BINDTABLE;
  369. typedef BINDTABLE * LPBINDTABLE;
  370. #define BINDTABLEHEADERSIZE (sizeof(BINDTABLE)-sizeof(BINDENTRY))
  371. // Defintions for MSRPC protocol parser entry point functions
  372. VOID WINAPI MSRPC_Register( HPROTOCOL hMSRPC );
  373. VOID WINAPI MSRPC_Deregister( HPROTOCOL hMSRPC );
  374. LPBYTE WINAPI MSRPC_RecognizeFrame( HFRAME hFrame,
  375. LPBYTE lpStartFrame,
  376. LPBYTE lpStartMSRPC,
  377. DWORD MacType,
  378. DWORD BytesLeft,
  379. HPROTOCOL hPreviousProtocol,
  380. DWORD nPreviousProtocolOffset,
  381. LPDWORD ProtocolStatusCode,
  382. LPHPROTOCOL hNextProtocol,
  383. LPDWORD lpInstData );
  384. LPBYTE WINAPI MSRPC_AttachProperties( HFRAME hFrame,
  385. LPBYTE lpStartFrame,
  386. LPBYTE lpStartMSRPC,
  387. DWORD MacType,
  388. DWORD BytesLeft,
  389. HPROTOCOL hPreviousProtocol,
  390. DWORD nPreviousProtocolOffset,
  391. DWORD InstData );
  392. DWORD WINAPI MSRPC_FormatProperties( HFRAME hFrame,
  393. LPBYTE MacFrame,
  394. LPBYTE ProtocolFrame,
  395. DWORD nPropertyInsts,
  396. LPPROPERTYINST p );
  397. VOID WINAPIV MSRPC_FmtSummary( LPPROPERTYINST lpPropertyInst );