PiDevCfgEnforceDevicePolicy
INT64 __fastcall PiDevCfgEnforceDevicePolicy(INT64 a1, INT64 a2, const WCHAR *a3){
int v5;
NTSTATUS v6;
unsigned int v7;
char v8;
unsigned int v9;
int v10;
_WORD *v11;
int v12;
wchar_t *v13;
const wchar_t *v14;
__int64 v15;
const wchar_t *v16;
__int64 v17;
int v18;
wchar_t *v19;
int v20;
WCHAR *v21;
WCHAR *v22;
WCHAR *v23;
const wchar_t *v24;
wchar_t *v25;
char v26;
const wchar_t *v27;
__int64 v28;
const wchar_t *v29;
__int64 v30;
__int64 v31;
int v32;
WCHAR *v33;
int v34;
WCHAR *v35;
const wchar_t *v36;
__int64 v37;
const wchar_t *v38;
__int64 v39;
bool v40;
PVOID v41;
unsigned int v42;
char v44;
char v45;
char v46;
char v47;
char v48;
char v49;
HANDLE Handle;
PVOID P;
BOOL v52;
__int64 v53;
const wchar_t *v54;
void *KeyHandle;
wchar_t *Str1;
WCHAR *PolicyStringList;
WCHAR *v58;
struct _OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR *v60;
WCHAR *v61;
PVOID v62;
UINT8 PolicyEnabled;
v53 = 8913030i64;
Handle = 0i64;
v54 = L"\\Registry\\Machine\\Software\\Policies\\Microsoft\\Windows\\DeviceInstall";
P = 0i64;
ObjectAttributes.ObjectName = (_UNICODE_STRING *)&v53;
Str1 = 0i64;
PolicyStringList = 0i64;
v58 = 0i64;
v60 = 0i64;
v61 = 0i64;
PolicyEnabled = 0;
v5 = 576;
*(_QWORD *)&ObjectAttributes.Length = 48i64;
*(_QWORD *)&ObjectAttributes.Attributes = 576i64;
KeyHandle = 0i64;
ObjectAttributes.RootDirectory = 0i64;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
v6 = ZwOpenKey(&KeyHandle, 0x20019u, &ObjectAttributes);
if( v6 == -1073741772 )
{
if( !PnpBootMode )
{
LABEL_5:
v7 = 0;
goto LABEL_129;
}
LODWORD(v53) = 6422624;
v54 = L"\\Registry\\Machine\\System\\DriverDatabase\\Policies";
*(_QWORD *)&ObjectAttributes.Length = 48i64;
ObjectAttributes.ObjectName = (_UNICODE_STRING *)&v53;
*(_QWORD *)&ObjectAttributes.Attributes = 576i64;
KeyHandle = 0i64;
ObjectAttributes.RootDirectory = 0i64;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
v6 = ZwOpenKey(&KeyHandle, 0x20019u, &ObjectAttributes);
}
if( v6 < 0 )
goto LABEL_5;
LODWORD(v53) = 1703960;
v54 = L"Restrictions";
ObjectAttributes.RootDirectory = KeyHandle;
*(_QWORD *)&ObjectAttributes.Length = 48i64;
ObjectAttributes.ObjectName = (_UNICODE_STRING *)&v53;
*(_QWORD *)&ObjectAttributes.Attributes = 576i64;
*(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
if( ZwOpenKey(&Handle, 0x20019u, &ObjectAttributes) < 0 )
goto LABEL_5;
LOBYTE(v5) = 0;
v8 = 0;
v52 = v5;
v44 = 0;
v47 = 0;
v46 = 0;
v45 = 0;
v48 = 0;
v49 = 0;
v9 = 1;
if( (int)PiDevCfgQueryPolicyEnabled(Handle, L"AllowDenyLayered", &PolicyEnabled) >= 0 )
v52 = PolicyEnabled != 0;
if( (int)PiDevCfgQueryPolicyEnabled(Handle, L"DenyRemovableDevices", &PolicyEnabled) >= 0
&& PolicyEnabled
&& (*(_BYTE *)(a1 + 560) & 0x10) != 0 )
{
v8 = 1;
}
v10 = PiDevCfgQueryPolicyStringList(Handle, (WCHAR *)L"AllowDeviceClasses", (WCHAR **)&P);
v11 = P;
if( v10 < 0 )
v11 = 0i64;
P = v11;
v12 = PiDevCfgQueryPolicyStringList(Handle, (WCHAR *)L"DenyDeviceClasses", &Str1);
v13 = Str1;
if( v12 < 0 )
v13 = 0i64;
v62 = v13;
if( a3 )
{
if( v11 )
{
v14 = v11;
if( *v11 )
{
while( wcsicmp(v14, a3) )
{
v15 = -1i64;
do
++v15;
while( v14[v15] );
v14 += v15 + 1;
if( !*v14 )
goto LABEL_28;
}
v44 = 1;
}
}
else if( !v13 )
{
goto LABEL_36;
}
LABEL_28:
if( v13 )
{
v16 = v13;
if( *v13 )
{
while( wcsicmp(v16, a3) )
{
v17 = -1i64;
do
++v17;
while( v16[v17] );
v16 += v17 + 1;
if( !*v16 )
goto LABEL_36;
}
v47 = 1;
v8 = 1;
}
}
}
LABEL_36:
v18 = PiDevCfgQueryPolicyStringList(Handle, (WCHAR *)L"AllowDeviceIDs", &PolicyStringList);
v19 = PolicyStringList;
if( v18 < 0 )
v19 = 0i64;
Str1 = v19;
v20 = PiDevCfgQueryPolicyStringList(Handle, (WCHAR *)L"DenyDeviceIDs", &v58);
v21 = v58;
if( v20 < 0 )
v21 = 0i64;
if( v19 || v21 )
{
v22 = (WCHAR *)2;
v23 = (WCHAR *)(a2 + 32);
PolicyStringList = (WCHAR *)2;
v58 = (WCHAR *)(a2 + 32);
do
{
v24 = *(const wchar_t **)v23;
if( *(_QWORD *)v23 && *v24 )
{
v25 = Str1;
v26 = v45;
do
{
if( v25 )
{
if( !v26 )
{
v27 = v25;
if( *v25 )
{
while( wcsicmp(v27, v24) )
{
v28 = -1i64;
do
++v28;
while( v27[v28] );
v27 += v28 + 1;
if( !*v27 )
goto LABEL_55;
}
v26 = 1;
v44 = 1;
}
}
}
LABEL_55:
if( v21 )
{
if( !v46 )
{
v29 = v21;
if( *v21 )
{
while( wcsicmp(v29, v24) )
{
v30 = -1i64;
do
++v30;
while( v29[v30] );
v29 += v30 + 1;
if( !*v29 )
goto LABEL_64;
}
v46 = 1;
v8 = 1;
}
}
}
LABEL_64:
v31 = -1i64;
do
++v31;
while( v24[v31] );
v24 += v31 + 1;
}
while( *v24 );
v22 = PolicyStringList;
v45 = v26;
v23 = v58;
}
v23 += 8;
v22 = (WCHAR *)((char *)v22 - 1);
v58 = v23;
PolicyStringList = v22;
}
while( v22 );
v19 = Str1;
}
v32 = PiDevCfgQueryPolicyStringList(Handle, (WCHAR *)L"AllowInstanceIDs", &v60);
v33 = v60;
if( v32 < 0 )
v33 = 0i64;
v34 = PiDevCfgQueryPolicyStringList(Handle, (WCHAR *)L"DenyInstanceIDs", &v61);
v35 = v61;
if( v34 < 0 )
v35 = 0i64;
if( v33 )
{
v36 = v33;
if( *v33 )
{
while( wcsicmp(v36, *(const wchar_t **)(a2 + 8)) )
{
v37 = -1i64;
do
++v37;
while( v36[v37] );
v36 += v37 + 1;
if( !*v36 )
goto LABEL_84;
}
v49 = 1;
v44 = 1;
}
}
else if( !v35 )
{
goto LABEL_92;
}
LABEL_84:
if( v35 )
{
v38 = v35;
if( *v35 )
{
while( wcsicmp(v38, *(const wchar_t **)(a2 + 8)) )
{
v39 = -1i64;
do
++v39;
while( v38[v39] );
v38 += v39 + 1;
if( !*v38 )
goto LABEL_92;
}
v48 = 1;
v8 = 1;
}
}
LABEL_92:
if( v8 )
{
v41 = P;
v40 = v52;
goto LABEL_105;
}
if( v44 )
{
v41 = P;
goto LABEL_101;
}
v40 = v52;
if( v52 || (int)PiDevCfgQueryPolicyEnabled(Handle, L"DenyUnspecified", &PolicyEnabled) < 0 || !PolicyEnabled )
{
v41 = P;
v7 = 0;
goto LABEL_117;
}
v41 = P;
if( (a3 || !P) && (!PnpSetupInProgress || !PnpSetupUpgradeInProgress) )
{
LABEL_105:
if( v40 && v44 )
{
if( v48 )
{
v9 = 0;
}
else if( !v46 )
{
v9 = 3 - (v47 != 0);
}
if( v49 )
v42 = 0;
else
v42 = 2 - (v45 != 0);
v7 = v42 >= v9 ? 0xC0000361 : 0;
}
else
{
v7 = -1073740959;
}
goto LABEL_117;
}
LABEL_101:
v7 = 0;
LABEL_117:
if( v41 )
ExFreePoolWithTag(v41, 0);
if( v62 )
ExFreePoolWithTag(v62, 0);
if( v19 )
ExFreePoolWithTag(v19, 0);
if( v21 )
ExFreePoolWithTag(v21, 0);
if( v33 )
ExFreePoolWithTag(v33, 0);
if( v35 )
ExFreePoolWithTag(v35, 0);
LABEL_129:
if( Handle )
ZwClose(Handle);
if( KeyHandle )
ZwClose(KeyHandle);
return v7;
}Referenced by:
PiDevCfgConfigureDevice