Skip to content

Commit 74af58b

Browse files
committed
Enable debug privileges to list all running processes.
1 parent 4d54bf1 commit 74af58b

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

Program.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
22
using System.Globalization;
3+
using System.Security.Principal;
34
using System.Windows.Forms;
45
using Microsoft.SqlServer.MessageBox;
56
using ReClassNET.Forms;
67
using ReClassNET.Logger;
78
using ReClassNET.Memory;
89
using ReClassNET.UI;
10+
using ReClassNET.Util;
911

1012
namespace ReClassNET
1113
{
@@ -34,6 +36,8 @@ static void Main()
3436

3537
DpiUtil.ConfigureProcess();
3638

39+
EnableDebugPrivileges();
40+
3741
Application.EnableVisualStyles();
3842
Application.SetCompatibleTextRenderingDefault(false);
3943

@@ -67,6 +71,27 @@ static void Main()
6771
Settings.Save(settings, Constants.SettingsFile);
6872
}
6973

74+
private static bool EnableDebugPrivileges()
75+
{
76+
var result = false;
77+
78+
IntPtr token;
79+
if (NativeMethods.OpenProcessToken(System.Diagnostics.Process.GetCurrentProcess().Handle, TokenAccessLevels.AllAccess, out token))
80+
{
81+
var privileges = new NativeMethods.TOKEN_PRIVILEGES();
82+
privileges.PrivilegeCount = 1;
83+
privileges.Luid.LowPart = 0x14;
84+
privileges.Luid.HighPart = 0;
85+
privileges.Attributes = 2;
86+
87+
result = NativeMethods.AdjustTokenPrivileges(token, false, ref privileges, 0, IntPtr.Zero, IntPtr.Zero);
88+
89+
NativeMethods.CloseHandle(token);
90+
}
91+
92+
return result;
93+
}
94+
7095
/// <summary>Shows the exception in a special form.</summary>
7196
/// <param name="ex">The exception.</param>
7297
public static void ShowException(Exception ex)

Util/NativeMethods.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using System.Security.Principal;
34
using System.Text;
45

56
namespace ReClassNET.Util
@@ -81,6 +82,21 @@ public struct SHFILEINFO
8182
public string szTypeName;
8283
};
8384

85+
[StructLayout(LayoutKind.Sequential, Pack = 1)]
86+
public struct LUID
87+
{
88+
public uint LowPart;
89+
public int HighPart;
90+
}
91+
92+
[StructLayout(LayoutKind.Sequential, Pack = 1)]
93+
public struct TOKEN_PRIVILEGES
94+
{
95+
public uint PrivilegeCount;
96+
public LUID Luid;
97+
public uint Attributes;
98+
}
99+
84100
#endregion
85101

86102
#region Natives
@@ -94,25 +110,34 @@ public struct SHFILEINFO
94110
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
95111
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
96112

113+
[DllImport("kernel32.dll", SetLastError = true)]
114+
public static extern bool CloseHandle(IntPtr hObject);
115+
97116
[DllImport("shell32.dll")]
98117
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
99118

100-
[DllImport("User32.dll")]
119+
[DllImport("user32.dll")]
101120
public static extern int DestroyIcon(IntPtr hIcon);
102121

103122
[DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Unicode)]
104123
static extern int UnDecorateSymbolName(string DecoratedName, StringBuilder UnDecoratedName, int UndecoratedLength, int Flags);
105124

106-
[DllImport("User32.dll")]
125+
[DllImport("user32.dll")]
107126
[return: MarshalAs(UnmanagedType.Bool)]
108127
internal static extern bool SetProcessDPIAware();
109128

110-
[DllImport("ShCore.dll")]
129+
[DllImport("shcore.dll")]
111130
internal static extern int SetProcessDpiAwareness([MarshalAs(UnmanagedType.U4)] ProcessDpiAwareness a);
112131

113132
[DllImport("kernel32.dll", SetLastError = true)]
114133
public static extern bool GetProcessTimes(IntPtr handle, out long creation, out long exit, out long kernel, out long user);
115134

135+
[DllImport("advapi32.dll", SetLastError = true)]
136+
public static extern bool OpenProcessToken(IntPtr ProcessHandle, TokenAccessLevels DesiredAccess, out IntPtr TokenHandle);
137+
138+
[DllImport("advapi32.dll", SetLastError = true)]
139+
public static extern bool AdjustTokenPrivileges(IntPtr TokenHandle, [MarshalAs(UnmanagedType.Bool)]bool DisableAllPrivileges, ref TOKEN_PRIVILEGES NewState, uint Zero, IntPtr Null1, IntPtr Null2);
140+
116141
#endregion
117142

118143
#region Helper

0 commit comments

Comments
 (0)