ReactOS 0.4.17-dev-1196-gb6224c3
csr.h File Reference
#include "csrmsg.h"
Include dependency graph for csr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

NTSTATUS NTAPI CsrClientConnectToServer (_In_ PCWSTR ObjectDirectory, _In_ ULONG ServerId, _In_ PVOID ConnectionInfo, _Inout_ PULONG ConnectionInfoSize, _Out_ PBOOLEAN ServerToServerCall)
 
NTSTATUS NTAPI CsrClientCallServer (_Inout_ PCSR_API_MESSAGE ApiMessage, _Inout_opt_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ CSR_API_NUMBER ApiNumber, _In_ ULONG DataLength)
 
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer (_In_ ULONG ArgumentCount, _In_ ULONG BufferSize)
 
ULONG NTAPI CsrAllocateMessagePointer (_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ ULONG MessageLength, _Out_ PVOID *CapturedData)
 
VOID NTAPI CsrCaptureMessageBuffer (_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_opt_ PVOID MessageBuffer, _In_ ULONG MessageLength, _Out_ PVOID *CapturedData)
 
VOID NTAPI CsrFreeCaptureBuffer (_In_ _Frees_ptr_ PCSR_CAPTURE_BUFFER CaptureBuffer)
 
VOID NTAPI CsrCaptureMessageString (_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_opt_ PCSTR String, _In_ ULONG StringLength, _In_ ULONG MaximumLength, _Out_ PSTRING CapturedString)
 
VOID NTAPI CsrCaptureMessageUnicodeStringInPlace (_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _Inout_ PUNICODE_STRING String)
 
NTSTATUS NTAPI CsrCaptureMessageMultiUnicodeStringsInPlace (_Inout_ PCSR_CAPTURE_BUFFER *CaptureBuffer, _In_ ULONG StringsCount, _In_ PUNICODE_STRING *MessageStrings)
 
PLARGE_INTEGER NTAPI CsrCaptureTimeout (_In_ ULONG Milliseconds, _Out_ PLARGE_INTEGER Timeout)
 
VOID NTAPI CsrProbeForRead (_In_ PVOID Address, _In_ ULONG Length, _In_ ULONG Alignment)
 
VOID NTAPI CsrProbeForWrite (_In_ PVOID Address, _In_ ULONG Length, _In_ ULONG Alignment)
 
HANDLE NTAPI CsrGetProcessId (VOID)
 
NTSTATUS NTAPI CsrNewThread (VOID)
 
NTSTATUS NTAPI CsrIdentifyAlertableThread (VOID)
 
NTSTATUS NTAPI CsrSetPriorityClass (_In_ HANDLE Process, _Inout_ PULONG PriorityClass)
 

Function Documentation

◆ CsrAllocateCaptureBuffer()

PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer ( _In_ ULONG  ArgumentCount,
_In_ ULONG  BufferSize 
)

Definition at line 87 of file capture.c.

90{
91 PCSR_CAPTURE_BUFFER CaptureBuffer;
92 ULONG OffsetsArraySize;
94
95 /* Validate the argument count. Note that on server side, CSRSRV
96 * limits the count to MAXUSHORT; here we are a bit more lenient. */
97 if (ArgumentCount > (MAXLONG / sizeof(ULONG_PTR)))
98 return NULL;
99
100 OffsetsArraySize = ArgumentCount * sizeof(ULONG_PTR);
101
102 /*
103 * Validate the total buffer size.
104 * The total size of the header plus the pointer-offset array and the
105 * provided buffer, together with the alignment padding for each argument,
106 * must be less than MAXLONG aligned to 4-byte boundary.
107 */
108 MaximumSize = (MAXLONG & ~3) - FIELD_OFFSET(CSR_CAPTURE_BUFFER, PointerOffsetsArray);
109 if (OffsetsArraySize >= MaximumSize)
110 return NULL;
111 MaximumSize -= OffsetsArraySize;
112 if (BufferSize >= MaximumSize)
113 return NULL;
115 if ((ArgumentCount * 3) + 3 >= MaximumSize)
116 return NULL;
117
118 /* Add the size of the header and of the pointer-offset array */
119 BufferSize += FIELD_OFFSET(CSR_CAPTURE_BUFFER, PointerOffsetsArray) +
120 OffsetsArraySize;
121
122 /* Add the size of the alignment padding for each argument */
123 BufferSize += ArgumentCount * 3;
124
125 /* Align it to a 4-byte boundary */
126 BufferSize = (BufferSize + 3) & ~3;
127
128 /* Allocate memory from the port heap */
130 if (CaptureBuffer == NULL) return NULL;
131
132 /* Initialize the header */
133 CaptureBuffer->Size = BufferSize;
134 CaptureBuffer->PointerCount = 0;
135
136 /* Initialize the pointer-offset array */
137 RtlZeroMemory(CaptureBuffer->PointerOffsetsArray, OffsetsArraySize);
138
139 /* Point to the start of the free buffer */
140 CaptureBuffer->BufferEnd = (PVOID)((ULONG_PTR)CaptureBuffer->PointerOffsetsArray +
141 OffsetsArraySize);
142
143 /* Return the address of the buffer */
144 return CaptureBuffer;
145}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
#define BufferSize
Definition: mmc.h:75
_In_ ULONG BufferSize
Definition: dispmprt.h:490
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define ULONG_PTR
Definition: config.h:101
_In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PLARGE_INTEGER MaximumSize
Definition: mmfuncs.h:366
ULONG PointerCount
Definition: csrmsg.h:94
ULONG_PTR PointerOffsetsArray[ANYSIZE_ARRAY]
Definition: csrmsg.h:96
HANDLE CsrPortHeap
Definition: connect.c:29
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define MAXLONG
Definition: umtypes.h:116

