Пример #1
0
/*
* exceptShowException
*
* Purpose:
*
* Output exception information to the user.
*
*/
VOID exceptShowException(
	EXCEPTION_POINTERS *ExceptionPointers
	)
{
	WCHAR szMessage[MAX_PATH * 2];
	ULONGLONG IdFile;

	RtlSecureZeroMemory(&szMessage, sizeof(szMessage));
	_strcpy(szMessage, L"Sorry, exception occurred at address: \n0x");
	u64tohex((ULONG_PTR)ExceptionPointers->ExceptionRecord->ExceptionAddress, _strend(szMessage));

	if (ExceptionPointers->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
		switch (ExceptionPointers->ExceptionRecord->ExceptionInformation[0]) {
		case 0:
			_strcat(szMessage, L"\n\nAttempt to read at address: \n0x");
			break;
		case 1:
			_strcat(szMessage, L"\n\nAttempt to write at address: \n0x");
			break;
		}
		u64tohex(ExceptionPointers->ExceptionRecord->ExceptionInformation[1], _strend(szMessage));
	}
	IdFile = GetTickCount64();

	if (exceptWriteDump(ExceptionPointers, IdFile)) {
		_strcat(szMessage, L"\n\nMinidump wobjex");
		u64tostr(IdFile, _strend(szMessage));
		_strcat(szMessage, L".dmp is in %TEMP% directory");
	}
	_strcat(szMessage, L"\n\nPlease report this to the developers, thanks");
	MessageBox(GetForegroundWindow(), szMessage, NULL, MB_ICONERROR);
}
Пример #2
0
/*
* exceptWriteDump
*
* Purpose:
*
* Writes minidump information to the specified file.
*
*/
BOOL exceptWriteDump(
	EXCEPTION_POINTERS *ExceptionPointers,
	ULONGLONG IdFile
	)
{
	BOOL bResult;
	HANDLE hDbgHelp, hFile;
	DWORD dwRetVal;
	MINIDUMP_EXCEPTION_INFORMATION mdei;
	WCHAR szTemp[MAX_PATH * 2];

	bResult = FALSE;
	hDbgHelp = GetModuleHandle(L"dbghelp.dll");
	if (hDbgHelp == NULL) {
		RtlSecureZeroMemory(szTemp, sizeof(szTemp));
		if (!GetSystemDirectory(szTemp, MAX_PATH)) {
			return bResult;
		}
		_strcat(szTemp, L"\\dbghelp.dll");

		hDbgHelp = LoadLibraryEx(szTemp, 0, 0);
		if (hDbgHelp == NULL) {
			return bResult;
		}
	}

	pMiniDumpWriteDump = (pfnMiniDumpWriteDump)GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
	if (pMiniDumpWriteDump == NULL) {
		return bResult;
	}

	RtlSecureZeroMemory(szTemp, sizeof(szTemp));
	dwRetVal = GetTempPath(MAX_PATH, szTemp);
	if (dwRetVal > MAX_PATH || (dwRetVal == 0)) {
		return bResult;
	}
	_strcat(szTemp, L"wobjex");
	u64tostr(IdFile, _strend(szTemp));
	_strcat(szTemp, L".dmp");

	hFile = CreateFile(szTemp, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
	if (hFile != INVALID_HANDLE_VALUE) {
		mdei.ThreadId = GetCurrentThreadId();
		mdei.ExceptionPointers = ExceptionPointers;
		mdei.ClientPointers = FALSE;
		bResult = pMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &mdei, NULL, NULL);
		CloseHandle(hFile);
	}
	return bResult;
}
Пример #3
0
/*
* PipeDisplayError
*
* Purpose:
*
* Display last Win32 error.
*
*/
VOID PipeDisplayError(
    HWND hwndDlg
)
{
    DWORD dwLastError;
    WCHAR szBuffer[MAX_PATH * 2];

    dwLastError = GetLastError();
    ShowWindow(GetDlgItem(hwndDlg, ID_PIPE_QUERYFAIL), SW_SHOW);

    RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
    _strcpy(szBuffer, TEXT("Cannot open pipe because: "));
    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwLastError,
        0, _strend(szBuffer), MAX_PATH, NULL);
    SetDlgItemText(hwndDlg, ID_PIPE_QUERYFAIL, szBuffer);
}
Пример #4
0
/*
* propBasicQuerySection
*
* Purpose:
*
* Set information values for Section object type
*
* If ExtendedInfoAvailable is FALSE then it calls propSetDefaultInfo to set Basic page properties
*
*/
VOID propBasicQuerySection(
    _In_ PROP_OBJECT_INFO *Context,
    _In_ HWND hwndDlg,
    _In_ BOOL ExtendedInfoAvailable
)
{
    BOOL      bSet;
    NTSTATUS  status;
    HANDLE    hObject;
    SIZE_T    bytesNeeded;
    LPWSTR    lpType;
    RECT      rGB;
    WCHAR     szBuffer[MAX_PATH * 2];

    SECTION_BASIC_INFORMATION sbi;
    SECTION_IMAGE_INFORMATION sii;

    SetDlgItemText(hwndDlg, ID_SECTION_ATTR, T_CannotQuery);
    SetDlgItemText(hwndDlg, ID_SECTIONSIZE, T_CannotQuery);

    if (Context == NULL) {
        return;
    }

    //
    // Open Section object.
    //
    hObject = NULL;
    if (!propOpenCurrentObject(Context, &hObject, SECTION_QUERY)) {
        return;
    }

    //this is for specific mars warning, mars doesn't recognize __stosb intrinsics
    szBuffer[0] = 0;

    //query basic information
    RtlSecureZeroMemory(&sbi, sizeof(SECTION_BASIC_INFORMATION));
    status = NtQuerySection(hObject, SectionBasicInformation, &sbi,
        sizeof(SECTION_BASIC_INFORMATION), &bytesNeeded);

    if (NT_SUCCESS(status)) {

        bSet = FALSE;
        RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
        if (sbi.AllocationAttributes & SEC_BASED) {
            _strcat(szBuffer, TEXT("Based"));
            bSet = TRUE;
        }
        if (sbi.AllocationAttributes & SEC_NO_CHANGE) {
            if (bSet) _strcat(szBuffer, TEXT(" + "));
            _strcat(szBuffer, TEXT("NoChange"));
            bSet = TRUE;
        }
        if (sbi.AllocationAttributes & SEC_FILE) {
            if (bSet) _strcat(szBuffer, TEXT(" + "));
            _strcat(szBuffer, TEXT("File"));
            bSet = TRUE;
        }
        if (sbi.AllocationAttributes & SEC_IMAGE) {
            if (bSet) _strcat(szBuffer, TEXT(" + "));
            _strcat(szBuffer, TEXT("Image"));
            bSet = TRUE;
        }
        if (sbi.AllocationAttributes & SEC_RESERVE) {
            if (bSet) _strcat(szBuffer, TEXT(" + "));
            _strcat(szBuffer, TEXT("Reserve"));
            bSet = TRUE;
        }
        if (sbi.AllocationAttributes & SEC_COMMIT) {
            if (bSet) _strcat(szBuffer, TEXT(" + "));
            _strcat(szBuffer, TEXT("Commit"));
            bSet = TRUE;
        }
        if (sbi.AllocationAttributes & SEC_NOCACHE) {
            if (bSet) _strcat(szBuffer, TEXT(" + "));
            _strcat(szBuffer, TEXT("NoCache"));
            bSet = TRUE;
        }
        if (sbi.AllocationAttributes & SEC_GLOBAL) {
            if (bSet) _strcat(szBuffer, TEXT(" + "));
            _strcat(szBuffer, TEXT("Global"));
            bSet = TRUE;
        }
        if (sbi.AllocationAttributes & SEC_LARGE_PAGES) {
            if (bSet) _strcat(szBuffer, TEXT(" + "));
            _strcat(szBuffer, TEXT("LargePages"));
        }
        SetDlgItemText(hwndDlg, ID_SECTION_ATTR, szBuffer);

        //Size
        RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
        wsprintf(szBuffer, TEXT("0x%I64X"), sbi.MaximumSize.QuadPart);
        SetDlgItemText(hwndDlg, ID_SECTIONSIZE, szBuffer);

        //query image information
        if ((sbi.AllocationAttributes & SEC_IMAGE) && (sbi.AllocationAttributes & SEC_FILE)) {

            RtlSecureZeroMemory(&sii, sizeof(SECTION_IMAGE_INFORMATION));
            status = NtQuerySection(hObject, SectionImageInformation, &sii,
                sizeof(SECTION_IMAGE_INFORMATION), &bytesNeeded);

            if (NT_SUCCESS(status)) {

                //show hidden controls
                if (GetWindowRect(GetDlgItem(hwndDlg, ID_IMAGEINFO), &rGB)) {
                    EnumChildWindows(hwndDlg, supEnumEnableChildWindows, (LPARAM)&rGB);
                }

                //Entry			
                RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
                wsprintf(szBuffer, TEXT("0x%I64X"), (ULONG_PTR)sii.TransferAddress);
                SetDlgItemText(hwndDlg, ID_IMAGE_ENTRY, szBuffer);

                //Stack Reserve
                RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
                wsprintf(szBuffer, TEXT("0x%I64X"), sii.MaximumStackSize);
                SetDlgItemText(hwndDlg, ID_IMAGE_STACKRESERVE, szBuffer);

                //Stack Commit
                RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
                wsprintf(szBuffer, TEXT("0x%I64X"), sii.CommittedStackSize);
                SetDlgItemText(hwndDlg, ID_IMAGE_STACKCOMMIT, szBuffer);

                //Executable			
                SetDlgItemText(hwndDlg, ID_IMAGE_EXECUTABLE,
                    (sii.ImageContainsCode) ? TEXT("Yes") : TEXT("No"));

                //Subsystem
                lpType = TEXT("Unknown");
                switch (sii.SubSystemType) {
                case IMAGE_SUBSYSTEM_NATIVE:
                    lpType = TEXT("Native");
                    break;
                case IMAGE_SUBSYSTEM_WINDOWS_GUI:
                    lpType = TEXT("Windows GUI");
                    break;
                case IMAGE_SUBSYSTEM_WINDOWS_CUI:
                    lpType = TEXT("Windows Console");
                    break;
                case IMAGE_SUBSYSTEM_OS2_CUI:
                    lpType = TEXT("OS/2 Console");
                    break;
                case IMAGE_SUBSYSTEM_POSIX_CUI:
                    lpType = TEXT("Posix Console");
                    break;
                case IMAGE_SUBSYSTEM_XBOX:
                    lpType = TEXT("XBox");
                    break;
                case IMAGE_SUBSYSTEM_EFI_APPLICATION:
                    lpType = TEXT("EFI Application");
                    break;
                case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
                    lpType = TEXT("EFI Boot Service Driver");
                    break;
                case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
                    lpType = TEXT("EFI Runtime Driver");
                    break;
                case IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION:
                    lpType = TEXT("Windows Boot Application");
                    break;
                }
                SetDlgItemText(hwndDlg, ID_IMAGE_SUBSYSTEM, lpType);

                //Major Version
                RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
                ultostr(sii.SubSystemMajorVersion, _strend(szBuffer));
                SetDlgItemText(hwndDlg, ID_IMAGE_MJV, szBuffer);

                //Minor Version
                RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
                ultostr(sii.SubSystemMinorVersion, _strend(szBuffer));
                SetDlgItemText(hwndDlg, ID_IMAGE_MNV, szBuffer);
            }
        }
    }

    //
    // Query object basic and type info if needed.
    //
    if (ExtendedInfoAvailable == FALSE) {
        propSetDefaultInfo(Context, hwndDlg, hObject);
    }
    NtClose(hObject);
}
Пример #5
0
/*
* propBasicQueryKey
*
* Purpose:
*
* Set information values for Key object type
*
* If ExtendedInfoAvailable is FALSE then it calls propSetDefaultInfo to set Basic page properties
*
*/
VOID propBasicQueryKey(
    _In_ PROP_OBJECT_INFO *Context,
    _In_ HWND hwndDlg,
    _In_ BOOL ExtendedInfoAvailable
)
{
    NTSTATUS    status;
    ULONG       bytesNeeded;
    HANDLE      hObject;
    TIME_FIELDS	SystemTime;
    WCHAR       szBuffer[MAX_PATH];

    KEY_FULL_INFORMATION  kfi;

    SetDlgItemText(hwndDlg, ID_KEYSUBKEYS, T_CannotQuery);
    SetDlgItemText(hwndDlg, ID_KEYVALUES, T_CannotQuery);
    SetDlgItemText(hwndDlg, ID_KEYLASTWRITE, T_CannotQuery);

    if (Context == NULL) {
        return;
    }

    //
    // Open Key object.
    //
    hObject = NULL;
    if (!propOpenCurrentObject(Context, &hObject, KEY_QUERY_VALUE)) {
        return;
    }

    RtlSecureZeroMemory(&kfi, sizeof(KEY_FULL_INFORMATION));
    status = NtQueryKey(hObject, KeyFullInformation, &kfi,
        sizeof(KEY_FULL_INFORMATION), &bytesNeeded);

    if (NT_SUCCESS(status)) {

        //Subkeys count
        RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
        ultostr(kfi.SubKeys, _strend(szBuffer));
        SetDlgItemText(hwndDlg, ID_KEYSUBKEYS, szBuffer);

        //Values count
        RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
        ultostr(kfi.Values, _strend(szBuffer));
        SetDlgItemText(hwndDlg, ID_KEYVALUES, szBuffer);

        //LastWrite time
        RtlSecureZeroMemory(&SystemTime, sizeof(SystemTime));
        FileTimeToLocalFileTime((PFILETIME)&kfi.LastWriteTime,
            (PFILETIME)&kfi.LastWriteTime);
        RtlTimeToTimeFields((PLARGE_INTEGER)&kfi.LastWriteTime,
            (PTIME_FIELDS)&SystemTime);

        //Month starts from 0 index
        if (SystemTime.Month - 1 < 0) SystemTime.Month = 1;
        if (SystemTime.Month > 12) SystemTime.Month = 12;

        RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
        wsprintf(szBuffer, FORMATTED_TIME_DATE_VALUE,
            SystemTime.Hour,
            SystemTime.Minute,
            SystemTime.Second,
            SystemTime.Day,
            Months[SystemTime.Month - 1],
            SystemTime.Year);

        SetDlgItemText(hwndDlg, ID_KEYLASTWRITE, szBuffer);
    }

    //
    // Query object basic and type info if needed.
    //
    if (ExtendedInfoAvailable == FALSE) {
        propSetDefaultInfo(Context, hwndDlg, hObject);
    }
    NtClose(hObject);
}
Пример #6
0
/*
* propSetBasicInfoEx
*
* Purpose:
*
* Set information values received with kldbgdrv help
*
*/
VOID propSetBasicInfoEx(
    _In_ HWND hwndDlg,
    _In_ POBJINFO InfoObject
)
{
    INT     i;
    HWND    hwndCB;
    WCHAR   szBuffer[MAX_PATH];

    if (InfoObject == NULL)
        return;

    //Object Address
    RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
    szBuffer[0] = L'0';
    szBuffer[1] = L'x';
    u64tohex(InfoObject->ObjectAddress, &szBuffer[2]);
    SetDlgItemText(hwndDlg, ID_OBJECT_ADDR, szBuffer);

    //Header Address
    RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
    szBuffer[0] = L'0';
    szBuffer[1] = L'x';
    u64tohex(InfoObject->HeaderAddress, &szBuffer[2]);
    SetDlgItemText(hwndDlg, ID_OBJECT_HEADER, szBuffer);

    //Reference Count
    RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
    ultostr(InfoObject->ObjectHeader.PointerCount, _strend(szBuffer));
    SetDlgItemText(hwndDlg, ID_OBJECT_REFC, szBuffer);

    //Handle Count
    RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
    ultostr(InfoObject->ObjectHeader.HandleCount, _strend(szBuffer));
    SetDlgItemText(hwndDlg, ID_OBJECT_HANDLES, szBuffer);

    //NonPagedPoolCharge
    RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
    ultostr(InfoObject->ObjectQuotaHeader.NonPagedPoolCharge, szBuffer);
    SetDlgItemText(hwndDlg, ID_OBJECT_NP_CHARGE, szBuffer);

    //PagedPoolCharge
    RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
    ultostr(InfoObject->ObjectQuotaHeader.PagedPoolCharge, _strend(szBuffer));
    SetDlgItemText(hwndDlg, ID_OBJECT_PP_CHARGE, szBuffer);

    //Attributes
    hwndCB = GetDlgItem(hwndDlg, IDC_OBJECT_FLAGS);
    if (hwndCB) {
        EnableWindow(hwndCB, (InfoObject->ObjectHeader.Flags > 0) ? TRUE : FALSE);
        SendMessage(hwndCB, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
        if (InfoObject->ObjectHeader.Flags > 0) {
            for (i = 0; i < 8; i++) {

                if (GET_BIT(InfoObject->ObjectHeader.Flags, i))

                    SendMessage(hwndCB,
                        CB_ADDSTRING,
                        (WPARAM)0,
                        (LPARAM)T_ObjectFlags[i]);
            }
            SendMessage(hwndCB, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
        }
    }
}
Пример #7
0
/*
* SfuBuildBotPath
*
* Purpose:
*
* Return full path to bot in both variants.
*
*/
BOOL SfuBuildBotPath(
	_Inout_ PZA_BOT_PATH Context
	)
{
	BOOL                           cond = FALSE, bResult = FALSE;
	OBJECT_ATTRIBUTES              obja;
	UNICODE_STRING                 ustr1, ustr2;
	WCHAR                          szRegBuffer[MAX_PATH + 1];
	HANDLE                         ProcessHeap; 
	HANDLE                         hKey = NULL;
	NTSTATUS                       status;
	KEY_VALUE_PARTIAL_INFORMATION *pki = NULL;
	LPWSTR                         lpEnv;
	ULONG                          memIO = 0;
	LPWSTR                         lpLocalBotName, lpPFilesBotName;
	PVOID                          Wow64Information = NULL;

	GUID sfGUID;

	if (Context == NULL)
		return bResult;

	ProcessHeap = RtlGetCurrentPeb()->ProcessHeap;

	RtlSecureZeroMemory(&ustr1, sizeof(ustr1));

	do {

		if (!SfInitMD5())
			break;

		RtlSecureZeroMemory(&sfGUID, sizeof(sfGUID));
		SfuCalcVolumeMD5((BYTE*)&sfGUID);

		status = NtQueryInformationProcess(NtCurrentProcess(), ProcessWow64Information, 
			&Wow64Information, sizeof(PVOID), NULL);
		if (!NT_SUCCESS(status))
			break;

		//query current user registry string
		if (!NT_SUCCESS(RtlFormatCurrentUserKeyPath(&ustr1)))
			break;

		lpLocalBotName = Context->szBotPathLocal;
		lpPFilesBotName = Context->szBotPathPFiles;

		RtlSecureZeroMemory(&szRegBuffer, sizeof(szRegBuffer));
		wsprintf(szRegBuffer, T_SHELL_FOLDERS_KEY, ustr1.Buffer);

		RtlFreeUnicodeString(&ustr1);
		
		//open User Shell Folders key to query Local AppData value
		RtlSecureZeroMemory(&ustr2, sizeof(ustr2));
		RtlInitUnicodeString(&ustr2, szRegBuffer);
		InitializeObjectAttributes(&obja, &ustr2, OBJ_CASE_INSENSITIVE, NULL, NULL);
		status = NtOpenKey(&hKey, KEY_READ, &obja);
		if (!NT_SUCCESS(status))
			break;

		//query value size
		RtlInitUnicodeString(&ustr2, T_LOCAL_APPDATA_VALUE);
		NtQueryValueKey(hKey, &ustr2, KeyValuePartialInformation,
			NULL, 0, &memIO);

		if (memIO == 0)
			break;

		pki = RtlAllocateHeap(ProcessHeap, HEAP_ZERO_MEMORY, memIO);
		if (pki == NULL)
			break;
		
		//query value
		status = NtQueryValueKey(hKey, &ustr2, KeyValuePartialInformation,
			pki, memIO, &memIO);

		if (!NT_SUCCESS(status)) 
			break;

		RtlInitUnicodeString(&ustr2, (WCHAR*)pki->Data);
		memIO = 0;

		//expand environment variable inside value
		RtlSecureZeroMemory(&szRegBuffer, sizeof(szRegBuffer));
		ustr1.Buffer = szRegBuffer;
		ustr1.Length = 0;
		ustr1.MaximumLength = sizeof(szRegBuffer);

		status = RtlExpandEnvironmentStrings_U(NULL, &ustr2, &ustr1, &memIO);
		if (!NT_SUCCESS(status)) {
			ustr1.Buffer = NULL;
			break;
		}

		//build result string
		_strcpy(lpLocalBotName, T_GLOBAL_LINK);
		_strcat(lpLocalBotName, szRegBuffer);
		
		wsprintf(_strend(lpLocalBotName), T_SIREFEF_DIRECTORY,
			sfGUID.Data1, sfGUID.Data2, sfGUID.Data3,
			sfGUID.Data4[0],
			sfGUID.Data4[1],
			sfGUID.Data4[2],
			sfGUID.Data4[3],
			sfGUID.Data4[4],
			sfGUID.Data4[5],
			sfGUID.Data4[6],
			sfGUID.Data4[7]);

		ustr1.Buffer = NULL;

		_strcpy(lpPFilesBotName, T_GLOBAL_LINK);
		
		if (Wow64Information == NULL) {
			lpEnv = L"ProgramFiles=";
		}
		else {
			lpEnv = L"ProgramFiles(x86)=";
		}

		RtlInitUnicodeString(&ustr2, lpEnv);
		lpEnv = SfuQueryEnvironmentVariableOffset(&ustr2);
		if (lpEnv) {
			_strcat(lpPFilesBotName, lpEnv);

			wsprintf(_strend(lpPFilesBotName), T_SIREFEF_DIRECTORY,
				sfGUID.Data1, sfGUID.Data2, sfGUID.Data3,
				sfGUID.Data4[0],
				sfGUID.Data4[1],
				sfGUID.Data4[2],
				sfGUID.Data4[3],
				sfGUID.Data4[4],
				sfGUID.Data4[5],
				sfGUID.Data4[6],
				sfGUID.Data4[7]);
		}

		bResult = TRUE;

	} while (cond);

	if (hKey != NULL) {
		NtClose(hKey);
	}

	if (ustr1.Buffer != NULL) {
		RtlFreeUnicodeString(&ustr1);
	}

	if (pki != NULL) {
		RtlFreeHeap(ProcessHeap, 0, pki);
	}
	return bResult;
}
Пример #8
0
/*
* AboutDialogInit
*
* Purpose:
*
* Displays program version and system information
*
*/
VOID AboutDialogInit(
	HWND hwndDlg
	)
{
	NTSTATUS status;
	WCHAR buf[MAX_PATH];
	BOOLEAN bSecureBoot = FALSE;
	ULONG returnLength;
	SYSTEM_BOOT_ENVIRONMENT_INFORMATION sbei;
	HANDLE hImage;

	SetDlgItemText(hwndDlg, ID_ABOUT_PROGRAM, PROFRAM_NAME_AND_TITLE);
	SetDlgItemText(hwndDlg, ID_ABOUT_BUILDINFO, PROGRAM_VERSION);

	hImage = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ICON_MAIN), IMAGE_ICON, 48, 48, LR_SHARED);
	if (hImage) {
		SendMessage(GetDlgItem(hwndDlg, ID_ABOUT_ICON), STM_SETIMAGE, IMAGE_ICON, (LPARAM)hImage);
		DestroyIcon(hImage);
	}

	//remove class icon if any
	SetClassLongPtr(hwndDlg, GCLP_HICON, (LONG_PTR)NULL);

	RtlSecureZeroMemory(buf, sizeof(buf)); 

#if (_MSC_VER == 1900) //2015
#if (_MSC_FULL_VER == 190023026) //2015 RTM
	_strcpy(buf, L"MSVC 2015");
#elif (_MSC_FULL_VER == 190023419) // 2015 Update 1 RC
	_strcpy(buf, L"MSVC 2015 Update 1 RC");
#endif
#else
#if (_MSC_VER == 1800) //2013
#if (_MSC_FULL_VER == 180040629)
	_strcpy(buf, L"MSVC 2013 Update 5");
#elif (_MSC_FULL_VER == 180031101)
	_strcpy(buf, L"MSVC 2013 Update 4");
#elif (_MSC_FULL_VER == 180030723)
	_strcpy(buf, L"MSVC 2013 Update 3");
#elif (_MSC_FULL_VER == 180030501)
	_strcpy(buf, L"MSVC 2013 Update 2");
#elif (_MSC_FULL_VER < 180021005)
	_strcpy(buf, L"MSVC 2013 Preview/Beta/RC");
#else
	_strcpy(buf, L"MSVC 2013");
#endif
#else
	_strcpy(buf, L"Unknown Compiler");
#endif
#endif
	SetDlgItemText(hwndDlg, ID_ABOUT_COMPILERINFO, buf);

	RtlSecureZeroMemory(buf, sizeof(buf));
	MultiByteToWideChar(CP_ACP, 0, __DATE__, (INT)_strlen_a(__DATE__), _strend(buf), 40);
	_strcat(buf, TEXT(" "));
	MultiByteToWideChar(CP_ACP, 0, __TIME__, (INT)_strlen_a(__TIME__), _strend(buf), 40);
	SetDlgItemText(hwndDlg, ID_ABOUT_BUILDDATE, buf);

	// fill OS name
	wsprintfW(buf, L"Windows NT %1u.%1u (build %u",
		g_kdctx.osver.dwMajorVersion, g_kdctx.osver.dwMinorVersion, g_kdctx.osver.dwBuildNumber);
	if (g_kdctx.osver.szCSDVersion[0]) {
		wsprintfW(_strend(buf), L", %ws)", g_kdctx.osver.szCSDVersion);
	}
	else {
		_strcat(buf, L")");
	}
	SetDlgItemText(hwndDlg, ID_ABOUT_OSNAME, buf);

	// fill boot options
	RtlSecureZeroMemory(&buf, sizeof(buf));
	RtlSecureZeroMemory(&sbei, sizeof(sbei));
	status = NtQuerySystemInformation(SystemBootEnvironmentInformation, &sbei, sizeof(sbei), &returnLength);
	if (NT_SUCCESS(status)) {

		wsprintfW(buf, L"%ws mode",
			((sbei.FirmwareType == FirmwareTypeUefi) ? L"UEFI" : ((sbei.FirmwareType == FirmwareTypeBios) ? L"BIOS" : L"Unknown")));
	
		if (sbei.FirmwareType == FirmwareTypeUefi) {
			bSecureBoot = FALSE;
			if (AboutDialogQuerySecureBootState(&bSecureBoot)) {
				wsprintfW(_strend(buf), L" with%ws SecureBoot", (bSecureBoot == TRUE) ? L"" : L"out");
			}
		}
	}
	SetDlgItemText(hwndDlg, ID_ABOUT_ADVINFO, buf);

	SetFocus(GetDlgItem(hwndDlg, IDOK));
}
Пример #9
0
/*
* AboutDialogInit
*
* Purpose:
*
* Displays program version and system information
*
*/
VOID AboutDialogInit(
    HWND hwndDlg
)
{
    BOOLEAN  bSecureBoot = FALSE;
    ULONG    returnLength;
    NTSTATUS status;
    HANDLE   hImage;
    WCHAR    szBuffer[MAX_PATH];

    SYSTEM_BOOT_ENVIRONMENT_INFORMATION sbei;

    SetDlgItemText(hwndDlg, ID_ABOUT_PROGRAM, PROFRAM_NAME_AND_TITLE);
    SetDlgItemText(hwndDlg, ID_ABOUT_BUILDINFO, PROGRAM_VERSION);

    hImage = LoadImage(g_WinObj.hInstance, MAKEINTRESOURCE(IDI_ICON_MAIN), IMAGE_ICON, 48, 48, LR_SHARED);
    if (hImage) {
        SendMessage(GetDlgItem(hwndDlg, ID_ABOUT_ICON), STM_SETIMAGE, IMAGE_ICON, (LPARAM)hImage);
        DestroyIcon(hImage);
    }

    //remove class icon if any
    SetClassLongPtr(hwndDlg, GCLP_HICON, (LONG_PTR)NULL);

    RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));

