PfpPfnPrioRequest

INT64 __fastcall PfpPfnPrioRequest(INT64 a1, CHAR a2, UINT64 *a3){
  unsigned int v5; 
  UINT8 *v6; 
  int v7; 
  unsigned int v8; 
  int v9; 
  _MMPFN_IDENTITY *v10; 
  _MMPFN_IDENTITY *v11; 
  _ETHREAD *CurrentThread; 
  UINT64 PageFrameIndex; 
  unsigned __int64 v14; 
  unsigned __int64 v15; 
  unsigned __int64 v16; 
  unsigned int v18; 
  int v19; 
  unsigned int v20; 
  int v21; 
  _DWORD *v22; 
  void *Src; 
  v5 = 0;
  v6 = 0i64;
  Src = 0i64;
  v7 = *(_DWORD *)(a1 + 8);
  if( v7 == 6 )
  {
    v8 = *(_DWORD *)(a1 + 24);
    if( v8 < 0xD8 )
    {
      v9 = -1073741306;
      goto LABEL_22;
    }
    v9 = PfpCopyUserPfnPrioRequest(*(_QWORD *)(a1 + 16), v8, 6, &Src, a2, 1);
    if( v9 >= 0 )
    {
      v22 = Src;
      v10 = (_MMPFN_IDENTITY *)((char *)Src + 192);
      v9 = 0;
      v11 = (_MMPFN_IDENTITY *)((char *)Src + 24 * *((_QWORD *)Src + 1) + 192);
      CurrentThread = (_ETHREAD *)KeGetCurrentThread();
      MiLockDynamicMemoryShared((INT64)&MiSystemPartition, (INT64)CurrentThread);
      if( v10 < v11 )
      {
        while( 1 )
        {
          PageFrameIndex = v10->PageFrameIndex;
          if( !(unsigned int)MiIsPfn(PageFrameIndex) )
            break;
          MiIdentifyPfnWrapper((_MMPFN *)((char *)MmGetPfnDb() + 48 * PageFrameIndex), v10++);
          if( v10 >= v11 )
            goto LABEL_7;
        }
        v10->u2.FileObject = (PVOID)((unsigned __int64)v10->u2.FileObject | 2);
        v9 = -1073741584;
      }
LABEL_7:
      MiUnlockDynamicMemoryShared((INT64)&MiSystemPartition, (INT64)CurrentThread);
      v6 = (UINT8 *)Src;
      if( v9 >= 0 && (*((_DWORD *)Src + 1) & 1) != 0 )
        MmQueryMemoryListInformation((PVOID)0xFFFFFFFFFFFFFFFFi64, (UINT64)Src + 16, (UINT64 *)0xB0);
      if( a2 )
      {
        v14 = *(_QWORD *)(a1 + 16);
        if( *(_DWORD *)(a1 + 24) )
        {
          if( (v14 & 7) != 0 )
            ExRaiseDatatypeMisalignment();
          v15 = v14 + *(unsigned int *)(a1 + 24) - 1i64;
          if( v14 > v15 || v15 >= 0x7FFFFFFF0000i64 )
            ExRaiseAccessViolation();
          v16 = (v15 & 0xFFFFFFFFFFFFF000ui64) + 4096;
          do
          {
            *(_BYTE *)v14 = *(_BYTE *)v14;
            v14 = (v14 & 0xFFFFFFFFFFFFF000ui64) + 4096;
          }
          while( v14 != v16 );
          v6 = (UINT8 *)Src;
        }
      }
      v5 = 24 * (v22[2] + 8);
      memmove(*(UINT8 **)(a1 + 16), v6, v5);
      goto LABEL_21;
    }
    goto LABEL_45;
  }
  if( v7 != 7 && v7 != 22 && v7 != 29 )
  {
    v9 = -1073741821;
    goto LABEL_22;
  }
  v18 = *(_DWORD *)(a1 + 24);
  if( v18 < 0xD8 )
  {
    v9 = -1073741306;
    goto LABEL_22;
  }
  v9 = PfpCopyUserPfnPrioRequest(*(_QWORD *)(a1 + 16), v18, v7, &Src, a2, 0);
  if( v9 >= 0 )
  {
    v19 = *(_DWORD *)(a1 + 8);
    if( v19 == 7 )
    {
      v20 = 0;
    }
    else
    {
      if( v19 != 29 )
      {
        v6 = (UINT8 *)Src;
        MmRelocatePfnList();
        goto LABEL_31;
      }
      v20 = 1;
    }
    v6 = (UINT8 *)Src;
    v21 = MmSetPfnListInfo(*((_QWORD *)Src + 1), (_QWORD *)Src + 24, v20);
LABEL_31:
    v9 = v21;
    if( *(_DWORD *)(a1 + 8) == 22 || v21 < 0 )
    {
      if( a2 )
        ProbeForWrite(*(VOID **)(a1 + 16), *(unsigned int *)(a1 + 24), 8ui64);
      v5 = 24 * (*((_DWORD *)v6 + 2) + 8);
      memmove(*(UINT8 **)(a1 + 16), v6, v5);
    }
LABEL_21:
    *(_DWORD *)a3 = v5;
    goto LABEL_22;
  }
LABEL_45:
  v6 = (UINT8 *)Src;
LABEL_22:
  if( v6 )
    ExFreePoolWithTag(v6, 0);
  return(unsigned int)v9;
}

Referenced by:

PfQuerySuperfetchInformation
PfSetSuperfetchInformation