83#if _M_IX86 || __i386__
84 static constexpr platform_id process_platform = platform_id::i386;
85#elif _M_X64 || __x86_64__
86 static constexpr platform_id process_platform = platform_id::x86_64;
87#elif _M_ARM || __arm__
88 static constexpr platform_id process_platform = platform_id::arm;
89#elif _M_ARM64 || __aarch64__
90 static constexpr platform_id process_platform = platform_id::aarch64;
92 #error Unknown platform
137 HMODULE kernel32_handle;
138 kernel32_handle = LoadLibrary(_T(
"kernel32.dll"));
139 stdex_assert(kernel32_handle);
140 BOOL(WINAPI * IsWow64Process2)(HANDLE hProcess, USHORT * pProcessMachine, USHORT * pNativeMachine);
141 *
reinterpret_cast<FARPROC*
>(&IsWow64Process2) = GetProcAddress(kernel32_handle,
"IsWow64Process2");
142 HANDLE process = GetCurrentProcess();
143 USHORT process_machine;
147 if (IsWow64Process2 && IsWow64Process2(process, &process_machine,
reinterpret_cast<USHORT*
>(&
os_platform))) {
148 wow64 = process_machine != IMAGE_FILE_MACHINE_UNKNOWN;
156 else if (IsWow64Process(process, &Wow64Process)) {
167 FreeLibrary(kernel32_handle);
169 memset(&m_utsn, 0,
sizeof(m_utsn));
170 if (uname(&m_utsn) != -1)
175 HWINSTA hWinSta = GetProcessWindowStation();
177 TCHAR sName[MAX_PATH];
178 if (GetUserObjectInformation(hWinSta, UOI_NAME, sName,
sizeof(sName), NULL)) {
179 sName[_countof(sName) - 1] = 0;
191 if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token_h)) {
194 TOKEN_ELEVATION elevation;
195 DWORD size =
sizeof(TOKEN_ELEVATION);
196 if (GetTokenInformation(token_h, TokenElevation, &elevation,
sizeof(elevation), &size))
197 elevated = elevation.TokenIsElevated;
199 GetTokenInformation(token.
get(), TokenGroups, NULL, 0, &size);
200 std::unique_ptr<TOKEN_GROUPS> groups((TOKEN_GROUPS*)
new uint8_t[size]);
201 if (GetTokenInformation(token.
get(), TokenGroups, (LPVOID)groups.get(), size, &size)) {
202 SID_IDENTIFIER_AUTHORITY authority = SECURITY_NT_AUTHORITY;
203 PSID sid_admins_h = NULL;
204 if (AllocateAndInitializeSid(&authority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &sid_admins_h)) {
205 struct SID_delete {
void operator()(_In_ PSID p)
const { FreeSid(p); } };
206 std::unique_ptr<void, SID_delete> sid_admins(sid_admins_h);
207 for (DWORD i = 0; i < groups->GroupCount; ++i)
208 if (EqualSid(sid_admins.get(), groups->Groups[i].Sid)) {
216#elif defined(__APPLE__)
218 gid_t gids[NGROUPS_MAX];
219 for (
int i = 0, n = getgroups(NGROUPS_MAX, gids); i < n; ++i) {
220 struct group* group = getgrgid(gids[i]);
221 if (!group)
continue;
222 if (strcmp(group->gr_name,
"admin") == 0) {
236#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL)
238 TCHAR szStackBuffer[0x100];
239 ULONG ulSize = _countof(szStackBuffer);
240 if (GetUserNameEx(NameSamCompatible, szStackBuffer, &ulSize))
241 username.assign(szStackBuffer, ulSize);
242 if (GetLastError() == ERROR_MORE_DATA) {
245 if (!GetUserNameEx(NameSamCompatible, &
username[0], &ulSize))
252 struct passwd *pw = getpwuid(geteuid());
253 if (pw && pw->pw_name)
266 return SystemParametersInfo(SPI_GETSCREENREADER, 0, &b, 0) && b;
274 struct utsname m_utsn;