Referenced by BaseCheckVDM(), CreateConsoleScreenBuffer(), CsrCaptureMessageMultiUnicodeStringsInPlace(), CsrClientConnectToServer(), DefineDosDeviceW(), DeviceEventWorker(), GetConsoleFontInfo(), GetConsoleProcessList(), GetNextVDMCommand(), GetVDMCurrentDirectories(), IntAddConsoleAlias(), IntAllocConsole(), IntAttachConsole(), IntExpungeConsoleCommandHistory(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasesLength(), IntGetConsoleAliasExes(), IntGetConsoleCommandHistory(), IntGetConsoleCommandHistoryLength(), IntGetConsoleInput(), IntGetConsoleTitle(), IntReadConsole(), IntReadConsoleOutput(), IntReadConsoleOutputCode(), IntRegisterConsoleIME(), IntSetConsoleNumberOfCommands(), IntSetConsoleTitle(), IntWriteConsole(), IntWriteConsoleInput(), IntWriteConsoleOutput(), IntWriteConsoleOutputCode(), RegisterConsoleVDM(), and SetVDMCurrentDirectories().

◆ CsrAllocateMessagePointer()

ULONG NTAPI CsrAllocateMessagePointer ( _Inout_ PCSR_CAPTURE_BUFFER  CaptureBuffer,
_In_ ULONG  MessageLength,
_Out_ PVOID *  CapturedData 
)

Definition at line 152 of file capture.c.

156{
157 if (MessageLength == 0)
158 {
159 *CapturedData = NULL;
160 CapturedData = NULL;
161 }
162 else
163 {
164 /* Set the capture data at our current available buffer */
165 *CapturedData = CaptureBuffer->BufferEnd;
166
167 /* Validate the size */
168 if (MessageLength >= MAXLONG) return 0;
169
170 /* Align it to a 4-byte boundary */
171 MessageLength = (MessageLength + 3) & ~3;
172
173 /* Move our available buffer beyond this space */
174 CaptureBuffer->BufferEnd = (PVOID)((ULONG_PTR)CaptureBuffer->BufferEnd + MessageLength);
175 }
176
177 /* Write down this pointer in the array and increase the count */
178 CaptureBuffer->PointerOffsetsArray[CaptureBuffer->PointerCount++] = (ULONG_PTR)CapturedData;
179
180 /* Return the aligned length */
181 return MessageLength;
182}

Referenced by CsrCaptureMessageBuffer(), CsrCaptureMessageString(), DefineDosDeviceW(), GetConsoleFontInfo(), GetConsoleProcessList(), GetNextVDMCommand(), GetVDMCurrentDirectories(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasExes(), IntGetConsoleCommandHistory(), IntGetConsoleInput(), IntGetConsoleTitle(), IntReadConsole(), IntReadConsoleOutput(), IntReadConsoleOutputCode(), and IntWriteConsoleOutput().

◆ CsrCaptureMessageBuffer()

VOID NTAPI CsrCaptureMessageBuffer ( _Inout_ PCSR_CAPTURE_BUFFER  CaptureBuffer,
_In_opt_ PVOID  MessageBuffer,
_In_ ULONG  MessageLength,
_Out_ PVOID *  CapturedData 
)

Definition at line 189 of file capture.c.

194{
195 /* Simply allocate a message pointer in the buffer */
196 CsrAllocateMessagePointer(CaptureBuffer, MessageLength, CapturedData);
197
198 /* Check if there was any data */
199 if (!MessageBuffer || !MessageLength) return;
200
201 /* Copy the data into the buffer */
202 RtlMoveMemory(*CapturedData, MessageBuffer, MessageLength);
203}
ULONG NTAPI CsrAllocateMessagePointer(_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ ULONG MessageLength, _Out_ PVOID *CapturedData)
Definition: capture.c:152
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264

Referenced by BaseCheckVDM(), CreateConsoleScreenBuffer(), CsrClientConnectToServer(), DeviceEventWorker(), IntAddConsoleAlias(), IntAllocConsole(), IntAttachConsole(), IntExpungeConsoleCommandHistory(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasesLength(), IntGetConsoleCommandHistory(), IntGetConsoleCommandHistoryLength(), IntRegisterConsoleIME(), IntSetConsoleNumberOfCommands(), IntSetConsoleTitle(), IntWriteConsole(), IntWriteConsoleInput(), IntWriteConsoleOutputCode(), RegisterConsoleVDM(), and SetVDMCurrentDirectories().

◆ CsrCaptureMessageMultiUnicodeStringsInPlace()

NTSTATUS NTAPI CsrCaptureMessageMultiUnicodeStringsInPlace ( _Inout_ PCSR_CAPTURE_BUFFER *  CaptureBuffer,
_In_ ULONG  StringsCount,
_In_ PUNICODE_STRING *  MessageStrings 
)

Definition at line 294 of file capture.c.

298{
299 ULONG Count;
300
301 if (!CaptureBuffer) return STATUS_INVALID_PARAMETER;
302
303 /* Allocate a new capture buffer if we don't have one already */
304 if (!*CaptureBuffer)
305 {
306 /* Compute the required size for the capture buffer */
307 ULONG Size = 0;
308
309 Count = 0;
310 while (Count < StringsCount)
311 {
312 if (MessageStrings[Count])
313 Size += MessageStrings[Count]->MaximumLength;
314
315 ++Count;
316 }
317
318 /* Allocate the capture buffer */
319 *CaptureBuffer = CsrAllocateCaptureBuffer(StringsCount, Size);
320 if (!*CaptureBuffer) return STATUS_NO_MEMORY;
321 }
322
323 /* Now capture each UNICODE string */
324 Count = 0;
325 while (Count < StringsCount)
326 {
327 if (MessageStrings[Count])
328 CsrCaptureMessageUnicodeStringInPlace(*CaptureBuffer, MessageStrings[Count]);
329
330 ++Count;
331 }
332
333 return STATUS_SUCCESS;
334}
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
int Count
Definition: noreturn.cpp:7
#define STATUS_SUCCESS
Definition: shellext.h:65
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer(_In_ ULONG ArgumentCount, _In_ ULONG BufferSize)
Definition: capture.c:87
VOID NTAPI CsrCaptureMessageUnicodeStringInPlace(_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _Inout_ PUNICODE_STRING String)
Definition: capture.c:271
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539

◆ CsrCaptureMessageString()

VOID NTAPI CsrCaptureMessageString ( _Inout_ PCSR_CAPTURE_BUFFER  CaptureBuffer,
_In_opt_ PCSTR  String,
_In_ ULONG  StringLength,
_In_ ULONG  MaximumLength,
_Out_ PSTRING  CapturedString 
)

Definition at line 222 of file capture.c.

228{
229 ASSERT(CapturedString != NULL);
230
231 /*
232 * If we don't have a string, initialize an empty one,
233 * otherwise capture the given string.
234 */
235 if (!String)
236 {
237 CapturedString->Length = 0;
238 CapturedString->MaximumLength = (USHORT)MaximumLength;
239
240 /* Allocate a pointer for it */
241 CsrAllocateMessagePointer(CaptureBuffer,
243 (PVOID*)&CapturedString->Buffer);
244 }
245 else
246 {
247 /* Cut-off the string length if needed */
248 if (StringLength > MaximumLength)
249 StringLength = MaximumLength;
250
251 CapturedString->Length = (USHORT)StringLength;
252
253 /* Allocate a buffer and get its size */
254 CapturedString->MaximumLength =
255 (USHORT)CsrAllocateMessagePointer(CaptureBuffer,
257 (PVOID*)&CapturedString->Buffer);
258
259 /* If the string has data, copy it into the buffer */
260 if (StringLength)
261 RtlMoveMemory(CapturedString->Buffer, String, StringLength);
262 }
263
264 /* Null-terminate the string if we don't take up the whole space */
265 if (CapturedString->Length < CapturedString->MaximumLength)
266 CapturedString->Buffer[CapturedString->Length] = ANSI_NULL;
267}
#define ASSERT(a)
Definition: mode.c:44
#define ANSI_NULL
unsigned short USHORT
Definition: pedump.c:61
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2439
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength

Referenced by CsrCaptureMessageUnicodeStringInPlace().

◆ CsrCaptureMessageUnicodeStringInPlace()

VOID NTAPI CsrCaptureMessageUnicodeStringInPlace ( _Inout_ PCSR_CAPTURE_BUFFER  CaptureBuffer,
_Inout_ PUNICODE_STRING  String 
)

Definition at line 271 of file capture.c.

274{
275 ASSERT(String != NULL);
276
277 /* This is a way to capture the UNICODE string, since (Maximum)Length are also in bytes */
278 CsrCaptureMessageString(CaptureBuffer,
279 (PCSTR)String->Buffer,
280 String->Length,
281 String->MaximumLength,
282 (PSTRING)String);
283
284 /* Null-terminate the string if we don't take up the whole space */
285 if (String->Length + sizeof(WCHAR) <= String->MaximumLength)
286 String->Buffer[String->Length / sizeof(WCHAR)] = UNICODE_NULL;
287}
#define UNICODE_NULL
short WCHAR
Definition: pedump.c:58
VOID NTAPI CsrCaptureMessageString(_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_opt_ PCSTR String, _In_ ULONG StringLength, _In_ ULONG MaximumLength, _Out_ PSTRING CapturedString)
Definition: capture.c:222
const char * PCSTR
Definition: typedefs.h:52

Referenced by CsrCaptureMessageMultiUnicodeStringsInPlace().

◆ CsrCaptureTimeout()

PLARGE_INTEGER NTAPI CsrCaptureTimeout ( _In_ ULONG  Milliseconds,
_Out_ PLARGE_INTEGER  Timeout 
)

Definition at line 341 of file capture.c.

344{
345 /* Validate the time */
346 if (Milliseconds == -1) return NULL;
347
348 /* Convert to relative ticks */
349 Timeout->QuadPart = Milliseconds * -10000LL;
350 return Timeout;
351}
static ULONG Timeout
Definition: ping.c:61

◆ CsrClientCallServer()

NTSTATUS NTAPI CsrClientCallServer ( _Inout_ PCSR_API_MESSAGE  ApiMessage,
_Inout_opt_ PCSR_CAPTURE_BUFFER  CaptureBuffer,
_In_ CSR_API_NUMBER  ApiNumber,
_In_ ULONG  DataLength 
)

Definition at line 368 of file connect.c.

373{
375
376 /* Make sure the length is valid */
377 if (DataLength > (MAXSHORT - sizeof(CSR_API_MESSAGE)))
378 {
379 DPRINT1("DataLength too big: %lu\n", DataLength);
381 }
382
383 /* Fill out the Port Message Header */
384 ApiMessage->Header.u2.ZeroInit = 0;
385 /* DataLength = user_data_size + anything between
386 * header and data, including intermediate padding */
387 ApiMessage->Header.u1.s1.DataLength = (CSHORT)DataLength +
388 FIELD_OFFSET(CSR_API_MESSAGE, Data) - sizeof(ApiMessage->Header);
389 /* TotalLength = header_size + DataLength + any structure trailing padding */
390 ApiMessage->Header.u1.s1.TotalLength = (CSHORT)DataLength +
391 sizeof(CSR_API_MESSAGE) - sizeof(ApiMessage->Data);
392
393 /* Fill out the CSR Header */
394 ApiMessage->ApiNumber = ApiNumber;
395 ApiMessage->CsrCaptureData = NULL;
396
397 DPRINT("API: %lx, u1.s1.DataLength: %x, u1.s1.TotalLength: %x\n",
398 ApiNumber,
399 ApiMessage->Header.u1.s1.DataLength,
400 ApiMessage->Header.u1.s1.TotalLength);
401
402 /* Check if we are already inside a CSR Server */
403 if (!InsideCsrProcess)
404 {
405 ULONG PointerCount;
406 PULONG_PTR OffsetPointer;
407
408 /* Check if we got a Capture Buffer */
409 if (CaptureBuffer)
410 {
411 /*
412 * We have to convert from our local (client) view
413 * to the remote (server) view.
414 */
415 ApiMessage->CsrCaptureData = (PCSR_CAPTURE_BUFFER)
416 ((ULONG_PTR)CaptureBuffer + CsrPortMemoryDelta);
417
418 /* Lock the buffer */
419 CaptureBuffer->BufferEnd = NULL;
420
421 /*
422 * Each client pointer inside the CSR message is converted into
423 * a server pointer, and each pointer to these message pointers
424 * is converted into an offset.
425 */
426 PointerCount = CaptureBuffer->PointerCount;
427 OffsetPointer = CaptureBuffer->PointerOffsetsArray;
428 while (PointerCount--)
429 {
430 if (*OffsetPointer != 0)
431 {
432 *(PULONG_PTR)*OffsetPointer += CsrPortMemoryDelta;
433 *OffsetPointer -= (ULONG_PTR)ApiMessage;
434 }
435 ++OffsetPointer;
436 }
437 }
438
439 /* Send the LPC Message */
441 &ApiMessage->Header,
442 &ApiMessage->Header);
443
444 /* Check if we got a Capture Buffer */
445 if (CaptureBuffer)
446 {
447 /*
448 * We have to convert back from the remote (server) view
449 * to our local (client) view.
450 */
451 ApiMessage->CsrCaptureData = (PCSR_CAPTURE_BUFFER)
452 ((ULONG_PTR)ApiMessage->CsrCaptureData - CsrPortMemoryDelta);
453
454 /*
455 * Convert back the offsets into pointers to CSR message
456 * pointers, and convert back these message server pointers
457 * into client pointers.
458 */
459 PointerCount = CaptureBuffer->PointerCount;
460 OffsetPointer = CaptureBuffer->PointerOffsetsArray;
461 while (PointerCount--)
462 {
463 if (*OffsetPointer != 0)
464 {
465 *OffsetPointer += (ULONG_PTR)ApiMessage;
466 *(PULONG_PTR)*OffsetPointer -= CsrPortMemoryDelta;
467 }
468 ++OffsetPointer;
469 }
470 }
471
472 /* Check for success */
473 if (!NT_SUCCESS(Status))
474 {
475 /* We failed. Overwrite the return value with the failure. */
476 DPRINT1("LPC Failed: %lx\n", Status);
477 ApiMessage->Status = Status;
478 }
479 }
480 else
481 {
482 /* This is a server-to-server call */
483 DPRINT("Server-to-server call\n");
484
485 /* Save our CID; we check this equality inside CsrValidateMessageBuffer */
486 ApiMessage->Header.ClientId = NtCurrentTeb()->ClientId;
487
488 /* Do a direct call */
489 Status = CsrServerApiRoutine(ApiMessage, ApiMessage);
490
491 /* Check for success */
492 if (!NT_SUCCESS(Status))
493 {
494 /* We failed. Overwrite the return value with the failure. */
495 ApiMessage->Status = Status;
496 }
497 }
498
499 /* Return the CSR Result */
500 DPRINT("Got back: 0x%lx\n", ApiMessage->Status);
501 return ApiMessage->Status;
502}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
struct _CSR_CAPTURE_BUFFER * PCSR_CAPTURE_BUFFER
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG DataLength
Definition: dispmprt.h:233
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:24
#define NtCurrentTeb
NTSTATUS NTAPI NtRequestWaitReplyPort(IN HANDLE PortHandle, IN PPORT_MESSAGE LpcRequest, IN OUT PPORT_MESSAGE LpcReply)
Definition: send.c:696
#define DPRINT
Definition: sndvol32.h:73
ULONG_PTR CsrPortMemoryDelta
Definition: connect.c:30
HANDLE CsrApiPort
Definition: connect.c:27
BOOLEAN InsideCsrProcess
Definition: connect.c:31
PCSR_SERVER_API_ROUTINE CsrServerApiRoutine
Definition: connect.c:38
uint32_t * PULONG_PTR
Definition: typedefs.h:65
#define MAXSHORT
Definition: umtypes.h:114
short CSHORT
Definition: umtypes.h:127

Referenced by BaseCheckForVDM(), BaseCheckVDM(), BasepNotifyCsrOfThread(), BaseUpdateVDMEntry(), CloseConsoleHandle(), ConsoleMenuControl(), CreateConsoleScreenBuffer(), CreateProcessInternalW(), CsrClientConnectToServer(), CsrIdentifyAlertableThread(), CsrSetPriorityClass(), DefineDosDeviceW(), DeviceEventWorker(), DuplicateConsoleHandle(), EndTask(), ExitProcess(), ExitVDM(), ExitWindowsWorker(), FlushConsoleInputBuffer(), FreeConsole(), GenerateConsoleCtrlEvent(), GetConsoleCP(), GetConsoleCursorInfo(), GetConsoleDisplayMode(), GetConsoleFontInfo(), GetConsoleFontSize(), GetConsoleHandleInformation(), GetConsoleHardwareState(), GetConsoleHistoryInfo(), GetConsoleMode(), GetConsoleOutputCP(), GetConsoleProcessList(), GetConsoleScreenBufferInfo(), GetConsoleSelectionInfo(), GetConsoleWindow(), GetCurrentConsoleFont(), GetLargestConsoleWindowSize(), GetNextVDMCommand(), GetNumberOfConsoleFonts(), GetNumberOfConsoleInputEvents(), GetNumberOfConsoleMouseButtons(), GetProcessShutdownParameters(), GetTempFileNameW(), GetThreadDesktop(), GetVDMCurrentDirectories(), IntAddConsoleAlias(), IntAllocConsole(), IntAttachConsole(), IntExpungeConsoleCommandHistory(), IntFillConsoleOutputCode(), IntGetConsoleAlias(), IntGetConsoleAliases(), IntGetConsoleAliasesLength(), IntGetConsoleAliasExes(), IntGetConsoleAliasExesLength(), IntGetConsoleCommandHistory(), IntGetConsoleCommandHistoryLength(), IntGetConsoleInput(), IntGetConsoleKeyboardLayoutName(), IntGetConsoleTitle(), IntReadConsole(), IntReadConsoleOutput(), IntReadConsoleOutputCode(), IntRegisterConsoleIME(), IntScrollConsoleScreenBuffer(), IntSetConsoleNumberOfCommands(), IntSetConsoleTitle(), IntUnregisterConsoleIME(), IntWriteConsole(), IntWriteConsoleInput(), IntWriteConsoleOutput(), IntWriteConsoleOutputCode(), InvalidateConsoleDIBits(), Logon(), NotifySoundSentry(), OpenConsoleW(), RegisterConsoleVDM(), RegisterLogonProcess(), RegisterServicesProcess(), SetConsoleActiveScreenBuffer(), SetConsoleCommandHistoryMode(), SetConsoleCP(), SetConsoleCursor(), SetConsoleCursorInfo(), SetConsoleCursorPosition(), SetConsoleDisplayMode(), SetConsoleFont(), SetConsoleHandleInformation(), SetConsoleHardwareState(), SetConsoleHistoryInfo(), SetConsoleIcon(), SetConsoleMenuClose(), SetConsoleMode(), SetConsoleOutputCP(), SetConsolePalette(), SetConsoleScreenBufferSize(), SetConsoleTextAttribute(), SetConsoleWindowInfo(), SetLastConsoleEventActive(), SetProcessShutdownParameters(), SetTEBLangID(), SetVDMCurrentDirectories(), ShowConsoleCursor(), and VerifyConsoleIoHandle().

◆ CsrClientConnectToServer()

NTSTATUS NTAPI CsrClientConnectToServer ( _In_ PCWSTR  ObjectDirectory,
_In_ ULONG  ServerId,
_In_ PVOID  ConnectionInfo,
_Inout_ PULONG  ConnectionInfoSize,
_Out_ PBOOLEAN  ServerToServerCall 
)

Definition at line 198 of file connect.c.

204{
206 PIMAGE_NT_HEADERS NtHeader;
207
208 DPRINT("CsrClientConnectToServer: %lx %p\n", ServerId, ConnectionInfo);
209
210 /* Validate the Connection Info */
211 if (ConnectionInfo && (!ConnectionInfoSize || !*ConnectionInfoSize))
212 {
213 DPRINT1("Connection info given, but no length\n");
215 }
216
217 /* Check if we're inside a CSR Process */
219 {
220 /* Tell the client that we're already inside CSR */
221 if (ServerToServerCall) *ServerToServerCall = TRUE;
222 return STATUS_SUCCESS;
223 }
224
225 /*
226 * We might be in a CSR Process but not know it, if this is the first call.
227 * So let's find out.
228 */
229 if (!(NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress)))
230 {
231 /* The image isn't valid */
232 DPRINT1("Invalid image\n");
234 }
236
237 /* Now we can check if we are inside or not */
239 {
240 UNICODE_STRING CsrSrvName;
241 HANDLE hCsrSrv;
242 ANSI_STRING CsrServerRoutineName;
243
244 /* We're inside, so let's find csrsrv */
245 RtlInitUnicodeString(&CsrSrvName, L"csrsrv");
247 NULL,
248 &CsrSrvName,
249 &hCsrSrv);
250
251 /* Now get the Server to Server routine */
252 RtlInitAnsiString(&CsrServerRoutineName, "CsrCallServerFromServer");
254 &CsrServerRoutineName,
255 0L,
257
258 /* Use the local heap as port heap */
259 CsrPortHeap = RtlGetProcessHeap();
260
261 /* Tell the caller we're inside the server */
262 if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
263 return STATUS_SUCCESS;
264 }
265
266 /* Now check if connection info is given */
267 if (ConnectionInfo)
268 {
269 CSR_API_MESSAGE ApiMessage;
270 PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage.Data.CsrClientConnect;
271 PCSR_CAPTURE_BUFFER CaptureBuffer;
272
273 /* Well, we're definitely in a client now */
275
276 /* Do we have a connection to CSR yet? */
277 if (!CsrApiPort)
278 {
279 /* No, set it up now */
280 Status = CsrpConnectToServer(ObjectDirectory);
281 if (!NT_SUCCESS(Status))
282 {
283 /* Failed */
284 DPRINT1("Failure to connect to CSR\n");
285 return Status;
286 }
287 }
288
289 /* Setup the connect message header */
290 ClientConnect->ServerId = ServerId;
291 ClientConnect->ConnectionInfoSize = *ConnectionInfoSize;
292
293 /* Setup a buffer for the connection info */
294 CaptureBuffer = CsrAllocateCaptureBuffer(1, ClientConnect->ConnectionInfoSize);
295 if (CaptureBuffer == NULL)
296 {
298 }
299
300 /* Capture the connection info data */
301 CsrCaptureMessageBuffer(CaptureBuffer,
302 ConnectionInfo,
303 ClientConnect->ConnectionInfoSize,
304 &ClientConnect->ConnectionInfo);
305
306 /* Return the allocated length */
307 *ConnectionInfoSize = ClientConnect->ConnectionInfoSize;
308
309 /* Call CSR */
310 Status = CsrClientCallServer(&ApiMessage,
311 CaptureBuffer,
313 sizeof(*ClientConnect));
314
315 /* Copy the updated connection info data back into the user buffer */
316 RtlMoveMemory(ConnectionInfo,
317 ClientConnect->ConnectionInfo,
318 *ConnectionInfoSize);
319
320 /* Free the capture buffer */
321 CsrFreeCaptureBuffer(CaptureBuffer);
322 }
323 else
324 {
325 /* No connection info, just return */
327 }
328
329 /* Let the caller know if this was server to server */
330 DPRINT("Status was: 0x%lx. Are we in server: 0x%x\n", Status, InsideCsrProcess);
331 if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
332
333 return Status;
334}
#define NtCurrentPeb()
Definition: FLS.c:22
#define CSR_CREATE_API_NUMBER(ServerId, ApiId)
Definition: csrmsg.h:37
#define CSRSRV_SERVERDLL_INDEX
Definition: csrmsg.h:20
@ CsrpClientConnect
Definition: csrmsg.h:25
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define RtlImageNtHeader
Definition: compat.h:806
#define L(x)
Definition: resources.c:13
NTSTATUS NTAPI LdrGetDllHandle(_In_opt_ PWSTR DllPath, _In_opt_ PULONG DllCharacteristics, _In_ PUNICODE_STRING DllName, _Out_ PVOID *DllHandle)
Definition: ldrapi.c:770
NTSTATUS NTAPI LdrGetProcedureAddress(_In_ PVOID BaseAddress, _In_opt_ _When_(Ordinal==0, _Notnull_) PANSI_STRING Name, _In_opt_ _When_(Name==NULL, _In_range_(>, 0)) ULONG Ordinal, _Out_ PVOID *ProcedureAddress)
Definition: ldrapi.c:789
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:453
PCSR_CAPTURE_BUFFER NTAPI CsrAllocateCaptureBuffer(_In_ ULONG ArgumentCount, _In_ ULONG BufferSize)
Definition: capture.c:87
VOID NTAPI CsrFreeCaptureBuffer(_In_ _Frees_ptr_ PCSR_CAPTURE_BUFFER CaptureBuffer)
Definition: capture.c:210
VOID NTAPI CsrCaptureMessageBuffer(_Inout_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_opt_ PVOID MessageBuffer, _In_ ULONG MessageLength, _Out_ PVOID *CapturedData)
Definition: capture.c:189
union _CSR_API_MESSAGE::@4310::@4312::@4314 Data
CSR_CLIENT_CONNECT CsrClientConnect
Definition: csrmsg.h:114
ULONG ConnectionInfoSize
Definition: csrmsg.h:87
PVOID ConnectionInfo
Definition: csrmsg.h:86
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
static NTSTATUS CsrpConnectToServer(_In_ PCWSTR ObjectDirectory)
Definition: connect.c:43
NTSTATUS NTAPI CsrClientCallServer(_Inout_ PCSR_API_MESSAGE ApiMessage, _Inout_opt_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ CSR_API_NUMBER ApiNumber, _In_ ULONG DataLength)
Definition: connect.c:368
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by ConnectConsole(), and DllMain().

