Esempio n. 1
0
        public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition)
        {
            var virtualKeyPath = RegistryTranslator.ToVirtualPath(request.KeyFullPath);
            var virtReq        = new RegistryRequest(request)
            {
                KeyFullPath = virtualKeyPath
            };
            var result = base.CreateKey(virtReq, out creationDisposition);

            request.Handle = virtReq.Handle;
            return(result);
        }
Esempio n. 2
0
        public override NativeResultCode QueryValue(RegistryValueRequest request)
        {
            var resultCode = base.QueryValue(request);

            if (resultCode != NativeResultCode.FileNotFound)
            {
                return(resultCode);             // Base knows the value
            }
            if (!IsKnownKey(request))
            {
                return(NativeResultCode.InvalidHandle); // Base does not know the handle
            }
            if (request.VirtualizationType == VirtualizationType.Virtual)
            {
                return(NativeResultCode.FileNotFound); // Not allowed to retrieve value from host registry
            }
            // Query the value from the real registry.
            try
            {
                ValueType valueType;
                var       realKeyPath = RegistryTranslator.ToRealPath(request.KeyFullPath);
                var       data        = HostRegistry.QueryValue(realKeyPath, request.Value.Name, out valueType);
                if (data == null)
                {
                    return(NativeResultCode.FileNotFound);
                }
                request.Value = new VirtualRegistryValue(request.Value.Name, data.ToByteArray(), valueType);
            }
            catch
            {
                return(NativeResultCode.AccessDenied);
            }
            // Determine whether the newly acquired value needs to be written to the base.
            if (request.VirtualizationType < VirtualizationType.TransparentRead)
            {
                var key = new VirtualRegistryKey(request.Handle, request.KeyFullPath);
                key.Values.Add(request.Value.Name, request.Value);
                WriteKey(key, false);
            }
            return(NativeResultCode.Success);
        }
Esempio n. 3
0
        public override NativeResultCode OpenKey(RegistryRequest request)
        {
            var virtualKeyPath = RegistryTranslator.ToVirtualPath(request.KeyFullPath);
            var virtReq        = new RegistryRequest(request)
            {
                KeyFullPath = virtualKeyPath
            };

            if (base.OpenKey(virtReq) == NativeResultCode.Success)
            {
                request.Handle = virtReq.Handle;
                return(NativeResultCode.Success);
            }
            if (request.VirtualizationType == VirtualizationType.Virtual ||
                !HostRegistry.KeyExists(request.KeyFullPath))
            {
                return(NativeResultCode.FileNotFound);
            }
            var virtualRegistryKey = ConstructRegistryKey(virtualKeyPath);

            WriteKey(virtualRegistryKey, true);
            request.Handle = virtualRegistryKey.Handle;
            return(NativeResultCode.Success);
        }