CmpLoadHiveVolatile

__int64 __fastcall CmpLoadHiveVolatile(__int64 a1, void *a2){
  _CM_KEY_CONTROL_BLOCK *v2; 
  UNICODE_STRING *v5; 
  int v7; 
  _HHIVE *KeyHive; 
  int Hive; 
  unsigned int v10; 
  unsigned int v11; 
  __int64 v12; 
  _UNICODE_STRING *v13; 
  __int16 v14; 
  unsigned __int16 v15; 
  UNICODE_STRING *v16; 
  unsigned __int16 v17; 
  __int16 v18; 
  __int64 v19; 
  __int64 v20; 
  struct _LOOKASIDE_LIST_EX *v21; 
  _QWORD *v22; 
  _QWORD *v23; 
  INT64 a5; 
  CHAR a6; 
  INT64 a6a; 
  INT64 a7; 
  UINT64 Flags; 
  UINT64 Flagsa; 
  PVOID P; 
  struct _UNICODE_STRING DestinationString; 
  PVOID v32; 
  int v33[2]; 
  UNICODE_STRING Source; 
  INT64 v35; 
  __int128 v36; 
  __int64 v37; 
  UUID a10; 
  UUID Uuid; 
  INT64 result[54]; 
  v2 = *(_CM_KEY_CONTROL_BLOCK **)(a1 + 8);
  v33[0] = -1;
  P = 0i64;
  v32 = 0i64;
  v37 = 0i64;
  v33[1] = 0;
  v5 = 0i64;
  Source = 0i64;
  DestinationString = 0i64;
  Uuid = 0i64;
  a10 = 0i64;
  v36 = 0i64;
  memset((INT64)result, 0i64);
  if( !CmpAcquireShutdownRundown() )
    return 3221225865i64;
  v7 = CmpUuidCreate(&Uuid);
  if( v7 >= 0 )
  {
    v7 = CmpUuidCreate(&a10);
    if( v7 >= 0 )
    {
      KeyHive = v2->KeyHash.KeyHive;
      if( KeyHive == (_HHIVE *)CmpMasterHive )
      {
        v37 = 0i64;
        LODWORD(Flags) = 17825793;
        v36 = 0i64;
        v35 = (INT64)a2;
        Hive = CmpCreateHive(
                 (INT64)&v32,
                 2ui64,
                 0x8000ui64,
                 0i64,
                 0i64,
                 (INT64)&v35,
                 0i64,
                 Flags,
                 0i64,
                 0i64,
                 0i64,
                 (INT64)result);
        if( Hive >= 0 )
        {
          LODWORD(Flagsa) = 17825792;
          v7 = CmpCreateHive(
                 (INT64)&P,
                 0i64,
                 1ui64,
                 0i64,
                 0i64,
                 0i64,
                 0i64,
                 Flagsa,
                 (INT64)&Uuid,
                 (INT64)&a10,
                 0i64,
                 (INT64)result);
          if( v7 >= 0 )
          {
            CmpLockRegistryExclusive();
            if( CmpIsKeyDeletedForKeyBody(a1, 0i64) )
            {
              v7 = -1073741444;
            }
            else if( LOBYTE(KeyHive[1].Storage[1].FreeDisplay[19].Display.SizeOfBitMap) == 1 )
            {
              v7 = -1073741431;
            }
            else
            {
              LODWORD(a7) = 1;
              v10 = CmpCopyKeyPartial(
                      (UINT64)v32,
                      *(unsigned int *)(*((_QWORD *)v32 + 8) + 36i64),
                      (UINT64)P,
                      0xFFFFFFFFui64,
                      2,
                      a6,
                      a7);
              v11 = v10;
              if( v10 != -1 )
              {
                LODWORD(a6a) = 0;
                *(_DWORD *)(*((_QWORD *)P + 8) + 36i64) = v10;
                if( CmpCopySyncTree(
                       (UINT64)v32,
                       *(unsigned int *)(*((_QWORD *)v32 + 8) + 36i64),
                       (UINT64)P,
                       v10,
                       2,
                       a6a) )
                {
                  v12 = (*((__int64(__fastcall **)(PVOID, _QWORD, int *))P + 1))(P, v11, v33);
                  if( v12 )
                  {
                    v13 = CmpConstructName(v2);
                    v14 = 2 * *(_WORD *)(v12 + 72);
                    v5 = v13;
                    if( (*(_BYTE *)(v12 + 2) & 0x20) == 0 )
                      v14 = *(_WORD *)(v12 + 72);
                    v15 = v13->Length + v14 + 2;
                    DestinationString.Buffer = (wchar_t *)ExAllocatePoolWithTag(PagedPool, v15, 0x20204D43ui64);
                    if( DestinationString.Buffer )
                    {
                      DestinationString.MaximumLength = v15;
                      DestinationString.Length = v15;
                      RtlCopyUnicodeString(&DestinationString, v5, v16);
                      RtlAppendUnicodeToString(&DestinationString, (PWCHAR)L"\\");
                      v17 = *(_WORD *)(v12 + 72);
                      if( (*(_BYTE *)(v12 + 2) & 0x20) != 0 )
                      {
                        CmpCopyCompressedName(
                          &DestinationString.Buffer[(unsigned __int64)DestinationString.Length >> 1],
                          DestinationString.MaximumLength - (unsigned int)DestinationString.Length,
                          (PWCHAR)(v12 + 76),
                          (unsigned __int16)(2 * v17));
                        v18 = 2 * *(_WORD *)(v12 + 72);
                        if( (*(_BYTE *)(v12 + 2) & 0x20) == 0 )
                          v18 = *(_WORD *)(v12 + 72);
                        DestinationString.Length += v18;
                      }
                      else
                      {
                        Source.MaximumLength = *(_WORD *)(v12 + 72);
                        Source.Length = v17;
                        Source.Buffer = (wchar_t *)(v12 + 76);
                        RtlAppendUnicodeStringToString(&DestinationString, &Source);
                      }
                      (*((void(__fastcall **)(PVOID, int *))P + 2))(P, v33);
                      LODWORD(a5) = 512;
                      v7 = CmpLinkHiveToMaster(
                             &DestinationString,
                             0i64,
                             (_CMHIVE *)P,
                             0i64,
                             a5,
                             0,
                             0i64,
                             0i64,
                             0i64,
                             0i64,
                             1u);
                      if( v7 >= 0 )
                      {
                        CmpAddToHiveFileList((__int64)P, v19, v20, v21);
                        CmpLockHiveListExclusive();
                        v22 = (_QWORD *)qword_140D2D918;
                        v23 = (char *)P + 1600;
                        if( *(__int64 **)qword_140D2D918 != &CmpHiveListHead )
                          __fastfail(3u);
                        *v23 = &CmpHiveListHead;
                        v23[1] = v22;
                        *v22 = v23;
                        qword_140D2D918 = (__int64)v23;
                        CmpUnlockHiveList();
                        if( !CmpProfileLoaded )
                        {
                          CmpGlobalQuotaAllowed = CmpGlobalQuota;
                          CmpProfileLoaded = 1;
                        }
                      }
                      CmpUnlockRegistry();
                      if( v7 < 0 )
                        CmpDestroyHive(P);
                      CmpDestroyHive(v32);
                      ExFreePoolWithTag(DestinationString.Buffer, 0);
                      ExFreePoolWithTag(v5, 0x624E4D43u);
                      goto LABEL_25;
                    }
                    (*((void(__fastcall **)(PVOID, int *))P + 2))(P, v33);
                  }
                }
              }
              v7 = -1073741670;
            }
            CmpUnlockRegistry();
            CmpDestroyHive(P);
          }
          CmpDestroyHive(v32);
          if( v5 )
            CmpFreeTransientPoolWithTag(v5, 0x624E4D43ui64);
        }
        else
        {
          v7 = Hive;
        }
      }
      else
      {
        v7 = -1073741811;
      }
    }
  }
LABEL_25:
  CmpReleaseShutdownRundown();
  return(unsigned int)v7;
}

Referenced by:

CmRestoreKey