[PATCH] ntdll: Use wide-char string literals in version.c.

Michael Stefaniuc mstefani at winehq.org
Thu Dec 3 17:36:31 CST 2020


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 dlls/ntdll/version.c | 177 ++++++++++++++++---------------------------
 1 file changed, 64 insertions(+), 113 deletions(-)

diff --git a/dlls/ntdll/version.c b/dlls/ntdll/version.c
index 46715575225..740d8403f5e 100644
--- a/dlls/ntdll/version.c
+++ b/dlls/ntdll/version.c
@@ -66,20 +66,17 @@ static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
     /* WIN20 FIXME: verify values */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 2, 0, 0, VER_PLATFORM_WIN32s,
-        {'W','i','n','3','2','s',' ','1','.','3',0},
-        0, 0, 0, 0, 0
+        L"Win32s 1.3", 0, 0, 0, 0, 0
     },
     /* WIN30 FIXME: verify values */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 3, 0, 0, VER_PLATFORM_WIN32s,
-        {'W','i','n','3','2','s',' ','1','.','3',0},
-        0, 0, 0, 0, 0
+        L"Win32s 1.3", 0, 0, 0, 0, 0
     },
     /* WIN31 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 3, 10, 0, VER_PLATFORM_WIN32s,
-        {'W','i','n','3','2','s',' ','1','.','3',0},
-        0, 0, 0, 0, 0
+        L"Win32s 1.3", 0, 0, 0, 0, 0
     },
     /* WIN95 */
     {
@@ -91,8 +88,7 @@ static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
          * Win95a/b can be discerned via regkey SubVersionNumber
          */
         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x40003B6, VER_PLATFORM_WIN32_WINDOWS,
-        {0},
-        0, 0, 0, 0, 0
+        L"", 0, 0, 0, 0, 0
     },
     /* WIN98 (second edition) */
     {
@@ -100,121 +96,111 @@ static const RTL_OSVERSIONINFOEXW VersionData[NB_WINDOWS_VERSIONS] =
          * Win98SE: 4, 10, 0x40A08AE, " A " 4.10.2222
          */
         sizeof(RTL_OSVERSIONINFOEXW), 4, 10, 0x40A08AE, VER_PLATFORM_WIN32_WINDOWS,
-        {' ','A',' ',0},
-        0, 0, 0, 0, 0
+        L" A ", 0, 0, 0, 0, 0
     },
     /* WINME */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 4, 90, 0x45A0BB8, VER_PLATFORM_WIN32_WINDOWS,
-        {' ',0},
-        0, 0, 0, 0, 0
+        L" ", 0, 0, 0, 0, 0
     },
     /* NT351 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 3, 51, 0x421, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','5',0},
-        5, 0, 0, VER_NT_WORKSTATION, 0
+        L"Service Pack 5", 5, 0, 0, VER_NT_WORKSTATION, 0
     },
     /* NT40 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 4, 0, 0x565, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','6','a',0},
-        6, 0, 0, VER_NT_WORKSTATION, 0
+        L"Service Pack 6a", 6, 0, 0, VER_NT_WORKSTATION, 0
     },
     /* NT2K */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 5, 0, 0x893, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','4',0},
-        4, 0, 0, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
+        L"Service Pack 4", 4, 0, 0, VER_NT_WORKSTATION,
+        30 /* FIXME: Great, a reserved field with a value! */
     },
     /* WINXP */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 5, 1, 0xA28, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0},
-        3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 30 /* FIXME: Great, a reserved field with a value! */
+        L"Service Pack 3", 3, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION,
+        30 /* FIXME: Great, a reserved field with a value! */
     },
     /* WINXP64 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
-        2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
+        L"Service Pack 2", 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
     },
     /* WIN2K3 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 5, 2, 0xECE, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
-        2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
+        L"Service Pack 2", 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
     },
     /* WINVISTA */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
