mirror of
https://github.com/decompals/wibo.git
synced 2025-12-14 23:56:16 +00:00
Remove advapi32/internal.cpp; move to relevant source files
This commit is contained in:
@@ -6,12 +6,77 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr WCHAR kAccountSystem[] = {u'S', u'Y', u'S', u'T', u'E', u'M', u'\0'};
|
||||
constexpr WCHAR kDomainNtAuthority[] = {u'N', u'T', u' ', u'A', u'U', u'T', u'H', u'O', u'R', u'I', u'T', u'Y', u'\0'};
|
||||
|
||||
std::mutex g_privilegeMapMutex;
|
||||
std::unordered_map<std::string, LUID> g_privilegeLuidCache;
|
||||
|
||||
bool isLocalSystemSid(const Sid *sid) {
|
||||
if (!sid) {
|
||||
return false;
|
||||
}
|
||||
if (sid->Revision != 1 || sid->SubAuthorityCount != 1) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < std::size(kNtAuthority); ++i) {
|
||||
if (sid->IdentifierAuthority.Value[i] != kNtAuthority[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return sid->SubAuthority[0] == SECURITY_LOCAL_SYSTEM_RID;
|
||||
}
|
||||
|
||||
std::string normalizePrivilegeName(const std::string &name) {
|
||||
std::string normalized;
|
||||
normalized.reserve(name.size());
|
||||
for (unsigned char ch : name) {
|
||||
normalized.push_back(static_cast<char>(std::tolower(ch)));
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
LUID generateDeterministicLuid(const std::string &normalizedName) {
|
||||
uint32_t hash = 2166136261u;
|
||||
for (unsigned char ch : normalizedName) {
|
||||
hash ^= ch;
|
||||
hash *= 16777619u;
|
||||
}
|
||||
if (hash == 0) {
|
||||
hash = 1;
|
||||
}
|
||||
LUID luid{};
|
||||
luid.LowPart = hash;
|
||||
luid.HighPart = 0;
|
||||
return luid;
|
||||
}
|
||||
|
||||
LUID lookupOrGeneratePrivilegeLuid(const std::string &normalizedName) {
|
||||
std::lock_guard<std::mutex> lock(g_privilegeMapMutex);
|
||||
static const std::unordered_map<std::string, uint32_t> predefined = {
|
||||
{"se_debug_name", 0x14},
|
||||
{"se_shutdown_name", 0x13},
|
||||
};
|
||||
auto it = g_privilegeLuidCache.find(normalizedName);
|
||||
if (it != g_privilegeLuidCache.end()) {
|
||||
return it->second;
|
||||
}
|
||||
LUID luid{};
|
||||
auto predefinedIt = predefined.find(normalizedName);
|
||||
if (predefinedIt != predefined.end()) {
|
||||
luid.LowPart = predefinedIt->second;
|
||||
luid.HighPart = 0;
|
||||
} else {
|
||||
luid = generateDeterministicLuid(normalizedName);
|
||||
}
|
||||
g_privilegeLuidCache[normalizedName] = luid;
|
||||
return luid;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace advapi32 {
|
||||
@@ -25,7 +90,7 @@ BOOL WIN_FUNC LookupAccountSidW(LPCWSTR lpSystemName, PSID Sid, LPWSTR Name, LPD
|
||||
wibo::lastError = ERROR_INVALID_PARAMETER;
|
||||
return FALSE;
|
||||
}
|
||||
auto *sidStruct = reinterpret_cast<const ::advapi32::Sid *>(Sid);
|
||||
auto *sidStruct = reinterpret_cast<const struct Sid *>(Sid);
|
||||
if (!isLocalSystemSid(sidStruct)) {
|
||||
wibo::lastError = ERROR_NONE_MAPPED;
|
||||
return FALSE;
|
||||
|
||||
Reference in New Issue
Block a user