CmDeleteCommonClassRegKeyWorker

__int64 __fastcall CmDeleteCommonClassRegKeyWorker(__int64 a1, const WCHAR *a2, __int16 a3, int a4, char a5){
  const WCHAR *v6; 
  int v8; 
  unsigned __int64 v10; 
  wchar_t *pszDest; 
  int v12; 
  int inited; 
  unsigned __int16 Length; 
  const WCHAR *v15; 
  char *v16; 
  _QWORD *v17; 
  char v18; 
  __int64 v19; 
  __int64 v20; 
  int v21; 
  __int64 v22; 
  __int64 v23; 
  int v24; 
  __int64 v25; 
  __int64 v26; 
  int v27; 
  __int64 v28; 
  int v30; 
  size_t cchDest; 
  char *v32; 
  HANDLE Handle; 
  struct _UNICODE_STRING DestinationString; 
  __int64 v36; 
  LODWORD(v36) = 0;
  v6 = a2;
  v32 = 0i64;
  Handle = 0i64;
  v8 = 4;
  DestinationString = 0i64;
  LODWORD(v10) = (a3 & 0x200) != 0 ? 320 : 200;
  pszDest = (wchar_t *)ExAllocatePoolWithTag(PagedPool, (unsigned int)v10, 0x52504E50ui64);
  if( pszDest )
  {
    while( 1 )
    {
      LODWORD(cchDest) = (unsigned int)v10 >> 1;
      CmGetCommonClassRegKeyPath((unsigned int)v10 >> 1, v6, a3, a4, v30, pszDest, cchDest, (__int64)&v36);
      inited = v12;
      if( v12 != -1073741789 )
        break;
      ExFreePoolWithTag(pszDest, 0);
      pszDest = 0i64;
      v10 = 2i64 * (unsigned int)v36;
      if( v10 > 0xFFFFFFFF )
      {
        inited = -1073741675;
        goto LABEL_60;
      }
      pszDest = (wchar_t *)ExAllocatePoolWithTag(PagedPool, (unsigned int)v10, 0x52504E50ui64);
      if( !pszDest )
        goto LABEL_7;
      v6 = a2;
    }
  }
  else
  {
LABEL_7:
    inited = -1073741801;
  }
  if( inited < 0 )
    goto LABEL_60;
  if( (a3 & 0x100) != 0 )
  {
    v15 = pszDest;
    if( a1 )
      v17 = *(_QWORD **)(a1 + 224);
    else
      v17 = 0i64;
    inited = SysCtxRegOpenCurrentUserKey(v17, 0, 0x2000000u, &Handle);
    if( inited < 0 )
      goto LABEL_60;
    v16 = (char *)Handle;
    v32 = (char *)Handle;
  }
  else
  {
    inited = RtlInitUnicodeStringEx(&DestinationString, pszDest);
    if( inited < 0 )
      goto LABEL_60;
    Length = DestinationString.Length;
    if( DestinationString.Length >= (unsigned int)v10
      || DestinationString.Length <= 0x32u
      || !(unsigned __int8)RtlPrefixUnicodeString(
                             (PVOID)&`_CmOpenDevicePanelRegKeyWorker'::`2'::ObjectPathRootPrefix,
                             (INT64 *)&DestinationString) )
    {
      inited = -1073741811;
      goto LABEL_60;
    }
    v15 = pszDest + 25;
    DestinationString.MaximumLength -= 50;
    DestinationString.Buffer = pszDest + 25;
    DestinationString.Length = Length - 50;
    if( (unsigned __int8)RtlPrefixUnicodeString(
                            (PVOID)&`_CmDeleteCommonClassRegKeyWorker'::`2'::ClassKeyPrefix,
                            (INT64 *)&DestinationString) )
    {
      v8 = 7;
      v15 = pszDest + 39;
    }
    else if( (unsigned __int8)RtlPrefixUnicodeString(
                                 (PVOID)&`_CmDeleteCommonClassRegKeyWorker'::`2'::DeviceClassesKeyPrefix,
                                 (INT64 *)&DestinationString) )
    {
      v8 = 8;
      v15 = pszDest + 47;
    }
    else if( (unsigned __int8)RtlPrefixUnicodeString(
                                 (PVOID)&`_CmOpenDeviceInterfaceRegKeyWorker'::`2'::HardwareProfilesKeyPrefix,
                                 (INT64 *)&DestinationString) )
    {
      v8 = 14;
      v15 = pszDest + 43;
    }
    inited = PnpCtxGetCachedContextBaseKey(a1, v8, (__int64 *)&v32);
    if( inited < 0 )
      goto LABEL_60;
    v16 = v32;
  }
  v18 = a5;
  if( a5 )
  {
    if( a1 && (v19 = *(_QWORD *)(a1 + 224)) != 0 )
      v20 = *(_QWORD *)(v19 + 8);
    else
      v20 = 0i64;
    v21 = RegRtlDeleteTreeInternal(v16, v15, v20, 0);
  }
  else
  {
    if( a1 && (v22 = *(_QWORD *)(a1 + 224)) != 0 )
      v23 = *(_QWORD *)(v22 + 8);
    else
      v23 = 0i64;
    v21 = RegRtlDeleteKeyTransacted(v16, v15, v23);
  }
  v24 = v21;
  if( (!v21 || v21 == -1073741444 || v21 == -1073741772) && v8 == 8 && *(_BYTE *)(a1 + 4) )
  {
    inited = PnpCtxGetCachedContextBaseKey(a1, 9, (__int64 *)&v32);
    if( inited < 0 )
      goto LABEL_60;
    v25 = *(_QWORD *)(a1 + 224);
    if( v18 )
    {
      if( v25 )
        v26 = *(_QWORD *)(v25 + 8);
      else
        v26 = 0i64;
      v27 = RegRtlDeleteTreeInternal(v32, v15, v26, 0);
    }
    else
    {
      if( v25 )
        v28 = *(_QWORD *)(v25 + 8);
      else
        v28 = 0i64;
      v27 = RegRtlDeleteKeyTransacted(v32, v15, v28);
    }
    if( v24 == -1073741772 || v27 != -1073741772 )
      v24 = v27;
  }
  if( (int)(v24 + 0x80000000) >= 0 && v24 != -1073741444 )
    inited = v24;
LABEL_60:
  if( Handle )
    ZwClose(Handle);
  if( pszDest )
    ExFreePoolWithTag(pszDest, 0);
  return(unsigned int)inited;
}

Referenced by:

CmDeleteCommonClassRegKey