CmDeleteDeviceWorker
__int64 __fastcall CmDeleteDeviceWorker(__int64 a1, const wchar_t *a2, __int16 a3){
int v5;
PVOID v6;
void *PoolWithTag;
int v8;
int v9;
int DeviceRegProp;
int ObjectProperty;
int MatchingFilteredDeviceInterfaceList;
const WCHAR *i;
__int64 v14;
PVOID v15;
int v16;
int MatchingDeviceList;
int *v18;
unsigned int v19;
int v20;
PVOID v21;
int k;
unsigned int v23;
unsigned __int64 v24;
unsigned int v25;
int v26;
unsigned __int64 v28;
unsigned __int64 v29;
_WORD *j;
__int64 v31;
SIZE_T NumberOfBytes;
unsigned int v33;
unsigned int v34;
HANDLE Handle;
int v36;
PVOID v37;
int v38;
PVOID v39;
PVOID P;
__int128 v41[2];
__int16 v42[40];
__int16 v43[40];
Handle = 0i64;
v5 = 0;
P = 0i64;
v6 = 0i64;
v39 = 0i64;
PoolWithTag = 0i64;
v8 = 0;
v33 = 0;
v38 = 0;
NumberOfBytes = 0i64;
v36 = 0;
v37 = 0i64;
if( a3 )
return(unsigned int)-1073741811;
v9 = CmOpenDeviceRegKey(a1, a2, 16, 0, 33619970, 0, (__int64)&Handle, 0i64);
if( v9 < 0 )
goto LABEL_51;
LODWORD(NumberOfBytes) = 78;
DeviceRegProp = CmGetDeviceRegProp(
a1,
a2,
(__int64)Handle,
37,
(__int64)&v38,
(__int64)v42,
(__int64)&NumberOfBytes,
0);
if( DeviceRegProp < 0 )
{
if( DeviceRegProp == -1073741275 )
goto LABEL_6;
LABEL_67:
v9 = DeviceRegProp;
goto LABEL_51;
}
DeviceRegProp = CmGetDeviceContainerIdFromBase(a1, a2, (const wchar_t *)v42, (wchar_t *)v43);
if( DeviceRegProp < 0 )
goto LABEL_67;
DeviceRegProp = CmRemoveDeviceFromContainer(a1, (const WCHAR *)v43, (__int64)v42, (__int64)a2);
if( DeviceRegProp < 0 )
goto LABEL_67;
LABEL_6:
while( 1 )
{
ObjectProperty = PnpGetObjectProperty(
a1,
(__int64)a2,
1i64,
(__int64)Handle,
0i64,
(__int64)&DEVPKEY_Device_PanelId,
&v36,
(unsigned __int64)PoolWithTag,
v8,
(ULONG *)&NumberOfBytes,
0);
if( ObjectProperty != -1073741789 )
break;
if( PoolWithTag )
ExFreePoolWithTag(PoolWithTag, 0);
v8 = NumberOfBytes;
PoolWithTag = ExAllocatePoolWithTag(PagedPool, (unsigned int)NumberOfBytes, 0x52504E50ui64);
if( !PoolWithTag )
{
ObjectProperty = -1073741801;
break;
}
}
if( ObjectProperty < 0 )
{
if( ObjectProperty == -1073741275 )
goto LABEL_9;
LABEL_78:
v9 = ObjectProperty;
goto LABEL_49;
}
if( v36 != 18
|| (unsigned int)NumberOfBytes < 2
|| *((_WORD *)PoolWithTag + ((unsigned __int64)(unsigned int)NumberOfBytes >> 1) - 1) )
{
v9 = -1073741823;
goto LABEL_49;
}
ObjectProperty = CmRemovePanelDevice(a1, (const WCHAR *)PoolWithTag, (__int64)a2);
if( ObjectProperty < 0 )
goto LABEL_78;
while( 1 )
{
LABEL_9:
MatchingFilteredDeviceInterfaceList = CmGetMatchingFilteredDeviceInterfaceList(
a1,
0i64,
(__int64)a2,
0,
0i64,
0i64,
(__int64)v6,
v5,
(__int64)&NumberOfBytes + 4,
0);
if( MatchingFilteredDeviceInterfaceList != -1073741789 )
goto LABEL_10;
v28 = 2i64 * HIDWORD(NumberOfBytes);
if( v28 > 0xFFFFFFFF )
{
MatchingFilteredDeviceInterfaceList = -1073741811;
goto LABEL_63;
}
if( v6 )
ExFreePoolWithTag(v6, 0);
P = ExAllocatePoolWithTag(PagedPool, (unsigned int)v28, 0x52504E50ui64);
v6 = P;
if( !P )
break;
v5 = HIDWORD(NumberOfBytes);
}
MatchingFilteredDeviceInterfaceList = -1073741801;
LABEL_10:
if( MatchingFilteredDeviceInterfaceList )
{
LABEL_63:
v9 = MatchingFilteredDeviceInterfaceList;
goto LABEL_45;
}
if( HIDWORD(NumberOfBytes) )
{
for( i = (const WCHAR *)v6; *i; i += v14 + 1 )
{
CmDeleteDeviceInterface(a1, i, 0);
v14 = -1i64;
do
++v14;
while( i[v14] );
}
}
v15 = v39;
v16 = 0;
while( 2 )
{
MatchingDeviceList = CmGetMatchingDeviceList(
a1,
(__int64)CmMatchLastKnownParentCallback,
(__int64)a2,
(__int64)v15,
v16,
(__int64)&v33,
0);
if( MatchingDeviceList != -1073741789 )
goto LABEL_18;
v29 = 2i64 * v33;
if( v29 > 0xFFFFFFFF )
{
MatchingDeviceList = -1073741811;
goto LABEL_88;
}
if( v15 )
ExFreePoolWithTag(v15, 0);
v39 = ExAllocatePoolWithTag(PagedPool, (unsigned int)v29, 0x52504E50ui64);
v15 = v39;
if( v39 )
{
v16 = v33;
continue;
}
break;
}
MatchingDeviceList = -1073741801;
LABEL_18:
if( MatchingDeviceList )
{
LABEL_88:
v9 = MatchingDeviceList;
goto LABEL_43;
}
if( v33 )
{
for( j = v15; *j; j += v31 + 1 )
{
PnpSetObjectProperty(a1, (__int64)j, 1u, 0i64, 0i64, (__int64)DEVPKEY_Device_LastKnownParent, 0, 0i64, 0, 0);
v31 = -1i64;
do
++v31;
while( j[v31] );
}
}
v18 = (int *)v41;
v19 = 0;
v41[0] = (__int128)_mm_load_si128((const __m128i *)&_xmm);
v41[1] = (__int128)_mm_load_si128((const __m128i *)&_xmm);
while( 1 )
{
v20 = CmDeleteDeviceRegKey(a1, a2, *v18, 0);
if( v20 )
{
if( v20 != -1073741637 && v20 != -1073741772 && v20 != -1073741811 )
break;
}
++v19;
++v18;
if( v19 >= 8 )
goto LABEL_24;
}
v9 = v20;
LABEL_24:
if( v9 >= 0 )
{
v37 = 0i64;
v21 = 0i64;
v34 = 0;
for( k = CmGetDeviceMappedPropertyKeys(a1, a2, (__int64)Handle, 1, 0i64, 0, &v34);
k == -1073741789;
k = CmGetDeviceMappedPropertyKeys(a1, a2, (__int64)Handle, 1, (__int64)v37, v23, &v34) )
{
v23 = v34;
v24 = 20i64 * v34;
if( v24 > 0xFFFFFFFF )
{
k = -1073741811;
goto LABEL_65;
}
if( v37 )
ExFreePoolWithTag(v37, 0);
v37 = ExAllocatePoolWithTag(PagedPool, (unsigned int)v24, 0x52504E50ui64);
v21 = v37;
if( !v37 )
{
k = -1073741801;
goto LABEL_35;
}
}
v23 = v34;
LABEL_35:
if( k && k != -1073741275 )
{
LABEL_65:
v9 = k;
goto LABEL_43;
}
v25 = 0;
if( v23 )
{
while( 1 )
{
v26 = CmSetDeviceMappedProperty(a1, a2, Handle, 0i64, (__int64)v21 + 20 * v25, 0, 0i64, 0);
if( v26 )
{
if( v26 != -1073741790 && v26 != -1073741275 && v26 != -1073741637 && v26 != -1073741802 )
break;
}
if( ++v25 >= v23 )
goto LABEL_40;
}
v9 = v26;
}
LABEL_40:
if( v9 >= 0 )
{
v9 = CmDeleteDeviceRegKey(a1, a2, 16, 0);
if( v9 >= 0 )
CmRaiseDeleteEvent(a1, (__int64)a2, 1u);
}
}
LABEL_43:
if( v39 )
ExFreePoolWithTag(v39, 0);
LABEL_45:
if( P )
ExFreePoolWithTag(P, 0);
if( v37 )
ExFreePoolWithTag(v37, 0);
LABEL_49:
if( PoolWithTag )
ExFreePoolWithTag(PoolWithTag, 0);
LABEL_51:
if( Handle )
ZwClose(Handle);
return(unsigned int)v9;
}Referenced by:
CmDeleteDevice