예제 #1
0
        public static MailslotHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            NativeHandle rootDirectory,
            int quota,
            int maxMessageSize,
            long readTimeout,
            FileCreateOptions createOptions
            )
        {
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock isb;
            IntPtr handle;

            try
            {
                Win32.NtCreateMailslotFile(
                    out handle,
                    access,
                    ref oa,
                    out isb,
                    createOptions,
                    quota,
                    maxMessageSize,
                    ref readTimeout
                    ).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return new MailslotHandle(handle, true);
        }
예제 #2
0
        public DirectoryHandle(string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, DirectoryAccess access)
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if (KProcessHacker.Instance != null)
                {
                    handle = KProcessHacker.Instance.KphOpenDirectoryObject(access, oa).ToIntPtr();
                }
                else
                {
                    if ((status = Win32.NtOpenDirectoryObject(out handle, access, ref oa)) >= NtStatus.Error)
                    {
                        Win32.Throw(status);
                    }
                }
            }
            finally
            {
                oa.Dispose();
            }

            this.Handle = handle;
        }
예제 #3
0
        public static SymbolicLinkHandle Create(SymbolicLinkAccess access, string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, string linkTarget)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                UnicodeString linkTargetString = new UnicodeString(linkTarget);

                try
                {
                    Win32.NtCreateSymbolicLinkObject(
                        out handle,
                        access,
                        ref oa,
                        ref linkTargetString
                        ).ThrowIf();
                }
                finally
                {
                    linkTargetString.Dispose();
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new SymbolicLinkHandle(handle, true));
        }
예제 #4
0
        public static TmHandle Create(
            TmAccess access,
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            string logFileName,
            TmOptions createOptions
            )
        {
            ObjectAttributes oa             = new ObjectAttributes(name, objectFlags, rootDirectory);
            UnicodeString    logFileNameStr = new UnicodeString(logFileName);
            IntPtr           handle;

            try
            {
                Win32.NtCreateTransactionManager(
                    out handle,
                    access,
                    ref oa,
                    ref logFileNameStr,
                    createOptions,
                    0
                    ).ThrowIf();
            }
            finally
            {
                logFileNameStr.Dispose();
                oa.Dispose();
            }

            return(new TmHandle(handle, true));
        }
예제 #5
0
        public static PortHandle Create(
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            int maxConnectionInfoLength,
            int maxMessageLength,
            int maxPoolUsage
            )
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtCreatePort(
                    out handle,
                    ref oa,
                    maxConnectionInfoLength,
                    maxMessageLength,
                    maxPoolUsage
                    ).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new PortHandle(handle, true));
        }
예제 #6
0
        public static PortHandle CreateWaitable(
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            int maxConnectionInfoLength,
            int maxMessageLength,
            int maxPoolUsage
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtCreateWaitablePort(
                         out handle,
                         ref oa,
                         maxConnectionInfoLength,
                         maxMessageLength,
                         maxPoolUsage
                         )) >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new PortHandle(handle, true));
        }
예제 #7
0
        public ResourceManagerHandle(
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            TmHandle tmHandle,
            Guid guid,
            ResourceManagerAccess access
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtOpenResourceManager(
                         out handle,
                         access,
                         tmHandle,
                         ref guid,
                         ref oa
                         )) >= NtStatus.Error)
                {
                    Win32.ThrowLastError(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            this.Handle = handle;
        }
        public static EnlistmentHandle Create(
            EnlistmentAccess access,
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            ResourceManagerHandle resourceManagerHandle,
            TransactionHandle transactionHandle,
            EnlistmentOptions createOptions,
            NotificationMask notificationMask,
            IntPtr enlistmentKey
            )
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtCreateEnlistment(
                    out handle,
                    access,
                    resourceManagerHandle,
                    transactionHandle,
                    ref oa,
                    createOptions,
                    notificationMask,
                    enlistmentKey
                    ).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new EnlistmentHandle(handle, true));
        }
        public EnlistmentHandle(
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            ResourceManagerHandle resourceManagerHandle,
            Guid guid,
            EnlistmentAccess access
            )
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtOpenEnlistment(
                    out handle,
                    access,
                    resourceManagerHandle,
                    ref guid,
                    ref oa
                    ).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            this.Handle = handle;
        }
