示例#1
0
        public void KphDuplicateObject(
            int sourceProcessHandle,
            int sourceHandle,
            int targetProcessHandle,
            int targetHandle,
            int desiredAccess,
            HandleFlags handleAttributes,
            DuplicateOptions options
            )
        {
            byte[] data = new byte[7 * sizeof(int)];

            fixed(byte *dataPtr = data)
            {
                *(int *)(dataPtr + 0x0)  = sourceProcessHandle;
                *(int *)(dataPtr + 0x4)  = sourceHandle;
                *(int *)(dataPtr + 0x8)  = targetProcessHandle;
                *(int *)(dataPtr + 0xc)  = targetHandle;
                *(int *)(dataPtr + 0x10) = desiredAccess;
                *(int *)(dataPtr + 0x14) = (int)handleAttributes;
                *(int *)(dataPtr + 0x18) = (int)options;

                _fileHandle.IoControl(CtlCode(Control.KphDuplicateObject), data, null);
            }
        }
示例#2
0
 public static void SetHandleInformation(SafeHandle handle, HandleFlags mask, HandleFlags flags)
 {
     if (!NativeSetHandleInformation(handle, mask, flags))
     {
         throw new Win32Exception();
     }
 }
示例#3
0
        public void SetHandleAttributes(ProcessHandle processHandle, IntPtr handle, HandleFlags flags)
        {
            byte *inData = stackalloc byte[12];

            *(int *)inData       = processHandle;
            *(int *)(inData + 4) = handle.ToInt32();
            *(int *)(inData + 8) = (int)flags;

            _fileHandle.IoControl(CtlCode(Control.SetHandleAttributes), inData, 12, null, 0);
        }
示例#4
0
        public static unsafe void DuplicateObject(
            IntPtr sourceProcessHandle,
            IntPtr sourceHandle,
            int desiredAccess,
            HandleFlags handleAttributes,
            DuplicateOptions options
            )
        {
            IntPtr dummy;

            DuplicateObject(
                sourceProcessHandle,
                sourceHandle,
                IntPtr.Zero,
                out dummy,
                desiredAccess,
                handleAttributes,
                options
                );
        }
示例#5
0
        public unsafe static void DuplicateObject(
            IntPtr sourceProcessHandle,
            IntPtr sourceHandle,
            int desiredAccess,
            HandleFlags handleAttributes,
            DuplicateOptions options
            )
        {
            IntPtr dummy;

            DuplicateObject(
                sourceProcessHandle,
                sourceHandle,
                IntPtr.Zero,
                out dummy,
                desiredAccess,
                handleAttributes,
                options
                );
        }
示例#6
0
 public static void DuplicateObject(
     IntPtr sourceProcessHandle,
     IntPtr sourceHandle,
     IntPtr targetProcessHandle,
     out IntPtr targetHandle,
     int desiredAccess,
     HandleFlags handleAttributes,
     DuplicateOptions options
     )
 {
     NtDuplicateObject(
         sourceProcessHandle,
         sourceHandle,
         targetProcessHandle,
         out targetHandle,
         desiredAccess,
         handleAttributes,
         options
         ).ThrowIf();
 }
示例#7
0
        public unsafe static void DuplicateObject(
            IntPtr sourceProcessHandle,
            IntPtr sourceHandle,
            IntPtr targetProcessHandle,
            out IntPtr targetHandle,
            int desiredAccess,
            HandleFlags handleAttributes,
            DuplicateOptions options
            )
        {
            if (KProcessHacker.Instance != null)
            {
                int target;

                KProcessHacker.Instance.KphDuplicateObject(
                    sourceProcessHandle.ToInt32(),
                    sourceHandle.ToInt32(),
                    targetProcessHandle.ToInt32(),
                    out target,
                    desiredAccess,
                    handleAttributes,
                    options);
                targetHandle = new IntPtr(target);
            }
            else
            {
                NtStatus status;

                if ((status = NtDuplicateObject(
                         sourceProcessHandle,
                         sourceHandle,
                         targetProcessHandle,
                         out targetHandle,
                         desiredAccess,
                         handleAttributes,
                         options)) >= NtStatus.Error)
                {
                    Throw(status);
                }
            }
        }
示例#8
0
        protected override void BeginProcessing()
        {
            if (Inherit)
            {
                _flags |= HandleFlags.Inherit;
            }

            if (ProtectFromClose)
            {
                _flags |= HandleFlags.ProtectFromClose;
            }

            if (Clear)
            {
                _mask = HandleFlags.Inherit | HandleFlags.ProtectFromClose;
            }
            else
            {
                _mask = _flags;
            }
        }
示例#9
0
        public void KphDuplicateObject(
            int sourceProcessHandle,
            int sourceHandle,
            int targetProcessHandle,
            out int targetHandle,
            int desiredAccess,
            HandleFlags handleAttributes,
            DuplicateOptions options
            )
        {
            int handle;

            KphDuplicateObject(
                sourceProcessHandle,
                sourceHandle,
                targetProcessHandle,
                (int)&handle,
                desiredAccess,
                handleAttributes,
                options
                );

            targetHandle = handle;
        }
示例#10
0
        private void inheritMenuItem_Click(object sender, EventArgs e)
        {
            HandleItem  item  = (HandleItem)listHandles.SelectedItems[0].Tag;
            HandleFlags flags = item.Handle.Flags;

            if ((flags & HandleFlags.Inherit) != 0)
            {
                flags &= ~HandleFlags.Inherit;
            }
            else
            {
                flags |= HandleFlags.Inherit;
            }

            try
            {
                //using (var phandle = new ProcessHandle(_pid, Program.MinProcessQueryRights))
                //KProcessHacker.Instance.SetHandleAttributes(phandle, new IntPtr(item.Handle.Handle), flags);
            }
            catch (Exception ex)
            {
                PhUtils.ShowException("Unable to set handle attributes", ex);
            }
        }
