MiRescanPageFileBitmapPortion

VOID __fastcall MiRescanPageFileBitmapPortion(
        _MMPAGING_FILE *PagingFile,
        _RTL_BITMAP *BitmapToScan,
        UINT64 StartingIndex,
        UINT64 Length,
        _MI_PAGEFILE_BITMAPS_CACHE_ENTRY **MinLengthCacheEntryInOut){
  unsigned int v5; 
  unsigned int v6; 
  unsigned __int64 v8; 
  _MMPAGING_FILE *v9; 
  unsigned int NextClearRunUlong; 
  unsigned int v11; 
  unsigned int v12; 
  __int64 v13; 
  _MMPAGING_FILE **v14; 
  unsigned __int64 v15; 
  unsigned __int64 v16; 
  bool v17; 
  unsigned __int64 v18; 
  unsigned __int64 *v19; 
  unsigned __int64 v20; 
  bool v21; 
  unsigned __int64 v22; 
  unsigned int v23; 
  __int64 v24; 
  RTL_BITMAP BitMapHeader; 
  *(&BitMapHeader.SizeOfBitMap + 1) = 0;
  v5 = StartingIndex & 0x1F;
  v6 = StartingIndex - v5;
  v8 = (unsigned __int64)((unsigned int)StartingIndex - v5) >> 5;
  v9 = (_MMPAGING_FILE *)*MinLengthCacheEntryInOut;
  BitMapHeader.Buffer = &BitmapToScan->Buffer[v8];
  BitMapHeader.SizeOfBitMap = v5 + Length;
  while( 1 )
  {
    NextClearRunUlong = RtlFindNextClearRunUlong(&BitMapHeader, v5, v8, (UINT64 *)0xFFFFFFFFi64);
    v11 = NextClearRunUlong;
    if( !NextClearRunUlong )
      break;
    v5 = NextClearRunUlong;
    v12 = *((_DWORD *)v9 + 13);
    if( v11 <= v12 )
    {
      if( *((_DWORD *)PagingFile + 35) > v11 )
        v11 = *((_DWORD *)PagingFile + 35);
      *((_DWORD *)PagingFile + 35) = v11;
    }
    else
    {
      if( v12 )
      {
        RtlRbRemoveNode((unsigned __int64 *)PagingFile + 18, (unsigned __int64)v9);
        RtlRbRemoveNode((unsigned __int64 *)PagingFile + 20, (unsigned __int64)v9 + 24);
        v23 = *((_DWORD *)PagingFile + 35);
        if( v23 <= *((_DWORD *)v9 + 13) )
          v23 = *((_DWORD *)v9 + 13);
        *((_DWORD *)PagingFile + 35) = v23;
      }
      else
      {
        v13 = *(_QWORD *)v9;
        if( *(_MMPAGING_FILE **)(*(_QWORD *)v9 + 8i64) != v9
          || (v14 = (_MMPAGING_FILE **)*((_QWORD *)v9 + 1), *v14 != v9) )
        {
          __fastfail(3u);
        }
        *v14 = (_MMPAGING_FILE *)v13;
        *(_QWORD *)(v13 + 8) = v14;
      }
      v15 = (unsigned __int64)PagingFile + 144;
      *((_DWORD *)v9 + 13) = v11;
      *((_DWORD *)v9 + 12) = v6;
      v16 = *((_QWORD *)PagingFile + 18);
      if( (*((_BYTE *)PagingFile + 152) & 1) != 0 && v16 )
        v16 ^= v15;
      v17 = 0;
      if( v16 )
      {
        while( 1 )
        {
          if( __PAIR64__(v11, v6) < *(_QWORD *)(v16 + 48) )
          {
            v18 = *(_QWORD *)v16;
            if( (*((_BYTE *)PagingFile + 152) & 1) != 0 )
            {
              if( !v18 )
                break;
              v18 ^= v16;
            }
            if( !v18 )
              break;
          }
          else
          {
            v18 = *(_QWORD *)(v16 + 8);
            if( (*((_BYTE *)PagingFile + 152) & 1) != 0 )
            {
              if( !v18 )
                goto LABEL_22;
              v18 ^= v16;
            }
            if( !v18 )
            {
LABEL_22:
              v17 = 1;
              break;
            }
          }
          v16 = v18;
        }
      }
      RtlRbInsertNodeEx((unsigned __int64 *)PagingFile + 18, v16, v17, (unsigned __int64)v9);
      v19 = (unsigned __int64 *)((char *)PagingFile + 160);
      v20 = *((_QWORD *)PagingFile + 20);
      if( (*((_BYTE *)PagingFile + 168) & 1) != 0 && v20 )
        v20 ^= (unsigned __int64)v19;
      v21 = 0;
      if( v20 )
      {
        while( 1 )
        {
          if( *((_DWORD *)v9 + 12) < *(_DWORD *)(v20 + 24) )
          {
            v22 = *(_QWORD *)v20;
            if( (*((_BYTE *)PagingFile + 168) & 1) != 0 )
            {
              if( !v22 )
                goto LABEL_37;
              v22 ^= v20;
            }
            if( !v22 )
            {
LABEL_37:
              v21 = 0;
              break;
            }
          }
          else
          {
            v22 = *(_QWORD *)(v20 + 8);
            if( (*((_BYTE *)PagingFile + 168) & 1) != 0 )
            {
              if( !v22 )
                goto LABEL_38;
              v22 ^= v20;
            }
            if( !v22 )
            {
LABEL_38:
              v21 = 1;
              break;
            }
          }
          v20 = v22;
        }
      }
      RtlRbInsertNodeEx(v19, v20, v21, (unsigned __int64)v9 + 24);
      ++*((_DWORD *)PagingFile + 32);
      v9 = (_MMPAGING_FILE *)*((_QWORD *)PagingFile + 22);
      if( v9 == (_MMPAGING_FILE *)((char *)PagingFile + 176) )
      {
        v24 = *((_QWORD *)PagingFile + 19);
        if( (v24 & 1) != 0 )
        {
          if( v24 == 1 )
            v9 = 0i64;
          else
            v9 = (_MMPAGING_FILE *)(v24 ^ (v15 | 1));
        }
        else
        {
          v9 = (_MMPAGING_FILE *)*((_QWORD *)PagingFile + 19);
        }
      }
    }
  }
  *MinLengthCacheEntryInOut = (_MI_PAGEFILE_BITMAPS_CACHE_ENTRY *)v9;
}

Referenced by:

MiRescanPagefileBitmaps