CmDeleteLayeredKey

NTSTATUS __stdcall CmDeleteLayeredKey(CM_KEY_BODY *KeyBody, LIST_ENTRY *DeferredPostAsync){
  __int64 v2; 
  __int64 v4; 
  _CM_KEY_CONTROL_BLOCK *KeyControlBlock; 
  char v6; 
  char v7; 
  INT64 ParentKcb; 
  char v9; 
  char v10; 
  NTSTATUS started; 
  INT64 v12; 
  _CM_KCB_LAYER_INFO *LayerInfo; 
  INT64 *p_UpperLayerListHead; 
  __int64 KeyCell; 
  int v16; 
  __int64 v17; 
  __int64 v19; 
  unsigned int v20; 
  unsigned int i; 
  __int64 v22; 
  INT64 v23; 
  int v24; 
  int v25; 
  unsigned int v26; 
  UINT64 KeyHive; 
  __int64 KcbInHashEntryByCellIndex; 
  char v29; 
  PVOID v30; 
  __int64 v31; 
  _HV_GET_CELL_CONTEXT v32; 
  _HV_GET_CELL_CONTEXT Context; 
  INT64 v34[2]; 
  __int128 v35; 
  INT64 v36[2]; 
  __int128 v37; 
  _UNICODE_STRING Component; 
  _CMP_DISCARD_AND_REPLACE_KCB_CONTEXT v39[2]; 
  PVOID CellIndex; 
  LIST_ENTRY *v41; 
  INT64 v42; 

  v41 = DeferredPostAsync;
  LODWORD(v42) = 0;
  *(_OWORD *)v34 = 0i64;
  v32 = 0i64;
  v4 = v2;
  v35 = 0i64;
  LODWORD(CellIndex) = 0;
  *(_OWORD *)v36 = 0i64;
  Context = 0i64;
  v37 = 0i64;
  Component = 0i64;
  memset(v39, 0, 32);
  CmpInitializeKcbStack((INT64)v34);
  CmpInitializeKcbStack((INT64)v36);
  KeyControlBlock = KeyBody->KeyControlBlock;
  v7 = v6;
  ParentKcb = (INT64)KeyControlBlock->ParentKcb;
  HvpGetCellContextInitialize(&Context);
  HvpGetCellContextInitialize(&v32);
  CmpInitializeDiscardReplaceContext(v39);
  v10 = v9;
  if( (KeyControlBlock->_bf_b8 & 0x80000) != 0 )
  {
    started = -1073741535;
    goto LABEL_28;
  }
  started = CmpStartKcbStackForTopLayerKcb((INT64)v34, (INT64)KeyControlBlock);
  if( started >= 0 )
  {
    started = CmpStartKcbStackForTopLayerKcb((INT64)v36, ParentKcb);
    if( started >= 0 )
    {
LABEL_23:
      CmpLockHashEntryExclusiveByKcb((UINT64)KeyControlBlock);
      CmpLockKcbStackTopExclusiveRestShared((INT64)v36);
      CmpLockKcbStackExclusive((INT64)v34);
      while( !CmpIsKeyDeletedForKeyBody(KeyBody, 0i64) )
      {
        started = CmpGetSubKeyCountForKcbStack((INT64)v34, &v42);
        if( started < 0 )
          goto LABEL_26;
        if( (_DWORD)v42 )
        {
          started = -1073741535;
          goto LABEL_26;
        }
        LayerInfo = KeyControlBlock->LayerInfo;
        if( LayerInfo )
        {
          p_UpperLayerListHead = (INT64 *)&LayerInfo->UpperLayerListHead;
          v12 = *p_UpperLayerListHead;
          if( (INT64 *)*p_UpperLayerListHead != p_UpperLayerListHead )
          {
            if( !v7 )
              goto LABEL_22;
            if( (INT64 *)v12 != p_UpperLayerListHead )
            {
              v10 = 1;
              started = CmpPrepareDiscardAndReplaceKcbAndUnbackedHigherLayers(KeyControlBlock, (__int64)v39);
              if( started < 0 )
                goto LABEL_26;
            }
          }
        }
        KeyCell = KeyControlBlock->KeyHash.KeyCell;
        if( (_DWORD)KeyCell != -1 )
        {
          if( !v7 )
          {
LABEL_22:
            CmpUnlockKcbStack((INT64)v34);
            CmpUnlockKcbStack((INT64)v36);
            CmpUnlockHashEntryByKcb((INT64)KeyControlBlock);
            CmpUnlockRegistry();
            CmpLockRegistryExclusive();
            v7 = 1;
            goto LABEL_23;
          }
          v19 = (__int64)KeyControlBlock->KeyHash.KeyHive->GetCellRoutine(
                           KeyControlBlock->KeyHash.KeyHive,
                           KeyCell,
                           &Context);
          v20 = 0;
          if( *(_DWORD *)(v19 + 24) + *(_DWORD *)(v19 + 20) )
          {
            while( 1 )
            {
              started = CmpFindSubKeyByNumber(
                          KeyControlBlock->KeyHash.KeyHive,
                          (_CM_KEY_NODE *)v19,
                          v20,
                          (UINT *)&CellIndex);
              if( started < 0 )
                break;
              if( !CmpMarkKeyDirty(KeyControlBlock->KeyHash.KeyHive, (PVOID)(unsigned int)CellIndex, 1) )
                goto LABEL_40;
              if( ++v20 >= *(_DWORD *)(v19 + 24) + *(_DWORD *)(v19 + 20) )
                goto LABEL_36;
            }
          }
          else
          {
LABEL_36:
            if( CmpMarkKeyDirty(KeyControlBlock->KeyHash.KeyHive, (PVOID)KeyControlBlock->KeyHash.KeyCell, 1) )
            {
              CmpFindSubKeyByNumber(KeyControlBlock->KeyHash.KeyHive, (_CM_KEY_NODE *)v19, 0i64, (UINT *)&CellIndex);
              for( i = (unsigned int)CellIndex; (_DWORD)CellIndex != -1; i = (unsigned int)CellIndex )
              {
                v22 = (__int64)KeyControlBlock->KeyHash.KeyHive->GetCellRoutine(
                                 KeyControlBlock->KeyHash.KeyHive,
                                 i,
                                 &v32);
                v23 = *(unsigned __int16 *)(v22 + 72);
                if( (*(_BYTE *)(v22 + 2) & 0x20) != 0 )
                {
                  v24 = CmpHashCompressedComponent((UINT8 *)(v22 + 76), v23);
                }
                else
                {
                  Component.Buffer = (wchar_t *)(v22 + 76);
                  Component.Length = v23;
                  Component.MaximumLength = v23;
                  v24 = CmpHashUnicodeComponent(&Component);
                }
                v25 = v24;
                KeyControlBlock->KeyHash.KeyHive->ReleaseCellRoutine(KeyControlBlock->KeyHash.KeyHive, &v32);
                v26 = v25 + 37 * KeyControlBlock->KeyHash.ConvKey.Hash;
                KeyHive = (UINT64)KeyControlBlock->KeyHash.KeyHive;
                KcbInHashEntryByCellIndex = CmpFindKcbInHashEntryByCellIndex(KeyHive, v26, i);
                if( KcbInHashEntryByCellIndex )
                {
                  *(_DWORD *)(KcbInHashEntryByCellIndex + 40) = -1;
                  KeyHive = (UINT64)KeyControlBlock->KeyHash.KeyHive;
                }
                CmpFreeKeyByCell(KeyHive, i, 1);
                CmpFindSubKeyByNumber(KeyControlBlock->KeyHash.KeyHive, (_CM_KEY_NODE *)v19, 0i64, (UINT *)&CellIndex);
              }
              CmpFreeKeyValues((__int64)KeyControlBlock->KeyHash.KeyHive, (void *)KeyControlBlock->KeyHash.KeyCell, v19);
              v29 = *(_BYTE *)(v19 + 13);
              *(_WORD *)(v19 + 2) &= 0x20u;
              *(_BYTE *)(v19 + 55) = 0;
              *(_DWORD *)(v19 + 52) &= 0xFF00FFFF;
              *(_BYTE *)(v19 + 13) = v29 & 0xFC | 1;
              *(_QWORD *)(v19 + 4) = 0i64;
              *(_QWORD *)(v19 + 56) = 0i64;
              *(_DWORD *)(v19 + 64) = 0;
              *(_WORD *)(v19 + 52) = 0;
              CmpIncrementKcbSequenceNumber((INT64)KeyControlBlock);
              CmpRebuildKcbCacheFromNode(v30, v19, v4, 1);
              CmpReportNotifyForKcbStack((INT64)v36, 0i64, 1i64, v41);
              CmpFlushNotifiesOnAllUnbackedHigherLayerKcbs((__int64)KeyControlBlock, v31, v4, 1);
              CmpFlushNotifiesOnKeyBodyList((__int64)KeyControlBlock, 8i64, v4, 1);
              if( v10 )
              {
                CmpCommitDiscardAndReplaceKcbAndUnbackedHigherLayers(KeyControlBlock, v39);
              }
              else
              {
                CmpMarkKeyUnbacked((__int64)KeyControlBlock, v4);
                CmpDiscardKcb((UINT64)KeyControlBlock, v4);
              }
              started = 0;
            }
            else
            {
LABEL_40:
              started = -1073741670;
            }
          }
          KeyControlBlock->KeyHash.KeyHive->ReleaseCellRoutine(KeyControlBlock->KeyHash.KeyHive, &Context);
          goto LABEL_26;
        }
        if( *(_DWORD *)(ParentKcb + 40) != -1 )
          goto LABEL_18;
        CmpUnlockKcbStack((INT64)v34);
        CmpUnlockKcbStack((INT64)v36);
        v16 = CmpPromoteKey((__int64)v36, 0, 1);
        started = v16;
        if( v16 == -1073741444 )
        {
          started = 0;
LABEL_27:
          CmpUnlockHashEntryByKcb((INT64)KeyControlBlock);
          goto LABEL_28;
        }
        if( v16 < 0 )
          goto LABEL_27;
        CmpLockKcbStackExclusive((INT64)v34);
        if( v7 )
        {
LABEL_18:
          started = CmpCreateTombstone(v12, (INT64)v34);
          if( started >= 0 )
          {
            CmpReportNotifyForKcbStack((INT64)v36, 0i64, 1i64, v41);
            CmpFlushNotifiesOnAllUnbackedHigherLayerKcbs((__int64)KeyControlBlock, v17, v4, 0);
            CmpFlushNotifiesOnKeyBodyList((__int64)KeyControlBlock, 8i64, v4, 0);
            if( v10 )
            {
              CmpCommitDiscardAndReplaceKcbAndUnbackedHigherLayers(KeyControlBlock, v39);
            }
            else
            {
              CmpMarkKeyUnbacked((__int64)KeyControlBlock, v4);
              CmpDiscardKcb((UINT64)KeyControlBlock, v4);
            }
            started = 0;
          }
          goto LABEL_26;
        }
      }
      started = 0;
LABEL_26:
      CmpUnlockKcbStack((INT64)v34);
      CmpUnlockKcbStack((INT64)v36);
      goto LABEL_27;
    }
  }
LABEL_28:
  CmpCleanupDiscardReplaceContext(v39);
  CmpCleanupKcbStack((INT64)v34);
  CmpCleanupKcbStack((INT64)v36);
  return started;
}

Referenced by:

No references.