예제 #10
0
        public static KeyHandle Create(
            KeyAccess access,
            string name,
            ObjectFlags objectFlags,
            KeyHandle rootDirectory,
            RegOptions createOptions,
            out KeyCreationDisposition creationDisposition
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtCreateKey(
                         out handle,
                         access,
                         ref oa,
                         0,
                         IntPtr.Zero,
                         createOptions,
                         out creationDisposition
                         )) >= NtStatus.Error)
                {
                    Win32.ThrowLastError(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new KeyHandle(handle, true));
        }
예제 #11
0
        public static MailslotHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            NativeHandle rootDirectory,
            int quota,
            int maxMessageSize,
            long readTimeout,
            FileCreateOptions createOptions
            )
        {
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock    isb;
            IntPtr           handle;

            try
            {
                Win32.NtCreateMailslotFile(
                    out handle,
                    access,
                    ref oa,
                    out isb,
                    createOptions,
                    quota,
                    maxMessageSize,
                    ref readTimeout
                    ).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new MailslotHandle(handle, true));
        }
예제 #12
0
        public TmHandle(string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, TmAccess access)
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtOpenTransactionManager(
                         out handle,
                         access,
                         ref oa,
                         IntPtr.Zero,
                         IntPtr.Zero,
                         0
                         )) >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            this.Handle = handle;
        }
예제 #13
0
        public static DebugObjectHandle Create(DebugObjectAccess access, string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, DebugObjectFlags flags)
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtCreateDebugObject(
                         out handle,
                         access,
                         ref oa,
                         flags
                         )) >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new DebugObjectHandle(handle, true));
        }
예제 #14
0
        public static ThreadHandle Create(
            ThreadAccess access,
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            ProcessHandle processHandle,
            out ClientId clientId,
            ref Context threadContext,
            ref InitialTeb initialTeb,
            bool createSuspended
            )
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtCreateThread(
                    out handle,
                    access,
                    ref oa,
                    processHandle,
                    out clientId,
                    ref threadContext,
                    ref initialTeb,
                    createSuspended
                    ).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new ThreadHandle(handle, true));
        }
예제 #15
0
        public TransactionHandle(
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            Guid unitOfWorkGuid,
            TmHandle tmHandle,
            TransactionAccess access
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtOpenTransaction(
                         out handle,
                         access,
                         ref oa,
                         ref unitOfWorkGuid,
                         tmHandle ?? IntPtr.Zero
                         )) >= NtStatus.Error)
                {
                    Win32.ThrowLastError(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            this.Handle = handle;
        }
예제 #16
0
        public TransactionHandle(
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            Guid unitOfWorkGuid,
            TmHandle tmHandle,
            TransactionAccess access
            )
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtOpenTransaction(
                    out handle,
                    access,
                    ref oa,
                    ref unitOfWorkGuid,
                    tmHandle ?? IntPtr.Zero
                    ).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            this.Handle = handle;
        }
예제 #17
0
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            NativeHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock    isb;
            IntPtr           handle;

            // If a timeout wasn't specified, use a default value.
            if (defaultTimeout == 0)
            {
                defaultTimeout = -50 * Win32.TimeMsTo100Ns; // 50 milliseconds
            }
            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                         out handle,
                         access,
                         ref oa,
                         out isb,
                         shareMode,
                         creationDisposition,
                         createOptions,
                         type,
                         readMode,
                         completionMode,
                         maximumInstances,
                         inboundQuota,
                         outboundQuota,
                         ref defaultTimeout
                         )) >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new NamedPipeHandle(handle, true));
        }
