MiCopySinglePage

NTSTATUS __stdcall MiCopySinglePage(
        PVOID VirtualAddress,
        UINT64 PageFrameIndex,
        UINT64 ByteOffset,
        UINT64 BytesInChunk,
        _MMPTE *PointerPte,
        UINT64 Flags){
  UINT64 v8; 
  char *v9; 
  __int64 v10; 
  _MMPFN *PfnDb; 
  INT64 v12; 
  unsigned __int8 v13; 
  int v14; 
  int ProtectionPfnCompatible; 
  __int64 v16; 
  UINT8 *v17; 
  __int64 v19; 
  if( PageFrameIndex > 0xFFFFFFFFFi64 )
    return -1073741503;
  v8 = 6 * PageFrameIndex;
  v9 = (char *)MmGetPfnDb() + 40;
  v10 = *(_QWORD *)&v9[48 * PageFrameIndex];
  if( (v10 & 0x4000000000000i64) == 0 )
    return -1073741503;
  PfnDb = MmGetPfnDb();
  v12 = (INT64)PfnDb + 48 * PageFrameIndex;
  if( (Flags & 1) != 0 )
  {
    v13 = MiLockPageInline((INT64)PfnDb + 48 * PageFrameIndex);
    v10 = *(_QWORD *)&v9[8 * v8];
  }
  else
  {
    v13 = 17;
  }
  if( (v10 & 0x4000000000000i64) == 0 )
  {
    if( v13 != 17 )
    {
      _InterlockedAnd64((volatile signed __int64 *)(v12 + 24), 0x7FFFFFFFFFFFFFFFui64);
      __writecr8(v13);
    }
    return -1073741503;
  }
  if( *(char *)(v12 + 35) < 0 || MiIsPageSecured(v12) )
  {
    if( v13 != 17 )
    {
      _InterlockedAnd64((volatile signed __int64 *)(v12 + 24), 0x7FFFFFFFFFFFFFFFui64);
      __writecr8(v13);
    }
    return -1073740023;
  }
  else
  {
    v14 = *(unsigned __int8 *)(v12 + 34) >> 6;
    if( v14 == 3 )
      MiChangePageAttribute(v12, 1i64, 1);
    ProtectionPfnCompatible = MiMakeProtectionPfnCompatible(1ui64, (_MMPFN *)v12);
    if( PointerPte )
    {
      *(_QWORD *)PointerPte = MiMakeValidPte((UINT64)PointerPte, PageFrameIndex, ProtectionPfnCompatible | 0x20000000u);
      v16 = (__int64)(((_QWORD)PointerPte << 25) - ((_QWORD)MmGetPteBase() << 25)) >> 16;
    }
    else
    {
      LODWORD(v19) = MiMapPageInHyperSpaceWorker(PageFrameIndex, 0i64, 0xA0000000ui64);
      v16 = v19;
    }
    v17 = (UINT8 *)(ByteOffset + v16);
    memmove((UINT8 *)VirtualAddress, v17, BytesInChunk);
    if( PointerPte )
      *(_QWORD *)PointerPte = ZeroPte;
    else
      MiUnmapPageInHyperSpaceWorker(v17, 0x11u, 0x80000000ui64);
    if( v14 == 3 )
      MiChangePageAttribute(v12, 3i64, 3);
    if( v13 != 17 )
    {
      _InterlockedAnd64((volatile signed __int64 *)(v12 + 24), 0x7FFFFFFFFFFFFFFFui64);
      __writecr8(v13);
    }
    return 0;
  }
}

Referenced by:

MmCopyMemory