CmOpenDeviceRegKeyWorker
__int64 __fastcall CmOpenDeviceRegKeyWorker(
__int64 a1,
const wchar_t *a2,
int a3,
int a4,
int a5,
char a6,
__int64 a7,
__int64 a8){
const wchar_t *v11;
wchar_t *PoolWithTag;
int v13;
PVOID v14;
unsigned __int64 v15;
int v16;
int DeviceRegKeySecurityDescriptor;
unsigned __int16 Length;
const WCHAR *v19;
HANDLE v20;
__int64 v21;
int v22;
int Tree;
int v25;
ACCESS_MASK v26;
__int64 v27;
HANDLE v28;
_QWORD *v29;
size_t v30;
PVOID P;
HANDLE v32;
HANDLE v33;
void *v34;
HANDLE Handle;
struct _UNICODE_STRING DestinationString;
__int64 v38;
LODWORD(v38) = 0;
v34 = 0i64;
v11 = a2;
v33 = 0i64;
PoolWithTag = 0i64;
v32 = 0i64;
v13 = 4;
Handle = 0i64;
v14 = 0i64;
P = 0i64;
DestinationString = 0i64;
if( a3 && (a3 & 0xFFFFFCE8) == 0 )
{
LODWORD(v15) = (a3 & 0x200) != 0 ? 360 : 240;
PoolWithTag = (wchar_t *)ExAllocatePoolWithTag(PagedPool, (unsigned int)v15, 0x52504E50ui64);
if( PoolWithTag )
{
while( 1 )
{
LODWORD(v30) = (unsigned int)v15 >> 1;
CmGetDeviceRegKeyPath(a1, v11, a3, a4, a6, PoolWithTag, v30, (__int64)&v38);
DeviceRegKeySecurityDescriptor = v16;
if( v16 != -1073741789 )
break;
ExFreePoolWithTag(PoolWithTag, 0);
PoolWithTag = 0i64;
v15 = 2i64 * (unsigned int)v38;
if( v15 > 0xFFFFFFFF )
{
DeviceRegKeySecurityDescriptor = -1073741675;
goto LABEL_19;
}
PoolWithTag = (wchar_t *)ExAllocatePoolWithTag(PagedPool, (unsigned int)v15, 0x52504E50ui64);
if( !PoolWithTag )
goto LABEL_61;
v11 = a2;
}
}
else
{
LABEL_61:
DeviceRegKeySecurityDescriptor = -1073741801;
}
if( DeviceRegKeySecurityDescriptor < 0 )
goto LABEL_19;
if( (a3 & 0x100) != 0 )
{
v19 = PoolWithTag;
if( a1 )
v29 = *(_QWORD **)(a1 + 224);
else
v29 = 0i64;
DeviceRegKeySecurityDescriptor = SysCtxRegOpenCurrentUserKey(v29, 0, 0x2000000u, &v33);
if( DeviceRegKeySecurityDescriptor < 0 )
goto LABEL_19;
v20 = v33;
LABEL_15:
v34 = v20;
if( a1 )
v21 = *(_QWORD *)(a1 + 224);
else
v21 = 0i64;
v22 = a5;
Tree = SysCtxRegOpenKey(v21, (char *)v20, v19, 0, a5, (void **)a7);
if( !Tree )
{
*(_DWORD *)a8 = 2;
goto LABEL_19;
}
if( Tree == -1073741444 )
goto LABEL_69;
if( Tree != -1073741772 )
{
LABEL_55:
DeviceRegKeySecurityDescriptor = Tree;
goto LABEL_19;
}
v25 = (unsigned __int8)a3;
if( !a6 )
{
if( (unsigned __int8)a3 != 16 || (a3 & 0xF00) != 0 )
DeviceRegKeySecurityDescriptor = -1073741772;
else
DeviceRegKeySecurityDescriptor = -1073741810;
goto LABEL_19;
}
if( (unsigned __int8)a3 != 16 || (a3 & 0xF00) != 0 )
{
DeviceRegKeySecurityDescriptor = CmOpenDeviceRegKey(a1, a2, 16, 0, 1, 0, (__int64)&Handle, 0i64);
if( DeviceRegKeySecurityDescriptor < 0 )
goto LABEL_19;
}
DeviceRegKeySecurityDescriptor = CmGetDeviceRegKeySecurityDescriptor(a1, a3, &P);
if( DeviceRegKeySecurityDescriptor < 0 )
goto LABEL_19;
v26 = v22;
if( P )
v26 = 917510;
Tree = PnpCtxRegCreateTree(a1, v34, v19, v25 == 19, v26, (__int64)P, (__int64)&v32, a8);
if( Tree == -1073741444 )
{
LABEL_69:
DeviceRegKeySecurityDescriptor = -1073741595;
goto LABEL_19;
}
if( Tree < 0 )
goto LABEL_55;
if( v26 == v22 )
{
v28 = v32;
v32 = 0i64;
*(_QWORD *)a7 = v28;
goto LABEL_19;
}
if( a1 )
v27 = *(_QWORD *)(a1 + 224);
else
v27 = 0i64;
Tree = SysCtxRegOpenKey(v27, (char *)v32, 0i64, 0, v22, (void **)a7);
if( Tree == -1073741444 )
{
DeviceRegKeySecurityDescriptor = -1073741772;
goto LABEL_19;
}
if( Tree < 0 )
goto LABEL_55;
LABEL_19:
v14 = P;
goto LABEL_20;
}
DeviceRegKeySecurityDescriptor = RtlInitUnicodeStringEx(&DestinationString, PoolWithTag);
if( DeviceRegKeySecurityDescriptor < 0 )
goto LABEL_19;
Length = DestinationString.Length;
if( DestinationString.Length < (unsigned int)v15
&& DestinationString.Length > 0x32u
&& (unsigned __int8)RtlPrefixUnicodeString(
(PVOID)&`_CmDeleteDeviceContainerRegKeyWorker'::`2'::ObjectPathRootPrefix,
(INT64 *)&DestinationString) )
{
v19 = PoolWithTag + 25;
DestinationString.MaximumLength -= 50;
DestinationString.Buffer = PoolWithTag + 25;
DestinationString.Length = Length - 50;
if( (unsigned __int8)RtlPrefixUnicodeString(
(PVOID)&`_CmDeleteDeviceRegKeyWorker'::`2'::EnumKeyPrefix,
(INT64 *)&DestinationString) )
{
v13 = 5;
v19 = PoolWithTag + 30;
}
else if( (unsigned __int8)RtlPrefixUnicodeString(
(PVOID)&`_CmDeleteDeviceInterfaceRegKeyWorker'::`2'::HardwareProfilesKeyPrefix,
(INT64 *)&DestinationString) )
{
v13 = 14;
v19 = PoolWithTag + 43;
}
DeviceRegKeySecurityDescriptor = PnpCtxGetCachedContextBaseKey(a1, v13, (__int64 *)&v34);
if( DeviceRegKeySecurityDescriptor < 0 )
goto LABEL_19;
v20 = v34;
goto LABEL_15;
}
v14 = P;
}
DeviceRegKeySecurityDescriptor = -1073741811;
LABEL_20:
if( Handle )
ZwClose(Handle);
if( v33 )
ZwClose(v33);
if( v32 )
ZwClose(v32);
if( v14 )
ExFreePoolWithTag(v14, 0);
if( PoolWithTag )
ExFreePoolWithTag(PoolWithTag, 0);
return(unsigned int)DeviceRegKeySecurityDescriptor;
}Referenced by:
CmOpenDeviceRegKey