예제 #18
0
        public static TokenHandle Create(
            TokenAccess access,
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            TokenType tokenType,
            Luid authenticationId,
            long expirationTime,
            Sid user,
            Sid[] groups,
            PrivilegeSet privileges,
            Sid owner,
            Sid primaryGroup,
            Acl defaultDacl,
            TokenSource source
            )
        {
            NtStatus          status;
            TokenUser         tokenUser         = new TokenUser(user);
            TokenGroups       tokenGroups       = new TokenGroups(groups);
            TokenPrivileges   tokenPrivileges   = new TokenPrivileges(privileges);
            TokenOwner        tokenOwner        = new TokenOwner(owner);
            TokenPrimaryGroup tokenPrimaryGroup = new TokenPrimaryGroup(primaryGroup);
            TokenDefaultDacl  tokenDefaultDacl  = new TokenDefaultDacl(defaultDacl);
            ObjectAttributes  oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr            handle;

            try
            {
                if ((status = Win32.NtCreateToken(
                         out handle,
                         access,
                         ref oa,
                         tokenType,
                         ref authenticationId,
                         ref expirationTime,
                         ref tokenUser,
                         ref tokenGroups,
                         ref tokenPrivileges,
                         ref tokenOwner,
                         ref tokenPrimaryGroup,
                         ref tokenDefaultDacl,
                         ref source
                         )) >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new TokenHandle(handle, true));
        }
예제 #19
0
        public static TransactionHandle Create(
            TransactionAccess access,
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            Guid unitOfWorkGuid,
            TmHandle tmHandle,
            TransactionOptions createOptions,
            long timeout,
            string description
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            if (unitOfWorkGuid == Guid.Empty)
            {
                unitOfWorkGuid = Guid.NewGuid();
            }

            try
            {
                UnicodeString descriptionStr = new UnicodeString(description);

                try
                {
                    if ((status = Win32.NtCreateTransaction(
                             out handle,
                             access,
                             ref oa,
                             ref unitOfWorkGuid,
                             tmHandle ?? IntPtr.Zero,
                             createOptions,
                             0,
                             0,
                             ref timeout,
                             ref descriptionStr
                             )) >= NtStatus.Error)
                    {
                        Win32.Throw(status);
                    }
                }
                finally
                {
                    descriptionStr.Dispose();
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new TransactionHandle(handle, true));
        }
예제 #20
0
        public static SectionHandle Create(
            SectionAccess access,
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            long maximumSize,
            SectionAttributes sectionAttributes,
            MemoryProtection pageAttributes,
            FileHandle fileHandle
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if (maximumSize != 0)
                {
                    if ((status = Win32.NtCreateSection(
                             out handle,
                             access,
                             ref oa,
                             ref maximumSize,
                             pageAttributes,
                             sectionAttributes,
                             fileHandle ?? IntPtr.Zero
                             )) >= NtStatus.Error)
                    {
                        Win32.Throw(status);
                    }
                }
                else
                {
                    if ((status = Win32.NtCreateSection(
                             out handle,
                             access,
                             ref oa,
                             IntPtr.Zero,
                             pageAttributes,
                             sectionAttributes,
                             fileHandle ?? IntPtr.Zero
                             )) >= NtStatus.Error)
                    {
                        Win32.Throw(status);
                    }
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new SectionHandle(handle, true));
        }
예제 #21
0
        public DriverHandle(string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);

            try
            {
                this.Handle = KProcessHacker.Instance.KphOpenDriver(oa).ToIntPtr();
            }
            finally
            {
                oa.Dispose();
            }
        }
예제 #22
0
        public static NativeHandle OpenObject(int access, string name, ObjectFlags objectFlags, NativeHandle rootDirectory)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);

            try
            {
                return(null);// new NativeHandle(KProcessHacker.Instance.KphOpenNamedObject(access, oa).ToIntPtr(), true);
            }
            finally
            {
                oa.Dispose();
            }
        }
예제 #23
0
        public DriverHandle(string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);

            try
            {
                this.Handle = KProcessHacker.Instance.KphOpenDriver(oa).ToIntPtr();
            }
            finally
            {
                oa.Dispose();
            }
        }
예제 #24
0
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            FileHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock    isb;
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                         out handle,
                         access,
                         ref oa,
                         out isb,
                         shareMode,
                         creationDisposition,
                         createOptions,
                         type,
                         readMode,
                         completionMode,
                         maximumInstances,
                         inboundQuota,
                         outboundQuota,
                         ref defaultTimeout
                         )) >= NtStatus.Error)
                {
                    Win32.ThrowLastError(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new NamedPipeHandle(handle, true));
        }
