CmpSaveKeyByFileCopy

__int64 __fastcall CmpSaveKeyByFileCopy(__int64 a1, __int64 a2){
  _DWORD *PoolWithQuotaTag; 
  unsigned int v5; 
  int v6; 
  unsigned int v7; 
  unsigned int v8; 
  unsigned int v9; 
  int v10; 
  int v11; 
  int v12; 
  int v13; 
  unsigned int *v15; 
  unsigned int *v16; 
  unsigned int *v17; 
  unsigned int *v18; 
  unsigned int *v19; 
  unsigned int v20; 
  unsigned int v21; 
  CMP_OFFSET_ARRAY offsetArray; 

  *(&offsetArray.FileOffset + 1) = 0;
  *(&offsetArray.DataLength + 1) = 0;
  PoolWithQuotaTag = ExAllocatePoolWithQuotaTag(NonPagedPoolBaseCacheAligned|PagedPool|0x8, 0x10000ui64, 0x20204D43ui64);
  if( PoolWithQuotaTag )
  {
    CmpBecomeActiveFlusherAndReconciler((PCMHIVE)a1);
    if( (*(_DWORD *)(a1 + 4264) & 2) != 0 )
    {
      v5 = -1073741670;
    }
    else
    {
      *(_QWORD *)(a1 + 1552) = a2;
      LODWORD(v15) = 4096;
      LOBYTE(v6) = CmpFileRead((_HHIVE *)a1, 0i64, 0i64, PoolWithQuotaTag, (UINT64)v15);
      if( v6 >= 0 )
      {
        v7 = PoolWithQuotaTag[10];
        offsetArray.FileOffset = 0;
        ++PoolWithQuotaTag[1];
        LODWORD(v16) = 0;
        offsetArray.DataBuffer = PoolWithQuotaTag;
        offsetArray.DataLength = 4096;
        if( (int)CmpFileWrite((_HHIVE *)a1, 2u, &offsetArray, 1u, v16, v20) >= 0 )
        {
          v8 = 0;
          if( v7 )
          {
            while( 1 )
            {
              v9 = v7 - v8;
              if( v7 - v8 > 0x10000 )
                v9 = 0x10000;
              LODWORD(v17) = v9;
              LOBYTE(v10) = CmpFileRead((_HHIVE *)a1, 0i64, (UINT *)(v8 + 4096), PoolWithQuotaTag, (UINT64)v17);
              if( v10 < 0 )
                break;
              LODWORD(v18) = 0;
              offsetArray.FileOffset = v8 + 4096;
              offsetArray.DataBuffer = PoolWithQuotaTag;
              offsetArray.DataLength = v9;
              if( (int)CmpFileWrite((_HHIVE *)a1, 2u, &offsetArray, 1u, v18, v21) < 0 )
                break;
              v8 += v9;
              if( v8 >= v7 )
                goto LABEL_14;
            }
          }
          else
          {
LABEL_14:
            if( (int)CmpFileFlush((_HHIVE *)a1, 2ui64) >= 0 )
            {
              LODWORD(v17) = 4096;
              LOBYTE(v11) = CmpFileRead((_HHIVE *)a1, 0i64, 0i64, PoolWithQuotaTag, (UINT64)v17);
              if( v11 >= 0 )
              {
                ++PoolWithQuotaTag[1];
                ++PoolWithQuotaTag[2];
                offsetArray.FileOffset = 0;
                LODWORD(v19) = 0;
                offsetArray.DataBuffer = PoolWithQuotaTag;
                offsetArray.DataLength = 4096;
                if( (int)CmpFileWrite((_HHIVE *)a1, 2u, &offsetArray, 1u, v19, v21) >= 0 )
                {
                  v12 = CmpFileFlush((_HHIVE *)a1, 2ui64);
                  v13 = 0;
                  if( v12 < 0 )
                    v13 = -1073741491;
                  v5 = v13;
                  goto LABEL_20;
                }
              }
            }
          }
        }
      }
      v5 = -1073741491;
    }
LABEL_20:
    *(_QWORD *)(a1 + 1552) = 0i64;
    CmpFinishBeingActiveFlusherAndReconciler((_EX_PUSH_LOCK *)a1);
    ExFreePoolWithTag(PoolWithQuotaTag, 0);
    return v5;
  }
  return(unsigned int)-1073741670;
}

Referenced by:

CmSaveKey