-        2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
+        L"Service Pack 2", 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
     },
     /* WIN2K8 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 6, 0, 0x1772, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','2',0},
-        2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
+        L"Service Pack 2", 2, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
     },
     /* WIN7 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
-        1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
+        L"Service Pack 1", 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
     },
     /* WIN2K8R2 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 6, 1, 0x1DB1, VER_PLATFORM_WIN32_NT,
-        {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','1',0},
-        1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
+        L"Service Pack 1", 1, 0, VER_SUITE_SINGLEUSERTS, VER_NT_SERVER, 0
     },
     /* WIN8 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 6, 2, 0x23F0, VER_PLATFORM_WIN32_NT,
-        {0}, 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
+        L"", 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
     },
     /* WIN81 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 6, 3, 0x2580, VER_PLATFORM_WIN32_NT,
-        {0}, 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
+        L"", 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
     },
     /* WIN10 */
     {
         sizeof(RTL_OSVERSIONINFOEXW), 10, 0, 0x4563, VER_PLATFORM_WIN32_NT,
-        {0}, 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
+        L"", 0, 0, VER_SUITE_SINGLEUSERTS, VER_NT_WORKSTATION, 0
     },
 
 };
 
 static const struct { WCHAR name[12]; WINDOWS_VERSION ver; } version_names[] =
 {
-    { {'w','i','n','2','0',0}, WIN20 },
-    { {'w','i','n','3','0',0}, WIN30 },
-    { {'w','i','n','3','1',0}, WIN31 },
-    { {'w','i','n','9','5',0}, WIN95 },
-    { {'w','i','n','9','8',0}, WIN98 },
-    { {'w','i','n','m','e',0}, WINME },
-    { {'n','t','3','5','1',0}, NT351 },
-    { {'n','t','4','0',0}, NT40 },
-    { {'w','i','n','2','0','0','0',0}, NT2K },
-    { {'w','i','n','2','k',0}, NT2K },
-    { {'n','t','2','k',0}, NT2K },
-    { {'n','t','2','0','0','0',0}, NT2K },
-    { {'w','i','n','x','p',0}, WINXP },
-    { {'w','i','n','x','p','6','4',0}, WINXP64 },
-    { {'w','i','n','2','0','0','3',0}, WIN2K3 },
-    { {'w','i','n','2','k','3',0}, WIN2K3 },
-    { {'v','i','s','t','a',0}, WINVISTA },
-    { {'w','i','n','v','i','s','t','a',0}, WINVISTA },
-    { {'w','i','n','2','0','0','8',0}, WIN2K8 },
-    { {'w','i','n','2','k','8',0}, WIN2K8 },
-    { {'w','i','n','2','0','0','8','r','2',0}, WIN2K8R2 },
-    { {'w','i','n','2','k','8','r','2',0}, WIN2K8R2 },
-    { {'w','i','n','7',0}, WIN7 },
-    { {'w','i','n','8',0}, WIN8 },
-    { {'w','i','n','8','1',0}, WIN81 },
-    { {'w','i','n','1','0',0}, WIN10 },
+    { L"win20", WIN20 },
+    { L"win30", WIN30 },
+    { L"win31", WIN31 },
+    { L"win95", WIN95 },
+    { L"win98", WIN98 },
+    { L"winme", WINME },
+    { L"nt351", NT351 },
+    { L"nt40", NT40 },
+    { L"win2000", NT2K },
+    { L"win2k", NT2K },
+    { L"nt2k", NT2K },
+    { L"nt2000", NT2K },
+    { L"winxp", WINXP },
+    { L"winxp64", WINXP64 },
+    { L"win2003", WIN2K3 },
+    { L"win2k3", WIN2K3 },
+    { L"vista", WINVISTA },
+    { L"winvista", WINVISTA },
+    { L"win2008", WIN2K8 },
+    { L"win2k8", WIN2K8 },
+    { L"win2008r2", WIN2K8R2 },
+    { L"win2k8r2", WIN2K8R2 },
+    { L"win7", WIN7 },
+    { L"win8", WIN8 },
+    { L"win81", WIN81 },
+    { L"win10", WIN10 },
 };
 
 
