Exemple #1
0
        /// <summary>
        /// Load a new hive
        /// </summary>
        /// <param name="key">Object attributes for the key name</param>
        /// <param name="file">Object attributes for the path to the hive file</param>
        /// <param name="flags">Load flags</param>
        /// <param name="desired_access">Desired access for the root key</param>
        /// <returns>The opened root key</returns>
        /// <exception cref="NtException">Thrown on error.</exception>
        public static NtKey LoadKey(ObjectAttributes key, ObjectAttributes file, LoadKeyFlags flags, KeyAccessRights desired_access)
        {
            SafeKernelObjectHandle key_handle;

            NtSystemCalls.NtLoadKeyEx(key, file, flags,
                                      IntPtr.Zero, IntPtr.Zero, desired_access, out key_handle, 0).ToNtException();
            return(new NtKey(key_handle));
        }
Exemple #2
0
        /// <summary>
        /// Load a new hive
        /// </summary>
        /// <param name="key_obj_attr">Object attributes for the key name</param>
        /// <param name="file_obj_attr">Object attributes for the path to the hive file</param>
        /// <param name="flags">Load flags</param>
        /// <param name="desired_access">Desired access for the root key</param>
        /// <param name="throw_on_error">True to throw an exception on error.</param>
        /// <returns>The NT status code and object result.</returns>
        public static NtResult <NtKey> LoadKey(ObjectAttributes key_obj_attr, ObjectAttributes file_obj_attr,
                                               LoadKeyFlags flags, KeyAccessRights desired_access, bool throw_on_error)
        {
            SafeKernelObjectHandle key_handle;

            return(NtSystemCalls.NtLoadKeyEx(key_obj_attr, file_obj_attr, flags,
                                             IntPtr.Zero, IntPtr.Zero, desired_access, out key_handle, 0)
                   .CreateResult(throw_on_error, () => new NtKey(key_handle, KeyDisposition.OpenedExistingKey)));
        }
Exemple #3
0
 /// <summary>
 /// Load a new hive
 /// </summary>
 /// <param name="destination">The destination path</param>
 /// <param name="filename">The path to the hive</param>
 /// <param name="flags">Load flags</param>
 /// <returns>The opened root key</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static NtKey LoadKey(string destination, string filename, LoadKeyFlags flags)
 {
     using (ObjectAttributes dest = new ObjectAttributes(destination, AttributeFlags.CaseInsensitive))
     {
         using (ObjectAttributes name = new ObjectAttributes(filename, AttributeFlags.CaseInsensitive))
         {
             return(LoadKey(dest, name, flags, KeyAccessRights.MaximumAllowed));
         }
     }
 }
Exemple #4
0
        static RegistryKey LoadKey(string path, bool read_only)
        {
            string             reg_name = @"\Registry\A\" + Guid.NewGuid().ToString("B");
            ObjectAttributes   KeyName  = new ObjectAttributes(reg_name);
            ObjectAttributes   FileName = new ObjectAttributes(@"\??\" + path);
            SafeRegistryHandle keyHandle;
            LoadKeyFlags       flags = LoadKeyFlags.AppKey;

            if (read_only)
            {
                flags |= LoadKeyFlags.ReadOnly;
            }

            int status = NtLoadKeyEx(KeyName,
                                     FileName, flags, IntPtr.Zero,
                                     IntPtr.Zero, GenericAccessRights.GenericRead, out keyHandle, 0);

            if (status != 0)
            {
                return(null);
            }
            return(RegistryKey.FromHandle(keyHandle));
        }
Exemple #5
0
 public static extern NtStatus NtLoadKey3([In] ObjectAttributes DestinationName, [In] ObjectAttributes FileName, LoadKeyFlags Flags,
                                          [In, MarshalAs(UnmanagedType.LPArray)] KeyLoadArgument[] LoadArguments, int LoadArgumentCount, KeyAccessRights DesiredAccess, IntPtr KeyHandle, int Unused);
Exemple #6
0
 public static extern NtStatus NtLoadKeyEx([In] ObjectAttributes DestinationName, [In] ObjectAttributes FileName, LoadKeyFlags Flags,
                                           IntPtr TrustKeyHandle, IntPtr EventHandle, KeyAccessRights DesiredAccess, IntPtr KeyHandle, int Unused);
 public static extern int NtLoadKeyEx(ObjectAttributes DestinationName, ObjectAttributes FileName, LoadKeyFlags Flags,
     IntPtr TrustKeyHandle, IntPtr EventHandle, GenericAccessRights DesiredAccess, out SafeRegistryHandle KeyHandle, int Unused);
Exemple #8
0
 public static extern int NtLoadKeyEx(ObjectAttributes DestinationName, ObjectAttributes FileName, LoadKeyFlags Flags,
                                      IntPtr TrustKeyHandle, IntPtr EventHandle, GenericAccessRights DesiredAccess, out SafeRegistryHandle KeyHandle, int Unused);
Exemple #9
0
 /// <summary>
 /// Load a new hive
 /// </summary>
 /// <param name="key_obj_attr">Object attributes for the key name</param>
 /// <param name="file_obj_attr">Object attributes for the path to the hive file</param>
 /// <param name="flags">Load flags</param>
 /// <param name="desired_access">Desired access for the root key</param>
 /// <returns>The opened root key</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static NtKey LoadKey(ObjectAttributes key_obj_attr, ObjectAttributes file_obj_attr, LoadKeyFlags flags, KeyAccessRights desired_access)
 {
     return(LoadKey(key_obj_attr, file_obj_attr, flags, desired_access, true).Result);
 }