Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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);
        }