ReactOS 0.4.15-dev-7942-gd23573b
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:590
#define BufferSize
Definition: mmc.h:75
#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:362
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
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

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}
int Count
Definition: noreturn.cpp:7
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#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:4533

◆ 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:2433
_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
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
__wchar_t WCHAR
Definition: xmlstorage.h:180

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 366 of file connect.c.

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

202{
204 PIMAGE_NT_HEADERS NtHeader;
205
206 DPRINT("CsrClientConnectToServer: %lx %p\n", ServerId, ConnectionInfo);
207
208 /* Validate the Connection Info */
209 if (ConnectionInfo && (!ConnectionInfoSize || !*ConnectionInfoSize))
210 {
211 DPRINT1("Connection info given, but no length\n");
213 }
214
215 /* Check if we're inside a CSR Process */
217 {
218 /* Tell the client that we're already inside CSR */
219 if (ServerToServerCall) *ServerToServerCall = TRUE;
220 return STATUS_SUCCESS;
221 }
222
223 /*
224 * We might be in a CSR Process but not know it, if this is the first call.
225 * So let's find out.
226 */
227 if (!(NtHeader = RtlImageNtHeader(NtCurrentPeb()->ImageBaseAddress)))
228 {
229 /* The image isn't valid */
230 DPRINT1("Invalid image\n");
232 }
234
235 /* Now we can check if we are inside or not */
237 {
238 UNICODE_STRING CsrSrvName;
239 HANDLE hCsrSrv;
240 ANSI_STRING CsrServerRoutineName;
241
242 /* We're inside, so let's find csrsrv */
243 RtlInitUnicodeString(&CsrSrvName, L"csrsrv");
245 NULL,
246 &CsrSrvName,
247 &hCsrSrv);
248
249 /* Now get the Server to Server routine */
250 RtlInitAnsiString(&CsrServerRoutineName, "CsrCallServerFromServer");
252 &CsrServerRoutineName,
253 0L,
255
256 /* Use the local heap as port heap */
257 CsrPortHeap = RtlGetProcessHeap();
258
259 /* Tell the caller we're inside the server */
260 if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
261 return STATUS_SUCCESS;
262 }
263
264 /* Now check if connection info is given */
265 if (ConnectionInfo)
266 {
267 CSR_API_MESSAGE ApiMessage;
268 PCSR_CLIENT_CONNECT ClientConnect = &ApiMessage.Data.CsrClientConnect;
269 PCSR_CAPTURE_BUFFER CaptureBuffer;
270
271 /* Well, we're definitely in a client now */
273
274 /* Do we have a connection to CSR yet? */
275 if (!CsrApiPort)
276 {
277 /* No, set it up now */
278 Status = CsrpConnectToServer(ObjectDirectory);
279 if (!NT_SUCCESS(Status))
280 {
281 /* Failed */
282 DPRINT1("Failure to connect to CSR\n");
283 return Status;
284 }
285 }
286
287 /* Setup the connect message header */
288 ClientConnect->ServerId = ServerId;
289 ClientConnect->ConnectionInfoSize = *ConnectionInfoSize;
290
291 /* Setup a buffer for the connection info */
292 CaptureBuffer = CsrAllocateCaptureBuffer(1, ClientConnect->ConnectionInfoSize);
293 if (CaptureBuffer == NULL)
294 {
296 }
297
298 /* Capture the connection info data */
299 CsrCaptureMessageBuffer(CaptureBuffer,
300 ConnectionInfo,
301 ClientConnect->ConnectionInfoSize,
302 &ClientConnect->ConnectionInfo);
303
304 /* Return the allocated length */
305 *ConnectionInfoSize = ClientConnect->ConnectionInfoSize;
306
307 /* Call CSR */
308 Status = CsrClientCallServer(&ApiMessage,
309 CaptureBuffer,
311 sizeof(*ClientConnect));
312
313 /* Copy the updated connection info data back into the user buffer */
314 RtlMoveMemory(ConnectionInfo,
315 ClientConnect->ConnectionInfo,
316 *ConnectionInfoSize);
317
318 /* Free the capture buffer */
319 CsrFreeCaptureBuffer(CaptureBuffer);
320 }
321 else
322 {
323 /* No connection info, just return */
325 }
326
327 /* Let the caller know if this was server to server */
328 DPRINT("Status was: 0x%lx. Are we in server: 0x%x\n", Status, InsideCsrProcess);
329 if (ServerToServerCall) *ServerToServerCall = InsideCsrProcess;
330
331 return Status;
332}
#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
NTSTATUS NTAPI LdrGetDllHandle(_In_opt_ PWSTR DllPath, _In_opt_ PULONG DllCharacteristics, _In_ PUNICODE_STRING DllName, _Out_ PVOID *DllHandle)
Definition: ldrapi.c:810
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:829
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:359
#define L(x)
Definition: ntvdm.h:50
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
CSR_CLIENT_CONNECT CsrClientConnect
Definition: csrmsg.h:114
union _CSR_API_MESSAGE::@3486::@3488::@3490 Data
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:366
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by ConnectConsole(), and DllMain().

◆ CsrFreeCaptureBuffer()

◆ CsrGetProcessId()

HANDLE NTAPI CsrGetProcessId ( VOID  )

Definition at line 507 of file connect.c.

508{
509 return CsrProcessId;
510}
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:366

◆ 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:1342

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:183
static WCHAR Address[46]
Definition: ping.c:68
unsigned char * PUCHAR
Definition: typedefs.h:53
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ 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:1692
_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:317