CmDeleteDeviceContainerRegKeyWorker

__int64 __fastcall CmDeleteDeviceContainerRegKeyWorker(__int64 a1, const WCHAR *a2, int a3, __int64 a4, char a5){
  wchar_t *pszDest; 
  unsigned __int64 v9; 
  UINT64 i; 
  __int64 v11; 
  int v12; 
  int inited; 
  const WCHAR *v14; 
  _QWORD *v15; 
  unsigned __int16 Length; 
  wchar_t *v18; 
  char v19; 
  char *v20; 
  __int64 v21; 
  __int64 v22; 
  int v23; 
  __int64 v24; 
  __int64 v25; 
  int v26; 
  size_t cchDest; 
  HANDLE Handle; 
  char *v29; 
  struct _UNICODE_STRING DestinationString; 
  __int64 v31; 
  pszDest = 0i64;
  LODWORD(v31) = 0;
  v29 = 0i64;
  Handle = 0i64;
  DestinationString = 0i64;
  if( !a3 || (a3 & 0xFFFFFEAF) != 0 )
    goto LABEL_45;
  LODWORD(v9) = 260;
  for( i = 260i64; ; i = (unsigned int)v9 )
  {
    pszDest = (wchar_t *)ExAllocatePoolWithTag(PagedPool, i, 0x52504E50ui64);
    if( !pszDest )
      break;
    LODWORD(cchDest) = (unsigned int)v9 >> 1;
    CmGetDeviceContainerRegKeyPath((unsigned int)v9 >> 1, a2, a3, v11, v26, pszDest, cchDest, (__int64)&v31);
    inited = v12;
    if( v12 != -1073741789 )
      goto LABEL_6;
    ExFreePoolWithTag(pszDest, 0);
    pszDest = 0i64;
    v9 = 2i64 * (unsigned int)v31;
    if( v9 > 0xFFFFFFFF )
    {
      inited = -1073741675;
      goto LABEL_11;
    }
  }
  inited = -1073741801;
LABEL_6:
  if( inited < 0 )
    goto LABEL_11;
  if( (a3 & 0x100) == 0 )
  {
    inited = RtlInitUnicodeStringEx(&DestinationString, pszDest);
    if( inited < 0 )
      goto LABEL_11;
    Length = DestinationString.Length;
    if( DestinationString.Length < (unsigned int)v9
      && DestinationString.Length > 0x32u
      && (unsigned __int8)RtlPrefixUnicodeString(
                            (PVOID)&`_CmDeleteDeviceContainerRegKeyWorker'::`2'::ObjectPathRootPrefix,
                            (INT64 *)&DestinationString) )
    {
      v18 = pszDest + 25;
      DestinationString.MaximumLength -= 50;
      DestinationString.Buffer = pszDest + 25;
      DestinationString.Length = Length - 50;
      v19 = RtlPrefixUnicodeString(
              (PVOID)&`_CmDeleteDeviceContainerRegKeyWorker'::`2'::DeviceContainersKeyPrefix,
              (INT64 *)&DestinationString);
      inited = PnpCtxGetCachedContextBaseKey(a1, v19 != 0 ? 10 : 4, (__int64 *)&v29);
      if( inited < 0 )
        goto LABEL_11;
      v20 = v29;
      if( !v19 )
        v18 = pszDest;
      v14 = v18 + 25;
      goto LABEL_24;
    }
LABEL_45:
    inited = -1073741811;
    goto LABEL_11;
  }
  v14 = pszDest;
  if( a1 )
    v15 = *(_QWORD **)(a1 + 224);
  else
    v15 = 0i64;
  inited = SysCtxRegOpenCurrentUserKey(v15, 0, 0x2000000u, &Handle);
  if( inited < 0 )
    goto LABEL_11;
  v20 = (char *)Handle;
LABEL_24:
  if( a5 )
  {
    if( a1 && (v21 = *(_QWORD *)(a1 + 224)) != 0 )
      v22 = *(_QWORD *)(v21 + 8);
    else
      v22 = 0i64;
    v23 = RegRtlDeleteTreeInternal(v20, v14, v22, 0);
  }
  else
  {
    if( a1 && (v24 = *(_QWORD *)(a1 + 224)) != 0 )
      v25 = *(_QWORD *)(v24 + 8);
    else
      v25 = 0i64;
    v23 = RegRtlDeleteKeyTransacted(v20, v14, v25);
  }
  if( (int)(v23 + 0x80000000) >= 0 && v23 != -1073741444 )
    inited = v23;
LABEL_11:
  if( Handle )
    ZwClose(Handle);
  if( pszDest )
    ExFreePoolWithTag(pszDest, 0);
  return(unsigned int)inited;
}

Referenced by:

CmDeleteDeviceContainerRegKey