-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlpctypes.h
359 lines (311 loc) · 7.63 KB
/
lpctypes.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*++ NDK Version: 0098
Copyright (c) Alex Ionescu. All rights reserved.
Header Name:
lpctypes.h
Abstract:
Type definitions for the Loader.
Author:
Alex Ionescu ([email protected]) - Updated - 27-Feb-2006
--*/
#ifndef _LPCTYPES_H
#define _LPCTYPES_H
//
// Dependencies
//
#include <..\ndk\umtypes.h>
//#include <..\ndk\pstypes.h>
#ifndef NTOS_MODE_USER
//
// Kernel Exported Object Types
//
extern POBJECT_TYPE NTSYSAPI LpcPortObjectType;
#endif // !NTOS_MODE_USER
//
// Internal helper macro
//
#define N_ROUND_UP(x,s) \
(((ULONG)(x)+(s)-1) & ~((ULONG)(s)-1))
//
// Port Object Access Masks
//
#define PORT_CONNECT 0x1
#define PORT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | \
SYNCHRONIZE | \
PORT_CONNECT)
//
// Port Object Flags
//
#define LPCP_CONNECTION_PORT 0x00000001
#define LPCP_UNCONNECTED_PORT 0x00000002
#define LPCP_COMMUNICATION_PORT 0x00000003
#define LPCP_CLIENT_PORT 0x00000004
#define LPCP_PORT_TYPE_MASK 0x0000000F
#define LPCP_PORT_DELETED 0x10000000
#define LPCP_WAITABLE_PORT 0x20000000
#define LPCP_NAME_DELETED 0x40000000
#define LPCP_SECURITY_DYNAMIC 0x80000000
//
// LPC Message Types
//
typedef enum _LPC_TYPE
{
LPC_NEW_MESSAGE,
LPC_REQUEST,
LPC_REPLY,
LPC_DATAGRAM,
LPC_LOST_REPLY,
LPC_PORT_CLOSED,
LPC_CLIENT_DIED,
LPC_EXCEPTION,
LPC_DEBUG_EVENT,
LPC_ERROR_EVENT,
LPC_CONNECTION_REQUEST,
LPC_CONNECTION_REFUSED,
LPC_MAXIMUM
} LPC_TYPE;
//
// Information Classes for NtQueryInformationPort
//
typedef enum _PORT_INFORMATION_CLASS
{
PortNoInformation
} PORT_INFORMATION_CLASS;
#ifdef NTOS_MODE_USER
//
// Maximum message size that can be sent through an LPC Port without a section
//
#ifdef _WIN64
#define PORT_MAXIMUM_MESSAGE_LENGTH 512
#else
#define PORT_MAXIMUM_MESSAGE_LENGTH 256
#endif
//
// Portable LPC Types for 32/64-bit compatibility
//
#ifdef USE_LPC6432
#define LPC_CLIENT_ID CLIENT_ID64
#define LPC_SIZE_T ULONGLONG
#define LPC_PVOID ULONGLONG
#define LPC_HANDLE ULONGLONG
#else
#define LPC_CLIENT_ID CLIENT_ID
#define LPC_SIZE_T SIZE_T
#define LPC_PVOID PVOID
#define LPC_HANDLE HANDLE
#endif
//
// LPC Port Message
//
typedef struct _PORT_MESSAGE
{
union
{
struct
{
CSHORT DataLength;
CSHORT TotalLength;
} s1;
ULONG Length;
} u1;
union
{
struct
{
CSHORT Type;
CSHORT DataInfoOffset;
} s2;
ULONG ZeroInit;
} u2;
union
{
LPC_CLIENT_ID ClientId;
double DoNotUseThisField;
};
ULONG MessageId;
union
{
LPC_SIZE_T ClientViewSize;
ULONG CallbackId;
};
} PORT_MESSAGE, *PPORT_MESSAGE;
//
// Local and Remove Port Views
//
typedef struct _PORT_VIEW
{
ULONG Length;
LPC_HANDLE SectionHandle;
ULONG SectionOffset;
LPC_SIZE_T ViewSize;
LPC_PVOID ViewBase;
LPC_PVOID ViewRemoteBase;
} PORT_VIEW, *PPORT_VIEW;
typedef struct _REMOTE_PORT_VIEW
{
ULONG Length;
LPC_SIZE_T ViewSize;
LPC_PVOID ViewBase;
} REMOTE_PORT_VIEW, *PREMOTE_PORT_VIEW;
//
// LPC Kernel-Mode Message Structures defined for size only
//
typedef struct _LPCP_MESSAGE
{
UCHAR Data[0x14];
PORT_MESSAGE Request;
} LPCP_MESSAGE;
typedef struct _LPCP_CONNECTION_MESSAGE
{
UCHAR Data[0x2C];
} LPCP_CONNECTION_MESSAGE;
#else
//
// LPC Paged and Non-Paged Port Queues
//
typedef struct _LPCP_NONPAGED_PORT_QUEUE
{
KSEMAPHORE Semaphore;
struct _LPCP_PORT_OBJECT *BackPointer;
} LPCP_NONPAGED_PORT_QUEUE, *PLPCP_NONPAGED_PORT_QUEUE;
typedef struct _LPCP_PORT_QUEUE
{
PLPCP_NONPAGED_PORT_QUEUE NonPagedPortQueue;
PKSEMAPHORE Semaphore;
LIST_ENTRY ReceiveHead;
} LPCP_PORT_QUEUE, *PLPCP_PORT_QUEUE;
//typedef struct _TOKEN_SOURCE {
// CHAR SourceName[TOKEN_SOURCE_LENGTH];
// LUID SourceIdentifier;
//} TOKEN_SOURCE, *PTOKEN_SOURCE;
//typedef struct _TOKEN_CONTROL {
// LUID TokenId;
// LUID AuthenticationId;
// LUID ModifiedId;
// TOKEN_SOURCE TokenSource;
//} TOKEN_CONTROL, *PTOKEN_CONTROL;
//typedef struct _SECURITY_CLIENT_CONTEXT
//{
// SECURITY_QUALITY_OF_SERVICE SecurityQos;
// PVOID ClientToken;
// UCHAR DirectlyAccessClientToken;
// UCHAR DirectAccessEffectiveOnly;
// UCHAR ServerIsRemote;
// TOKEN_CONTROL ClientTokenControl;
//} SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT;
//
// LPC Port Object
//
typedef struct _LPCP_PORT_OBJECT
{
struct _LPCP_PORT_OBJECT *ConnectionPort;
struct _LPCP_PORT_OBJECT *ConnectedPort;
LPCP_PORT_QUEUE MsgQueue;
CLIENT_ID Creator;
PVOID ClientSectionBase;
PVOID ServerSectionBase;
PVOID PortContext;
PETHREAD ClientThread;
SECURITY_QUALITY_OF_SERVICE SecurityQos;
SECURITY_CLIENT_CONTEXT StaticSecurity;
LIST_ENTRY LpcReplyChainHead;
LIST_ENTRY LpcDataInfoChainHead;
union
{
PEPROCESS ServerProcess;
PEPROCESS MappingProcess;
};
ULONG MaxMessageLength;
ULONG MaxConnectionInfoLength;
ULONG Flags;
KEVENT WaitEvent;
} LPCP_PORT_OBJECT, *PLPCP_PORT_OBJECT;
typedef struct _PORT_MESSAGE
{
ULONG u1;
ULONG u2;
union
{
CLIENT_ID ClientId;
float DoNotUseThisField;
};
ULONG MessageId;
union
{
ULONG ClientViewSize;
ULONG CallbackId;
};
} PORT_MESSAGE, *PPORT_MESSAGE;
//
// LPC Kernel-Mode Message Structures
//
typedef struct _LPCP_MESSAGE
{
union
{
LIST_ENTRY Entry;
struct
{
SINGLE_LIST_ENTRY FreeEntry;
ULONG Reserved0;
};
};
PLPCP_PORT_OBJECT SenderPort;
PETHREAD RepliedToThread;
PVOID PortContext;
PORT_MESSAGE Request;
} LPCP_MESSAGE, *PLPCP_MESSAGE;
typedef struct _PORT_VIEW {
ULONG Length; // Size of this structure
HANDLE SectionHandle; // Handle to section object with
// SECTION_MAP_WRITE and SECTION_MAP_READ
ULONG SectionOffset; // The offset in the section to map a view for
// the port data area. The offset must be aligned
// with the allocation granularity of the system.
ULONG ViewSize; // The size of the view (in bytes)
PVOID ViewBase; // The base address of the view in the creator
//
PVOID ViewRemoteBase; // The base address of the view in the process
// connected to the port.
} PORT_VIEW, *PPORT_VIEW;
typedef struct _REMOTE_PORT_VIEW {
ULONG Length; // Size of this structure
ULONG ViewSize; // The size of the view (bytes)
PVOID ViewBase; // Base address of the view
} REMOTE_PORT_VIEW, *PREMOTE_PORT_VIEW;
typedef struct _LPCP_CONNECTION_MESSAGE
{
PORT_VIEW ClientView;
PLPCP_PORT_OBJECT ClientPort;
PVOID SectionToMap;
REMOTE_PORT_VIEW ServerView;
} LPCP_CONNECTION_MESSAGE, *PLPCP_CONNECTION_MESSAGE;
#endif
//
// Client Died LPC Message
//
typedef struct _CLIENT_DIED_MSG
{
PORT_MESSAGE h;
LARGE_INTEGER CreateTime;
} CLIENT_DIED_MSG, *PCLIENT_DIED_MSG;
//
// Maximum total Kernel-Mode LPC Message Structure Size
//
#define LPCP_MAX_MESSAGE_SIZE \
N_ROUND_UP(PORT_MAXIMUM_MESSAGE_LENGTH + \
sizeof(LPCP_MESSAGE) + \
sizeof(LPCP_CONNECTION_MESSAGE), 16)
//
// Maximum actual LPC Message Length
//
#define LPC_MAX_MESSAGE_LENGTH \
(LPCP_MAX_MESSAGE_SIZE - \
FIELD_OFFSET(LPCP_MESSAGE, Request))
//
// Maximum actual size of LPC Message Data
//
#define LPC_MAX_DATA_LENGTH \
(LPC_MAX_MESSAGE_LENGTH - \
sizeof(PORT_MESSAGE) - \
sizeof(LPCP_CONNECTION_MESSAGE))
#endif // _LPCTYPES_H