Esempio n. 1
0
 /// <summary>
 /// Duplicate an instance from a process
 /// </summary>
 /// <param name="process">The process (with DupHandle access)</param>
 /// <param name="handle">The handle value to duplicate</param>
 /// <param name="access">The access rights to duplicate with</param>
 /// <param name="options">The options for duplication.</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 <O> DuplicateFrom(NtProcess process, IntPtr handle,
                                          A access, DuplicateObjectOptions options, bool throw_on_error)
 {
     return(NtObject.DuplicateHandle(process, new SafeKernelObjectHandle(handle, false),
                                     NtProcess.Current, ToGenericAccess(access), AttributeFlags.None,
                                     options, throw_on_error).Map(h => FromHandle(h)));
 }
Esempio n. 2
0
 /// <summary>
 /// Duplicate an instance from a process to an other process
 /// </summary>
 /// <param name="src_process">The source process (with DupHandle access)</param>
 /// <param name="handle">The handle value to duplicate</param>
 /// <param name="dst_process">The destination process (with DupHandle access)</param>
 /// <param name="access">The access rights to duplicate with</param>
 /// <param name="options">The options for duplication.</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 <IntPtr> DuplicateTo(NtProcess src_process, IntPtr handle, NtProcess dst_process,
                                             A access, DuplicateObjectOptions options, bool throw_on_error)
 {
     return(NtObject.DuplicateHandle(src_process, handle,
                                     dst_process, ToGenericAccess(access), AttributeFlags.None,
                                     options, throw_on_error));
 }
Esempio n. 3
0
 /// <summary>
 /// Create a .NET wait handle from an object.
 /// </summary>
 /// <param name="obj">The object to create the wait handle on</param>
 internal NtWaitHandle(NtObject obj)
 {
     using (SafeKernelObjectHandle handle = NtObject.DuplicateHandle(obj.Handle)) {
         SafeWaitHandle = new SafeWaitHandle(handle.DangerousGetHandle(), true);
         handle.SetHandleAsInvalid();
     }
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="object_name">The object name, can be null.</param>
        /// <param name="attributes">The object attribute flags.</param>
        /// <param name="root">An optional root handle, can be SafeKernelObjectHandle.Null. Will duplicate the handle.</param>
        /// <param name="sqos">An optional security quality of service.</param>
        /// <param name="security_descriptor">An optional security descriptor.</param>
        public ObjectAttributes(string object_name, AttributeFlags attributes, SafeKernelObjectHandle root,
                                SecurityQualityOfService sqos, SecurityDescriptor security_descriptor)
        {
            Length = Marshal.SizeOf(this);
            if (object_name != null)
            {
                ObjectName = new UnicodeString(object_name).ToBuffer();
            }
            else
            {
                ObjectName = SafeHGlobalBuffer.Null;
            }

            Attributes = attributes;
            if (sqos != null)
            {
                SecurityQualityOfService = sqos.ToBuffer();
            }
            else
            {
                SecurityQualityOfService = SafeHGlobalBuffer.Null;
            }

            RootDirectory = !root.IsInvalid ? NtObject.DuplicateHandle(root) : SafeKernelObjectHandle.Null;
            if (security_descriptor != null)
            {
                SecurityDescriptor = security_descriptor.ToSafeBuffer();
            }
            else
            {
                SecurityDescriptor = SafeHGlobalBuffer.Null;
            }
        }
Esempio n. 5
0
        private ObjectAttributes(SafeBuffer object_name, AttributeFlags attributes, SafeKernelObjectHandle root,
                                 SecurityQualityOfService sqos, SecurityDescriptor security_descriptor)
        {
            try {
                if (root == null)
                {
                    throw new ArgumentNullException(nameof(root), "Use SafeKernelObjectHandle.Null for a null handle");
                }
                Length     = Marshal.SizeOf(this);
                ObjectName = object_name;
                Attributes = attributes;
                if (sqos != null)
                {
                    SecurityQualityOfService = sqos.ToBuffer();
                }
                else
                {
                    SecurityQualityOfService = SafeHGlobalBuffer.Null;
                }

                RootDirectory = !root.IsInvalid ? NtObject.DuplicateHandle(root) : SafeKernelObjectHandle.Null;
                if (security_descriptor != null)
                {
                    SecurityDescriptor = security_descriptor.ToSafeBuffer();
                }
                else
                {
                    SecurityDescriptor = SafeHGlobalBuffer.Null;
                }
            } catch {
                Dispose();
                throw;
            }
        }
Esempio n. 6
0
 internal NtEnclaveVBS(SafeEnclaveHandle handle, SafeKernelObjectHandle process)
     : base(handle, LdrEnclaveType.VBS)
 {
     _process = process.PseudoHandle ? process : NtObject.DuplicateHandle(process);
 }
Esempio n. 7
0
 /// <summary>
 /// Duplicate an instance from a process with same access rights.
 /// </summary>
 /// <param name="process">The process (with DupHandle access)</param>
 /// <param name="handle">The handle value to duplicate</param>
 /// <returns>The duplicated handle</returns>
 public static O DuplicateFrom(NtProcess process, IntPtr handle)
 {
     return(FromHandle(NtObject.DuplicateHandle(process, new SafeKernelObjectHandle(handle, false), NtProcess.Current)));
 }
Esempio n. 8
0
 /// <summary>
 /// Duplicate an instance from a process
 /// </summary>
 /// <param name="process">The process (with DupHandle access)</param>
 /// <param name="handle">The handle value to duplicate</param>
 /// <param name="access">The access rights to duplicate with</param>
 /// <returns>The duplicated handle</returns>
 public static O DuplicateFrom(NtProcess process, IntPtr handle, A access)
 {
     return(FromHandle(NtObject.DuplicateHandle(process, new SafeKernelObjectHandle(handle, false), NtProcess.Current, (GenericAccessRights)access.ToUInt32(null))));
 }
Esempio n. 9
0
 public static ProcessAttribute HandleList(IEnumerable <SafeHandle> handles)
 {
     return(new ProcessAttribute(ProcessAttributeNum.HandleList, false, true, false,
                                 new SafeHandleListHandle(handles.Select(h => NtObject.DuplicateHandle(h.ToSafeKernelHandle())))));
 }
Esempio n. 10
0
 public static ProcessAttribute Token(SafeKernelObjectHandle token)
 {
     return(new ProcessAttribute(ProcessAttributeNum.Token,
                                 false, true, true, NtObject.DuplicateHandle(token)));
 }
Esempio n. 11
0
 public static ProcessAttribute ParentProcess(SafeKernelObjectHandle parent_process)
 {
     return(new ProcessAttribute(ProcessAttributeNum.ParentProcess,
                                 false, true, true, NtObject.DuplicateHandle(parent_process)));
 }
 public static ProcessAttribute DebugPort(SafeKernelObjectHandle debug_port)
 {
     return(new ProcessAttribute(ProcessAttributeNum.DebugPort,
                                 false, true, true, NtObject.DuplicateHandle(debug_port)));
 }
 public static SafeHandleListHandle CreateAndDuplicate(IEnumerable <SafeKernelObjectHandle> handles)
 {
     return(new SafeHandleListHandle(handles.Select(h => NtObject.DuplicateHandle(h)).ToArray()));
 }