mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
[WIN32CSR]
- Fix CSR hard error messages. Parameters are now converted to ANSI string which are expected by message format string. svn path=/trunk/; revision=52619
This commit is contained in:
parent
c93b41ab3f
commit
f9f36696f9
1 changed files with 73 additions and 53 deletions
|
@ -106,6 +106,25 @@ CsrpGetClientFileName(
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
VOID
|
||||||
|
CsrpFreeStringParameters(
|
||||||
|
IN OUT PULONG_PTR Parameters,
|
||||||
|
IN PHARDERROR_MSG HardErrorMessage)
|
||||||
|
{
|
||||||
|
ULONG nParam;
|
||||||
|
|
||||||
|
/* Loop all parameters */
|
||||||
|
for (nParam = 0; nParam < HardErrorMessage->NumberOfParameters; nParam++)
|
||||||
|
{
|
||||||
|
/* Check if the current parameter is a string */
|
||||||
|
if (HardErrorMessage->UnicodeStringParameterMask & (1 << nParam) && Parameters[nParam])
|
||||||
|
{
|
||||||
|
/* Free the string buffer */
|
||||||
|
RtlFreeHeap(RtlGetProcessHeap(), 0, (PVOID)Parameters[nParam]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
@ -115,62 +134,82 @@ CsrpCaptureStringParameters(
|
||||||
IN PHARDERROR_MSG HardErrorMessage,
|
IN PHARDERROR_MSG HardErrorMessage,
|
||||||
HANDLE hProcess)
|
HANDLE hProcess)
|
||||||
{
|
{
|
||||||
ULONG nParam, UnicodeStringParameterMask, Size = 0;
|
ULONG nParam, Size = 0;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
UNICODE_STRING TempStringU;
|
UNICODE_STRING TempStringU, ParamStringU;
|
||||||
CHAR *ParamString;
|
ANSI_STRING TempStringA;
|
||||||
|
|
||||||
UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask;
|
|
||||||
|
|
||||||
/* Read all strings from client space */
|
/* Read all strings from client space */
|
||||||
for (nParam = 0;
|
for (nParam = 0; nParam < HardErrorMessage->NumberOfParameters; nParam++)
|
||||||
nParam < HardErrorMessage->NumberOfParameters;
|
|
||||||
nParam++, UnicodeStringParameterMask >>= 1)
|
|
||||||
{
|
{
|
||||||
Parameters[nParam] = 0;
|
Parameters[nParam] = 0;
|
||||||
|
|
||||||
/* Check if the current parameter is a unicode string */
|
/* Check if the current parameter is a unicode string */
|
||||||
if (UnicodeStringParameterMask & 0x01)
|
if (HardErrorMessage->UnicodeStringParameterMask & (1 << nParam))
|
||||||
{
|
{
|
||||||
/* Read the UNICODE_STRING from the process memory */
|
/* Read the UNICODE_STRING from the process memory */
|
||||||
Status = NtReadVirtualMemory(hProcess,
|
Status = NtReadVirtualMemory(hProcess,
|
||||||
(PVOID)HardErrorMessage->Parameters[nParam],
|
(PVOID)HardErrorMessage->Parameters[nParam],
|
||||||
&TempStringU,
|
&ParamStringU,
|
||||||
sizeof(TempStringU),
|
sizeof(ParamStringU),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status)) return Status;
|
if (!NT_SUCCESS(Status))
|
||||||
|
break;
|
||||||
|
|
||||||
/* Allocate a buffer for the string */
|
/* Allocate a buffer for the string */
|
||||||
ParamString = RtlAllocateHeap(RtlGetProcessHeap(),
|
TempStringU.MaximumLength = ParamStringU.Length;
|
||||||
HEAP_ZERO_MEMORY,
|
TempStringU.Length = ParamStringU.Length;
|
||||||
TempStringU.Length + sizeof(WCHAR));
|
TempStringU.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
TempStringU.MaximumLength);
|
||||||
|
|
||||||
if (!ParamString)
|
if (!TempStringU.Buffer)
|
||||||
{
|
{
|
||||||
DPRINT1("Cannot allocate memory %d\n", TempStringU.Length);
|
DPRINT1("Cannot allocate memory %u\n", TempStringU.MaximumLength);
|
||||||
return STATUS_NO_MEMORY;
|
Status = STATUS_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the string buffer from the process memory */
|
/* Read the string buffer from the process memory */
|
||||||
Status = NtReadVirtualMemory(hProcess,
|
Status = NtReadVirtualMemory(hProcess,
|
||||||
|
ParamStringU.Buffer,
|
||||||
TempStringU.Buffer,
|
TempStringU.Buffer,
|
||||||
ParamString,
|
ParamStringU.Length,
|
||||||
TempStringU.Length,
|
|
||||||
NULL);
|
NULL);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
DPRINT1("NtReadVirtualMemory failed with code: %lx\n", Status);
|
DPRINT1("NtReadVirtualMemory failed with code: %lx\n", Status);
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, ParamString);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, TempStringU.Buffer);
|
||||||
return Status;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Zero terminate the string */
|
DPRINT("ParamString=\'%wZ\'\n", &TempStringU);
|
||||||
ParamString[TempStringU.Length] = 0;
|
|
||||||
ParamString[TempStringU.Length + 1] = 0;
|
|
||||||
DPRINT("ParamString=\'%S\'\n", ParamString);
|
|
||||||
|
|
||||||
Parameters[nParam] = (ULONG_PTR)ParamString;
|
/* Allocate a buffer for converted to ANSI string */
|
||||||
|
TempStringA.MaximumLength = RtlUnicodeStringToAnsiSize(&TempStringU);
|
||||||
|
TempStringA.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
TempStringA.MaximumLength);
|
||||||
|
|
||||||
|
if (!TempStringA.Buffer)
|
||||||
|
{
|
||||||
|
DPRINT1("Cannot allocate memory %u\n", TempStringA.MaximumLength);
|
||||||
|
RtlFreeHeap(RtlGetProcessHeap(), 0, TempStringU.Buffer);
|
||||||
|
Status = STATUS_NO_MEMORY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert string to ANSI and free temporary buffer */
|
||||||
|
Status = RtlUnicodeStringToAnsiString(&TempStringA, &TempStringU, FALSE);
|
||||||
|
RtlFreeHeap(RtlGetProcessHeap(), 0, TempStringU.Buffer);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
RtlFreeHeap(RtlGetProcessHeap(), 0, TempStringA.Buffer);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Note: RtlUnicodeStringToAnsiString returns NULL terminated string */
|
||||||
|
Parameters[nParam] = (ULONG_PTR)TempStringA.Buffer;
|
||||||
Size += TempStringU.Length;
|
Size += TempStringU.Length;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -180,34 +219,15 @@ CsrpCaptureStringParameters(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*SizeOfAllUnicodeStrings = Size;
|
if (!NT_SUCCESS(Status))
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static
|
|
||||||
VOID
|
|
||||||
CsrpFreeStringParameters(
|
|
||||||
IN OUT PULONG_PTR Parameters,
|
|
||||||
IN PHARDERROR_MSG HardErrorMessage)
|
|
||||||
{
|
|
||||||
ULONG nParam, UnicodeStringParameterMask;
|
|
||||||
|
|
||||||
UnicodeStringParameterMask = HardErrorMessage->UnicodeStringParameterMask;
|
|
||||||
|
|
||||||
/* Loop all parameters */
|
|
||||||
for (nParam = 0;
|
|
||||||
nParam < HardErrorMessage->NumberOfParameters;
|
|
||||||
nParam++, UnicodeStringParameterMask >>= 1)
|
|
||||||
{
|
{
|
||||||
/* Check if the current parameter is a string */
|
CsrpFreeStringParameters(Parameters, HardErrorMessage);
|
||||||
if (UnicodeStringParameterMask & 0x01)
|
return Status;
|
||||||
{
|
|
||||||
/* Free the string buffer */
|
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, (PVOID)Parameters[nParam]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
*SizeOfAllUnicodeStrings = Size;
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
|
Loading…
Reference in a new issue