CmpCopySyncTree2

CHAR __fastcall CmpCopySyncTree2(
        INT64 a1,
        INT64 a2,
        INT64 a3,
        UINT64 a4,
        UINT64 BugCheckParameter2,
        INT16 a6,
        INT64 a7){
  __int64 v7; 
  WCHAR *v8; 
  INT64 v9; 
  INT64 v11; 
  WCHAR *PoolWithTag; 
  unsigned int *v13; 
  _CM_KEY_NODE *v14; 
  unsigned __int64 v15; 
  _CM_KEY_NODE *v16; 
  _CM_KEY_NODE *v17; 
  _CM_KEY_NODE *v18; 
  unsigned int v19; 
  __int64 v20; 
  char v21; 
  int v22; 
  void(__fastcall *v23)(UINT64, int *); 
  _DWORD *v24; 
  __int64 v25; 
  _DWORD *v26; 
  int v27; 
  char v28; 
  unsigned int v29; 
  int v30; 
  __int64 v31; 
  UINT8 *v32; 
  void *v33; 
  unsigned int v34; 
  int v35; 
  __int64 v36; 
  UINT64 v37; 
  int v38; 
  INT64 v39; 
  int v40; 
  _CM_KEY_NODE *v41; 
  UINT64 v42; 
  _CM_KEY_NODE *v43; 
  char v44; 
  char v45; 
  __int64 v46; 
  __int64 v47; 
  __int64 v48; 
  unsigned __int16 v49; 
  unsigned int v50; 
  __int64 v51; 
  char v52; 
  char v53; 
  WCHAR *a5; 
  CHAR v56; 
  UINT64 v57; 
  char v58; 
  int v59; 
  int v60; 
  WCHAR *P; 
  unsigned int v62; 
  _CM_KEY_NODE *v63; 
  UINT ChildCell; 
  UINT Cell; 
  int v66; 
  int v67; 
  int v68[2]; 
  int v69[2]; 
  void *Src; 
  int v71[2]; 
  int v72[2]; 
  int v73[2]; 
  int v74[2]; 
  int v75[2]; 
  int v76[2]; 
  _UNICODE_STRING KeyName; 
  bool v79; 
  v7 = 0i64;
  ChildCell = 0;
  v69[1] = 0;
  v8 = 0i64;
  v73[1] = 0;
  v9 = a1;
  v72[1] = 0;
  v75[1] = 0;
  v74[1] = 0;
  v66 = a6 & 1;
  v58 = 0;
  v69[0] = -1;
  KeyName = 0i64;
  v73[0] = -1;
  v72[0] = -1;
  Src = 0i64;
  v11 = 0i64;
  v75[0] = -1;
  v74[0] = -1;
  v67 = -1;
  P = 0i64;
  v79 = (unsigned int)(a7 - 1) <= 1;
  v68[0] = -1;
  v68[1] = 0;
  v62 = 0;
  v59 = -1;
  v60 = 1;
  if( (unsigned int)(a7 - 1) <= 1 )
  {
    PoolWithTag = (WCHAR *)ExAllocatePoolWithTag(PagedPool, 0x200ui64, 0x6E5A6D43ui64);
    P = PoolWithTag;
    v8 = PoolWithTag;
    if( !PoolWithTag )
      return(char)PoolWithTag;
    v9 = a1;
  }
  while( 2 )
  {
    v13 = (unsigned int *)(v9 + 20 * v7);
    v13[2] = 0;
    while( 1 )
    {
      while( 1 )
      {
        if( v11 )
          (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v72);
        v14 = (_CM_KEY_NODE *)(*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a4 + 8))(a4, *v13, v72);
        v63 = v14;
        v11 = (INT64)v14;
        if( !v14 )
        {
          v53 = 0;
          goto LABEL_102;
        }
        if( (int)CmpFindSubKeyByNumber((_HHIVE *)a4, v14, v13[2], &ChildCell) < 0 )
          goto LABEL_91;
        v15 = ChildCell;
        ++v13[2];
        if( (_DWORD)v15 != -1 && ((_BYTE)v66 || (v15 & 0x80000000) == 0i64) )
          break;
        if( v79 && (_DWORD)a7 != 2 )
        {
          v24 = (_DWORD *)(*(__int64(__fastcall **)(UINT64, _QWORD, int *))(BugCheckParameter2 + 8))(
                            BugCheckParameter2,
                            v13[1],
                            v75);
          v26 = v24;
          if( !v24 )
            goto LABEL_91;
          if( (_BYTE)v66 )
            v27 = *(_DWORD *)(v11 + 24);
          else
            v27 = 0;
          if( v24[5] + v24[6] > (unsigned int)(*(_DWORD *)(v11 + 20) + v27) )
            CmpSyncSubKeysAfterDelete(a4, v11, BugCheckParameter2, v24, v8);
          (*(void(__fastcall **)(UINT64, int *, __int64, _DWORD *))(BugCheckParameter2 + 16))(
            BugCheckParameter2,
            v75,
            v25,
            v26);
        }
        v28 = *((_BYTE *)v13 + 16);
        v29 = v59;
        if( (v28 & 1) != 0 )
        {
          v29 = v59 + 1;
          v59 = v29;
          if( v29 < v62 )
          {
            v32 = (UINT8 *)Src;
          }
          else
          {
            v30 = 1;
            if( v62 + 1 <= (v62 >> 1) + v62 )
              v30 = v62 >> 1;
            v31 = v62 + v30;
            v32 = (UINT8 *)ExAllocatePoolWithTag(PagedPool, 20 * v31, 0x20204D43ui64);
            if( !v32 )
              goto LABEL_91;
            v33 = Src;
            memmove(v32, (UINT8 *)Src, 20i64 * v62);
            if( v33 )
              ExFreePoolWithTag(v33, 0);
            v28 = *((_BYTE *)v13 + 16);
            v62 = v31;
            v29 = v59;
            Src = v32;
          }
          v34 = v13[3];
          v13[2] = 0;
          v35 = v60;
          v13[3] ^= ((unsigned __int8)v60 ^ (unsigned __int8)v34) & 7;
          *((_BYTE *)v13 + 16) = v28 & 0xFE;
          v36 = 5i64 * v29;
          *(_OWORD *)&v32[4 * v36] = *(_OWORD *)v13;
          *(_DWORD *)&v32[4 * v36 + 16] = v13[4];
        }
        else
        {
          v32 = (UINT8 *)Src;
          v35 = v60;
        }
        if( (_DWORD)v7 )
        {
          v39 = a1;
        }
        else
        {
          if( v29 == -1 )
          {
            if( (a6 & 0x40) != 0 )
              *(_DWORD *)(BugCheckParameter2 + 4800) = *(_DWORD *)(BugCheckParameter2 + 272);
            v43 = 0i64;
            v53 = 1;
            v17 = 0i64;
            goto LABEL_97;
          }
          v37 = 20i64 * v29;
          v38 = v29 - 1;
          v59 = v38;
          if( ((v32[12] ^ v32[v37 + 12]) & 7) != 0 )
          {
            *(_OWORD *)a1 = *(_OWORD *)v32;
            *(_DWORD *)(a1 + 16) = *((_DWORD *)v32 + 4);
            memmove(v32, v32 + 20, v37);
            v39 = a1;
          }
          else
          {
            v39 = a1;
            *(_OWORD *)a1 = *(_OWORD *)&v32[v37];
            *(_DWORD *)(a1 + 16) = *(_DWORD *)&v32[v37 + 16];
          }
          LODWORD(v7) = 1;
          if( v35 == (int)(*(_DWORD *)(v39 + 12) << 29) >> 29 )
          {
            v40 = *(_DWORD *)(BugCheckParameter2 + 272);
            v60 = v35 + 1;
            v59 = v38;
            if( v35 == 1 )
              *(_DWORD *)(BugCheckParameter2 + 4792) = v40;
            else
              *(_DWORD *)(BugCheckParameter2 + 4796) = v40;
          }
        }
        v11 = (INT64)v63;
        v7 = (unsigned int)(v7 - 1);
        v8 = P;
        v13 = (unsigned int *)(v39 + 20 * v7);
        if( v58 && (_DWORD)v7 == v67 )
        {
          v79 = 1;
          v58 = 0;
        }
      }
      if( v79 )
        break;
LABEL_17:
      if( (a6 & 0x40) == 0 )
        goto LABEL_69;
      v20 = (*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a4 + 8))(a4, (unsigned int)v15, v68);
      if( !v20 )
        goto LABEL_91;
      v21 = *(_BYTE *)(v20 + 12);
      if( (v21 & 2) != 0 )
        v22 = 1;
      else
        v22 = ((v21 & 1) == 0) | 2;
      if( v22 > v60 )
      {
        *((_BYTE *)v13 + 16) |= 1u;
        (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v68);
        goto LABEL_26;
      }
      v23 = *(void(__fastcall **)(UINT64, int *))(a4 + 16);
      if( v22 > (int)(v13[3] << 29) >> 29 )
      {
        v23(a4, v68);
LABEL_69:
        LODWORD(v57) = 2;
        v19 = CmpCopyKeyPartial(a4, (unsigned int)v15, BugCheckParameter2, v13[1], a6 | 4u, v56, v57);
        if( v19 != -1 )
        {
          v45 = 1;
          if( (v13[4] & 2) != 0 )
            goto LABEL_73;
          if( HvpMarkCellDirty(BugCheckParameter2, v13[1], 0) )
          {
            *((_BYTE *)v13 + 16) |= 2u;
LABEL_73:
            if( CmpAddSubKeyEx(BugCheckParameter2, v13[1], v19, v63->SubKeyCounts[v15 >> 31]) )
            {
              v46 = v13[1];
              v71[0] = -1;
              v71[1] = 0;
              v76[0] = -1;
              v76[1] = 0;
              v47 = (*(__int64(__fastcall **)(UINT64, __int64, int *))(BugCheckParameter2 + 8))(
                      BugCheckParameter2,
                      v46,
                      v71);
              if( v47 )
              {
                v48 = (*(__int64(__fastcall **)(UINT64, _QWORD, int *))(BugCheckParameter2 + 8))(
                        BugCheckParameter2,
                        v19,
                        v76);
                if( v48 )
                {
                  v49 = 2 * *(_WORD *)(v48 + 72);
                  if( (*(_BYTE *)(v48 + 2) & 0x20) == 0 )
                    v49 = *(_WORD *)(v48 + 72);
                  if( (unsigned __int16)*(_DWORD *)(v47 + 52) < (unsigned int)v49 )
                    *(_WORD *)(v47 + 52) = v49;
                  v50 = *(unsigned __int16 *)(v48 + 74);
                  if( *(_DWORD *)(v47 + 56) < v50 )
                    *(_DWORD *)(v47 + 56) = v50;
                  (*(void(__fastcall **)(UINT64, int *))(BugCheckParameter2 + 16))(BugCheckParameter2, v76);
                  (*(void(__fastcall **)(UINT64, int *))(BugCheckParameter2 + 16))(BugCheckParameter2, v71);
                  if( !v79 || !v58 )
                    goto LABEL_86;
                  if( CmpMarkKeyParentDirty(BugCheckParameter2, v19) )
                  {
                    v67 = v7;
                    v79 = 0;
                    goto LABEL_86;
                  }
                }
                else
                {
                  (*(void(__fastcall **)(UINT64, int *))(BugCheckParameter2 + 16))(BugCheckParameter2, v71);
                }
              }
            }
          }
        }
LABEL_91:
        v43 = 0i64;
        v17 = 0i64;
        goto LABEL_92;
      }
      v23(a4, v68);
LABEL_26:
      v8 = P;
    }
    v16 = (_CM_KEY_NODE *)(*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a4 + 8))(a4, (unsigned int)v15, v69);
    v17 = v16;
    if( !v16 )
      goto LABEL_89;
    CmpInitializeKeyNameString(v16, &KeyName, v8);
    v18 = (_CM_KEY_NODE *)(*(__int64(__fastcall **)(UINT64, _QWORD, int *))(BugCheckParameter2 + 8))(
                            BugCheckParameter2,
                            v13[1],
                            v74);
    if( !v18 )
      goto LABEL_89;
    Cell = 0;
    CmpFindSubKeyByNameWithStatus((_HHIVE *)BugCheckParameter2, v18, &KeyName, &Cell);
    v19 = Cell;
    (*(void(__fastcall **)(UINT64, int *))(BugCheckParameter2 + 16))(BugCheckParameter2, v74);
    if( v19 == -1 )
    {
      (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v69);
      v11 = (INT64)v63;
      v58 = 1;
      goto LABEL_17;
    }
    v41 = (_CM_KEY_NODE *)(*(__int64(__fastcall **)(UINT64, _QWORD, int *))(BugCheckParameter2 + 8))(
                            BugCheckParameter2,
                            v19,
                            v73);
    v43 = v41;
    if( v41 )
    {
      if( (_DWORD)a7 != 2 )
      {
        if( v41->LastWriteTime.QuadPart < v17->LastWriteTime.QuadPart )
        {
          LODWORD(a5) = v19;
          v44 = CmpSyncKeyValues(a4, v42, (INT64)v17, BugCheckParameter2, (UINT64)a5, (INT64)v41, v57);
          goto LABEL_65;
        }
LABEL_67:
        (*(void(__fastcall **)(UINT64, int *))(BugCheckParameter2 + 16))(BugCheckParameter2, v73);
        (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v69);
        v45 = 0;
LABEL_86:
        v7 = (unsigned int)(v7 + 1);
        if( (unsigned int)v7 < 0x200 )
        {
          v9 = a1;
          v51 = 5 * v7;
          v52 = *(_BYTE *)(a1 + 20 * v7 + 16);
          *(_DWORD *)(a1 + 4 * v51 + 12) &= 0xFFFFFFF8;
          *(_DWORD *)(a1 + 4 * v51 + 4) = v19;
          v8 = P;
          *(_BYTE *)(a1 + 4 * v51 + 16) = v52 & 0xFC | (2 * v45);
          v11 = (INT64)v63;
          *(_DWORD *)(a1 + 4 * v51) = v15;
          continue;
        }
        v17 = 0i64;
LABEL_89:
        v43 = 0i64;
LABEL_92:
        v53 = 0;
        goto LABEL_97;
      }
      LODWORD(a5) = v19;
      v44 = CmpMergeKeyValues((_HHIVE *)a4, v42, v17, (_HHIVE *)BugCheckParameter2, (UINT64)a5, v41, v57);
LABEL_65:
      if( v44 )
      {
        v43->LastWriteTime.QuadPart = v17->LastWriteTime.QuadPart;
        goto LABEL_67;
      }
    }
    break;
  }
  v53 = 0;
LABEL_97:
  (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v72);
  if( v17 )
    (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v69);
  if( v43 )
    (*(void(__fastcall **)(UINT64, int *))(BugCheckParameter2 + 16))(BugCheckParameter2, v73);
LABEL_102:
  if( P )
    ExFreePoolWithTag(P, 0);
  if( Src )
    ExFreePoolWithTag(Src, 0);
  LOBYTE(PoolWithTag) = v53;
  return(char)PoolWithTag;
}

Referenced by:

CmpCopySyncTree