PspReadUserQuotaLimits
NTSTATUS __stdcall PspReadUserQuotaLimits(VOID *UserSid, UINT64 *UseDefault, PS_QUOTA_LIMIT *Limits){
int v3;
VOID *v6;
int v7;
INT64 v8;
NTSTATUS v10;
signed __int64 v11;
unsigned int v12;
PS_QUOTA_LIMIT *v13;
PS_QUOTA_LIMIT v14;
_UNICODE_STRING *Class;
_UNICODE_STRING *Classa;
UINT64 CreateOptions;
UINT64 *Disposition;
INT64 v19;
VOID *Handle;
VOID *KeyHandle;
UINT64 ResultLength;
_OBJECT_ATTRIBUTES ObjectAttributes;
UINT64 *v24;
_UNICODE_STRING UnicodeString;
__int128 KeyValueInformation;
int v27;
v3 = 0;
v24 = UseDefault;
LODWORD(ResultLength) = 0;
KeyHandle = 0i64;
KeyValueInformation = 0i64;
v27 = 0;
*(_OWORD *)&ObjectAttributes.Length = 0i64;
*(_DWORD *)UseDefault = 1;
v6 = (VOID *)PspQuotaDatabaseKey;
Handle = (VOID *)PspQuotaDatabaseKey;
memset(&ObjectAttributes.ObjectName, 0, 32);
UnicodeString = 0i64;
if( !PspQuotaDatabaseKey )
{
LODWORD(CreateOptions) = 0;
ObjectAttributes.Length = 48;
ObjectAttributes.RootDirectory = 0i64;
ObjectAttributes.Attributes = 704;
ObjectAttributes.ObjectName = (_UNICODE_STRING *)PspQuotaKeyNames;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
v10 = ZwCreateKey(&Handle, 9ui64, &ObjectAttributes, 0i64, 0i64, CreateOptions, 0i64);
v11 = (signed __int64)Handle;
if( v10 < 0 )
v11 = 1i64;
Handle = (VOID *)v11;
v6 = (VOID *)_InterlockedCompareExchange64(&PspQuotaDatabaseKey, v11, 0i64);
if( v6 )
{
if( Handle != (VOID *)1 )
ZwClose((_HANDLE)Handle);
Handle = v6;
}
else
{
v6 = Handle;
}
}
if( v6 == (VOID *)1 )
return 0;
v7 = RtlConvertSidToUnicodeString(&UnicodeString, UserSid, 1u);
if( v7 >= 0 )
{
ObjectAttributes.RootDirectory = Handle;
ObjectAttributes.Length = 48;
ObjectAttributes.ObjectName = &UnicodeString;
ObjectAttributes.Attributes = 704;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
v7 = ZwOpenKey(&KeyHandle, 1ui64, &ObjectAttributes, v8, (INT64)Class, CreateOptions, (INT64)Disposition, v19);
RtlFreeAnsiString(&UnicodeString);
if( v7 >= 0 )
{
v12 = 0;
v13 = Limits;
do
{
LODWORD(Classa) = 20;
v7 = ZwQueryValueKey(
KeyHandle,
(_UNICODE_STRING *)&PspDefaultResourceNames[8 * v3],
KeyValuePartialInformation,
&KeyValueInformation,
(UINT64)Classa,
&ResultLength);
if( (int)(v7 + 0x80000000) >= 0 && v7 != -1073741772 )
{
ZwClose((_HANDLE)KeyHandle);
return v7;
}
if( v7 == -1073741772 || *(_QWORD *)((char *)&KeyValueInformation + 4) != 0x400000004i64 )
{
v14 = *(PS_QUOTA_LIMIT *)((char *)v13 + (char *)PspDefaultResourceLimits - (char *)Limits);
++v12;
}
else
{
v14 = HIDWORD(KeyValueInformation);
}
*v13 = v14;
++v3;
++v13;
}
while( v3 < 4 );
ZwClose((_HANDLE)KeyHandle);
if( v12 < 4 )
{
v7 = PspSanitizeResourceLimits(Limits, 0i64);
if( v7 < 0 )
return v7;
*(_DWORD *)v24 = 0;
}
return 0;
}
if( v7 == -1073741772 )
return 0;
}
return v7;
}Referenced by:
PspAssignProcessQuotaBlock