* PROJECT: ReactOS kernel
* FILE: dll/ntdll/csr/capture.c
* PURPOSE: Routines for probing and capturing CSR API Messages
- * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
+ * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
+ * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
*/
/* INCLUDES *******************************************************************/
NTAPI
CsrAllocateMessagePointer(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer,
IN ULONG MessageLength,
- OUT PVOID *CapturedData)
+ OUT PVOID* CapturedData)
{
if (MessageLength == 0)
{
CsrCaptureMessageBuffer(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer,
IN PVOID MessageBuffer OPTIONAL,
IN ULONG MessageLength,
- OUT PVOID *CapturedData)
+ OUT PVOID* CapturedData)
{
/* Simply allocate a message pointer in the buffer */
CsrAllocateMessagePointer(CaptureBuffer, MessageLength, CapturedData);
RtlFreeHeap(CsrPortHeap, 0, CaptureBuffer);
}
-/*
- * @unimplemented
- */
-NTSTATUS
-NTAPI
-CsrCaptureMessageMultiUnicodeStringsInPlace(IN PCSR_CAPTURE_BUFFER *CaptureBuffer,
- IN ULONG MessageCount,
- IN PVOID MessageStrings)
-{
- /* FIXME: allocate a buffer if we don't have one, and return it */
- /* FIXME: call CsrCaptureMessageUnicodeStringInPlace for each string */
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
-}
-
/*
* @implemented
*/
VOID
NTAPI
CsrCaptureMessageString(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer,
- IN LPSTR String OPTIONAL,
+ IN PCSTR String OPTIONAL,
IN ULONG StringLength,
IN ULONG MaximumLength,
- OUT PANSI_STRING CapturedString)
+ OUT PSTRING CapturedString)
{
- ULONG ReturnedLength;
+ ASSERT(CapturedString != NULL);
- /* If we don't have a string, initialize an empty one */
+ /*
+ * If we don't have a string, initialize an empty one,
+ * otherwise capture the given string.
+ */
if (!String)
{
CapturedString->Length = 0;
CsrAllocateMessagePointer(CaptureBuffer,
MaximumLength,
(PVOID*)&CapturedString->Buffer);
- return;
+ }
+ else
+ {
+ /* Cut-off the string length if needed */
+ if (StringLength > MaximumLength)
+ StringLength = MaximumLength;
+
+ CapturedString->Length = (USHORT)StringLength;
+
+ /* Allocate a buffer and get its size */
+ CapturedString->MaximumLength =
+ (USHORT)CsrAllocateMessagePointer(CaptureBuffer,
+ MaximumLength,
+ (PVOID*)&CapturedString->Buffer);
+
+ /* If the string has data, copy it into the buffer */
+ if (StringLength)
+ RtlMoveMemory(CapturedString->Buffer, String, StringLength);
}
- /* Initialize this string */
- CapturedString->Length = (USHORT)StringLength;
+ /* Null-terminate the string if we don't take up the whole space */
+ if (CapturedString->Length < CapturedString->MaximumLength)
+ CapturedString->Buffer[CapturedString->Length] = '\0';
+}
- /* Allocate a buffer and get its size */
- ReturnedLength = CsrAllocateMessagePointer(CaptureBuffer,
- MaximumLength,
- (PVOID*)&CapturedString->Buffer);
- CapturedString->MaximumLength = (USHORT)ReturnedLength;
+static VOID
+CsrCaptureMessageUnicodeStringInPlace(IN OUT PCSR_CAPTURE_BUFFER CaptureBuffer,
+ IN PUNICODE_STRING String)
+{
+ ASSERT(String != NULL);
+
+ /* This is a way to capture the UNICODE string, since (Maximum)Length are also in bytes */
+ CsrCaptureMessageString(CaptureBuffer,
+ (PCSTR)String->Buffer,
+ String->Length,
+ String->MaximumLength,
+ (PSTRING)String);
- /* If the string had data */
- if (StringLength)
+ /* Null-terminate the string */
+ if (String->MaximumLength >= String->Length + sizeof(WCHAR))
{
- /* Copy it into the capture buffer */
- RtlMoveMemory(CapturedString->Buffer, String, MaximumLength);
+ String->Buffer[String->Length / sizeof(WCHAR)] = L'\0';
+ }
+}
- /* If we don't take up the whole space */
- if (CapturedString->Length < CapturedString->MaximumLength)
+/*
+ * @implemented
+ */
+NTSTATUS
+NTAPI
+CsrCaptureMessageMultiUnicodeStringsInPlace(OUT PCSR_CAPTURE_BUFFER* CaptureBuffer,
+ IN ULONG StringsCount,
+ IN PUNICODE_STRING* MessageStrings)
+{
+ ULONG Count;
+
+ if (!CaptureBuffer) return STATUS_INVALID_PARAMETER;
+
+ /* Allocate a new capture buffer if we don't have one already */
+ if (!*CaptureBuffer)
+ {
+ /* Compute the required size for the capture buffer */
+ ULONG Size = 0;
+
+ Count = 0;
+ while (Count < StringsCount)
{
- /* Null-terminate it */
- CapturedString->Buffer[CapturedString->Length] = '\0';
+ if (MessageStrings[Count])
+ Size += MessageStrings[Count]->MaximumLength;
+
+ ++Count;
}
+
+ /* Allocate the capture buffer */
+ *CaptureBuffer = CsrAllocateCaptureBuffer(StringsCount, Size);
+ if (!*CaptureBuffer) return STATUS_NO_MEMORY;
+ }
+
+ /* Now capture each UNICODE string */
+ Count = 0;
+ while (Count < StringsCount)
+ {
+ if (MessageStrings[Count])
+ CsrCaptureMessageUnicodeStringInPlace(*CaptureBuffer, MessageStrings[Count]);
+
+ ++Count;
}
+
+ return STATUS_SUCCESS;
}
/*
if (Milliseconds == -1) return NULL;
/* Convert to relative ticks */
- Timeout->QuadPart = Int32x32To64(Milliseconds, -10000);
+ Timeout->QuadPart = Milliseconds * -10000LL;
return Timeout;
}