Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/mscorlib/System.Private.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@
<PropertyGroup Condition="'$(OsEnvironment)' == 'Unix'">
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetsOSX)' == 'true'">
<DefineConstants>PLATFORM_OSX;$(DefineConstants)</DefineConstants>
</PropertyGroup>

<!-- Assembly attributes -->
<PropertyGroup>
<AssemblyName>System.Private.CoreLib</AssemblyName>
Expand Down Expand Up @@ -625,6 +627,7 @@
<Compile Condition="'$(FeatureWin32Registry)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\Registry.cs" />
<Compile Condition="'$(FeatureWin32Registry)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\RegistryKey.cs" />
<Compile Condition="'$(FeatureWin32Registry)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\RegistryValueKind.cs" />
<Compile Condition="'$(FeatureWin32Registry)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\RegistryView.cs" />
<Compile Condition="'$(FeatureClassicCominterop)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\OAVariantLib.cs" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -757,4 +760,4 @@
<Win32Resource Condition="'$(GenerateNativeVersionInfo)'=='true'">$(IntermediateOutputPath)\System.Private.CoreLib.res</Win32Resource>
</PropertyGroup>
<Import Project="GenerateCompilerResponseFile.targets" />
</Project>
</Project>
18 changes: 9 additions & 9 deletions src/mscorlib/shared/System/Diagnostics/Tracing/EventProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,21 +555,21 @@ private unsafe bool GetDataFromController(int etwSessionId,
{
#if (!ES_BUILD_PCL && !ES_BUILD_PN && !FEATURE_PAL)
string regKey = @"\Microsoft\Windows\CurrentVersion\Winevt\Publishers\{" + m_providerId + "}";
if (Marshal.SizeOf(typeof(IntPtr)) == 8)
regKey = @"Software" + @"\Wow6432Node" + regKey;
if (System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)) == 8)
regKey = @"HKEY_LOCAL_MACHINE\Software" + @"\Wow6432Node" + regKey;
else
regKey = @"Software" + regKey;
regKey = @"HKEY_LOCAL_MACHINE\Software" + regKey;

string valueName = "ControllerData_Session_" + etwSessionId.ToString(CultureInfo.InvariantCulture);

using (RegistryKey key = Registry.LocalMachine.OpenSubKey(regKey, writable: false))
{
data = key.GetValue(valueName) as byte[];
}

// we need to assert this permission for partial trust scenarios
#if !CORECLR
(new RegistryPermission(RegistryPermissionAccess.Read, regKey)).Assert();
#endif
data = Microsoft.Win32.Registry.GetValue(regKey, valueName, null) as byte[];
if (data != null)
{
// We only used the persisted data from the registry for updates.
// We only used the persisted data from the registry for updates.
command = ControllerCommand.Update;
return true;
}
Expand Down
134 changes: 132 additions & 2 deletions src/mscorlib/src/Microsoft/Win32/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,142 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace Microsoft.Win32
{
/**
* Registry encapsulation. Contains members representing all top level system
* keys.
*
* @security(checkClassLinking=on)
*/
//This class contains only static members and does not need to be serializable.
internal static class Registry
{
public static readonly RegistryKey CurrentUser = RegistryKey.CurrentUser;
public static readonly RegistryKey LocalMachine = RegistryKey.LocalMachine;
/**
* Current User Key.
*
* This key should be used as the root for all user specific settings.
*/
public static readonly RegistryKey CurrentUser = RegistryKey.GetBaseKey(RegistryKey.HKEY_CURRENT_USER);

/**
* Local Machine Key.
*
* This key should be used as the root for all machine specific settings.
*/
public static readonly RegistryKey LocalMachine = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE);

/**
* Classes Root Key.
*
* This is the root key of class information.
*/
public static readonly RegistryKey ClassesRoot = RegistryKey.GetBaseKey(RegistryKey.HKEY_CLASSES_ROOT);

/**
* Users Root Key.
*
* This is the root of users.
*/
public static readonly RegistryKey Users = RegistryKey.GetBaseKey(RegistryKey.HKEY_USERS);

/**
* Performance Root Key.
*
* This is where dynamic performance data is stored on NT.
*/
public static readonly RegistryKey PerformanceData = RegistryKey.GetBaseKey(RegistryKey.HKEY_PERFORMANCE_DATA);

/**
* Current Config Root Key.
*
* This is where current configuration information is stored.
*/
public static readonly RegistryKey CurrentConfig = RegistryKey.GetBaseKey(RegistryKey.HKEY_CURRENT_CONFIG);

//
// Following function will parse a keyName and returns the basekey for it.
// It will also store the subkey name in the out parameter.
// If the keyName is not valid, we will throw ArgumentException.
// The return value shouldn't be null.
//
private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subKeyName)
{
if (keyName == null)
{
throw new ArgumentNullException(nameof(keyName));
}

string basekeyName;
int i = keyName.IndexOf('\\');
if (i != -1)
{
basekeyName = keyName.Substring(0, i).ToUpper(System.Globalization.CultureInfo.InvariantCulture);
}
else
{
basekeyName = keyName.ToUpper(System.Globalization.CultureInfo.InvariantCulture);
}
RegistryKey basekey = null;

switch (basekeyName)
{
case "HKEY_CURRENT_USER":
basekey = Registry.CurrentUser;
break;
case "HKEY_LOCAL_MACHINE":
basekey = Registry.LocalMachine;
break;
case "HKEY_CLASSES_ROOT":
basekey = Registry.ClassesRoot;
break;
case "HKEY_USERS":
basekey = Registry.Users;
break;
case "HKEY_PERFORMANCE_DATA":
basekey = Registry.PerformanceData;
break;
case "HKEY_CURRENT_CONFIG":
basekey = Registry.CurrentConfig;
break;
default:
throw new ArgumentException(SR.Format(SR.Arg_RegInvalidKeyName, nameof(keyName)));
}
if (i == -1 || i == keyName.Length)
{
subKeyName = string.Empty;
}
else
{
subKeyName = keyName.Substring(i + 1, keyName.Length - i - 1);
}
return basekey;
}

public static object GetValue(string keyName, string valueName, object defaultValue)
{
string subKeyName;
RegistryKey basekey = GetBaseKeyFromKeyName(keyName, out subKeyName);
BCLDebug.Assert(basekey != null, "basekey can't be null.");
RegistryKey key = basekey.OpenSubKey(subKeyName);
if (key == null)
{ // if the key doesn't exist, do nothing
return null;
}
try
{
return key.GetValue(valueName, defaultValue);
}
finally
{
key.Close();
}
}
}
}

Expand Down
Loading