-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlatformUtils.h
More file actions
76 lines (57 loc) · 1.95 KB
/
Copy pathPlatformUtils.h
File metadata and controls
76 lines (57 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
#ifdef __APPLE__
#include "MemBuffer.h"
#include <CoreFoundation/CoreFoundation.h>
#include <sys/sysctl.h>
#endif
NS_BEGIN
// Platform specific utilities
#ifdef _WIN32
CStr GetUsername(const uint32_t nSessionId);
CStr SidToAccountName(const CStr &strSid);
bool IsValidSidW(const CStrW &strSid);
struct ComputerUser final
{
CStr strUsername;
CFilePath pathHomeDir;
CStr strSid;
};
std::vector<ComputerUser> GetComputerUsers(void);
HMODULE SystemLoadLibrary(PCWSTR szModuleName);
bool LoadUserRegistryHive(PCNSTR szKeyName, PCNSTR szHiveFilename);
bool UnloadUserRegistryHive(PCNSTR szKeyName);
HRESULT ComInit(const bool bMultithreaded = true);
HRESULT ComInitEx(const bool bMultithreaded = true, const DWORD dwAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT);
void ComFree(void);
bool GetRemoteTZOffset(const CStrW &strMachine, int16_t &nOffset);
#elif __APPLE__
enum EPrivilegeLevel : uint8_t
{
EPL_Unknown = 0,
EPL_Denied,
EPL_Granted
};
EPrivilegeLevel CheckFullDiskAccess(void);
ERRCODE GetIORegistryString(PCSTR szPath, PCSTR szKey, CStr &strValue);
ERRCODE GetIORegistryData(PCSTR szPath, PCSTR szKey, CMemBuffer &bufValue);
bool GetSysctlValue(const int nLevel1, const int nLevel2, CStr &str);
bool GetSysctlValue(PCNSTR szName, CStr &str);
//#################################################################################################
template<typename INTTYPE>
bool GetSysctlValue(const int nLevel1, const int nLevel2, INTTYPE &n)
{
n = 0;
int mib[2] = {nLevel1, nLevel2};
size_t nDataSize = sizeof(n);
return (sysctl(mib, COUNTOF(mib), &n, &nDataSize, nullptr, 0) == 0);
}
//#################################################################################################
template<typename INTTYPE>
bool GetSysctlValue(PCNSTR szName, INTTYPE &n)
{
n = 0;
size_t nDataSize = sizeof(n);
return (sysctlbyname(szName, &n, &nDataSize, nullptr, 0) == 0);
}
#endif
NS_END