Example #1
0
        public static bool SetDebugPrivileges()
        {
            IntPtr zero = IntPtr.Zero;

            MemoryApi.LUID luid = default(MemoryApi.LUID);
            luid.HighPart = 0;
            luid.LowPart  = 0u;
            MemoryApi.TOKEN_PRIVILEGES tOKEN_PRIVILEGES = default(MemoryApi.TOKEN_PRIVILEGES);

            IntPtr currentProcess = MemoryApi.GetCurrentProcess();

            if (!MemoryApi.OpenProcessToken(currentProcess, 40u, out zero))
            {
                return(false);
            }

            if (!MemoryApi.LookupPrivilegeValue("", "SeDebugPrivilege", out luid))
            {
                return(false);
            }

            tOKEN_PRIVILEGES.PrivilegeCount = 1u;
            tOKEN_PRIVILEGES.Luid           = luid;
            tOKEN_PRIVILEGES.Attributes     = 2u;

            return(MemoryApi.AdjustTokenPrivileges(zero, false, ref tOKEN_PRIVILEGES, 0u, IntPtr.Zero, IntPtr.Zero) && MemoryApi.CloseHandle(zero) != 0);
        }
Example #2
0
 public static extern bool AdjustTokenPrivileges(IntPtr TokenHandle, [MarshalAs(UnmanagedType.Bool)] bool DisableAllPrivileges, ref MemoryApi.TOKEN_PRIVILEGES NewState, uint BufferLength, IntPtr previous, IntPtr ReturnLength);