From 28c134ec411baadd2de07d7d34a27985d2a7cbf0 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Sun, 20 Apr 2008 08:48:55 +0000 Subject: [PATCH] - avoid using BringWindowToTop as it creates display problems - build a custom function GetRegValue to allow dxdiag be used on older Windows versions - try to fix potential buffer overflows svn path=/trunk/; revision=33050 --- reactos/base/applications/dxdiag/dxdiag.c | 5 +- reactos/base/applications/dxdiag/precomp.h | 2 +- reactos/base/applications/dxdiag/system.c | 66 +++++++++++++++------- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/reactos/base/applications/dxdiag/dxdiag.c b/reactos/base/applications/dxdiag/dxdiag.c index 4ab34adcc21..bbb00c092cb 100644 --- a/reactos/base/applications/dxdiag/dxdiag.c +++ b/reactos/base/applications/dxdiag/dxdiag.c @@ -66,9 +66,6 @@ TabCtrl_OnSelChange(PDXDIAG_CONTEXT pContext) else ShowWindow(pContext->hDialogs[Index], SW_HIDE); } - - /* make sure its displayed */ - BringWindowToTop(pContext->hDialogs[CurSel]); } @@ -190,7 +187,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, UNREFERENCED_PARAMETER(nCmdShow); InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX); - InitControls.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES; + InitControls.dwICC = ICC_TAB_CLASSES | ICC_LISTVIEW_CLASSES | ICC_STANDARD_CLASSES; InitCommonControlsEx(&InitControls); hInst = hInstance; diff --git a/reactos/base/applications/dxdiag/precomp.h b/reactos/base/applications/dxdiag/precomp.h index 082a9c07df0..3ab30374486 100644 --- a/reactos/base/applications/dxdiag/precomp.h +++ b/reactos/base/applications/dxdiag/precomp.h @@ -4,7 +4,6 @@ #include #include #include - #include "resource.h" typedef struct @@ -27,6 +26,7 @@ INT_PTR CALLBACK MusicPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM INT_PTR CALLBACK InputPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK NetworkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK HelpPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); +BOOL GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPWSTR Result, DWORD Size); #endif diff --git a/reactos/base/applications/dxdiag/system.c b/reactos/base/applications/dxdiag/system.c index 7920c7fc3ca..dfc0bf1f056 100644 --- a/reactos/base/applications/dxdiag/system.c +++ b/reactos/base/applications/dxdiag/system.c @@ -9,14 +9,40 @@ #include "precomp.h" +BOOL +GetRegValue(HKEY hBaseKey, LPWSTR SubKey, LPWSTR ValueName, DWORD Type, LPWSTR Result, DWORD Size) +{ + HKEY hKey; + LONG res; + DWORD dwType; + DWORD dwSize; + + + if (RegOpenKeyExW(hBaseKey, SubKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) + return FALSE; + + dwSize = Size; + res = RegQueryValueExW(hKey, ValueName, NULL, &dwType, (LPBYTE)Result, &dwSize); + RegCloseKey(hKey); + + if (dwType != Type) + return FALSE; + + if (res != ERROR_SUCCESS) + return FALSE; + + Result[(Size / sizeof(WCHAR))-1] = L'\0'; + return TRUE; +} + + static BOOL GetDirectXVersion(WCHAR * szBuffer) { WCHAR szVer[20]; - DWORD dwVer = sizeof(szVer); - if (RegGetValueW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX", L"Version", RRF_RT_REG_SZ, NULL, szVer, &dwVer) != ERROR_SUCCESS) + if (!GetRegValue(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX", L"Version", REG_SZ, szVer, sizeof(szVer))) return FALSE; if(!wcscmp(szVer, L"4.02.0095")) @@ -218,8 +244,7 @@ InitializeSystemPage(HWND hwndDlg) /* set system manufacturer */ szTime[0] = L'\0'; - Length = sizeof(szTime) / sizeof(WCHAR); - if (RegGetValueW(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"SystemManufacturer", RRF_RT_REG_SZ, NULL, szTime, &Length) == ERROR_SUCCESS) + if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"SystemManufacturer", REG_SZ, szTime, sizeof(szTime))) { szTime[199] = L'\0'; SendDlgItemMessageW(hwndDlg, IDC_STATIC_MANU, WM_SETTEXT, 0, (LPARAM)szTime); @@ -227,37 +252,36 @@ InitializeSystemPage(HWND hwndDlg) /* set motherboard model */ szTime[0] = L'\0'; - Length = sizeof(szTime) / sizeof(WCHAR); - if (RegGetValueW(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"SystemProductName", RRF_RT_REG_SZ, NULL, szTime, &Length) == ERROR_SUCCESS) + if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"SystemProductName", REG_SZ, szTime, sizeof(szTime))) { - szTime[199] = L'\0'; SendDlgItemMessageW(hwndDlg, IDC_STATIC_MODEL, WM_SETTEXT, 0, (LPARAM)szTime); } /* set bios model */ szTime[0] = L'\0'; - Length = sizeof(szTime) / sizeof(WCHAR); - if (RegGetValueW(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"BIOSVendor", RRF_RT_REG_SZ, NULL, szTime, &Length) == ERROR_SUCCESS) + if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"BIOSVendor", REG_SZ, szTime, sizeof(szTime))) { DWORD Index; - DWORD StrLength = (sizeof(szTime) / sizeof(WCHAR)) - (Length/sizeof(WCHAR)); + DWORD StrLength = (sizeof(szTime) / sizeof(WCHAR)); - Index = (Length/sizeof(WCHAR)); - szTime[Index-1] = L' '; + Index = wcslen(szTime); + StrLength -= Index; - if (RegGetValueW(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"BIOSReleaseDate", RRF_RT_REG_SZ, NULL, &szTime[Index], &StrLength) == ERROR_SUCCESS) + if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\BIOS", L"BIOSReleaseDate", REG_SZ, &szTime[Index], StrLength)) { - StrLength = (StrLength/sizeof(WCHAR)); + if (Index + StrLength > (sizeof(szTime)/sizeof(WCHAR))- 15) + { + //FIXME retrieve BiosMajorRelease, BiosMinorRelease + //StrLength = wcslen(&szTime[Index]); + //szTime[Index+StrLength] = L' '; + //wcscpy(&szTime[Index+StrLength], L"Ver: "); //FIXME NON-NLS + //szTime[(sizeof(szTime)/sizeof(WCHAR))-1] = L'\0'; + } + SendDlgItemMessageW(hwndDlg, IDC_STATIC_BIOS, WM_SETTEXT, 0, (LPARAM)szTime); } - szTime[Index+StrLength] = L' '; - wcscpy(&szTime[Index+StrLength], L"Ver: "); //FIXME NON-NLS - szTime[199] = L'\0'; - SendDlgItemMessageW(hwndDlg, IDC_STATIC_BIOS, WM_SETTEXT, 0, (LPARAM)szTime); - //FIXME retrieve BiosMajorRelease, BiosMinorRelease } /* set processor string */ - Length = sizeof(szDesc); - if (RegGetValueW(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\CentralProcessor\\0", L"ProcessorNameString", RRF_RT_REG_SZ, NULL, szDesc, &Length) == ERROR_SUCCESS) + if (GetRegValue(HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System\\CentralProcessor\\0", L"ProcessorNameString", REG_SZ, szDesc, sizeof(szDesc))) { /* FIXME retrieve current speed */ szFormat[0] = L'\0';