PipInitComputerIds
NTSTATUS __stdcall PipInitComputerIds(_LOADER_PARAMETER_BLOCK *LoaderBlock){
VOID *v2;
unsigned int v3;
VOID **v4;
NTSTATUS ComputerId;
_SMBIOS3_TABLE_HEADER *SMBiosEPSHeader;
_LARGE_INTEGER StructureTableAddress;
unsigned int StructureTableMaximumSize;
_BYTE *v9;
_BYTE *v10;
unsigned __int8 *Struct;
unsigned __int8 *v12;
unsigned __int8 *v13;
NTSTATUS String;
NTSTATUS v15;
NTSTATUS v16;
NTSTATUS v17;
NTSTATUS v18;
_BYTE *v19;
__int64 v20;
unsigned __int8 *v21;
NTSTATUS v22;
NTSTATUS v23;
unsigned __int8 *v24;
unsigned __int8 *v25;
unsigned __int8 *v26;
NTSTATUS v27;
NTSTATUS v28;
NTSTATUS v29;
_BYTE *v30;
unsigned int v31;
int v32;
unsigned int v33;
_UNICODE_STRING *v34;
unsigned int v35;
_UNICODE_STRING *v36;
PCWSTR *v37;
_OBJECT_TYPE *v38;
void *v39;
__int64 v40;
wchar_t *Buffer;
VOID *v42;
unsigned int v43;
_UNICODE_STRING **v44;
_UNICODE_STRING *v45;
__int64 v46;
__int128 *v47;
unsigned int v48;
_UNICODE_STRING *v49;
__int64 v50;
__int128 *v51;
__int128 *v52;
__int64 v53;
_UNICODE_STRING *v54;
__int64 v55;
_UNICODE_STRING *v56;
__int128 *v57;
__int64 v58;
_UNICODE_STRING *v59;
__int128 *v60;
__int64 v61;
_UNICODE_STRING *v62;
__int128 *v63;
__int64 v64;
_UNICODE_STRING *v65;
UINT64 *v66;
VOID **PoolWithTag;
VOID **v68;
wchar_t *v69;
unsigned __int16 v70;
wchar_t *v71;
unsigned __int64 v72;
__int64 v73;
const wchar_t *v74;
signed __int64 v75;
__int64 v76;
unsigned __int64 v77;
_UNICODE_STRING *v78;
__int64 v79;
HPNPCTX *v80;
INT64 v81;
INT64 v82;
PVOID v83;
_OWORD *CreateOptions;
UINT64 *Disposition;
INT64 a7;
INT64 a8;
unsigned int v89;
_BYTE *v90;
unsigned __int8 KeyName;
_UNICODE_STRING KeyName_8;
int Data;
PVOID Handle;
VOID *HardwareConfigKey;
PVOID v96;
unsigned int v97;
VOID *v98;
_UNICODE_STRING DestinationString;
__int64 v100;
_UNICODE_STRING v101;
UINT64 StringCount[2];
__int128 v103;
__int128 v104;
_UNICODE_STRING *p_DestinationString;
_UNICODE_STRING UnicodeString[10];
_OWORD v107[15];
WCHAR SourceString;
WCHAR pszDest[8];
v100 = 0i64;
v2 = 0i64;
HardwareConfigKey = 0i64;
v3 = 0;
Handle = 0i64;
v96 = 0i64;
KeyName = 0;
Data = 0;
v97 = 0;
v98 = 0i64;
DestinationString = 0i64;
p_DestinationString = 0i64;
v101 = 0i64;
*(_OWORD *)StringCount = 0i64;
v103 = 0i64;
v104 = 0i64;
KeyName_8 = 0i64;
memset(UnicodeString, 0i64, sizeof(UnicodeString));
ComputerId = PipHardwareConfigOpenKey(v4);
if( ComputerId >= 0 )
{
PnpCtxRegDeleteTree(*(&stru_140CF2E80 + 607), HardwareConfigKey, (WCHAR *)L"ComputerIds");
*(_DWORD *)&KeyName_8.Length = 1572886;
LODWORD(CreateOptions) = 0;
KeyName_8.Buffer = (wchar_t *)L"ComputerIds";
ComputerId = IopCreateRegistryKeyEx(&Handle, 0i64, &KeyName_8, 0xF003Fui64, (UINT64)CreateOptions, 0i64);
if( ComputerId >= 0 )
{
PnpCtxRegDeleteTree(*(&stru_140CF2E80 + 607), 0i64, (WCHAR *)L"ProductIds");
*(_DWORD *)&KeyName_8.Length = 1441812;
KeyName_8.Buffer = (wchar_t *)L"ProductIds";
LODWORD(CreateOptions) = 0;
ComputerId = IopCreateRegistryKeyEx(&v96, 0i64, &KeyName_8, 0xF003Fui64, (UINT64)CreateOptions, 0i64);
if( ComputerId >= 0 )
{
SMBiosEPSHeader = LoaderBlock->Extension->SMBiosEPSHeader;
if( !SMBiosEPSHeader
|| (StructureTableAddress = (_LARGE_INTEGER)SMBiosEPSHeader->StructureTableAddress,
!StructureTableAddress.QuadPart) )
{
ComputerId = -1073741637;
goto LABEL_149;
}
StructureTableMaximumSize = SMBiosEPSHeader->StructureTableMaximumSize;
v89 = StructureTableMaximumSize;
v9 = MmMapIoSpaceEx(StructureTableAddress, StructureTableMaximumSize, 2ui64);
v90 = v9;
v10 = v9;
if( !v9 )
{
ComputerId = -1073741670;
v2 = 0i64;
LABEL_163:
v3 = StructureTableMaximumSize;
goto LABEL_149;
}
Struct = PipSmBiosFindStruct(1, 0, v9, StructureTableMaximumSize);
v12 = Struct;
if( Struct )
{
v13 = Struct + 5;
if( Struct + 5 <= &Struct[Struct[1]] )
{
String = PipSmBiosGetString(
(__int64)Struct,
Struct[4],
(__int64)v10,
StructureTableMaximumSize,
UnicodeString);
ComputerId = String;
if( String == -1073741275 )
{
ComputerId = 0;
}
else if( String < 0 )
{
goto LABEL_162;
}
}
if( v12 + 27 <= &v12[v12[1]] )
{
v15 = PipSmBiosGetString((__int64)v12, v12[26], (__int64)v10, StructureTableMaximumSize, &UnicodeString[1]);
ComputerId = v15;
if( v15 == -1073741275 )
{
ComputerId = 0;
}
else if( v15 < 0 )
{
goto LABEL_162;
}
}
if( v12 + 6 <= &v12[v12[1]] )
{
v16 = PipSmBiosGetString((__int64)v12, *v13, (__int64)v10, StructureTableMaximumSize, &UnicodeString[2]);
ComputerId = v16;
if( v16 == -1073741275 )
{
ComputerId = 0;
}
else if( v16 < 0 )
{
goto LABEL_162;
}
}
if( v12 + 26 <= &v12[v12[1]] )
{
v17 = PipSmBiosGetString((__int64)v12, v12[25], (__int64)v10, StructureTableMaximumSize, &UnicodeString[3]);
ComputerId = v17;
if( v17 == -1073741275 )
{
ComputerId = 0;
}
else if( v17 < 0 )
{
goto LABEL_162;
}
}
if( v12 + 7 <= &v12[v12[1]] )
{
v18 = PipSmBiosGetString((__int64)v12, v12[6], (__int64)v10, StructureTableMaximumSize, &UnicodeString[9]);
ComputerId = v18;
if( v18 == -1073741275 )
{
ComputerId = 0;
}
else if( v18 < 0 )
{
goto LABEL_162;
}
}
}
v19 = PipSmBiosFindStruct(2, 10, v10, StructureTableMaximumSize);
v20 = (__int64)v19;
if( v19 )
{
v21 = v19 + 5;
if( v19 + 5 <= &v19[(unsigned __int8)v19[1]] )
{
v22 = PipSmBiosGetString((__int64)v19, v19[4], (__int64)v10, StructureTableMaximumSize, &UnicodeString[6]);
ComputerId = v22;
if( v22 == -1073741275 )
{
ComputerId = 0;
}
else if( v22 < 0 )
{
goto LABEL_162;
}
}
if( v20 + 6 <= v20 + (unsigned __int64)*(unsigned __int8 *)(v20 + 1) )
{
v23 = PipSmBiosGetString(v20, *v21, (__int64)v10, StructureTableMaximumSize, &UnicodeString[7]);
ComputerId = v23;
if( v23 == -1073741275 )
{
ComputerId = 0;
}
else if( v23 < 0 )
{
goto LABEL_162;
}
}
}
v24 = PipSmBiosFindStruct(0, 0, v10, StructureTableMaximumSize);
v25 = v24;
if( !v24 )
goto LABEL_42;
v26 = v24 + 5;
if( v24 + 5 <= &v24[v24[1]] )
{
v27 = PipSmBiosGetString((__int64)v24, v24[4], (__int64)v10, StructureTableMaximumSize, &UnicodeString[4]);
ComputerId = v27;
if( v27 == -1073741275 )
{
ComputerId = 0;
}
else if( v27 < 0 )
{
goto LABEL_162;
}
}
if( v25 + 6 > &v25[v25[1]] )
goto LABEL_37;
v28 = PipSmBiosGetString((__int64)v25, *v26, (__int64)v10, StructureTableMaximumSize, &UnicodeString[5]);
ComputerId = v28;
if( v28 == -1073741275 )
{
ComputerId = 0;
goto LABEL_37;
}
if( v28 >= 0 )
{
LABEL_37:
if( v25 + 9 > &v25[v25[1]] )
goto LABEL_40;
v29 = PipSmBiosGetString((__int64)v25, v25[8], (__int64)v10, StructureTableMaximumSize, &UnicodeString[8]);
ComputerId = v29;
if( v29 == -1073741275 )
{
ComputerId = 0;
LABEL_40:
if( v25 + 22 <= &v25[v25[1]] )
KeyName = v25[21];
LABEL_42:
v30 = PipSmBiosFindStruct(3, 0, v10, StructureTableMaximumSize);
v31 = 0;
if( v30 && v30 + 6 <= &v30[(unsigned __int8)v30[1]] )
{
v32 = v30[5] & 0x7F;
Data = v32;
}
else
{
v32 = Data;
}
if( v32 )
{
KeyName_8.Buffer = L"EnclosureType";
LODWORD(Disposition) = 4;
*(_DWORD *)&KeyName_8.Length = 1835034;
ZwSetValueKey(HardwareConfigKey, &KeyName_8, 0i64, 4ui64, &Data, (UINT64)Disposition);
}
v33 = 0;
v34 = UnicodeString;
do
{
if( v34->Buffer && !v34->Length )
RtlFreeAnsiString(&UnicodeString[v33]);
++v33;
++v34;
}
while( v33 < 0xA );
v35 = 0;
v36 = UnicodeString;
v37 = (PCWSTR *)off_1400082A0;
do
{
RtlInitUnicodeString(&KeyName_8, *v37);
if( v36->Length )
{
if( (int)PnpUnicodeStringToWstr((__int16 **)&v98, 0i64, &UnicodeString[v35].Length) >= 0 )
{
v39 = v98;
v40 = -1i64;
do
++v40;
while( *((_WORD *)v98 + v40) );
LODWORD(Disposition) = 2 * v40 + 2;
ZwSetValueKey(HardwareConfigKey, &KeyName_8, 0i64, 1ui64, v98, (UINT64)Disposition);
PnpUnicodeStringToWstrFree(v39, (__int64)&UnicodeString[v35]);
}
v31 = 0;
}
else
{
ZwDeleteValueKey(HardwareConfigKey, &KeyName_8, v38);
}
++v35;
++v37;
++v36;
}
while( v35 < 0xA );
Buffer = UnicodeString[0].Buffer;
v42 = Handle;
v43 = v97;
if( !UnicodeString[0].Buffer )
{
LABEL_124:
PoolWithTag = ExAllocatePoolWithTag(1ui64, 112 * v43 + 2, 1852403792i64);
v68 = PoolWithTag;
if( PoolWithTag )
{
v69 = (wchar_t *)PoolWithTag;
KeyName_8.Buffer = (wchar_t *)PoolWithTag;
v70 = 112 * v43 + 2;
KeyName_8.MaximumLength = v70;
if( v43 )
{
v96 = L"ComputerMetadata\\";
do
{
v71 = 0i64;
KeyName_8.Length = 0;
v72 = 0i64;
ComputerId = 0;
if( (KeyName_8.MaximumLength & 1) != 0 || v70 == 0xFFFF )
{
ComputerId = -1073741811;
}
else
{
if( v69 || !v70 )
{
v71 = v69;
v72 = (unsigned __int64)v70 >> 1;
}
else
{
ComputerId = -1073741811;
}
if( ComputerId < 0 )
goto LABEL_147;
v73 = 0i64;
if( v72 )
{
v74 = L"ComputerMetadata\\";
v75 = (char *)v71 - (_BYTE *)v96;
v76 = 0x7FFFi64;
v77 = v72;
ComputerId = 0;
do
{
if( !v76 )
break;
if( *v74 == (_WORD)v100 )
break;
*(const wchar_t *)((char *)v74 + v75) = *v74;
--v76;
++v74;
++v73;
--v77;
}
while( v77 );
if( !v77 && v76 && *v74 )
ComputerId = -2147483643;
v71 += v73;
LOWORD(v72) = v72 - v73;
}
else
{
ComputerId = v71 != 0i64 ? -2147483643 : -1073741811;
}
KeyName_8.Length = 2 * v73;
if( ((ComputerId + 0x80000000) & 0x80000000) != 0 || ComputerId == -2147483643 )
{
KeyName_8.Length = 0;
KeyName_8.MaximumLength = 2 * v72;
KeyName_8.Buffer = v71;
}
}
if( ComputerId < 0 )
goto LABEL_147;
ComputerId = RtlStringFromGUIDEx((_GUID *)&v107[v31], &KeyName_8, 0);
if( ComputerId < 0 )
goto LABEL_147;
ComputerId = RtlUpcaseUnicodeString(&KeyName_8, &KeyName_8, 0);
if( ComputerId < 0 )
goto LABEL_147;
v69 = KeyName_8.Buffer + 39;
v70 = KeyName_8.MaximumLength - 78;
KeyName_8.Buffer += 39;
++v31;
KeyName_8.MaximumLength -= 78;
}
while( v31 < v43 );
}
if( ComputerId >= 0 )
{
*v69 = 0;
++KeyName_8.Buffer;
ComputerId = PnpSetObjectProperty(
*(&stru_140CF2E80 + 607),
(INT64)L"{00000000-0000-0000-FFFF-FFFFFFFFFFFF}",
5u,
0i64,
0i64,
(__int64)&DEVPKEY_Device_HardwareIds,
8210,
(__int64)v68,
112 * v43 + 2,
0);
}
LABEL_147:
ExFreePoolWithTag(v68, 0);
}
else
{
ComputerId = -1073741670;
}
goto LABEL_148;
}
v44 = (_UNICODE_STRING **)v96;
if( UnicodeString[2].Buffer && UnicodeString[4].Buffer && UnicodeString[5].Buffer )
{
LODWORD(CreateOptions) = KeyName;
ComputerId = RtlStringCchPrintfW(pszDest, 8ui64, (WCHAR *)L"%02x&%02x");
if( ComputerId < 0 )
goto LABEL_148;
RtlInitUnicodeString(&DestinationString, pszDest);
if( UnicodeString[3].Buffer )
{
StringCount[0] = (UINT64)UnicodeString;
v45 = &UnicodeString[2];
StringCount[1] = (UINT64)&UnicodeString[1];
v46 = 4i64;
v47 = &v103;
do
{
*(_QWORD *)v47 = v45++;
v47 = (__int128 *)((char *)v47 + 8);
--v46;
}
while( v46 );
p_DestinationString = &DestinationString;
CreateOptions = v107;
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 7);
v43 = 1;
if( ComputerId < 0 )
goto LABEL_148;
}
StringCount[0] = (UINT64)UnicodeString;
StringCount[1] = (UINT64)&UnicodeString[1];
*(_QWORD *)&v103 = &UnicodeString[2];
*((_QWORD *)&v103 + 1) = &UnicodeString[4];
*(_QWORD *)&v104 = &UnicodeString[5];
*((_QWORD *)&v104 + 1) = &DestinationString;
CreateOptions = &v107[v43];
v48 = v43 + 1;
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 6);
if( ComputerId < 0 )
goto LABEL_148;
StringCount[0] = (UINT64)UnicodeString;
StringCount[1] = (UINT64)&UnicodeString[2];
*(_QWORD *)&v103 = &UnicodeString[4];
*((_QWORD *)&v103 + 1) = &UnicodeString[5];
*(_QWORD *)&v104 = &DestinationString;
CreateOptions = &v107[v48];
v43 = v48 + 1;
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 5);
if( ComputerId < 0 )
goto LABEL_148;
Buffer = UnicodeString[0].Buffer;
}
if( !Buffer )
goto LABEL_124;
if( UnicodeString[2].Buffer )
{
if( UnicodeString[3].Buffer )
{
if( UnicodeString[6].Buffer )
{
if( UnicodeString[7].Buffer )
{
StringCount[0] = (UINT64)UnicodeString;
v49 = &UnicodeString[2];
v50 = 2i64;
StringCount[1] = (UINT64)&UnicodeString[1];
v51 = &v103;
do
{
*(_QWORD *)v51 = v49++;
v51 = (__int128 *)((char *)v51 + 8);
--v50;
}
while( v50 );
v52 = &v104;
v53 = 2i64;
v54 = &UnicodeString[6];
do
{
*(_QWORD *)v52 = v54++;
v52 = (__int128 *)((char *)v52 + 8);
--v53;
}
while( v53 );
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 6);
if( ComputerId < 0 )
goto LABEL_148;
}
}
v55 = 2i64;
StringCount[0] = (UINT64)UnicodeString;
v56 = &UnicodeString[2];
StringCount[1] = (UINT64)&UnicodeString[1];
v57 = &v103;
do
{
*(_QWORD *)v57 = v56++;
v57 = (__int128 *)((char *)v57 + 8);
--v55;
}
while( v55 );
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 4);
if( ComputerId < 0 )
goto LABEL_148;
}
StringCount[0] = (UINT64)UnicodeString;
StringCount[1] = (UINT64)&UnicodeString[1];
*(_QWORD *)&v103 = &UnicodeString[2];
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 3);
if( ComputerId < 0 )
goto LABEL_148;
Buffer = UnicodeString[0].Buffer;
}
if( !Buffer )
goto LABEL_124;
if( UnicodeString[3].Buffer )
{
if( UnicodeString[6].Buffer )
{
if( UnicodeString[7].Buffer )
{
v58 = 2i64;
StringCount[0] = (UINT64)UnicodeString;
v59 = &UnicodeString[6];
StringCount[1] = (UINT64)&UnicodeString[3];
v60 = &v103;
do
{
*(_QWORD *)v60 = v59++;
v60 = (__int128 *)((char *)v60 + 8);
--v58;
}
while( v58 );
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 4);
if( ComputerId < 0 )
goto LABEL_148;
}
}
StringCount[0] = (UINT64)UnicodeString;
StringCount[1] = (UINT64)&UnicodeString[3];
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 2);
if( ComputerId < 0 )
goto LABEL_148;
Buffer = UnicodeString[0].Buffer;
}
if( !Buffer )
goto LABEL_124;
if( UnicodeString[2].Buffer )
{
if( UnicodeString[6].Buffer )
{
if( UnicodeString[7].Buffer )
{
StringCount[0] = (UINT64)UnicodeString;
StringCount[1] = (UINT64)&UnicodeString[2];
*(_QWORD *)&v103 = &UnicodeString[6];
*((_QWORD *)&v103 + 1) = &UnicodeString[7];
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 4);
if( ComputerId < 0 )
goto LABEL_148;
}
}
StringCount[0] = (UINT64)UnicodeString;
StringCount[1] = (UINT64)&UnicodeString[2];
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 2);
if( ComputerId < 0 )
goto LABEL_148;
Buffer = UnicodeString[0].Buffer;
}
if( !Buffer )
goto LABEL_124;
if( UnicodeString[1].Buffer )
{
if( UnicodeString[7].Buffer )
{
if( UnicodeString[6].Buffer )
{
v61 = 2i64;
StringCount[0] = (UINT64)UnicodeString;
v62 = &UnicodeString[6];
StringCount[1] = (UINT64)&UnicodeString[1];
v63 = &v103;
do
{
*(_QWORD *)v63 = v62++;
v63 = (__int128 *)((char *)v63 + 8);
--v61;
}
while( v61 );
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 4);
if( ComputerId < 0 )
goto LABEL_148;
}
}
StringCount[0] = (UINT64)UnicodeString;
StringCount[1] = (UINT64)&UnicodeString[1];
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, v44, (UINT64)StringCount, 2);
if( ComputerId < 0 )
goto LABEL_148;
Buffer = UnicodeString[0].Buffer;
}
if( !Buffer )
goto LABEL_124;
if( Data )
{
ComputerId = RtlStringCchPrintfW(&SourceString, 4ui64, (WCHAR *)L"%x");
if( ComputerId < 0 )
goto LABEL_148;
RtlInitUnicodeString(&v101, &SourceString);
StringCount[0] = (UINT64)UnicodeString;
StringCount[1] = (UINT64)&v101;
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, 0i64, (UINT64)StringCount, 2);
if( ComputerId < 0 )
goto LABEL_148;
Buffer = UnicodeString[0].Buffer;
}
if( !Buffer )
goto LABEL_124;
if( !UnicodeString[7].Buffer )
goto LABEL_189;
if( !UnicodeString[6].Buffer )
goto LABEL_189;
v64 = 2i64;
StringCount[0] = (UINT64)UnicodeString;
v65 = &UnicodeString[6];
v66 = &StringCount[1];
do
{
*v66++ = (UINT64)v65++;
--v64;
}
while( v64 );
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, 0i64, (UINT64)StringCount, 3);
if( ComputerId >= 0 )
{
LABEL_189:
StringCount[0] = (UINT64)UnicodeString;
CreateOptions = &v107[v43++];
ComputerId = PipCreateComputerId(v42, 0i64, (UINT64)StringCount, 1);
if( ComputerId >= 0 )
goto LABEL_124;
}
LABEL_148:
v3 = v89;
v2 = v90;
goto LABEL_149;
}
if( v29 >= 0 )
goto LABEL_40;
}
LABEL_162:
v2 = v10;
goto LABEL_163;
}
}
}
LABEL_149:
v78 = UnicodeString;
v79 = 10i64;
do
{
RtlFreeAnsiString(v78++);
--v79;
}
while( v79 );
v83 = Handle;
if( v2 )
MmUnmapIoSpace(v2, v3);
if( v83 )
ZwClose((_HANDLE)v83);
if( HardwareConfigKey )
PnpCtxRegCloseKey(v80, HardwareConfigKey, v81, v82, (INT64)CreateOptions, (INT64)Disposition, a7, a8);
return ComputerId;
}Referenced by:
IopInitializeBootDrivers