CmpRefreshHive

__int64 __fastcall CmpRefreshHive(__int64 a1){
  char v2; 
  char v3; 
  _PRIVILEGE_SET *v4; 
  _CM_KEY_CONTROL_BLOCK *v5; 
  INT64 KeyHive; 
  int v7; 
  __int64 v9; 
  _PRIVILEGE_SET *TransientPoolWithTag; 
  int v11; 
  UINT64 v12; 
  UINT64 v13; 
  __int64 v14; 
  __int64 v15; 
  int v16; 
  UINT64 Flags; 
  __int64 v18; 
  __int64 v19; 
  _QWORD a1a[2]; 
  INT64 a6[13]; 
  char v22; 
  UINT8 v23; 
  PVOID Hive; 
  __int64 v25; 

  v25 = 0xFFFFFFFFi64;
  v18 = 0xFFFFFFFFi64;
  v2 = 0;
  Hive = 0i64;
  memset(a6, 0, 32);
  v3 = 0;
  v4 = 0i64;
  v19 = 0i64;
  *(_OWORD *)a1a = 0i64;
  CmpInitializeDelayDerefContext(a1a);
  v5 = *(_CM_KEY_CONTROL_BLOCK **)(a1 + 8);
  KeyHive = (INT64)v5->KeyHash.KeyHive;
  v23 = ExAcquireRundownProtection((_EX_RUNDOWN_REF *)(KeyHive + 1632));
  if( !v23 )
  {
    v7 = -1073740763;
    goto LABEL_7;
  }
  CmpBecomeActiveFlusherAndReconciler((PCMHIVE)KeyHive);
  v2 = 1;
  CmpLockRegistry();
  CmpLockKcbShared(v5);
  v22 = 1;
  v7 = CmpPerformKeyBodyDeletionCheck((CM_KEY_BODY *)a1, 0i64);
  if( v7 < 0 )
    goto LABEL_6;
  if( *(_BYTE *)(KeyHive + 2936) == 1 )
  {
    v7 = -1073741431;
LABEL_6:
    CmpUnlockKcb(v5);
    v3 = 1;
    goto LABEL_7;
  }
  if( (*(_DWORD *)(KeyHive + 160) & 2) == 0 )
  {
LABEL_19:
    v7 = -1073741811;
    goto LABEL_6;
  }
  HvLockHiveFlusherShared(KeyHive);
  HvLockHiveWriter(KeyHive);
  if( *(_DWORD *)(KeyHive + 904) )
  {
    v7 = -1073741823;
    HvUnlockHiveWriter(KeyHive);
    HvUnlockHiveFlusherShared(KeyHive);
    v9 = 0i64;
LABEL_45:
    if( v19 )
      (*(void(__fastcall **)(INT64, __int64 *))(KeyHive + 16))(KeyHive, &v25);
    if( v9 )
      (*((void(__fastcall **)(PVOID, __int64 *))Hive + 2))(Hive, &v18);
    v3 = 1;
    if( v22 )
      goto LABEL_6;
    goto LABEL_7;
  }
  HvUnlockHiveWriter(KeyHive);
  HvUnlockHiveFlusherShared(KeyHive);
  if( (v5->_bf_b8 & 0x40000) == 0 )
    goto LABEL_19;
  if( *(_DWORD *)(KeyHive + 2912) )
  {
    v7 = -1073741823;
    goto LABEL_6;
  }
  CmpUnlockKcb(v5);
  v22 = 0;
  CmpUnlockRegistry();
  TransientPoolWithTag = (_PRIVILEGE_SET *)CmpAllocateTransientPoolWithTag(1ui64, 0x1B0ui64);
  v4 = TransientPoolWithTag;
  if( !TransientPoolWithTag )
  {
    v7 = -1073741670;
    goto LABEL_7;
  }
  memset(TransientPoolWithTag, 0i64, 0x1B0u);
  memset(&a6[1], 0, 24);
  a6[0] = *(_QWORD *)(KeyHive + 1536);
  v11 = *(_DWORD *)(KeyHive + 164);
  if( v11 )
  {
    if( v11 == 1 )
    {
      v12 = 1i64;
      a6[1] = *(_QWORD *)(KeyHive + 1544);
    }
    else
    {
      v12 = 2i64;
      *(_OWORD *)&a6[1] = *(_OWORD *)(KeyHive + 1568);
    }
  }
  else
  {
    v12 = 0i64;
  }
  v13 = *(unsigned int *)(KeyHive + 160);
  LODWORD(v13) = v13 & 0xFFFEFFFF;
  LODWORD(Flags) = 17825794;
  v7 = CmpCreateHive((INT64)&Hive, 2ui64, v13, v12, 0i64, (INT64)a6, 0i64, Flags, 0i64, 0i64, 0i64, (INT64)v4);
  if( v7 >= 0 )
  {
    CmpLockRegistryExclusive();
    v3 = 1;
    v7 = CmpPerformKeyBodyDeletionCheck((CM_KEY_BODY *)a1, 0i64);
    if( v7 >= 0 )
    {
      if( *(_BYTE *)(KeyHive + 2936) == 1 )
      {
        v7 = -1073741431;
        goto LABEL_7;
      }
      if( (*(_DWORD *)(KeyHive + 160) & 2) == 0 )
        goto LABEL_37;
      if( *(_DWORD *)(KeyHive + 904) )
      {
LABEL_39:
        v7 = -1073741823;
        goto LABEL_7;
      }
      if( (v5->_bf_b8 & 0x40000) != 0 )
      {
        if( *(_DWORD *)(KeyHive + 2912) )
          goto LABEL_39;
        v14 = *(unsigned int *)(*((_QWORD *)Hive + 8) + 36i64);
        if( (_DWORD)v14 == *(_DWORD *)(*(_QWORD *)(KeyHive + 64) + 36i64) )
        {
          v9 = (*((__int64(__fastcall **)(PVOID, __int64, __int64 *))Hive + 1))(Hive, v14, &v18);
          v15 = (*(__int64(__fastcall **)(INT64, _QWORD, __int64 *))(KeyHive + 8))(
                  KeyHive,
                  *(unsigned int *)(*(_QWORD *)(KeyHive + 64) + 36i64),
                  &v25);
          v19 = v15;
          if( HvMarkCellDirty(Hive, (PVOID)*(unsigned int *)(*((_QWORD *)Hive + 8) + 36i64), 0) )
          {
            v16 = *(_DWORD *)(v15 + 16);
            *(_WORD *)(v9 + 2) |= 0xCu;
            *(_DWORD *)(v9 + 16) = v16;
            (*(void(__fastcall **)(INT64, __int64 *))(KeyHive + 16))(KeyHive, &v25);
            (*((void(__fastcall **)(PVOID, __int64 *))Hive + 2))(Hive, &v18);
            CmpCleanUpKCBCacheTable(KeyHive);
            CmpSearchKeyControlBlockTreeEx(
              (__int64(__fastcall *)(__int64 *, __int64, __int64, __int64))CmpRefreshWorkerRoutine,
              KeyHive,
              (__int64)a1a,
              0i64,
              1);
            CmpFlushNotifiesOnKeyBodyList((__int64)v5, 0i64, (__int64)a1a, 1);
            CmpSwapHiveStorage(KeyHive, (INT64)Hive);
            CmpRebuildKcbCache(v5, (__int64)a1a);
            ++*(_DWORD *)(KeyHive + 204);
            v7 = 0;
            goto LABEL_7;
          }
          v7 = -1073741443;
          goto LABEL_45;
        }
      }
LABEL_37:
      v7 = -1073741811;
    }
  }
LABEL_7:
  CmpDrainDelayDerefContext((UINT64 **)a1a);
  if( v3 )
    CmpUnlockRegistry();
  if( v2 )
    CmpFinishBeingActiveFlusherAndReconciler((_EX_PUSH_LOCK *)KeyHive);
  if( v23 )
    ExReleaseRundownProtection((_EX_RUNDOWN_REF *)(KeyHive + 1632));
  if( Hive )
    CmpDestroyHive(Hive);
  if( v4 )
    CmSiFreeMemory(v4);
  return(unsigned int)v7;
}

Referenced by:

CmRestoreKey