#if ((_MSC_VER == 1910) || (_MSC_VER == 1911) || (_MSC_VER == 1912))//2017
#if (_MSC_FULL_VER == 191025017)
    _strcpy(szBuffer, L"MSVC 2017");
#else
    _strcpy(szBuffer, L"MSVC 2017");
#endif
#else
#if (_MSC_VER == 1900) //2015
#if (_MSC_FULL_VER == 190023026) //2015 RTM
    _strcpy(szBuffer, L"MSVC 2015");
#elif (_MSC_FULL_VER == 190023506) // 2015 Update 1
    _strcpy(szBuffer, L"MSVC 2015 Update 1");
#elif (_MSC_FULL_VER == 190023918) // 2015 Update 2
    _strcpy(szBuffer, L"MSVC 2015 Update 2");
#elif (_MSC_FULL_VER == 190024210) // 2015 Update 3
    _strcpy(szBuffer, L"MSVC 2015 Update 3");
#elif (_MSC_FULL_VER == 190024215) // 2015 Update 3 with Cumulative Servicing Release
    _strcpy(szBuffer, L"MSVC 2015 Update 3 CSR");
#endif
#else
#if (_MSC_VER == 1800) //2013
#if (_MSC_FULL_VER == 180040629)
    _strcpy(szBuffer, L"MSVC 2013 Update 5");
