mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-26 16:11:02 +08:00
(ETW) setDebugPrivelege() rename
This commit is contained in:
parent
0dc944a877
commit
5e4193cb13
@ -246,15 +246,14 @@ namespace profiler {
|
||||
m_lowPriority.store(_value, ::std::memory_order_release);
|
||||
}
|
||||
|
||||
bool EasyEventTracer::setDebugPrivilege()
|
||||
bool setPrivilege(HANDLE hToken, LPCSTR _privelegeName)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
HANDLE hToken = nullptr;
|
||||
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
|
||||
if (hToken)
|
||||
{
|
||||
LUID privilegyId;
|
||||
if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &privilegyId))
|
||||
if (LookupPrivilegeValue(NULL, _privelegeName, &privilegyId))
|
||||
{
|
||||
TOKEN_PRIVILEGES tokenPrivilege;
|
||||
tokenPrivilege.PrivilegeCount = 1;
|
||||
@ -262,18 +261,45 @@ namespace profiler {
|
||||
tokenPrivilege.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
success = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivilege, sizeof(TOKEN_PRIVILEGES), NULL, NULL) != FALSE;
|
||||
}
|
||||
|
||||
CloseHandle(hToken);
|
||||
}
|
||||
|
||||
#if EASY_LOG_ENABLED != 0
|
||||
if (!success)
|
||||
::std::cerr << "Warning: EasyProfiler failed to set Debug privelege for the application. Some context switch events could not get process name.\n";
|
||||
::std::cerr << "Warning: EasyProfiler failed to set " << _privelegeName << " privelege for the application.\n";
|
||||
#endif
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void EasyEventTracer::setProcessPrivileges()
|
||||
{
|
||||
static bool alreadySet = false;
|
||||
if (alreadySet)
|
||||
return;
|
||||
|
||||
alreadySet = true;
|
||||
|
||||
HANDLE hToken = nullptr;
|
||||
if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
|
||||
{
|
||||
#if EASY_LOG_ENABLED != 0
|
||||
const bool success = setPrivilege(hToken, SE_DEBUG_NAME);
|
||||
if (!success)
|
||||
::std::cerr << "Warning: Some context switch events could not get process name.\n";
|
||||
#else
|
||||
setPrivilege(hToken, SE_DEBUG_NAME);
|
||||
#endif
|
||||
|
||||
CloseHandle(hToken);
|
||||
}
|
||||
#if EASY_LOG_ENABLED != 0
|
||||
else
|
||||
{
|
||||
::std::cerr << "Warning: EasyProfiler failed to open process to adjust priveleges.\n";
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
::profiler::EventTracingEnableStatus EasyEventTracer::startTrace(bool _force, int _step)
|
||||
{
|
||||
auto startTraceResult = StartTrace(&m_sessionHandle, KERNEL_LOGGER_NAME, props());
|
||||
@ -355,12 +381,8 @@ namespace profiler {
|
||||
/*
|
||||
Trying to set debug privilege for current process
|
||||
to be able to get other process information (process name).
|
||||
|
||||
Also it seems that debug privelege lets you to launch
|
||||
event tracing without Administrator access rights.
|
||||
*/
|
||||
if (!m_bPrivilegeSet)
|
||||
m_bPrivilegeSet = setDebugPrivilege();
|
||||
EasyEventTracer::setProcessPrivileges();
|
||||
|
||||
// Clear properties
|
||||
memset(&m_properties, 0, sizeof(m_properties));
|
||||
|
@ -85,7 +85,6 @@ namespace profiler {
|
||||
TRACEHANDLE m_sessionHandle = INVALID_PROCESSTRACE_HANDLE;
|
||||
TRACEHANDLE m_openedHandle = INVALID_PROCESSTRACE_HANDLE;
|
||||
bool m_bEnabled = false;
|
||||
bool m_bPrivilegeSet = false;
|
||||
|
||||
public:
|
||||
|
||||
@ -97,6 +96,7 @@ namespace profiler {
|
||||
::profiler::EventTracingEnableStatus enable(bool _force = false);
|
||||
void disable();
|
||||
void setLowPriority(bool _value);
|
||||
static void setProcessPrivileges();
|
||||
|
||||
private:
|
||||
|
||||
@ -108,7 +108,6 @@ namespace profiler {
|
||||
}
|
||||
|
||||
::profiler::EventTracingEnableStatus startTrace(bool _force, int _step = 0);
|
||||
bool setDebugPrivilege();
|
||||
|
||||
}; // END of class EasyEventTracer.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user