PipResetDevices
NTSTATUS __stdcall PipResetDevices(INT64 a1){
HPNPCTX *v1;
ULONG v2;
NTSTATUS result;
HPNPCTX *v4;
int v5;
HPNPCTX *v6;
INT64 v7;
INT64 v8;
INT64 v9;
WCHAR *v10;
_ETHREAD *CurrentThread;
_CM_OBJECT_TYPE v12;
VOID **PoolWithTag;
HPNPCTX *v14;
INT64 v15;
INT64 v16;
WCHAR *v17;
_CM_OBJECT_TYPE v18;
_ETHREAD *v19;
VOID **v20;
INT64 v21;
HPNPCTX *v22;
HPNPCTX *v23;
INT64 v24;
INT64 v25;
ULONG v26;
int v27;
NTSTATUS v28;
NTSTATUS MatchingFilteredDeviceList;
_CM_OBJECT_TYPE v30;
VOID **v31;
WCHAR *i;
__int64 v33;
unsigned int v34;
HPNPCTX v35;
NTSTATUS v36;
NTSTATUS v37;
VOID **v38;
WCHAR *v39;
HPNPCTX *v40;
__int64 v41;
UINT64 DesiredAccess;
INT64 DesiredAccessd;
UINT64 DesiredAccessa;
UINT64 DesiredAccessb;
INT64 DesiredAccessc;
VOID **phkResultb;
VOID **phkResult;
VOID **phkResulta;
INT64 v50;
INT64 v51;
VOID *v52;
VOID *v53;
VOID *v54;
WCHAR *v55;
UINT64 v56;
UINT64 *v57;
_HANDLE v58[2];
INT64 v59;
_HANDLE v60[2];
UINT64 DataSize;
int v62;
HPNPCTX v63;
NTSTATUS v64;
_HANDLE v65[2];
INT64 v66;
_CM_OBJECT_TYPE v67;
unsigned int v68;
int Data;
v66 = a1;
v1 = (HPNPCTX *)*(&stru_140CF2E80 + 607);
v2 = 0;
LODWORD(DesiredAccess) = 1;
v59 = *(&stru_140CF2E80 + 607);
*(_QWORD *)v65 = 0i64;
HIDWORD(DataSize) = 0;
Data = 0;
result = PnpCtxRegOpenKey(
*(&stru_140CF2E80 + 607),
(VOID *)0x80000002i64,
(WCHAR *)L"SYSTEM",
0i64,
DesiredAccess,
(VOID **)v65);
if( result >= 0 )
{
LODWORD(DataSize) = 4;
v5 = PnpCtxRegQueryValue(
v4,
*(VOID **)v65,
(WCHAR *)L"DevModeEverEnabled",
(UINT64 *)((char *)&DataSize + 4),
&Data,
&DataSize);
v64 = v5;
PnpCtxRegCloseKey(v6, *(VOID **)v65, v7, v8, DesiredAccessd, (INT64)phkResultb, v50, (INT64)v52);
if( v5 >= 0 && Data )
{
return v5;
}
else
{
LODWORD(v66) = 0;
*(_QWORD *)v58 = 0i64;
v10 = 0i64;
CurrentThread = (_ETHREAD *)KeGetCurrentThread();
v12 = CM_OBJECT_TYPE_NONE;
LODWORD(v57) = 0;
PoolWithTag = 0i64;
v56 = 0i64;
--CurrentThread->Tcb.KernelApcDisable;
ExAcquireResourceExclusiveLite((UINT64)&PnpReplaceEvent + 6688, 1, v9);
LODWORD(DesiredAccessa) = 131097;
if( PnpCtxRegOpenKey(
v1,
(VOID *)0x80000002i64,
(WCHAR *)L"System\\CurrentControlSet\\Control\\StateSeparation\\PnP\\ResetDevices\\Classes",
0i64,
DesiredAccessa,
(VOID **)v58) >= 0
&& (int)PnpCtxRegQueryInfoKey((__int64)v14, *(VOID **)v58, 0i64, 0i64, &v56, (_DWORD *)&v56 + 1, 0i64) >= 0 )
{
v26 = v56;
if( (_DWORD)v56 )
{
v27 = HIDWORD(v56) + 1;
PoolWithTag = ExAllocatePoolWithTag(1ui64, 2i64 * (unsigned int)(HIDWORD(v56) + 1), 1852403792i64);
if( PoolWithTag )
{
v14 = 0i64;
if( v26 )
{
while( 1 )
{
v53 = 0i64;
v62 = v27;
v28 = PnpCtxRegEnumValue(0i64, v58[0], v2, PoolWithTag, (INT64)&v62, 0i64, 0i64);
v14 = 0i64;
if( v28 >= 0 )
{
DbgPrintEx(0x20u, 0, "Resetting devices in device setup class '%ws'\n", PoolWithTag);
MatchingFilteredDeviceList = CmGetMatchingFilteredDeviceList(
v1,
(const WCHAR *)PoolWithTag,
CM_DEVICE_LIST_FILTER_CLASS,
0i64,
0i64,
v10,
v12,
&v66,
v54,
v55,
v56,
v57,
*(UINT64 *)v58);
if( MatchingFilteredDeviceList == -1073741789 )
{
if( v10 )
ExFreePoolWithTag(v10, 0);
v30 = (int)v66;
LODWORD(v57) = v66;
v31 = ExAllocatePoolWithTag(1ui64, 2i64 * (unsigned int)v66, 1852403792i64);
v14 = 0i64;
v10 = (WCHAR *)v31;
if( !v31 )
{
LABEL_38:
v2 = 0;
break;
}
MatchingFilteredDeviceList = CmGetMatchingFilteredDeviceList(
v1,
(const WCHAR *)PoolWithTag,
CM_DEVICE_LIST_FILTER_CLASS,
0i64,
0i64,
(const WCHAR *)v31,
v30,
&v66,
v54,
v55,
v56,
v57,
*(UINT64 *)v58);
}
v14 = 0i64;
if( MatchingFilteredDeviceList >= 0 )
{
if( (_DWORD)v66 )
{
for( i = v10; *i; i += v33 + 1 )
{
PipResetDevice(v1, i);
v33 = -1i64;
v14 = 0i64;
do
++v33;
while( i[v33] );
}
}
}
}
v12 = (int)v57;
if( ++v2 >= v26 )
goto LABEL_38;
}
}
}
}
}
if( *(_QWORD *)v58 )
PnpCtxRegCloseKey(v14, *(VOID **)v58, v15, v16, DesiredAccessb, (INT64)phkResult, v51, (INT64)v53);
if( PoolWithTag )
ExFreePoolWithTag(PoolWithTag, 0);
if( v10 )
ExFreePoolWithTag(v10, 0);
ExReleaseResourceLite((PERESOURCE)((char *)&PnpReplaceEvent + 6688));
KeLeaveCriticalRegionThread(KeGetCurrentThread());
v67 = CM_OBJECT_TYPE_NONE;
v17 = 0i64;
*(_QWORD *)v60 = 0i64;
v18 = CM_OBJECT_TYPE_NONE;
v19 = (_ETHREAD *)KeGetCurrentThread();
v20 = 0i64;
HIDWORD(v57) = 0;
v68 = 0;
--v19->Tcb.KernelApcDisable;
ExAcquireResourceExclusiveLite((UINT64)&PnpReplaceEvent + 6688, 1, v21);
v22 = (HPNPCTX *)v59;
LODWORD(DesiredAccessb) = 131097;
if( PnpCtxRegOpenKey(
(HPNPCTX *)v59,
(VOID *)0x80000002i64,
(WCHAR *)L"System\\CurrentControlSet\\Control\\StateSeparation\\PnP\\ResetDevices\\Services",
0i64,
DesiredAccessb,
(VOID **)v60) >= 0
&& (int)PnpCtxRegQueryInfoKey((__int64)v23, *(VOID **)v60, 0i64, 0i64, &v68, (_DWORD *)&v57 + 1, 0i64) >= 0 )
{
v34 = v68;
if( v68 )
{
v35 = HIDWORD(v57) + 1;
LODWORD(v66) = HIDWORD(v57) + 1;
v20 = ExAllocatePoolWithTag(1ui64, 2i64 * (unsigned int)(HIDWORD(v57) + 1), 1852403792i64);
if( v20 )
{
v23 = 0i64;
if( v34 )
{
do
{
v53 = 0i64;
v63 = v35;
v36 = PnpCtxRegEnumValue(0i64, v60[0], v2, v20, (INT64)&v63, 0i64, 0i64);
v23 = 0i64;
if( v36 >= 0 )
{
DbgPrintEx(0x20u, 0, "Resetting devices using service '%ws'\n", v20);
v37 = CmGetMatchingFilteredDeviceList(
v22,
(const WCHAR *)v20,
CM_DEVICE_LIST_FILTER_SERVICE,
0i64,
0i64,
v17,
v18,
&v67,
v54,
v55,
v56,
v57,
*(UINT64 *)v58);
if( v37 == -1073741789 )
{
if( v17 )
ExFreePoolWithTag(v17, 0);
v18 = v67;
v38 = ExAllocatePoolWithTag(1ui64, 2i64 * (unsigned int)v67, 1852403792i64);
v23 = 0i64;
v17 = (WCHAR *)v38;
if( !v38 )
break;
v37 = CmGetMatchingFilteredDeviceList(
v22,
(const WCHAR *)v20,
CM_DEVICE_LIST_FILTER_SERVICE,
0i64,
0i64,
(const WCHAR *)v38,
v18,
&v67,
v54,
v55,
v56,
v57,
*(UINT64 *)v58);
}
v23 = 0i64;
if( v37 >= 0 && v67 )
{
v39 = v17;
if( *v17 )
{
v40 = (HPNPCTX *)v59;
do
{
PipResetDevice(v40, v39);
v41 = -1i64;
v23 = 0i64;
do
++v41;
while( v39[v41] );
v39 += v41 + 1;
}
while( *v39 );
v34 = v68;
v35 = v66;
}
v22 = (HPNPCTX *)v59;
}
}
++v2;
}
while( v2 < v34 );
}
}
}
}
if( *(_QWORD *)v60 )
PnpCtxRegCloseKey(v23, *(VOID **)v60, v24, v25, DesiredAccessc, (INT64)phkResulta, v51, (INT64)v53);
if( v20 )
ExFreePoolWithTag(v20, 0);
if( v17 )
ExFreePoolWithTag(v17, 0);
ExReleaseResourceLite((PERESOURCE)((char *)&PnpReplaceEvent + 6688));
KeLeaveCriticalRegionThread(KeGetCurrentThread());
return v64;
}
}
return result;
}Referenced by:
IopInitializePlugPlayServices