CmDeleteDeviceInterfaceRegKeyWorker
NTSTATUS __stdcall CmDeleteDeviceInterfaceRegKeyWorker(
HPNPCTX *hPnpCtx,
WCHAR *DeviceInterfaceName,
WCHAR *CmKeyTypeFlags,
INT64 HardwareProfileId,
CHAR DeleteTree,
INT64 a6,
INT64 a8,
INT64 E8,
INT64 a9){
unsigned int v9;
_CM_KEY_TYPE v10;
WCHAR *v11;
PNPCTX_BASE_KEY_TYPE v12;
WCHAR *PoolWithTag;
unsigned __int64 v15;
int DeviceInterfaceRegKeyPath;
WCHAR *v17;
HSYSCTX *v18;
UINT64 v19;
unsigned __int16 Length;
VOID *v22;
__int64 v23;
VOID *v24;
int v25;
__int64 v26;
VOID *v27;
INT64 DesiredAccess;
WCHAR *BaseKeyPath;
UINT64 BaseKeyLength;
UINT64 *RequiredLength;
VOID *Handle;
INT64 v33;
VOID *DeviceInterfaceKey;
_UNICODE_STRING DestinationString;
UINT64 Disposition;
LODWORD(Disposition) = 0;
v9 = HardwareProfileId;
v33 = 0i64;
v10 = (int)CmKeyTypeFlags;
Handle = 0i64;
v11 = DeviceInterfaceName;
DeviceInterfaceKey = 0i64;
v12 = PNPCTX_BASE_KEY_TYPE_CONTROLSET;
PoolWithTag = 0i64;
DestinationString = 0i64;
if( !(_DWORD)CmKeyTypeFlags || ((unsigned int)CmKeyTypeFlags & 0xFFFFFCCC) != 0 )
goto LABEL_50;
LODWORD(v15) = ((unsigned __int16)CmKeyTypeFlags & 0x200) != 0 ? 600 : 480;
PoolWithTag = (WCHAR *)ExAllocatePoolWithTag(1ui64, (unsigned int)v15, 1380994640i64);
if( PoolWithTag )
{
while( 1 )
{
LODWORD(BaseKeyLength) = (unsigned int)v15 >> 1;
DeviceInterfaceRegKeyPath = CmGetDeviceInterfaceRegKeyPath(
(HPNPCTX *)((unsigned int)v15 >> 1),
v11,
v10,
v9,
DesiredAccess,
PoolWithTag,
BaseKeyLength,
&Disposition);
if( DeviceInterfaceRegKeyPath != -1073741789 )
break;
ExFreePoolWithTag(PoolWithTag, 0);
PoolWithTag = 0i64;
v15 = 2i64 * (unsigned int)Disposition;
if( v15 > 0xFFFFFFFF )
{
DeviceInterfaceRegKeyPath = -1073741675;
goto LABEL_10;
}
PoolWithTag = (WCHAR *)ExAllocatePoolWithTag(1ui64, (unsigned int)v15, 1380994640i64);
if( !PoolWithTag )
goto LABEL_46;
v11 = DeviceInterfaceName;
}
}
else
{
LABEL_46:
DeviceInterfaceRegKeyPath = -1073741801;
}
if( DeviceInterfaceRegKeyPath < 0 )
goto LABEL_10;
if( (v10 & 0x100) != 0 )
{
v17 = PoolWithTag;
if( hPnpCtx )
v18 = (HSYSCTX *)*((_QWORD *)hPnpCtx + 28);
else
v18 = 0i64;
DeviceInterfaceRegKeyPath = SysCtxRegOpenCurrentUserKey(
v18,
0,
0x2000000,
&Handle,
DesiredAccess,
(INT64)BaseKeyPath,
BaseKeyLength,
(INT64)RequiredLength);
if( DeviceInterfaceRegKeyPath < 0 )
goto LABEL_10;
v22 = Handle;
goto LABEL_25;
}
DeviceInterfaceRegKeyPath = RtlInitUnicodeStringEx(&DestinationString, PoolWithTag);
if( DeviceInterfaceRegKeyPath < 0 )
goto LABEL_10;
Length = DestinationString.Length;
if( DestinationString.Length >= (unsigned int)v15
|| DestinationString.Length <= 0x32u
|| !(unsigned __int8)RtlPrefixUnicodeString(
&`_CmDeleteDeviceContainerRegKeyWorker'::`2'::ObjectPathRootPrefix,
&DestinationString,
1u) )
{
LABEL_50:
DeviceInterfaceRegKeyPath = -1073741811;
goto LABEL_10;
}
v17 = PoolWithTag + 25;
DestinationString.MaximumLength -= 50;
DestinationString.Buffer = PoolWithTag + 25;
DestinationString.Length = Length - 50;
if( (unsigned __int8)RtlPrefixUnicodeString(
&`_CmDeleteDeviceInterfaceRegKeyWorker'::`2'::DeviceClassesKeyPrefix,
&DestinationString,
1u) )
{
v12 = PNPCTX_BASE_KEY_TYPE_DEVICECONTAINERS;
v17 = PoolWithTag + 47;
}
else if( (unsigned __int8)RtlPrefixUnicodeString(
&`_CmDeleteDeviceInterfaceRegKeyWorker'::`2'::HardwareProfilesKeyPrefix,
&DestinationString,
1u) )
{
v12 = PNPCTX_BASE_KEY_TYPE_HARDWAREPROFILES|PNPCTX_BASE_KEY_TYPE_SOFTWARE;
v17 = PoolWithTag + 43;
}
DeviceInterfaceRegKeyPath = PnpCtxGetCachedContextBaseKey(hPnpCtx, v12, (VOID **)&v33);
if( DeviceInterfaceRegKeyPath >= 0 )
{
v22 = (VOID *)v33;
LABEL_25:
if( v10 == CM_KEY_TYPE_DEVICE_INTERFACE_SYMLINK
|| (LOBYTE(BaseKeyPath) = 0,
LODWORD(DesiredAccess) = 1,
DeviceInterfaceRegKeyPath = CmOpenDeviceInterfaceRegKey(
hPnpCtx,
DeviceInterfaceName,
48i64,
v19,
DesiredAccess,
(INT64)BaseKeyPath,
&DeviceInterfaceKey,
0i64),
DeviceInterfaceRegKeyPath >= 0) )
{
if( DeleteTree )
{
if( hPnpCtx && (v23 = *((_QWORD *)hPnpCtx + 28)) != 0 )
v24 = *(VOID **)(v23 + 8);
else
v24 = 0i64;
v25 = RegRtlDeleteTreeInternal(v22, v17, v24, 0);
}
else
{
if( hPnpCtx && (v26 = *((_QWORD *)hPnpCtx + 28)) != 0 )
v27 = *(VOID **)(v26 + 8);
else
v27 = 0i64;
v25 = RegRtlDeleteKeyTransacted(v22, v17, v27);
}
if( (int)(v25 + 0x80000000) >= 0 && v25 != -1073741444 )
DeviceInterfaceRegKeyPath = v25;
}
}
LABEL_10:
if( DeviceInterfaceKey )
ZwClose((_HANDLE)DeviceInterfaceKey);
if( Handle )
ZwClose((_HANDLE)Handle);
if( PoolWithTag )
ExFreePoolWithTag(PoolWithTag, 0);
return DeviceInterfaceRegKeyPath;
}Referenced by:
CmDeleteDeviceInterfaceRegKey