CmpGetAcpiProfileInformation
__int64 __fastcall CmpGetAcpiProfileInformation(
void *a1,
__int64 a2,
__int64 a3,
__int64 a4,
VOID *KeyValueInformation){
unsigned int v5;
INT64 v9;
NTSTATUS v10;
VOID **PoolWithTag;
unsigned int v12;
INT64 v13;
unsigned int v14;
VOID **v15;
size_t v16;
size_t v17;
__int128 *v18;
int v19;
_DWORD *v20;
unsigned int v21;
unsigned int v22;
unsigned int v23;
__int64 v24;
__int128 v25;
__int64 v26;
INT64 v27;
VOID **v28;
INT64 v29;
unsigned int v30;
VOID **v31;
size_t v32;
VOID *v33;
_DWORD *v35;
unsigned int v36;
void *v37;
_DWORD *v38;
unsigned int v39;
void *v40;
UINT64 *ResultLength;
UINT64 *ResultLengtha;
UINT64 *ResultLengthb;
UINT64 *ResultLengthc;
UINT64 *ResultLengthd;
UINT64 *ResultLengthe;
UINT64 *ResultLengthf;
UINT64 *ResultLengthg;
UINT64 *ResultLengthh;
UINT64 *ResultLengthi;
INT64 v51;
INT64 v52;
INT64 v53;
INT64 v54;
INT64 v55;
_UNICODE_STRING DestinationString;
VOID *Handle;
VOID *KeyHandle;
__int128 v59;
UINT64 Value[2];
_OBJECT_ATTRIBUTES ObjectAttributes;
__int128 v62;
__int128 KeyInformation;
__int128 v64;
__int128 v65;
v5 = 0;
*(_QWORD *)a2 = 0i64;
Handle = 0i64;
KeyHandle = 0i64;
v55 = 0i64;
LODWORD(v54) = 0;
*(_QWORD *)&ObjectAttributes.Length = 48i64;
*(_QWORD *)&ObjectAttributes.Attributes = 576i64;
DestinationString = 0i64;
*(_QWORD *)a3 = 0i64;
KeyInformation = 0i64;
v64 = 0i64;
v65 = 0i64;
RtlInitUnicodeString(&DestinationString, L"Hardware Profiles");
ObjectAttributes.RootDirectory = a1;
ObjectAttributes.ObjectName = &DestinationString;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
v10 = ZwOpenKey(&KeyHandle, 0x20019ui64, &ObjectAttributes, v9, (INT64)ResultLength, v51, v54, v55);
if( v10 < 0 )
{
KeyHandle = 0i64;
goto LABEL_46;
}
v10 = ZwQueryKey(KeyHandle, KeyFullInformation, &KeyInformation, 0x30ui64, (UINT64 *)&v54);
if( v10 < 0 )
goto LABEL_46;
LODWORD(v54) = 32 * (DWORD1(v64) - 1) + 40;
PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)v54, 538987843i64);
*(_QWORD *)a2 = PoolWithTag;
if( !PoolWithTag )
goto LABEL_53;
memset(PoolWithTag, 0i64, v54);
v12 = 0;
**(_DWORD **)a2 = DWORD1(v64);
for( *(_DWORD *)(*(_QWORD *)a2 + 4i64) = 0; v12 < DWORD1(v64); v5 = 0 )
{
LODWORD(ResultLengtha) = 254;
DWORD1(v59) = 0;
HIDWORD(Value[0]) = 0;
HIDWORD(Value[1]) = 0;
if( ZwEnumerateKey(KeyHandle, v12, KeyBasicInformation, KeyValueInformation, (UINT64)ResultLengtha, (UINT64 *)&v54) < 0 )
break;
*((_WORD *)KeyValueInformation + ((unsigned __int64)*((unsigned int *)KeyValueInformation + 3) >> 1) + 8) = 0;
DestinationString.Length = *((_WORD *)KeyValueInformation + 6);
DestinationString.MaximumLength = DestinationString.Length + 2;
DestinationString.Buffer = (wchar_t *)((char *)KeyValueInformation + 16);
ObjectAttributes.RootDirectory = KeyHandle;
ObjectAttributes.ObjectName = &DestinationString;
ObjectAttributes.Length = 48;
ObjectAttributes.Attributes = 576;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
if( ZwOpenKey((VOID **)&v55, 0x20019ui64, &ObjectAttributes, v13, (INT64)ResultLengtha, v52, v54, v55) < 0 )
break;
RtlUnicodeStringToInteger(&DestinationString, 0i64, (UINT64 *)((char *)Value + 4));
RtlInitUnicodeString(&DestinationString, L"PreferenceOrder");
LODWORD(ResultLengtha) = 256;
if( ZwQueryValueKey(
(VOID *)v55,
&DestinationString,
KeyValueFullInformation,
KeyValueInformation,
(UINT64)ResultLengtha,
(UINT64 *)&v54) >= 0
&& *((_DWORD *)KeyValueInformation + 1) == 4 )
{
v14 = *(_DWORD *)((char *)KeyValueInformation + *((unsigned int *)KeyValueInformation + 2));
}
else
{
v14 = -1;
}
LODWORD(Value[0]) = v14;
RtlInitUnicodeString(&DestinationString, L"FriendlyName");
LODWORD(ResultLengthb) = 256;
if( ZwQueryValueKey(
(VOID *)v55,
&DestinationString,
KeyValueFullInformation,
KeyValueInformation,
(UINT64)ResultLengthb,
(UINT64 *)&v54) >= 0
&& *((_DWORD *)KeyValueInformation + 1) == 1 )
{
v15 = ExAllocatePoolWithTag(1ui64, *((unsigned int *)KeyValueInformation + 3), 538987843i64);
v16 = *((_DWORD *)KeyValueInformation + 3);
LODWORD(v59) = v16;
*((_QWORD *)&v59 + 1) = v15;
if( !v15 )
goto LABEL_60;
v17 = v16;
v18 = (__int128 *)((char *)KeyValueInformation + *((unsigned int *)KeyValueInformation + 2));
}
else
{
v62 = *(_OWORD *)L"-------";
v15 = ExAllocatePoolWithTag(1ui64, 0x10ui64, 538987843i64);
LODWORD(v59) = 16;
*((_QWORD *)&v59 + 1) = v15;
if( !v15 )
{
LABEL_60:
v10 = -1073741670;
LABEL_65:
ZwClose(v55);
goto LABEL_46;
}
v17 = *((_DWORD *)KeyValueInformation + 3);
v18 = &v62;
}
memmove(v15, v18, v17);
v19 = 0;
LODWORD(Value[1]) = 0;
RtlInitUnicodeString(&DestinationString, L"Aliasable");
LODWORD(ResultLengthc) = 256;
if( ZwQueryValueKey(
(VOID *)v55,
&DestinationString,
KeyValueFullInformation,
KeyValueInformation,
(UINT64)ResultLengthc,
(UINT64 *)&v54) < 0
|| *((_DWORD *)KeyValueInformation + 1) != 4
|| *(_DWORD *)((char *)KeyValueInformation + *((unsigned int *)KeyValueInformation + 2)) )
{
v19 = 1;
LODWORD(Value[1]) = 1;
}
RtlInitUnicodeString(&DestinationString, L"Pristine");
LODWORD(ResultLengthd) = 256;
if( ZwQueryValueKey(
(VOID *)v55,
&DestinationString,
KeyValueFullInformation,
KeyValueInformation,
(UINT64)ResultLengthd,
(UINT64 *)&v54) >= 0
&& *((_DWORD *)KeyValueInformation + 1) == 4 )
{
if( *(_DWORD *)((char *)KeyValueInformation + *((unsigned int *)KeyValueInformation + 2)) )
v19 = 4;
LODWORD(Value[1]) = v19;
}
if( !HIDWORD(Value[0]) )
{
Value[0] = 0xFFFFFFFFi64;
v14 = -1;
LODWORD(Value[1]) = 4;
}
v20 = *(_DWORD **)a2;
v21 = 0;
v22 = *(_DWORD *)(*(_QWORD *)a2 + 4i64);
if( v22 )
{
while( 1 )
{
v23 = v21 + 1;
v24 = 8i64 * v21;
if( v20[v24 + 6] >= v14 )
break;
++v21;
if( v23 >= v22 )
goto LABEL_27;
}
memmove(&v20[8 * v23 + 2], &v20[v24 + 2], 32 * (*v20 - v21 - 1));
v20 = *(_DWORD **)a2;
}
LABEL_27:
v25 = *(_OWORD *)Value;
v26 = 8i64 * v21;
*(_OWORD *)&v20[v26 + 2] = v59;
*(_OWORD *)&v20[v26 + 6] = v25;
++*(_DWORD *)(*(_QWORD *)a2 + 4i64);
ZwClose(v55);
++v12;
}
RtlInitUnicodeString(&DestinationString, L"AcpiAlias");
ObjectAttributes.Length = 48;
ObjectAttributes.ObjectName = &DestinationString;
ObjectAttributes.RootDirectory = a1;
ObjectAttributes.Attributes = 576;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
if( ZwOpenKey(&Handle, 0x20019ui64, &ObjectAttributes, v27, (INT64)ResultLengtha, v52, v54, v55) < 0 )
{
v10 = 0;
Handle = 0i64;
goto LABEL_48;
}
v10 = ZwQueryKey(Handle, KeyFullInformation, &KeyInformation, 0x30ui64, (UINT64 *)&v54);
if( v10 >= 0 )
{
v28 = ExAllocatePoolWithTag(1ui64, 32i64 * (unsigned int)(DWORD1(v64) - 1) + 40, 538987843i64);
*(_QWORD *)a3 = v28;
if( v28 )
{
*((_DWORD *)v28 + 1) = DWORD1(v64);
**(_DWORD **)a3 = DWORD1(v64);
if( DWORD1(v64) )
{
while( 1 )
{
LODWORD(ResultLengthe) = 254;
v10 = ZwEnumerateKey(
Handle,
v5,
KeyBasicInformation,
KeyValueInformation,
(UINT64)ResultLengthe,
(UINT64 *)&v54);
if( v10 < 0 )
break;
*((_WORD *)KeyValueInformation + ((unsigned __int64)*((unsigned int *)KeyValueInformation + 3) >> 1) + 8) = 0;
DestinationString.Length = *((_WORD *)KeyValueInformation + 6);
DestinationString.MaximumLength = DestinationString.Length + 2;
DestinationString.Buffer = (wchar_t *)((char *)KeyValueInformation + 16);
ObjectAttributes.RootDirectory = Handle;
ObjectAttributes.ObjectName = &DestinationString;
ObjectAttributes.Length = 48;
ObjectAttributes.Attributes = 576;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
v10 = ZwOpenKey((VOID **)&v55, 0x20019ui64, &ObjectAttributes, v29, (INT64)ResultLengthf, v53, v54, v55);
if( v10 < 0 )
break;
RtlInitUnicodeString(&DestinationString, L"ProfileNumber");
LODWORD(ResultLengthg) = 256;
if( ZwQueryValueKey(
(VOID *)v55,
&DestinationString,
KeyValueFullInformation,
KeyValueInformation,
(UINT64)ResultLengthg,
(UINT64 *)&v54) < 0
|| *((_DWORD *)KeyValueInformation + 1) != 4
|| (*(_DWORD *)(*(_QWORD *)a3 + 24i64 * v5 + 8) = *(_DWORD *)((char *)KeyValueInformation
+ *((unsigned int *)KeyValueInformation + 2)),
RtlInitUnicodeString(&DestinationString, L"DockingState"),
LODWORD(ResultLengthh) = 256,
ZwQueryValueKey(
(VOID *)v55,
&DestinationString,
KeyValueFullInformation,
KeyValueInformation,
(UINT64)ResultLengthh,
(UINT64 *)&v54) < 0)
|| *((_DWORD *)KeyValueInformation + 1) != 4
|| (*(_DWORD *)(*(_QWORD *)a3 + 24i64 * v5 + 12) = *(_DWORD *)((char *)KeyValueInformation
+ *((unsigned int *)KeyValueInformation + 2)),
RtlInitUnicodeString(&DestinationString, L"AcpiSerialNumber"),
LODWORD(ResultLengthi) = 256,
v10 = ZwQueryValueKey(
(VOID *)v55,
&DestinationString,
KeyValueFullInformation,
KeyValueInformation,
(UINT64)ResultLengthi,
(UINT64 *)&v54),
v10 < 0)
|| *((_DWORD *)KeyValueInformation + 1) != 3 )
{
v10 = -1073741492;
goto LABEL_65;
}
*(_DWORD *)(*(_QWORD *)a3 + 24i64 * v5 + 16) = *((_DWORD *)KeyValueInformation + 3);
v30 = *((_DWORD *)KeyValueInformation + 3);
if( v30 )
v31 = ExAllocatePoolWithTag(1ui64, v30, 538987843i64);
else
v31 = 0i64;
*(_QWORD *)(*(_QWORD *)a3 + 24i64 * v5 + 24) = v31;
v32 = *((_DWORD *)KeyValueInformation + 3);
if( v32 )
{
v33 = *(VOID **)(*(_QWORD *)a3 + 24i64 * v5 + 24);
if( !v33 )
goto LABEL_60;
memmove(v33, (char *)KeyValueInformation + *((unsigned int *)KeyValueInformation + 2), v32);
}
ZwClose(v55);
if( ++v5 >= DWORD1(v64) )
goto LABEL_46;
}
}
goto LABEL_46;
}
LABEL_53:
v10 = -1073741670;
}
LABEL_46:
if( Handle )
ZwClose((_HANDLE)Handle);
LABEL_48:
if( KeyHandle )
ZwClose((_HANDLE)KeyHandle);
if( v10 < 0 )
{
v35 = *(_DWORD **)a2;
if( *(_QWORD *)a2 )
{
v36 = 0;
if( v35[1] )
{
do
{
v37 = *(void **)&v35[8 * v36 + 4];
if( v37 )
ExFreePoolWithTag(v37, 0);
v35 = *(_DWORD **)a2;
++v36;
}
while( v36 < *(_DWORD *)(*(_QWORD *)a2 + 4i64) );
}
ExFreePoolWithTag(v35, 0);
*(_QWORD *)a2 = 0i64;
}
v38 = *(_DWORD **)a3;
if( *(_QWORD *)a3 )
{
v39 = 0;
if( v38[1] )
{
do
{
v40 = *(void **)&v38[6 * v39 + 6];
if( v40 )
ExFreePoolWithTag(v40, 0);
v38 = *(_DWORD **)a3;
++v39;
}
while( v39 < *(_DWORD *)(*(_QWORD *)a3 + 4i64) );
}
ExFreePoolWithTag(v38, 0);
*(_QWORD *)a3 = 0i64;
}
}
return(unsigned int)v10;
}Referenced by:
CmSetAcpiHwProfile