◆ CsrFreeCaptureBuffer()

◆ CsrGetProcessId()

HANDLE NTAPI CsrGetProcessId ( VOID  )

Definition at line 509 of file connect.c.

510{
511 return CsrProcessId;
512}
HANDLE CsrProcessId
Definition: connect.c:28

Referenced by ProcessIdToHandle().

◆ CsrIdentifyAlertableThread()

NTSTATUS NTAPI CsrIdentifyAlertableThread ( VOID  )

Definition at line 37 of file api.c.

38{
39#if (NTDDI_VERSION < NTDDI_WS03)
41 CSR_API_MESSAGE ApiMessage;
42 PCSR_IDENTIFY_ALERTABLE_THREAD IdentifyAlertableThread;
43
44 /* Set up the data for CSR */
45 IdentifyAlertableThread = &ApiMessage.Data.IdentifyAlertableThread;
46 IdentifyAlertableThread->Cid = NtCurrentTeb()->ClientId;
47
48 /* Call it */
49 Status = CsrClientCallServer(&ApiMessage,
50 NULL,
52 sizeof(*IdentifyAlertableThread));
53
54 /* Return to caller */
55 return Status;
56#else
57 /* Deprecated */
58 return STATUS_SUCCESS;
59#endif
60}
@ CsrpIdentifyAlertableThread
Definition: csrmsg.h:28
NTSTATUS NTAPI CsrClientCallServer(_Inout_ PCSR_API_MESSAGE ApiMessage, _Inout_opt_ PCSR_CAPTURE_BUFFER CaptureBuffer, _In_ CSR_API_NUMBER ApiNumber, _In_ ULONG DataLength)
Definition: connect.c:368

