[*] Further reduce win32 link time requirements (advanced api)
This commit is contained in:
parent
33f77cf011
commit
ff77873ad6
@ -169,6 +169,20 @@ namespace Aurora
|
|||||||
ADD_GET_PROC(AdvancedApi, CryptReleaseContext)
|
ADD_GET_PROC(AdvancedApi, CryptReleaseContext)
|
||||||
ADD_GET_PROC(AdvancedApi, CryptGenRandom)
|
ADD_GET_PROC(AdvancedApi, CryptGenRandom)
|
||||||
|
|
||||||
|
ADD_GET_PROC(AdvancedApi, RegSetValueExW)
|
||||||
|
ADD_GET_PROC(AdvancedApi, RegCloseKey)
|
||||||
|
ADD_GET_PROC(AdvancedApi, RegOpenKeyExW)
|
||||||
|
ADD_GET_PROC(AdvancedApi, RegQueryValueExW)
|
||||||
|
|
||||||
|
ADD_GET_PROC(AdvancedApi, DeregisterEventSource)
|
||||||
|
ADD_GET_PROC(AdvancedApi, RegisterEventSourceW)
|
||||||
|
ADD_GET_PROC(AdvancedApi, ReportEventW)
|
||||||
|
|
||||||
|
ADD_GET_PROC(AdvancedApi, SetEntriesInAclA)
|
||||||
|
ADD_GET_PROC(AdvancedApi, AllocateAndInitializeSid)
|
||||||
|
ADD_GET_PROC(AdvancedApi, SetNamedSecurityInfoW)
|
||||||
|
ADD_GET_PROC(AdvancedApi, FreeSid)
|
||||||
|
|
||||||
ADD_GET_PROC_INTERNAL_MAP(AdvancedApi, RtlGenRandom, SystemFunction036)
|
ADD_GET_PROC_INTERNAL_MAP(AdvancedApi, RtlGenRandom, SystemFunction036)
|
||||||
|
|
||||||
ADD_GET_PROC(BCrypt, BCryptGenRandom)
|
ADD_GET_PROC(BCrypt, BCryptGenRandom)
|
||||||
|
@ -17,6 +17,9 @@ struct _MINIDUMP_CALLBACK_INFORMATION;
|
|||||||
struct _MIB_IPADDRTABLE;
|
struct _MIB_IPADDRTABLE;
|
||||||
struct _IP_ADAPTER_INFO;
|
struct _IP_ADAPTER_INFO;
|
||||||
struct _CREATEFILE2_EXTENDED_PARAMETERS;
|
struct _CREATEFILE2_EXTENDED_PARAMETERS;
|
||||||
|
struct _EXPLICIT_ACCESS_A;
|
||||||
|
struct _ACL;
|
||||||
|
enum _SE_OBJECT_TYPE;
|
||||||
enum _MINIDUMP_TYPE;
|
enum _MINIDUMP_TYPE;
|
||||||
|
|
||||||
#if defined(AURORA_COMPILER_MSVC)
|
#if defined(AURORA_COMPILER_MSVC)
|
||||||
@ -292,32 +295,12 @@ namespace Aurora
|
|||||||
ULONG Flags
|
ULONG Flags
|
||||||
);
|
);
|
||||||
|
|
||||||
inline NTSTATUS(__stdcall *pBCryptGenRandom)(
|
|
||||||
PVOID hAlgorithm,
|
|
||||||
PUCHAR pbBuffer,
|
|
||||||
ULONG cbBuffer,
|
|
||||||
ULONG dwFlags
|
|
||||||
);
|
|
||||||
|
|
||||||
inline BOOL(__stdcall *pCryptGenRandom)(
|
inline BOOL(__stdcall *pCryptGenRandom)(
|
||||||
ULONG_PTR hProv,
|
ULONG_PTR hProv,
|
||||||
DWORD dwLen,
|
DWORD dwLen,
|
||||||
BYTE *pbBuffer
|
BYTE *pbBuffer
|
||||||
);
|
);
|
||||||
|
|
||||||
inline BOOL(__stdcall *pCryptAcquireContextW)(
|
|
||||||
ULONG_PTR * hProv,
|
|
||||||
LPCWSTR szContainer,
|
|
||||||
LPCWSTR szProvider,
|
|
||||||
DWORD dwProvType,
|
|
||||||
DWORD dwFlags
|
|
||||||
);
|
|
||||||
|
|
||||||
inline BOOL(__stdcall *pCryptReleaseContext)(
|
|
||||||
ULONG_PTR hProvz,
|
|
||||||
DWORD dwFlags
|
|
||||||
);
|
|
||||||
|
|
||||||
inline NTSTATUS(__stdcall *pZwSetTimerResolution)(
|
inline NTSTATUS(__stdcall *pZwSetTimerResolution)(
|
||||||
ULONG RequestedResolution,
|
ULONG RequestedResolution,
|
||||||
BOOLEAN Set,
|
BOOLEAN Set,
|
||||||
@ -438,6 +421,13 @@ namespace Aurora
|
|||||||
HANDLE hThread
|
HANDLE hThread
|
||||||
);
|
);
|
||||||
|
|
||||||
|
inline NTSTATUS(__stdcall *pBCryptGenRandom)(
|
||||||
|
PVOID hAlgorithm,
|
||||||
|
PUCHAR pbBuffer,
|
||||||
|
ULONG cbBuffer,
|
||||||
|
ULONG dwFlags
|
||||||
|
);
|
||||||
|
|
||||||
// dbghelp
|
// dbghelp
|
||||||
|
|
||||||
inline DWORD(__stdcall *pUnDecorateSymbolName)(
|
inline DWORD(__stdcall *pUnDecorateSymbolName)(
|
||||||
@ -583,6 +573,108 @@ namespace Aurora
|
|||||||
int * pNumArgs
|
int * pNumArgs
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Advanced API
|
||||||
|
|
||||||
|
inline LSTATUS(__stdcall *pRegSetValueExW)(
|
||||||
|
HKEY hKey,
|
||||||
|
LPCWSTR lpValueName,
|
||||||
|
DWORD Reserved,
|
||||||
|
DWORD dwType,
|
||||||
|
CONST BYTE * lpData,
|
||||||
|
DWORD cbData
|
||||||
|
);
|
||||||
|
|
||||||
|
inline LSTATUS(__stdcall *pRegQueryValueExW)(
|
||||||
|
HKEY hKey,
|
||||||
|
LPCWSTR lpValueName,
|
||||||
|
LPDWORD lpReserved,
|
||||||
|
LPDWORD lpType,
|
||||||
|
LPBYTE lpData,
|
||||||
|
LPDWORD lpcbData
|
||||||
|
);
|
||||||
|
|
||||||
|
inline LSTATUS(__stdcall *pRegCloseKey)(
|
||||||
|
HKEY hKey
|
||||||
|
);
|
||||||
|
|
||||||
|
inline LSTATUS(__stdcall *pRegOpenKeyExW)(
|
||||||
|
HKEY hKey,
|
||||||
|
LPCWSTR lpSubKey,
|
||||||
|
DWORD ulOptions,
|
||||||
|
REGSAM samDesired,
|
||||||
|
PHKEY phkResult
|
||||||
|
);
|
||||||
|
|
||||||
|
inline HANDLE(__stdcall *pRegisterEventSourceW)(
|
||||||
|
LPCWSTR lpUNCServerName,
|
||||||
|
LPCWSTR lpSourceName
|
||||||
|
);
|
||||||
|
|
||||||
|
inline BOOL(__stdcall *pDeregisterEventSource)(
|
||||||
|
HANDLE hEventLog
|
||||||
|
);
|
||||||
|
|
||||||
|
inline BOOL(__stdcall *pReportEventW)(
|
||||||
|
HANDLE hEventLog,
|
||||||
|
WORD wType,
|
||||||
|
WORD wCategory,
|
||||||
|
DWORD dwEventID,
|
||||||
|
PSID lpUserSid,
|
||||||
|
WORD wNumStrings,
|
||||||
|
DWORD dwDataSize,
|
||||||
|
LPCWSTR * lpStrings,
|
||||||
|
LPVOID lpRawData
|
||||||
|
);
|
||||||
|
|
||||||
|
inline BOOL(__stdcall *pCryptAcquireContextW)(
|
||||||
|
ULONG_PTR * hProv,
|
||||||
|
LPCWSTR szContainer,
|
||||||
|
LPCWSTR szProvider,
|
||||||
|
DWORD dwProvType,
|
||||||
|
DWORD dwFlags
|
||||||
|
);
|
||||||
|
|
||||||
|
inline BOOL(__stdcall *pCryptReleaseContext)(
|
||||||
|
ULONG_PTR hProvz,
|
||||||
|
DWORD dwFlags
|
||||||
|
);
|
||||||
|
|
||||||
|
inline DWORD(__stdcall *pSetEntriesInAclA)(
|
||||||
|
ULONG cCountOfExplicitEntries,
|
||||||
|
_EXPLICIT_ACCESS_A * pListOfExplicitEntries,
|
||||||
|
_ACL * OldAcl,
|
||||||
|
_ACL ** NewAcl
|
||||||
|
);
|
||||||
|
|
||||||
|
inline BOOL(__stdcall *pAllocateAndInitializeSid)(
|
||||||
|
PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
|
||||||
|
BYTE nSubAuthorityCount,
|
||||||
|
DWORD nSubAuthority0,
|
||||||
|
DWORD nSubAuthority1,
|
||||||
|
DWORD nSubAuthority2,
|
||||||
|
DWORD nSubAuthority3,
|
||||||
|
DWORD nSubAuthority4,
|
||||||
|
DWORD nSubAuthority5,
|
||||||
|
DWORD nSubAuthority6,
|
||||||
|
DWORD nSubAuthority7,
|
||||||
|
VOID ** pSid
|
||||||
|
);
|
||||||
|
|
||||||
|
inline DWORD(__stdcall *pSetNamedSecurityInfoW)(
|
||||||
|
LPWSTR pObjectName,
|
||||||
|
_SE_OBJECT_TYPE ObjectType,
|
||||||
|
SECURITY_INFORMATION SecurityInfo,
|
||||||
|
VOID * psidOwner,
|
||||||
|
VOID * psidGroup,
|
||||||
|
_ACL * pDacl,
|
||||||
|
_ACL * pSacl
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
inline PVOID(__stdcall *pFreeSid)(
|
||||||
|
VOID * pSid
|
||||||
|
);
|
||||||
|
|
||||||
inline bool gUseNativeWaitMutex {};
|
inline bool gUseNativeWaitMutex {};
|
||||||
inline bool gUseNativeWaitCondvar {};
|
inline bool gUseNativeWaitCondvar {};
|
||||||
inline bool gUseNativeWaitSemapahore {};
|
inline bool gUseNativeWaitSemapahore {};
|
||||||
|
@ -546,11 +546,18 @@ namespace Aurora::Debug
|
|||||||
auto procNameWide = AuLocale::ConvertFromUTF8(procName);
|
auto procNameWide = AuLocale::ConvertFromUTF8(procName);
|
||||||
|
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
if (::RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\ExcludedApplications", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS)
|
if (pRegOpenKeyExW &&
|
||||||
|
pRegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting\\ExcludedApplications", 0, KEY_WRITE, &hKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
DWORD bioluminescenceReductionFactor { 1 };
|
DWORD bioluminescenceReductionFactor { 1 };
|
||||||
(void)::RegSetValueExW(hKey, procNameWide.c_str(), 0, REG_DWORD, (const BYTE *)&bioluminescenceReductionFactor, sizeof(DWORD));
|
if (pRegSetValueExW)
|
||||||
::RegCloseKey(hKey);
|
{
|
||||||
|
(void)pRegSetValueExW(hKey, procNameWide.c_str(), 0, REG_DWORD, (const BYTE *)&bioluminescenceReductionFactor, sizeof(DWORD));
|
||||||
|
}
|
||||||
|
if (pRegCloseKey)
|
||||||
|
{
|
||||||
|
pRegCloseKey(hKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -490,12 +490,18 @@ namespace Aurora::IO::FS
|
|||||||
SID_IDENTIFIER_AUTHORITY SIDAuthWorld =
|
SID_IDENTIFIER_AUTHORITY SIDAuthWorld =
|
||||||
SECURITY_WORLD_SID_AUTHORITY;
|
SECURITY_WORLD_SID_AUTHORITY;
|
||||||
const int NUM_ACES = 1;
|
const int NUM_ACES = 1;
|
||||||
EXPLICIT_ACCESS ea[NUM_ACES];
|
EXPLICIT_ACCESS_A ea[NUM_ACES];
|
||||||
DWORD dwRes;
|
DWORD dwRes;
|
||||||
|
|
||||||
|
if (!pAllocateAndInitializeSid)
|
||||||
|
{
|
||||||
|
SysPushErrorFIO("AllocateAndInitializeSid (Everyone) error");
|
||||||
|
goto Cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
// Specify the DACL to use.
|
// Specify the DACL to use.
|
||||||
// Create a SID for the Everyone group.
|
// Create a SID for the Everyone group.
|
||||||
if (!AllocateAndInitializeSid(&SIDAuthWorld, 1,
|
if (!pAllocateAndInitializeSid(&SIDAuthWorld, 1,
|
||||||
SECURITY_WORLD_RID,
|
SECURITY_WORLD_RID,
|
||||||
0,
|
0,
|
||||||
0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0,
|
||||||
@ -505,7 +511,7 @@ namespace Aurora::IO::FS
|
|||||||
goto Cleanup;
|
goto Cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMemory(&ea, NUM_ACES * sizeof(EXPLICIT_ACCESS));
|
ZeroMemory(&ea, NUM_ACES * sizeof(EXPLICIT_ACCESS_A));
|
||||||
|
|
||||||
// Set read access for Everyone.
|
// Set read access for Everyone.
|
||||||
ea[0].grfAccessPermissions = GENERIC_ALL;
|
ea[0].grfAccessPermissions = GENERIC_ALL;
|
||||||
@ -515,7 +521,13 @@ namespace Aurora::IO::FS
|
|||||||
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
|
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
|
||||||
ea[0].Trustee.ptstrName = (LPTSTR) pSIDEveryone;
|
ea[0].Trustee.ptstrName = (LPTSTR) pSIDEveryone;
|
||||||
|
|
||||||
if (ERROR_SUCCESS != SetEntriesInAcl(NUM_ACES,
|
if (!pSetEntriesInAclA)
|
||||||
|
{
|
||||||
|
SysPushErrorFIO("Failed SetEntriesInAcl");
|
||||||
|
goto Cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ERROR_SUCCESS != pSetEntriesInAclA(NUM_ACES,
|
||||||
ea,
|
ea,
|
||||||
NULL,
|
NULL,
|
||||||
&pACL))
|
&pACL))
|
||||||
@ -524,8 +536,14 @@ namespace Aurora::IO::FS
|
|||||||
goto Cleanup;
|
goto Cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!pSetNamedSecurityInfoW)
|
||||||
|
{
|
||||||
|
SysPushErrorFIO("Failed SetNamedSecurityInfoW");
|
||||||
|
goto Cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
// Try to modify the object's DACL.
|
// Try to modify the object's DACL.
|
||||||
dwRes = SetNamedSecurityInfoW(
|
dwRes = pSetNamedSecurityInfoW(
|
||||||
Locale::ConvertFromUTF8(FS::NormalizePathRet(path)).data(), // name of the object
|
Locale::ConvertFromUTF8(FS::NormalizePathRet(path)).data(), // name of the object
|
||||||
SE_FILE_OBJECT, // type of object
|
SE_FILE_OBJECT, // type of object
|
||||||
DACL_SECURITY_INFORMATION, // change only the object's DACL
|
DACL_SECURITY_INFORMATION, // change only the object's DACL
|
||||||
@ -549,7 +567,10 @@ namespace Aurora::IO::FS
|
|||||||
|
|
||||||
if (pSIDEveryone)
|
if (pSIDEveryone)
|
||||||
{
|
{
|
||||||
FreeSid(pSIDEveryone);
|
if (pFreeSid)
|
||||||
|
{
|
||||||
|
pFreeSid(pSIDEveryone);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pACL)
|
if (pACL)
|
||||||
@ -559,7 +580,7 @@ namespace Aurora::IO::FS
|
|||||||
|
|
||||||
if (hToken)
|
if (hToken)
|
||||||
{
|
{
|
||||||
CloseHandle(hToken);
|
AuWin32CloseHandle(hToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bRetval)
|
if (!bRetval)
|
||||||
|
@ -14,12 +14,14 @@ namespace Aurora::Logging::Sinks
|
|||||||
|
|
||||||
EventLogSink::EventLogSink(const AuString &value)
|
EventLogSink::EventLogSink(const AuString &value)
|
||||||
{
|
{
|
||||||
this->winCurrentSink_ = RegisterEventSourceW(NULL, Locale::ConvertFromUTF8(value).c_str());
|
SysAssert(pRegisterEventSourceW);
|
||||||
|
this->winCurrentSink_ = pRegisterEventSourceW(NULL, Locale::ConvertFromUTF8(value).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
EventLogSink::~EventLogSink()
|
EventLogSink::~EventLogSink()
|
||||||
{
|
{
|
||||||
DeregisterEventSource(winCurrentSink_);
|
SysAssert(pDeregisterEventSource);
|
||||||
|
pDeregisterEventSource(winCurrentSink_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +106,12 @@ namespace Aurora::Logging::Sinks
|
|||||||
{
|
{
|
||||||
auto &strs = AuGet<1>(sortedMessages);
|
auto &strs = AuGet<1>(sortedMessages);
|
||||||
auto handle = strs.data();
|
auto handle = strs.data();
|
||||||
ReportEventW(this->winCurrentSink_, AuGet<0>(sortedMessages), 0, kMagicEventNumber, NULL, 1, 0, (CONST WCHAR **)&handle, NULL);
|
|
||||||
|
if (!pReportEventW)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pReportEventW(this->winCurrentSink_, AuGet<0>(sortedMessages), 0, kMagicEventNumber, NULL, 1, 0, (CONST WCHAR **)&handle, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->winCompleteArrayBuffer_.clear();
|
this->winCompleteArrayBuffer_.clear();
|
||||||
@ -112,6 +119,11 @@ namespace Aurora::Logging::Sinks
|
|||||||
|
|
||||||
IBasicSink *NewOSNamedEventDirectorySinkNew(const AuString &name)
|
IBasicSink *NewOSNamedEventDirectorySinkNew(const AuString &name)
|
||||||
{
|
{
|
||||||
|
if (!pReportEventW)
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _new EventLogSink(name);
|
return _new EventLogSink(name);
|
||||||
|
@ -45,7 +45,8 @@ namespace Aurora::SWInfo
|
|||||||
{
|
{
|
||||||
DWORD dwBufferSize {};
|
DWORD dwBufferSize {};
|
||||||
|
|
||||||
if (RegQueryValueExW(hKey, pWideKey, 0, NULL, NULL, &dwBufferSize) != ERROR_SUCCESS)
|
if (!pRegQueryValueExW ||
|
||||||
|
pRegQueryValueExW(hKey, pWideKey, 0, NULL, NULL, &dwBufferSize) != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
SysPushErrorUnavailableError("Couldn't access registery key");
|
SysPushErrorUnavailableError("Couldn't access registery key");
|
||||||
return false;
|
return false;
|
||||||
@ -59,7 +60,8 @@ namespace Aurora::SWInfo
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RegQueryValueExW(hKey, pWideKey, 0, NULL, reinterpret_cast<LPBYTE>(in.data()), &dwBufferSize) != ERROR_SUCCESS)
|
if (!pRegQueryValueExW ||
|
||||||
|
pRegQueryValueExW(hKey, pWideKey, 0, NULL, reinterpret_cast<LPBYTE>(in.data()), &dwBufferSize) != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
SysPushErrorUnavailableError("Couldn't access registery key");
|
SysPushErrorUnavailableError("Couldn't access registery key");
|
||||||
return false;
|
return false;
|
||||||
@ -140,14 +142,21 @@ namespace Aurora::SWInfo
|
|||||||
|
|
||||||
#if defined(AURORA_PLATFORM_WIN32)
|
#if defined(AURORA_PLATFORM_WIN32)
|
||||||
HKEY hKey;
|
HKEY hKey;
|
||||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
if (pRegOpenKeyExW &&
|
||||||
|
pRegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!Win32ReadRegistry(hKey, L"BuildLabEx", gBuildString))
|
if (!Win32ReadRegistry(hKey, L"BuildLabEx", gBuildString))
|
||||||
{
|
{
|
||||||
Win32ReadRegistry(hKey, L"BuildLab", gBuildString);
|
Win32ReadRegistry(hKey, L"BuildLab", gBuildString);
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32ReadRegistry(hKey, L"ProductName", gUserlandBrand);
|
Win32ReadRegistry(hKey, L"ProductName", gUserlandBrand);
|
||||||
RegCloseKey(hKey);
|
|
||||||
|
if (pRegCloseKey)
|
||||||
|
{
|
||||||
|
pRegCloseKey(hKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user