PnpBuildCmResourceList
int __fastcall PnpBuildCmResourceList(__int64 a1, int a2){
__int64 v2;
VOID **v3;
__int64 v4;
unsigned int v5;
__int64 v6;
__int64 v7;
__int64 *v8;
__int64 v9;
VOID **PoolWithTag;
_CM_RESOURCE_LIST *v11;
VOID **v12;
VOID **v13;
__int64 v14;
_CM_PARTIAL_RESOURCE_DESCRIPTOR *PartialDescriptors;
int v16;
char *v17;
__int64 v18;
__int64 v19;
__int64 v20;
__int64 v21;
_DEVICE_NODE *v22;
PCM_PARTIAL_RESOURCE_DESCRIPTOR v23;
int v24;
_WORD *v25;
int v26;
unsigned __int16 v27;
VOID *v28;
NTSTATUS v29;
PVOID v30;
char *v31;
int v32;
__int64 v33;
int v34;
PCM_PARTIAL_RESOURCE_DESCRIPTOR Source;
PCM_PARTIAL_RESOURCE_DESCRIPTOR *Target;
PCM_PARTIAL_RESOURCE_DESCRIPTOR *Targeta;
NTSTATUS v39;
UINT64 ReturnLength;
_QWORD Destination[3];
UINT64 ResourceListSize;
_UNICODE_STRING ClassName;
_UNICODE_STRING DriverName;
PCM_PARTIAL_RESOURCE_DESCRIPTOR v45;
PVOID Handle;
__int128 v47;
char v48;
v2 = *(_QWORD *)(a1 + 32);
v3 = 0i64;
v4 = a1;
*(_QWORD *)&DriverName.Length = a1;
LODWORD(ReturnLength) = a2;
v5 = 0;
Handle = 0i64;
v7 = *(_QWORD *)(v2 + 16);
v45 = 0i64;
v6 = *(_QWORD *)v7;
Destination[0] = v6;
LODWORD(v7) = *(_DWORD *)(v6 + 20);
if( !(_DWORD)v7 )
goto LABEL_42;
v8 = (__int64 *)(v6 + 24);
v9 = (unsigned int)v7;
do
{
v7 = *v8++;
v5 += *(_DWORD *)(v7 + 276) + 1;
--v9;
}
while( v9 );
if( !v5 )
{
LABEL_42:
*(_DWORD *)(v4 + 56) = -1073741595;
goto LABEL_43;
}
LODWORD(ResourceListSize) = 20 * (v5 + 1);
PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)ResourceListSize, 538996816i64);
Destination[1] = PoolWithTag;
v11 = (_CM_RESOURCE_LIST *)PoolWithTag;
if( !PoolWithTag )
{
LABEL_37:
LODWORD(v7) = -1073741670;
*(_DWORD *)(v4 + 56) = -1073741670;
LABEL_43:
*(_QWORD *)(v4 + 48) = 0i64;
goto LABEL_21;
}
memset(PoolWithTag, 0i64, ResourceListSize);
v12 = ExAllocatePoolWithTag(1ui64, (unsigned int)ResourceListSize, 538996816i64);
v13 = v12;
if( !v12 )
{
ExFreePoolWithTag(v11, 0);
goto LABEL_37;
}
memset(v12, 0i64, ResourceListSize);
v14 = Destination[0];
PartialDescriptors = v11->List[0].PartialResourceList.PartialDescriptors;
v11->Count = 1;
v11->List[0].InterfaceType = *(_DWORD *)v2;
v11->List[0].BusNumber = *(_DWORD *)(v2 + 4);
*(_DWORD *)&v11->List[0].PartialResourceList.Version = 65537;
v11->List[0].PartialResourceList.Count = v5;
*(_DWORD *)v13 = 1;
*((_DWORD *)v13 + 1) = *(_DWORD *)v2;
v16 = *(_DWORD *)(v2 + 4);
v17 = (char *)v13 + 20;
*((_DWORD *)v13 + 2) = v16;
v7 = 0i64;
*((_DWORD *)v13 + 3) = 65537;
*((_DWORD *)v13 + 4) = v5;
HIDWORD(ReturnLength) = 0;
if( !*(_DWORD *)(v14 + 20) )
{
LABEL_19:
if( (_DWORD)ReturnLength )
{
v28 = *(VOID **)v4;
LODWORD(Source) = 1;
LODWORD(v7) = IopCreateRegistryKeyEx(
&Handle,
0i64,
&CmRegistryMachineHardwareResourceMapName,
0x2001Fui64,
(UINT64)Source,
0i64);
if( (int)v7 >= 0 )
{
LODWORD(ReturnLength) = 0;
ClassName.Buffer = L"PnP Manager";
*(_QWORD *)&ClassName.Length = 1572886i64;
DriverName.Buffer = L"PnpManager";
*(_QWORD *)&DriverName.Length = 1441812i64;
*(_OWORD *)&Destination[1] = 0i64;
v29 = ObQueryNameStringMode(v28, (_OBJECT_NAME_INFORMATION *)&v47, 0x200ui64, &ReturnLength, 0);
v30 = Handle;
if( v29 >= 0 )
{
WORD1(v47) = 496;
v31 = &v48;
if( (_WORD)v47 )
v31 = (char *)*((_QWORD *)&v47 + 1);
*((_QWORD *)&v47 + 1) = v31;
*(_OWORD *)&Destination[1] = v47;
RtlAppendUnicodeToString((_UNICODE_STRING *)&Destination[1], (WCHAR *)L".Raw");
v32 = ResourceListSize;
LODWORD(Target) = ResourceListSize;
if( IopWriteResourceList(
v30,
&ClassName,
&DriverName,
(_UNICODE_STRING *)&Destination[1],
(_CM_RESOURCE_LIST *)v13,
(UINT64)Target) >= 0 )
{
*(_OWORD *)&Destination[1] = v47;
RtlAppendUnicodeToString((_UNICODE_STRING *)&Destination[1], (WCHAR *)L".Translated");
LODWORD(Targeta) = v32;
IopWriteResourceList(v30, &ClassName, &DriverName, (_UNICODE_STRING *)&Destination[1], v11, (UINT64)Targeta);
}
}
LODWORD(v7) = ZwClose((_HANDLE)v30);
}
}
*(_QWORD *)(v4 + 48) = v11;
v3 = v13;
goto LABEL_21;
}
while( 1 )
{
v18 = *(_QWORD *)(v14 + 8 * v7 + 24);
if( !*(_BYTE *)(v18 + 8) )
{
*(_OWORD *)v17 = *(_OWORD *)(v18 + 136);
*((_DWORD *)v17 + 4) = *(_DWORD *)(v18 + 152);
*PartialDescriptors = *(_CM_PARTIAL_RESOURCE_DESCRIPTOR *)(v18 + 136);
v34 = *(_DWORD *)(v18 + 152);
goto LABEL_33;
}
v19 = *(_QWORD *)(v18 + 32);
*(_QWORD *)&ClassName.Length = v19;
if( *(_DWORD *)(v19 + 128) == 2 )
{
v20 = *(_QWORD *)(v19 + 112);
}
else
{
v39 = IopParentToRawTranslation((_REQ_DESC *)v19);
if( v39 < 0 )
break;
v20 = *(_QWORD *)(v18 + 112);
v19 = *(_QWORD *)&ClassName.Length;
}
*(_OWORD *)v17 = *(_OWORD *)v20;
*((_DWORD *)v17 + 4) = *(_DWORD *)(v20 + 16);
if( *(_DWORD *)(v19 + 128) == 2 )
{
v33 = *(_QWORD *)(v19 + 112);
v14 = Destination[0];
*PartialDescriptors = *(_CM_PARTIAL_RESOURCE_DESCRIPTOR *)v33;
v34 = *(_DWORD *)(v33 + 16);
LABEL_33:
*(_DWORD *)&PartialDescriptors[1].Type = v34;
goto LABEL_17;
}
v21 = *(_QWORD *)(v18 + 72);
v22 = v21 ? *(_DEVICE_NODE **)(*(_QWORD *)(v21 + 312) + 40i64) : 0i64;
v39 = IopChildToRootTranslation(
v22,
*(_INTERFACE_TYPE *)v18,
*(unsigned int *)(v18 + 4),
*(_ARBITER_REQUEST_SOURCE *)(v18 + 80),
(PCM_PARTIAL_RESOURCE_DESCRIPTOR)(v18 + 136),
&v45);
if( v39 < 0 )
break;
v23 = v45;
*PartialDescriptors = *v45;
*(_DWORD *)&PartialDescriptors[1].Type = *(_DWORD *)&v23[1].Type;
ExFreePoolWithTag(v23, 0);
v14 = Destination[0];
LABEL_17:
v24 = *(_DWORD *)(v18 + 276);
v17 += 20;
PartialDescriptors = (_CM_PARTIAL_RESOURCE_DESCRIPTOR *)((char *)PartialDescriptors + 20);
if( v24 )
{
v25 = (_WORD *)(*(_QWORD *)(v18 + 280) + 8i64);
v26 = v24;
do
{
*v17 = -127;
PartialDescriptors->Type = -127;
v17[1] = 1;
PartialDescriptors->ShareDisposition = 1;
v27 = *(v25 - 2);
*((_WORD *)v17 + 1) = v27;
PartialDescriptors->Flags = v27;
memmove(v17 + 4, v25, 0xCu);
memmove(&PartialDescriptors->u, v25, 0xCu);
v25 += 16;
v17 += 20;
PartialDescriptors = (_CM_PARTIAL_RESOURCE_DESCRIPTOR *)((char *)PartialDescriptors + 20);
--v26;
}
while( v26 );
v4 = *(_QWORD *)&DriverName.Length;
v11 = (_CM_RESOURCE_LIST *)Destination[1];
v14 = Destination[0];
}
v7 = (unsigned int)(HIDWORD(ReturnLength) + 1);
HIDWORD(ReturnLength) = v7;
if( (unsigned int)v7 >= *(_DWORD *)(v14 + 20) )
goto LABEL_19;
}
ExFreePoolWithTag(v11, 0);
ExFreePoolWithTag(v13, 0);
LODWORD(v7) = -1073741670;
if( v39 == -1073741267 )
LODWORD(v7) = -1073741267;
*(_DWORD *)(v4 + 56) = v7;
LABEL_21:
*(_QWORD *)(v4 + 40) = v3;
return v7;
}Referenced by:
IopAllocateBootResourcesInternal
PnpBuildCmResourceLists