ui: Added icon to footer when ImHex has elevated permissions
This commit is contained in:
parent
9bf9788689
commit
51474b2eae
@ -13,6 +13,12 @@ namespace hex::plugin::builtin {
|
||||
|
||||
void addFooterItems() {
|
||||
|
||||
if (hex::isProcessElevated()) {
|
||||
ContentRegistry::Interface::addFooterItem([] {
|
||||
ImGui::TextUnformatted(ICON_VS_SHIELD);
|
||||
});
|
||||
}
|
||||
|
||||
ContentRegistry::Interface::addFooterItem([] {
|
||||
static float framerate = 0;
|
||||
if (ImGui::HasSecondPassed()) {
|
||||
|
@ -237,6 +237,8 @@ namespace hex {
|
||||
return *value;
|
||||
}
|
||||
|
||||
bool isProcessElevated();
|
||||
|
||||
namespace scope_guard {
|
||||
|
||||
#define SCOPE_GUARD ::hex::scope_guard::ScopeGuardOnExit() + [&]()
|
||||
|
@ -7,9 +7,11 @@
|
||||
|
||||
#include <hex/helpers/fmt.hpp>
|
||||
|
||||
#if defined(OS_WINDOWS)
|
||||
#if defined (OS_WINDOWS)
|
||||
#include <windows.h>
|
||||
#elif defined(OS_MACOS)
|
||||
#elif defined (OS_LINUX)
|
||||
#include <unistd.h>
|
||||
#elif defined (OS_MACOS)
|
||||
#include <CoreFoundation/CFBundle.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#endif
|
||||
@ -253,4 +255,27 @@ namespace hex {
|
||||
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
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user