示例#11
0
 public static extern bool SetHandleInformation(SafeHandle handle, HandleFlags dwMask, HandleFlags dwFlags);
 private static extern bool SetHandleInformation(SafeFileHandle hObject, HandleFlags dwMask, HandleFlags dwFlags);
示例#13
0
 internal static extern bool SetHandleInformation(IntPtr handle, HandleFlags dwMask, HandleFlags dwFlags);
示例#14
0
        public void KphDuplicateObject(
            int sourceProcessHandle,
            int sourceHandle,
            int targetProcessHandle,
            int targetHandle,
            int desiredAccess,
            HandleFlags handleAttributes,
            DuplicateOptions options
            )
        {
            byte[] data = new byte[7 * sizeof(int)];

            fixed (byte* dataPtr = data)
            {
                *(int*)(dataPtr + 0x0) = sourceProcessHandle;
                *(int*)(dataPtr + 0x4) = sourceHandle;
                *(int*)(dataPtr + 0x8) = targetProcessHandle;
                *(int*)(dataPtr + 0xc) = targetHandle;
                *(int*)(dataPtr + 0x10) = desiredAccess;
                *(int*)(dataPtr + 0x14) = (int)handleAttributes;
                *(int*)(dataPtr + 0x18) = (int)options;

                _fileHandle.IoControl(CtlCode(Control.KphDuplicateObject), data, null);
            }
        }
示例#15
0
        public unsafe static void DuplicateObject(
            IntPtr sourceProcessHandle,
            IntPtr sourceHandle,
            IntPtr targetProcessHandle,
            out IntPtr targetHandle,
            int desiredAccess,
            HandleFlags handleAttributes,
            DuplicateOptions options
            )
        {
            if (KProcessHacker.Instance != null)
            {
                int target;

                KProcessHacker.Instance.KphDuplicateObject(
                    sourceProcessHandle.ToInt32(),
                    sourceHandle.ToInt32(),
                    targetProcessHandle.ToInt32(),
                    out target,
                    desiredAccess,
                    handleAttributes,
                    options);
                targetHandle = new IntPtr(target);
            }
            else
            {
                NtStatus status;

                if ((status = NtDuplicateObject(
                    sourceProcessHandle,
                    sourceHandle,
                    targetProcessHandle,
                    out targetHandle,
                    desiredAccess,
                    handleAttributes,
                    options)) >= NtStatus.Error)
                    ThrowLastError(status);
            }
        }
示例#16
0
 public static extern Bool SetHandleInformation(IntPtr handle, HandleFlags change, HandleFlags value);
示例#17
0
        public void KphDuplicateObject(
            int sourceProcessHandle,
            int sourceHandle,
            int targetProcessHandle,
            out int targetHandle,
            int desiredAccess,
            HandleFlags handleAttributes,
            DuplicateOptions options
            )
        {
            int handle;

            KphDuplicateObject(
                sourceProcessHandle,
                sourceHandle,
                targetProcessHandle,
                (int)&handle,
                desiredAccess,
                handleAttributes,
                options
                );

            targetHandle = handle;
        }
示例#18
0
 static extern bool SetHandleInformation(IntPtr hObject, HandleFlags dwMask, HandleFlags dwFlags);
示例#19
0
 private static extern bool SetHandleInformation(IntPtr hObject, HandleFlags dwMask, HandleFlags dwFlags);
示例#20
0
 internal static partial bool SetHandleInformation(SafeHandle hObject, HandleFlags dwMask, HandleFlags dwFlags);
示例#21
0
 private static extern bool NativeGetHandleInformation(
     SafeHandle hObject,
     out HandleFlags lpdwFlags
     );
示例#22
0
 public static extern bool GetHandleInformation(SafeHandle handle, out HandleFlags lpdwFlags);
示例#23
0
 void SetFlags(HandleFlags mask, HandleFlags value)
 {
     UnsafeNativeMethods.SetHandleInformation(m_handle, (uint)mask, (uint)value).EnsureNoWin32Error();
 }
示例#24
0
 public static void DuplicateObject(
     IntPtr sourceProcessHandle,
     IntPtr sourceHandle,
     IntPtr targetProcessHandle,
     out IntPtr targetHandle,
     int desiredAccess,
     HandleFlags handleAttributes,
     DuplicateOptions options
     )
 {
     NtDuplicateObject(
         sourceProcessHandle,
         sourceHandle,
         targetProcessHandle,
         out targetHandle,
         desiredAccess,
         handleAttributes,
         options
         ).ThrowIf();
 }
示例#25
0
 public static extern bool SetHandleInformation(IntPtr handle, HandleFlags dwMask, HandleFlags dwFlags);
示例#26
0
        public void SetHandleAttributes(ProcessHandle processHandle, IntPtr handle, HandleFlags flags)
        {
            byte* inData = stackalloc byte[12];

            *(int*)inData = processHandle;
            *(int*)(inData + 4) = handle.ToInt32();
            *(int*)(inData + 8) = (int)flags;

            _fileHandle.IoControl(CtlCode(Control.SetHandleAttributes), inData, 12, null, 0);
        }
示例#27
0
 public static extern bool GetHandleInformation(IntPtr handle, out HandleFlags lpdwFlags);
 private static extern bool SetHandleInformation(SafeFileHandle hObject, HandleFlags dwMask, HandleFlags dwFlags);