[*] Further reduce win32 link time requirements (advanced api)

This commit is contained in:
Reece Wilson 2023-10-11 02:13:49 +01:00
parent 33f77cf011
commit ff77873ad6
6 changed files with 202 additions and 47 deletions

View File

@ -168,7 +168,21 @@ namespace Aurora
ADD_GET_PROC(AdvancedApi, CryptAcquireContextW)
ADD_GET_PROC(AdvancedApi, CryptReleaseContext)
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(BCrypt, BCryptGenRandom)

View File

@ -17,6 +17,9 @@ struct _MINIDUMP_CALLBACK_INFORMATION;
struct _MIB_IPADDRTABLE;
struct _IP_ADAPTER_INFO;
struct _CREATEFILE2_EXTENDED_PARAMETERS;
struct _EXPLICIT_ACCESS_A;
struct _ACL;
enum _SE_OBJECT_TYPE;
enum _MINIDUMP_TYPE;
#if defined(AURORA_COMPILER_MSVC)
@ -292,32 +295,12 @@ namespace Aurora
ULONG Flags
);
inline NTSTATUS(__stdcall *pBCryptGenRandom)(
PVOID hAlgorithm,
PUCHAR pbBuffer,
ULONG cbBuffer,
ULONG dwFlags
);
inline BOOL(__stdcall *pCryptGenRandom)(
ULONG_PTR hProv,
DWORD dwLen,
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)(
ULONG RequestedResolution,
BOOLEAN Set,
@ -438,6 +421,13 @@ namespace Aurora
HANDLE hThread
);
inline NTSTATUS(__stdcall *pBCryptGenRandom)(
PVOID hAlgorithm,
PUCHAR pbBuffer,
ULONG cbBuffer,
ULONG dwFlags
);
// dbghelp
inline DWORD(__stdcall *pUnDecorateSymbolName)(
@ -583,6 +573,108 @@ namespace Aurora
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 gUseNativeWaitCondvar {};
inline bool gUseNativeWaitSemapahore {};

View File

@ -546,11 +546,18 @@ namespace Aurora::Debug
auto procNameWide = AuLocale::ConvertFromUTF8(procName);
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 };
(void)::RegSetValueExW(hKey, procNameWide.c_str(), 0, REG_DWORD, (const BYTE *)&bioluminescenceReductionFactor, sizeof(DWORD));
::RegCloseKey(hKey);
if (pRegSetValueExW)
{
(void)pRegSetValueExW(hKey, procNameWide.c_str(), 0, REG_DWORD, (const BYTE *)&bioluminescenceReductionFactor, sizeof(DWORD));
}
if (pRegCloseKey)
{
pRegCloseKey(hKey);
}
}
#endif

View File

@ -490,22 +490,28 @@ namespace Aurora::IO::FS
SID_IDENTIFIER_AUTHORITY SIDAuthWorld =
SECURITY_WORLD_SID_AUTHORITY;
const int NUM_ACES = 1;
EXPLICIT_ACCESS ea[NUM_ACES];
EXPLICIT_ACCESS_A ea[NUM_ACES];
DWORD dwRes;
// Specify the DACL to use.
// Create a SID for the Everyone group.
if (!AllocateAndInitializeSid(&SIDAuthWorld, 1,
SECURITY_WORLD_RID,
0,
0, 0, 0, 0, 0, 0,
&pSIDEveryone))
if (!pAllocateAndInitializeSid)
{
SysPushErrorFIO("AllocateAndInitializeSid (Everyone) error");
goto Cleanup;
}
ZeroMemory(&ea, NUM_ACES * sizeof(EXPLICIT_ACCESS));
// Specify the DACL to use.
// Create a SID for the Everyone group.
if (!pAllocateAndInitializeSid(&SIDAuthWorld, 1,
SECURITY_WORLD_RID,
0,
0, 0, 0, 0, 0, 0,
&pSIDEveryone))
{
SysPushErrorFIO("AllocateAndInitializeSid (Everyone) error");
goto Cleanup;
}
ZeroMemory(&ea, NUM_ACES * sizeof(EXPLICIT_ACCESS_A));
// Set read access for Everyone.
ea[0].grfAccessPermissions = GENERIC_ALL;
@ -515,17 +521,29 @@ namespace Aurora::IO::FS
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName = (LPTSTR) pSIDEveryone;
if (ERROR_SUCCESS != SetEntriesInAcl(NUM_ACES,
ea,
NULL,
&pACL))
if (!pSetEntriesInAclA)
{
SysPushErrorFIO("Failed SetEntriesInAcl");
goto Cleanup;
}
if (ERROR_SUCCESS != pSetEntriesInAclA(NUM_ACES,
ea,
NULL,
&pACL))
{
SysPushErrorFIO("Failed SetEntriesInAcl");
goto Cleanup;
}
if (!pSetNamedSecurityInfoW)
{
SysPushErrorFIO("Failed SetNamedSecurityInfoW");
goto Cleanup;
}
// Try to modify the object's DACL.
dwRes = SetNamedSecurityInfoW(
dwRes = pSetNamedSecurityInfoW(
Locale::ConvertFromUTF8(FS::NormalizePathRet(path)).data(), // name of the object
SE_FILE_OBJECT, // type of object
DACL_SECURITY_INFORMATION, // change only the object's DACL
@ -549,7 +567,10 @@ namespace Aurora::IO::FS
if (pSIDEveryone)
{
FreeSid(pSIDEveryone);
if (pFreeSid)
{
pFreeSid(pSIDEveryone);
}
}
if (pACL)
@ -559,7 +580,7 @@ namespace Aurora::IO::FS
if (hToken)
{
CloseHandle(hToken);
AuWin32CloseHandle(hToken);
}
if (!bRetval)

View File

@ -14,12 +14,14 @@ namespace Aurora::Logging::Sinks
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()
{
DeregisterEventSource(winCurrentSink_);
SysAssert(pDeregisterEventSource);
pDeregisterEventSource(winCurrentSink_);
}
@ -104,7 +106,12 @@ namespace Aurora::Logging::Sinks
{
auto &strs = AuGet<1>(sortedMessages);
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();
@ -112,6 +119,11 @@ namespace Aurora::Logging::Sinks
IBasicSink *NewOSNamedEventDirectorySinkNew(const AuString &name)
{
if (!pReportEventW)
{
return {};
}
try
{
return _new EventLogSink(name);

View File

@ -45,7 +45,8 @@ namespace Aurora::SWInfo
{
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");
return false;
@ -59,7 +60,8 @@ namespace Aurora::SWInfo
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");
return false;
@ -140,14 +142,21 @@ namespace Aurora::SWInfo
#if defined(AURORA_PLATFORM_WIN32)
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))
{
Win32ReadRegistry(hKey, L"BuildLab", gBuildString);
}
Win32ReadRegistry(hKey, L"ProductName", gUserlandBrand);
RegCloseKey(hKey);
if (pRegCloseKey)
{
pRegCloseKey(hKey);
}
}
#endif