summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/Microsoft/Win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/Microsoft/Win32')
-rw-r--r--src/mscorlib/src/Microsoft/Win32/Registry.cs21
-rw-r--r--src/mscorlib/src/Microsoft/Win32/RegistryKey.cs758
-rw-r--r--src/mscorlib/src/Microsoft/Win32/RegistryOptions.cs25
-rw-r--r--src/mscorlib/src/Microsoft/Win32/RegistryValueKind.cs4
-rw-r--r--src/mscorlib/src/Microsoft/Win32/RegistryView.cs2
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs39
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs1
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs1
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs29
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs4
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs46
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs2
-rw-r--r--src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs5
-rw-r--r--src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs15
-rw-r--r--src/mscorlib/src/Microsoft/Win32/Win32Native.cs1389
15 files changed, 9 insertions, 2332 deletions
diff --git a/src/mscorlib/src/Microsoft/Win32/Registry.cs b/src/mscorlib/src/Microsoft/Win32/Registry.cs
index 3ee5f46..bf4f739 100644
--- a/src/mscorlib/src/Microsoft/Win32/Registry.cs
+++ b/src/mscorlib/src/Microsoft/Win32/Registry.cs
@@ -15,8 +15,7 @@ namespace Microsoft.Win32 {
* @security(checkClassLinking=on)
*/
//This class contains only static members and does not need to be serializable.
- [ComVisible(true)]
- public static class Registry {
+ internal static class Registry {
static Registry()
{
}
@@ -130,24 +129,6 @@ namespace Microsoft.Win32 {
key.Close();
}
}
-
- public static void SetValue(string keyName, string valueName, object value ) {
- SetValue(keyName, valueName, value, RegistryValueKind.Unknown);
- }
-
- public static void SetValue(string keyName, string valueName, object value, RegistryValueKind valueKind ) {
- string subKeyName;
- RegistryKey basekey = GetBaseKeyFromKeyName(keyName, out subKeyName);
- BCLDebug.Assert(basekey != null, "basekey can't be null!");
- RegistryKey key = basekey.CreateSubKey(subKeyName);
- BCLDebug.Assert(key != null, "An exception should be thrown if failed!");
- try {
- key.SetValue(valueName, value, valueKind);
- }
- finally {
- key.Close();
- }
- }
}
}
diff --git a/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs b/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs
index ff678f1..f82b276 100644
--- a/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs
+++ b/src/mscorlib/src/Microsoft/Win32/RegistryKey.cs
@@ -55,7 +55,6 @@ namespace Microsoft.Win32
using System.Collections;
using System.Collections.Generic;
using System.Security;
- using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.IO;
@@ -68,21 +67,6 @@ namespace Microsoft.Win32
using System.Diagnostics.CodeAnalysis;
/**
- * Registry hive values. Useful only for GetRemoteBaseKey
- */
- [Serializable]
- [System.Runtime.InteropServices.ComVisible(true)]
- public enum RegistryHive
- {
- ClassesRoot = unchecked((int)0x80000000),
- CurrentUser = unchecked((int)0x80000001),
- LocalMachine = unchecked((int)0x80000002),
- Users = unchecked((int)0x80000003),
- PerformanceData = unchecked((int)0x80000004),
- CurrentConfig = unchecked((int)0x80000005),
- }
-
- /**
* Registry encapsulation. To get an instance of a RegistryKey use the
* Registry class's static members then call OpenSubKey.
*
@@ -90,8 +74,7 @@ namespace Microsoft.Win32
* @security(checkDllCalls=off)
* @security(checkClassLinking=on)
*/
- [ComVisible(true)]
- public sealed class RegistryKey : MarshalByRefObject, IDisposable
+ internal sealed class RegistryKey : MarshalByRefObject, IDisposable
{
// We could use const here, if C# supported ELEMENT_TYPE_I fully.
@@ -168,17 +151,6 @@ namespace Microsoft.Win32
* Creates a RegistryKey.
*
* This key is bound to hkey, if writable is <b>false</b> then no write operations
- * will be allowed.
- */
- private RegistryKey(SafeRegistryHandle hkey, bool writable, RegistryView view)
- : this(hkey, writable, false, false, false, view) {
- }
-
-
- /**
- * Creates a RegistryKey.
- *
- * This key is bound to hkey, if writable is <b>false</b> then no write operations
* will be allowed. If systemkey is set then the hkey won't be released
* when the object is GC'ed.
* The remoteKey flag when set to true indicates that we are dealing with registry entries
@@ -239,262 +211,11 @@ namespace Microsoft.Win32
}
}
- public void Flush() {
- if (hkey != null) {
- if (IsDirty()) {
- Win32Native.RegFlushKey(hkey);
- }
- }
- }
-
void IDisposable.Dispose()
{
Dispose(true);
}
- /**
- * Creates a new subkey, or opens an existing one.
- *
- * @param subkey Name or path to subkey to create or open.
- *
- * @return the subkey, or <b>null</b> if the operation failed.
- */
- [SuppressMessage("Microsoft.Concurrency", "CA8001", Justification = "Reviewed for thread safety")]
- public RegistryKey CreateSubKey(String subkey) {
- return CreateSubKey(subkey, checkMode);
- }
-
- [ComVisible(false)]
- public RegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck)
- {
- return CreateSubKeyInternal(subkey, permissionCheck, null, RegistryOptions.None);
- }
-
- [ComVisible(false)]
- public RegistryKey CreateSubKey(String subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions options)
- {
- return CreateSubKeyInternal(subkey, permissionCheck, null, options);
- }
-
- [ComVisible(false)]
- public RegistryKey CreateSubKey(String subkey, bool writable)
- {
- return CreateSubKeyInternal(subkey, writable ? RegistryKeyPermissionCheck.ReadWriteSubTree : RegistryKeyPermissionCheck.ReadSubTree, null, RegistryOptions.None);
- }
-
- [ComVisible(false)]
- public RegistryKey CreateSubKey(String subkey, bool writable, RegistryOptions options)
- {
- return CreateSubKeyInternal(subkey, writable ? RegistryKeyPermissionCheck.ReadWriteSubTree : RegistryKeyPermissionCheck.ReadSubTree, null, options);
- }
-
- [ComVisible(false)]
- private unsafe RegistryKey CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, object registrySecurityObj, RegistryOptions registryOptions)
- {
- ValidateKeyOptions(registryOptions);
- ValidateKeyName(subkey);
- ValidateKeyMode(permissionCheck);
- EnsureWriteable();
- subkey = FixupName(subkey); // Fixup multiple slashes to a single slash
-
- // only keys opened under read mode is not writable
- if (!remoteKey) {
- RegistryKey key = InternalOpenSubKey(subkey, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree));
- if (key != null) { // Key already exits
- CheckPermission(RegistryInternalCheck.CheckSubKeyWritePermission, subkey, false, RegistryKeyPermissionCheck.Default);
- CheckPermission(RegistryInternalCheck.CheckSubTreePermission, subkey, false, permissionCheck);
- key.checkMode = permissionCheck;
- return key;
- }
- }
-
- CheckPermission(RegistryInternalCheck.CheckSubKeyCreatePermission, subkey, false, RegistryKeyPermissionCheck.Default);
-
- Win32Native.SECURITY_ATTRIBUTES secAttrs = null;
-
- int disposition = 0;
-
- // By default, the new key will be writable.
- SafeRegistryHandle result = null;
- int ret = Win32Native.RegCreateKeyEx(hkey,
- subkey,
- 0,
- null,
- (int)registryOptions /* specifies if the key is volatile */,
- GetRegistryKeyAccess(permissionCheck != RegistryKeyPermissionCheck.ReadSubTree) | (int)regView,
- secAttrs,
- out result,
- out disposition);
-
- if (ret == 0 && !result.IsInvalid) {
- RegistryKey key = new RegistryKey(result, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree), false, remoteKey, false, regView);
- CheckPermission(RegistryInternalCheck.CheckSubTreePermission, subkey, false, permissionCheck);
- key.checkMode = permissionCheck;
-
- if (subkey.Length == 0)
- key.keyName = keyName;
- else
- key.keyName = keyName + "\\" + subkey;
- return key;
- }
- else if (ret != 0) // syscall failed, ret is an error code.
- Win32Error(ret, keyName + "\\" + subkey); // Access denied?
-
- BCLDebug.Assert(false, "Unexpected code path in RegistryKey::CreateSubKey");
- return null;
- }
-
- /**
- * Deletes the specified subkey. Will throw an exception if the subkey has
- * subkeys. To delete a tree of subkeys use, DeleteSubKeyTree.
- *
- * @param subkey SubKey to delete.
- *
- * @exception InvalidOperationException thrown if the subkey has child subkeys.
- */
- public void DeleteSubKey(String subkey) {
- DeleteSubKey(subkey, true);
- }
-
- public void DeleteSubKey(String subkey, bool throwOnMissingSubKey) {
- ValidateKeyName(subkey);
- EnsureWriteable();
- subkey = FixupName(subkey); // Fixup multiple slashes to a single slash
- CheckPermission(RegistryInternalCheck.CheckSubKeyWritePermission, subkey, false, RegistryKeyPermissionCheck.Default);
-
- // Open the key we are deleting and check for children. Be sure to
- // explicitly call close to avoid keeping an extra HKEY open.
- //
- RegistryKey key = InternalOpenSubKey(subkey,false);
- if (key != null) {
- try {
- if (key.InternalSubKeyCount() > 0) {
- ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_RegRemoveSubKey);
- }
- }
- finally {
- key.Close();
- }
-
- int ret;
-
- try {
- ret = Win32Native.RegDeleteKeyEx(hkey, subkey, (int)regView, 0);
- }
- catch (EntryPointNotFoundException) {
- ret = Win32Native.RegDeleteKey(hkey, subkey);
- }
-
- if (ret!=0) {
- if (ret == Win32Native.ERROR_FILE_NOT_FOUND) {
- if (throwOnMissingSubKey)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RegSubKeyAbsent);
- }
- else
- Win32Error(ret, null);
- }
- }
- else { // there is no key which also means there is no subkey
- if (throwOnMissingSubKey)
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RegSubKeyAbsent);
- }
- }
-
- /**
- * Recursively deletes a subkey and any child subkeys.
- *
- * @param subkey SubKey to delete.
- */
- public void DeleteSubKeyTree(String subkey) {
- DeleteSubKeyTree(subkey, true /*throwOnMissingSubKey*/);
- }
-
- [ComVisible(false)]
- public void DeleteSubKeyTree(String subkey, Boolean throwOnMissingSubKey) {
- ValidateKeyName(subkey);
-
- // Security concern: Deleting a hive's "" subkey would delete all
- // of that hive's contents. Don't allow "".
- if (subkey.Length==0 && IsSystemKey()) {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RegKeyDelHive);
- }
-
- EnsureWriteable();
-
- subkey = FixupName(subkey); // Fixup multiple slashes to a single slash
- CheckPermission(RegistryInternalCheck.CheckSubTreeWritePermission, subkey, false, RegistryKeyPermissionCheck.Default);
-
- RegistryKey key = InternalOpenSubKey(subkey, true);
- if (key != null) {
- try {
- if (key.InternalSubKeyCount() > 0) {
- String[] keys = key.InternalGetSubKeyNames();
-
- for (int i=0; i<keys.Length; i++) {
- key.DeleteSubKeyTreeInternal(keys[i]);
- }
- }
- }
- finally {
- key.Close();
- }
-
- int ret;
- try {
- ret = Win32Native.RegDeleteKeyEx(hkey, subkey, (int)regView, 0);
- }
- catch (EntryPointNotFoundException) {
- ret = Win32Native.RegDeleteKey(hkey, subkey);
- }
-
- if (ret!=0) Win32Error(ret, null);
- }
- else if(throwOnMissingSubKey) {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RegSubKeyAbsent);
- }
- }
-
- // An internal version which does no security checks or argument checking. Skipping the
- // security checks should give us a slight perf gain on large trees.
- private void DeleteSubKeyTreeInternal(string subkey) {
- RegistryKey key = InternalOpenSubKey(subkey, true);
- if (key != null) {
- try {
- if (key.InternalSubKeyCount() > 0) {
- String[] keys = key.InternalGetSubKeyNames();
-
- for (int i=0; i<keys.Length; i++) {
- key.DeleteSubKeyTreeInternal(keys[i]);
- }
- }
- }
- finally {
- key.Close();
- }
-
- int ret;
- try {
- ret = Win32Native.RegDeleteKeyEx(hkey, subkey, (int)regView, 0);
- }
- catch (EntryPointNotFoundException) {
- ret = Win32Native.RegDeleteKey(hkey, subkey);
- }
- if (ret!=0) Win32Error(ret, null);
- }
- else {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RegSubKeyAbsent);
- }
- }
-
- /**
- * Deletes the specified value from this key.
- *
- * @param name Name of value to delete.
- */
- public void DeleteValue(String name) {
- DeleteValue(name, true);
- }
-
public void DeleteValue(String name, bool throwOnMissingValue) {
EnsureWriteable();
CheckPermission(RegistryInternalCheck.CheckValueWritePermission, name, false, RegistryKeyPermissionCheck.Default);
@@ -552,68 +273,6 @@ namespace Microsoft.Win32
return key;
}
-
- [ComVisible(false)]
- public static RegistryKey OpenBaseKey(RegistryHive hKey, RegistryView view) {
- ValidateKeyView(view);
- CheckUnmanagedCodePermission();
- return GetBaseKey((IntPtr)((int)hKey), view);
- }
-
- /**
- * Retrieves a new RegistryKey that represents the requested key on a foreign
- * machine. Valid values for hKey are members of the RegistryHive enum, or
- * Win32 integers such as:
- *
- * HKEY_CLASSES_ROOT,
- * HKEY_CURRENT_USER,
- * HKEY_LOCAL_MACHINE,
- * HKEY_USERS,
- * HKEY_PERFORMANCE_DATA,
- * HKEY_CURRENT_CONFIG,
- * HKEY_DYN_DATA.
- *
- * @param hKey HKEY_* to open.
- * @param machineName the machine to connect to
- *
- * @return the RegistryKey requested.
- */
- public static RegistryKey OpenRemoteBaseKey(RegistryHive hKey, String machineName) {
- return OpenRemoteBaseKey(hKey, machineName, RegistryView.Default);
- }
-
- [ComVisible(false)]
- public static RegistryKey OpenRemoteBaseKey(RegistryHive hKey, String machineName, RegistryView view) {
- if (machineName==null)
- throw new ArgumentNullException(nameof(machineName));
- int index = (int)hKey & 0x0FFFFFFF;
- if (index < 0 || index >= hkeyNames.Length || ((int)hKey & 0xFFFFFFF0) != 0x80000000) {
- throw new ArgumentException(Environment.GetResourceString("Arg_RegKeyOutOfRange"));
- }
- ValidateKeyView(view);
-
- CheckUnmanagedCodePermission();
- // connect to the specified remote registry
- SafeRegistryHandle foreignHKey = null;
- int ret = Win32Native.RegConnectRegistry(machineName, new SafeRegistryHandle(new IntPtr((int)hKey), false), out foreignHKey);
-
- if (ret == Win32Native.ERROR_DLL_INIT_FAILED)
- // return value indicates an error occurred
- throw new ArgumentException(Environment.GetResourceString("Arg_DllInitFailure"));
-
- if (ret != 0)
- Win32ErrorStatic(ret, null);
-
- if (foreignHKey.IsInvalid)
- // return value indicates an error occurred
- throw new ArgumentException(Environment.GetResourceString("Arg_RegKeyNoRemoteConnect", machineName));
-
- RegistryKey key = new RegistryKey(foreignHKey, true, false, true, ((IntPtr) hKey) == HKEY_PERFORMANCE_DATA, view);
- key.checkMode = RegistryKeyPermissionCheck.Default;
- key.keyName = hkeyNames[index];
- return key;
- }
-
/**
* Retrieves a subkey. If readonly is <b>true</b>, then the subkey is opened with
* read-only access.
@@ -685,26 +344,6 @@ namespace Microsoft.Win32
return OpenSubKey(name, false);
}
- /**
- * Retrieves the count of subkeys.
- *
- * @return a count of subkeys.
- */
- public int SubKeyCount {
- get {
- CheckPermission(RegistryInternalCheck.CheckKeyReadPermission, null, false, RegistryKeyPermissionCheck.Default);
- return InternalSubKeyCount();
- }
- }
-
- [ComVisible(false)]
- public RegistryView View {
- get {
- EnsureNotDisposed();
- return regView;
- }
- }
-
internal int InternalSubKeyCount() {
EnsureNotDisposed();
@@ -770,18 +409,6 @@ namespace Microsoft.Win32
return names;
}
- /**
- * Retrieves the count of values.
- *
- * @return a count of values.
- */
- public int ValueCount {
- get {
- CheckPermission(RegistryInternalCheck.CheckKeyReadPermission, null, false, RegistryKeyPermissionCheck.Default);
- return InternalValueCount();
- }
- }
-
internal int InternalValueCount() {
EnsureNotDisposed();
int values = 0;
@@ -883,7 +510,6 @@ namespace Microsoft.Win32
return InternalGetValue(name, defaultValue, false, true);
}
- [ComVisible(false)]
public Object GetValue(String name, Object defaultValue, RegistryValueOptions options) {
if( options < RegistryValueOptions.None || options > RegistryValueOptions.DoNotExpandEnvironmentNames) {
throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)options), nameof(options));
@@ -1110,37 +736,6 @@ namespace Microsoft.Win32
return data;
}
-
- [ComVisible(false)]
- public RegistryValueKind GetValueKind(string name) {
- CheckPermission(RegistryInternalCheck.CheckValueReadPermission, name, false, RegistryKeyPermissionCheck.Default);
- EnsureNotDisposed();
-
- int type = 0;
- int datasize = 0;
- int ret = Win32Native.RegQueryValueEx(hkey, name, null, ref type, (byte[])null, ref datasize);
- if (ret != 0)
- Win32Error(ret, null);
- if (type == Win32Native.REG_NONE)
- return RegistryValueKind.None;
- else if (!Enum.IsDefined(typeof(RegistryValueKind), type))
- return RegistryValueKind.Unknown;
- else
- return (RegistryValueKind) type;
- }
-
- /**
- * Retrieves the current state of the dirty property.
- *
- * A key is marked as dirty if any operation has occurred that modifies the
- * contents of the key.
- *
- * @return <b>true</b> if the key has been modified.
- */
- private bool IsDirty() {
- return (this.state & STATE_DIRTY) != 0;
- }
-
private bool IsSystemKey() {
return (this.state & STATE_SYSTEMKEY) != 0;
}
@@ -1153,13 +748,6 @@ namespace Microsoft.Win32
return (this.state & STATE_PERF_DATA) != 0;
}
- public String Name {
- get {
- EnsureNotDisposed();
- return keyName;
- }
- }
-
private void SetDirty() {
this.state |= STATE_DIRTY;
}
@@ -1174,7 +762,6 @@ namespace Microsoft.Win32
SetValue(name, value, RegistryValueKind.Unknown);
}
- [ComVisible(false)]
public unsafe void SetValue(String name, Object value, RegistryValueKind valueKind) {
if (value==null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value);
@@ -1392,19 +979,6 @@ namespace Microsoft.Win32
}
}
- internal static void Win32ErrorStatic(int errorCode, String str) {
- switch (errorCode) {
- case Win32Native.ERROR_ACCESS_DENIED:
- if (str != null)
- throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_RegistryKeyGeneric_Key", str));
- else
- throw new UnauthorizedAccessException();
-
- default:
- throw new IOException(Win32Native.GetMessage(errorCode), errorCode);
- }
- }
-
internal static String FixupName(String name)
{
BCLDebug.Assert(name!=null,"[FixupName]name!=null");
@@ -1469,301 +1043,9 @@ namespace Microsoft.Win32
}
- //
- // Read/Write/Create SubKey Permission
- //
- private void GetSubKeyReadPermission(string subkeyName, out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Read;
- path = keyName + "\\" + subkeyName + "\\.";
- }
- private void GetSubKeyWritePermission(string subkeyName, out RegistryPermissionAccess access, out string path) {
- // If we want to open a subkey of a read-only key as writeable, we need to do the check.
- access = RegistryPermissionAccess.Write;
- path = keyName + "\\" + subkeyName + "\\.";
- }
- private void GetSubKeyCreatePermission(string subkeyName, out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Create;
- path = keyName + "\\" + subkeyName + "\\.";
- }
-
- //
- // Read/Write/ReadWrite SubTree Permission
- //
- private void GetSubTreeReadPermission(string subkeyName, out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Read;
- path = keyName + "\\" + subkeyName + "\\";
- }
- private void GetSubTreeWritePermission(string subkeyName, out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Write;
- path = keyName + "\\" + subkeyName + "\\";
- }
- private void GetSubTreeReadWritePermission(string subkeyName, out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Write | RegistryPermissionAccess.Read;
- path = keyName + "\\" + subkeyName;
- }
-
- //
- // Read/Write/Create Value Permission
- //
- private void GetValueReadPermission(string valueName, out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Read;
- path = keyName+"\\"+valueName;
- }
- private void GetValueWritePermission(string valueName, out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Write;
- path = keyName+"\\"+valueName;
- }
- private void GetValueCreatePermission(string valueName, out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Create;
- path = keyName+"\\"+valueName;
- }
-
- // Read Key Permission
- private void GetKeyReadPermission(out RegistryPermissionAccess access, out string path) {
- access = RegistryPermissionAccess.Read;
- path = keyName + "\\.";
- }
-
private void CheckPermission(RegistryInternalCheck check, string item, bool subKeyWritable, RegistryKeyPermissionCheck subKeyCheck)
{
- bool demand = false;
- RegistryPermissionAccess access = RegistryPermissionAccess.NoAccess;
- string path = null;
-
- switch (check) {
- //
- // Read/Write/Create SubKey Permission
- //
- case RegistryInternalCheck.CheckSubKeyReadPermission:
- if (remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- BCLDebug.Assert(checkMode == RegistryKeyPermissionCheck.Default, "Should be called from a key opened under default mode only!");
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- demand = true;
- GetSubKeyReadPermission(item, out access, out path);
- }
- break;
- case RegistryInternalCheck.CheckSubKeyWritePermission:
- if (remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- BCLDebug.Assert(checkMode != RegistryKeyPermissionCheck.ReadSubTree, "We shouldn't allow creating sub key under read-only key!");
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- demand = true;
- GetSubKeyWritePermission(item, out access, out path);
- }
- }
- break;
- case RegistryInternalCheck.CheckSubKeyCreatePermission:
- if (remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- BCLDebug.Assert(checkMode != RegistryKeyPermissionCheck.ReadSubTree, "We shouldn't allow creating sub key under read-only key!");
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- demand = true;
- GetSubKeyCreatePermission(item, out access, out path);
- }
- }
- break;
- //
- // Read/Write/ReadWrite SubTree Permission
- //
- case RegistryInternalCheck.CheckSubTreeReadPermission:
- if (remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- demand = true;
- GetSubTreeReadPermission(item, out access, out path);
- }
- }
- break;
- case RegistryInternalCheck.CheckSubTreeWritePermission:
- if (remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- BCLDebug.Assert(checkMode != RegistryKeyPermissionCheck.ReadSubTree, "We shouldn't allow writing value to read-only key!");
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- demand = true;
- GetSubTreeWritePermission(item, out access, out path);
- }
- }
- break;
- case RegistryInternalCheck.CheckSubTreeReadWritePermission:
- if (remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- // If we want to open a subkey of a read-only key as writeable, we need to do the check.
- demand = true;
- GetSubTreeReadWritePermission(item, out access, out path);
- }
- break;
- //
- // Read/Write/Create Value Permission
- //
- case RegistryInternalCheck.CheckValueReadPermission:
- ///*** no remoteKey check ***///
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- // only need to check for default mode (dynamice check)
- demand = true;
- GetValueReadPermission(item, out access, out path);
- }
- break;
- case RegistryInternalCheck.CheckValueWritePermission:
- if (remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- BCLDebug.Assert(checkMode != RegistryKeyPermissionCheck.ReadSubTree, "We shouldn't allow writing value to read-only key!");
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- // skip the security check if the key is opened under write mode
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- demand = true;
- GetValueWritePermission(item, out access, out path);
- }
- }
- break;
- case RegistryInternalCheck.CheckValueCreatePermission:
- if (remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- BCLDebug.Assert(checkMode != RegistryKeyPermissionCheck.ReadSubTree, "We shouldn't allow creating value under read-only key!");
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- // skip the security check if the key is opened under write mode
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- demand = true;
- GetValueCreatePermission(item, out access, out path);
- }
- }
- break;
- //
- // CheckKeyReadPermission
- //
- case RegistryInternalCheck.CheckKeyReadPermission:
- ///*** no remoteKey check ***///
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- BCLDebug.Assert(item == null, "CheckKeyReadPermission should never have a non-null item parameter!");
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
-
- // only need to check for default mode (dynamice check)
- demand = true;
- GetKeyReadPermission(out access, out path);
- }
- break;
- //
- // CheckSubTreePermission
- //
- case RegistryInternalCheck.CheckSubTreePermission:
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- if( subKeyCheck == RegistryKeyPermissionCheck.ReadSubTree) {
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- if( remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- demand = true;
- GetSubTreeReadPermission(item, out access, out path);
- }
- }
- }
- else if(subKeyCheck == RegistryKeyPermissionCheck.ReadWriteSubTree) {
- if( checkMode != RegistryKeyPermissionCheck.ReadWriteSubTree) {
- if( remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- demand = true;
- GetSubTreeReadWritePermission(item, out access, out path);
- }
- }
- }
- break;
-
- //
- // CheckOpenSubKeyWithWritablePermission uses the 'subKeyWritable' parameter
- //
- case RegistryInternalCheck.CheckOpenSubKeyWithWritablePermission:
- BCLDebug.Assert(subKeyCheck == RegistryKeyPermissionCheck.Default, "subKeyCheck should be Default (unused)");
- // If the parent key is not opened under default mode, we have access already.
- // If the parent key is opened under default mode, we need to check for permission.
- if(checkMode == RegistryKeyPermissionCheck.Default) {
- if( remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- demand = true;
- GetSubKeyReadPermission(item, out access, out path);
- }
- break;
- }
- if( subKeyWritable && (checkMode == RegistryKeyPermissionCheck.ReadSubTree)) {
- if( remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- demand = true;
- GetSubTreeReadWritePermission(item, out access, out path);
- }
- break;
- }
- break;
-
- //
- // CheckOpenSubKeyPermission uses the 'subKeyCheck' parameter
- //
- case RegistryInternalCheck.CheckOpenSubKeyPermission:
- BCLDebug.Assert(subKeyWritable == false, "subKeyWritable should be false (unused)");
- if(subKeyCheck == RegistryKeyPermissionCheck.Default) {
- if( checkMode == RegistryKeyPermissionCheck.Default) {
- if(remoteKey) {
- CheckUnmanagedCodePermission();
- }
- else {
- demand = true;
- GetSubKeyReadPermission(item, out access, out path);
- }
- }
- }
- break;
-
- default:
- BCLDebug.Assert(false, "CheckPermission default switch case should never be hit!");
- break;
- }
-
- if (demand) {
- new RegistryPermission(access, path).Demand();
- }
- }
-
- static private void CheckUnmanagedCodePermission() {
-#pragma warning disable 618
- new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
-#pragma warning restore 618
+ // TODO: Cleanup
}
private bool ContainsRegistryValue(string name) {
@@ -1798,26 +1080,6 @@ namespace Microsoft.Win32
return winAccess;
}
- static int GetRegistryKeyAccess(RegistryKeyPermissionCheck mode) {
- int winAccess = 0;
- switch(mode) {
- case RegistryKeyPermissionCheck.ReadSubTree:
- case RegistryKeyPermissionCheck.Default:
- winAccess = Win32Native.KEY_READ;
- break;
-
- case RegistryKeyPermissionCheck.ReadWriteSubTree:
- winAccess = Win32Native.KEY_READ| Win32Native.KEY_WRITE;
- break;
-
- default:
- BCLDebug.Assert(false, "unexpected code path");
- break;
- }
-
- return winAccess;
- }
-
private RegistryKeyPermissionCheck GetSubKeyPermissonCheck(bool subkeyWritable) {
if( checkMode == RegistryKeyPermissionCheck.Default) {
return checkMode;
@@ -1851,18 +1113,6 @@ namespace Microsoft.Win32
ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RegKeyStrLenBug);
}
-
- static private void ValidateKeyMode(RegistryKeyPermissionCheck mode) {
- if( mode < RegistryKeyPermissionCheck.Default || mode > RegistryKeyPermissionCheck.ReadWriteSubTree) {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidRegistryKeyPermissionCheck, ExceptionArgument.mode);
- }
- }
-
- static private void ValidateKeyOptions(RegistryOptions options) {
- if (options < RegistryOptions.None || options > RegistryOptions.Volatile) {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidRegistryOptionsCheck, ExceptionArgument.options);
- }
- }
static private void ValidateKeyView(RegistryView view) {
if (view != RegistryView.Default && view != RegistryView.Registry32 && view != RegistryView.Registry64) {
@@ -1877,14 +1127,14 @@ namespace Microsoft.Win32
}
[Flags]
- public enum RegistryValueOptions {
+ internal enum RegistryValueOptions {
None = 0,
DoNotExpandEnvironmentNames = 1
}
// the name for this API is meant to mimic FileMode, which has similar values
- public enum RegistryKeyPermissionCheck {
+ internal enum RegistryKeyPermissionCheck {
Default = 0,
ReadSubTree = 1,
ReadWriteSubTree = 2
diff --git a/src/mscorlib/src/Microsoft/Win32/RegistryOptions.cs b/src/mscorlib/src/Microsoft/Win32/RegistryOptions.cs
deleted file mode 100644
index 4d5e3aa..0000000
--- a/src/mscorlib/src/Microsoft/Win32/RegistryOptions.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-//
-//
-//
-// Implements Microsoft.Win32.RegistryOptions
-//
-// ======================================================================================
-namespace Microsoft.Win32 {
- using System;
-
- [Flags]
- public enum RegistryOptions {
- None = Win32Native.REG_OPTION_NON_VOLATILE, // 0x0000
- Volatile = Win32Native.REG_OPTION_VOLATILE, // 0x0001
-///
-/// Consider exposing more options in a future release. Users can access this
-/// functionality by calling [RegistryKey].Handle and pinvoking
-///
-/// CreateLink = Win32Native.REG_OPTION_CREATE_LINK, // 0x0002
-/// BackupRestore = Win32Native.REG_OPTION_BACKUP_RESTORE,// 0x0004
- };
-}
diff --git a/src/mscorlib/src/Microsoft/Win32/RegistryValueKind.cs b/src/mscorlib/src/Microsoft/Win32/RegistryValueKind.cs
index c88d5f9..5e22275 100644
--- a/src/mscorlib/src/Microsoft/Win32/RegistryValueKind.cs
+++ b/src/mscorlib/src/Microsoft/Win32/RegistryValueKind.cs
@@ -4,8 +4,7 @@
namespace Microsoft.Win32 {
-[System.Runtime.InteropServices.ComVisible(true)]
- public enum RegistryValueKind {
+ internal enum RegistryValueKind {
String = Win32Native.REG_SZ,
ExpandString = Win32Native.REG_EXPAND_SZ,
Binary = Win32Native.REG_BINARY,
@@ -13,7 +12,6 @@ namespace Microsoft.Win32 {
MultiString = Win32Native.REG_MULTI_SZ,
QWord = Win32Native.REG_QWORD,
Unknown = 0, // REG_NONE is defined as zero but BCL
- [System.Runtime.InteropServices.ComVisible(false)]
None = unchecked((int)0xFFFFFFFF), // mistakingly overrode this value.
} // Now instead of using Win32Native.REG_NONE we use "-1" and play games internally.
}
diff --git a/src/mscorlib/src/Microsoft/Win32/RegistryView.cs b/src/mscorlib/src/Microsoft/Win32/RegistryView.cs
index 7fbc2b3..302a603 100644
--- a/src/mscorlib/src/Microsoft/Win32/RegistryView.cs
+++ b/src/mscorlib/src/Microsoft/Win32/RegistryView.cs
@@ -11,7 +11,7 @@
namespace Microsoft.Win32 {
using System;
- public enum RegistryView {
+ internal enum RegistryView {
Default = 0, // 0x0000 operate on the default registry view
Registry64 = Win32Native.KEY_WOW64_64KEY, // 0x0100 operate on the 64-bit registry view
Registry32 = Win32Native.KEY_WOW64_32KEY, // 0x0200 operate on the 32-bit registry view
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs
deleted file mode 100644
index cb915fe..0000000
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFileMappingHandle.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** A wrapper for file handles
-**
-**
-===========================================================*/
-using System;
-using System.Security;
-using System.Security.Permissions;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-using System.Runtime.Versioning;
-
-namespace Microsoft.Win32.SafeHandles
-{
- internal sealed class SafeFileMappingHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- internal SafeFileMappingHandle() : base(true) {}
-
- // 0 is an Invalid Handle
- internal SafeFileMappingHandle(IntPtr handle, bool ownsHandle) : base (ownsHandle)
- {
- SetHandle(handle);
- }
-
- override protected bool ReleaseHandle()
- {
- return Win32Native.CloseHandle(handle);
- }
- }
-}
-
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs
index 219fb77..89ea22b 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeFindHandle.cs
@@ -13,7 +13,6 @@
using System;
using System.Security;
-using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs
index 2363198..603558c 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLibraryHandle.cs
@@ -4,7 +4,6 @@
namespace Microsoft.Win32 {
using Microsoft.Win32.SafeHandles;
- using System.Security.Permissions;
sealed internal class SafeLibraryHandle : SafeHandleZeroOrMinusOneIsInvalid {
internal SafeLibraryHandle() : base(true) {}
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs
deleted file mode 100644
index d6c1577..0000000
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeLocalAllocHandle.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Win32.SafeHandles
-{
- using System;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Runtime.ConstrainedExecution;
-
- internal sealed class SafeLocalAllocHandle : SafeBuffer {
- private SafeLocalAllocHandle () : base(true) {}
-
- // 0 is an Invalid Handle
- internal SafeLocalAllocHandle (IntPtr handle) : base (true) {
- SetHandle(handle);
- }
-
- internal static SafeLocalAllocHandle InvalidHandle {
- get { return new SafeLocalAllocHandle(IntPtr.Zero); }
- }
-
- override protected bool ReleaseHandle()
- {
- return Win32Native.LocalFree(handle) == IntPtr.Zero;
- }
- }
-}
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
index 4f96b81..a1e5bc4 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
@@ -11,13 +11,12 @@
namespace Microsoft.Win32.SafeHandles {
using System;
using System.Security;
- using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.Versioning;
- public sealed class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid {
+ internal sealed class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid {
internal SafeRegistryHandle() : base(true) {}
public SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle) {
@@ -30,7 +29,6 @@ namespace Microsoft.Win32.SafeHandles {
[DllImport(Win32Native.ADVAPI32)]
[SuppressUnmanagedCodeSecurity]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern int RegCloseKey(IntPtr hKey);
}
}
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs
deleted file mode 100644
index 38a9323..0000000
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeViewOfFileHandle.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-/*============================================================
-**
-**
-**
-** A wrapper for file handles
-**
-**
-===========================================================*/
-using System;
-using System.Security;
-using System.Security.Permissions;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-using System.Runtime.Versioning;
-using Microsoft.Win32;
-using Microsoft.Win32.SafeHandles;
-
-namespace Microsoft.Win32.SafeHandles
-{
- internal sealed class SafeViewOfFileHandle : SafeHandleZeroOrMinusOneIsInvalid
- {
- internal SafeViewOfFileHandle() : base(true) {}
-
- // 0 is an Invalid Handle
- internal SafeViewOfFileHandle(IntPtr handle, bool ownsHandle) : base (ownsHandle) {
- SetHandle(handle);
- }
-
- override protected bool ReleaseHandle()
- {
- if (Win32Native.UnmapViewOfFile(handle))
- {
- handle = IntPtr.Zero;
- return true;
- }
-
- return false;
- }
- }
-}
-
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs
index 0e57136..0ebcd5c 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/SafeWaitHandle.cs
@@ -14,7 +14,6 @@
using System;
using System.Security;
-using System.Security.Permissions;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
@@ -31,7 +30,6 @@ namespace Microsoft.Win32.SafeHandles {
{
}
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
public SafeWaitHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle)
{
SetHandle(existingHandle);
diff --git a/src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs b/src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs
index 08ae095..6241813 100644
--- a/src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs
+++ b/src/mscorlib/src/Microsoft/Win32/SafeHandles/Win32SafeHandles.cs
@@ -18,13 +18,11 @@ namespace Microsoft.Win32.SafeHandles
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
- using System.Security.Permissions;
using System.Runtime.ConstrainedExecution;
// Class of safe handle which uses 0 or -1 as an invalid handle.
public abstract class SafeHandleZeroOrMinusOneIsInvalid : SafeHandle
{
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected SafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
{
}
@@ -43,7 +41,6 @@ namespace Microsoft.Win32.SafeHandles
// Class of safe handle which uses only -1 as an invalid handle.
public abstract class SafeHandleMinusOneIsInvalid : SafeHandle
{
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected SafeHandleMinusOneIsInvalid(bool ownsHandle) : base(new IntPtr(-1), ownsHandle)
{
}
@@ -62,7 +59,6 @@ namespace Microsoft.Win32.SafeHandles
// Class of critical handle which uses 0 or -1 as an invalid handle.
public abstract class CriticalHandleZeroOrMinusOneIsInvalid : CriticalHandle
{
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected CriticalHandleZeroOrMinusOneIsInvalid() : base(IntPtr.Zero)
{
}
@@ -75,7 +71,6 @@ namespace Microsoft.Win32.SafeHandles
// Class of critical handle which uses only -1 as an invalid handle.
public abstract class CriticalHandleMinusOneIsInvalid : CriticalHandle
{
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
protected CriticalHandleMinusOneIsInvalid() : base(new IntPtr(-1))
{
}
diff --git a/src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs b/src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs
index 19d638d..6e37b9c 100644
--- a/src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs
+++ b/src/mscorlib/src/Microsoft/Win32/UnsafeNativeMethods.cs
@@ -12,7 +12,6 @@ namespace Microsoft.Win32 {
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
- using System.Security.Permissions;
using System.Text;
using System.Diagnostics.Tracing;
@@ -59,7 +58,6 @@ namespace Microsoft.Win32 {
[DllImport(Win32Native.KERNEL32, CharSet=System.Runtime.InteropServices.CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern bool FreeLibrary(IntPtr hModule);
@@ -120,19 +118,6 @@ namespace Microsoft.Win32 {
[DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventUnregister", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern uint EventUnregister([In] long registrationHandle);
- //
- // Writing (Publishing/Logging) APIs
- //
- //
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
- [DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventWrite", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
- internal static extern unsafe int EventWrite(
- [In] long registrationHandle,
- [In] ref EventDescriptor eventDescriptor,
- [In] int userDataCount,
- [In] EventProvider.EventData* userData
- );
-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[DllImport(Win32Native.ADVAPI32, ExactSpelling = true, EntryPoint = "EventWriteString", CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
internal static extern unsafe int EventWriteString(
diff --git a/src/mscorlib/src/Microsoft/Win32/Win32Native.cs b/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
index b5b808b..b081b16 100644
--- a/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
+++ b/src/mscorlib/src/Microsoft/Win32/Win32Native.cs
@@ -155,42 +155,6 @@ namespace Microsoft.Win32 {
internal const int HWND_BROADCAST = 0xffff;
internal const int WM_SETTINGCHANGE = 0x001A;
- // CryptProtectMemory and CryptUnprotectMemory.
- internal const uint CRYPTPROTECTMEMORY_BLOCK_SIZE = 16;
- internal const uint CRYPTPROTECTMEMORY_SAME_PROCESS = 0x00;
- internal const uint CRYPTPROTECTMEMORY_CROSS_PROCESS = 0x01;
- internal const uint CRYPTPROTECTMEMORY_SAME_LOGON = 0x02;
-
- // Security Quality of Service flags
- internal const int SECURITY_ANONYMOUS = ((int)SECURITY_IMPERSONATION_LEVEL.Anonymous << 16);
- internal const int SECURITY_SQOS_PRESENT = 0x00100000;
-
- // Access Control library.
- internal const string MICROSOFT_KERBEROS_NAME = "Kerberos";
- internal const uint ANONYMOUS_LOGON_LUID = 0x3e6;
-
- internal const int SECURITY_ANONYMOUS_LOGON_RID = 0x00000007;
- internal const int SECURITY_AUTHENTICATED_USER_RID = 0x0000000B;
- internal const int SECURITY_LOCAL_SYSTEM_RID = 0x00000012;
- internal const int SECURITY_BUILTIN_DOMAIN_RID = 0x00000020;
-
- internal const uint SE_PRIVILEGE_DISABLED = 0x00000000;
- internal const uint SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001;
- internal const uint SE_PRIVILEGE_ENABLED = 0x00000002;
- internal const uint SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000;
-
- internal const uint SE_GROUP_MANDATORY = 0x00000001;
- internal const uint SE_GROUP_ENABLED_BY_DEFAULT = 0x00000002;
- internal const uint SE_GROUP_ENABLED = 0x00000004;
- internal const uint SE_GROUP_OWNER = 0x00000008;
- internal const uint SE_GROUP_USE_FOR_DENY_ONLY = 0x00000010;
- internal const uint SE_GROUP_LOGON_ID = 0xC0000000;
- internal const uint SE_GROUP_RESOURCE = 0x20000000;
-
- internal const uint DUPLICATE_CLOSE_SOURCE = 0x00000001;
- internal const uint DUPLICATE_SAME_ACCESS = 0x00000002;
- internal const uint DUPLICATE_SAME_ATTRIBUTES = 0x00000004;
-
// TimeZone
internal const int TIME_ZONE_ID_INVALID = -1;
internal const int TIME_ZONE_ID_UNKNOWN = 0;
@@ -416,20 +380,6 @@ namespace Microsoft.Win32 {
}
[StructLayout(LayoutKind.Sequential)]
- internal struct SYSTEM_INFO {
- internal int dwOemId; // This is a union of a DWORD and a struct containing 2 WORDs.
- internal int dwPageSize;
- internal IntPtr lpMinimumApplicationAddress;
- internal IntPtr lpMaximumApplicationAddress;
- internal IntPtr dwActiveProcessorMask;
- internal int dwNumberOfProcessors;
- internal int dwProcessorType;
- internal int dwAllocationGranularity;
- internal short wProcessorLevel;
- internal short wProcessorRevision;
- }
-
- [StructLayout(LayoutKind.Sequential)]
internal class SECURITY_ATTRIBUTES {
internal int nLength = 0;
// don't remove null, or this field will disappear in bcl.small
@@ -465,206 +415,6 @@ namespace Microsoft.Win32 {
}
[StructLayout(LayoutKind.Sequential)]
- internal struct FILE_TIME {
- public FILE_TIME(long fileTime) {
- ftTimeLow = (uint) fileTime;
- ftTimeHigh = (uint) (fileTime >> 32);
- }
-
- public long ToTicks() {
- return ((long) ftTimeHigh << 32) + ftTimeLow;
- }
-
- internal uint ftTimeLow;
- internal uint ftTimeHigh;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct KERB_S4U_LOGON {
- internal uint MessageType;
- internal uint Flags;
- internal UNICODE_INTPTR_STRING ClientUpn; // REQUIRED: UPN for client
- internal UNICODE_INTPTR_STRING ClientRealm; // Optional: Client Realm, if known
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct LSA_OBJECT_ATTRIBUTES {
- internal int Length;
- internal IntPtr RootDirectory;
- internal IntPtr ObjectName;
- internal int Attributes;
- internal IntPtr SecurityDescriptor;
- internal IntPtr SecurityQualityOfService;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct UNICODE_STRING {
- internal ushort Length;
- internal ushort MaximumLength;
- [MarshalAs(UnmanagedType.LPWStr)] internal string Buffer;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct UNICODE_INTPTR_STRING {
- /// <remarks>
- /// Note - this constructor extracts the raw pointer from the safe handle, so any
- /// strings created with this version of the constructor will be unsafe to use after the buffer
- /// has been freed.
- /// </remarks>
- internal UNICODE_INTPTR_STRING (int stringBytes, SafeLocalAllocHandle buffer) {
- BCLDebug.Assert(buffer == null || (stringBytes >= 0 && (ulong)stringBytes <= buffer.ByteLength),
- "buffer == null || (stringBytes >= 0 && stringBytes <= buffer.ByteLength)");
-
- this.Length = (ushort) stringBytes;
- this.MaxLength = (ushort) buffer.ByteLength;
-
- // Marshaling with a SafePointer does not work correctly, so unfortunately we need to extract
- // the raw handle here.
- this.Buffer = buffer.DangerousGetHandle();
- }
-
- /// <remarks>
- /// This constructor should be used for constructing UNICODE_STRING structures with pointers
- /// into a block of memory managed by a SafeHandle or the GC. It shouldn't be used to own
- /// any memory on its own.
- /// </remarks>
- internal UNICODE_INTPTR_STRING(int stringBytes, IntPtr buffer) {
- BCLDebug.Assert((stringBytes == 0 && buffer == IntPtr.Zero) || (stringBytes > 0 && stringBytes <= UInt16.MaxValue && buffer != IntPtr.Zero),
- "(stringBytes == 0 && buffer == IntPtr.Zero) || (stringBytes > 0 && stringBytes <= UInt16.MaxValue && buffer != IntPtr.Zero)");
-
- this.Length = (ushort)stringBytes;
- this.MaxLength = (ushort)stringBytes;
- this.Buffer = buffer;
- }
-
- internal ushort Length;
- internal ushort MaxLength;
- internal IntPtr Buffer;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct LSA_TRANSLATED_NAME {
- internal int Use;
- internal UNICODE_INTPTR_STRING Name;
- internal int DomainIndex;
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct LSA_TRANSLATED_SID {
- internal int Use;
- internal uint Rid;
- internal int DomainIndex;
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct LSA_TRANSLATED_SID2 {
- internal int Use;
- internal IntPtr Sid;
- internal int DomainIndex;
- uint Flags;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct LSA_TRUST_INFORMATION {
- internal UNICODE_INTPTR_STRING Name;
- internal IntPtr Sid;
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct LSA_REFERENCED_DOMAIN_LIST {
- internal int Entries;
- internal IntPtr Domains;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct LUID {
- internal uint LowPart;
- internal uint HighPart;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct LUID_AND_ATTRIBUTES {
- internal LUID Luid;
- internal uint Attributes;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct QUOTA_LIMITS {
- internal IntPtr PagedPoolLimit;
- internal IntPtr NonPagedPoolLimit;
- internal IntPtr MinimumWorkingSetSize;
- internal IntPtr MaximumWorkingSetSize;
- internal IntPtr PagefileLimit;
- internal IntPtr TimeLimit;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct SECURITY_LOGON_SESSION_DATA {
- internal uint Size;
- internal LUID LogonId;
- internal UNICODE_INTPTR_STRING UserName;
- internal UNICODE_INTPTR_STRING LogonDomain;
- internal UNICODE_INTPTR_STRING AuthenticationPackage;
- internal uint LogonType;
- internal uint Session;
- internal IntPtr Sid;
- internal long LogonTime;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct SID_AND_ATTRIBUTES {
- internal IntPtr Sid;
- internal uint Attributes;
- internal static readonly long SizeOf = (long)Marshal.SizeOf(typeof(SID_AND_ATTRIBUTES));
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct TOKEN_GROUPS {
- internal uint GroupCount;
- internal SID_AND_ATTRIBUTES Groups; // SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal struct TOKEN_PRIMARY_GROUP
- {
- internal IntPtr PrimaryGroup;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct TOKEN_PRIVILEGE {
- internal uint PrivilegeCount;
- internal LUID_AND_ATTRIBUTES Privilege;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct TOKEN_SOURCE {
- private const int TOKEN_SOURCE_LENGTH = 8;
-
- [MarshalAs(UnmanagedType.ByValArray, SizeConst=TOKEN_SOURCE_LENGTH)]
- internal char[] Name;
- internal LUID SourceIdentifier;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct TOKEN_STATISTICS {
- internal LUID TokenId;
- internal LUID AuthenticationId;
- internal long ExpirationTime;
- internal uint TokenType;
- internal uint ImpersonationLevel;
- internal uint DynamicCharged;
- internal uint DynamicAvailable;
- internal uint GroupCount;
- internal uint PrivilegeCount;
- internal LUID ModifiedId;
- }
-
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
- internal struct TOKEN_USER {
- internal SID_AND_ATTRIBUTES User;
- }
-
- [StructLayout(LayoutKind.Sequential)]
internal struct MEMORYSTATUSEX {
// The length field must be set to the size of this data structure.
internal int length;
@@ -707,18 +457,11 @@ namespace Microsoft.Win32 {
internal const String SHIM = "mscoree.dll";
internal const String CRYPT32 = "crypt32.dll";
internal const String SECUR32 = "secur32.dll";
-#if FEATURE_MAIN_CLR_MODULE_USES_CORE_NAME
internal const String MSCORWKS = "coreclr.dll";
-#else //FEATURE_MAIN_CLR_MODULE_USES_CORE_NAME
- internal const String MSCORWKS = "clr.dll";
-#endif //FEATURE_MAIN_CLR_MODULE_USES_CORE_NAME
// From WinBase.h
internal const int SEM_FAILCRITICALERRORS = 1;
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern void GetSystemInfo(ref SYSTEM_INFO lpSystemInfo);
-
[DllImport(KERNEL32, CharSet=CharSet.Auto, BestFitMapping=true)]
internal static extern int FormatMessage(int dwFlags, IntPtr lpSource,
int dwMessageId, int dwLanguageId, [Out]StringBuilder lpBuffer,
@@ -741,22 +484,13 @@ namespace Microsoft.Win32 {
}
[DllImport(KERNEL32, EntryPoint="LocalAlloc")]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern IntPtr LocalAlloc_NoSafeHandle(int uFlags, UIntPtr sizetdwBytes);
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- SafeLocalAllocHandle LocalAlloc(
- [In] int uFlags,
- [In] UIntPtr sizetdwBytes);
-
[DllImport(KERNEL32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern IntPtr LocalFree(IntPtr handle);
// MSDN says the length is a SIZE_T.
[DllImport(NTDLL, EntryPoint = "RtlZeroMemory")]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern void ZeroMemory(IntPtr address, UIntPtr length);
internal static bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX buffer)
@@ -775,52 +509,11 @@ namespace Microsoft.Win32 {
// the MemoryFailPoint implementation (within a CER) to increase the
// size of the page file, ignoring any host memory allocators.
[DllImport(KERNEL32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
unsafe internal static extern void * VirtualAlloc(void* address, UIntPtr numBytes, int commitOrReserve, int pageProtectionMode);
[DllImport(KERNEL32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
unsafe internal static extern bool VirtualFree(void* address, UIntPtr numBytes, int pageFreeMode);
-
-
- // Note - do NOT use this to call methods. Use P/Invoke, which will
- // do much better things w.r.t. marshaling, pinning memory, security
- // stuff, better interactions with thread aborts, etc. This is used
- // solely by DoesWin32MethodExist for avoiding try/catch EntryPointNotFoundException
- // in scenarios where an OS Version check is insufficient
- [DllImport(KERNEL32, CharSet=CharSet.Ansi, BestFitMapping=false, SetLastError=true, ExactSpelling=true)]
- private static extern IntPtr GetProcAddress(IntPtr hModule, String methodName);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, BestFitMapping=false, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- private static extern IntPtr GetModuleHandle(String moduleName);
-
- internal static bool DoesWin32MethodExist(String moduleName, String methodName)
- {
- // GetModuleHandle does not increment the module's ref count, so we don't need to call FreeLibrary.
- IntPtr hModule = Win32Native.GetModuleHandle(moduleName);
- if (hModule == IntPtr.Zero) {
- BCLDebug.Assert(hModule != IntPtr.Zero, "GetModuleHandle failed. Dll isn't loaded?");
- return false;
- }
- IntPtr functionPointer = Win32Native.GetProcAddress(hModule, methodName);
- return (functionPointer != IntPtr.Zero);
- }
-
- // There is no need to call CloseProcess or to use a SafeHandle if you get the handle
- // using GetCurrentProcess as it returns a pseudohandle
- [DllImport(KERNEL32, SetLastError = true, CallingConvention = CallingConvention.Winapi)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool IsWow64Process(
- [In]
- IntPtr hSourceProcessHandle,
- [Out, MarshalAs(UnmanagedType.Bool)]
- out bool isWow64);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern uint GetTempPath(int bufferLen, [Out]StringBuilder buffer);
-
[DllImport(KERNEL32, CharSet=CharSet.Ansi, ExactSpelling=true, EntryPoint="lstrlenA")]
internal static extern int lstrlenA(IntPtr ptr);
@@ -828,37 +521,23 @@ namespace Microsoft.Win32 {
internal static extern int lstrlenW(IntPtr ptr);
[DllImport(Win32Native.OLEAUT32, CharSet = CharSet.Unicode)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern IntPtr SysAllocStringLen(String src, int len); // BSTR
[DllImport(Win32Native.OLEAUT32)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern uint SysStringLen(IntPtr bstr);
[DllImport(Win32Native.OLEAUT32)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern void SysFreeString(IntPtr bstr);
#if FEATURE_COMINTEROP
[DllImport(Win32Native.OLEAUT32)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern IntPtr SysAllocStringByteLen(byte[] str, uint len); // BSTR
[DllImport(Win32Native.OLEAUT32)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern uint SysStringByteLen(IntPtr bstr);
-#if FEATURE_LEGACYSURFACE
- [DllImport(Win32Native.OLEAUT32)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern uint SysStringLen(SafeBSTRHandle bstr);
#endif
-#endif
-
- [DllImport(KERNEL32)]
- internal static extern int GetACP();
-
[DllImport(KERNEL32, SetLastError=true)]
internal static extern bool SetEvent(SafeWaitHandle handle);
@@ -872,134 +551,24 @@ namespace Microsoft.Win32 {
internal static extern SafeWaitHandle OpenEvent(/* DWORD */ int desiredAccess, bool inheritHandle, String name);
[DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern SafeWaitHandle CreateMutex(SECURITY_ATTRIBUTES lpSecurityAttributes, bool initialOwner, String name);
[DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern SafeWaitHandle OpenMutex(/* DWORD */ int desiredAccess, bool inheritHandle, String name);
[DllImport(KERNEL32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
internal static extern bool ReleaseMutex(SafeWaitHandle handle);
- [DllImport(KERNEL32, SetLastError = true, CharSet = CharSet.Auto, BestFitMapping = false)]
- internal unsafe static extern int GetFullPathName(char* path, int numBufferChars, char* buffer, IntPtr mustBeZero);
-
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal unsafe static extern int GetFullPathName(String path, int numBufferChars, [Out]StringBuilder buffer, IntPtr mustBeZero);
-
- [DllImport(KERNEL32, SetLastError = true, CharSet = CharSet.Auto, BestFitMapping = false)]
- internal unsafe static extern int GetLongPathName(char* path, char* longPathBuffer, int bufferLength);
-
- [DllImport(KERNEL32, SetLastError = true, ExactSpelling = true)]
- internal unsafe static extern uint GetFullPathNameW(char* path, uint numBufferChars, SafeHandle buffer, IntPtr mustBeZero);
-
- [DllImport(KERNEL32, SetLastError = true, CharSet = CharSet.Auto, BestFitMapping = false)]
- internal static extern int GetLongPathName(String path, [Out]StringBuilder longPathBuffer, int bufferLength);
-
- [DllImport(KERNEL32, SetLastError = true, ExactSpelling = true)]
- internal static extern uint GetLongPathNameW(SafeHandle lpszShortPath, SafeHandle lpszLongPath, uint cchBuffer);
-
- [DllImport(KERNEL32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern uint GetLongPathNameW(string lpszShortPath, SafeHandle lpszLongPath, uint cchBuffer);
-
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern SafeFileMappingHandle CreateFileMapping(SafeFileHandle hFile, IntPtr lpAttributes, uint fProtect, uint dwMaximumSizeHigh, uint dwMaximumSizeLow, String lpName);
-
- [DllImport(KERNEL32, SetLastError=true, ExactSpelling=true)]
- internal static extern IntPtr MapViewOfFile(
- SafeFileMappingHandle handle, uint dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow, UIntPtr dwNumerOfBytesToMap);
-
- [DllImport(KERNEL32, ExactSpelling=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern bool UnmapViewOfFile(IntPtr lpBaseAddress );
-
[DllImport(KERNEL32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern bool CloseHandle(IntPtr handle);
- [DllImport(KERNEL32)]
- internal static extern int GetFileType(SafeFileHandle handle);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetEndOfFile(SafeFileHandle hFile);
-
- [DllImport(KERNEL32, SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool FlushFileBuffers(SafeFileHandle hFile);
-
- [DllImport(KERNEL32, SetLastError=true, EntryPoint="SetFilePointer")]
- private unsafe static extern int SetFilePointerWin32(SafeFileHandle handle, int lo, int * hi, int origin);
-
- internal unsafe static long SetFilePointer(SafeFileHandle handle, long offset, System.IO.SeekOrigin origin, out int hr) {
- hr = 0;
- int lo = (int) offset;
- int hi = (int) (offset >> 32);
- lo = SetFilePointerWin32(handle, lo, &hi, (int) origin);
-
- if (lo == -1 && ((hr = Marshal.GetLastWin32Error()) != 0))
- return -1;
- return (long) (((ulong) ((uint) hi)) << 32) | ((uint) lo);
- }
-
- // Note there are two different ReadFile prototypes - this is to use
- // the type system to force you to not trip across a "feature" in
- // Win32's async IO support. You can't do the following three things
- // simultaneously: overlapped IO, free the memory for the overlapped
- // struct in a callback (or an EndRead method called by that callback),
- // and pass in an address for the numBytesRead parameter.
-
- [DllImport(KERNEL32, SetLastError=true)]
- unsafe internal static extern int ReadFile(SafeFileHandle handle, byte* bytes, int numBytesToRead, IntPtr numBytesRead_mustBeZero, NativeOverlapped* overlapped);
-
- [DllImport(KERNEL32, SetLastError=true)]
- unsafe internal static extern int ReadFile(SafeFileHandle handle, byte* bytes, int numBytesToRead, out int numBytesRead, IntPtr mustBeZero);
-
- // Note there are two different WriteFile prototypes - this is to use
- // the type system to force you to not trip across a "feature" in
- // Win32's async IO support. You can't do the following three things
- // simultaneously: overlapped IO, free the memory for the overlapped
- // struct in a callback (or an EndWrite method called by that callback),
- // and pass in an address for the numBytesRead parameter.
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static unsafe extern int WriteFile(SafeFileHandle handle, byte* bytes, int numBytesToWrite, IntPtr numBytesWritten_mustBeZero, NativeOverlapped* lpOverlapped);
-
[DllImport(KERNEL32, SetLastError=true)]
internal static unsafe extern int WriteFile(SafeFileHandle handle, byte* bytes, int numBytesToWrite, out int numBytesWritten, IntPtr mustBeZero);
- // This is only available on Vista or higher
- [DllImport(KERNEL32, SetLastError=true)]
- internal static unsafe extern bool CancelIoEx(SafeFileHandle handle, NativeOverlapped* lpOverlapped);
-
- // NOTE: The out parameters are PULARGE_INTEGERs and may require
- // some byte munging magic.
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
- internal static extern bool GetDiskFreeSpaceEx(String drive, out long freeBytesForUser, out long totalBytes, out long freeBytes);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
- internal static extern int GetDriveType(String drive);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
- internal static extern bool GetVolumeInformation(String drive, [Out]StringBuilder volumeName, int volumeNameBufLen, out int volSerialNumber, out int maxFileNameLen, out int fileSystemFlags, [Out]StringBuilder fileSystemName, int fileSystemNameBufLen);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
- internal static extern bool SetVolumeLabel(String driveLetter, String volumeName);
-
- // The following 4 methods are used by Microsoft.WlcProfile
- [DllImport(KERNEL32)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool QueryPerformanceCounter(out long value);
-
- [DllImport(KERNEL32)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool QueryPerformanceFrequency(out long value);
-
[DllImport(KERNEL32, SetLastError = true, CharSet = CharSet.Auto, BestFitMapping = false)]
internal static extern SafeWaitHandle CreateSemaphore(SECURITY_ATTRIBUTES lpSecurityAttributes, int initialCount, int maximumCount, String name);
[DllImport(KERNEL32, SetLastError = true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool ReleaseSemaphore(SafeWaitHandle handle, int releaseCount, out int previousCount);
@@ -1023,24 +592,8 @@ namespace Microsoft.Win32 {
}
[DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
- internal static extern int GetWindowsDirectory([Out]StringBuilder sb, int length);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
internal static extern int GetSystemDirectory([Out]StringBuilder sb, int length);
- [DllImport(KERNEL32, SetLastError=true)]
- internal unsafe static extern bool SetFileTime(SafeFileHandle hFile, FILE_TIME* creationTime,
- FILE_TIME* lastAccessTime, FILE_TIME* lastWriteTime);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern int GetFileSize(SafeFileHandle hFile, out int highSize);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool LockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool UnlockFile(SafeFileHandle handle, int offsetLow, int offsetHigh, int countLow, int countHigh);
-
internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1); // WinBase.h
// Note, these are #defines used to extract handles, and are NOT handles.
@@ -1188,42 +741,6 @@ namespace Microsoft.Win32 {
internal String cAlternateFileName = null;
}
-#if FEATURE_CORESYSTEM
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- private static extern bool CopyFileEx(String src,
- String dst,
- IntPtr progressRoutine,
- IntPtr progressData,
- ref uint cancel,
- uint flags);
-
- internal static bool CopyFile(String src, String dst, bool failIfExists)
- {
- uint cancel = 0;
- return CopyFileEx(src, dst, IntPtr.Zero, IntPtr.Zero, ref cancel, failIfExists ? 1U : 0U);
- }
-#else // FEATURE_CORESYSTEM
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool CopyFile(
- String src, String dst, bool failIfExists);
-#endif // FEATURE_CORESYSTEM
-
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool CreateDirectory(
- String path, SECURITY_ATTRIBUTES lpSecurityAttributes);
-
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool DeleteFile(String path);
-
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool ReplaceFile(String replacedFileName, String replacementFileName, String backupFileName, int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);
-
- [DllImport(ADVAPI32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool DecryptFile(String path, int reservedMustBeZero);
-
- [DllImport(ADVAPI32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool EncryptFile(String path);
-
[DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern SafeFindHandle FindFirstFile(String fileName, [In, Out] Win32Native.WIN32_FIND_DATA data);
@@ -1234,71 +751,26 @@ namespace Microsoft.Win32 {
WIN32_FIND_DATA lpFindFileData);
[DllImport(KERNEL32)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern bool FindClose(IntPtr handle);
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern int GetCurrentDirectory(
- int nBufferLength,
- [Out]StringBuilder lpBuffer);
-
[DllImport(KERNEL32, SetLastError = true, ExactSpelling = true)]
- internal static extern uint GetCurrentDirectoryW(uint nBufferLength, SafeHandle lpBuffer);
+ internal static extern uint GetCurrentDirectoryW(uint nBufferLength, char[] lpBuffer);
[DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern bool GetFileAttributesEx(String name, int fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation);
[DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool SetFileAttributes(String name, int attr);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern int GetLogicalDrives();
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
- internal static extern uint GetTempFileName(String tmpPath, String prefix, uint uniqueIdOrZero, [Out]StringBuilder tmpFileName);
-
-#if FEATURE_CORESYSTEM
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- private static extern bool MoveFileEx(String src, String dst, uint flags);
-
- internal static bool MoveFile(String src, String dst)
- {
- return MoveFileEx(src, dst, 2 /* MOVEFILE_COPY_ALLOWED */);
- }
-#else // FEATURE_CORESYSTEM
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool MoveFile(String src, String dst);
-#endif // FEATURE_CORESYSTEM
-
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool DeleteVolumeMountPoint(String mountPoint);
-
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern bool RemoveDirectory(String path);
-
- [DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern bool SetCurrentDirectory(String path);
[DllImport(KERNEL32, SetLastError=false, EntryPoint="SetErrorMode", ExactSpelling=true)]
private static extern int SetErrorMode_VistaAndOlder(int newMode);
- [DllImport(KERNEL32, SetLastError=true, EntryPoint="SetThreadErrorMode")]
- private static extern bool SetErrorMode_Win7AndNewer(int newMode, out int oldMode);
-
// RTM versions of Win7 and Windows Server 2008 R2
private static readonly Version ThreadErrorModeMinOsVersion = new Version(6, 1, 7600);
// this method uses the thread-safe version of SetErrorMode on Windows 7 / Windows Server 2008 R2 operating systems.
internal static int SetErrorMode(int newMode)
{
-#if !FEATURE_CORESYSTEM // ARMSTUB
- if (Environment.OSVersion.Version >= ThreadErrorModeMinOsVersion)
- {
- int oldMode;
- SetErrorMode_Win7AndNewer(newMode, out oldMode);
- return oldMode;
- }
-#endif
return SetErrorMode_VistaAndOlder(newMode);
}
@@ -1307,13 +779,6 @@ namespace Microsoft.Win32 {
[DllImport(KERNEL32)]
internal static extern unsafe int WideCharToMultiByte(uint cp, uint flags, char* pwzSource, int cchSource, byte* pbDestBuffer, int cbDestBuffer, IntPtr null1, IntPtr null2);
- // A Win32 HandlerRoutine
- internal delegate bool ConsoleCtrlHandlerRoutine(int controlType);
-
- [DllImport(KERNEL32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern bool SetConsoleCtrlHandler(ConsoleCtrlHandlerRoutine handler, bool addOrRemove);
-
[DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
internal static extern bool SetEnvironmentVariable(string lpName, string lpValue);
@@ -1329,9 +794,6 @@ namespace Microsoft.Win32 {
[DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
internal static extern uint GetCurrentProcessId();
- [DllImport(ADVAPI32, CharSet=CharSet.Auto)]
- internal static extern bool GetUserName([Out]StringBuilder lpBuffer, ref int nSize);
-
[DllImport(KERNEL32, CharSet=CharSet.Auto, BestFitMapping=false)]
internal extern static int GetComputerName([Out]StringBuilder nameBuffer, ref int bufferSize);
@@ -1347,195 +809,7 @@ namespace Microsoft.Win32 {
[DllImport(OLE32)]
internal static extern IntPtr CoTaskMemRealloc(IntPtr pv, UIntPtr cb);
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct COORD
- {
- internal short X;
- internal short Y;
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct SMALL_RECT
- {
- internal short Left;
- internal short Top;
- internal short Right;
- internal short Bottom;
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct CONSOLE_SCREEN_BUFFER_INFO
- {
- internal COORD dwSize;
- internal COORD dwCursorPosition;
- internal short wAttributes;
- internal SMALL_RECT srWindow;
- internal COORD dwMaximumWindowSize;
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct CONSOLE_CURSOR_INFO
- {
- internal int dwSize;
- internal bool bVisible;
- }
-
- // Win32's KEY_EVENT_RECORD
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
- internal struct KeyEventRecord
- {
- internal bool keyDown;
- internal short repeatCount;
- internal short virtualKeyCode;
- internal short virtualScanCode;
- internal char uChar; // Union between WCHAR and ASCII char
- internal int controlKeyState;
- }
-
- // Really, this is a union of KeyEventRecords and other types.
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
- internal struct InputRecord
- {
- internal short eventType;
- internal KeyEventRecord keyEvent;
- // This struct is a union! Word alighment should take care of padding!
- }
-
-[Serializable]
- [Flags]
- internal enum Color : short
- {
- Black = 0,
- ForegroundBlue = 0x1,
- ForegroundGreen = 0x2,
- ForegroundRed = 0x4,
- ForegroundYellow = 0x6,
- ForegroundIntensity = 0x8,
- BackgroundBlue = 0x10,
- BackgroundGreen = 0x20,
- BackgroundRed = 0x40,
- BackgroundYellow = 0x60,
- BackgroundIntensity = 0x80,
-
- ForegroundMask = 0xf,
- BackgroundMask = 0xf0,
- ColorMask = 0xff
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct CHAR_INFO
- {
- ushort charData; // Union between WCHAR and ASCII char
- short attributes;
- }
-
- internal const int ENABLE_PROCESSED_INPUT = 0x0001;
- internal const int ENABLE_LINE_INPUT = 0x0002;
- internal const int ENABLE_ECHO_INPUT = 0x0004;
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int mode);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool Beep(int frequency, int duration);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool GetConsoleScreenBufferInfo(IntPtr hConsoleOutput,
- out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleScreenBufferSize(IntPtr hConsoleOutput, COORD size);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern COORD GetLargestConsoleWindowSize(IntPtr hConsoleOutput);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern bool FillConsoleOutputCharacter(IntPtr hConsoleOutput,
- char character, int nLength, COORD dwWriteCoord, out int pNumCharsWritten);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool FillConsoleOutputAttribute(IntPtr hConsoleOutput,
- short wColorAttribute, int numCells, COORD startCoord, out int pNumBytesWritten);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static unsafe extern bool SetConsoleWindowInfo(IntPtr hConsoleOutput,
- bool absolute, SMALL_RECT* consoleWindow);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, short attributes);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleCursorPosition(IntPtr hConsoleOutput,
- COORD cursorPosition);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool GetConsoleCursorInfo(IntPtr hConsoleOutput,
- out CONSOLE_CURSOR_INFO cci);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleCursorInfo(IntPtr hConsoleOutput,
- ref CONSOLE_CURSOR_INFO cci);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=true)]
- internal static extern bool SetConsoleTitle(String title);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern bool ReadConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern bool PeekConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static unsafe extern bool ReadConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO* pBuffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion);
-
- [DllImport(KERNEL32, CharSet=CharSet.Unicode, SetLastError=true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static unsafe extern bool ReadConsoleW(SafeFileHandle hConsoleInput, Byte* lpBuffer, Int32 nNumberOfCharsToRead, out Int32 lpNumberOfCharsRead, IntPtr pInputControl);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static unsafe extern bool WriteConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO* buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
-
- [DllImport(KERNEL32, CharSet=CharSet.Unicode, SetLastError=true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static unsafe extern bool WriteConsoleW(SafeFileHandle hConsoleOutput, Byte* lpBuffer, Int32 nNumberOfCharsToWrite, out Int32 lpNumberOfCharsWritten, IntPtr lpReservedMustBeNull);
-
- [DllImport(USER32)] // Appears to always succeed
- internal static extern short GetKeyState(int virtualKeyCode);
-
- [DllImport(KERNEL32, SetLastError=false)]
- internal static extern uint GetConsoleCP();
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleCP(uint codePage);
-
- [DllImport(KERNEL32, SetLastError=false)]
- internal static extern uint GetConsoleOutputCP();
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleOutputCP(uint codePage);
-
#if FEATURE_WIN32_REGISTRY
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern int RegConnectRegistry(String machineName,
- SafeRegistryHandle key, out SafeRegistryHandle result);
-
- // Note: RegCreateKeyEx won't set the last error on failure - it returns
- // an error code if it fails.
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern int RegCreateKeyEx(SafeRegistryHandle hKey, String lpSubKey,
- int Reserved, String lpClass, int dwOptions,
- int samDesired, SECURITY_ATTRIBUTES lpSecurityAttributes,
- out SafeRegistryHandle hkResult, out int lpdwDisposition);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern int RegDeleteKey(SafeRegistryHandle hKey, String lpSubKey);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern int RegDeleteKeyEx(SafeRegistryHandle hKey, String lpSubKey,
- int samDesired, int Reserved);
[DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern int RegDeleteValue(SafeRegistryHandle hKey, String lpValueName);
@@ -1552,17 +826,9 @@ namespace Microsoft.Win32 {
IntPtr lpReserved_MustBeZero, int[] lpType, byte[] lpData,
int[] lpcbData);
-
- [DllImport(ADVAPI32)]
- internal static extern int RegFlushKey(SafeRegistryHandle hKey);
-
[DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern int RegOpenKeyEx(SafeRegistryHandle hKey, String lpSubKey,
int ulOptions, int samDesired, out SafeRegistryHandle hkResult);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern int RegOpenKeyEx(IntPtr hKey, String lpSubKey,
- int ulOptions, int samDesired, out SafeRegistryHandle hkResult);
[DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern int RegQueryInfoKey(SafeRegistryHandle hKey, [Out]StringBuilder lpClass,
@@ -1593,11 +859,6 @@ namespace Microsoft.Win32 {
ref int lpcbData);
[DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern int RegQueryValueEx(SafeRegistryHandle hKey, String lpValueName,
- int[] lpReserved, ref int lpType, [Out]StringBuilder lpData,
- ref int lpcbData);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern int RegSetValueEx(SafeRegistryHandle hKey, String lpValueName,
int Reserved, RegistryValueKind dwType, byte[] lpData, int cbData);
@@ -1676,640 +937,11 @@ namespace Microsoft.Win32 {
internal const int CSIDL_MYMUSIC = 0x000d;
internal const int CSIDL_MYPICTURES = 0x0027;
- [DllImport(SHELL32, CharSet=CharSet.Auto, BestFitMapping=false)]
- internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, [Out]StringBuilder lpszPath);
-
internal const int NameSamCompatible = 2;
-
- [DllImport(SECUR32, CharSet=CharSet.Unicode, SetLastError=true)]
- // Win32 return type is BOOLEAN (which is 1 byte and not BOOL which is 4bytes)
- internal static extern byte GetUserNameEx(int format, [Out]StringBuilder domainName, ref uint domainNameLen);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=false)]
- internal static extern bool LookupAccountName(string machineName, string accountName, byte[] sid,
- ref int sidLen, [Out]StringBuilder domainName, ref uint domainNameLen, out int peUse);
-
- // Note: This returns a handle, but it shouldn't be closed. The Avalon
- // team says CloseWindowStation would ignore this handle. So there
- // isn't a lot of value to switching to SafeHandle here.
- [DllImport(USER32, ExactSpelling=true)]
- internal static extern IntPtr GetProcessWindowStation();
-
- [DllImport(USER32, SetLastError=true)]
- internal static extern bool GetUserObjectInformation(IntPtr hObj, int nIndex,
- [MarshalAs(UnmanagedType.LPStruct)] USEROBJECTFLAGS pvBuffer, int nLength, ref int lpnLengthNeeded);
[DllImport(USER32, SetLastError=true, BestFitMapping=false)]
internal static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, String lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);
- [StructLayout(LayoutKind.Sequential)]
- internal class USEROBJECTFLAGS {
- internal int fInherit = 0;
- internal int fReserved = 0;
- internal int dwFlags = 0;
- }
-
- //
- // DPAPI
- //
-
-#if FEATURE_LEGACYSURFACE
- //
- // RtlEncryptMemory and RtlDecryptMemory are declared in the internal header file crypt.h.
- // They were also recently declared in the public header file ntsecapi.h (in the Platform SDK as well as the current build of Server 2003).
- // We use them instead of CryptProtectMemory and CryptUnprotectMemory because
- // they are available in both WinXP and in Windows Server 2003.
- //
-
- [DllImport(Win32Native.ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern
- int SystemFunction040 (
- [In,Out] SafeBSTRHandle pDataIn,
- [In] uint cbDataIn, // multiple of RTL_ENCRYPT_MEMORY_SIZE
- [In] uint dwFlags);
-
- [DllImport(Win32Native.ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- int SystemFunction041 (
- [In,Out] SafeBSTRHandle pDataIn,
- [In] uint cbDataIn, // multiple of RTL_ENCRYPT_MEMORY_SIZE
- [In] uint dwFlags);
-#endif // FEATURE_LEGACYSURFACE
-
- [DllImport(NTDLL, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- int RtlNtStatusToDosError (
- [In] int status);
-
- // Get the current FIPS policy setting on Vista and above
- [DllImport("bcrypt.dll")]
- internal static extern uint BCryptGetFipsAlgorithmMode(
- [MarshalAs(UnmanagedType.U1), Out]out bool pfEnabled);
-
- //
- // Managed ACLs
- //
-
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- [DllImport(ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- bool AdjustTokenPrivileges (
- [In] SafeAccessTokenHandle TokenHandle,
- [In] bool DisableAllPrivileges,
- [In] ref TOKEN_PRIVILEGE NewState,
- [In] uint BufferLength,
- [In,Out] ref TOKEN_PRIVILEGE PreviousState,
- [In,Out] ref uint ReturnLength);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- bool AllocateLocallyUniqueId(
- [In,Out] ref LUID Luid);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- bool CheckTokenMembership(
- [In] SafeAccessTokenHandle TokenHandle,
- [In] byte[] SidToCheck,
- [In,Out] ref bool IsMember);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="ConvertSecurityDescriptorToStringSecurityDescriptorW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL ConvertSdToStringSd(
- byte[] securityDescriptor,
- /* DWORD */ uint requestedRevision,
- ULONG securityInformation,
- out IntPtr resultString,
- ref ULONG resultStringLength );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="ConvertStringSecurityDescriptorToSecurityDescriptorW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL ConvertStringSdToSd(
- string stringSd,
- /* DWORD */ uint stringSdRevision,
- out IntPtr resultSd,
- ref ULONG resultSdLength );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="ConvertStringSidToSidW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL ConvertStringSidToSid(
- string stringSid,
- out IntPtr ByteArray
- );
-
- [DllImport(
- ADVAPI32,
- EntryPoint = "ConvertSidToStringSidW",
- CallingConvention = CallingConvention.Winapi,
- SetLastError = true,
- ExactSpelling = true,
- CharSet = CharSet.Unicode)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool ConvertSidToStringSid(
- IntPtr Sid,
- ref IntPtr StringSid
- );
-
-
- [DllImport(
- ADVAPI32,
- EntryPoint="CreateWellKnownSid",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL CreateWellKnownSid(
- int sidType,
- byte[] domainSid,
- [Out] byte[] resultSid,
- ref /*DWORD*/ uint resultSidLength );
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool DuplicateHandle (
- [In] IntPtr hSourceProcessHandle,
- [In] IntPtr hSourceHandle,
- [In] IntPtr hTargetProcessHandle,
- [In,Out] ref SafeAccessTokenHandle lpTargetHandle,
- [In] uint dwDesiredAccess,
- [In] bool bInheritHandle,
- [In] uint dwOptions);
-
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool DuplicateHandle (
- [In] IntPtr hSourceProcessHandle,
- [In] SafeAccessTokenHandle hSourceHandle,
- [In] IntPtr hTargetProcessHandle,
- [In,Out] ref SafeAccessTokenHandle lpTargetHandle,
- [In] uint dwDesiredAccess,
- [In] bool bInheritHandle,
- [In] uint dwOptions);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="EqualDomainSid",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL IsEqualDomainSid(
- byte[] sid1,
- byte[] sid2,
- out bool result);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern IntPtr GetCurrentProcess();
-
- [DllImport(KERNEL32, CharSet = CharSet.Auto, SetLastError = true)]
- internal static extern IntPtr GetCurrentThread();
-
- [DllImport(
- ADVAPI32,
- EntryPoint="GetSecurityDescriptorLength",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint GetSecurityDescriptorLength(
- IntPtr byteArray );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="GetSecurityInfo",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint GetSecurityInfoByHandle(
- SafeHandle handle,
- /*DWORD*/ uint objectType,
- /*DWORD*/ uint securityInformation,
- out IntPtr sidOwner,
- out IntPtr sidGroup,
- out IntPtr dacl,
- out IntPtr sacl,
- out IntPtr securityDescriptor );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="GetNamedSecurityInfoW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint GetSecurityInfoByName(
- string name,
- /*DWORD*/ uint objectType,
- /*DWORD*/ uint securityInformation,
- out IntPtr sidOwner,
- out IntPtr sidGroup,
- out IntPtr dacl,
- out IntPtr sacl,
- out IntPtr securityDescriptor );
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool GetTokenInformation (
- [In] IntPtr TokenHandle,
- [In] uint TokenInformationClass,
- [In] SafeLocalAllocHandle TokenInformation,
- [In] uint TokenInformationLength,
- [Out] out uint ReturnLength);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool GetTokenInformation (
- [In] SafeAccessTokenHandle TokenHandle,
- [In] uint TokenInformationClass,
- [In] SafeLocalAllocHandle TokenInformation,
- [In] uint TokenInformationLength,
- [Out] out uint ReturnLength);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="GetWindowsAccountDomainSid",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL GetWindowsAccountDomainSid(
- byte[] sid,
- [Out] byte[] resultSid,
- ref /*DWORD*/ uint resultSidLength );
-
- internal enum SECURITY_IMPERSONATION_LEVEL
- {
- Anonymous = 0,
- Identification = 1,
- Impersonation = 2,
- Delegation = 3,
- }
-
- // Structures and definitions for Claims that are being introduced in Win8
- // inside the NTTOken - see winnt.h. They will be surfaced through WindowsIdentity.Claims
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID -> 0x00
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID = 0;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64 -> 0x01
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64 = 1;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64 -> 0x02
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64 = 2;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING -> 0x03
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING = 3;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN -> 0x04
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN = 4;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_SID -> 0x05
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_SID = 5;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN -> 0x06
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN = 6;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING -> 0x10
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING = 16;
-
- // CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE -> 0x0001
- internal const int CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE = 1;
-
- // CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE -> 0x0002
- internal const int CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE = 2;
-
- // CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY -> 0x0004
- internal const int CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY = 4;
-
- // CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT -> 0x0008
- internal const int CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT = 8;
-
- // CLAIM_SECURITY_ATTRIBUTE_DISABLED -> 0x0010
- internal const int CLAIM_SECURITY_ATTRIBUTE_DISABLED = 16;
-
- // CLAIM_SECURITY_ATTRIBUTE_MANDATORY -> 0x0020
- internal const int CLAIM_SECURITY_ATTRIBUTE_MANDATORY = 32;
-
- internal const int CLAIM_SECURITY_ATTRIBUTE_VALID_FLAGS =
- CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE
- | CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE
- | CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY
- | CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT
- | CLAIM_SECURITY_ATTRIBUTE_DISABLED
- | CLAIM_SECURITY_ATTRIBUTE_MANDATORY;
-
-
- [StructLayoutAttribute( LayoutKind.Explicit )]
- internal struct CLAIM_SECURITY_ATTRIBUTE_INFORMATION_V1
- {
- // defined as union in CLAIM_SECURITY_ATTRIBUTES_INFORMATION
- [FieldOffsetAttribute( 0 )]
- public IntPtr pAttributeV1;
- }
-
- [StructLayoutAttribute( LayoutKind.Sequential )]
- internal struct CLAIM_SECURITY_ATTRIBUTES_INFORMATION
- {
- /// WORD->unsigned short
- public ushort Version;
-
- /// WORD->unsigned short
- public ushort Reserved;
-
- /// DWORD->unsigned int
- public uint AttributeCount;
-
- /// CLAIM_SECURITY_ATTRIBUTE_V1
- public CLAIM_SECURITY_ATTRIBUTE_INFORMATION_V1 Attribute;
- }
-
- //
- // Fully-qualified binary name.
- //
- [StructLayoutAttribute( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
- internal struct CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE
- {
- // DWORD64->unsigned __int64
- public ulong Version;
-
- // PWSTR->WCHAR*
- [MarshalAsAttribute( UnmanagedType.LPWStr )]
- public string Name;
- }
-
- [StructLayoutAttribute( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
- internal struct CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE
- {
- /// PVOID->void*
- public IntPtr pValue;
-
- /// DWORD->unsigned int
- public uint ValueLength;
- }
-
- [StructLayoutAttribute( LayoutKind.Explicit, CharSet = CharSet.Unicode )]
- internal struct CLAIM_VALUES_ATTRIBUTE_V1
- {
- // PLONG64->__int64*
- [FieldOffsetAttribute( 0 )]
- public IntPtr pInt64;
-
- // PDWORD64->unsigned __int64*
- [FieldOffsetAttribute( 0 )]
- public IntPtr pUint64;
-
- // PWSTR*
- [FieldOffsetAttribute( 0 )]
- public IntPtr ppString;
-
- // PCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE->_CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE*
- [FieldOffsetAttribute( 0 )]
- public IntPtr pFqbn;
-
- // PCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE->_CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE*
- [FieldOffsetAttribute( 0 )]
- public IntPtr pOctetString;
- }
-
- [StructLayoutAttribute( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
- internal struct CLAIM_SECURITY_ATTRIBUTE_V1
- {
- // PWSTR->WCHAR*
- [MarshalAsAttribute( UnmanagedType.LPWStr )]
- public string Name;
-
- // WORD->unsigned short
- public ushort ValueType;
-
- // WORD->unsigned short
- public ushort Reserved;
-
- // DWORD->unsigned int
- public uint Flags;
-
- // DWORD->unsigned int
- public uint ValueCount;
-
- // struct CLAIM_VALUES - a union of 4 possible values
- public CLAIM_VALUES_ATTRIBUTE_V1 Values;
- }
-
- [DllImport(
- ADVAPI32,
- EntryPoint="IsWellKnownSid",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL IsWellKnownSid(
- byte[] sid,
- int type );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="LsaOpenPolicy",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint LsaOpenPolicy(
- string systemName,
- ref LSA_OBJECT_ATTRIBUTES attributes,
- int accessMask,
- out SafeLsaPolicyHandle handle
- );
-
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- [DllImport(
- ADVAPI32,
- EntryPoint="LookupPrivilegeValueW",
- CharSet=CharSet.Auto,
- SetLastError=true,
- ExactSpelling=true,
- BestFitMapping=false)]
- internal static extern
- bool LookupPrivilegeValue (
- [In] string lpSystemName,
- [In] string lpName,
- [In,Out] ref LUID Luid);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="LsaLookupSids",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint LsaLookupSids(
- SafeLsaPolicyHandle handle,
- int count,
- IntPtr[] sids,
- ref SafeLsaMemoryHandle referencedDomains,
- ref SafeLsaMemoryHandle names
- );
-
- [DllImport(ADVAPI32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern int LsaFreeMemory( IntPtr handle );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="LsaLookupNames",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint LsaLookupNames(
- SafeLsaPolicyHandle handle,
- int count,
- UNICODE_STRING[] names,
- ref SafeLsaMemoryHandle referencedDomains,
- ref SafeLsaMemoryHandle sids
- );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="LsaLookupNames2",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint LsaLookupNames2(
- SafeLsaPolicyHandle handle,
- int flags,
- int count,
- UNICODE_STRING[] names,
- ref SafeLsaMemoryHandle referencedDomains,
- ref SafeLsaMemoryHandle sids
- );
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaConnectUntrusted (
- [In,Out] ref SafeLsaLogonProcessHandle LsaHandle);
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaGetLogonSessionData (
- [In] ref LUID LogonId,
- [In,Out] ref SafeLsaReturnBufferHandle ppLogonSessionData);
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaLogonUser (
- [In] SafeLsaLogonProcessHandle LsaHandle,
- [In] ref UNICODE_INTPTR_STRING OriginName,
- [In] uint LogonType,
- [In] uint AuthenticationPackage,
- [In] IntPtr AuthenticationInformation,
- [In] uint AuthenticationInformationLength,
- [In] IntPtr LocalGroups,
- [In] ref TOKEN_SOURCE SourceContext,
- [In,Out] ref SafeLsaReturnBufferHandle ProfileBuffer,
- [In,Out] ref uint ProfileBufferLength,
- [In,Out] ref LUID LogonId,
- [In,Out] ref SafeAccessTokenHandle Token,
- [In,Out] ref QUOTA_LIMITS Quotas,
- [In,Out] ref int SubStatus);
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaLookupAuthenticationPackage (
- [In] SafeLsaLogonProcessHandle LsaHandle,
- [In] ref UNICODE_INTPTR_STRING PackageName,
- [In,Out] ref uint AuthenticationPackage);
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaRegisterLogonProcess (
- [In] ref UNICODE_INTPTR_STRING LogonProcessName,
- [In,Out] ref SafeLsaLogonProcessHandle LsaHandle,
- [In,Out] ref IntPtr SecurityMode);
-
- [DllImport(SECUR32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern int LsaDeregisterLogonProcess(IntPtr handle);
-
- [DllImport(ADVAPI32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern int LsaClose( IntPtr handle );
-
- [DllImport(SECUR32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern int LsaFreeReturnBuffer(IntPtr handle);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="SetNamedSecurityInfoW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint SetSecurityInfoByName(
- string name,
- /*DWORD*/ uint objectType,
- /*DWORD*/ uint securityInformation,
- byte[] owner,
- byte[] group,
- byte[] dacl,
- byte[] sacl );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="SetSecurityInfo",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint SetSecurityInfoByHandle(
- SafeHandle handle,
- /*DWORD*/ uint objectType,
- /*DWORD*/ uint securityInformation,
- byte[] owner,
- byte[] group,
- byte[] dacl,
- byte[] sacl );
-
- [DllImport(KERNEL32, CharSet=CharSet.Unicode)]
- [SuppressUnmanagedCodeSecurityAttribute()]
- internal unsafe static extern int WideCharToMultiByte(
- int CodePage,
- UInt32 dwFlags,
- char* lpWideCharStr,
- int cchWideChar,
- byte* lpMultiByteStr,
- int cchMultiByte,
- char* lpDefaultChar,
- bool* lpUsedDefaultChar);
-
- [DllImport(KERNEL32, CharSet=CharSet.Unicode)]
- [SuppressUnmanagedCodeSecurityAttribute()]
- internal unsafe static extern int MultiByteToWideChar(
- int CodePage,
- UInt32 dwFlags,
- byte* lpMultiByteStr,
- int cchMultiByte,
- char* lpWideCharStr,
- int cchWideChar);
-
[DllImport(KERNEL32, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal extern static bool QueryUnbiasedInterruptTime(out ulong UnbiasedTime);
@@ -2320,25 +952,6 @@ namespace Microsoft.Win32 {
[Out, MarshalAs(UnmanagedType.LPArray)] byte[] buffer, int length);
#else
private const int BCRYPT_USE_SYSTEM_PREFERRED_RNG = 0x00000002;
-
- [DllImport("BCrypt.dll", CharSet = CharSet.Unicode)]
- private static extern uint BCryptGenRandom(IntPtr hAlgorithm, [In, Out] byte[] pbBuffer, int cbBuffer, int dwFlags);
-
- internal static void Random(bool bStrong, byte[] buffer, int length)
- {
- uint status = BCryptGenRandom(IntPtr.Zero, buffer, length, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
- if (status != STATUS_SUCCESS)
- {
- if (status == STATUS_NO_MEMORY)
- {
- throw new OutOfMemoryException();
- }
- else
- {
- throw new InvalidOperationException();
- }
- }
- }
#endif
}
}