CmpInitializeMachineDependentConfiguration
NTSTATUS __stdcall CmpInitializeMachineDependentConfiguration(_LOADER_PARAMETER_BLOCK *LoaderBlock){
INT64 v1;
unsigned __int64 v2;
_LOADER_PARAMETER_BLOCK *v3;
unsigned int v4;
unsigned int v5;
NTSTATUS result;
unsigned int v7;
_KPRCB *v8;
unsigned int v9;
KPCR *Pcr;
unsigned int SecondLevelCacheSize;
unsigned __int8 *VendorString;
int v13;
int v14;
bool v15;
int v16;
_LARGE_INTEGER *Table;
unsigned __int8 LowPart;
bool v19;
bool v20;
char QuadPart;
bool v22;
VOID *Data;
INT64 DataSize;
UINT64 DataSizea;
UINT64 DataSizeb;
UINT64 DataSizec;
UINT64 DataSized;
UINT64 DataSizee;
UINT64 *Disposition;
INT64 v31;
VOID *Handle;
UINT64 v33;
VOID *KeyHandle;
VOID *SectionHandle;
_UNICODE_STRING DestinationString;
_OBJECT_ATTRIBUTES ObjectAttributes;
int v38;
_GROUP_AFFINITY Affinity;
_LOADER_PARAMETER_BLOCK *v40;
_UNICODE_STRING v41;
_UNICODE_STRING v42;
__int64 v43;
ULONG v44;
_GROUP_AFFINITY PreviousAffinity;
v40 = LoaderBlock;
LODWORD(v33) = 0;
Handle = 0i64;
v2 = 0i64;
KeyHandle = 0i64;
v3 = LoaderBlock;
SectionHandle = 0i64;
v43 = 0i64;
v41 = 0i64;
v4 = 0;
v44 = 0;
memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
v5 = 0;
v42 = 0i64;
Affinity = 0i64;
PreviousAffinity = 0i64;
DestinationString = 0i64;
do
{
if( v2 >= 0x54 )
_report_rangecheckfailure();
*(_WORD *)((char *)CmpDeviceIndexTable + v2) = 0;
++v5;
v2 += 2i64;
}
while( v5 < 0x2A );
ObjectAttributes.Length = 48;
ObjectAttributes.RootDirectory = 0i64;
ObjectAttributes.Attributes = 576;
ObjectAttributes.ObjectName = &CmRegistryMachineSystemCurrentControlSetControlSessionManagerMemoryManagement;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
if( ZwOpenKey(&KeyHandle, 0x2001Fui64, &ObjectAttributes, v1, (INT64)Data, DataSize, (INT64)Disposition, v31) >= 0 )
{
v38 = 1;
RtlInitUnicodeString(&DestinationString, L"PhysicalAddressExtension");
LODWORD(DataSizea) = 4;
ZwSetValueKey(KeyHandle, &DestinationString, 0i64, 4ui64, &v38, DataSizea);
ZwClose((_HANDLE)KeyHandle);
}
LODWORD(DataSizea) = 0;
ObjectAttributes.ObjectName = &CmRegistryMachineHardwareDescriptionSystemName;
ObjectAttributes.Length = 48;
ObjectAttributes.RootDirectory = 0i64;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
ObjectAttributes.Attributes = 576;
result = ZwCreateKey(&Handle, 0x20019ui64, &ObjectAttributes, 0i64, 0i64, DataSizea, 0i64);
if( result >= 0 )
{
RtlInitUnicodeString(&v41, L"CentralProcessor");
ObjectAttributes.RootDirectory = Handle;
ObjectAttributes.Length = 48;
ObjectAttributes.ObjectName = &v41;
ObjectAttributes.Attributes = 576;
LODWORD(DataSizeb) = 0;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
ZwCreateKey(&KeyHandle, 0x2001Fui64, &ObjectAttributes, 0i64, 0i64, DataSizeb, &v33);
ZwClose((_HANDLE)KeyHandle);
if( (_DWORD)v33 == 1 )
{
CmpConfigurationData = ExAllocatePoolWithTag(1ui64, (unsigned int)CmpConfigurationAreaSize, 538987843i64);
v7 = 0;
if( (_DWORD)KeNumberProcessors_0 )
{
while( 1 )
{
v8 = *(&KiProcessorBlock + v7);
v9 = KiProcessorIndexToNumberMappingTable[v8->Number];
Affinity.Reserved[1] = 0;
Affinity.Reserved[2] = 0;
*(_DWORD *)&Affinity.Group = (unsigned __int16)(v9 >> 6);
Affinity.Mask = 1i64 << (v9 & 0x3F);
KeSetSystemGroupAffinityThread(&Affinity, &PreviousAffinity);
CmpAddProcessorConfigurationEntry(v8, v7, Handle);
Pcr = KeGetPcr();
if( v7 )
{
SecondLevelCacheSize = Pcr->SecondLevelCacheSize;
if( v8->CpuID )
{
VendorString = v8->VendorString;
do
{
v13 = VendorString[(char *)KiProcessorBlock - (char *)v8];
v14 = *VendorString - v13;
if( v14 )
break;
++VendorString;
}
while( v13 );
if( v14 )
CmProcessorMismatch |= 1u;
if( SecondLevelCacheSize != v4 )
CmProcessorMismatch |= 4u;
if( v8->CpuType != KiProcessorBlock->CpuType )
{
LABEL_42:
CmProcessorMismatch |= 2u;
goto LABEL_21;
}
v15 = v8->CpuStep == KiProcessorBlock->CpuStep;
}
else
{
v15 = KiProcessorBlock->CpuID == 0;
}
if( !v15 )
goto LABEL_42;
}
else
{
v4 = Pcr->SecondLevelCacheSize;
}
LABEL_21:
KeRevertToUserGroupAffinityThread(&PreviousAffinity);
if( ++v7 >= (unsigned int)KeNumberProcessors_0 )
{
v3 = v40;
break;
}
}
}
if( CmpConfigurationData )
{
ExFreePoolWithTag(CmpConfigurationData, 0);
CmpConfigurationData = 0i64;
}
}
RtlInitUnicodeString(&v42, L"\\Device\\PhysicalMemory");
ObjectAttributes.Length = 48;
ObjectAttributes.ObjectName = &v42;
ObjectAttributes.RootDirectory = 0i64;
ObjectAttributes.Attributes = 576;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
if( ZwOpenSection(&SectionHandle, 0xF001Fui64, &ObjectAttributes) >= 0 )
{
v16 = *(&ExBootDevicesRemovedEvent + 276);
if( *(&ExBootDevicesRemovedEvent + 276) == 1 )
CmpSetSystemBiosInformation(v3, SectionHandle, Handle);
else
CmpInitializeSystemBiosInformation(v3);
Table = HalpAcpiGetTable(v3, (const UINT8 *)0x50434146, 0i64);
if( Table )
{
LowPart = Table[1].anonymous_0.LowPart;
v19 = LowPart == 0;
v20 = LowPart == 1;
if( LowPart > 1u )
{
LODWORD(v43) = *(unsigned __int16 *)((char *)&Table[13].QuadPart + 5);
v44 = Table[14].anonymous_0.LowPart;
HIDWORD(v43) = BYTE5(Table[5].QuadPart);
QuadPart = Table[1].QuadPart;
v19 = QuadPart == 0;
v20 = QuadPart == 1;
}
v22 = !v19 && !v20;
}
else
{
v22 = 0;
}
if( v22 )
{
RtlInitUnicodeString(&DestinationString, L"BootArchitecture");
LODWORD(DataSizec) = 4;
ZwSetValueKey(Handle, &DestinationString, 0i64, 4ui64, &v43, DataSizec);
RtlInitUnicodeString(&DestinationString, L"PreferredProfile");
LODWORD(DataSized) = 4;
ZwSetValueKey(Handle, &DestinationString, 0i64, 4ui64, (char *)&v43 + 4, DataSized);
RtlInitUnicodeString(&DestinationString, L"Capabilities");
LODWORD(DataSizee) = 4;
ZwSetValueKey(Handle, &DestinationString, 0i64, 4ui64, &v44, DataSizee);
}
if( v16 == 1 )
CmpSetVideoBiosInformation(SectionHandle, Handle);
ZwClose((_HANDLE)SectionHandle);
}
ZwClose((_HANDLE)Handle);
return 0;
}
return result;
}Referenced by:
CmInitSystem1