ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
May 2023
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
16 participants
69 discussions
Start a n
N
ew thread
[reactos] 01/01: [RAPPS] Cleanup headers inclusions (#4206)
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3eb6cca9bdce0545640cc…
commit 3eb6cca9bdce0545640cc8f9cdf089e881c42f7d Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sun Dec 26 04:05:10 2021 +0100 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Wed May 10 12:12:25 2023 +0200 [RAPPS] Cleanup headers inclusions (#4206) --- base/applications/rapps/gui.cpp | 4 ---- base/applications/rapps/include/configparser.h | 1 - base/applications/rapps/include/dialogs.h | 1 - base/applications/rapps/include/gui.h | 1 - base/applications/rapps/include/misc.h | 1 - base/applications/rapps/include/settings.h | 2 +- base/applications/rapps/include/winmain.h | 3 +-- base/applications/rapps/unattended.cpp | 1 - 8 files changed, 2 insertions(+), 12 deletions(-) diff --git a/base/applications/rapps/gui.cpp b/base/applications/rapps/gui.cpp index 43c641f9e0a..353dd3bcbce 100644 --- a/base/applications/rapps/gui.cpp +++ b/base/applications/rapps/gui.cpp @@ -10,12 +10,8 @@ #include "rapps.h" #include "rosui.h" #include "crichedit.h" -#include "appview.h" #include "asyncinet.h" -#include "misc.h" #include "gui.h" -#include "appview.h" -#include "winmain.h" #include <shlobj_undoc.h> #include <shlguid_undoc.h> diff --git a/base/applications/rapps/include/configparser.h b/base/applications/rapps/include/configparser.h index 10868d5e49f..364d073383c 100644 --- a/base/applications/rapps/include/configparser.h +++ b/base/applications/rapps/include/configparser.h @@ -1,6 +1,5 @@ #pragma once -#include <windef.h> #include <atlstr.h> class CConfigParser diff --git a/base/applications/rapps/include/dialogs.h b/base/applications/rapps/include/dialogs.h index ee49f287d82..ba94025b4a3 100644 --- a/base/applications/rapps/include/dialogs.h +++ b/base/applications/rapps/include/dialogs.h @@ -2,7 +2,6 @@ #include "appinfo.h" -#include <windef.h> #include <atlsimpcoll.h> // Settings dialog (settingsdlg.cpp) diff --git a/base/applications/rapps/include/gui.h b/base/applications/rapps/include/gui.h index 330f1118dac..4cbd6d267fd 100644 --- a/base/applications/rapps/include/gui.h +++ b/base/applications/rapps/include/gui.h @@ -4,7 +4,6 @@ #include "rosui.h" #include "crichedit.h" #include "asyncinet.h" -#include "misc.h" #include "appview.h" #include <shlobj_undoc.h> #include <shlguid_undoc.h> diff --git a/base/applications/rapps/include/misc.h b/base/applications/rapps/include/misc.h index ff4ff9029e9..593ef5a82b0 100644 --- a/base/applications/rapps/include/misc.h +++ b/base/applications/rapps/include/misc.h @@ -1,6 +1,5 @@ #pragma once -#include <windef.h> #include <atlstr.h> #ifdef _M_IX86 diff --git a/base/applications/rapps/include/settings.h b/base/applications/rapps/include/settings.h index a3b4b867ffd..29f48985e71 100644 --- a/base/applications/rapps/include/settings.h +++ b/base/applications/rapps/include/settings.h @@ -1,5 +1,5 @@ #pragma once -#include <windef.h> + #include <wininet.h> struct SETTINGS_INFO diff --git a/base/applications/rapps/include/winmain.h b/base/applications/rapps/include/winmain.h index d6a214298a6..d98bf057a5b 100644 --- a/base/applications/rapps/include/winmain.h +++ b/base/applications/rapps/include/winmain.h @@ -1,6 +1,5 @@ #pragma once -#include <windef.h> -#include <wininet.h> + #include "settings.h" extern LPCWSTR szWindowClass; diff --git a/base/applications/rapps/unattended.cpp b/base/applications/rapps/unattended.cpp index e5fe54ed2ea..8311e47a976 100644 --- a/base/applications/rapps/unattended.cpp +++ b/base/applications/rapps/unattended.cpp @@ -8,7 +8,6 @@ #include "rapps.h" #include "unattended.h" -#include "winmain.h" #include <setupapi.h> #include <conutils.h>
1 year, 7 months
1
0
0
0
[reactos] 01/01: [IMM32][NTUSER][SDK] Add ImmCallImeConsoleIME (#5271)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4aff6293028ffeb837dce…
commit 4aff6293028ffeb837dce4a6bc58e84c150907f7 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Wed May 10 14:04:01 2023 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Wed May 10 14:04:01 2023 +0900 [IMM32][NTUSER][SDK] Add ImmCallImeConsoleIME (#5271) - Add <jpnvkeys.h>. - Add imm32!ImmCallImeConsoleIME. CORE-11700 --- dll/win32/imm32/imm32.spec | 1 + dll/win32/imm32/keymsg.c | 92 ++++++++++++++++++++++++++++++++++++++++++ sdk/include/reactos/jpnvkeys.h | 27 +++++++++++++ win32ss/user/ntuser/ime.c | 19 +-------- 4 files changed, 122 insertions(+), 17 deletions(-) diff --git a/dll/win32/imm32/imm32.spec b/dll/win32/imm32/imm32.spec index 77442f45829..92ac837fffd 100644 --- a/dll/win32/imm32/imm32.spec +++ b/dll/win32/imm32/imm32.spec @@ -9,6 +9,7 @@ @ stdcall ImmActivateLayout(ptr) @ stdcall ImmAssociateContext(ptr ptr) @ stdcall ImmAssociateContextEx(ptr ptr long) +@ stdcall ImmCallImeConsoleIME(ptr long ptr ptr ptr) @ stdcall ImmConfigureIMEA(ptr ptr long ptr) @ stdcall ImmConfigureIMEW(ptr ptr long ptr) @ stdcall ImmCreateContext() diff --git a/dll/win32/imm32/keymsg.c b/dll/win32/imm32/keymsg.c index c759176e7d6..3e05fe416b9 100644 --- a/dll/win32/imm32/keymsg.c +++ b/dll/win32/imm32/keymsg.c @@ -10,6 +10,7 @@ */ #include "precomp.h" +#include <jpnvkeys.h> WINE_DEFAULT_DEBUG_CHANNEL(imm); @@ -1195,3 +1196,94 @@ ImmSendMessageToActiveDefImeWndW(UINT uMsg, WPARAM wParam, LPARAM lParam) return SendMessageW(hwndIME, uMsg, wParam, lParam); } + +/*********************************************************************** + * ImmCallImeConsoleIME (IMM32.@) + */ +DWORD WINAPI +ImmCallImeConsoleIME( + _In_ HWND hWnd, + _In_ UINT uMsg, + _In_ WPARAM wParam, + _In_ LPARAM lParam, + _Out_ LPUINT puVK) +{ + DWORD dwThreadId, ret = 0; + HKL hKL; + PWND pWnd = NULL; + HIMC hIMC; + PIMEDPI pImeDpi; + UINT uVK; + PIMC pIMC; + + switch (uMsg) + { + case WM_KEYDOWN: + case WM_KEYUP: + case WM_SYSKEYDOWN: + case WM_SYSKEYUP: + break; + + default: + return 0; + } + + dwThreadId = GetWindowThreadProcessId(hWnd, NULL); + hKL = GetKeyboardLayout(dwThreadId); + + if (hWnd && gpsi) + pWnd = ValidateHwndNoErr(hWnd); + if (IS_NULL_UNEXPECTEDLY(pWnd)) + return 0; + + hIMC = ImmGetContext(hWnd); + if (IS_NULL_UNEXPECTEDLY(hIMC)) + return 0; + + uVK = *puVK = (wParam & 0xFF); + + pIMC = ValidateHandleNoErr(hIMC, TYPE_INPUTCONTEXT); + if (IS_NULL_UNEXPECTEDLY(pIMC)) + return 0; + + pImeDpi = ImmLockImeDpi(hKL); + if (IS_NULL_UNEXPECTEDLY(pImeDpi)) + return 0; + + if ((lParam & MAKELPARAM(0, KF_UP)) && (pImeDpi->ImeInfo.fdwProperty & IME_PROP_IGNORE_UPKEYS)) + goto Quit; + + switch (uVK) + { + case VK_DBE_ROMAN: + case VK_DBE_NOROMAN: + case VK_DBE_HIRAGANA: + case VK_DBE_KATAKANA: + case VK_DBE_CODEINPUT: + case VK_DBE_NOCODEINPUT: + case VK_DBE_ENTERWORDREGISTERMODE: + case VK_DBE_ENTERCONFIGMODE: + break; + + default: + { + if (uMsg == WM_SYSKEYDOWN || uMsg == WM_SYSKEYUP) + { + if (uVK != VK_MENU && uVK != VK_F10) + goto Quit; + } + + if (!(pImeDpi->ImeInfo.fdwProperty & IME_PROP_NEED_ALTKEY)) + { + if (uVK == VK_MENU || (lParam & MAKELPARAM(0, KF_ALTDOWN))) + goto Quit; + } + } + } + + ret = ImmProcessKey(hWnd, hKL, uVK, lParam, INVALID_HOTKEY_ID); + +Quit: + ImmUnlockImeDpi(pImeDpi); + return ret; +} diff --git a/sdk/include/reactos/jpnvkeys.h b/sdk/include/reactos/jpnvkeys.h new file mode 100644 index 00000000000..1f71f04e67b --- /dev/null +++ b/sdk/include/reactos/jpnvkeys.h @@ -0,0 +1,27 @@ +/* + * PROJECT: ReactOS header + * LICENSE: LGPL-2.0-or-later (
https://spdx.org/licenses/LGPL-2.0-or-later
) + * PURPOSE: The special virtual keys for Japanese + * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> + */ + +#pragma once + +/* + * The special virtual keys for Japanese: Used for key states. + *
https://www.kthree.co.jp/kihelp/index.html?page=app/vkey&type=html
+ */ +#define VK_DBE_ALPHANUMERIC 0xF0 +#define VK_DBE_KATAKANA 0xF1 +#define VK_DBE_HIRAGANA 0xF2 +#define VK_DBE_SBCSCHAR 0xF3 +#define VK_DBE_DBCSCHAR 0xF4 +#define VK_DBE_ROMAN 0xF5 +#define VK_DBE_NOROMAN 0xF6 +#define VK_DBE_ENTERWORDREGISTERMODE 0xF7 +#define VK_DBE_ENTERCONFIGMODE 0xF8 +#define VK_DBE_FLUSHSTRING 0xF9 +#define VK_DBE_CODEINPUT 0xFA +#define VK_DBE_NOCODEINPUT 0xFB +#define VK_DBE_DETERINESTRING 0xFC +#define VK_DBE_ENTERDLGCONVERSIONMODE 0xFD diff --git a/win32ss/user/ntuser/ime.c b/win32ss/user/ntuser/ime.c index 5a1eeb86580..5c21f2f9da9 100644 --- a/win32ss/user/ntuser/ime.c +++ b/win32ss/user/ntuser/ime.c @@ -8,6 +8,8 @@ */ #include <win32k.h> +#include <jpnvkeys.h> + DBG_DEFAULT_CHANNEL(UserMisc); #define INVALID_THREAD_ID ((ULONG)-1) @@ -21,23 +23,6 @@ DBG_DEFAULT_CHANNEL(UserMisc); #define LANGID_CHINESE_TRADITIONAL MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL) #define LANGID_NEUTRAL MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) -// The special virtual keys for Japanese: Used for key states. -//
https://www.kthree.co.jp/kihelp/index.html?page=app/vkey&type=html
-#define VK_DBE_ALPHANUMERIC 0xF0 -#define VK_DBE_KATAKANA 0xF1 -#define VK_DBE_HIRAGANA 0xF2 -#define VK_DBE_SBCSCHAR 0xF3 -#define VK_DBE_DBCSCHAR 0xF4 -#define VK_DBE_ROMAN 0xF5 -#define VK_DBE_NOROMAN 0xF6 -#define VK_DBE_ENTERWORDREGISTERMODE 0xF7 -#define VK_DBE_ENTERCONFIGMODE 0xF8 -#define VK_DBE_FLUSHSTRING 0xF9 -#define VK_DBE_CODEINPUT 0xFA -#define VK_DBE_NOCODEINPUT 0xFB -#define VK_DBE_DETERINESTRING 0xFC -#define VK_DBE_ENTERDLGCONVERSIONMODE 0xFD - HIMC ghIMC = NULL; BOOL gfImeOpen = (BOOL)-1; DWORD gdwImeConversion = (DWORD)-1;
1 year, 7 months
1
0
0
0
[reactos] 02/02: [NTOS:PNP] IopEnumerateDetectedDevices(): Formatting only CORE-18962
by Stanislav Motylkov
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6e3ad0411ace111ac97b8…
commit 6e3ad0411ace111ac97b8034759f23705288c03b Author: Stanislav Motylkov <x86corez(a)gmail.com> AuthorDate: Mon May 8 15:50:21 2023 +0200 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Mon May 8 16:07:11 2023 +0200 [NTOS:PNP] IopEnumerateDetectedDevices(): Formatting only CORE-18962 --- ntoskrnl/io/pnpmgr/pnpmap.c | 879 ++++++++++++++++++++++++-------------------- 1 file changed, 477 insertions(+), 402 deletions(-) diff --git a/ntoskrnl/io/pnpmgr/pnpmap.c b/ntoskrnl/io/pnpmgr/pnpmap.c index 795e4a3c2ce..97a170fc46d 100644 --- a/ntoskrnl/io/pnpmgr/pnpmap.c +++ b/ntoskrnl/io/pnpmgr/pnpmap.c @@ -18,68 +18,69 @@ static CODE_SEG("INIT") NTSTATUS IopEnumerateDetectedDevices( - IN HANDLE hBaseKey, - IN PUNICODE_STRING RelativePath OPTIONAL, - IN HANDLE hRootKey, - IN BOOLEAN EnumerateSubKeys, - IN PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources, - IN ULONG ParentBootResourcesLength) + _In_ HANDLE hBaseKey, + _In_opt_ PUNICODE_STRING RelativePath, + _In_ HANDLE hRootKey, + _In_ BOOLEAN EnumerateSubKeys, + _In_ PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources, + _In_ ULONG ParentBootResourcesLength) { - UNICODE_STRING IdentifierU = RTL_CONSTANT_STRING(L"Identifier"); - UNICODE_STRING HardwareIDU = RTL_CONSTANT_STRING(L"HardwareID"); - UNICODE_STRING ConfigurationDataU = RTL_CONSTANT_STRING(L"Configuration Data"); - UNICODE_STRING BootConfigU = RTL_CONSTANT_STRING(L"BootConfig"); - UNICODE_STRING LogConfU = RTL_CONSTANT_STRING(L"LogConf"); - OBJECT_ATTRIBUTES ObjectAttributes; - HANDLE hDevicesKey = NULL; - HANDLE hDeviceKey = NULL; - HANDLE hLevel1Key, hLevel2Key = NULL, hLogConf; - UNICODE_STRING Level2NameU; - WCHAR Level2Name[5]; - ULONG IndexDevice = 0; - ULONG IndexSubKey; - PKEY_BASIC_INFORMATION pDeviceInformation = NULL; - ULONG DeviceInfoLength = sizeof(KEY_BASIC_INFORMATION) + 50 * sizeof(WCHAR); - PKEY_VALUE_PARTIAL_INFORMATION pValueInformation = NULL; - ULONG ValueInfoLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 50 * sizeof(WCHAR); - UNICODE_STRING DeviceName, ValueName; - ULONG RequiredSize; - PCM_FULL_RESOURCE_DESCRIPTOR BootResources = NULL; - ULONG BootResourcesLength; - NTSTATUS Status; - - const UNICODE_STRING IdentifierSerial = RTL_CONSTANT_STRING(L"SerialController"); - UNICODE_STRING HardwareIdSerial = RTL_CONSTANT_STRING(L"*PNP0501\0"); - static ULONG DeviceIndexSerial = 0; - const UNICODE_STRING IdentifierKeyboard = RTL_CONSTANT_STRING(L"KeyboardController"); - UNICODE_STRING HardwareIdKeyboard = RTL_CONSTANT_STRING(L"*PNP0303\0"); - static ULONG DeviceIndexKeyboard = 0; - const UNICODE_STRING IdentifierMouse = RTL_CONSTANT_STRING(L"PointerController"); - /* FIXME: IopEnumerateDetectedDevices() should be rewritten. - * The PnP identifiers can either be hardcoded or parsed from a LegacyXlate - * sections of driver INF files. - */ + UNICODE_STRING IdentifierU = RTL_CONSTANT_STRING(L"Identifier"); + UNICODE_STRING HardwareIDU = RTL_CONSTANT_STRING(L"HardwareID"); + UNICODE_STRING ConfigurationDataU = RTL_CONSTANT_STRING(L"Configuration Data"); + UNICODE_STRING BootConfigU = RTL_CONSTANT_STRING(L"BootConfig"); + UNICODE_STRING LogConfU = RTL_CONSTANT_STRING(L"LogConf"); + OBJECT_ATTRIBUTES ObjectAttributes; + HANDLE hDevicesKey = NULL; + HANDLE hDeviceKey = NULL; + HANDLE hLevel1Key, hLevel2Key = NULL, hLogConf; + UNICODE_STRING Level2NameU; + WCHAR Level2Name[5]; + ULONG IndexDevice = 0; + ULONG IndexSubKey; + PKEY_BASIC_INFORMATION pDeviceInformation = NULL; + ULONG DeviceInfoLength = sizeof(KEY_BASIC_INFORMATION) + 50 * sizeof(WCHAR); + PKEY_VALUE_PARTIAL_INFORMATION pValueInformation = NULL; + ULONG ValueInfoLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 50 * sizeof(WCHAR); + UNICODE_STRING DeviceName, ValueName; + ULONG RequiredSize; + PCM_FULL_RESOURCE_DESCRIPTOR BootResources = NULL; + ULONG BootResourcesLength; + NTSTATUS Status; + + const UNICODE_STRING IdentifierSerial = RTL_CONSTANT_STRING(L"SerialController"); + UNICODE_STRING HardwareIdSerial = RTL_CONSTANT_STRING(L"*PNP0501\0"); + static ULONG DeviceIndexSerial = 0; + const UNICODE_STRING IdentifierKeyboard = RTL_CONSTANT_STRING(L"KeyboardController"); + UNICODE_STRING HardwareIdKeyboard = RTL_CONSTANT_STRING(L"*PNP0303\0"); + static ULONG DeviceIndexKeyboard = 0; + const UNICODE_STRING IdentifierMouse = RTL_CONSTANT_STRING(L"PointerController"); + /* FIXME: IopEnumerateDetectedDevices() should be rewritten. + * The PnP identifiers can either be hardcoded or parsed from a LegacyXlate + * sections of driver INF files. + */ #if defined(SARCH_PC98) - UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*nEC1F00\0"); + UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*nEC1F00\0"); #else - UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*PNP0F13\0"); + UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*PNP0F13\0"); #endif - static ULONG DeviceIndexMouse = 0; - const UNICODE_STRING IdentifierParallel = RTL_CONSTANT_STRING(L"ParallelController"); - UNICODE_STRING HardwareIdParallel = RTL_CONSTANT_STRING(L"*PNP0400\0"); - static ULONG DeviceIndexParallel = 0; - const UNICODE_STRING IdentifierFloppy = RTL_CONSTANT_STRING(L"FloppyDiskPeripheral"); - UNICODE_STRING HardwareIdFloppy = RTL_CONSTANT_STRING(L"*PNP0700\0"); - static ULONG DeviceIndexFloppy = 0; - UNICODE_STRING HardwareIdKey; - PUNICODE_STRING pHardwareId; - ULONG DeviceIndex = 0; - PUCHAR CmResourceList; - ULONG ListCount; + static ULONG DeviceIndexMouse = 0; + const UNICODE_STRING IdentifierParallel = RTL_CONSTANT_STRING(L"ParallelController"); + UNICODE_STRING HardwareIdParallel = RTL_CONSTANT_STRING(L"*PNP0400\0"); + static ULONG DeviceIndexParallel = 0; + const UNICODE_STRING IdentifierFloppy = RTL_CONSTANT_STRING(L"FloppyDiskPeripheral"); + UNICODE_STRING HardwareIdFloppy = RTL_CONSTANT_STRING(L"*PNP0700\0"); + static ULONG DeviceIndexFloppy = 0; + UNICODE_STRING HardwareIdKey; + PUNICODE_STRING pHardwareId; + ULONG DeviceIndex = 0; + PUCHAR CmResourceList; + ULONG ListCount; if (RelativePath) { Status = IopOpenRegistryKeyEx(&hDevicesKey, hBaseKey, RelativePath, KEY_ENUMERATE_SUB_KEYS); + if (!NT_SUCCESS(Status)) { DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); @@ -89,370 +90,444 @@ IopEnumerateDetectedDevices( else hDevicesKey = hBaseKey; - pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); - if (!pDeviceInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - - pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); - if (!pValueInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - - while (TRUE) - { - Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); - if (Status == STATUS_NO_MORE_ENTRIES) - break; - else if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) - { - ExFreePool(pDeviceInformation); - DeviceInfoLength = RequiredSize; - pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); - if (!pDeviceInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; + pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); + if (!pDeviceInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + + pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); + if (!pValueInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + + while (TRUE) + { + Status = ZwEnumerateKey(hDevicesKey, + IndexDevice, + KeyBasicInformation, + pDeviceInformation, + DeviceInfoLength, + &RequiredSize); + + if (Status == STATUS_NO_MORE_ENTRIES) + break; + else if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + { + ExFreePool(pDeviceInformation); + DeviceInfoLength = RequiredSize; + pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); + + if (!pDeviceInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + + Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); + } + + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status); goto cleanup; - } - Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); - } - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } - IndexDevice++; - - /* Open device key */ - DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength; - DeviceName.Buffer = pDeviceInformation->Name; - - Status = IopOpenRegistryKeyEx(&hDeviceKey, hDevicesKey, &DeviceName, - KEY_QUERY_VALUE + (EnumerateSubKeys ? KEY_ENUMERATE_SUB_KEYS : 0)); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } - - /* Read boot resources, and add then to parent ones */ - Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); - if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) - { - ExFreePool(pValueInformation); - ValueInfoLength = RequiredSize; - pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); - if (!pValueInformation) - { - DPRINT("ExAllocatePool() failed\n"); - ZwDeleteKey(hLevel2Key); - Status = STATUS_NO_MEMORY; + } + IndexDevice++; + + /* Open device key */ + DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength; + DeviceName.Buffer = pDeviceInformation->Name; + + Status = IopOpenRegistryKeyEx(&hDeviceKey, hDevicesKey, &DeviceName, + KEY_QUERY_VALUE + (EnumerateSubKeys ? KEY_ENUMERATE_SUB_KEYS : 0)); + + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); goto cleanup; - } - Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); - } - if (Status == STATUS_OBJECT_NAME_NOT_FOUND) - { - BootResources = ParentBootResources; - BootResourcesLength = ParentBootResourcesLength; - } - else if (!NT_SUCCESS(Status)) - { - DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status); - goto nextdevice; - } - else if (pValueInformation->Type != REG_FULL_RESOURCE_DESCRIPTOR) - { - DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_FULL_RESOURCE_DESCRIPTOR); - goto nextdevice; - } - else - { - static const ULONG Header = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList.PartialDescriptors); - - /* Concatenate current resources and parent ones */ - if (ParentBootResourcesLength == 0) - BootResourcesLength = pValueInformation->DataLength; - else - BootResourcesLength = ParentBootResourcesLength - + pValueInformation->DataLength - - Header; - BootResources = ExAllocatePool(PagedPool, BootResourcesLength); - if (!BootResources) - { - DPRINT("ExAllocatePool() failed\n"); + } + + /* Read boot resources, and add then to parent ones */ + Status = ZwQueryValueKey(hDeviceKey, + &ConfigurationDataU, + KeyValuePartialInformation, + pValueInformation, + ValueInfoLength, + &RequiredSize); + + if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + { + ExFreePool(pValueInformation); + ValueInfoLength = RequiredSize; + pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); + + if (!pValueInformation) + { + DPRINT("ExAllocatePool() failed\n"); + ZwDeleteKey(hLevel2Key); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + + Status = ZwQueryValueKey(hDeviceKey, + &ConfigurationDataU, + KeyValuePartialInformation, + pValueInformation, + ValueInfoLength, + &RequiredSize); + } + + if (Status == STATUS_OBJECT_NAME_NOT_FOUND) + { + BootResources = ParentBootResources; + BootResourcesLength = ParentBootResourcesLength; + } + else if (!NT_SUCCESS(Status)) + { + DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status); + goto nextdevice; + } + else if (pValueInformation->Type != REG_FULL_RESOURCE_DESCRIPTOR) + { + DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_FULL_RESOURCE_DESCRIPTOR); goto nextdevice; - } - if (ParentBootResourcesLength < sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) - { - RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength); - } - else if (ParentBootResources->PartialResourceList.PartialDescriptors[ParentBootResources->PartialResourceList.Count - 1].Type == CmResourceTypeDeviceSpecific) - { - RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength); - RtlCopyMemory( - (PVOID)((ULONG_PTR)BootResources + pValueInformation->DataLength), - (PVOID)((ULONG_PTR)ParentBootResources + Header), - ParentBootResourcesLength - Header); - BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count; - } - else - { - RtlCopyMemory(BootResources, pValueInformation->Data, Header); - RtlCopyMemory( - (PVOID)((ULONG_PTR)BootResources + Header), - (PVOID)((ULONG_PTR)ParentBootResources + Header), - ParentBootResourcesLength - Header); - RtlCopyMemory( - (PVOID)((ULONG_PTR)BootResources + ParentBootResourcesLength), - pValueInformation->Data + Header, - pValueInformation->DataLength - Header); - BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count; - } - } - - if (EnumerateSubKeys) - { - IndexSubKey = 0; - while (TRUE) - { - Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); - if (Status == STATUS_NO_MORE_ENTRIES) - break; - else if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + } + else + { + static const ULONG Header = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList.PartialDescriptors); + + /* Concatenate current resources and parent ones */ + if (ParentBootResourcesLength == 0) + BootResourcesLength = pValueInformation->DataLength; + else + BootResourcesLength = ParentBootResourcesLength + + pValueInformation->DataLength + - Header; + + BootResources = ExAllocatePool(PagedPool, BootResourcesLength); + if (!BootResources) { - ExFreePool(pDeviceInformation); - DeviceInfoLength = RequiredSize; - pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); - if (!pDeviceInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); + DPRINT("ExAllocatePool() failed\n"); + goto nextdevice; } - if (!NT_SUCCESS(Status)) + + if (ParentBootResourcesLength < sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) { - DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status); - goto cleanup; + RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength); } - IndexSubKey++; - DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength; - DeviceName.Buffer = pDeviceInformation->Name; - - Status = IopEnumerateDetectedDevices( - hDeviceKey, - &DeviceName, - hRootKey, - TRUE, - BootResources, - BootResourcesLength); - if (!NT_SUCCESS(Status)) - goto cleanup; - } - } - - /* Read identifier */ - Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); - if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) - { - ExFreePool(pValueInformation); - ValueInfoLength = RequiredSize; - pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); - if (!pValueInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); - } - if (!NT_SUCCESS(Status)) - { - if (Status != STATUS_OBJECT_NAME_NOT_FOUND) - { - DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status); + else if (ParentBootResources->PartialResourceList.PartialDescriptors[ParentBootResources->PartialResourceList.Count - 1].Type == CmResourceTypeDeviceSpecific) + { + RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength); + RtlCopyMemory( + (PVOID)((ULONG_PTR)BootResources + pValueInformation->DataLength), + (PVOID)((ULONG_PTR)ParentBootResources + Header), + ParentBootResourcesLength - Header); + BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count; + } + else + { + RtlCopyMemory(BootResources, pValueInformation->Data, Header); + RtlCopyMemory( + (PVOID)((ULONG_PTR)BootResources + Header), + (PVOID)((ULONG_PTR)ParentBootResources + Header), + ParentBootResourcesLength - Header); + RtlCopyMemory( + (PVOID)((ULONG_PTR)BootResources + ParentBootResourcesLength), + pValueInformation->Data + Header, + pValueInformation->DataLength - Header); + BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count; + } + } + + if (EnumerateSubKeys) + { + IndexSubKey = 0; + + while (TRUE) + { + Status = ZwEnumerateKey(hDeviceKey, + IndexSubKey, + KeyBasicInformation, + pDeviceInformation, + DeviceInfoLength, + &RequiredSize); + + if (Status == STATUS_NO_MORE_ENTRIES) + break; + else if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + { + ExFreePool(pDeviceInformation); + DeviceInfoLength = RequiredSize; + pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); + + if (!pDeviceInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + + Status = ZwEnumerateKey(hDeviceKey, + IndexSubKey, + KeyBasicInformation, + pDeviceInformation, + DeviceInfoLength, + &RequiredSize); + } + + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status); + goto cleanup; + } + IndexSubKey++; + DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength; + DeviceName.Buffer = pDeviceInformation->Name; + + Status = IopEnumerateDetectedDevices( + hDeviceKey, + &DeviceName, + hRootKey, + TRUE, + BootResources, + BootResourcesLength); + + if (!NT_SUCCESS(Status)) + goto cleanup; + } + } + + /* Read identifier */ + Status = ZwQueryValueKey(hDeviceKey, + &IdentifierU, + KeyValuePartialInformation, + pValueInformation, + ValueInfoLength, + &RequiredSize); + + if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + { + ExFreePool(pValueInformation); + ValueInfoLength = RequiredSize; + pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); + + if (!pValueInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + + Status = ZwQueryValueKey(hDeviceKey, + &IdentifierU, + KeyValuePartialInformation, + pValueInformation, + ValueInfoLength, + &RequiredSize); + } + + if (!NT_SUCCESS(Status)) + { + if (Status != STATUS_OBJECT_NAME_NOT_FOUND) + { + DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status); + goto nextdevice; + } + ValueName.Length = ValueName.MaximumLength = 0; + } + else if (pValueInformation->Type != REG_SZ) + { + DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_SZ); goto nextdevice; - } - ValueName.Length = ValueName.MaximumLength = 0; - } - else if (pValueInformation->Type != REG_SZ) - { - DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_SZ); - goto nextdevice; - } - else - { - /* Assign hardware id to this device */ - ValueName.Length = ValueName.MaximumLength = (USHORT)pValueInformation->DataLength; - ValueName.Buffer = (PWCHAR)pValueInformation->Data; - if (ValueName.Length >= sizeof(WCHAR) && ValueName.Buffer[ValueName.Length / sizeof(WCHAR) - 1] == UNICODE_NULL) - ValueName.Length -= sizeof(WCHAR); - } - - if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierSerial, FALSE) == 0) - { - pHardwareId = &HardwareIdSerial; - DeviceIndex = DeviceIndexSerial++; - } - else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierKeyboard, FALSE) == 0) - { - pHardwareId = &HardwareIdKeyboard; - DeviceIndex = DeviceIndexKeyboard++; - } - else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierMouse, FALSE) == 0) - { - pHardwareId = &HardwareIdMouse; - DeviceIndex = DeviceIndexMouse++; - } - else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierParallel, FALSE) == 0) - { - pHardwareId = &HardwareIdParallel; - DeviceIndex = DeviceIndexParallel++; - } - else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierFloppy, FALSE) == 0) - { - pHardwareId = &HardwareIdFloppy; - DeviceIndex = DeviceIndexFloppy++; - } - else - { - /* Unknown key path */ - DPRINT("Unknown key path '%wZ'\n", RelativePath); - goto nextdevice; - } - - /* Prepare hardware id key (hardware id value without final \0) */ - HardwareIdKey = *pHardwareId; - HardwareIdKey.Length -= sizeof(UNICODE_NULL); - - /* Add the detected device to Root key */ - InitializeObjectAttributes(&ObjectAttributes, &HardwareIdKey, OBJ_KERNEL_HANDLE, hRootKey, NULL); - Status = ZwCreateKey( - &hLevel1Key, - KEY_CREATE_SUB_KEY, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_NON_VOLATILE, - NULL); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); - goto nextdevice; - } - swprintf(Level2Name, L"%04lu", DeviceIndex); - RtlInitUnicodeString(&Level2NameU, Level2Name); - InitializeObjectAttributes(&ObjectAttributes, &Level2NameU, OBJ_KERNEL_HANDLE, hLevel1Key, NULL); - Status = ZwCreateKey( - &hLevel2Key, - KEY_SET_VALUE | KEY_CREATE_SUB_KEY, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_NON_VOLATILE, - NULL); - ZwClose(hLevel1Key); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); - goto nextdevice; - } - DPRINT("Found %wZ #%lu (%wZ)\n", &ValueName, DeviceIndex, &HardwareIdKey); - Status = ZwSetValueKey(hLevel2Key, &HardwareIDU, 0, REG_MULTI_SZ, pHardwareId->Buffer, pHardwareId->MaximumLength); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status); - ZwDeleteKey(hLevel2Key); - goto nextdevice; - } - /* Create 'LogConf' subkey */ - InitializeObjectAttributes(&ObjectAttributes, &LogConfU, OBJ_KERNEL_HANDLE, hLevel2Key, NULL); - Status = ZwCreateKey( - &hLogConf, - KEY_SET_VALUE, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_VOLATILE, - NULL); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); - ZwDeleteKey(hLevel2Key); - goto nextdevice; - } - if (BootResourcesLength >= sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) - { - CmResourceList = ExAllocatePool(PagedPool, BootResourcesLength + sizeof(ULONG)); - if (!CmResourceList) - { - ZwClose(hLogConf); - ZwDeleteKey(hLevel2Key); + } + else + { + /* Assign hardware id to this device */ + ValueName.Length = ValueName.MaximumLength = (USHORT)pValueInformation->DataLength; + ValueName.Buffer = (PWCHAR)pValueInformation->Data; + if (ValueName.Length >= sizeof(WCHAR) && ValueName.Buffer[ValueName.Length / sizeof(WCHAR) - 1] == UNICODE_NULL) + ValueName.Length -= sizeof(WCHAR); + } + + if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierSerial, FALSE) == 0) + { + pHardwareId = &HardwareIdSerial; + DeviceIndex = DeviceIndexSerial++; + } + else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierKeyboard, FALSE) == 0) + { + pHardwareId = &HardwareIdKeyboard; + DeviceIndex = DeviceIndexKeyboard++; + } + else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierMouse, FALSE) == 0) + { + pHardwareId = &HardwareIdMouse; + DeviceIndex = DeviceIndexMouse++; + } + else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierParallel, FALSE) == 0) + { + pHardwareId = &HardwareIdParallel; + DeviceIndex = DeviceIndexParallel++; + } + else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierFloppy, FALSE) == 0) + { + pHardwareId = &HardwareIdFloppy; + DeviceIndex = DeviceIndexFloppy++; + } + else + { + /* Unknown key path */ + DPRINT("Unknown key path '%wZ'\n", RelativePath); + goto nextdevice; + } + + /* Prepare hardware id key (hardware id value without final \0) */ + HardwareIdKey = *pHardwareId; + HardwareIdKey.Length -= sizeof(UNICODE_NULL); + + /* Add the detected device to Root key */ + InitializeObjectAttributes(&ObjectAttributes, &HardwareIdKey, OBJ_KERNEL_HANDLE, hRootKey, NULL); + + Status = ZwCreateKey( + &hLevel1Key, + KEY_CREATE_SUB_KEY, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + NULL); + + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); + goto nextdevice; + } + + swprintf(Level2Name, L"%04lu", DeviceIndex); + RtlInitUnicodeString(&Level2NameU, Level2Name); + InitializeObjectAttributes(&ObjectAttributes, &Level2NameU, OBJ_KERNEL_HANDLE, hLevel1Key, NULL); + + Status = ZwCreateKey( + &hLevel2Key, + KEY_SET_VALUE | KEY_CREATE_SUB_KEY, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + NULL); + + ZwClose(hLevel1Key); + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); goto nextdevice; - } - - /* Add the list count (1st member of CM_RESOURCE_LIST) */ - ListCount = 1; - RtlCopyMemory(CmResourceList, - &ListCount, - sizeof(ULONG)); - - /* Now add the actual list (2nd member of CM_RESOURCE_LIST) */ - RtlCopyMemory(CmResourceList + sizeof(ULONG), - BootResources, - BootResourcesLength); - - /* Save boot resources to 'LogConf\BootConfig' */ - Status = ZwSetValueKey(hLogConf, &BootConfigU, 0, REG_RESOURCE_LIST, CmResourceList, BootResourcesLength + sizeof(ULONG)); - if (!NT_SUCCESS(Status)) - { + } + + DPRINT("Found %wZ #%lu (%wZ)\n", &ValueName, DeviceIndex, &HardwareIdKey); + Status = ZwSetValueKey(hLevel2Key, &HardwareIDU, 0, REG_MULTI_SZ, pHardwareId->Buffer, pHardwareId->MaximumLength); + + if (!NT_SUCCESS(Status)) + { DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status); - ZwClose(hLogConf); ZwDeleteKey(hLevel2Key); goto nextdevice; - } - } - ZwClose(hLogConf); + } + + /* Create 'LogConf' subkey */ + InitializeObjectAttributes(&ObjectAttributes, &LogConfU, OBJ_KERNEL_HANDLE, hLevel2Key, NULL); + + Status = ZwCreateKey( + &hLogConf, + KEY_SET_VALUE, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_VOLATILE, + NULL); + + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); + ZwDeleteKey(hLevel2Key); + goto nextdevice; + } + + if (BootResourcesLength >= sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) + { + CmResourceList = ExAllocatePool(PagedPool, BootResourcesLength + sizeof(ULONG)); + if (!CmResourceList) + { + ZwClose(hLogConf); + ZwDeleteKey(hLevel2Key); + goto nextdevice; + } + + /* Add the list count (1st member of CM_RESOURCE_LIST) */ + ListCount = 1; + RtlCopyMemory(CmResourceList, + &ListCount, + sizeof(ULONG)); + + /* Now add the actual list (2nd member of CM_RESOURCE_LIST) */ + RtlCopyMemory(CmResourceList + sizeof(ULONG), + BootResources, + BootResourcesLength); + + /* Save boot resources to 'LogConf\BootConfig' */ + Status = ZwSetValueKey(hLogConf, + &BootConfigU, + 0, + REG_RESOURCE_LIST, + CmResourceList, + BootResourcesLength + sizeof(ULONG)); + + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status); + ZwClose(hLogConf); + ZwDeleteKey(hLevel2Key); + goto nextdevice; + } + } + ZwClose(hLogConf); nextdevice: - if (BootResources && BootResources != ParentBootResources) - { - ExFreePool(BootResources); - BootResources = NULL; - } - if (hLevel2Key) - { - ZwClose(hLevel2Key); - hLevel2Key = NULL; - } - if (hDeviceKey) - { - ZwClose(hDeviceKey); - hDeviceKey = NULL; - } - } - - Status = STATUS_SUCCESS; + if (BootResources && BootResources != ParentBootResources) + { + ExFreePool(BootResources); + BootResources = NULL; + } + if (hLevel2Key) + { + ZwClose(hLevel2Key); + hLevel2Key = NULL; + } + if (hDeviceKey) + { + ZwClose(hDeviceKey); + hDeviceKey = NULL; + } + } + + Status = STATUS_SUCCESS; cleanup: - if (hDevicesKey && hDevicesKey != hBaseKey) - ZwClose(hDevicesKey); - if (hDeviceKey) - ZwClose(hDeviceKey); - if (pDeviceInformation) - ExFreePool(pDeviceInformation); - if (pValueInformation) - ExFreePool(pValueInformation); - return Status; + if (hDevicesKey && hDevicesKey != hBaseKey) + ZwClose(hDevicesKey); + if (hDeviceKey) + ZwClose(hDeviceKey); + if (pDeviceInformation) + ExFreePool(pDeviceInformation); + if (pValueInformation) + ExFreePool(pValueInformation); + + return Status; } static
1 year, 7 months
1
0
0
0
[reactos] 01/02: [NTOS:PNP] Move Firmware Mapper functions into new file CORE-18962
by Stanislav Motylkov
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=484c26d99fea3ee24796a…
commit 484c26d99fea3ee24796a27aa0b49c0c37dd3024 Author: Stanislav Motylkov <x86corez(a)gmail.com> AuthorDate: Mon May 8 15:49:46 2023 +0200 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Mon May 8 16:07:01 2023 +0200 [NTOS:PNP] Move Firmware Mapper functions into new file CORE-18962 --- ntoskrnl/io/pnpmgr/pnpmap.c | 585 ++++++++++++++++++++++++++++++++++++++++++++ ntoskrnl/io/pnpmgr/pnpmgr.c | 570 ------------------------------------------ ntoskrnl/ntos.cmake | 1 + 3 files changed, 586 insertions(+), 570 deletions(-) diff --git a/ntoskrnl/io/pnpmgr/pnpmap.c b/ntoskrnl/io/pnpmgr/pnpmap.c new file mode 100644 index 00000000000..795e4a3c2ce --- /dev/null +++ b/ntoskrnl/io/pnpmgr/pnpmap.c @@ -0,0 +1,585 @@ +/* + * PROJECT: ReactOS Kernel + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) + * PURPOSE: PnP manager Firmware Mapper functions + * COPYRIGHT: Copyright 2006-2007 Hervé Poussineau <hpoussin(a)reactos.org> + * Copyright 2008-2011 Cameron Gutman <cameron.gutman(a)reactos.org> + */ + +/* INCLUDES ******************************************************************/ + +#include <ntoskrnl.h> +#define NDEBUG +#include <debug.h> + +/* FUNCTIONS *****************************************************************/ + +static +CODE_SEG("INIT") +NTSTATUS +IopEnumerateDetectedDevices( + IN HANDLE hBaseKey, + IN PUNICODE_STRING RelativePath OPTIONAL, + IN HANDLE hRootKey, + IN BOOLEAN EnumerateSubKeys, + IN PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources, + IN ULONG ParentBootResourcesLength) +{ + UNICODE_STRING IdentifierU = RTL_CONSTANT_STRING(L"Identifier"); + UNICODE_STRING HardwareIDU = RTL_CONSTANT_STRING(L"HardwareID"); + UNICODE_STRING ConfigurationDataU = RTL_CONSTANT_STRING(L"Configuration Data"); + UNICODE_STRING BootConfigU = RTL_CONSTANT_STRING(L"BootConfig"); + UNICODE_STRING LogConfU = RTL_CONSTANT_STRING(L"LogConf"); + OBJECT_ATTRIBUTES ObjectAttributes; + HANDLE hDevicesKey = NULL; + HANDLE hDeviceKey = NULL; + HANDLE hLevel1Key, hLevel2Key = NULL, hLogConf; + UNICODE_STRING Level2NameU; + WCHAR Level2Name[5]; + ULONG IndexDevice = 0; + ULONG IndexSubKey; + PKEY_BASIC_INFORMATION pDeviceInformation = NULL; + ULONG DeviceInfoLength = sizeof(KEY_BASIC_INFORMATION) + 50 * sizeof(WCHAR); + PKEY_VALUE_PARTIAL_INFORMATION pValueInformation = NULL; + ULONG ValueInfoLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 50 * sizeof(WCHAR); + UNICODE_STRING DeviceName, ValueName; + ULONG RequiredSize; + PCM_FULL_RESOURCE_DESCRIPTOR BootResources = NULL; + ULONG BootResourcesLength; + NTSTATUS Status; + + const UNICODE_STRING IdentifierSerial = RTL_CONSTANT_STRING(L"SerialController"); + UNICODE_STRING HardwareIdSerial = RTL_CONSTANT_STRING(L"*PNP0501\0"); + static ULONG DeviceIndexSerial = 0; + const UNICODE_STRING IdentifierKeyboard = RTL_CONSTANT_STRING(L"KeyboardController"); + UNICODE_STRING HardwareIdKeyboard = RTL_CONSTANT_STRING(L"*PNP0303\0"); + static ULONG DeviceIndexKeyboard = 0; + const UNICODE_STRING IdentifierMouse = RTL_CONSTANT_STRING(L"PointerController"); + /* FIXME: IopEnumerateDetectedDevices() should be rewritten. + * The PnP identifiers can either be hardcoded or parsed from a LegacyXlate + * sections of driver INF files. + */ +#if defined(SARCH_PC98) + UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*nEC1F00\0"); +#else + UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*PNP0F13\0"); +#endif + static ULONG DeviceIndexMouse = 0; + const UNICODE_STRING IdentifierParallel = RTL_CONSTANT_STRING(L"ParallelController"); + UNICODE_STRING HardwareIdParallel = RTL_CONSTANT_STRING(L"*PNP0400\0"); + static ULONG DeviceIndexParallel = 0; + const UNICODE_STRING IdentifierFloppy = RTL_CONSTANT_STRING(L"FloppyDiskPeripheral"); + UNICODE_STRING HardwareIdFloppy = RTL_CONSTANT_STRING(L"*PNP0700\0"); + static ULONG DeviceIndexFloppy = 0; + UNICODE_STRING HardwareIdKey; + PUNICODE_STRING pHardwareId; + ULONG DeviceIndex = 0; + PUCHAR CmResourceList; + ULONG ListCount; + + if (RelativePath) + { + Status = IopOpenRegistryKeyEx(&hDevicesKey, hBaseKey, RelativePath, KEY_ENUMERATE_SUB_KEYS); + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); + goto cleanup; + } + } + else + hDevicesKey = hBaseKey; + + pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); + if (!pDeviceInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + + pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); + if (!pValueInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + + while (TRUE) + { + Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); + if (Status == STATUS_NO_MORE_ENTRIES) + break; + else if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + { + ExFreePool(pDeviceInformation); + DeviceInfoLength = RequiredSize; + pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); + if (!pDeviceInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); + } + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status); + goto cleanup; + } + IndexDevice++; + + /* Open device key */ + DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength; + DeviceName.Buffer = pDeviceInformation->Name; + + Status = IopOpenRegistryKeyEx(&hDeviceKey, hDevicesKey, &DeviceName, + KEY_QUERY_VALUE + (EnumerateSubKeys ? KEY_ENUMERATE_SUB_KEYS : 0)); + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); + goto cleanup; + } + + /* Read boot resources, and add then to parent ones */ + Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); + if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + { + ExFreePool(pValueInformation); + ValueInfoLength = RequiredSize; + pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); + if (!pValueInformation) + { + DPRINT("ExAllocatePool() failed\n"); + ZwDeleteKey(hLevel2Key); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); + } + if (Status == STATUS_OBJECT_NAME_NOT_FOUND) + { + BootResources = ParentBootResources; + BootResourcesLength = ParentBootResourcesLength; + } + else if (!NT_SUCCESS(Status)) + { + DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status); + goto nextdevice; + } + else if (pValueInformation->Type != REG_FULL_RESOURCE_DESCRIPTOR) + { + DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_FULL_RESOURCE_DESCRIPTOR); + goto nextdevice; + } + else + { + static const ULONG Header = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList.PartialDescriptors); + + /* Concatenate current resources and parent ones */ + if (ParentBootResourcesLength == 0) + BootResourcesLength = pValueInformation->DataLength; + else + BootResourcesLength = ParentBootResourcesLength + + pValueInformation->DataLength + - Header; + BootResources = ExAllocatePool(PagedPool, BootResourcesLength); + if (!BootResources) + { + DPRINT("ExAllocatePool() failed\n"); + goto nextdevice; + } + if (ParentBootResourcesLength < sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) + { + RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength); + } + else if (ParentBootResources->PartialResourceList.PartialDescriptors[ParentBootResources->PartialResourceList.Count - 1].Type == CmResourceTypeDeviceSpecific) + { + RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength); + RtlCopyMemory( + (PVOID)((ULONG_PTR)BootResources + pValueInformation->DataLength), + (PVOID)((ULONG_PTR)ParentBootResources + Header), + ParentBootResourcesLength - Header); + BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count; + } + else + { + RtlCopyMemory(BootResources, pValueInformation->Data, Header); + RtlCopyMemory( + (PVOID)((ULONG_PTR)BootResources + Header), + (PVOID)((ULONG_PTR)ParentBootResources + Header), + ParentBootResourcesLength - Header); + RtlCopyMemory( + (PVOID)((ULONG_PTR)BootResources + ParentBootResourcesLength), + pValueInformation->Data + Header, + pValueInformation->DataLength - Header); + BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count; + } + } + + if (EnumerateSubKeys) + { + IndexSubKey = 0; + while (TRUE) + { + Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); + if (Status == STATUS_NO_MORE_ENTRIES) + break; + else if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + { + ExFreePool(pDeviceInformation); + DeviceInfoLength = RequiredSize; + pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); + if (!pDeviceInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); + } + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status); + goto cleanup; + } + IndexSubKey++; + DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength; + DeviceName.Buffer = pDeviceInformation->Name; + + Status = IopEnumerateDetectedDevices( + hDeviceKey, + &DeviceName, + hRootKey, + TRUE, + BootResources, + BootResourcesLength); + if (!NT_SUCCESS(Status)) + goto cleanup; + } + } + + /* Read identifier */ + Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); + if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) + { + ExFreePool(pValueInformation); + ValueInfoLength = RequiredSize; + pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); + if (!pValueInformation) + { + DPRINT("ExAllocatePool() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); + } + if (!NT_SUCCESS(Status)) + { + if (Status != STATUS_OBJECT_NAME_NOT_FOUND) + { + DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status); + goto nextdevice; + } + ValueName.Length = ValueName.MaximumLength = 0; + } + else if (pValueInformation->Type != REG_SZ) + { + DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_SZ); + goto nextdevice; + } + else + { + /* Assign hardware id to this device */ + ValueName.Length = ValueName.MaximumLength = (USHORT)pValueInformation->DataLength; + ValueName.Buffer = (PWCHAR)pValueInformation->Data; + if (ValueName.Length >= sizeof(WCHAR) && ValueName.Buffer[ValueName.Length / sizeof(WCHAR) - 1] == UNICODE_NULL) + ValueName.Length -= sizeof(WCHAR); + } + + if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierSerial, FALSE) == 0) + { + pHardwareId = &HardwareIdSerial; + DeviceIndex = DeviceIndexSerial++; + } + else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierKeyboard, FALSE) == 0) + { + pHardwareId = &HardwareIdKeyboard; + DeviceIndex = DeviceIndexKeyboard++; + } + else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierMouse, FALSE) == 0) + { + pHardwareId = &HardwareIdMouse; + DeviceIndex = DeviceIndexMouse++; + } + else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierParallel, FALSE) == 0) + { + pHardwareId = &HardwareIdParallel; + DeviceIndex = DeviceIndexParallel++; + } + else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierFloppy, FALSE) == 0) + { + pHardwareId = &HardwareIdFloppy; + DeviceIndex = DeviceIndexFloppy++; + } + else + { + /* Unknown key path */ + DPRINT("Unknown key path '%wZ'\n", RelativePath); + goto nextdevice; + } + + /* Prepare hardware id key (hardware id value without final \0) */ + HardwareIdKey = *pHardwareId; + HardwareIdKey.Length -= sizeof(UNICODE_NULL); + + /* Add the detected device to Root key */ + InitializeObjectAttributes(&ObjectAttributes, &HardwareIdKey, OBJ_KERNEL_HANDLE, hRootKey, NULL); + Status = ZwCreateKey( + &hLevel1Key, + KEY_CREATE_SUB_KEY, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); + goto nextdevice; + } + swprintf(Level2Name, L"%04lu", DeviceIndex); + RtlInitUnicodeString(&Level2NameU, Level2Name); + InitializeObjectAttributes(&ObjectAttributes, &Level2NameU, OBJ_KERNEL_HANDLE, hLevel1Key, NULL); + Status = ZwCreateKey( + &hLevel2Key, + KEY_SET_VALUE | KEY_CREATE_SUB_KEY, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + NULL); + ZwClose(hLevel1Key); + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); + goto nextdevice; + } + DPRINT("Found %wZ #%lu (%wZ)\n", &ValueName, DeviceIndex, &HardwareIdKey); + Status = ZwSetValueKey(hLevel2Key, &HardwareIDU, 0, REG_MULTI_SZ, pHardwareId->Buffer, pHardwareId->MaximumLength); + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status); + ZwDeleteKey(hLevel2Key); + goto nextdevice; + } + /* Create 'LogConf' subkey */ + InitializeObjectAttributes(&ObjectAttributes, &LogConfU, OBJ_KERNEL_HANDLE, hLevel2Key, NULL); + Status = ZwCreateKey( + &hLogConf, + KEY_SET_VALUE, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_VOLATILE, + NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); + ZwDeleteKey(hLevel2Key); + goto nextdevice; + } + if (BootResourcesLength >= sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) + { + CmResourceList = ExAllocatePool(PagedPool, BootResourcesLength + sizeof(ULONG)); + if (!CmResourceList) + { + ZwClose(hLogConf); + ZwDeleteKey(hLevel2Key); + goto nextdevice; + } + + /* Add the list count (1st member of CM_RESOURCE_LIST) */ + ListCount = 1; + RtlCopyMemory(CmResourceList, + &ListCount, + sizeof(ULONG)); + + /* Now add the actual list (2nd member of CM_RESOURCE_LIST) */ + RtlCopyMemory(CmResourceList + sizeof(ULONG), + BootResources, + BootResourcesLength); + + /* Save boot resources to 'LogConf\BootConfig' */ + Status = ZwSetValueKey(hLogConf, &BootConfigU, 0, REG_RESOURCE_LIST, CmResourceList, BootResourcesLength + sizeof(ULONG)); + if (!NT_SUCCESS(Status)) + { + DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status); + ZwClose(hLogConf); + ZwDeleteKey(hLevel2Key); + goto nextdevice; + } + } + ZwClose(hLogConf); + +nextdevice: + if (BootResources && BootResources != ParentBootResources) + { + ExFreePool(BootResources); + BootResources = NULL; + } + if (hLevel2Key) + { + ZwClose(hLevel2Key); + hLevel2Key = NULL; + } + if (hDeviceKey) + { + ZwClose(hDeviceKey); + hDeviceKey = NULL; + } + } + + Status = STATUS_SUCCESS; + +cleanup: + if (hDevicesKey && hDevicesKey != hBaseKey) + ZwClose(hDevicesKey); + if (hDeviceKey) + ZwClose(hDeviceKey); + if (pDeviceInformation) + ExFreePool(pDeviceInformation); + if (pValueInformation) + ExFreePool(pValueInformation); + return Status; +} + +static +CODE_SEG("INIT") +BOOLEAN +IopIsFirmwareMapperDisabled(VOID) +{ + UNICODE_STRING KeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CURRENTCONTROLSET\\Control\\Pnp"); + UNICODE_STRING KeyNameU = RTL_CONSTANT_STRING(L"DisableFirmwareMapper"); + OBJECT_ATTRIBUTES ObjectAttributes; + HANDLE hPnpKey; + PKEY_VALUE_PARTIAL_INFORMATION KeyInformation; + ULONG DesiredLength, Length; + ULONG KeyValue = 0; + NTSTATUS Status; + + InitializeObjectAttributes(&ObjectAttributes, &KeyPathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); + Status = ZwOpenKey(&hPnpKey, KEY_QUERY_VALUE, &ObjectAttributes); + if (NT_SUCCESS(Status)) + { + Status = ZwQueryValueKey(hPnpKey, + &KeyNameU, + KeyValuePartialInformation, + NULL, + 0, + &DesiredLength); + if ((Status == STATUS_BUFFER_TOO_SMALL) || + (Status == STATUS_BUFFER_OVERFLOW)) + { + Length = DesiredLength; + KeyInformation = ExAllocatePool(PagedPool, Length); + if (KeyInformation) + { + Status = ZwQueryValueKey(hPnpKey, + &KeyNameU, + KeyValuePartialInformation, + KeyInformation, + Length, + &DesiredLength); + if (NT_SUCCESS(Status) && KeyInformation->DataLength == sizeof(ULONG)) + { + KeyValue = (ULONG)(*KeyInformation->Data); + } + else + { + DPRINT1("ZwQueryValueKey(%wZ%wZ) failed\n", &KeyPathU, &KeyNameU); + } + + ExFreePool(KeyInformation); + } + else + { + DPRINT1("Failed to allocate memory for registry query\n"); + } + } + else + { + DPRINT1("ZwQueryValueKey(%wZ%wZ) failed with status 0x%08lx\n", &KeyPathU, &KeyNameU, Status); + } + + ZwClose(hPnpKey); + } + else + { + DPRINT1("ZwOpenKey(%wZ) failed with status 0x%08lx\n", &KeyPathU, Status); + } + + DPRINT("Firmware mapper is %s\n", KeyValue != 0 ? "disabled" : "enabled"); + + return (KeyValue != 0) ? TRUE : FALSE; +} + +CODE_SEG("INIT") +NTSTATUS +NTAPI +IopUpdateRootKey(VOID) +{ + UNICODE_STRING EnumU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum"); + UNICODE_STRING RootPathU = RTL_CONSTANT_STRING(L"Root"); + UNICODE_STRING MultiKeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter"); + OBJECT_ATTRIBUTES ObjectAttributes; + HANDLE hEnum, hRoot; + NTSTATUS Status; + + InitializeObjectAttributes(&ObjectAttributes, &EnumU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); + Status = ZwCreateKey(&hEnum, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwCreateKey() failed with status 0x%08lx\n", Status); + return Status; + } + + InitializeObjectAttributes(&ObjectAttributes, &RootPathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, hEnum, NULL); + Status = ZwCreateKey(&hRoot, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); + ZwClose(hEnum); + if (!NT_SUCCESS(Status)) + { + DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status); + return Status; + } + + if (!IopIsFirmwareMapperDisabled()) + { + Status = IopOpenRegistryKeyEx(&hEnum, NULL, &MultiKeyPathU, KEY_ENUMERATE_SUB_KEYS); + if (!NT_SUCCESS(Status)) + { + /* Nothing to do, don't return with an error status */ + DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); + ZwClose(hRoot); + return STATUS_SUCCESS; + } + Status = IopEnumerateDetectedDevices( + hEnum, + NULL, + hRoot, + TRUE, + NULL, + 0); + ZwClose(hEnum); + } + else + { + /* Enumeration is disabled */ + Status = STATUS_SUCCESS; + } + + ZwClose(hRoot); + + return Status; +} diff --git a/ntoskrnl/io/pnpmgr/pnpmgr.c b/ntoskrnl/io/pnpmgr/pnpmgr.c index 87bf857e9fc..2b92983a9a0 100644 --- a/ntoskrnl/io/pnpmgr/pnpmgr.c +++ b/ntoskrnl/io/pnpmgr/pnpmgr.c @@ -880,576 +880,6 @@ cleanup: return Status; } -static -CODE_SEG("INIT") -NTSTATUS -IopEnumerateDetectedDevices( - IN HANDLE hBaseKey, - IN PUNICODE_STRING RelativePath OPTIONAL, - IN HANDLE hRootKey, - IN BOOLEAN EnumerateSubKeys, - IN PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources, - IN ULONG ParentBootResourcesLength) -{ - UNICODE_STRING IdentifierU = RTL_CONSTANT_STRING(L"Identifier"); - UNICODE_STRING HardwareIDU = RTL_CONSTANT_STRING(L"HardwareID"); - UNICODE_STRING ConfigurationDataU = RTL_CONSTANT_STRING(L"Configuration Data"); - UNICODE_STRING BootConfigU = RTL_CONSTANT_STRING(L"BootConfig"); - UNICODE_STRING LogConfU = RTL_CONSTANT_STRING(L"LogConf"); - OBJECT_ATTRIBUTES ObjectAttributes; - HANDLE hDevicesKey = NULL; - HANDLE hDeviceKey = NULL; - HANDLE hLevel1Key, hLevel2Key = NULL, hLogConf; - UNICODE_STRING Level2NameU; - WCHAR Level2Name[5]; - ULONG IndexDevice = 0; - ULONG IndexSubKey; - PKEY_BASIC_INFORMATION pDeviceInformation = NULL; - ULONG DeviceInfoLength = sizeof(KEY_BASIC_INFORMATION) + 50 * sizeof(WCHAR); - PKEY_VALUE_PARTIAL_INFORMATION pValueInformation = NULL; - ULONG ValueInfoLength = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 50 * sizeof(WCHAR); - UNICODE_STRING DeviceName, ValueName; - ULONG RequiredSize; - PCM_FULL_RESOURCE_DESCRIPTOR BootResources = NULL; - ULONG BootResourcesLength; - NTSTATUS Status; - - const UNICODE_STRING IdentifierSerial = RTL_CONSTANT_STRING(L"SerialController"); - UNICODE_STRING HardwareIdSerial = RTL_CONSTANT_STRING(L"*PNP0501\0"); - static ULONG DeviceIndexSerial = 0; - const UNICODE_STRING IdentifierKeyboard = RTL_CONSTANT_STRING(L"KeyboardController"); - UNICODE_STRING HardwareIdKeyboard = RTL_CONSTANT_STRING(L"*PNP0303\0"); - static ULONG DeviceIndexKeyboard = 0; - const UNICODE_STRING IdentifierMouse = RTL_CONSTANT_STRING(L"PointerController"); - /* FIXME: IopEnumerateDetectedDevices() should be rewritten. - * The PnP identifiers can either be hardcoded or parsed from a LegacyXlate - * sections of driver INF files. - */ -#if defined(SARCH_PC98) - UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*nEC1F00\0"); -#else - UNICODE_STRING HardwareIdMouse = RTL_CONSTANT_STRING(L"*PNP0F13\0"); -#endif - static ULONG DeviceIndexMouse = 0; - const UNICODE_STRING IdentifierParallel = RTL_CONSTANT_STRING(L"ParallelController"); - UNICODE_STRING HardwareIdParallel = RTL_CONSTANT_STRING(L"*PNP0400\0"); - static ULONG DeviceIndexParallel = 0; - const UNICODE_STRING IdentifierFloppy = RTL_CONSTANT_STRING(L"FloppyDiskPeripheral"); - UNICODE_STRING HardwareIdFloppy = RTL_CONSTANT_STRING(L"*PNP0700\0"); - static ULONG DeviceIndexFloppy = 0; - UNICODE_STRING HardwareIdKey; - PUNICODE_STRING pHardwareId; - ULONG DeviceIndex = 0; - PUCHAR CmResourceList; - ULONG ListCount; - - if (RelativePath) - { - Status = IopOpenRegistryKeyEx(&hDevicesKey, hBaseKey, RelativePath, KEY_ENUMERATE_SUB_KEYS); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } - } - else - hDevicesKey = hBaseKey; - - pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); - if (!pDeviceInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - - pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); - if (!pValueInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - - while (TRUE) - { - Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); - if (Status == STATUS_NO_MORE_ENTRIES) - break; - else if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) - { - ExFreePool(pDeviceInformation); - DeviceInfoLength = RequiredSize; - pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); - if (!pDeviceInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - Status = ZwEnumerateKey(hDevicesKey, IndexDevice, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); - } - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } - IndexDevice++; - - /* Open device key */ - DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength; - DeviceName.Buffer = pDeviceInformation->Name; - - Status = IopOpenRegistryKeyEx(&hDeviceKey, hDevicesKey, &DeviceName, - KEY_QUERY_VALUE + (EnumerateSubKeys ? KEY_ENUMERATE_SUB_KEYS : 0)); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } - - /* Read boot resources, and add then to parent ones */ - Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); - if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) - { - ExFreePool(pValueInformation); - ValueInfoLength = RequiredSize; - pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); - if (!pValueInformation) - { - DPRINT("ExAllocatePool() failed\n"); - ZwDeleteKey(hLevel2Key); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - Status = ZwQueryValueKey(hDeviceKey, &ConfigurationDataU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); - } - if (Status == STATUS_OBJECT_NAME_NOT_FOUND) - { - BootResources = ParentBootResources; - BootResourcesLength = ParentBootResourcesLength; - } - else if (!NT_SUCCESS(Status)) - { - DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status); - goto nextdevice; - } - else if (pValueInformation->Type != REG_FULL_RESOURCE_DESCRIPTOR) - { - DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_FULL_RESOURCE_DESCRIPTOR); - goto nextdevice; - } - else - { - static const ULONG Header = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList.PartialDescriptors); - - /* Concatenate current resources and parent ones */ - if (ParentBootResourcesLength == 0) - BootResourcesLength = pValueInformation->DataLength; - else - BootResourcesLength = ParentBootResourcesLength - + pValueInformation->DataLength - - Header; - BootResources = ExAllocatePool(PagedPool, BootResourcesLength); - if (!BootResources) - { - DPRINT("ExAllocatePool() failed\n"); - goto nextdevice; - } - if (ParentBootResourcesLength < sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) - { - RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength); - } - else if (ParentBootResources->PartialResourceList.PartialDescriptors[ParentBootResources->PartialResourceList.Count - 1].Type == CmResourceTypeDeviceSpecific) - { - RtlCopyMemory(BootResources, pValueInformation->Data, pValueInformation->DataLength); - RtlCopyMemory( - (PVOID)((ULONG_PTR)BootResources + pValueInformation->DataLength), - (PVOID)((ULONG_PTR)ParentBootResources + Header), - ParentBootResourcesLength - Header); - BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count; - } - else - { - RtlCopyMemory(BootResources, pValueInformation->Data, Header); - RtlCopyMemory( - (PVOID)((ULONG_PTR)BootResources + Header), - (PVOID)((ULONG_PTR)ParentBootResources + Header), - ParentBootResourcesLength - Header); - RtlCopyMemory( - (PVOID)((ULONG_PTR)BootResources + ParentBootResourcesLength), - pValueInformation->Data + Header, - pValueInformation->DataLength - Header); - BootResources->PartialResourceList.Count += ParentBootResources->PartialResourceList.Count; - } - } - - if (EnumerateSubKeys) - { - IndexSubKey = 0; - while (TRUE) - { - Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); - if (Status == STATUS_NO_MORE_ENTRIES) - break; - else if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) - { - ExFreePool(pDeviceInformation); - DeviceInfoLength = RequiredSize; - pDeviceInformation = ExAllocatePool(PagedPool, DeviceInfoLength); - if (!pDeviceInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - Status = ZwEnumerateKey(hDeviceKey, IndexSubKey, KeyBasicInformation, pDeviceInformation, DeviceInfoLength, &RequiredSize); - } - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwEnumerateKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } - IndexSubKey++; - DeviceName.Length = DeviceName.MaximumLength = (USHORT)pDeviceInformation->NameLength; - DeviceName.Buffer = pDeviceInformation->Name; - - Status = IopEnumerateDetectedDevices( - hDeviceKey, - &DeviceName, - hRootKey, - TRUE, - BootResources, - BootResourcesLength); - if (!NT_SUCCESS(Status)) - goto cleanup; - } - } - - /* Read identifier */ - Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); - if (Status == STATUS_BUFFER_OVERFLOW || Status == STATUS_BUFFER_TOO_SMALL) - { - ExFreePool(pValueInformation); - ValueInfoLength = RequiredSize; - pValueInformation = ExAllocatePool(PagedPool, ValueInfoLength); - if (!pValueInformation) - { - DPRINT("ExAllocatePool() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - Status = ZwQueryValueKey(hDeviceKey, &IdentifierU, KeyValuePartialInformation, pValueInformation, ValueInfoLength, &RequiredSize); - } - if (!NT_SUCCESS(Status)) - { - if (Status != STATUS_OBJECT_NAME_NOT_FOUND) - { - DPRINT("ZwQueryValueKey() failed with status 0x%08lx\n", Status); - goto nextdevice; - } - ValueName.Length = ValueName.MaximumLength = 0; - } - else if (pValueInformation->Type != REG_SZ) - { - DPRINT("Wrong registry type: got 0x%lx, expected 0x%lx\n", pValueInformation->Type, REG_SZ); - goto nextdevice; - } - else - { - /* Assign hardware id to this device */ - ValueName.Length = ValueName.MaximumLength = (USHORT)pValueInformation->DataLength; - ValueName.Buffer = (PWCHAR)pValueInformation->Data; - if (ValueName.Length >= sizeof(WCHAR) && ValueName.Buffer[ValueName.Length / sizeof(WCHAR) - 1] == UNICODE_NULL) - ValueName.Length -= sizeof(WCHAR); - } - - if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierSerial, FALSE) == 0) - { - pHardwareId = &HardwareIdSerial; - DeviceIndex = DeviceIndexSerial++; - } - else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierKeyboard, FALSE) == 0) - { - pHardwareId = &HardwareIdKeyboard; - DeviceIndex = DeviceIndexKeyboard++; - } - else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierMouse, FALSE) == 0) - { - pHardwareId = &HardwareIdMouse; - DeviceIndex = DeviceIndexMouse++; - } - else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierParallel, FALSE) == 0) - { - pHardwareId = &HardwareIdParallel; - DeviceIndex = DeviceIndexParallel++; - } - else if (RelativePath && RtlCompareUnicodeString(RelativePath, &IdentifierFloppy, FALSE) == 0) - { - pHardwareId = &HardwareIdFloppy; - DeviceIndex = DeviceIndexFloppy++; - } - else - { - /* Unknown key path */ - DPRINT("Unknown key path '%wZ'\n", RelativePath); - goto nextdevice; - } - - /* Prepare hardware id key (hardware id value without final \0) */ - HardwareIdKey = *pHardwareId; - HardwareIdKey.Length -= sizeof(UNICODE_NULL); - - /* Add the detected device to Root key */ - InitializeObjectAttributes(&ObjectAttributes, &HardwareIdKey, OBJ_KERNEL_HANDLE, hRootKey, NULL); - Status = ZwCreateKey( - &hLevel1Key, - KEY_CREATE_SUB_KEY, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_NON_VOLATILE, - NULL); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); - goto nextdevice; - } - swprintf(Level2Name, L"%04lu", DeviceIndex); - RtlInitUnicodeString(&Level2NameU, Level2Name); - InitializeObjectAttributes(&ObjectAttributes, &Level2NameU, OBJ_KERNEL_HANDLE, hLevel1Key, NULL); - Status = ZwCreateKey( - &hLevel2Key, - KEY_SET_VALUE | KEY_CREATE_SUB_KEY, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_NON_VOLATILE, - NULL); - ZwClose(hLevel1Key); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); - goto nextdevice; - } - DPRINT("Found %wZ #%lu (%wZ)\n", &ValueName, DeviceIndex, &HardwareIdKey); - Status = ZwSetValueKey(hLevel2Key, &HardwareIDU, 0, REG_MULTI_SZ, pHardwareId->Buffer, pHardwareId->MaximumLength); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status); - ZwDeleteKey(hLevel2Key); - goto nextdevice; - } - /* Create 'LogConf' subkey */ - InitializeObjectAttributes(&ObjectAttributes, &LogConfU, OBJ_KERNEL_HANDLE, hLevel2Key, NULL); - Status = ZwCreateKey( - &hLogConf, - KEY_SET_VALUE, - &ObjectAttributes, - 0, - NULL, - REG_OPTION_VOLATILE, - NULL); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwCreateKey() failed with status 0x%08lx\n", Status); - ZwDeleteKey(hLevel2Key); - goto nextdevice; - } - if (BootResourcesLength >= sizeof(CM_FULL_RESOURCE_DESCRIPTOR)) - { - CmResourceList = ExAllocatePool(PagedPool, BootResourcesLength + sizeof(ULONG)); - if (!CmResourceList) - { - ZwClose(hLogConf); - ZwDeleteKey(hLevel2Key); - goto nextdevice; - } - - /* Add the list count (1st member of CM_RESOURCE_LIST) */ - ListCount = 1; - RtlCopyMemory(CmResourceList, - &ListCount, - sizeof(ULONG)); - - /* Now add the actual list (2nd member of CM_RESOURCE_LIST) */ - RtlCopyMemory(CmResourceList + sizeof(ULONG), - BootResources, - BootResourcesLength); - - /* Save boot resources to 'LogConf\BootConfig' */ - Status = ZwSetValueKey(hLogConf, &BootConfigU, 0, REG_RESOURCE_LIST, CmResourceList, BootResourcesLength + sizeof(ULONG)); - if (!NT_SUCCESS(Status)) - { - DPRINT("ZwSetValueKey() failed with status 0x%08lx\n", Status); - ZwClose(hLogConf); - ZwDeleteKey(hLevel2Key); - goto nextdevice; - } - } - ZwClose(hLogConf); - -nextdevice: - if (BootResources && BootResources != ParentBootResources) - { - ExFreePool(BootResources); - BootResources = NULL; - } - if (hLevel2Key) - { - ZwClose(hLevel2Key); - hLevel2Key = NULL; - } - if (hDeviceKey) - { - ZwClose(hDeviceKey); - hDeviceKey = NULL; - } - } - - Status = STATUS_SUCCESS; - -cleanup: - if (hDevicesKey && hDevicesKey != hBaseKey) - ZwClose(hDevicesKey); - if (hDeviceKey) - ZwClose(hDeviceKey); - if (pDeviceInformation) - ExFreePool(pDeviceInformation); - if (pValueInformation) - ExFreePool(pValueInformation); - return Status; -} - -static -CODE_SEG("INIT") -BOOLEAN -IopIsFirmwareMapperDisabled(VOID) -{ - UNICODE_STRING KeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CURRENTCONTROLSET\\Control\\Pnp"); - UNICODE_STRING KeyNameU = RTL_CONSTANT_STRING(L"DisableFirmwareMapper"); - OBJECT_ATTRIBUTES ObjectAttributes; - HANDLE hPnpKey; - PKEY_VALUE_PARTIAL_INFORMATION KeyInformation; - ULONG DesiredLength, Length; - ULONG KeyValue = 0; - NTSTATUS Status; - - InitializeObjectAttributes(&ObjectAttributes, &KeyPathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = ZwOpenKey(&hPnpKey, KEY_QUERY_VALUE, &ObjectAttributes); - if (NT_SUCCESS(Status)) - { - Status = ZwQueryValueKey(hPnpKey, - &KeyNameU, - KeyValuePartialInformation, - NULL, - 0, - &DesiredLength); - if ((Status == STATUS_BUFFER_TOO_SMALL) || - (Status == STATUS_BUFFER_OVERFLOW)) - { - Length = DesiredLength; - KeyInformation = ExAllocatePool(PagedPool, Length); - if (KeyInformation) - { - Status = ZwQueryValueKey(hPnpKey, - &KeyNameU, - KeyValuePartialInformation, - KeyInformation, - Length, - &DesiredLength); - if (NT_SUCCESS(Status) && KeyInformation->DataLength == sizeof(ULONG)) - { - KeyValue = (ULONG)(*KeyInformation->Data); - } - else - { - DPRINT1("ZwQueryValueKey(%wZ%wZ) failed\n", &KeyPathU, &KeyNameU); - } - - ExFreePool(KeyInformation); - } - else - { - DPRINT1("Failed to allocate memory for registry query\n"); - } - } - else - { - DPRINT1("ZwQueryValueKey(%wZ%wZ) failed with status 0x%08lx\n", &KeyPathU, &KeyNameU, Status); - } - - ZwClose(hPnpKey); - } - else - { - DPRINT1("ZwOpenKey(%wZ) failed with status 0x%08lx\n", &KeyPathU, Status); - } - - DPRINT("Firmware mapper is %s\n", KeyValue != 0 ? "disabled" : "enabled"); - - return (KeyValue != 0) ? TRUE : FALSE; -} - -CODE_SEG("INIT") -NTSTATUS -NTAPI -IopUpdateRootKey(VOID) -{ - UNICODE_STRING EnumU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum"); - UNICODE_STRING RootPathU = RTL_CONSTANT_STRING(L"Root"); - UNICODE_STRING MultiKeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter"); - OBJECT_ATTRIBUTES ObjectAttributes; - HANDLE hEnum, hRoot; - NTSTATUS Status; - - InitializeObjectAttributes(&ObjectAttributes, &EnumU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = ZwCreateKey(&hEnum, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); - if (!NT_SUCCESS(Status)) - { - DPRINT1("ZwCreateKey() failed with status 0x%08lx\n", Status); - return Status; - } - - InitializeObjectAttributes(&ObjectAttributes, &RootPathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, hEnum, NULL); - Status = ZwCreateKey(&hRoot, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); - ZwClose(hEnum); - if (!NT_SUCCESS(Status)) - { - DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status); - return Status; - } - - if (!IopIsFirmwareMapperDisabled()) - { - Status = IopOpenRegistryKeyEx(&hEnum, NULL, &MultiKeyPathU, KEY_ENUMERATE_SUB_KEYS); - if (!NT_SUCCESS(Status)) - { - /* Nothing to do, don't return with an error status */ - DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status); - ZwClose(hRoot); - return STATUS_SUCCESS; - } - Status = IopEnumerateDetectedDevices( - hEnum, - NULL, - hRoot, - TRUE, - NULL, - 0); - ZwClose(hEnum); - } - else - { - /* Enumeration is disabled */ - Status = STATUS_SUCCESS; - } - - ZwClose(hRoot); - - return Status; -} - NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, diff --git a/ntoskrnl/ntos.cmake b/ntoskrnl/ntos.cmake index 60d4436a438..dddb6cae4ab 100644 --- a/ntoskrnl/ntos.cmake +++ b/ntoskrnl/ntos.cmake @@ -157,6 +157,7 @@ list(APPEND SOURCE ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpdma.c ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpinit.c ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpirp.c + ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpmap.c ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpmgr.c ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpnotify.c ${REACTOS_SOURCE_DIR}/ntoskrnl/io/pnpmgr/pnpreport.c
1 year, 7 months
1
0
0
0
[reactos] 01/01: [FREELDR] PeLdrLoadImage: FileName -> FilePath and make it const.
by Hermès Bélusca-Maïto
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7112815e23f46a67b0645…
commit 7112815e23f46a67b0645a0e904ed89859a54c6d Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> AuthorDate: Sun May 7 22:13:03 2023 +0200 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Sun May 7 22:14:30 2023 +0200 [FREELDR] PeLdrLoadImage: FileName -> FilePath and make it const. --- boot/freeldr/freeldr/include/peloader.h | 6 ++--- boot/freeldr/freeldr/lib/peloader.c | 40 ++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/boot/freeldr/freeldr/include/peloader.h b/boot/freeldr/freeldr/include/peloader.h index 1f67ed3bbac..5df073fecc1 100644 --- a/boot/freeldr/freeldr/include/peloader.h +++ b/boot/freeldr/freeldr/include/peloader.h @@ -28,9 +28,9 @@ extern PELDR_IMPORTDLL_LOAD_CALLBACK PeLdrImportDllLoadCallback; BOOLEAN PeLdrLoadImage( - IN PCHAR FileName, - IN TYPE_OF_MEMORY MemoryType, - OUT PVOID *ImageBasePA); + _In_ PCSTR FilePath, + _In_ TYPE_OF_MEMORY MemoryType, + _Out_ PVOID* ImageBasePA); BOOLEAN PeLdrAllocateDataTableEntry( diff --git a/boot/freeldr/freeldr/lib/peloader.c b/boot/freeldr/freeldr/lib/peloader.c index f97639e4cec..e73012fab28 100644 --- a/boot/freeldr/freeldr/lib/peloader.c +++ b/boot/freeldr/freeldr/lib/peloader.c @@ -725,18 +725,22 @@ PeLdrFreeDataTableEntry( FrLdrHeapFree(Entry, TAG_WLDR_DTE); } -/* - * PeLdrLoadImage loads the specified image from the file (it doesn't - * perform any additional operations on the filename, just directly - * calls the file I/O routines), and relocates it so that it's ready - * to be used when paging is enabled. - * Addressing mode: physical - */ +/** + * @brief + * Loads the specified image from the file. + * + * PeLdrLoadImage doesn't perform any additional operations on the file path, + * it just directly calls the file I/O routines. It then relocates the image + * so that it's ready to be used when paging is enabled. + * + * @note + * Addressing mode: physical. + **/ BOOLEAN PeLdrLoadImage( - IN PCHAR FileName, - IN TYPE_OF_MEMORY MemoryType, - OUT PVOID *ImageBasePA) + _In_ PCSTR FilePath, + _In_ TYPE_OF_MEMORY MemoryType, + _Out_ PVOID* ImageBasePA) { ULONG FileId; PVOID PhysicalBase; @@ -749,13 +753,13 @@ PeLdrLoadImage( LARGE_INTEGER Position; ULONG i, BytesRead; - TRACE("PeLdrLoadImage('%s', %ld)\n", FileName, MemoryType); + TRACE("PeLdrLoadImage('%s', %ld)\n", FilePath, MemoryType); /* Open the image file */ - Status = ArcOpen((PSTR)FileName, OpenReadOnly, &FileId); + Status = ArcOpen((PSTR)FilePath, OpenReadOnly, &FileId); if (Status != ESUCCESS) { - WARN("ArcOpen('%s') failed. Status: %u\n", FileName, Status); + WARN("ArcOpen('%s') failed. Status: %u\n", FilePath, Status); return FALSE; } @@ -763,7 +767,7 @@ PeLdrLoadImage( Status = ArcRead(FileId, HeadersBuffer, SECTOR_SIZE * 2, &BytesRead); if (Status != ESUCCESS) { - ERR("ArcRead('%s') failed. Status: %u\n", FileName, Status); + ERR("ArcRead('%s') failed. Status: %u\n", FilePath, Status); ArcClose(FileId); return FALSE; } @@ -772,7 +776,7 @@ PeLdrLoadImage( NtHeaders = RtlImageNtHeader(HeadersBuffer); if (!NtHeaders) { - ERR("No NT header found in \"%s\"\n", FileName); + ERR("No NT header found in \"%s\"\n", FilePath); ArcClose(FileId); return FALSE; } @@ -780,7 +784,7 @@ PeLdrLoadImage( /* Ensure this is executable image */ if (((NtHeaders->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE) == 0)) { - ERR("Not an executable image \"%s\"\n", FileName); + ERR("Not an executable image \"%s\"\n", FilePath); ArcClose(FileId); return FALSE; } @@ -801,7 +805,7 @@ PeLdrLoadImage( if (PhysicalBase == NULL) { - ERR("Failed to alloc %lu bytes for image %s\n", NtHeaders->OptionalHeader.SizeOfImage, FileName); + ERR("Failed to alloc %lu bytes for image %s\n", NtHeaders->OptionalHeader.SizeOfImage, FilePath); ArcClose(FileId); return FALSE; } @@ -820,7 +824,7 @@ PeLdrLoadImage( Status = ArcRead(FileId, (PUCHAR)PhysicalBase + sizeof(HeadersBuffer), NtHeaders->OptionalHeader.SizeOfHeaders - sizeof(HeadersBuffer), &BytesRead); if (Status != ESUCCESS) { - ERR("ArcRead('%s') failed. Status: %u\n", FileName, Status); + ERR("ArcRead('%s') failed. Status: %u\n", FilePath, Status); // UiMessageBox("Error reading headers."); ArcClose(FileId); goto Failure;
1 year, 7 months
1
0
0
0
[reactos] 01/01: [KERNEL32][SDK] RegisterConsoleIME and UnregisterConsoleIME (#5270)
by Katayama Hirofumi MZ
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8b948ff06254350a7ab92…
commit 8b948ff06254350a7ab9296ce70b9e59b622aa6d Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Sun May 7 22:55:46 2023 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Sun May 7 22:55:46 2023 +0900 [KERNEL32][SDK] RegisterConsoleIME and UnregisterConsoleIME (#5270) The conime.exe program exists in WinXP/Win2k3 and it realizes Console IME. conime.exe calls kernel32!RegisterConsoleIME and kernel32!UnregisterConsoleIME. To realize Console IME, these two functions are required. CORE-11700 --- dll/win32/kernel32/client/console/console.c | 106 ++++++++++++++++++++++++++-- sdk/include/reactos/subsys/win/conmsg.h | 20 ++++++ 2 files changed, 121 insertions(+), 5 deletions(-) diff --git a/dll/win32/kernel32/client/console/console.c b/dll/win32/kernel32/client/console/console.c index 7a5b3b61c34..dfa8ab7f21b 100644 --- a/dll/win32/kernel32/client/console/console.c +++ b/dll/win32/kernel32/client/console/console.c @@ -3030,13 +3030,109 @@ SetConsoleLocalEUDC(DWORD Unknown1, DWORD Unknown2, DWORD Unknown3, DWORD Unknow return FALSE; } +static BOOL +IntRegisterConsoleIME( + _In_ HWND hWnd, + _In_ DWORD dwThreadId, + _In_opt_ SIZE_T cbDesktop, + _In_opt_ PWSTR pDesktop, + _Out_opt_ PDWORD pdwAttachToThreadId) +{ + CONSOLE_API_MESSAGE ApiMessage; + PCONSOLE_REGISTERCONSOLEIME RegisterConsoleIME = &ApiMessage.Data.RegisterConsoleIME; + PCSR_CAPTURE_BUFFER CaptureBuffer; + + if (!cbDesktop || !pDesktop) + { + pDesktop = NtCurrentPeb()->ProcessParameters->DesktopInfo.Buffer; + cbDesktop = NtCurrentPeb()->ProcessParameters->DesktopInfo.Length; + } + + cbDesktop = min(cbDesktop, (MAX_PATH + 1) * sizeof(WCHAR)); + + RegisterConsoleIME->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + RegisterConsoleIME->hWnd = hWnd; + RegisterConsoleIME->dwThreadId = dwThreadId; + RegisterConsoleIME->cbDesktop = cbDesktop; + + CaptureBuffer = CsrAllocateCaptureBuffer(1, cbDesktop); + if (!CaptureBuffer) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return FALSE; + } + + CsrCaptureMessageBuffer(CaptureBuffer, + pDesktop, + cbDesktop, + (PVOID*)&RegisterConsoleIME->pDesktop); + + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + CaptureBuffer, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepRegisterConsoleIME), + sizeof(*RegisterConsoleIME)); + + CsrFreeCaptureBuffer(CaptureBuffer); + + if (!NT_SUCCESS(ApiMessage.Status)) + { + BaseSetLastNTError(ApiMessage.Status); + return FALSE; + } + + if (pdwAttachToThreadId) + { + _SEH2_TRY + { + *pdwAttachToThreadId = RegisterConsoleIME->dwAttachToThreadId; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + BaseSetLastNTError(STATUS_ACCESS_VIOLATION); + _SEH2_YIELD(return FALSE); + } + _SEH2_END; + } + + return TRUE; +} + +static BOOL +IntUnregisterConsoleIME( + _In_ DWORD dwThreadId) +{ + CONSOLE_API_MESSAGE ApiMessage; + PCONSOLE_UNREGISTERCONSOLEIME UnregisterConsoleIME = &ApiMessage.Data.UnregisterConsoleIME; + + UnregisterConsoleIME->ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + UnregisterConsoleIME->dwThreadId = dwThreadId; + + CsrClientCallServer((PCSR_API_MESSAGE)&ApiMessage, + NULL, + CSR_CREATE_API_NUMBER(CONSRV_SERVERDLL_INDEX, ConsolepUnregisterConsoleIME), + sizeof(*UnregisterConsoleIME)); + if (!NT_SUCCESS(ApiMessage.Status)) + { + BaseSetLastNTError(ApiMessage.Status); + return FALSE; + } + + return TRUE; +} + +/* This function is called by CONIME.EXE */ BOOL WINAPI DECLSPEC_HOTPATCH -RegisterConsoleIME(HWND hWnd, LPDWORD ThreadId) +RegisterConsoleIME( + _In_ HWND hWnd, + _Out_opt_ LPDWORD pdwAttachToThreadId) { - STUB; - return FALSE; + return IntRegisterConsoleIME(hWnd, + GetCurrentThreadId(), + 0, + NULL, + pdwAttachToThreadId); } BOOL @@ -3057,13 +3153,13 @@ SetConsoleOS2OemFormat(BOOL bUnknown) return FALSE; } +/* This function is called by CONIME.EXE */ BOOL WINAPI DECLSPEC_HOTPATCH UnregisterConsoleIME(VOID) { - STUB; - return FALSE; + return IntUnregisterConsoleIME(GetCurrentThreadId()); } /** diff --git a/sdk/include/reactos/subsys/win/conmsg.h b/sdk/include/reactos/subsys/win/conmsg.h index dd50cb11437..67dba20e420 100644 --- a/sdk/include/reactos/subsys/win/conmsg.h +++ b/sdk/include/reactos/subsys/win/conmsg.h @@ -894,6 +894,22 @@ typedef struct _CONSOLE_REGISTERVDM PVOID VDMBuffer; } CONSOLE_REGISTERVDM, *PCONSOLE_REGISTERVDM; +typedef struct _CONSOLE_REGISTERCONSOLEIME +{ + HANDLE ConsoleHandle; + HWND hWnd; + DWORD dwThreadId; + DWORD cbDesktop; + LPWSTR pDesktop; + DWORD dwAttachToThreadId; +} CONSOLE_REGISTERCONSOLEIME, *PCONSOLE_REGISTERCONSOLEIME; + +typedef struct _CONSOLE_UNREGISTERCONSOLEIME +{ + HANDLE ConsoleHandle; + DWORD dwThreadId; +} CONSOLE_UNREGISTERCONSOLEIME, *PCONSOLE_UNREGISTERCONSOLEIME; + typedef struct _CONSOLE_API_MESSAGE { PORT_MESSAGE Header; @@ -1002,6 +1018,10 @@ typedef struct _CONSOLE_API_MESSAGE /* Virtual DOS Machine */ CONSOLE_REGISTERVDM RegisterVDMRequest; + + /* Console IME */ + CONSOLE_REGISTERCONSOLEIME RegisterConsoleIME; + CONSOLE_UNREGISTERCONSOLEIME UnregisterConsoleIME; } Data; } CONSOLE_API_MESSAGE, *PCONSOLE_API_MESSAGE;
1 year, 7 months
1
0
0
0
[reactos] 02/02: [WINLOGON] Implement logoff and MessageBeep sounds support (#4755) CORE-13951
by Thamatip Chitpong
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9d48f26d2992af33c0fbe…
commit 9d48f26d2992af33c0fbeb9ad51bf776cf334ccc Author: Thamatip Chitpong <tangaming123456(a)outlook.com> AuthorDate: Wed Oct 5 08:33:28 2022 +0700 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Fri May 5 20:18:34 2023 +0200 [WINLOGON] Implement logoff and MessageBeep sounds support (#4755) CORE-13951 --- base/system/winlogon/sas.c | 186 ++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 111 deletions(-) diff --git a/base/system/winlogon/sas.c b/base/system/winlogon/sas.c index bc37d5db49d..b94663b1c55 100644 --- a/base/system/winlogon/sas.c +++ b/base/system/winlogon/sas.c @@ -4,7 +4,7 @@ * FILE: base/system/winlogon/sas.c * PURPOSE: Secure Attention Sequence * PROGRAMMERS: Thomas Weidenmueller (w3seek(a)users.sourceforge.net) - * Herv� Poussineau (hpoussin(a)reactos.org) + * Hervé Poussineau (hpoussin(a)reactos.org) * Arnav Bhatt (arnavbhatt288(a)gmail.com) * UPDATE HISTORY: * Created 28/03/2004 @@ -290,88 +290,11 @@ WINAPI PlayLogonSoundThread( IN LPVOID lpParameter) { - BYTE TokenUserBuffer[256]; - PTOKEN_USER pTokenUser = (TOKEN_USER*)TokenUserBuffer; - ULONG Length; - HKEY hKey; - WCHAR wszBuffer[MAX_PATH] = {0}; - WCHAR wszDest[MAX_PATH]; - DWORD dwSize = sizeof(wszBuffer), dwType; SERVICE_STATUS_PROCESS Info; - UNICODE_STRING SidString; - NTSTATUS Status; + DWORD dwSize; ULONG Index = 0; SC_HANDLE hSCManager, hService; - // - // FIXME: Isn't it possible to *JUST* impersonate the current user - // *AND* open its HKCU?? - // - - /* Get SID of current user */ - Status = NtQueryInformationToken((HANDLE)lpParameter, - TokenUser, - TokenUserBuffer, - sizeof(TokenUserBuffer), - &Length); - if (!NT_SUCCESS(Status)) - { - ERR("NtQueryInformationToken failed: %x!\n", Status); - return 0; - } - - /* Convert SID to string */ - RtlInitEmptyUnicodeString(&SidString, wszBuffer, sizeof(wszBuffer)); - Status = RtlConvertSidToUnicodeString(&SidString, pTokenUser->User.Sid, FALSE); - if (!NT_SUCCESS(Status)) - { - ERR("RtlConvertSidToUnicodeString failed: %x!\n", Status); - return 0; - } - - /* Build path to logon sound registry key. - Note: We can't use HKCU here, because Winlogon is owned by SYSTEM user */ - if (FAILED(StringCbCopyW(wszBuffer + SidString.Length/sizeof(WCHAR), - sizeof(wszBuffer) - SidString.Length, - L"\\AppEvents\\Schemes\\Apps\\.Default\\WindowsLogon\\.Current"))) - { - /* SID is too long. Should not happen. */ - ERR("StringCbCopyW failed!\n"); - return 0; - } - - /* Open registry key and query sound path */ - if (RegOpenKeyExW(HKEY_USERS, wszBuffer, 0, KEY_READ, &hKey) != ERROR_SUCCESS) - { - ERR("RegOpenKeyExW(%ls) failed!\n", wszBuffer); - return 0; - } - - if (RegQueryValueExW(hKey, NULL, NULL, &dwType, - (LPBYTE)wszBuffer, &dwSize) != ERROR_SUCCESS || - (dwType != REG_SZ && dwType != REG_EXPAND_SZ)) - { - ERR("RegQueryValueExW failed!\n"); - RegCloseKey(hKey); - return 0; - } - - RegCloseKey(hKey); - - if (!wszBuffer[0]) - { - /* No sound has been set */ - ERR("No sound has been set\n"); - return 0; - } - - /* Expand environment variables */ - if (!ExpandEnvironmentStringsW(wszBuffer, wszDest, MAX_PATH)) - { - ERR("ExpandEnvironmentStringsW failed!\n"); - return 0; - } - /* Open the service manager */ hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); if (!hSCManager) @@ -417,8 +340,16 @@ PlayLogonSoundThread( } /* Sound subsystem is running. Play logon sound. */ - TRACE("Playing logon sound: %ls\n", wszDest); - PlaySoundRoutine(wszDest, TRUE, SND_FILENAME); + TRACE("Playing logon sound\n"); + if (!ImpersonateLoggedOnUser((HANDLE)lpParameter)) + { + ERR("ImpersonateLoggedOnUser failed (%x)\n", GetLastError()); + } + else + { + PlaySoundRoutine(L"WindowsLogon", TRUE, SND_ALIAS | SND_NODEFAULT); + RevertToSelf(); + } return 0; } @@ -434,6 +365,37 @@ PlayLogonSound( CloseHandle(hThread); } +static +VOID +PlayLogoffSound( + _In_ PWLSESSION Session) +{ + if (!ImpersonateLoggedOnUser(Session->UserToken)) + return; + + PlaySoundRoutine(L"WindowsLogoff", FALSE, SND_ALIAS | SND_NODEFAULT); + + RevertToSelf(); +} + +static +BOOL +PlayEventSound( + _In_ PWLSESSION Session, + _In_ LPCWSTR EventName) +{ + BOOL bRet; + + if (!ImpersonateLoggedOnUser(Session->UserToken)) + return FALSE; + + bRet = PlaySoundRoutine(EventName, FALSE, SND_ALIAS | SND_ASYNC | SND_NODEFAULT); + + RevertToSelf(); + + return bRet; +} + static VOID RestoreAllConnections(PWLSESSION Session) @@ -880,7 +842,7 @@ HandleLogoff( SwitchDesktop(Session->WinlogonDesktop); - // TODO: Play logoff sound! + PlayLogoffSound(Session); SetWindowStationUser(Session->InteractiveWindowStation, &LuidNone, NULL, 0); @@ -1274,38 +1236,40 @@ UnregisterHotKeys( return TRUE; } +static BOOL -WINAPI -HandleMessageBeep(UINT uType) +HandleMessageBeep( + _In_ PWLSESSION Session, + _In_ UINT uType) { LPWSTR EventName; - switch(uType) - { - case 0xFFFFFFFF: - EventName = NULL; - break; - case MB_OK: - EventName = L"SystemDefault"; - break; - case MB_ICONASTERISK: - EventName = L"SystemAsterisk"; - break; - case MB_ICONEXCLAMATION: - EventName = L"SystemExclamation"; - break; - case MB_ICONHAND: - EventName = L"SystemHand"; - break; - case MB_ICONQUESTION: - EventName = L"SystemQuestion"; - break; - default: - WARN("Unhandled type %d\n", uType); - EventName = L"SystemDefault"; - } - - return PlaySoundRoutine(EventName, FALSE, SND_ALIAS | SND_NOWAIT | SND_NOSTOP | SND_ASYNC); + switch (uType) + { + case 0xFFFFFFFF: + EventName = NULL; + break; + case MB_OK: + EventName = L"SystemDefault"; + break; + case MB_ICONASTERISK: + EventName = L"SystemAsterisk"; + break; + case MB_ICONEXCLAMATION: + EventName = L"SystemExclamation"; + break; + case MB_ICONHAND: + EventName = L"SystemHand"; + break; + case MB_ICONQUESTION: + EventName = L"SystemQuestion"; + break; + default: + WARN("Unhandled type %d\n", uType); + EventName = L"SystemDefault"; + } + + return PlayEventSound(Session, EventName); } static @@ -1376,7 +1340,7 @@ SASWindowProc( { case LN_MESSAGE_BEEP: { - return HandleMessageBeep(lParam); + return HandleMessageBeep(Session, lParam); } case LN_SHELL_EXITED: {
1 year, 7 months
1
0
0
0
[reactos] 01/02: [REACTOS] Add converted sound files (#4755) CORE-13951
by Thamatip Chitpong
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cc114a070600df4b2e113…
commit cc114a070600df4b2e113b93f501f77131a9ff04 Author: Thamatip Chitpong <tangaming123456(a)outlook.com> AuthorDate: Wed Oct 5 11:51:06 2022 +0700 Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org> CommitDate: Fri May 5 20:18:12 2023 +0200 [REACTOS] Add converted sound files (#4755) CORE-13951 Add ReactOS_Critical_Stop.wav and ReactOS_Notify.wav --- media/CMakeLists.txt | 3 +-- media/sounds/CMakeLists.txt | 5 +++++ media/sounds/ReactOS_Critical_Stop.wav | Bin 0 -> 143222 bytes media/sounds/ReactOS_Notify.wav | Bin 0 -> 117878 bytes 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/media/CMakeLists.txt b/media/CMakeLists.txt index 2f8cecc8b22..699d2ff141a 100644 --- a/media/CMakeLists.txt +++ b/media/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(fonts) add_subdirectory(inf) add_subdirectory(nls) add_subdirectory(sdb) +add_subdirectory(sounds) add_subdirectory(themes) add_subdirectory(vgafonts) @@ -11,8 +12,6 @@ add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/drivers/etc/KDBinit DESTINATION rea add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/drivers/etc/networks DESTINATION reactos/system32/drivers/etc FOR all) add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/drivers/etc/protocol DESTINATION reactos/system32/drivers/etc FOR all) add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/drivers/etc/services DESTINATION reactos/system32/drivers/etc FOR all) -add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/sounds/ReactOS_LogOn.wav DESTINATION reactos/media FOR all) -add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/sounds/ReactOS_Recycle.wav DESTINATION reactos/media FOR all) add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/systemcompatible.manifest DESTINATION reactos/winsxs/manifests FOR all) add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/forwardcompatible.manifest DESTINATION reactos/winsxs/manifests FOR all) diff --git a/media/sounds/CMakeLists.txt b/media/sounds/CMakeLists.txt new file mode 100644 index 00000000000..03da1c51adc --- /dev/null +++ b/media/sounds/CMakeLists.txt @@ -0,0 +1,5 @@ + +add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/ReactOS_Critical_Stop.wav DESTINATION reactos/media FOR all) +add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/ReactOS_LogOn.wav DESTINATION reactos/media FOR all) +add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/ReactOS_Notify.wav DESTINATION reactos/media FOR all) +add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/ReactOS_Recycle.wav DESTINATION reactos/media FOR all) diff --git a/media/sounds/ReactOS_Critical_Stop.wav b/media/sounds/ReactOS_Critical_Stop.wav new file mode 100644 index 00000000000..9a446908acc Binary files /dev/null and b/media/sounds/ReactOS_Critical_Stop.wav differ diff --git a/media/sounds/ReactOS_Notify.wav b/media/sounds/ReactOS_Notify.wav new file mode 100644 index 00000000000..2b6056c1fe7 Binary files /dev/null and b/media/sounds/ReactOS_Notify.wav differ
1 year, 7 months
1
0
0
0
[reactos] 01/01: [NTOS:CM] Initialize the alternative system architecture field on PC-98 builds (#5136)
by Dmitry Borisov
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8df1b535080cbac032898…
commit 8df1b535080cbac0328985f15eaac3f96eb45f95 Author: Dmitry Borisov <di.sean(a)protonmail.com> AuthorDate: Fri May 5 22:04:35 2023 +0600 Commit: GitHub <noreply(a)github.com> CommitDate: Fri May 5 18:04:35 2023 +0200 [NTOS:CM] Initialize the alternative system architecture field on PC-98 builds (#5136) This is needed by some 3rd party drivers. CORE-17977 --- ntoskrnl/config/cmconfig.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ntoskrnl/config/cmconfig.c b/ntoskrnl/config/cmconfig.c index 42c428f971e..43239537d79 100644 --- a/ntoskrnl/config/cmconfig.c +++ b/ntoskrnl/config/cmconfig.c @@ -333,6 +333,11 @@ CmpInitializeHardwareConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock) ULONG Disposition; UNICODE_STRING KeyName; + /* Set the alternative system architecture information */ +#if defined(SARCH_PC98) + SharedUserData->AlternativeArchitecture = NEC98x86; +#endif + /* Setup the key name */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Hardware\\DeviceMap");
1 year, 7 months
1
0
0
0
[reactos] 01/01: [WINMM] Winmm fixes for system sound (#4635)
by Thamatip Chitpong
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f18111b64120806529e93…
commit f18111b64120806529e93404f21b6320f211ec39 Author: Thamatip Chitpong <tangaming123456(a)outlook.com> AuthorDate: Fri May 5 19:19:34 2023 +0700 Commit: GitHub <noreply(a)github.com> CommitDate: Fri May 5 14:19:34 2023 +0200 [WINMM] Winmm fixes for system sound (#4635) CORE-13951 MIDIMAP_LoadSettings and PlaySound: Use RegOpenCurrentUser to access the appropriate HKEY_CURRENT_USER key. This allows functions that use HKEY_CURRENT_USER to be called from system processes while impersonating, for example: winlogon. PlaySound: - Open the correct registry key. - Expand environment strings if registry value type is REG_EXPAND_SZ. - Handle "SystemDefault" event and improve flags handling. - Don't use proc_PlaySound as thread proc. - Fix SND_ASYNC flag for system processes. Move get_mmio* code out of proc_PlaySound to fix impersonation problem. --- dll/win32/winmm/midimap/midimap.c | 15 +- dll/win32/winmm/playsound.c | 515 +++++++++++++++++++++++--------------- 2 files changed, 322 insertions(+), 208 deletions(-) diff --git a/dll/win32/winmm/midimap/midimap.c b/dll/win32/winmm/midimap/midimap.c index 8eefac33d14..a214b64a15a 100644 --- a/dll/win32/winmm/midimap/midimap.c +++ b/dll/win32/winmm/midimap/midimap.c @@ -202,11 +202,20 @@ static BOOL MIDIMAP_LoadSettingsScheme(MIDIMAPDATA* mom, const WCHAR* scheme) static BOOL MIDIMAP_LoadSettings(MIDIMAPDATA* mom) { - HKEY hKey; + HKEY hUserKey, hKey; + DWORD err; BOOL ret; - if (RegOpenKeyA(HKEY_CURRENT_USER, - "Software\\Microsoft\\Windows\\CurrentVersion\\Multimedia\\MIDIMap", &hKey)) + err = RegOpenCurrentUser(KEY_READ, &hUserKey); + if (err == ERROR_SUCCESS) + { + err = RegOpenKeyW(hUserKey, + L"Software\\Microsoft\\Windows\\CurrentVersion\\Multimedia\\MIDIMap", + &hKey); + RegCloseKey(hUserKey); + } + + if (err != ERROR_SUCCESS) { ret = MIDIMAP_LoadSettingsDefault(mom, NULL); } diff --git a/dll/win32/winmm/playsound.c b/dll/win32/winmm/playsound.c index a6fdbd7ed19..f0b2fe086f9 100644 --- a/dll/win32/winmm/playsound.c +++ b/dll/win32/winmm/playsound.c @@ -29,12 +29,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(winmm); typedef struct tagWINE_PLAYSOUND { - unsigned bLoop : 1, - bAlloc : 1; - LPCWSTR pszSound; - HMODULE hMod; - DWORD fdwSound; - HANDLE hThread; + unsigned bLoop : 1; + HMMIO hmmio; HWAVEOUT hWave; struct tagWINE_PLAYSOUND* lpNext; } WINE_PLAYSOUND; @@ -50,7 +46,7 @@ static HMMIO get_mmioFromFile(LPCWSTR lpszName) ret = mmioOpenW((LPWSTR)lpszName, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); if (ret != 0) return ret; - if (SearchPathW(NULL, lpszName, NULL, sizeof(buf)/sizeof(buf[0]), buf, &dummy)) + if (SearchPathW(NULL, lpszName, NULL, ARRAY_SIZE(buf), buf, &dummy)) { return mmioOpenW(buf, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); @@ -58,55 +54,67 @@ static HMMIO get_mmioFromFile(LPCWSTR lpszName) return 0; } -static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName) +static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName) { - WCHAR str[128]; - LPWSTR ptr; - HMMIO hmmio; - HKEY hRegSnd, hRegApp, hScheme, hSnd; - DWORD err, type, count; - - static const WCHAR wszSounds[] = {'S','o','u','n','d','s',0}; - static const WCHAR wszDefault[] = {'D','e','f','a','u','l','t',0}; - static const WCHAR wszKey[] = {'A','p','p','E','v','e','n','t','s','\\', - 'S','c','h','e','m','e','s','\\', - 'A','p','p','s',0}; - static const WCHAR wszDotDefault[] = {'.','D','e','f','a','u','l','t',0}; - static const WCHAR wszDotCurrent[] = {'.','C','u','r','r','e','n','t',0}; - static const WCHAR wszNull[] = {0}; + WCHAR str[128]; + LPWSTR ptr, pszSnd; + HMMIO hmmio; + HKEY hUserKey, hRegSnd, hRegApp, hScheme, hSnd; + DWORD err, type, count; + BOOL bIsDefault; TRACE("searching in SystemSound list for %s\n", debugstr_w(lpszName)); - GetProfileStringW(wszSounds, lpszName, wszNull, str, sizeof(str)/sizeof(str[0])); + + bIsDefault = (_wcsicmp(lpszName, L"SystemDefault") == 0); + + GetProfileStringW(L"Sounds", + bIsDefault ? L"Default" : lpszName, + L"", + str, + ARRAY_SIZE(str)); if (lstrlenW(str) == 0) - { - if (uFlags & SND_NODEFAULT) goto next; - GetProfileStringW(wszSounds, wszDefault, wszNull, str, sizeof(str)/sizeof(str[0])); - if (lstrlenW(str) == 0) goto next; - } - for (ptr = str; *ptr && *ptr != ','; ptr++); - if (*ptr) *ptr = 0; + goto Next; + + for (ptr = str; *ptr && *ptr != L','; ptr++); + + if (*ptr) + *ptr = UNICODE_NULL; + hmmio = mmioOpenW(str, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); - if (hmmio != 0) return hmmio; - next: + if (hmmio) + return hmmio; + +Next: /* we look up the registry under * HKCU\AppEvents\Schemes\Apps\.Default * HKCU\AppEvents\Schemes\Apps\<AppName> */ - if (RegOpenKeyW(HKEY_CURRENT_USER, wszKey, &hRegSnd) != 0) goto none; + err = RegOpenCurrentUser(KEY_READ, &hUserKey); + if (err == ERROR_SUCCESS) + { + err = RegOpenKeyW(hUserKey, L"AppEvents\\Schemes\\Apps", &hRegSnd); + RegCloseKey(hUserKey); + } + + if (err != ERROR_SUCCESS) + goto None; + if (uFlags & SND_APPLICATION) { DWORD len; - err = 1; /* error */ - len = GetModuleFileNameW(0, str, sizeof(str)/sizeof(str[0])); - if (len > 0 && len < sizeof(str)/sizeof(str[0])) + err = ERROR_FILE_NOT_FOUND; /* error */ + len = GetModuleFileNameW(NULL, str, ARRAY_SIZE(str)); + if (len > 0 && len < ARRAY_SIZE(str)) { for (ptr = str + lstrlenW(str) - 1; ptr >= str; ptr--) { - if (*ptr == '.') *ptr = 0; - if (*ptr == '\\') + if (*ptr == L'.') + *ptr = UNICODE_NULL; + + if (*ptr == L'\\') { - err = RegOpenKeyW(hRegSnd, ptr+1, &hRegApp); + err = RegOpenKeyW(hRegSnd, ptr + 1, &hRegApp); break; } } @@ -114,31 +122,188 @@ static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName) } else { - err = RegOpenKeyW(hRegSnd, wszDotDefault, &hRegApp); + err = RegOpenKeyW(hRegSnd, L".Default", &hRegApp); } + RegCloseKey(hRegSnd); - if (err != 0) goto none; - err = RegOpenKeyW(hRegApp, lpszName, &hScheme); + + if (err != ERROR_SUCCESS) + goto None; + + err = RegOpenKeyW(hRegApp, + bIsDefault ? L".Default" : lpszName, + &hScheme); + RegCloseKey(hRegApp); - if (err != 0) goto none; - /* what's the difference between .Current and .Default ? */ - err = RegOpenKeyW(hScheme, wszDotDefault, &hSnd); - if (err != 0) - { - err = RegOpenKeyW(hScheme, wszDotCurrent, &hSnd); - RegCloseKey(hScheme); - if (err != 0) - goto none; - } + + if (err != ERROR_SUCCESS) + goto None; + + err = RegOpenKeyW(hScheme, L".Current", &hSnd); + + RegCloseKey(hScheme); + + if (err != ERROR_SUCCESS) + goto None; + count = sizeof(str); err = RegQueryValueExW(hSnd, NULL, 0, &type, (LPBYTE)str, &count); + RegCloseKey(hSnd); - if (err != 0 || !*str) goto none; - hmmio = mmioOpenW(str, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); - if (hmmio) return hmmio; - none: + + if (err != ERROR_SUCCESS || !*str) + goto None; + + if (type == REG_EXPAND_SZ) + { + count = ExpandEnvironmentStringsW(str, NULL, 0); + if (count == 0) + goto None; + + pszSnd = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR)); + if (!pszSnd) + goto None; + + if (ExpandEnvironmentStringsW(str, pszSnd, count) == 0) + { + HeapFree(GetProcessHeap(), 0, pszSnd); + goto None; + } + } + else if (type == REG_SZ) + { + /* The type is REG_SZ, no need to expand */ + pszSnd = str; + } + else + { + /* Invalid type */ + goto None; + } + + hmmio = mmioOpenW(pszSnd, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); + + if (type == REG_EXPAND_SZ) + HeapFree(GetProcessHeap(), 0, pszSnd); + + if (hmmio) + return hmmio; + +None: WARN("can't find SystemSound=%s !\n", debugstr_w(lpszName)); - return 0; + return NULL; +} + +static HMMIO PlaySound_GetMMIO(LPCWSTR pszSound, HMODULE hMod, DWORD fdwSound) +{ + BOOL bIsDefault = FALSE; + HMMIO hmmio = NULL; + + TRACE("SoundName=%s !\n", debugstr_w(pszSound)); + + if (fdwSound & SND_MEMORY) + { + PVOID data; + MMIOINFO mminfo; + + /* NOTE: SND_RESOURCE has the SND_MEMORY bit set */ + if ((fdwSound & SND_RESOURCE) == SND_RESOURCE) + { + HRSRC hRes; + HGLOBAL hGlob; + + hRes = FindResourceW(hMod, pszSound, L"WAVE"); + hGlob = LoadResource(hMod, hRes); + if (!hRes || !hGlob) + goto Quit; + + data = LockResource(hGlob); + FreeResource(hGlob); + if (!data) + goto Quit; + } + else + { + data = (PVOID)pszSound; + } + + ZeroMemory(&mminfo, sizeof(mminfo)); + mminfo.fccIOProc = FOURCC_MEM; + mminfo.pchBuffer = data; + mminfo.cchBuffer = -1; /* FIXME: when a resource, could grab real size */ + + TRACE("Memory sound %p\n", data); + + hmmio = mmioOpenW(NULL, &mminfo, MMIO_READ); + } + else if (fdwSound & SND_ALIAS) + { + LPCWSTR pszName; + + /* NOTE: SND_ALIAS_ID has the SND_ALIAS bit set */ + if ((fdwSound & SND_ALIAS_ID) == SND_ALIAS_ID) + { + if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMASTERISK) + pszName = L"SystemAsterisk"; + else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMDEFAULT) + pszName = L"SystemDefault"; + else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXCLAMATION) + pszName = L"SystemExclamation"; + else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXIT) + pszName = L"SystemExit"; + else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMHAND) + pszName = L"SystemHand"; + else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMQUESTION) + pszName = L"SystemQuestion"; + else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMSTART) + pszName = L"SystemStart"; + else if (pszSound == (LPCWSTR)SND_ALIAS_SYSTEMWELCOME) + pszName = L"SystemWelcome"; + else + goto Quit; + } + else + { + pszName = pszSound; + } + + bIsDefault = (_wcsicmp(pszName, L"SystemDefault") == 0); + hmmio = get_mmioFromProfile(fdwSound, pszName); + } + else if (fdwSound & SND_FILENAME) + { + hmmio = get_mmioFromFile(pszSound); + } + else + { + hmmio = get_mmioFromProfile(fdwSound, pszSound); + if (!hmmio) + hmmio = get_mmioFromFile(pszSound); + } + +Quit: + if (!hmmio && !(fdwSound & SND_NODEFAULT)) + { + if (fdwSound & SND_APPLICATION) + { + if (!bIsDefault) + { + /* Find application-defined default sound */ + hmmio = get_mmioFromProfile(fdwSound, L"SystemDefault"); + if (hmmio) + return hmmio; + } + + /* Find system default sound */ + hmmio = get_mmioFromProfile(fdwSound & ~SND_APPLICATION, L"SystemDefault"); + } + else if (!bIsDefault) + { + hmmio = get_mmioFromProfile(fdwSound, L"SystemDefault"); + } + } + + return hmmio; } struct playsound_data @@ -183,15 +348,23 @@ static BOOL PlaySound_IsString(DWORD fdwSound, const void* psz) /* SND_RESOURCE is 0x40004 while * SND_MEMORY is 0x00004 */ - switch (fdwSound & (SND_RESOURCE|SND_ALIAS_ID|SND_FILENAME)) + switch (fdwSound & (SND_RESOURCE | SND_ALIAS_ID | SND_FILENAME)) { - case SND_RESOURCE: return HIWORD(psz) != 0; /* by name or by ID ? */ - case SND_ALIAS_ID: - case SND_MEMORY: return FALSE; - case SND_ALIAS: - case SND_FILENAME: - case 0: return TRUE; - default: FIXME("WTF\n"); return FALSE; + case SND_RESOURCE: + return HIWORD(psz) != 0; /* by name or by ID ? */ + + case SND_ALIAS_ID: + case SND_MEMORY: + return FALSE; + + case SND_ALIAS: + case SND_FILENAME: + case 0: + return TRUE; + + default: + FIXME("WTF\n"); + return FALSE; } } @@ -204,151 +377,64 @@ static void PlaySound_Free(WINE_PLAYSOUND* wps) if (*p) *p = (*p)->lpNext; if (PlaySoundList == NULL) SetEvent(psLastEvent); LeaveCriticalSection(&WINMM_cs); - if (wps->bAlloc) HeapFree(GetProcessHeap(), 0, (void*)wps->pszSound); - if (wps->hThread) CloseHandle(wps->hThread); + if (wps->hmmio) mmioClose(wps->hmmio, 0); HeapFree(GetProcessHeap(), 0, wps); } -static WINE_PLAYSOUND* PlaySound_Alloc(const void* pszSound, HMODULE hmod, - DWORD fdwSound, BOOL bUnicode) +static WINE_PLAYSOUND* PlaySound_AllocAndGetMMIO(const void* pszSound, HMODULE hmod, + DWORD fdwSound, BOOL bUnicode) { + BOOL bIsString; + LPCWSTR pszSoundW; + UNICODE_STRING usBuffer; WINE_PLAYSOUND* wps; - wps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wps)); - if (!wps) return NULL; + bIsString = PlaySound_IsString(fdwSound, pszSound); - wps->hMod = hmod; - wps->fdwSound = fdwSound; - if (PlaySound_IsString(fdwSound, pszSound)) + if (bIsString && !bUnicode) { - if (bUnicode) - { - if (fdwSound & SND_ASYNC) - { - LPWSTR sound = HeapAlloc(GetProcessHeap(), 0, - (lstrlenW(pszSound)+1) * sizeof(WCHAR)); - if (!sound) goto oom_error; - wps->pszSound = lstrcpyW(sound, pszSound); - wps->bAlloc = TRUE; - } - else - wps->pszSound = pszSound; - } - else + RtlCreateUnicodeStringFromAsciiz(&usBuffer, pszSound); + if (!usBuffer.Buffer) + return NULL; + + pszSoundW = usBuffer.Buffer; + } + else + { + pszSoundW = pszSound; + } + + wps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wps)); + if (wps) + { + /* construct an MMIO stream (either in memory, or from a file) */ + wps->hmmio = PlaySound_GetMMIO(pszSoundW, hmod, fdwSound); + if (!wps->hmmio) { - UNICODE_STRING usBuffer; - RtlCreateUnicodeStringFromAsciiz(&usBuffer, pszSound); - wps->pszSound = usBuffer.Buffer; - if (!wps->pszSound) goto oom_error; - wps->bAlloc = TRUE; + PlaySound_Free(wps); + wps = NULL; } } - else - wps->pszSound = pszSound; + + if (bIsString && !bUnicode) + RtlFreeUnicodeString(&usBuffer); return wps; - oom_error: - PlaySound_Free(wps); - return NULL; } -static DWORD WINAPI proc_PlaySound(LPVOID arg) +static BOOL proc_PlaySound(WINE_PLAYSOUND *wps) { - WINE_PLAYSOUND* wps = arg; BOOL bRet = FALSE; - HMMIO hmmio = 0; MMCKINFO ckMainRIFF; MMCKINFO mmckInfo; LPWAVEFORMATEX lpWaveFormat = NULL; LPWAVEHDR waveHdr = NULL; INT count, bufsize, left, index; struct playsound_data s; - void* data; s.hEvent = 0; - TRACE("SoundName=%s !\n", debugstr_w(wps->pszSound)); - - /* if resource, grab it */ - if ((wps->fdwSound & SND_RESOURCE) == SND_RESOURCE) { - static const WCHAR wszWave[] = {'W','A','V','E',0}; - HRSRC hRes; - HGLOBAL hGlob; - - if ((hRes = FindResourceW(wps->hMod, wps->pszSound, wszWave)) == 0 || - (hGlob = LoadResource(wps->hMod, hRes)) == 0) - goto errCleanUp; - if ((data = LockResource(hGlob)) == NULL) { - FreeResource(hGlob); - goto errCleanUp; - } - FreeResource(hGlob); - } else - data = (void*)wps->pszSound; - - /* construct an MMIO stream (either in memory, or from a file */ - if (wps->fdwSound & SND_MEMORY) - { /* NOTE: SND_RESOURCE has the SND_MEMORY bit set */ - MMIOINFO mminfo; - - memset(&mminfo, 0, sizeof(mminfo)); - mminfo.fccIOProc = FOURCC_MEM; - mminfo.pchBuffer = data; - mminfo.cchBuffer = -1; /* FIXME: when a resource, could grab real size */ - TRACE("Memory sound %p\n", data); - hmmio = mmioOpenW(NULL, &mminfo, MMIO_READ); - } - else if (wps->fdwSound & SND_ALIAS) - { - if ((wps->fdwSound & SND_ALIAS_ID) == SND_ALIAS_ID) - { - static const WCHAR wszSystemAsterisk[] = {'S','y','s','t','e','m','A','s','t','e','r','i','s','k',0}; - static const WCHAR wszSystemDefault[] = {'S','y','s','t','e','m','D','e','f','a','u','l','t',0}; - static const WCHAR wszSystemExclamation[] = {'S','y','s','t','e','m','E','x','c','l','a','m','a','t','i','o','n',0}; - static const WCHAR wszSystemExit[] = {'S','y','s','t','e','m','E','x','i','t',0}; - static const WCHAR wszSystemHand[] = {'S','y','s','t','e','m','H','a','n','d',0}; - static const WCHAR wszSystemQuestion[] = {'S','y','s','t','e','m','Q','u','e','s','t','i','o','n',0}; - static const WCHAR wszSystemStart[] = {'S','y','s','t','e','m','S','t','a','r','t',0}; - static const WCHAR wszSystemWelcome[] = {'S','y','s','t','e','m','W','e','l','c','o','m','e',0}; - - wps->fdwSound &= ~(SND_ALIAS_ID ^ SND_ALIAS); - if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMASTERISK) - wps->pszSound = wszSystemAsterisk; - else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMDEFAULT) - wps->pszSound = wszSystemDefault; - else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXCLAMATION) - wps->pszSound = wszSystemExclamation; - else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMEXIT) - wps->pszSound = wszSystemExit; - else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMHAND) - wps->pszSound = wszSystemHand; - else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMQUESTION) - wps->pszSound = wszSystemQuestion; - else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMSTART) - wps->pszSound = wszSystemStart; - else if (wps->pszSound == (LPCWSTR)SND_ALIAS_SYSTEMWELCOME) - wps->pszSound = wszSystemWelcome; - else goto errCleanUp; - } - hmmio = get_mmioFromProfile(wps->fdwSound, wps->pszSound); - } - else if (wps->fdwSound & SND_FILENAME) - { - hmmio = get_mmioFromFile(wps->pszSound); - } - else - { - if ((hmmio = get_mmioFromProfile(wps->fdwSound | SND_NODEFAULT, wps->pszSound)) == 0) - { - if ((hmmio = get_mmioFromFile(wps->pszSound)) == 0) - { - hmmio = get_mmioFromProfile(wps->fdwSound, wps->pszSound); - } - } - } - if (hmmio == 0) goto errCleanUp; - - if (mmioDescend(hmmio, &ckMainRIFF, NULL, 0)) + if (mmioDescend(wps->hmmio, &ckMainRIFF, NULL, 0)) goto errCleanUp; TRACE("ParentChunk ckid=%.4s fccType=%.4s cksize=%08X\n", @@ -359,14 +445,14 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) goto errCleanUp; mmckInfo.ckid = mmioFOURCC('f', 'm', 't', ' '); - if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK)) + if (mmioDescend(wps->hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK)) goto errCleanUp; TRACE("Chunk Found ckid=%.4s fccType=%08x cksize=%08X\n", (LPSTR)&mmckInfo.ckid, mmckInfo.fccType, mmckInfo.cksize); lpWaveFormat = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize); - if (mmioRead(hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize) < sizeof(PCMWAVEFORMAT)) + if (mmioRead(wps->hmmio, (HPSTR)lpWaveFormat, mmckInfo.cksize) < sizeof(PCMWAVEFORMAT)) goto errCleanUp; TRACE("wFormatTag=%04X !\n", lpWaveFormat->wFormatTag); @@ -377,10 +463,10 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) TRACE("wBitsPerSample=%u !\n", lpWaveFormat->wBitsPerSample); /* move to end of 'fmt ' chunk */ - mmioAscend(hmmio, &mmckInfo, 0); + mmioAscend(wps->hmmio, &mmckInfo, 0); mmckInfo.ckid = mmioFOURCC('d', 'a', 't', 'a'); - if (mmioDescend(hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK)) + if (mmioDescend(wps->hmmio, &mmckInfo, &ckMainRIFF, MMIO_FINDCHUNK)) goto errCleanUp; TRACE("Chunk Found ckid=%.4s fccType=%08x cksize=%08X\n", @@ -413,7 +499,7 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) do { left = mmckInfo.cksize; - mmioSeek(hmmio, mmckInfo.dwDataOffset, SEEK_SET); + mmioSeek(wps->hmmio, mmckInfo.dwDataOffset, SEEK_SET); while (left) { if (WaitForSingleObject(psStopEvent, 0) == WAIT_OBJECT_0) @@ -421,7 +507,7 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) wps->bLoop = FALSE; break; } - count = mmioRead(hmmio, waveHdr[index].lpData, min(bufsize, left)); + count = mmioRead(wps->hmmio, waveHdr[index].lpData, min(bufsize, left)); if (count < 1) break; left -= count; waveHdr[index].dwBufferLength = count; @@ -442,18 +528,45 @@ static DWORD WINAPI proc_PlaySound(LPVOID arg) waveOutUnprepareHeader(wps->hWave, &waveHdr[1], sizeof(WAVEHDR)); errCleanUp: - TRACE("Done playing=%s => %s!\n", debugstr_w(wps->pszSound), bRet ? "ok" : "ko"); + TRACE("Done playing sound => %s!\n", bRet ? "ok" : "ko"); CloseHandle(s.hEvent); HeapFree(GetProcessHeap(), 0, waveHdr); HeapFree(GetProcessHeap(), 0, lpWaveFormat); if (wps->hWave) while (waveOutClose(wps->hWave) == WAVERR_STILLPLAYING) Sleep(100); - if (hmmio) mmioClose(hmmio, 0); PlaySound_Free(wps); return bRet; } +static DWORD WINAPI PlaySoundAsyncThreadProc(LPVOID lpParameter) +{ + WINE_PLAYSOUND *wps = (WINE_PLAYSOUND*)lpParameter; + + /* Play the sound */ + proc_PlaySound(wps); + + return 0; +} + +static BOOL proc_PlaySoundAsync(WINE_PLAYSOUND *wps) +{ + HANDLE hThread; + + /* Create a thread to play the sound asynchronously */ + hThread = CreateThread(NULL, 0, PlaySoundAsyncThreadProc, wps, 0, NULL); + if (hThread) + { + SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL); + CloseHandle(hThread); + return TRUE; + } + + /* Error cases */ + PlaySound_Free(wps); + return FALSE; +} + static BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSound, BOOL bUnicode) { WINE_PLAYSOUND* wps = NULL; @@ -470,7 +583,7 @@ static BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSo /* alloc internal structure, if we need to play something */ if (pszSound && !(fdwSound & SND_PURGE)) { - if (!(wps = PlaySound_Alloc(pszSound, hmod, fdwSound, bUnicode))) + if (!(wps = PlaySound_AllocAndGetMMIO(pszSound, hmod, fdwSound, bUnicode))) return FALSE; } @@ -501,20 +614,12 @@ static BOOL MULTIMEDIA_PlaySound(const void* pszSound, HMODULE hmod, DWORD fdwSo if (fdwSound & SND_ASYNC) { - DWORD id; - HANDLE handle; wps->bLoop = (fdwSound & SND_LOOP) ? TRUE : FALSE; - if ((handle = CreateThread(NULL, 0, proc_PlaySound, wps, 0, &id)) != 0) { - wps->hThread = handle; - SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL); - return TRUE; - } + + return proc_PlaySoundAsync(wps); } - else return proc_PlaySound(wps); - - /* error cases */ - PlaySound_Free(wps); - return FALSE; + + return proc_PlaySound(wps); } /**************************************************************************
1 year, 7 months
1
0
0
0
← Newer
1
2
3
4
5
6
7
Older →
Jump to page:
1
2
3
4
5
6
7
Results per page:
10
25
50
100
200