/// <summary> /// Initialize a Silo to a Server Silo. /// </summary> /// <param name="delete_event">Event to signal when silo deleted.</param> /// <param name="downlevel_container">True if a downlevel container.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The NT status code.</returns> /// <remarks>You must have set a system root and added a \Device directory (which shadows the real directory) to the silo object directory.</remarks> public NtStatus InitializeServerSilo(NtEvent delete_event, bool downlevel_container, bool throw_on_error) { ServerSiloInitInformation init = new ServerSiloInitInformation() { DeleteEvent = delete_event?.Handle.DangerousGetHandle() ?? IntPtr.Zero, IsDownlevelContainer = downlevel_container }; return(Set(JobObjectInformationClass.JobObjectServerSiloInitialize, init, throw_on_error)); }
internal NtAsyncResult(NtObject @object) { _object = @object; if (!_object.CanSynchronize) { _event = NtEvent.Create(null, EventType.SynchronizationEvent, false); } _io_status = new SafeIoStatusBuffer(); _result = null; }
/// <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> /// Initialize a Silo to a Server Silo. /// </summary> /// <param name="delete_event">Event to signal when silo deleted.</param> /// <param name="downlevel_container">True if a downlevel container.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The NT status code.</returns> /// <remarks>You must have set a system root and added a \Device directory (which shadows the real directory) to the silo object directory.</remarks> public NtStatus InitializeServerSilo(NtEvent delete_event, bool downlevel_container, bool throw_on_error) { IntPtr event_handle = delete_event?.Handle.DangerousGetHandle() ?? IntPtr.Zero; ServerSiloInitInformation init = new ServerSiloInitInformation() { DeleteEvent = event_handle, IsDownlevelContainer = downlevel_container }; var status = Set(JobObjectInformationClass.JobObjectServerSiloInitialize, init, false); if (!status.IsSuccess()) { if (status != NtStatus.STATUS_INFO_LENGTH_MISMATCH) { return(status.ToNtException(throw_on_error)); } return(Set(JobObjectInformationClass.JobObjectServerSiloInitialize, event_handle, throw_on_error)); } return(status); }
protected override sealed NtResult <NtEvent> OpenInternal(ObjectAttributes obj_attributes, EventAccessRights desired_access, bool throw_on_error) { return(NtEvent.Open(obj_attributes, desired_access, throw_on_error)); }
/// <summary> /// Initialize a Silo to a Server Silo. /// </summary> /// <param name="delete_event">Event to signal when silo deleted.</param> /// <param name="downlevel_container">True if a downlevel container.</param> /// <returns>The NT status code.</returns> public void InitializeServerSilo(NtEvent delete_event, bool downlevel_container) { InitializeServerSilo(delete_event, downlevel_container, true); }
/// <summary> /// Create and initialize a Server Silo, /// </summary> /// <param name="root_dir_flags">Flags for root directory.</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 NtJob CreateServerSilo(SiloObjectRootDirectoryControlFlags root_dir_flags, string system_root, NtEvent delete_event, bool downlevel_container) { return(CreateServerSilo(root_dir_flags, system_root, delete_event, downlevel_container, true).Result); }
/// <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> /// Constructor. /// </summary> /// <param name="event_object">The event object.</param> public AlpcDirectMessageAttribute(NtEvent event_object) : base(AlpcMessageAttributeFlags.Direct) { Event = event_object.Duplicate(); }