MiComparePteProtections

__int64 __fastcall MiComparePteProtections(ULONG_PTR a1, unsigned __int64 a2, unsigned __int64 a3, int a4, int a5){
  unsigned int v5; 
  __int64 v10; 
  unsigned __int8 v11; 
  int v12; 
  bool v13; 
  int v15; 
  int v16; 
  unsigned __int64 v17; 
  __int16 v18; 
  int v19; 
  v5 = 0;
  v17 = 0i64;
  v15 = 0;
  v19 = 0;
  v16 = 0;
  v18 = 0;
  v10 = *((_QWORD *)KeGetCurrentThread() + 23);
  v11 = MiLockWorkingSetShared(v10 + 1664);
  while( a2 <= a3 )
  {
    MiQueryAddressState(a2, a3, v11, a1, 0i64, &v19, &v16, &v18, &v17, &v15);
    v12 = v19;
    if( !v19 )
    {
      if( v15 )
        goto LABEL_13;
      v13 = ((*(_DWORD *)(a1 + 48) >> 7) & 0x1F) == 0;
      v12 = (*(_DWORD *)(a1 + 48) >> 7) & 0x1F;
      v19 = v12;
      if( v13 )
        goto LABEL_13;
    }
    if( a5 == 1 )
    {
      if( v12 != a4 )
        goto LABEL_13;
    }
    else if( v12 == -1 || (v12 & 0xFFFFFFF8) == 16 || (a4 != 1 ? (v13 = (v12 & 4) == 0) : (v13 = (v12 & 7) == 0), v13) )
    {
LABEL_13:
      v5 = -1073741755;
      break;
    }
    a2 = v17;
  }
  MiUnlockWorkingSetShared(v10 + 1664, v11);
  return v5;
}

Referenced by:

MiCheckSecuredVad
MiSecureVad