internal ObjectDirectoryInformation(NtDirectory root, string base_path, string name, string typename) { _root = root; Name = name; NtTypeName = typename; FullPath = String.Format(@"{0}\{1}", base_path, Name); }
internal ObjectDirectoryInformation(NtDirectory root, string base_path, string name, string typename) { _root = root; Name = name; NtTypeName = typename; FullPath = $@"{base_path}\{Name}"; }
/// <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> /// <param name="attributes">Attributes to open the object.</param> /// <param name="security_quality_of_service">Security quality of service.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The opened object.</returns> /// <exception cref="NtException">Thrown if an error occurred opening the object.</exception> public static NtResult <NtObject> OpenWithType(string typename, string path, NtObject root, AttributeFlags attributes, AccessMask access, SecurityQualityOfService security_quality_of_service, bool throw_on_error) { using (var obj_attr = new ObjectAttributes(path, attributes, root, security_quality_of_service, null)) { if (typename == null) { typename = NtDirectory.GetDirectoryEntryType(path, root); } // Brute force the open. if (typename == null) { foreach (var nttype in NtType.GetTypes().Where(t => t.CanOpen)) { var result = nttype.Open(obj_attr, access, false); if (result.IsSuccess) { return(result); } } return(NtStatus.STATUS_OBJECT_TYPE_MISMATCH.CreateResultFromError <NtObject>(true)); } NtType type = NtType.GetTypeByName(typename, false); if (type != null && type.CanOpen) { return(type.Open(obj_attr, access, throw_on_error)); } else { return(NtStatus.STATUS_OBJECT_TYPE_MISMATCH.CreateResultFromError <NtObject>(true)); } } }
/// <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> /// <param name="attributes">Attributes to open the object.</param> /// <param name="security_quality_of_service">Security quality of service.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The opened object.</returns> /// <exception cref="NtException">Thrown if an error occurred opening the object.</exception> public static NtResult <NtObject> OpenWithType(string typename, string path, NtObject root, AttributeFlags attributes, AccessMask access, SecurityQualityOfService security_quality_of_service, bool throw_on_error) { using (var obj_attr = new ObjectAttributes(path, attributes, root, security_quality_of_service, null)) { NtType type = NtType.GetTypeByName(typename ?? NtDirectory.GetDirectoryEntryType(path, root), false); return(OpenWithType(type, obj_attr, access, throw_on_error)); } }
/// <summary> /// Create and initialize a Server Silo, /// </summary> /// <param name="root_dir_flags">Flags for root directory.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <param name="system_root">Path to the system root.</param> /// <param name="delete_event">Event to signal when silo deleted.</param> /// <param name="downlevel_container">True if a downlevel container.</param> /// <returns>The Job object.</returns> public static NtResult <NtJob> CreateServerSilo(SiloObjectRootDirectoryControlFlags root_dir_flags, string system_root, NtEvent delete_event, bool downlevel_container, bool throw_on_error) { using (var job = CreateSilo(root_dir_flags, throw_on_error)) { if (!job.IsSuccess) { return(job); } NtStatus status = job.Result.SetSiloSystemRoot(system_root, throw_on_error); if (!status.IsSuccess()) { return(status.CreateResultFromError <NtJob>(throw_on_error)); } var silo_dir = job.Result.QuerySiloRootDirectory(throw_on_error); if (!silo_dir.IsSuccess) { return(silo_dir.Cast <NtJob>()); } string device_path = $@"{silo_dir.Result}\Device"; using (var device_dir = NtDirectory.Open(@"\Device", null, DirectoryAccessRights.MaximumAllowed, throw_on_error)) { if (!device_dir.IsSuccess) { return(device_dir.Cast <NtJob>()); } using (var obja = new ObjectAttributes(device_path, AttributeFlags.CaseInsensitive | AttributeFlags.Permanent | AttributeFlags.OpenIf)) { using (var dir = NtDirectory.Create(obja, DirectoryAccessRights.MaximumAllowed, device_dir.Result, throw_on_error)) { if (!dir.IsSuccess) { return(dir.Cast <NtJob>()); } } } } status = job.Result.InitializeServerSilo(delete_event, downlevel_container, throw_on_error); if (!status.IsSuccess()) { return(status.CreateResultFromError <NtJob>(throw_on_error)); } return(job.Result.Duplicate().CreateResult()); } }
/// <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)); } }
/// <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, AccessMask 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)); } } NtType type = NtType.GetTypeByName(typename, false); if (type != null && type.CanOpen) { return(type.Open(path, root, access)); } else { throw new ArgumentException(String.Format("Can't open type {0}", typename)); } }
/// <summary> /// Get the NT type from a path. /// </summary> /// <param name="path">The object manager path.</param> /// <param name="root">Optional root object.</param> /// <returns>The NT type. Returns null if not available or unknown.</returns> public static NtType GetTypeFromPath(string path, NtObject root) { NtType type = root?.NtType; // If a file or a key root then that's what the target must end up being. switch (type?.Name) { case "File": case "Key": return(type); } string type_name = NtDirectory.GetDirectoryEntryType(path, root); if (type_name != null) { return(GetTypeByName(type_name, true)); } string full_path = path; if (root != null) { string root_path = root.FullPath; full_path = $@"{(root_path == @"\" ? string.Empty : root_path)}\{full_path}"; } if (full_path.Equals(@"\REGISTRY", StringComparison.OrdinalIgnoreCase) || full_path.StartsWith(@"\REGISTRY\", StringComparison.OrdinalIgnoreCase)) { return(GetTypeByType <NtKey>()); } if (full_path.StartsWith(@"\??\") || full_path.StartsWith(@"\GLOBAL??\", StringComparison.OrdinalIgnoreCase) || full_path.StartsWith(@"\Device\", StringComparison.OrdinalIgnoreCase)) { return(GetTypeByType <NtFile>()); } return(null); }
internal ObjectDirectoryInformation(NtDirectory root, string base_path, OBJECT_DIRECTORY_INFORMATION info) : this(root, base_path, info.Name.ToString(), info.TypeName.ToString()) { }
protected override sealed NtResult <NtDirectory> OpenInternal(ObjectAttributes obj_attributes, DirectoryAccessRights desired_access, bool throw_on_error) { return(NtDirectory.Open(obj_attributes, desired_access, throw_on_error)); }
public ObjectDirectoryInformation(NtDirectory root, string name, string typename) { _root = root; Name = name; TypeName = typename; }