예제 #25
0
        public SemaphoreHandle(string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, SemaphoreAccess access)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtOpenSemaphore(out handle, access, ref oa).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            this.Handle = handle;
        }
예제 #26
0
        public static KeyedEventHandle Create(KeyedEventAccess access, string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtCreateKeyedEvent(out handle, access, ref oa, 0).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new KeyedEventHandle(handle, true));
        }
예제 #27
0
        public KeyedEventHandle(string name, DirectoryHandle rootDirectory, ObjectFlags objectFlags, KeyedEventAccess access)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtOpenKeyedEvent(out handle, access, ref oa).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            this.Handle = handle;
        }
예제 #28
0
        public static MutantHandle Create(MutantAccess access, string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, bool initialOwner)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtCreateMutant(out handle, access, ref oa, initialOwner).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new MutantHandle(handle, true));
        }
예제 #29
0
        public static IoCompletionHandle Create(IoCompletionAccess access, string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, int count)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtCreateIoCompletion(out handle, access, ref oa, count).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new IoCompletionHandle(handle, true));
        }
예제 #30
0
        /// <summary>
        /// Creates a timer.
        /// </summary>
        /// <param name="access">The desired access to the timer.</param>
        /// <param name="name">A name for the timer in the object manager namespace.</param>
        /// <param name="objectFlags">The flags to use when creating the object.</param>
        /// <param name="rootDirectory">The directory in which to place the timer. This can be null.</param>
        /// <param name="type">
        /// The type of timer; synchronization timers will be reset once waiting threads are released.
        /// </param>
        /// <returns>A handle to the timer.</returns>
        public static TimerHandle Create(TimerAccess access, string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, TimerType type)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtCreateTimer(out handle, access, ref oa, type).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new TimerHandle(handle, true));
        }
예제 #31
0
        public static EventHandle Create(EventAccess access, string name, ObjectFlags objectFlags, DirectoryHandle rootDirectory, EventType type, bool initialState)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                Win32.NtCreateEvent(out handle, access, ref oa, type, initialState).ThrowIf();
            }
            finally
            {
                oa.Dispose();
            }

            return(new EventHandle(handle, true));
        }
예제 #32
0
        public static ResourceManagerHandle Create(
            ResourceManagerAccess access,
            string name,
            ObjectFlags objectFlags,
            DirectoryHandle rootDirectory,
            TmHandle tmHandle,
            Guid guid,
            ResourceManagerOptions createOptions,
            string description
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                UnicodeString descriptionStr = new UnicodeString(description);

                try
                {
                    if ((status = Win32.NtCreateResourceManager(
                             out handle,
                             access,
                             tmHandle,
                             ref guid,
                             ref oa,
                             createOptions,
                             ref descriptionStr
                             )) >= NtStatus.Error)
                    {
                        Win32.ThrowLastError(status);
                    }
                }
                finally
                {
                    descriptionStr.Dispose();
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new ResourceManagerHandle(handle, true));
        }
예제 #33
0
        public static NativeHandle OpenObject(int access, string name, ObjectFlags objectFlags, NativeHandle rootDirectory)
        {
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);

            try
            {
                return new NativeHandle(KProcessHacker.Instance.KphOpenNamedObject(access, oa).ToIntPtr(), true);
            }
            finally
            {
                oa.Dispose();
            }
        }
예제 #34
0
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            FileHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock isb;
            IntPtr handle;

            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                    out handle,
                    access,
                    ref oa,
                    out isb,
                    shareMode,
                    creationDisposition,
                    createOptions,
                    type,
                    readMode,
                    completionMode,
                    maximumInstances,
                    inboundQuota,
                    outboundQuota,
                    ref defaultTimeout
                    )) >= NtStatus.Error)
                    Win32.ThrowLastError(status);
            }
            finally
            {
                oa.Dispose();
            }

            return new NamedPipeHandle(handle, true);
        }