@@ -229,29 +215,6 @@ static const RTL_OSVERSIONINFOEXW *current_version;
  */
 static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
 {
-    static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
-                                         'S','o','f','t','w','a','r','e','\\',
-                                         'M','i','c','r','o','s','o','f','t','\\',
-                                         'W','i','n','d','o','w','s',' ','N','T','\\',
-                                         'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
-    static const WCHAR service_pack_keyW[] = {'M','a','c','h','i','n','e','\\',
-                                              'S','y','s','t','e','m','\\',
-                                              'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
-                                              'C','o','n','t','r','o','l','\\',
-                                              'W','i','n','d','o','w','s',0};
-    static const WCHAR product_keyW[] = {'M','a','c','h','i','n','e','\\',
-                                         'S','y','s','t','e','m','\\',
-                                         'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
-                                         'C','o','n','t','r','o','l','\\',
-                                         'P','r','o','d','u','c','t','O','p','t','i','o','n','s',0};
-    static const WCHAR CurrentBuildNumberW[] = {'C','u','r','r','e','n','t','B','u','i','l','d','N','u','m','b','e','r',0};
-    static const WCHAR CSDVersionW[] = {'C','S','D','V','e','r','s','i','o','n',0};
-    static const WCHAR CurrentVersionW[] = {'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
-    static const WCHAR ProductTypeW[] = {'P','r','o','d','u','c','t','T','y','p','e',0};
-    static const WCHAR WinNTW[]    = {'W','i','n','N','T',0};
-    static const WCHAR ServerNTW[] = {'S','e','r','v','e','r','N','T',0};
-    static const WCHAR LanmanNTW[] = {'L','a','n','m','a','n','N','T',0};
-
     OBJECT_ATTRIBUTES attr;
     UNICODE_STRING nameW, valueW;
     HANDLE hkey, hkey2;
@@ -266,13 +229,13 @@ static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
     attr.Attributes = 0;
     attr.SecurityDescriptor = NULL;
     attr.SecurityQualityOfService = NULL;
-    RtlInitUnicodeString( &nameW, version_keyW );
+    RtlInitUnicodeString( &nameW, L"Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion" );
 
     if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
 
     memset( version, 0, sizeof(*version) );
 
-    RtlInitUnicodeString( &valueW, CurrentVersionW );
+    RtlInitUnicodeString( &valueW, L"CurrentVersion" );
     if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
     {
         WCHAR *p, *str = (WCHAR *)info->Data;
@@ -293,7 +256,7 @@ static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
 
         /* get build number */
 
-        RtlInitUnicodeString( &valueW, CurrentBuildNumberW );
+        RtlInitUnicodeString( &valueW, L"CurrentBuildNumber" );
         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
         {
             WCHAR *str = (WCHAR *)info->Data;
@@ -303,7 +266,7 @@ static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
 
         /* get version description */
 
-        RtlInitUnicodeString( &valueW, CSDVersionW );
+        RtlInitUnicodeString( &valueW, L"CSDVersion" );
         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
         {
             DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
@@ -313,10 +276,10 @@ static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
 
         /* get service pack version */
 
-        RtlInitUnicodeString( &nameW, service_pack_keyW );
+        RtlInitUnicodeString( &nameW, L"Machine\\System\\CurrentControlSet\\Control\\Windows" );
         if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
         {
-            RtlInitUnicodeString( &valueW, CSDVersionW );
+            RtlInitUnicodeString( &valueW, L"CSDVersion" );
             if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp), &count ))
             {
                 if (info->DataLength >= sizeof(DWORD))
@@ -331,17 +294,17 @@ static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
 
         /* get product type */
 
-        RtlInitUnicodeString( &nameW, product_keyW );
+        RtlInitUnicodeString( &nameW, L"Machine\\System\\CurrentControlSet\\Control\\ProductOptions" );
         if (!NtOpenKey( &hkey2, KEY_ALL_ACCESS, &attr ))
         {
-            RtlInitUnicodeString( &valueW, ProductTypeW );
+            RtlInitUnicodeString( &valueW, L"ProductType" );
             if (!NtQueryValueKey( hkey2, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
             {
                 WCHAR *str = (WCHAR *)info->Data;
                 str[info->DataLength / sizeof(WCHAR)] = 0;
-                if (!wcsicmp( str, WinNTW )) version->wProductType = VER_NT_WORKSTATION;
-                else if (!wcsicmp( str, LanmanNTW )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
-                else if (!wcsicmp( str, ServerNTW )) version->wProductType = VER_NT_SERVER;
+                if (!wcsicmp( str, L"WinNT" )) version->wProductType = VER_NT_WORKSTATION;
+                else if (!wcsicmp( str, L"LanmanNT" )) version->wProductType = VER_NT_DOMAIN_CONTROLLER;
+                else if (!wcsicmp( str, L"ServerNT" )) version->wProductType = VER_NT_SERVER;
             }
             NtClose( hkey2 );
         }
@@ -361,14 +324,6 @@ static BOOL get_nt_registry_version( RTL_OSVERSIONINFOEXW *version )
  */
 static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
 {
-    static const WCHAR version_keyW[] = {'M','a','c','h','i','n','e','\\',
-                                         'S','o','f','t','w','a','r','e','\\',
-                                         'M','i','c','r','o','s','o','f','t','\\',
-                                         'W','i','n','d','o','w','s','\\',
-                                         'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0};
-    static const WCHAR VersionNumberW[] = {'V','e','r','s','i','o','n','N','u','m','b','e','r',0};
-    static const WCHAR SubVersionNumberW[] = {'S','u','b','V','e','r','s','i','o','n','N','u','m','b','e','r',0};
-
     OBJECT_ATTRIBUTES attr;
     UNICODE_STRING nameW, valueW;
     HANDLE hkey;
@@ -383,13 +338,13 @@ static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
     attr.Attributes = 0;
     attr.SecurityDescriptor = NULL;
     attr.SecurityQualityOfService = NULL;
-    RtlInitUnicodeString( &nameW, version_keyW );
+    RtlInitUnicodeString( &nameW, L"Machine\\Software\\Microsoft\\Windows\\CurrentVersion" );
 
     if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr )) return FALSE;
 
     memset( version, 0, sizeof(*version) );
 
-    RtlInitUnicodeString( &valueW, VersionNumberW );
+    RtlInitUnicodeString( &valueW, L"VersionNumber" );
     if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
     {
         WCHAR *p, *str = (WCHAR *)info->Data;
@@ -417,7 +372,7 @@ static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
         ret = TRUE;
         version->dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
 
-        RtlInitUnicodeString( &valueW, SubVersionNumberW );
+        RtlInitUnicodeString( &valueW, L"SubVersionNumber" );
         if (!NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp)-1, &count ))
         {
             DWORD len = min( info->DataLength, sizeof(version->szCSDVersion) - sizeof(WCHAR) );
@@ -438,14 +393,12 @@ static BOOL get_win9x_registry_version( RTL_OSVERSIONINFOEXW *version )
  */
 static BOOL parse_win_version( HANDLE hkey )
 {
-    static const WCHAR VersionW[] = {'V','e','r','s','i','o','n',0};
-
     UNICODE_STRING valueW;
     WCHAR *name, tmp[64];
     KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)tmp;
     DWORD i, count;
 
-    RtlInitUnicodeString( &valueW, VersionW );
+    RtlInitUnicodeString( &valueW, L"Version" );
     if (NtQueryValueKey( hkey, &valueW, KeyValuePartialInformation, tmp, sizeof(tmp) - sizeof(WCHAR), &count ))
         return FALSE;
 
@@ -470,8 +423,6 @@ static BOOL parse_win_version( HANDLE hkey )
  */
 void version_init(void)
 {
-    static const WCHAR configW[] = {'S','o','f','t','w','a','r','e','\\','W','i','n','e',0};
-    static const WCHAR appdefaultsW[] = {'A','p','p','D','e','f','a','u','l','t','s','\\',0};
     OBJECT_ATTRIBUTES attr;
     UNICODE_STRING nameW;
     HANDLE root, hkey, config_key;
@@ -488,7 +439,7 @@ void version_init(void)
     attr.Attributes = 0;
     attr.SecurityDescriptor = NULL;
     attr.SecurityQualityOfService = NULL;
-    RtlInitUnicodeString( &nameW, configW );
+    RtlInitUnicodeString( &nameW, L"Software\\Wine" );
 
     /* @@ Wine registry key: HKCU\Software\Wine */
     if (NtOpenKey( &config_key, KEY_ALL_ACCESS, &attr )) config_key = 0;
@@ -500,7 +451,7 @@ void version_init(void)
     if ((p = wcsrchr( appname, '/' ))) appname = p + 1;
     if ((p = wcsrchr( appname, '\\' ))) appname = p + 1;
 
-    wcscpy( appversion, appdefaultsW );
+    wcscpy( appversion, L"AppDefaults\\" );
     wcscat( appversion, appname );
     RtlInitUnicodeString( &nameW, appversion );
     attr.RootDirectory = config_key;
-- 
2.26.2




More information about the wine-devel mailing list