|
4 | 4 |
|
5 | 5 | #if FEATURE_REGISTRY |
6 | 6 |
|
7 | | -using Microsoft.Win32; |
8 | | -using Microsoft.Win32.SafeHandles; |
9 | 7 | using System; |
| 8 | +using System.Buffers.Binary; |
10 | 9 | using System.Collections.Concurrent; |
11 | 10 | using System.ComponentModel; |
12 | 11 | using System.Diagnostics; |
|
22 | 21 | using IronPython.Runtime.Exceptions; |
23 | 22 | using IronPython.Runtime.Types; |
24 | 23 |
|
| 24 | +using Microsoft.Win32; |
| 25 | +using Microsoft.Win32.SafeHandles; |
| 26 | + |
25 | 27 | [assembly: PythonModule("winreg", typeof(IronPython.Modules.PythonWinReg), PlatformsAttribute.PlatformFamily.Windows)] |
26 | 28 | namespace IronPython.Modules { |
27 | 29 | [SupportedOSPlatform("windows")] |
@@ -70,6 +72,7 @@ public static class PythonWinReg { |
70 | 72 | public const int REG_FULL_RESOURCE_DESCRIPTOR = 0X9; |
71 | 73 | public const int REG_RESOURCE_REQUIREMENTS_LIST = 0XA; |
72 | 74 | public const int REG_QWORD = 0xB; |
| 75 | + public const int REG_QWORD_LITTLE_ENDIAN = 0XB; |
73 | 76 |
|
74 | 77 | public const int REG_NOTIFY_CHANGE_NAME = 0X1; |
75 | 78 | public const int REG_NOTIFY_CHANGE_ATTRIBUTES = 0X2; |
@@ -346,19 +349,22 @@ private static void QueryValueExImpl(SafeRegistryHandle handle, string valueName |
346 | 349 | break; |
347 | 350 | case REG_EXPAND_SZ: |
348 | 351 | case REG_SZ: |
349 | | - if (length >= 2 && data[length - 1] == 0 && data[length - 2] == 0) { |
350 | | - value = ExtractString(data, 0, (int)length - 2); |
351 | | - } else { |
352 | | - value = ExtractString(data, 0, (int)length); |
353 | | - } |
| 352 | + var span = MemoryMarshal.Cast<byte, char>(data.AsSpan()); |
| 353 | + var len = span.IndexOf((char)0); |
| 354 | + if (len != -1) span = span.Slice(0, len); |
| 355 | + value = span.ToString(); |
354 | 356 | break; |
355 | 357 | case REG_DWORD: |
356 | | - if (BitConverter.IsLittleEndian) { |
357 | | - value = (uint)((data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0]); |
358 | | - } else { |
359 | | - value = (uint)((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]); |
360 | | - } |
| 358 | + var dval = BitConverter.ToUInt32(data, 0); |
| 359 | + if (!BitConverter.IsLittleEndian) dval = BinaryPrimitives.ReverseEndianness(dval); |
| 360 | + value = dval > int.MaxValue ? (BigInteger)dval : unchecked((int)dval); |
361 | 361 | break; |
| 362 | + case REG_QWORD: |
| 363 | + var qval = BitConverter.ToUInt64(data, 0); |
| 364 | + if (!BitConverter.IsLittleEndian) qval = BinaryPrimitives.ReverseEndianness(qval); |
| 365 | + value = (BigInteger)qval; |
| 366 | + break; |
| 367 | + |
362 | 368 | default: |
363 | 369 | value = null; |
364 | 370 | break; |
|
0 commit comments