CmpLightWeightPrepareRenameKeyUoW

NTSTATUS __stdcall CmpLightWeightPrepareRenameKeyUoW(_CM_KCB_UOW *UoW){
  _CM_KEY_CONTROL_BLOCK *KeyControlBlock; 
  __int64 StorageType; 
  UINT64 KeyHive; 
  __int64 v5; 
  struct _LOOKASIDE_LIST_EX *v6; 
  UINT64 *PrepareDataPointer; 
  int ModificationData; 
  NTSTATUS v9; 
  ULONG_PTR v10; 
  _CM_KEY_CONTROL_BLOCK *ChildKCB; 
  _CM_KEY_CONTROL_BLOCK *v12; 
  ULONG_PTR v13; 
  unsigned int v14; 
  char *v15; 
  int v16; 
  _WORD *v17; 
  UINT64 v18; 
  UINT64 v19; 
  CHAR v20; 
  INT64 v21; 
  _CM_KEY_CONTROL_BLOCK *v22; 
  int v24[2]; 
  VOID *CellAddress; 
  INT64 a4[2]; 
  __int128 v27; 
  UINT64 *v28; 
  INT64 a1; 
  INT64 v30; 
  _HV_GET_CELL_CONTEXT CellAddressContext; 
  v24[1] = 0;
  *(_DWORD *)&CellAddressContext.BinContext = 0;
  v24[0] = -1;
  KeyControlBlock = UoW->KeyControlBlock;
  StorageType = UoW->StorageType;
  CellAddressContext.Cell = -1;
  *(_OWORD *)a4 = 0i64;
  KeyHive = (UINT64)KeyControlBlock->KeyHash.KeyHive;
  v27 = 0i64;
  CellAddress = 0i64;
  CmpInitializeDelayDerefContext(a4);
  PrepareDataPointer = (UINT64 *)UoW->ParentUoW->PrepareDataPointer;
  v28 = PrepareDataPointer;
  if( PrepareDataPointer )
  {
    ++*(_DWORD *)PrepareDataPointer;
  }
  else
  {
    ModificationData = CmpLightWeightCreateModificationData((__int64)UoW, (unsigned int **)&v28, v5, v6);
    PrepareDataPointer = v28;
    v9 = ModificationData;
    if( ModificationData < 0 )
      goto LABEL_32;
  }
  CmpReferenceKeyControlBlock((UINT64)UoW->KeyControlBlock);
  v10 = (ULONG_PTR)UoW->KeyControlBlock;
  ChildKCB = UoW->ChildKCB;
  a1 = v10;
  CmpReferenceKeyControlBlock((UINT64)ChildKCB);
  v12 = UoW->KeyControlBlock;
  v13 = (ULONG_PTR)UoW->ChildKCB;
  v30 = v13;
  if( (*(__int64(__fastcall **)(UINT64, _QWORD, int *))(KeyHive + 8))(
         KeyHive,
         v12->ParentKcb->KeyHash.$EFC1DA493FC87C83AB9A993AAC68F300::KeyCell,
         v24) )
  {
    if( !HvMarkCellDirty(KeyHive, UoW->KeyControlBlock->ParentKcb->KeyHash.KeyCell, 1)
      || !HvMarkCellDirty(KeyHive, UoW->KeyControlBlock->KeyHash.KeyCell, 1)
      || !HvMarkCellDirty(KeyHive, *(unsigned int *)(UoW->LastWriteTime.QuadPart + 40), 1) )
    {
      v9 = -1073741443;
LABEL_27:
      (*(void(__fastcall **)(UINT64, int *))(KeyHive + 16))(KeyHive, v24);
      goto LABEL_28;
    }
    v14 = CmpCopyCell(
            (_HHIVE *)KeyHive,
            UoW->KeyControlBlock->KeyHash.KeyCell,
            (_HHIVE *)KeyHive,
            (HSTORAGE_TYPE)StorageType);
    if( v14 == -1 )
    {
      v9 = -1073741670;
LABEL_26:
      v13 = v30;
      goto LABEL_27;
    }
    v15 = (char *)PrepareDataPointer + 4 * StorageType;
    if( *((_DWORD *)v15 + 3) == -1 )
    {
      LODWORD(v28) = *(_DWORD *)(KeyHive + 212);
      v16 = HvAllocateCell((_HHIVE *)KeyHive, 0xCui64, (HSTORAGE_TYPE)StorageType, &CellAddress, &CellAddressContext);
      *((_DWORD *)v15 + 3) = v16;
      if( v16 == -1 )
        goto LABEL_15;
      v17 = CellAddress;
      *(_WORD *)CellAddress = (unsigned int)v28 < 5 ? 26220 : 26732;
      v17[1] = 0;
      *((_DWORD *)PrepareDataPointer + StorageType + 1) = 0;
      (*(void(__fastcall **)(UINT64, _HV_GET_CELL_CONTEXT *))(KeyHive + 16))(KeyHive, &CellAddressContext);
    }
    if( CmpAddSubKeyToList(KeyHive, (UINT64 *)(v15 + 12), v14) )
    {
      ++*((_DWORD *)PrepareDataPointer + StorageType + 1);
      v18 = *(unsigned int *)(UoW->LastWriteTime.QuadPart + 40);
      v19 = v18 >> 31;
      if( CmpRemoveSubKeyFromList(
             (_HHIVE *)KeyHive,
             (UINT64 *)((char *)PrepareDataPointer + 4 * (v18 >> 31) + 12),
             v18) )
      {
        --*((_DWORD *)PrepareDataPointer + v19 + 1);
        v20 = CmpMarkAllChildrenDirty(KeyHive, v14);
        v10 = a1;
        if( v20 )
        {
          v9 = CmpPrepareToInvalidateAllHigherLayerKcbs(a1, 1u, (INT64)&v27);
          if( v9 >= 0 )
          {
            v21 = v30;
            v9 = CmpPrepareToInvalidateAllHigherLayerKcbs(v30, 1u, (INT64)&v27);
            if( v9 >= 0 )
            {
              CmpInvalidateAllHigherLayerKcbs(v10, 1u, 8i64, (INT64)a4);
              CmpInvalidateAllHigherLayerKcbs(v21, 1u, 8i64, (INT64)a4);
              v22 = UoW->KeyControlBlock;
              UoW->PrepareDataPointer = PrepareDataPointer;
              v9 = 0;
              PrepareDataPointer = 0i64;
              v30 = 0i64;
              v10 = 0i64;
              UoW->TxSecurityCell = v22->KeyHash.KeyCell;
              v22->KeyHash.KeyCell = v14;
              v14 = -1;
            }
          }
        }
        else
        {
          v9 = -1073741670;
        }
        goto LABEL_24;
      }
    }
LABEL_15:
    v10 = a1;
    v9 = -1073741670;
LABEL_24:
    if( v14 != -1 )
      CmpFreeKeyByCell((_HHIVE *)KeyHive, v14, 0);
    goto LABEL_26;
  }
  v9 = -1073741670;
LABEL_28:
  if( v13 )
    CmpDereferenceKeyControlBlockWithLock(v13, (INT64)a4, 0);
  if( v10 )
    CmpDereferenceKeyControlBlockWithLock(v10, (INT64)a4, 0);
LABEL_32:
  if( PrepareDataPointer )
    CmpLightWeightCleanupModifyKeyDataUoW(KeyHive, PrepareDataPointer);
  CmpCleanupRollbackPacket((INT64)&v27);
  CmpDrainDelayDerefContext((UINT64 **)a4);
  return v9;
}

Referenced by:

CmpProcessLightWeightUOW