◆ CsrNewThread()

NTSTATUS NTAPI CsrNewThread ( VOID  )

Definition at line 26 of file api.c.

27{
28 /* Register the termination port to CSR's */
30}
NTSTATUS NTAPI NtRegisterThreadTerminatePort(IN HANDLE PortHandle)
Definition: kill.c:1378

Referenced by BaseThreadStartup(), and DllMain().

◆ CsrProbeForRead()

VOID NTAPI CsrProbeForRead ( _In_ PVOID  Address,
_In_ ULONG  Length,
_In_ ULONG  Alignment 
)

Definition at line 23 of file capture.c.

27{
28 volatile UCHAR *Pointer;
29 UCHAR Data;
30
31 /* Validate length */
32 if (Length == 0) return;
33
34 /* Validate alignment */
35 if ((ULONG_PTR)Address & (Alignment - 1))
36 {
37 /* Raise exception if it doesn't match */
39 }
40
41 /* Probe first byte */
42 Pointer = Address;
43 Data = *Pointer;
44
45 /* Probe last byte */
46 Pointer = (PUCHAR)Address + Length - 1;
47 Data = *Pointer;
48 (void)Data;
49}
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:263
static WCHAR Address[46]
Definition: ping.c:68
unsigned char UCHAR
Definition: typedefs.h:53
unsigned char * PUCHAR
Definition: typedefs.h:53

