Ejemplo n.º 1
0
        /// <summary>
        /// Returns the registry that must be used to handle te specified <see cref="RegistryRequest"/> with.
        /// </summary>
        /// <param name="request">The <see cref="RegistryRequest"/> to get the handling registry for.</param>
        /// <param name="recoverHandle">Indicates whether or not a possible unknown <see cref="RegistryRequest.Handle"/> should be recovered and virtualized.</param>
        /// <returns></returns>
        public RegistryBase GetRegistryFor(RegistryRequest request, bool recoverHandle)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            RegistryBase result = null;

            if (_virtualRegistry.IsKnownKey(request))
            {
                result = _virtualRegistry;
            }
            else if (_transparentRegistry.IsKnownKey(request))
            {
                result = _transparentRegistry;
            }
            else if (HiveHelper.IsHiveHandle(request.Handle))
            {
                request.KeyFullPath = HiveHelper.GetHive(request.Handle).AsRegistryHiveName();
                result = GetDefaultRegistryFor(request);
            }
            else if (recoverHandle)
            {
                // Unknown handle, and allowed to be recovered and virtualized.
                result = TryRecoverUnknownHandle(request);
            }
            else
            {
                EngineCore.Log.Error("Unknown registry key handle => {0}", request.Handle);
            }
            request.VirtualizationType = GetVirtualizationType(request.KeyFullPath);
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tries to recover from an unknown handle.
        /// </summary>
        /// <param name="request">The request for the unknown key handle to try to virtualize.</param>
        /// <returns></returns>
        private RegistryBase TryRecoverUnknownHandle(RegistryRequest request)
        {
            request.KeyFullPath = HostRegistry.GetKeyNameByHandle(request.Handle);
            if (request.KeyFullPath == null)
            {
                EngineCore.Log.Error("Unknown registry key handle => {0}", request.Handle);
                return(null);
            }
            EngineCore.Log.Warning("Recovering from unknown registry key handle => {0} => {1}", request.Handle,
                                   request.KeyFullPath);
            // Teach target about the recovered key handle.
            var       recoveredHandle = request.Handle;
            var       target          = GetDefaultRegistryFor(request);
            Exception error           = null;

            if (target.OpenKey(request) == NativeResultCode.Success)
            {
                try
                {
                    target.AddAlias(request.Handle, recoveredHandle);
                    HostRegistry.CloseKey(recoveredHandle);
                    return(target);
                }
                catch (ApplicationException e)
                {
                    error = e;
                }
            }
            EngineCore.Log.Error("Unable to recover from unknown registry key handle => {0}",
                                 error, request.Handle, request.KeyFullPath);
            return(null);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the <see cref="RegistryBase"/> able to process requests for the given <paramref name="request"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 private RegistryBase GetDefaultRegistryFor(RegistryRequest request)
 {
     request.VirtualizationType = GetVirtualizationType(request.KeyFullPath);
     return(request.VirtualizationType == VirtualizationType.Transparent
        ? _transparentRegistry
        : _virtualRegistry);
 }
Ejemplo n.º 4
0
 public RegistryRequest(RegistryRequest request)
 {
     _accessMechanism = request.VirtualizationType;
     _handle          = request.Handle;
     _hive            = request.Hive;
     _keyFullName     = request.KeyFullName;
     _keyFullPath     = request.KeyFullPath;
 }
 public NativeResultCode OpenKey(uint hKey, string subKeyName, out uint hSubKey)
 {
   var request = new RegistryRequest {Handle = hKey};
   var registry = _switch.GetRegistryFor(request);
   if (registry != null)
   {
     request.KeyFullPath = HostRegistry.CombineKeyNames(request.KeyFullPath, subKeyName);
     var result = registry.OpenKey(request);
     hSubKey = request.Handle;
     return result;
   }
   hSubKey = 0;
   return NativeResultCode.InvalidHandle;
 }
Ejemplo n.º 6
0
        public NativeResultCode DeleteKey(uint hKey)
        {
            if (HiveHelper.IsHiveHandle(hKey))
            {
                return(NativeResultCode.AccessDenied);
            }
            var request = new RegistryRequest {
                Handle = hKey
            };
            var registry = _switch.GetRegistryFor(request);

            return(registry != null
               ? registry.DeleteKey(request)
               : NativeResultCode.InvalidHandle);
        }
Ejemplo n.º 7
0
        public NativeResultCode CloseKey(uint hKey)
        {
            var request = new RegistryRequest {
                Handle = hKey
            };
            var registry = _switch.GetRegistryFor(request, false);

            if (registry != null)
            {
                return(registry.CloseKey(request));
            }
            return(HostRegistry.CloseKey(hKey)
               ? NativeResultCode.Success
               : NativeResultCode.InvalidHandle);
        }
Ejemplo n.º 8
0
        public NativeResultCode OpenKey(uint hKey, string subKeyName, out uint hSubKey)
        {
            var request = new RegistryRequest {
                Handle = hKey
            };
            var registry = _switch.GetRegistryFor(request);

            if (registry != null)
            {
                request.KeyFullPath = HostRegistry.CombineKeyNames(request.KeyFullPath, subKeyName);
                var result = registry.OpenKey(request);
                hSubKey = request.Handle;
                return(result);
            }
            hSubKey = 0;
            return(NativeResultCode.InvalidHandle);
        }
Ejemplo n.º 9
0
        public NativeResultCode CreateKey(uint hKey, string subKeyName, out uint hSubKey, out RegCreationDisposition creationDisposition)
        {
            var request = new RegistryRequest {
                Handle = hKey
            };
            var registry = _switch.GetRegistryFor(request);

            request.KeyFullPath = HostRegistry.CombineKeyNames(request.KeyFullPath, subKeyName);
            if (registry != null)
            {
                var result = registry.CreateKey(request, out creationDisposition);
                hSubKey = request.Handle;
                return(result);
            }
            hSubKey             = 0;
            creationDisposition = RegCreationDisposition.NoKeyCreated;
            return(NativeResultCode.InvalidHandle);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Tries to recover from an unknown handle.
 /// </summary>
 /// <param name="request">The request for the unknown key handle to try to virtualize.</param>
 /// <returns></returns>
 private RegistryBase TryRecoverUnknownHandle(RegistryRequest request)
 {
   request.KeyFullPath = HostRegistry.GetKeyNameByHandle(request.Handle);
   if (request.KeyFullPath == null)
   {
     EngineCore.Log.Error("Unknown registry key handle => {0}", request.Handle);
     return null;
   }
   EngineCore.Log.Warning("Recovering from unknown registry key handle => {0} => {1}", request.Handle,
                         request.KeyFullPath);
   // Teach target about the recovered key handle.
   var recoveredHandle = request.Handle;
   var target = GetDefaultRegistryFor(request);
   Exception error = null;
   if (target.OpenKey(request) == NativeResultCode.Success)
   {
     try
     {
       target.AddAlias(request.Handle, recoveredHandle);
       HostRegistry.CloseKey(recoveredHandle);
       return target;
     }
     catch (ApplicationException e)
     {
       error = e;
     }
   }
   EngineCore.Log.Error("Unable to recover from unknown registry key handle => {0}",
                       error, request.Handle, request.KeyFullPath);
   return null;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Returns the <see cref="RegistryBase"/> able to process requests for the given <paramref name="request"/>.
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 private RegistryBase GetDefaultRegistryFor(RegistryRequest request)
 {
   request.VirtualizationType = GetVirtualizationType(request.KeyFullPath);
   return request.VirtualizationType == VirtualizationType.Transparent
            ? _transparentRegistry
            : _virtualRegistry;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Returns the registry that must be used to handle te specified <see cref="RegistryRequest"/> with.
 /// </summary>
 /// <param name="request">The <see cref="RegistryRequest"/> to get the handling registry for.</param>
 /// <returns></returns>
 public RegistryBase GetRegistryFor(RegistryRequest request)
 {
     return(GetRegistryFor(request, true));
 }
Ejemplo n.º 13
0
 public NativeResultCode DeleteKey(uint hKey)
 {
   if (HiveHelper.IsHiveHandle(hKey))
     return NativeResultCode.AccessDenied;
   var request = new RegistryRequest {Handle = hKey};
   var registry = _switch.GetRegistryFor(request);
   return registry != null
            ? registry.DeleteKey(request)
            : NativeResultCode.InvalidHandle;
 }
Ejemplo n.º 14
0
 public NativeResultCode CreateKey(uint hKey, string subKeyName, out uint hSubKey, out RegCreationDisposition creationDisposition)
 {
   var request = new RegistryRequest { Handle = hKey };
   var registry = _switch.GetRegistryFor(request);
   request.KeyFullPath = HostRegistry.CombineKeyNames(request.KeyFullPath, subKeyName);
   if (registry != null)
   {
     var result = registry.CreateKey(request, out creationDisposition);
     hSubKey = request.Handle;
     return result;
   }
   hSubKey = 0;
   creationDisposition = RegCreationDisposition.NoKeyCreated;
   return NativeResultCode.InvalidHandle;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Returns the registry that must be used to handle te specified <see cref="RegistryRequest"/> with.
 /// </summary>
 /// <param name="request">The <see cref="RegistryRequest"/> to get the handling registry for.</param>
 /// <returns></returns>
 public RegistryBase GetRegistryFor(RegistryRequest request)
 {
   return GetRegistryFor(request, true);
 }
Ejemplo n.º 16
0
 public RegistryRequest(RegistryRequest request)
 {
   _accessMechanism = request.VirtualizationType;
   _handle = request.Handle;
   _hive = request.Hive;
   _keyFullName = request.KeyFullName;
   _keyFullPath = request.KeyFullPath;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Returns the registry that must be used to handle te specified <see cref="RegistryRequest"/> with.
 /// </summary>
 /// <param name="request">The <see cref="RegistryRequest"/> to get the handling registry for.</param>
 /// <param name="recoverHandle">Indicates whether or not a possible unknown <see cref="RegistryRequest.Handle"/> should be recovered and virtualized.</param>
 /// <returns></returns>
 public RegistryBase GetRegistryFor(RegistryRequest request, bool recoverHandle)
 {
   if (request == null)
     throw new ArgumentNullException("request");
   RegistryBase result = null;
   if (_virtualRegistry.IsKnownKey(request))
     result = _virtualRegistry;
   else if (_transparentRegistry.IsKnownKey(request))
     result = _transparentRegistry;
   else if (HiveHelper.IsHiveHandle(request.Handle))
   {
     request.KeyFullPath = HiveHelper.GetHive(request.Handle).AsRegistryHiveName();
     result = GetDefaultRegistryFor(request);
   }
   else if (recoverHandle)
     // Unknown handle, and allowed to be recovered and virtualized.
     result = TryRecoverUnknownHandle(request);
   else
     EngineCore.Log.Error("Unknown registry key handle => {0}", request.Handle);
   request.VirtualizationType = GetVirtualizationType(request.KeyFullPath);
   return result;
 }
Ejemplo n.º 18
0
 public NativeResultCode CloseKey(uint hKey)
 {
   var request = new RegistryRequest {Handle = hKey};
   var registry = _switch.GetRegistryFor(request, false);
   if (registry != null)
     return registry.CloseKey(request);
   return HostRegistry.CloseKey(hKey)
            ? NativeResultCode.Success
            : NativeResultCode.InvalidHandle;
 }