373{
374
375 static const PCWSTR pszUnknownHardError =
376 L"Unknown Hard Error 0x%08lx\n"
377 L"Parameters: 0x%p 0x%p 0x%p 0x%p";
378 static const PCWSTR pszExceptionHardError =
379 L"Exception processing message 0x%08lx\n"
380 L"Parameters: 0x%p 0x%p 0x%p 0x%p";
381
389 UNICODE_STRING WindowTitleU, FileNameU, TempStringU, FormatU, Format2U;
394 size_t cszBuffer;
395
396
403 {
404 DPRINT1(
"NtOpenProcess failed with status 0x%08lx, possibly SYSTEM process.\n",
Status);
406 }
407
408
410
411
412 TextStringU->Length = 0;
414
415 CaptionStringU->Length = 0;
417
418
419
420
421
423 {
424
426
427
428
429
430
431
433
434
435
436
437
438
439 if (
Message->UnicodeStringParameterMask & 0x1)
441 if (
Message->UnicodeStringParameterMask & 0x2)
443
444
445 if (
Message->NumberOfParameters >= 4)
447 else
449
450 goto Quit;
451 }
452
453
454 *pdwType = 0;
455 switch (
Message->ValidResponseOptions)
456 {
459 break;
462 break;
465 break;
468 break;
471 break;
474 break;
477 break;
480 break;
483 break;
484 }
485
486
487
491
493
494
496
497
499
500
504
505
507
508
509
510
511
513 {
516 }
517
518
524 &MessageResource);
526 {
527 if (MessageResource->
Flags)
528 {
531 }
532 else
533 {
536 }
538 }
539 else
540 {
541
542
543
544
545
546
547 RtlInitEmptyUnicodeString(&FormatU,
NULL, 0);
549 }
550
552
553
555 {
556
558
559
560 for (TempStringU.
Length = 0;
563 {
565 }
566
567
569
572 }
573 else
574 {
583 else
585 }
586
587
588 RtlInitEmptyUnicodeString(&WindowTitleU,
L"", 0);
592 if (hwndOwner)
593 {
595 if (cszBuffer != 0)
596 {
597 cszBuffer += 3;
598 cszBuffer *=
sizeof(
WCHAR);
601 cszBuffer);
602 if (pszBuffer)
603 {
604 RtlInitEmptyUnicodeString(&WindowTitleU, pszBuffer, (
USHORT)cszBuffer);
610 }
611 }
612 }
613
614
617 if (CaptionStringU->MaximumLength < cszBuffer)
618 {
619
622 cszBuffer);
623 if (!pszBuffer)
624 {
625
626 DPRINT1(
"Cannot allocate memory for CaptionStringU, use original buffer.\n");
627 }
628 else
629 {
630 RtlInitEmptyUnicodeString(CaptionStringU, pszBuffer, (
USHORT)cszBuffer);
631 }
632 }
633 CaptionStringU->Length = 0;
635
636
638 CaptionStringU->MaximumLength,
640 &WindowTitleU, &FileNameU, &TempStringU);
641 CaptionStringU->Length = (
USHORT)(
wcslen(CaptionStringU->Buffer) *
sizeof(
WCHAR));
642
643
648
650
651
653 goto BuildMessage;
654
655
657 {
659
660
665 &MessageResource);
667 {
668 if (MessageResource->
Flags)
669 {
672 }
673 else
674 {
677 }
679
680
682 {
683
685 CopyParameters[0] = CopyParameters[1];
686 CopyParameters[1] = CopyParameters[3];
687 if (CopyParameters[2])
689 else
691 }
693 {
694
696 CopyParameters[0] = CopyParameters[1];
697 CopyParameters[1] = CopyParameters[3];
698 }
699 else
700 {
701
702 CopyParameters[2] = CopyParameters[1];
703 CopyParameters[1] = CopyParameters[0];
704
705 pszBuffer = Format2U.
Buffer;
706 if (!
_wcsnicmp(pszBuffer,
L"{EXCEPTION}", 11))
707 {
708
709
710
711
712 pszBuffer += 11;
713
714
715 pszBuffer += 2;
716
717 CopyParameters[0] = (
ULONG_PTR)pszBuffer;
718 }
719 else
720 {
721
722 CopyParameters[0] = (
ULONG_PTR)
L"unknown software exception";
723 }
724 }
725 }
726 else
727 {
728
729 CopyParameters[2] = CopyParameters[1];
730 CopyParameters[1] = CopyParameters[0];
731 CopyParameters[0] = (
ULONG_PTR)
L"unknown software exception";
732 }
733 }
734
735BuildMessage:
736
737
738
739
740
741 cszBuffer = 0;
742
744 {
746 {
747
752 cszBuffer *=
sizeof(
WCHAR);
753 }
754 else
755 {
757 CopyParameters[0], CopyParameters[1],
758 CopyParameters[2], CopyParameters[3]);
759 cszBuffer *=
sizeof(
WCHAR);
760
761
763 {
766 {
767
769 }
771 {
772
774 }
775 }
776 }
777 }
779 {
780
785 cszBuffer *=
sizeof(
WCHAR);
786 }
788
790
791 if (TextStringU->MaximumLength < cszBuffer)
792 {
793
796 cszBuffer);
797 if (!pszBuffer)
798 {
799
800 DPRINT1(
"Cannot allocate memory for TextStringU, use original buffer.\n");
801 }
802 else
803 {
804 RtlInitEmptyUnicodeString(TextStringU, pszBuffer, (
USHORT)cszBuffer);
805 }
806 }
807 TextStringU->Length = 0;
809
810
812 {
813
814 pszBuffer = TextStringU->Buffer;
815 cszBuffer = TextStringU->MaximumLength;
816
818 {
819
821 pszUnknownHardError,
825 }
826 else
827 {
829 &pszBuffer, &cszBuffer,
830 0,
832 CopyParameters[0], CopyParameters[1],
833 CopyParameters[2], CopyParameters[3]);
834
835
837 {
840 {
842 &pszBuffer, &cszBuffer,
843 0,
846 }
848 {
850 &pszBuffer, &cszBuffer,
851 0,
854 }
855 }
856 }
857 }
859 {
860
861 DPRINT1(
"Exception 0x%08lx occurred while building hard-error message, fall back to default message.\n",
863
865 TextStringU->MaximumLength,
866 pszExceptionHardError,
870 }
872
874
875
878
879Quit:
880
882}
_Inout_ PIRP _In_ NTSTATUS ExceptionCode
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
#define STATUS_SEVERITY_WARNING
#define STATUS_SEVERITY_ERROR
#define STATUS_SEVERITY_INFORMATIONAL
#define STATUS_SEVERITY_SUCCESS
DWORD FormatString(DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
static VOID UserpCaptureStringParameters(OUT PULONG_PTR Parameters, OUT PULONG SizeOfAllUnicodeStrings, IN PHARDERROR_MSG Message, IN HANDLE hProcess OPTIONAL)
int __cdecl _scwprintf(const wchar_t *format,...)
static NTSTATUS UserpGetClientFileName(OUT PUNICODE_STRING ClientFileNameU, IN HANDLE hProcess)
static VOID UserpDuplicateParamStringToUnicodeString(IN OUT PUNICODE_STRING UnicodeString, IN PCWSTR ParamString)
static VOID UserpFreeStringParameters(IN OUT PULONG_PTR Parameters, IN PHARDERROR_MSG Message)
#define EXCEPTION_EXECUTE_HANDLER
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define PROCESS_QUERY_INFORMATION
#define MAXIMUM_HARDERROR_PARAMETERS
@ OptionCancelTryContinue
NTSYSAPI NTSTATUS NTAPI RtlFindMessage(_In_ PVOID BaseAddress, _In_ ULONG Type, _In_ ULONG Language, _In_ ULONG MessageId, _Out_ PMESSAGE_RESOURCE_ENTRY *MessageResourceEntry)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
NTSTATUS NTAPI NtOpenProcess(OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN PCLIENT_ID ClientId)
#define STATUS_UNHANDLED_EXCEPTION
#define STATUS_ACCESS_VIOLATION
#define STATUS_IN_PAGE_ERROR
NTSTRSAFEVAPI RtlStringCbPrintfExW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _Outptr_opt_result_bytebuffer_(*pcbRemaining) NTSTRSAFE_PWSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
#define _SEH2_GetExceptionCode()
#define _SEH2_EXCEPT(...)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
UCHAR Text[ANYSIZE_ARRAY]
#define RtlCopyMemory(Destination, Source, Length)
#define MB_CANCELTRYCONTINUE
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
BOOL CALLBACK FindTopLevelWnd(IN HWND hWnd, IN LPARAM lParam)
#define MB_ABORTRETRYIGNORE
int WINAPI GetWindowTextLengthW(_In_ HWND)
#define MB_ICONINFORMATION
BOOL WINAPI EnumThreadWindows(_In_ DWORD, _In_ WNDENUMPROC, _In_ LPARAM)