예제 #1
0
        /// <summary>
        /// Open an NT object with a specified type.
        /// </summary>
        /// <param name="typename">The name of the type to open (e.g. Event). If null the method will try and lookup the appropriate type.</param>
        /// <param name="path">The path to the object to open.</param>
        /// <param name="root">A root directory to open from.</param>
        /// <param name="access">Generic access rights to the object.</param>
        /// <returns>The opened object.</returns>
        /// <exception cref="NtException">Thrown if an error occurred opening the object.</exception>
        /// <exception cref="ArgumentException">Thrown if type of resource couldn't be found.</exception>
        public static NtObject OpenWithType(string typename, string path, NtObject root, GenericAccessRights access)
        {
            if (typename == null)
            {
                typename = NtDirectory.GetDirectoryEntryType(path, root);
                if (typename == null)
                {
                    throw new ArgumentException(String.Format("Can't find type for path {0}", path));
                }
            }

            switch (typename.ToLower())
            {
            case "device":
                return(NtFile.Open(path, root, (FileAccessRights)access, FileShareMode.None, FileOpenOptions.None));

            case "file":
                return(NtFile.Open(path, root, (FileAccessRights)access, FileShareMode.Read | FileShareMode.Write | FileShareMode.Delete, FileOpenOptions.None));

            case "event":
                return(NtEvent.Open(path, root, (EventAccessRights)access));

            case "directory":
                return(NtDirectory.Open(path, root, (DirectoryAccessRights)access));

            case "symboliclink":
                return(NtSymbolicLink.Open(path, root, (SymbolicLinkAccessRights)access));

            case "mutant":
                return(NtMutant.Open(path, root, (MutantAccessRights)access));

            case "semaphore":
                return(NtSemaphore.Open(path, root, (SemaphoreAccessRights)access));

            case "section":
                return(NtSection.Open(path, root, (SectionAccessRights)access));

            case "job":
                return(NtJob.Open(path, root, (JobAccessRights)access));

            case "key":
                return(NtKey.Open(path, root, (KeyAccessRights)access));

            default:
                throw new ArgumentException(String.Format("Can't open type {0}", typename));
            }
        }
예제 #2
0
파일: NtMutant.cs 프로젝트: codehz/winsilo
 protected override sealed NtResult <NtMutant> OpenInternal(ObjectAttributes obj_attributes,
                                                            MutantAccessRights desired_access, bool throw_on_error)
 {
     return(NtMutant.Open(obj_attributes, desired_access, throw_on_error));
 }