BOOLEAN GetRegisterSID(UNICODE_STRING& uStringSID)
{
BOOLEAN bRet = FALSE;
UNICODE_STRING uRegSID;
RtlInitUnicodeString(&uRegSID, L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList");
OBJECT_ATTRIBUTES ObjAttributes;
InitializeObjectAttributes(&ObjAttributes, &uRegSID, OBJ_CASE_INSENSITIVE, NULL, NULL);
HANDLE hRegister = NULL;
NTSTATUS status = ZwOpenKey(&hRegister, KEY_ALL_ACCESS, &ObjAttributes);
if ((NT_SUCCESS(status)) && (NULL != hRegister))
{
ULONG uKeySize = 0;
status = ZwQueryKey(hRegister, KeyFullInformation, NULL, 0, &uKeySize);
if (uKeySize > 0)
{
PKEY_FULL_INFORMATION pFullInfo = (PKEY_FULL_INFORMATION)ExAllocatePool(PagedPool, uKeySize);
if (NULL != pFullInfo)
{
RtlZeroMemory(pFullInfo, uKeySize);
ULONG uRelust = 0;
status = ZwQueryKey(hRegister, KeyFullInformation, pFullInfo, uKeySize, &uRelust);
for (ULONG i = 0; i < pFullInfo->SubKeys; i++)
{
status = ZwEnumerateKey(hRegister, i, KeyBasicInformation, NULL, 0, &uRelust);
if (uRelust > 0)
{//SID
PKEY_BASIC_INFORMATION pBaseInfo = (PKEY_BASIC_INFORMATION)ExAllocatePool(PagedPool, uRelust);
if (NULL != pBaseInfo)
{
RtlZeroMemory(pBaseInfo, uRelust);
if (NT_SUCCESS(ZwEnumerateKey(hRegister, i, KeyBasicInformation, pBaseInfo, uRelust, &uRelust)))
{
if (pBaseInfo->NameLength > 20)
{
RtlCopyMemory(uStringSID.Buffer, pBaseInfo->Name, pBaseInfo->NameLength);
uStringSID.Length = (USHORT)pBaseInfo->NameLength;
bRet = true;
break;
}
}
ExFreePool(pBaseInfo);
}
}
}
ExFreePool(pFullInfo);
}
}
ZwClose(hRegister);
}
return bRet;
}