forked from sunflyer/vlmcsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.h
178 lines (154 loc) · 3.47 KB
/
rpc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef __rpc_h
#define __rpc_h
#ifndef CONFIG
#define CONFIG "config.h"
#endif // CONFIG
#include CONFIG
#include "types.h"
typedef struct {
BYTE VersionMajor;
BYTE VersionMinor;
BYTE PacketType;
BYTE PacketFlags;
DWORD DataRepresentation;
WORD FragLength;
WORD AuthLength;
DWORD CallId;
} /*__packed*/ RPC_HEADER;
typedef struct {
WORD MaxXmitFrag;
WORD MaxRecvFrag;
DWORD AssocGroup;
DWORD NumCtxItems;
struct {
WORD ContextId;
WORD NumTransItems;
GUID InterfaceUUID;
WORD InterfaceVerMajor;
WORD InterfaceVerMinor;
GUID TransferSyntax;
DWORD SyntaxVersion;
} CtxItems[1];
} /*__packed*/ RPC_BIND_REQUEST;
typedef struct {
WORD MaxXmitFrag;
WORD MaxRecvFrag;
DWORD AssocGroup;
WORD SecondaryAddressLength;
BYTE SecondaryAddress[6];
DWORD NumResults;
struct {
WORD AckResult;
WORD AckReason;
GUID TransferSyntax;
DWORD SyntaxVersion;
} Results[0];
} /*__packed*/ RPC_BIND_RESPONSE;
typedef struct {
DWORD AllocHint;
WORD ContextId;
WORD Opnum;
struct {
DWORD DataLength;
DWORD DataSizeIs;
} Ndr;
BYTE Data[0];
} /*__packed*/ RPC_REQUEST;
typedef struct {
DWORD AllocHint;
WORD ContextId;
BYTE CancelCount;
BYTE Pad1;
struct {
DWORD DataLength;
DWORD DataSizeIs1;
DWORD DataSizeIs2;
} Ndr;
BYTE Data[0];
} /*__packed*/ RPC_RESPONSE;
typedef struct {
DWORD AllocHint;
WORD ContextId;
WORD Opnum;
union {
struct {
DWORD DataLength;
DWORD DataSizeIs;
BYTE Data[0];
} Ndr;
struct {
uint64_t DataLength;
uint64_t DataSizeIs;
BYTE Data[0];
} Ndr64;
};
} /*__packed*/ RPC_REQUEST64;
typedef struct {
DWORD AllocHint;
WORD ContextId;
BYTE CancelCount;
BYTE Pad1;
union {
struct {
DWORD DataLength;
DWORD DataSizeMax;
union
{
DWORD DataSizeIs;
DWORD status;
};
BYTE Data[0];
} Ndr;
struct {
uint64_t DataLength;
uint64_t DataSizeMax;
union
{
uint64_t DataSizeIs;
DWORD status;
};
BYTE Data[0];
} Ndr64;
};
} /*__packed*/ RPC_RESPONSE64;
typedef SOCKET RpcCtx;
typedef int RpcStatus;
#define INVALID_NDR_CTX ((WORD)~0)
#define RPC_BIND_ACCEPT (0)
#define RPC_BIND_NACK (LE16(2))
#define RPC_BIND_ACK (LE16(3))
#define RPC_SYNTAX_UNSUPPORTED (LE16(2))
#define RPC_ABSTRACTSYNTAX_UNSUPPORTED (LE16(1))
#define RPC_BTFN_SEC_CONTEXT_MULTIPLEX (LE16(1))
#define RPC_BTFN_KEEP_ORPHAN (LE16(2))
#define INVALID_RPCCTX INVALID_SOCKET
#define closeRpc socketclose
#define RPC_PT_REQUEST 0
#define RPC_PT_RESPONSE 2
#define RPC_PT_BIND_REQ 11
#define RPC_PT_BIND_ACK 12
#define RPC_PT_ALTERCONTEXT_REQ 14
#define RPC_PT_ALTERCONTEXT_ACK 15
#define RPC_PF_FIRST 1
#define RPC_PF_LAST 2
#define RPC_PF_CANCEL_PENDING 4
#define RPC_PF_RESERVED 8
#define RPC_PF_MULTIPLEX 16
#define RPC_PF_NOT_EXEC 32
#define RPC_PF_MAYBE 64
#define RPC_PF_OBJECT 128
typedef union _RPC_FLAGS
{
DWORD mask;
struct {
uint32_t FlagsBTFN : 16;
BOOL HasNDR32 : 1;
BOOL HasNDR64 : 1;
BOOL HasBTFN : 1;
};
} RPC_FLAGS, *PRPC_FLAGS;
extern RPC_FLAGS RpcFlags;
void rpcServer(const RpcCtx socket, const DWORD RpcAssocGroup, const char* const ipstr);
RpcStatus rpcBindClient(const RpcCtx sock, const int_fast8_t verbose);
RpcStatus rpcSendRequest(const RpcCtx socket, const BYTE *const KmsRequest, const size_t requestSize, BYTE **KmsResponse, size_t *const responseSize);
#endif // __rpc_h