1
0
mirror of synced 2025-01-18 09:04:52 +01:00

ui: Added icon to footer when ImHex has elevated permissions

This commit is contained in:
WerWolv 2021-12-13 22:58:23 +01:00
parent 9bf9788689
commit 51474b2eae
3 changed files with 35 additions and 2 deletions

View File

@ -13,6 +13,12 @@ namespace hex::plugin::builtin {
void addFooterItems() { void addFooterItems() {
if (hex::isProcessElevated()) {
ContentRegistry::Interface::addFooterItem([] {
ImGui::TextUnformatted(ICON_VS_SHIELD);
});
}
ContentRegistry::Interface::addFooterItem([] { ContentRegistry::Interface::addFooterItem([] {
static float framerate = 0; static float framerate = 0;
if (ImGui::HasSecondPassed()) { if (ImGui::HasSecondPassed()) {

View File

@ -237,6 +237,8 @@ namespace hex {
return *value; return *value;
} }
bool isProcessElevated();
namespace scope_guard { namespace scope_guard {
#define SCOPE_GUARD ::hex::scope_guard::ScopeGuardOnExit() + [&]() #define SCOPE_GUARD ::hex::scope_guard::ScopeGuardOnExit() + [&]()

View File

@ -7,9 +7,11 @@
#include <hex/helpers/fmt.hpp> #include <hex/helpers/fmt.hpp>
#if defined(OS_WINDOWS) #if defined (OS_WINDOWS)
#include <windows.h> #include <windows.h>
#elif defined(OS_MACOS) #elif defined (OS_LINUX)
#include <unistd.h>
#elif defined (OS_MACOS)
#include <CoreFoundation/CFBundle.h> #include <CoreFoundation/CFBundle.h>
#include <ApplicationServices/ApplicationServices.h> #include <ApplicationServices/ApplicationServices.h>
#endif #endif
@ -253,4 +255,27 @@ namespace hex {
return reinterpret_cast<float&>(result); return reinterpret_cast<float&>(result);
} }
bool isProcessElevated() {
#if defined (OS_WINDOWS)
bool elevated = false;
HANDLE token = INVALID_HANDLE_VALUE;
if (::OpenProcessToken(::GetCurrentProcess(), TOKEN_QUERY, &token)) {
TOKEN_ELEVATION elevation;
DWORD elevationSize = sizeof(TOKEN_ELEVATION);
if (::GetTokenInformation(token, TokenElevation, &elevation, sizeof(elevation), &elevationSize))
elevated = elevation.TokenIsElevated;
}
if (token != INVALID_HANDLE_VALUE)
::CloseHandle(token);
return elevated;
#elif defined(OS_LINUX) || defined (OS_MACOS)
return getuid() < 0 || getuid() != geteuid();
#endif
}
} }