◆ CsrProbeForWrite()

VOID NTAPI CsrProbeForWrite ( _In_ PVOID  Address,
_In_ ULONG  Length,
_In_ ULONG  Alignment 
)

Definition at line 56 of file capture.c.

60{
61 volatile UCHAR *Pointer;
62
63 /* Validate length */
64 if (Length == 0) return;
65
66 /* Validate alignment */
67 if ((ULONG_PTR)Address & (Alignment - 1))
68 {
69 /* Raise exception if it doesn't match */
71 }
72
73 /* Probe first byte */
74 Pointer = Address;
75 *Pointer = *Pointer;
76
77 /* Probe last byte */
78 Pointer = (PUCHAR)Address + Length - 1;
79 *Pointer = *Pointer;
80}

◆ CsrSetPriorityClass()

NTSTATUS NTAPI CsrSetPriorityClass ( _In_ HANDLE  Process,
_Inout_ PULONG  PriorityClass 
)

Definition at line 67 of file api.c.

70{
71#if (NTDDI_VERSION < NTDDI_WS03)
73 CSR_API_MESSAGE ApiMessage;
74 PCSR_SET_PRIORITY_CLASS SetPriorityClass = &ApiMessage.Data.SetPriorityClass;
75
76 /* Set up the data for CSR */
77 SetPriorityClass->hProcess = Process;
78 SetPriorityClass->PriorityClass = *PriorityClass;
79
80 /* Call it */
81 Status = CsrClientCallServer(&ApiMessage,
82 NULL,
84 sizeof(*SetPriorityClass));
85
86 /* Return what we got, if requested */
87 if (*PriorityClass) *PriorityClass = SetPriorityClass->PriorityClass;
88
89 /* Return to caller */
90 return Status;
91#else
93 UNREFERENCED_PARAMETER(PriorityClass);
94
95 /* Deprecated */
97#endif
98}
@ CsrpSetPriorityClass
Definition: csrmsg.h:29
BOOL WINAPI SetPriorityClass(IN HANDLE hProcess, IN DWORD dwPriorityClass)
Definition: proc.c:1593
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329