MiWalkVaRange

INT64 __fastcall MiWalkVaRange(UINT64 rcx0, UINT64 rdx0, INT64 r8_0, INT64 a4, INT64 Partition){
  INT64 v5; 
  _MMPFN *v8; 
  _MMPTE *PteBase; 
  unsigned __int64 v10; 
  unsigned __int64 v11; 
  UINT64 v12; 
  INT64 v13; 
  char v14; 
  unsigned __int64 v15; 
  unsigned __int64 v16; 
  _MMPTE *v17; 
  unsigned int v18; 
  INT64 v19; 
  INT64 ProtoPteAddress; 
  int v21; 
  int v22; 
  UINT64 v23; 
  int v24; 
  INT64 v25; 
  UINT64 v26; 
  INT64 v27; 
  unsigned int v28; 
  int v30; 
  unsigned __int64 v31; 
  __int64 v32; 
  INT64 v33; 
  INT64 v34; 
  __int64 v35; 
  __int64 v36; 
  __int64 v37; 
  int v38; 
  INT64 a5; 
  _DWORD *a6; 
  _MI_PARTITION **OriginalPte; 
  INT64 a8; 
  INT64 a9; 
  INT64 rcx0a; 
  INT64 a11; 
  INT64 OperationArgument; 
  UINT64 v47; 
  INT64 v48; 
  INT64 v49; 
  unsigned __int64 v50; 
  int v51; 
  UINT64 a2; 
  _SUBSECTION *ContainingSubsection; 
  INT64 a1; 
  __int64 v55; 
  INT64 a3[4]; 
  INT64 result[20]; 
  rcx0a = r8_0;
  v5 = r8_0;
  a2 = 0i64;
  v51 = 0;
  a1 = 0i64;
  LODWORD(OperationArgument) = a4;
  memset((INT64)result, 0i64);
  HIDWORD(a9) = 0;
  v8 = 0i64;
  a11 = 0i64;
  LOBYTE(a9) = 17;
  PteBase = MmGetPteBase();
  v10 = (unsigned __int64)PteBase + ((rcx0 >> 9) & 0x7FFFFFFFF8i64);
  v11 = (unsigned __int64)PteBase + ((rdx0 >> 9) & 0x7FFFFFFFF8i64);
  a3[1] = 20i64;
  a3[0] = 1i64;
  v12 = 0i64;
  a3[2] = 0i64;
  a3[3] = 0i64;
  v50 = v11;
  v47 = 0i64;
  v55 = *((_QWORD *)KeGetCurrentThread() + 23);
  v13 = v55 + 1664;
  v48 = v55 + 1664;
  BYTE1(a9) = MiLockWorkingSetShared(v55 + 1664);
  v14 = BYTE1(a9);
  if( v10 > v11 )
  {
    v28 = 0;
    goto LABEL_35;
  }
LABEL_2:
  if( v12 )
  {
    MiUnlockPageTableInternal(v13, v12);
    v12 = 0i64;
    v47 = 0i64;
  }
  MiGetNextPageTable(v10, v11, (INT64)a3, v14, 0, &v51);
  LODWORD(v49) = 1;
  v16 = v15;
  v17 = MmGetPteBase();
  if( v15 == v10 )
    goto LABEL_5;
  if( (*(_DWORD *)(v5 + 48) & 0x100000) == 0
    && *(_QWORD *)(v5 + 80)
    && MiGetProtoPteAddress(
         (_MMVAD *)v5,
         (unsigned __int64)((__int64)((v10 << 25) - ((_QWORD)v17 << 25)) >> 16) >> 12,
         0i64,
         &ContainingSubsection) )
  {
    LODWORD(v49) = 0;
    goto LABEL_5;
  }
  v28 = -1073740748;
  HIDWORD(a9) = -1073740748;
  if( v16 )
  {
    v10 = v16;
LABEL_5:
    if( v16 )
      v47 = (UINT64)v17 + ((v16 >> 9) & 0x7FFFFFFFF8i64);
    v18 = v49;
    v19 = rcx0a;
    while( 1 )
    {
      ProtoPteAddress = 0i64;
      v21 = 0;
      v22 = 0;
      if( !v18 )
        goto LABEL_61;
      v23 = *(_QWORD *)v10;
      MiPteInShadowRange(v10);
      if( !v23 )
        break;
      if( (v23 & 1) != 0 || (v23 & 0x400) == 0 )
      {
        v19 = rcx0a;
        goto LABEL_13;
      }
      v30 = OperationArgument;
      if( (_DWORD)OperationArgument == 2 && MI_PROTO_FORMAT_COMBINED(v23) )
      {
        v32 = v23;
        if( qword_140C4DC80 && (v23 & 0x10) == 0 )
          v32 = v23 & ~qword_140C4DC80;
        ProtoPteAddress = v32 >> 16;
LABEL_54:
        v19 = rcx0a;
        if( ProtoPteAddress )
        {
LABEL_55:
          if( ((ProtoPteAddress ^ a11) & 0xFFFFFFFFFFFFF000ui64) != 0 )
          {
            if( v8 )
            {
              MiUnlockProtoPoolPage(v8, (unsigned __int8)a9);
              a11 = 0i64;
            }
            v8 = MiLockProtoPoolPage((_MMPTE *)ProtoPteAddress, (UINT8 *)&a9);
            if( !v8 )
            {
              MiFlushTbList((__int64)a3);
              v12 = v47;
              v13 = v48;
              if( v47 )
              {
                MiUnlockPageTableInternal(v48, v47);
                v12 = 0i64;
                v47 = 0i64;
              }
              v14 = BYTE1(a9);
              MiUnlockWorkingSetShared(v13, BYTE1(a9));
              MmAccessFault(2ui64, (PVOID)ProtoPteAddress, 0, 0i64);
              v11 = v50;
LABEL_32:
              MiLockWorkingSetShared(v13);
              v5 = rcx0a;
              if( v10 > v11 )
              {
                v28 = HIDWORD(a9);
                goto LABEL_34;
              }
              goto LABEL_2;
            }
            a11 = ProtoPteAddress;
          }
        }
        else
        {
LABEL_13:
          if( v8 )
          {
            MiUnlockProtoPoolPage(v8, (unsigned __int8)a9);
            v8 = 0i64;
            a11 = 0i64;
          }
        }
        LODWORD(a5) = OperationArgument;
        v24 = MiActOnPte(v19, v18, (_MMPTE *)v10, (_MMPTE *)ProtoPteAddress, a5, Partition, (_MI_PARTITION **)&a1, &a2);
        if( v24 )
        {
          if( v24 == 274 )
          {
            v37 = (__int64)((v10 << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16;
            MiInsertTbFlushEntry((INT64)a3, v37, 1i64, 0i64);
            MiFlushTbList((__int64)a3);
            v38 = MiCopyOnWrite(v37, (UINT64 *)v10, -1i64, 0i64);
            v19 = rcx0a;
            v22 = v38;
            v10 -= 8i64;
            v21 = 1;
          }
          else if( v24 == -1073741791 )
          {
            MiInsertTbFlushEntry((INT64)a3, (__int64)((v10 << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16, 1i64, 0i64);
          }
          else
          {
            HIDWORD(a9) = v24;
          }
        }
        v26 = a2;
        if( a2 )
        {
          if( v8 )
          {
            MiUnlockProtoPoolPage(v8, (unsigned __int8)a9);
            v26 = a2;
            v8 = 0i64;
            a11 = 0i64;
          }
          MiReleasePageFileInfo(
            a1,
            v26,
            1,
            v25,
            a5,
            (INT64)a6,
            (INT64)OriginalPte,
            a8,
            a9,
            rcx0a,
            a11,
            OperationArgument);
        }
        goto LABEL_17;
      }
      if( MI_PROTO_FORMAT_COMBINED(v23) )
      {
        if( v30 == 1 )
        {
          v19 = rcx0a;
          HIDWORD(a9) = -1073740748;
        }
        else
        {
          if( v8 )
            MiUnlockProtoPoolPage(v8, (unsigned __int8)a9);
          v33 = 0i64;
          if( !v8 )
            v33 = a11;
          v34 = v33;
          a11 = v33;
          MiFlushTbList((__int64)a3);
          HIDWORD(a9) = (unsigned int)MiMakeProtoLeafValid((MMPTE *)v10, 0x18ui64, BYTE1(a9));
          if( a9 >= 0 )
          {
            v10 -= 8i64;
            a11 = v34;
            v19 = rcx0a;
            v8 = 0i64;
          }
          else
          {
            v19 = rcx0a;
            v8 = 0i64;
            HIDWORD(a9) = -1073740748;
          }
        }
        goto LABEL_17;
      }
      v31 = (__int64)((v10 << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16;
      if( ((v31 & 0xFFFFFFFFFFFFF000ui64) == 2147352576
         || (v31 & 0xFFFFFFFFFFFFF000ui64) == qword_140C4DB88 && qword_140C4DB88)
        && (*(_DWORD *)(v55 + 2172) & 1) == 0 )
      {
        v19 = rcx0a;
        HIDWORD(a9) = -1073740748;
      }
      else
      {
        if( (*(_DWORD *)(rcx0a + 48) & 0x100000) == 0 && *(_QWORD *)(rcx0a + 80) )
        {
          ProtoPteAddress = (INT64)MiGetProtoPteAddress((_MMVAD *)rcx0a, v31 >> 12, 0i64, &ContainingSubsection);
          if( MiIsPrototypePteVadLookup(v23) )
            goto LABEL_54;
          v35 = v23;
          if( qword_140C4DC80 && (v23 & 0x10) == 0 )
            v35 = v23 & ~qword_140C4DC80;
          if( ProtoPteAddress == v35 >> 16 )
            goto LABEL_54;
        }
        v36 = v23;
        if( qword_140C4DC80 && (v23 & 0x10) == 0 )
          v36 = v23 & ~qword_140C4DC80;
        ProtoPteAddress = v36 >> 16;
        if( (_DWORD)OperationArgument == 2 )
          goto LABEL_54;
        v19 = rcx0a;
        HIDWORD(a9) = -1073740748;
      }
LABEL_17:
      v11 = v50;
      v10 += 8i64;
      if( v21 == 1
        || v22 < 0
        || v10 > v50
        || (v10 & 0xFFF) == 0
        || (v10 & 0x78) == 0 && MiWorkingSetIsContended(v48)
        || KeShouldYieldProcessor() )
      {
        if( v8 )
          MiUnlockProtoPoolPage(v8, (unsigned __int8)a9);
        v27 = 0i64;
        if( !v8 )
          v27 = a11;
        a11 = v27;
        MiFlushTbList((__int64)a3);
        v13 = v48;
        if( v47 )
        {
          MiUnlockPageTableInternal(v48, v47);
          v47 = 0i64;
        }
        v14 = BYTE1(a9);
        MiUnlockWorkingSetShared(v13, BYTE1(a9));
        if( v22 == -1073740748 )
          MiCopyOnWriteCheckConditions(v13, 3221226548i64);
        v12 = v47;
        v8 = 0i64;
        goto LABEL_32;
      }
    }
    v19 = rcx0a;
LABEL_61:
    if( (*(_DWORD *)(v19 + 48) & 0x100000) != 0 || !*(_QWORD *)(v19 + 80) )
      goto LABEL_13;
    ProtoPteAddress = (INT64)MiGetProtoPteAddress(
                               (_MMVAD *)v19,
                               (unsigned __int64)((__int64)((v10 << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16) >> 12,
                               0i64,
                               &ContainingSubsection);
    if( ProtoPteAddress )
      goto LABEL_55;
    if( v18 )
      goto LABEL_13;
    v21 = 1;
    v10 -= 8i64;
    goto LABEL_17;
  }
  v13 = v48;
LABEL_34:
  v14 = BYTE1(a9);
LABEL_35:
  MiFlushTbList((__int64)a3);
  if( v12 )
    MiUnlockPageTableInternal(v13, v12);
  MiUnlockWorkingSetShared(v13, v14);
  return v28;
}

Referenced by:

MiProcessVaRangesInfoClass
MiResetVirtualMemory