CmDeleteDeviceRegKeyWorker
__int64 __fastcall CmDeleteDeviceRegKeyWorker(__int64 a1, const wchar_t *a2, int a3, int a4, char a5){
const wchar_t *v8;
int v9;
wchar_t *PoolWithTag;
unsigned __int64 v11;
int v12;
int inited;
const WCHAR *v14;
_QWORD *v15;
unsigned __int16 Length;
char *v18;
int v19;
__int64 v20;
__int64 v21;
char *v22;
int v23;
WCHAR *v24;
WCHAR *v25;
__int64 v26;
__int64 v27;
int *p_DestinationString;
unsigned int v29;
int v30;
__int64 v31;
__int64 v32;
__int64 v33;
__int64 v34;
size_t v35;
__int64 v36;
char *v37;
const wchar_t *v38;
HANDLE v39;
HANDLE Handle;
struct _UNICODE_STRING DestinationString;
v38 = a2;
LODWORD(v36) = 0;
v37 = 0i64;
v39 = 0i64;
v8 = a2;
Handle = 0i64;
v9 = 4;
PoolWithTag = 0i64;
DestinationString = 0i64;
if( !a3 || (a3 & 0xFFFFFCE8) != 0 )
goto LABEL_85;
LODWORD(v11) = (a3 & 0x200) != 0 ? 360 : 240;
PoolWithTag = (wchar_t *)ExAllocatePoolWithTag(PagedPool, (unsigned int)v11, 0x52504E50ui64);
if( PoolWithTag )
{
while( 1 )
{
LODWORD(v35) = (unsigned int)v11 >> 1;
CmGetDeviceRegKeyPath(a1, v8, a3, a4, 0, PoolWithTag, v35, (__int64)&v36);
inited = v12;
if( v12 != -1073741789 )
break;
ExFreePoolWithTag(PoolWithTag, 0);
PoolWithTag = 0i64;
v11 = 2i64 * (unsigned int)v36;
if( v11 > 0xFFFFFFFF )
{
inited = -1073741675;
goto LABEL_10;
}
PoolWithTag = (wchar_t *)ExAllocatePoolWithTag(PagedPool, (unsigned int)v11, 0x52504E50ui64);
if( !PoolWithTag )
goto LABEL_60;
v8 = v38;
}
}
else
{
LABEL_60:
inited = -1073741801;
}
if( inited < 0 )
goto LABEL_10;
if( (a3 & 0x100) == 0 )
{
inited = RtlInitUnicodeStringEx(&DestinationString, PoolWithTag);
if( inited < 0 )
goto LABEL_10;
Length = DestinationString.Length;
if( DestinationString.Length < (unsigned int)v11
&& DestinationString.Length > 0x32u
&& (unsigned __int8)RtlPrefixUnicodeString(
(PVOID)&`_CmDeleteDeviceContainerRegKeyWorker'::`2'::ObjectPathRootPrefix,
(INT64 *)&DestinationString) )
{
v14 = PoolWithTag + 25;
DestinationString.MaximumLength -= 50;
DestinationString.Buffer = PoolWithTag + 25;
DestinationString.Length = Length - 50;
if( (unsigned __int8)RtlPrefixUnicodeString(
(PVOID)&`_CmDeleteDeviceRegKeyWorker'::`2'::EnumKeyPrefix,
(INT64 *)&DestinationString) )
{
v9 = 5;
v14 = PoolWithTag + 30;
}
else if( (unsigned __int8)RtlPrefixUnicodeString(
(PVOID)&`_CmDeleteDeviceInterfaceRegKeyWorker'::`2'::HardwareProfilesKeyPrefix,
(INT64 *)&DestinationString) )
{
v9 = 14;
v14 = PoolWithTag + 43;
}
inited = PnpCtxGetCachedContextBaseKey(a1, v9, (__int64 *)&v37);
if( inited < 0 )
goto LABEL_10;
v18 = v37;
goto LABEL_26;
}
LABEL_85:
inited = -1073741811;
goto LABEL_10;
}
v14 = PoolWithTag;
v15 = 0i64;
if( a1 )
v15 = *(_QWORD **)(a1 + 224);
inited = SysCtxRegOpenCurrentUserKey(v15, 0, 0x2000000u, &v39);
if( inited < 0 )
goto LABEL_10;
v18 = (char *)v39;
LABEL_26:
v37 = v18;
inited = CmOpenDeviceRegKey(a1, v38, 16, 0, 1, 0, (__int64)&Handle, 0i64);
if( inited < 0 )
goto LABEL_10;
v19 = (unsigned __int8)a3;
LODWORD(v36) = (unsigned __int8)a3;
if( (unsigned __int8)a3 == 18 && (a3 & 0xF00) == 0 )
{
*(_DWORD *)&DestinationString.Length = 786;
p_DestinationString = (int *)&DestinationString;
*(_DWORD *)(&DestinationString.MaximumLength + 1) = 530;
v29 = 0;
LODWORD(DestinationString.Buffer) = 274;
while( 1 )
{
v30 = CmDeleteDeviceRegKey(a1, v38, *p_DestinationString, 0);
if( v30 )
{
if( v30 != -1073741637 && v30 != -1073741772 && v30 != -1073741811 )
break;
}
++v29;
++p_DestinationString;
if( v29 >= 3 )
goto LABEL_51;
}
inited = v30;
LABEL_51:
if( inited < 0 )
goto LABEL_10;
CmDeleteDeviceMappedPropertyForAllDriverKeyRegValues(a1, (__int64)v38);
v23 = CmSetDeviceRegProp(a1, v38, 0i64, 0xAu, 1u, 0i64, 0, 0);
if( v23 && v23 != -1073741275 && v23 != -1073741810 )
goto LABEL_36;
v19 = v36;
}
if( a5 )
{
if( a1 && (v20 = *(_QWORD *)(a1 + 224)) != 0 )
v21 = *(_QWORD *)(v20 + 8);
else
v21 = 0i64;
v22 = v37;
v23 = RegRtlDeleteTreeInternal(v37, v14, v21, 0);
}
else
{
if( a1 && (v31 = *(_QWORD *)(a1 + 224)) != 0 )
v32 = *(_QWORD *)(v31 + 8);
else
v32 = 0i64;
v22 = v37;
v23 = RegRtlDeleteKeyTransacted(v37, v14, v32);
}
if( v23 != -1073741444 )
{
if( v23 < 0 )
goto LABEL_36;
if( v19 != 18 && (v19 != 17 || (a3 & 0xF00) != 0) )
{
v24 = wcsrchr(v14, 0x5Cu);
if( !v24 || (*v24 = 0, (v25 = wcsrchr(v14, 0x5Cu)) == 0i64) )
{
inited = -1073741595;
goto LABEL_10;
}
if( a1 && (v26 = *(_QWORD *)(a1 + 224)) != 0 )
v27 = *(_QWORD *)(v26 + 8);
else
v27 = 0i64;
v23 = RegRtlDeleteKeyTransacted(v22, v14, v27);
if( v23 != -1073741535 )
{
if( v23 < 0
|| ((*v25 = 0, !a1) || (v33 = *(_QWORD *)(a1 + 224)) == 0 ? (v34 = 0i64) : (v34 = *(_QWORD *)(v33 + 8)),
(v23 = RegRtlDeleteKeyTransacted(v22, v14, v34), (int)(v23 + 0x80000000) >= 0) && v23 != -1073741535) )
{
LABEL_36:
inited = v23;
}
}
}
}
LABEL_10:
if( Handle )
ZwClose(Handle);
if( v39 )
ZwClose(v39);
if( PoolWithTag )
ExFreePoolWithTag(PoolWithTag, 0);
return(unsigned int)inited;
}Referenced by:
CmDeleteDeviceRegKey