diff options
author | fireice-uk <fireice-uk@users.noreply.github.com> | 2017-10-04 22:11:31 +0100 |
---|---|---|
committer | fireice-uk <fireice-uk@users.noreply.github.com> | 2017-10-04 22:11:31 +0100 |
commit | d8d403b2ace66ba05c9c6ff9da35361920fde908 (patch) | |
tree | baa3259691ff3dd4b179398b260f12479fdf2a88 /xmrstak | |
parent | 2b9bcc2dfd835d3c0a6a7de3f5f224c9afd5434b (diff) | |
download | xmr-stak-d8d403b2ace66ba05c9c6ff9da35361920fde908.zip xmr-stak-d8d403b2ace66ba05c9c6ff9da35361920fde908.tar.gz |
Non-manifest UAC elevation
Diffstat (limited to 'xmrstak')
-rw-r--r-- | xmrstak/cli/cli-miner.cpp | 11 | ||||
-rw-r--r-- | xmrstak/misc/uac.hpp | 44 |
2 files changed, 54 insertions, 1 deletions
diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp index ff31d2c..fbd5039 100644 --- a/xmrstak/cli/cli-miner.cpp +++ b/xmrstak/cli/cli-miner.cpp @@ -33,7 +33,11 @@ #include "xmrstak/version.hpp" #ifndef CONF_NO_HTTPD -# include "xmrstak/http//httpd.hpp" +# include "xmrstak/http/httpd.hpp" +#endif + +#ifdef _WIN32 +# include "xmrstak/misc/uac.hpp" #endif #include <stdlib.h> @@ -88,6 +92,11 @@ void help() int main(int argc, char *argv[]) { +#ifdef _WIN32 + if (!IsElevated() && SelfElevate(argv[0])) + return 0; +#endif + #ifndef CONF_NO_TLS SSL_library_init(); SSL_load_error_strings(); diff --git a/xmrstak/misc/uac.hpp b/xmrstak/misc/uac.hpp new file mode 100644 index 0000000..fdf3be9 --- /dev/null +++ b/xmrstak/misc/uac.hpp @@ -0,0 +1,44 @@ +#pragma once +#include <windows.h> + +BOOL IsElevated() +{ + BOOL fRet = FALSE; + HANDLE hToken = NULL; + if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) + { + TOKEN_ELEVATION Elevation; + DWORD cbSize = sizeof(TOKEN_ELEVATION); + if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) + fRet = Elevation.TokenIsElevated; + } + if (hToken) + CloseHandle(hToken); + return fRet; +} + +BOOL SelfElevate(const char* my_path) +{ + if (IsElevated()) + return FALSE; + + SHELLEXECUTEINFO shExecInfo = { 0 }; + shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + shExecInfo.fMask = NULL; + shExecInfo.hwnd = NULL; + shExecInfo.lpVerb = "runas"; + shExecInfo.lpFile = my_path; + shExecInfo.lpParameters = NULL; + shExecInfo.lpDirectory = NULL; + shExecInfo.nShow = SW_SHOW; + shExecInfo.hInstApp = NULL; + + if (!ShellExecuteEx(&shExecInfo)) + return FALSE; + + // Hide our window and loiter in the background to make scripting easier + // ShowWindow(GetConsoleWindow(), SW_HIDE); + // WaitForSingleObject(shExecInfo.hProcess, INFINITE); + + return TRUE; +} |