PnpFilterResourceRequirementsList
__int64 __fastcall PnpFilterResourceRequirementsList(VOID *Src, unsigned int *a2, char **a3, _DWORD *a4){
unsigned int v4;
unsigned int *v6;
int v8;
VOID **PoolWithTag;
__int64 v10;
unsigned int *v11;
__int64 v12;
unsigned int *v13;
unsigned int v14;
__int64 i;
unsigned __int8 v16;
unsigned int v17;
int v18;
__int64 v19;
int v20;
unsigned __int64 v21;
int v22;
unsigned __int64 v23;
bool v24;
int v25;
int v26;
__int64 v27;
_IO_RESOURCE_DESCRIPTOR *v28;
__int64 v29;
_CM_PARTIAL_RESOURCE_DESCRIPTOR *v30;
int v31;
unsigned int v32;
_CM_PARTIAL_RESOURCE_DESCRIPTOR *v33;
unsigned int v34;
_CM_PARTIAL_RESOURCE_DESCRIPTOR *v35;
unsigned __int64 v36;
unsigned int v37;
_IO_RESOURCE_DESCRIPTOR *v38;
unsigned __int8 Type;
unsigned __int64 v40;
int ShareDisposition;
unsigned __int64 HighPart;
int v43;
unsigned __int8 v44;
int v45;
UINT64 Length;
UINT64 v47;
unsigned __int64 v48;
unsigned __int64 v49;
UINT64 v50;
unsigned __int8 v51;
_IO_RESOURCE_DESCRIPTOR *m;
__int64 LowPart;
int v54;
size_t v55;
VOID **v56;
VOID **v57;
unsigned int *v58;
unsigned int v59;
int v60;
_OWORD *v61;
unsigned __int64 v62;
unsigned __int64 v63;
unsigned __int64 v64;
__int16 v65;
char *v66;
ULONGLONG v67;
int v69;
int v70;
int v71;
int v72;
int v73;
_IO_RESOURCE_DESCRIPTOR *j;
_IO_RESOURCE_DESCRIPTOR *k;
PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor;
unsigned __int64 v77;
int v78;
unsigned int v79;
int v80;
int v81;
__int64 v82;
__int16 v83;
unsigned int v84;
unsigned int v85;
int v86;
int v87;
unsigned __int64 Start;
int v89;
int v90;
int v91;
UINT64 MinimumAddress;
UINT64 MaximumAddress;
UINT64 Alignment;
__int64 v95;
unsigned __int64 v96;
VOID **v97;
__int64 v98;
unsigned int *v99;
_CM_PARTIAL_RESOURCE_DESCRIPTOR *v100;
unsigned __int8 v101;
v4 = 0;
v95 = 0i64;
v6 = a2;
v80 = 0;
*a3 = 0i64;
v8 = 0;
*a4 = 0;
if( !Src || !*((_DWORD *)Src + 7) )
{
if( a2 && *a2 )
*a3 = (char *)PnpCmResourcesToIoResources((__int64)Src, a2, 1);
return 0i64;
}
PoolWithTag = ExAllocatePoolWithTag(1ui64, *(unsigned int *)Src, 1970499664i64);
v97 = PoolWithTag;
v10 = (__int64)PoolWithTag;
if( !PoolWithTag )
return 3221225626i64;
memmove(PoolWithTag, Src, *(_DWORD *)Src);
if( !v6 || !*v6 )
goto LABEL_154;
v11 = v6 + 1;
v12 = *v6;
v99 = v6 + 1;
v13 = v6 + 1;
do
{
v14 = v13[3];
v13 += 4;
v8 += v14;
if( v14 )
{
for( i = v14; i; --i )
{
v16 = *(_BYTE *)v13;
v17 = 0;
if( *(_BYTE *)v13 == 5 )
{
v17 = v13[1];
}
else if( (v16 <= 0x7Fu || v16 > 0x81u) && (unsigned __int8)(v16 - 1) <= 6u )
{
goto LABEL_12;
}
--v8;
LABEL_12:
v13 = (unsigned int *)((char *)v13 + v17 + 20);
}
}
--v12;
}
while( v12 );
v81 = v8;
if( !v8 )
{
LABEL_154:
*a3 = (char *)v10;
return 0i64;
}
v18 = *(_DWORD *)(v10 + 28);
v19 = v10 + 32;
v20 = 0;
v87 = 0;
v21 = v10 + 32;
v22 = v18 - 1;
if( v18 - 1 >= 0 )
{
do
{
v23 = v21 + 8;
v21 += 8 + 32i64 * *(unsigned int *)(v21 + 4);
while( v23 < v21 )
{
v24 = *(_BYTE *)(v23 + 1) == 0;
v25 = v20 + 1;
*(_BYTE *)(v23 + 3) = 0;
if( !v24 )
v25 = v20;
v23 += 32i64;
v20 = v25;
}
--v22;
}
while( v22 >= 0 );
v18 = *(_DWORD *)(v10 + 28);
v87 = v20;
}
v26 = v18 - 1;
v91 = v18 - 1;
v86 = v18 - 1;
if( v18 - 1 >= 0 )
{
while( 2 )
{
v83 = *(_WORD *)v19;
if( *(_WORD *)v19 == 0xFFFF )
v83 = 1;
v27 = *(unsigned int *)(v19 + 4);
v28 = (_IO_RESOURCE_DESCRIPTOR *)(v19 + 8);
*(_WORD *)v19 = 0;
v29 = v19 + 8 + 32 * v27;
v98 = v27;
v77 = v29;
if( v19 + 8 == v29 )
{
*(_WORD *)v19 = -1;
--*(_DWORD *)(v10 + 28);
goto LABEL_80;
}
v30 = (_CM_PARTIAL_RESOURCE_DESCRIPTOR *)v11;
v31 = 1;
v32 = 0;
v100 = (_CM_PARTIAL_RESOURCE_DESCRIPTOR *)v11;
v78 = 1;
v85 = 0;
if( *v6 )
{
do
{
v33 = v30 + 1;
v34 = 0;
Descriptor = v30 + 1;
v84 = 0;
if( v30->u.Length )
{
v35 = v100;
do
{
if( v33->Type == 5 )
{
LowPart = v33->u.Start.anonymous_0.LowPart;
}
else
{
if( v33->Type != 129 && (unsigned __int8)(v33->Type - 1) <= 6u )
{
v36 = v77;
v37 = 0;
v79 = 0;
while( 1 )
{
v38 = v28;
if( (unsigned __int64)v28 >= v36 )
goto LABEL_67;
Type = v33->Type;
v40 = v77;
v101 = v33->Type;
while( 1 )
{
if( v38->Type != Type || v38->Spare1 )
goto LABEL_40;
ShareDisposition = v33->ShareDisposition;
HighPart = 0i64;
v43 = v38->ShareDisposition;
v44 = v33->ShareDisposition - 1;
Start = 0i64;
MinimumAddress = 0i64;
v45 = ShareDisposition;
MaximumAddress = 0i64;
if( v44 > 2u )
v45 = v43;
v82 = 1i64;
v89 = v45;
Alignment = 1i64;
if( (unsigned __int8)(v43 - 1) > 2u )
v43 = (unsigned __int8)v45;
Length = 0i64;
v90 = v43;
v47 = 0i64;
v48 = 1i64;
if( Type != 1 )
{
if( Type == 2 )
{
HighPart = (unsigned int)Descriptor->u.Start.anonymous_0.HighPart;
v49 = HighPart;
LABEL_50:
Length = v38->u.Port.Length;
v47 = v38->u.Port.Alignment;
LABEL_51:
v50 = 1i64;
goto LABEL_52;
}
if( Type != 3 )
{
if( Type == 4 )
{
v49 = Descriptor->u.Start.anonymous_0.LowPart;
HighPart = v49;
goto LABEL_50;
}
if( Type == 6 )
{
Length = v38->u.Port.Alignment;
v47 = v38->u.Port.MinimumAddress.anonymous_0.LowPart;
v50 = v38->u.Port.Length;
HighPart = Descriptor->u.Start.anonymous_0.LowPart;
v48 = (unsigned int)Descriptor->u.Start.anonymous_0.HighPart;
v49 = (unsigned int)(v48 + HighPart - 1);
goto LABEL_99;
}
if( Type != 7 )
{
v49 = 0i64;
goto LABEL_51;
}
}
}
v67 = RtlCmDecodeMemIoResource(Descriptor, &Start);
HighPart = Start;
v96 = v67;
Start = v67 + Start - 1;
v50 = RtlIoDecodeMemIoResource(v38, &Alignment, &MinimumAddress, &MaximumAddress);
Length = MinimumAddress;
v47 = MaximumAddress;
v49 = Start;
v48 = v96;
LOBYTE(v45) = v89;
LOBYTE(v43) = v90;
LABEL_99:
v82 = v50;
LABEL_52:
if( v79 )
{
v78 = 0;
if( v47 >= v49
&& (_BYTE)v45 == (_BYTE)v43
&& Length <= HighPart
&& v50 >= v48
&& ((Alignment - 1) & HighPart) == 0 )
{
v69 = Type - 1;
if( !v69 )
goto LABEL_128;
v70 = v69 - 1;
if( !v70 )
goto LABEL_138;
v71 = v70 - 1;
if( !v71 )
goto LABEL_128;
v72 = v71 - 1;
if( v72 )
{
v73 = v72 - 2;
if( v73 )
{
if( v73 == 1 )
{
LABEL_128:
v38->u.Port.MinimumAddress.QuadPart = HighPart;
v38->u.Port.MaximumAddress.QuadPart = HighPart + v82 - 1;
}
}
else
{
v38->u.Port.Alignment = HighPart;
v38->u.Port.MinimumAddress.anonymous_0.LowPart = HighPart + v82 - 1;
}
}
else
{
LABEL_138:
v38->u.Port.Length = HighPart;
v38->u.Port.Alignment = v49;
}
++*(_WORD *)v19;
v28 = (_IO_RESOURCE_DESCRIPTOR *)(v19 + 8);
v24 = (v38->Option & 8) == 0;
v33 = Descriptor;
v38->Spare1 = 0x80;
v38->Flags = Descriptor->Flags;
if( !v24 )
{
for( j = v38 - 1; j >= v28; --j )
{
j->Type = 0;
--*(_DWORD *)(v19 + 4);
if( j->Option != 8 )
break;
}
}
v36 = v77;
v38->Option = 1;
while( (unsigned __int64)++v38 < v77 && (v38->Option & 8) != 0 )
{
v38->Type = 0;
--*(_DWORD *)(v19 + 4);
}
v31 = 0;
LABEL_42:
v37 = v79;
goto LABEL_67;
}
goto LABEL_101;
}
if( Length == HighPart && (_BYTE)v45 == (_BYTE)v43 && v47 >= v49 && v50 >= v48 )
break;
LABEL_101:
v33 = Descriptor;
Type = v101;
v40 = v77;
LABEL_40:
if( (unsigned __int64)++v38 >= v40 )
{
v36 = v77;
v28 = (_IO_RESOURCE_DESCRIPTOR *)(v19 + 8);
v31 = v78;
goto LABEL_42;
}
}
v31 = v78;
v24 = v47 == v49;
v28 = (_IO_RESOURCE_DESCRIPTOR *)(v19 + 8);
if( !v24 )
v31 = 0;
++*(_WORD *)v19;
v24 = (v38->Option & 8) == 0;
v78 = v31;
v38->Spare1 = 0x80;
if( !v24 )
{
for( k = v38 - 1; k >= v28; --k )
{
k->Type = 0;
--*(_DWORD *)(v19 + 4);
if( k->Option != 8 )
break;
}
}
v33 = Descriptor;
v51 = v38->Type;
v38->Option = 1;
v38->Flags = Descriptor->Flags;
if( ((v51 - 1) & 0xF9) != 0 || v51 == 5 )
{
if( v51 == 6 )
{
v38->u.Port.Alignment = HighPart;
v38->u.Port.MinimumAddress.anonymous_0.LowPart = HighPart + v82 - 1;
}
}
else
{
v38->u.Port.MinimumAddress.QuadPart = HighPart;
v38->u.Port.Alignment = 1;
v38->u.Port.MaximumAddress.QuadPart = HighPart + v82 - 1;
}
v36 = v77;
for( m = v38 + 1; (unsigned __int64)m < v77 && (m->Option & 8) != 0; ++m )
{
m->Type = 0;
--*(_DWORD *)(v19 + 4);
}
v37 = 1;
LABEL_67:
v79 = ++v37;
if( v37 >= 2 )
{
v34 = v84;
break;
}
}
}
LowPart = 0i64;
}
++v34;
v33 = (_CM_PARTIAL_RESOURCE_DESCRIPTOR *)((char *)v33 + LowPart + 20);
v84 = v34;
Descriptor = v33;
}
while( v34 < v35->u.Length );
v6 = a2;
v32 = v85;
}
++v32;
v30 = v33;
v100 = v33;
v85 = v32;
}
while( v32 < *v6 );
v10 = (__int64)v97;
v11 = v6 + 1;
v8 = v81;
v29 = v77;
v26 = v86;
LODWORD(v27) = v98;
}
if( *(_WORD *)v19 == (_WORD)v8 )
{
v54 = *(_DWORD *)(v19 + 4);
if( v54 != v8 && (v54 != v8 + 1 || *(_BYTE *)(v19 + 9) != 0x80) )
{
v80 += v54;
*(_WORD *)v19 = v83;
goto LABEL_79;
}
if( !v95 )
{
v80 += v54;
v95 = v19;
*(_WORD *)v19 = v83;
if( v31 )
*a4 = 1;
goto LABEL_79;
}
}
*(_WORD *)v19 = -1;
--*(_DWORD *)(v10 + 28);
LABEL_79:
*(_DWORD *)(v19 + 4) = v27;
v19 = v29;
LABEL_80:
v18 = *(_DWORD *)(v10 + 28);
v86 = --v26;
if( v26 >= 0 )
continue;
break;
}
v20 = v87;
}
if( v18 )
{
v55 = 32 * (v80 - v20 + 1) + 40 * v18;
v56 = ExAllocatePoolWithTag(1ui64, v55, 1970499664i64);
v57 = v56;
if( v56 )
{
memset(v56, 0i64, v55);
v58 = v99;
*(_DWORD *)v57 = v55;
*((_DWORD *)v57 + 1) = *v58;
*((_DWORD *)v57 + 2) = a2[2];
*((_DWORD *)v57 + 3) = *(_DWORD *)(v10 + 12);
v59 = *(_DWORD *)(v10 + 28);
if( v59 > 1 )
*a4 = 0;
v60 = v91;
v61 = v57 + 4;
*((_DWORD *)v57 + 7) = v59;
if( v60 >= 0 )
{
v62 = v10 + 32;
do
{
v63 = v62 + 8;
v64 = v62 + 8 + 32i64 * *(unsigned int *)(v62 + 4);
if( *(_WORD *)v62 != 0xFFFF )
{
*(_WORD *)v61 = *(_WORD *)v62;
v65 = *(_WORD *)(v62 + 2);
v66 = (char *)v61 + 8;
*((_WORD *)v61 + 1) = v65;
if( *(_BYTE *)(v63 + 1) == 0x80 )
{
*(_DWORD *)v57 -= 32;
}
else
{
*((_WORD *)v61 + 4) = -32767;
v66 = (char *)v61 + 40;
*(_DWORD *)((char *)v61 + 10) = 3;
*((_WORD *)v61 + 7) = 0;
*((_DWORD *)v61 + 4) = 1;
}
while( v63 < v64 )
{
if( *(_BYTE *)(v63 + 1) )
{
*(_OWORD *)v66 = *(_OWORD *)v63;
*((_OWORD *)v66 + 1) = *(_OWORD *)(v63 + 16);
v66 += 32;
}
v63 += 32i64;
}
*((_DWORD *)v61 + 1) = (v66 - (char *)v61 - 8) >> 5;
*((_DWORD *)v61 + 4) = 1;
v61 = v66;
}
--v60;
v62 = v64;
}
while( v60 >= 0 );
}
*a3 = (char *)v57;
ExFreePoolWithTag((PVOID)v10, 0);
return 0i64;
}
v4 = -1073741670;
}
else
{
*a3 = (char *)PnpCmResourcesToIoResources(0xFFFFi64, v6, 1);
}
ExFreePoolWithTag((PVOID)v10, 0);
return v4;
}Referenced by:
IopQueryDeviceResources
PnpGetResourceRequirementsForAssignTable