#elif (_MSC_FULL_VER == 180031101)
    _strcpy(szBuffer, L"MSVC 2013 Update 4");
#elif (_MSC_FULL_VER == 180030723)
    _strcpy(szBuffer, L"MSVC 2013 Update 3");
#elif (_MSC_FULL_VER == 180030501)
    _strcpy(szBuffer, L"MSVC 2013 Update 2");
#elif (_MSC_FULL_VER < 180021005)
    _strcpy(szBuffer, L"MSVC 2013 Preview/Beta/RC");
#else
    _strcpy(szBuffer, L"MSVC 2013");
#endif
#else
    _strcpy(szBuffer, L"Unknown Compiler");
#endif
#endif
#endif
    if (szBuffer[0] == 0) {
        ultostr(_MSC_FULL_VER, szBuffer);
    }
    SetDlgItemText(hwndDlg, ID_ABOUT_COMPILERINFO, szBuffer);

    RtlSecureZeroMemory(szBuffer, sizeof(szBuffer));
    MultiByteToWideChar(CP_ACP, 0, __DATE__, (INT)_strlen_a(__DATE__), _strend(szBuffer), 40);
    _strcat(szBuffer, TEXT(" "));
    MultiByteToWideChar(CP_ACP, 0, __TIME__, (INT)_strlen_a(__TIME__), _strend(szBuffer), 40);
    SetDlgItemText(hwndDlg, ID_ABOUT_BUILDDATE, szBuffer);

    // fill OS name
    wsprintf(szBuffer, TEXT("Windows NT %1u.%1u (build %u"),
        g_WinObj.osver.dwMajorVersion, g_WinObj.osver.dwMinorVersion, g_WinObj.osver.dwBuildNumber);
    if (g_WinObj.osver.szCSDVersion[0]) {
        wsprintf(_strend(szBuffer), TEXT(", %ws)"), g_WinObj.osver.szCSDVersion);
    }
    else {
        _strcat(szBuffer, TEXT(")"));
    }
    SetDlgItemText(hwndDlg, ID_ABOUT_OSNAME, szBuffer);

    // fill boot options
    RtlSecureZeroMemory(&szBuffer, sizeof(szBuffer));
    RtlSecureZeroMemory(&sbei, sizeof(sbei));
    status = NtQuerySystemInformation(SystemBootEnvironmentInformation, &sbei, sizeof(sbei), &returnLength);
    if (NT_SUCCESS(status)) {
        wsprintf(szBuffer, TEXT("%ws mode"),
            ((sbei.FirmwareType == FirmwareTypeUefi) ? TEXT("UEFI") : ((sbei.FirmwareType == FirmwareTypeBios) ? TEXT("BIOS") : TEXT("Unknown"))));

        if (sbei.FirmwareType == FirmwareTypeUefi) {
            bSecureBoot = FALSE;
            if (supQuerySecureBootState(&bSecureBoot)) {
                wsprintf(_strend(szBuffer), TEXT(" with%ws SecureBoot"), (bSecureBoot == TRUE) ? TEXT("") : TEXT("out"));
            }
        }
    }
    else {
        _strcpy(szBuffer, TEXT("Unknown"));
    }
    SetDlgItemText(hwndDlg, ID_ABOUT_ADVINFO, szBuffer);

    SetFocus(GetDlgItem(hwndDlg, IDOK));
}