コード例 #1
0
 public override NativeResultCode DeleteValue(RegistryValueRequest request)
 {
     if (IsKnownKey(request))
     {
         try
         {
             var regKey = HostRegistry.OpenKey(request.KeyFullPath, true);
             if (regKey == null)
             {
                 return(NativeResultCode.FileNotFound);
             }
             regKey.DeleteValue(request.Value.Name, true);
             regKey.Close();
             return(NativeResultCode.Success);
         }
         catch (ArgumentException)
         {
             return(NativeResultCode.FileNotFound);
         }
         catch
         {
             return(NativeResultCode.AccessDenied);
         }
     }
     return(NativeResultCode.InvalidHandle);
 }
コード例 #2
0
 public override NativeResultCode OpenKey(RegistryRequest request)
 {
     // Always create a new VirtualRegistryKey, no matter if if one already exists for keyName.
     // Why? There is no counter for the number of users of each handle.
     // => if one user closes the handle, other users won't be able to use it anymore.
     if (HostRegistry.KeyExists(request.KeyFullPath))
     {
         request.Handle = BufferKey(request.KeyFullPath);
         return(NativeResultCode.Success);
     }
     request.Handle = 0;
     return(NativeResultCode.FileNotFound);
 }
コード例 #3
0
        public override NativeResultCode CreateKey(RegistryRequest request, out RegCreationDisposition creationDisposition)
        {
            // Create the key in the real registry.
            var registryKey = HostRegistry.CreateKey(request.KeyFullPath, out creationDisposition);

            if (registryKey != null)
            {
                registryKey.Close();
                request.Handle = BufferKey(request.KeyFullPath);
                return(NativeResultCode.Success);
            }
            request.Handle = 0;
            return(NativeResultCode.AccessDenied);
        }
コード例 #4
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);
        }
コード例 #5
0
 public override NativeResultCode QueryValue(RegistryValueRequest request)
 {
     if (IsKnownKey(request))
     {
         try
         {
             ValueType valueType;
             var       data = HostRegistry.QueryValue(request.KeyFullPath, request.Value.Name, out valueType);
             if (data != null)
             {
                 request.Value = new VirtualRegistryValue(request.Value.Name, data.ToByteArray(), valueType);
                 return(NativeResultCode.Success);
             }
             return(NativeResultCode.FileNotFound);
         }
         catch
         {
             return(NativeResultCode.AccessDenied);
         }
     }
     return(NativeResultCode.InvalidHandle);
 }
コード例 #6
0
        public override NativeResultCode DeleteKey(RegistryRequest request)
        {
            // Overriden, first delete the real key.
            if (HiveHelper.IsHiveHandle(request.Handle))
            {
                return(NativeResultCode.AccessDenied);
            }
            if (!IsKnownKey(request))
            {
                return(NativeResultCode.InvalidHandle);
            }
            var index       = request.KeyFullPath.LastIndexOf(@"\");
            var subKeyName  = request.KeyFullPath.Substring(index + 1);
            var keyFullPath = request.KeyFullPath.Substring(0, index);
            var registryKey = HostRegistry.OpenKey(keyFullPath, true);

            try
            {
                if (registryKey != null)
                {
                    registryKey.DeleteSubKeyTree(subKeyName);
                }
            }
            catch (ArgumentException)
            {
                // Key is not found in real registry, call base to delete it from the buffer.
                base.DeleteKey(request);
                return(NativeResultCode.FileNotFound);
            }
            catch
            {
                return(NativeResultCode.AccessDenied);
            }
            // Real key is deleted, now delete the virtual one.
            return(base.DeleteKey(request));
        }
コード例 #7
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);
        }