├── .gitignore ├── SetDebugPrivilege.sln └── SetDebugPrivilege ├── SetDebugPrivilege.cpp ├── SetDebugPrivilege.h ├── SetDebugPrivilege.vcxproj ├── SetDebugPrivilege.vcxproj.filters ├── SetDebugPrivilege.vcxproj.user ├── main.cpp └── main.h /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | Debug/ 3 | SetDebugPrivilege/Debug/ 4 | SetDebugPrivilege/x64/ 5 | x64/ 6 | -------------------------------------------------------------------------------- /SetDebugPrivilege.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2026 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SetDebugPrivilege", "SetDebugPrivilege\SetDebugPrivilege.vcxproj", "{FCBB4154-5E1F-436B-A8B7-256A83F4256C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C}.Debug|x64.ActiveCfg = Debug|x64 17 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C}.Debug|x64.Build.0 = Debug|x64 18 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C}.Debug|x86.ActiveCfg = Debug|Win32 19 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C}.Debug|x86.Build.0 = Debug|Win32 20 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C}.Release|x64.ActiveCfg = Release|x64 21 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C}.Release|x64.Build.0 = Release|x64 22 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C}.Release|x86.ActiveCfg = Release|Win32 23 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {45B7B733-2992-4894-B6AC-123F166A89CB} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SetDebugPrivilege/SetDebugPrivilege.cpp: -------------------------------------------------------------------------------- 1 | #include "SetDebugPrivilege.h" 2 | 3 | bool Attachable(DWORD PID) 4 | { 5 | HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, PID); 6 | if (!hProc) 7 | return false; 8 | 9 | CloseHandle(hProc); 10 | 11 | return true; 12 | } 13 | 14 | void ListProcesses(std::vector & List) 15 | { 16 | List.clear(); 17 | PROCESSENTRY32 PE32{ 0 }; 18 | PE32.dwSize = sizeof(PROCESSENTRY32); 19 | 20 | HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 21 | if (hSnap == INVALID_HANDLE_VALUE) 22 | return; 23 | 24 | BOOL bRet = Process32First(hSnap, &PE32); 25 | while (bRet) 26 | { 27 | if (!Attachable(PE32.th32ProcessID) || PE32.th32ProcessID == GetCurrentProcessId()) 28 | { 29 | bRet = Process32Next(hSnap, &PE32); 30 | continue; 31 | } 32 | 33 | PROCESS_DATA current{ 0 }; 34 | memcpy(current.szExeFileName, PE32.szExeFile, _tcslen(PE32.szExeFile) * sizeof(TCHAR)); 35 | current.PID = PE32.th32ProcessID; 36 | List.push_back(current); 37 | bRet = Process32Next(hSnap, &PE32); 38 | } 39 | } 40 | 41 | bool SetPrivilege(DWORD PID) 42 | { 43 | HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, PID); 44 | if (!hProc) 45 | return false; 46 | 47 | HANDLE hToken = nullptr; 48 | if (!OpenProcessToken(hProc, TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken)) 49 | { 50 | CloseHandle(hProc); 51 | return false; 52 | } 53 | 54 | CloseHandle(hProc); 55 | 56 | TOKEN_PRIVILEGES TokenPrivileges = { 0 }; 57 | TokenPrivileges.PrivilegeCount = 1; 58 | TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 59 | 60 | if (!LookupPrivilegeValue(nullptr, SE_DEBUG_NAME, &TokenPrivileges.Privileges[0].Luid)) 61 | { 62 | CloseHandle(hToken); 63 | return false; 64 | } 65 | 66 | if (!AdjustTokenPrivileges(hToken, FALSE, &TokenPrivileges, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr)) 67 | { 68 | CloseHandle(hToken); 69 | return false; 70 | } 71 | 72 | CloseHandle(hToken); 73 | 74 | return true; 75 | } -------------------------------------------------------------------------------- /SetDebugPrivilege/SetDebugPrivilege.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | struct PROCESS_DATA 9 | { 10 | TCHAR szExeFileName[MAX_PATH]; 11 | DWORD PID; 12 | }; 13 | 14 | void ListProcesses(std::vector & List); 15 | bool SetPrivilege(DWORD PID); -------------------------------------------------------------------------------- /SetDebugPrivilege/SetDebugPrivilege.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {FCBB4154-5E1F-436B-A8B7-256A83F4256C} 24 | SetDebugPrivilege 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | MultiByte 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | MultiByte 40 | 41 | 42 | Application 43 | true 44 | v142 45 | MultiByte 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | MultiByte 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | false 74 | 75 | 76 | false 77 | 78 | 79 | 80 | Level3 81 | Disabled 82 | true 83 | true 84 | stdcpp17 85 | 86 | 87 | 88 | 89 | Level3 90 | Disabled 91 | true 92 | true 93 | stdcpp17 94 | 95 | 96 | 97 | 98 | Level4 99 | MaxSpeed 100 | true 101 | true 102 | true 103 | true 104 | None 105 | stdcpp17 106 | 107 | 108 | true 109 | true 110 | AsInvoker 111 | 112 | 113 | 114 | 115 | Level4 116 | MaxSpeed 117 | true 118 | true 119 | true 120 | true 121 | None 122 | stdcpp17 123 | 124 | 125 | true 126 | true 127 | AsInvoker 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /SetDebugPrivilege/SetDebugPrivilege.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Headerdateien 20 | 21 | 22 | Headerdateien 23 | 24 | 25 | 26 | 27 | Quelldateien 28 | 29 | 30 | Quelldateien 31 | 32 | 33 | -------------------------------------------------------------------------------- /SetDebugPrivilege/SetDebugPrivilege.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /SetDebugPrivilege/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #pragma comment(lib, "Comctl32.lib") 7 | 8 | #define SS_DESCENDING 0x01000000 9 | 10 | HINSTANCE g_hInstance = NULL; 11 | LPARAM g_SortSense = 0; 12 | HWND g_hListView = NULL; 13 | 14 | HWND CreateListView(HWND hParent, int x, int y, int w, int h, DWORD ex = 0); 15 | LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 16 | bool UpdateProcessList(HWND hListView); 17 | 18 | int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char * lpCmdLine, int nCmdShow) 19 | { 20 | UNREFERENCED_PARAMETER(hPrevInstance); 21 | UNREFERENCED_PARAMETER(lpCmdLine); 22 | 23 | SetPrivilege(GetCurrentProcessId()); 24 | 25 | g_hInstance = hInstance; 26 | 27 | int width = 300; 28 | int height = 300; 29 | 30 | HWND hWnd; 31 | WNDCLASSEX wc{ 0 }; 32 | wc.cbSize = sizeof(WNDCLASSEX); 33 | wc.lpfnWndProc = WindowProc; 34 | wc.hInstance = hInstance; 35 | wc.hCursor = LoadCursor(0, IDC_ARROW); 36 | wc.hbrBackground = (HBRUSH)COLOR_WINDOW; 37 | wc.lpszClassName = TEXT("WindowClass"); 38 | 39 | RegisterClassEx(&wc); 40 | 41 | hWnd = CreateWindowEx(0, TEXT("WindowClass"), TEXT("SetDebugPrivilege"), WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 150, 150, width, height, 0, 0, hInstance, nullptr); 42 | 43 | ShowWindow(hWnd, 5); 44 | 45 | RECT wnd_rect{ 0 }; 46 | GetClientRect(hWnd, &wnd_rect); 47 | width = wnd_rect.right - wnd_rect.left; 48 | height = wnd_rect.bottom - wnd_rect.top; 49 | 50 | g_hListView = CreateListView(hWnd, 0, 0, width, height - 50, LVS_EX_FULLROWSELECT); 51 | 52 | TCHAR szText[256]{ 0 }; 53 | 54 | LVCOLUMN lvc{ 0 }; 55 | 56 | lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVS_REPORT; 57 | lvc.pszText = const_cast(TEXT("Processname")); 58 | lvc.cx = width - 70; 59 | LoadString(hInstance, 0, szText, sizeof(szText) / sizeof(TCHAR)); 60 | ListView_InsertColumn(g_hListView, 0, &lvc); 61 | 62 | ZeroMemory(&lvc, sizeof(lvc)); 63 | 64 | lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVS_REPORT; 65 | lvc.pszText = const_cast(TEXT("PID")); 66 | lvc.cx = 50; 67 | LoadString(hInstance, 1, szText, sizeof(szText) / sizeof(TCHAR)); 68 | ListView_InsertColumn(g_hListView, 1, &lvc); 69 | 70 | UpdateProcessList(g_hListView); 71 | 72 | ShowWindow(g_hListView, 5); 73 | 74 | HWND h_B_Update = CreateWindow(TEXT("BUTTON"), TEXT("Update"), WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, height - 40, width / 2 - 15, 30, hWnd, NULL, hInstance, nullptr); 75 | HWND h_B_SetPriv = CreateWindow(TEXT("BUTTON"), TEXT("Set Privilege"), WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, width / 2 + 5, height - 40, width / 2 - 15, 30, hWnd, NULL, hInstance, nullptr); 76 | 77 | ShowWindow(h_B_Update, 5); 78 | ShowWindow(h_B_SetPriv, 5); 79 | 80 | MSG msg{ 0 }; 81 | while (GetMessage(&msg, NULL, 0, 0)) 82 | { 83 | if (msg.hwnd == h_B_Update) 84 | { 85 | if (msg.message == WM_LBUTTONUP) 86 | { 87 | g_SortSense = 0; 88 | UpdateProcessList(g_hListView); 89 | } 90 | } 91 | 92 | if (msg.hwnd == h_B_SetPriv) 93 | { 94 | if (msg.message == WM_LBUTTONUP) 95 | { 96 | int index = ListView_GetNextItem(g_hListView, -1, LVNI_SELECTED); 97 | while (index != -1) 98 | { 99 | TCHAR szPID[8]{ 0 }; 100 | ListView_GetItemText(g_hListView, index, 1, szPID, 8); 101 | TCHAR szName[sizeof(PROCESSENTRY32::szExeFile) / sizeof(TCHAR)]{ 0 }; 102 | ListView_GetItemText(g_hListView, index, 0, szName, sizeof(szName) / sizeof(TCHAR)); 103 | 104 | std::basic_string info_string(szName); 105 | info_string += TEXT(" ("); 106 | info_string += szPID; 107 | info_string += TEXT(")"); 108 | 109 | DWORD PID = 0; 110 | #ifdef UNICODE 111 | PID = (DWORD)_wtoi(szPID); 112 | #else 113 | PID = (DWORD)atoi(szPID); 114 | #endif 115 | 116 | if (PID) 117 | { 118 | if (SetPrivilege(PID)) 119 | { 120 | MessageBox(NULL, TEXT("Privilege enabled."), info_string.c_str(), MB_ICONINFORMATION); 121 | } 122 | else 123 | { 124 | MessageBox(NULL, TEXT("Enabling privilege failed."), info_string.c_str(), MB_ICONERROR); 125 | } 126 | } 127 | 128 | index = ListView_GetNextItem(g_hListView, index, LVNI_SELECTED); 129 | } 130 | } 131 | } 132 | 133 | TranslateMessage(&msg); 134 | DispatchMessage(&msg); 135 | 136 | if (msg.message == WM_QUIT) 137 | break; 138 | } 139 | 140 | return (int)msg.wParam; 141 | } 142 | 143 | HWND CreateListView(HWND hParent, int x, int y, int w, int h, DWORD ex) 144 | { 145 | INITCOMMONCONTROLSEX icex; 146 | icex.dwICC = ICC_LISTVIEW_CLASSES; 147 | InitCommonControlsEx(&icex); 148 | 149 | RECT rcClient{ 0 }; 150 | GetClientRect(hParent, &rcClient); 151 | 152 | HWND hWnd = CreateWindow(WC_LISTVIEW, TEXT(""), WS_CHILD | LVS_REPORT, x, y, w, h, hParent, NULL, g_hInstance, nullptr); 153 | 154 | if (ex && hWnd) 155 | { 156 | SendMessage(hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, ex, ex); 157 | } 158 | 159 | return hWnd; 160 | } 161 | 162 | LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 163 | { 164 | switch (message) 165 | { 166 | case WM_NOTIFY: 167 | { 168 | NMHDR * nmhdr = reinterpret_cast(lParam); 169 | if (nmhdr->hwndFrom == g_hListView && nmhdr->code == LVN_COLUMNCLICK) 170 | { 171 | NMLISTVIEW * info = reinterpret_cast(lParam); 172 | if ((g_SortSense & 0x00FFFFFF) == info->iSubItem) 173 | { 174 | if (g_SortSense & SS_DESCENDING) 175 | g_SortSense ^= SS_DESCENDING; 176 | else 177 | g_SortSense |= SS_DESCENDING; 178 | } 179 | else 180 | { 181 | g_SortSense = info->iSubItem; 182 | } 183 | 184 | UpdateProcessList(g_hListView); 185 | } 186 | }break; 187 | 188 | case WM_DESTROY: 189 | { 190 | PostQuitMessage(0); 191 | return 0; 192 | }break; 193 | 194 | case WM_CLOSE: 195 | { 196 | DestroyWindow(hWnd); 197 | }break; 198 | 199 | } 200 | 201 | return DefWindowProc(hWnd, message, wParam, lParam); 202 | } 203 | 204 | bool UpdateProcessList(HWND hListView) 205 | { 206 | ListView_DeleteAllItems(hListView); 207 | 208 | std::vector data; 209 | ListProcesses(data); 210 | 211 | if (g_SortSense & 1) 212 | std::sort(data.begin(), data.end(), [](const PROCESS_DATA & a, const PROCESS_DATA & b) -> bool { return a.PID > b.PID; }); 213 | else 214 | std::sort(data.begin(), data.end(), [](const PROCESS_DATA & a, const PROCESS_DATA & b) -> bool { return (0 < _tcsicmp(a.szExeFileName, b.szExeFileName)); }); 215 | 216 | if (g_SortSense & SS_DESCENDING) 217 | std::reverse(data.begin(), data.end()); 218 | 219 | if (data.empty()) 220 | return false; 221 | 222 | for (auto i : data) 223 | { 224 | LVITEM item{ 0 }; 225 | item.mask = LVIF_TEXT; 226 | item.pszText = i.szExeFileName; 227 | ListView_InsertItem(hListView, &item); 228 | 229 | TCHAR szPID[8]{ 0 }; 230 | _ultot_s<8>(i.PID, szPID, 10); 231 | item.pszText = szPID; 232 | item.iSubItem = 1; 233 | ListView_SetItem(hListView, &item); 234 | } 235 | 236 | return false; 237 | } -------------------------------------------------------------------------------- /SetDebugPrivilege/main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SetDebugPrivilege.h" --------------------------------------------------------------------------------