MiGetProtoPteAddress

VOID __fastcall MiGetProtoPteAddress(){
  __int64 v0; 
  __int64 v1; 
  char v2; 
  _SUBSECTION **v3; 
  _SUBSECTION **v4; 
  char v5; 
  unsigned __int64 v6; 
  unsigned int v7; 
  _SUBSECTION *v8; 
  _CONTROL_AREA *ControlArea; 
  unsigned __int64 v10; 
  unsigned __int64 PtesInSubsection; 
  __int64 v12; 
  unsigned __int64 v13; 
  _SUBSECTION *v14; 
  unsigned __int64 v15; 
  UINT64 v16; 
  _SUBSECTION *SubsectionNode; 
  unsigned __int64 v18; 
  unsigned __int64 v19; 
  unsigned __int64 v20; 
  unsigned __int64 v21; 
  unsigned __int64 v22; 
  unsigned int SessionId; 

  v4 = v3;
  v5 = v2;
  v6 = *(unsigned int *)(v1 + 24) | ((unsigned __int64)*(unsigned __int8 *)(v1 + 32) << 32);
  if( ((*(_DWORD *)(v1 + 48) & 0x70) != 32 || (*(_DWORD *)(**(_QWORD **)(v1 + 72) + 56i64) & 0x4000000) == 0)
    && (__int64)(*(_QWORD *)(v1 + 88) - *(_QWORD *)(v1 + 80)) >> 3 >= v0 - v6
    && (v2 & 4) == 0 )
  {
    *v3 = *(_SUBSECTION **)(v1 + 72);
    return;
  }
  v7 = 0;
  *v4 = 0i64;
  v8 = *(_SUBSECTION **)(v1 + 72);
  ControlArea = v8->ControlArea;
  v10 = v0 + ((__int64)(*(_QWORD *)(v1 + 80) - (unsigned __int64)v8->SubsectionBase) >> 3) - v6;
  if( !v8->ControlArea->FilePointer.Value )
  {
    if( (ControlArea->u.LongFlags & 0x1000) != 0 || v8->u1.e1._bf_0 >= 0x40000000u )
    {
      v18 = 0x100000i64;
      if( v8->u1.e1._bf_0 >= 0x40000000u )
        v18 = 0x200000i64;
      v19 = v18 >> 3;
      if( v19 == 0x20000 )
      {
        v20 = v10 >> 17;
        v21 = v10 & 0x1FFFF;
      }
      else
      {
        v20 = v10 / v19;
        v21 = v10 % v19;
      }
      v22 = (unsigned int)v20 + 1i64;
      if( !v21 )
        v22 = (unsigned int)v20;
      if( v22 > ControlArea->u2.FlushInProgressCount )
        return;
      v8 = (_SUBSECTION *)((char *)v8 + 88 * v20);
      if( v21 >= v8->PtesInSubsection )
        return;
    }
    else if( v10 >= v8->PtesInSubsection )
    {
      return;
    }
    if( !v8 )
      return;
    *v4 = v8;
    if( !v8->SubsectionBase )
      return;
    goto LABEL_13;
  }
  PtesInSubsection = v8->PtesInSubsection;
  v12 = 0i64;
  v13 = v0 + ((__int64)(*(_QWORD *)(v1 + 80) - (unsigned __int64)v8->SubsectionBase) >> 3) - v6;
  v14 = *(_SUBSECTION **)(v1 + 72);
  if( v10 < PtesInSubsection )
  {
LABEL_10:
    v15 = v13;
    v8 = v14;
LABEL_11:
    if( v15 >= v8->PtesInSubsection - (v8->_bf_34 & 0x3FFFFFFF) )
      return;
    *v4 = v8;
LABEL_13:
    if( (v8->u.SubsectionFlags._bf_2 & 2) != 0 && (ControlArea->u.LongFlags & 0x4000000) != 0 && (v5 & 2) == 0 )
    {
      SessionId = MmGetSessionIdEx(KeGetCurrentThread()->ApcState.Process);
      MiGetSharedProtos(ControlArea, SessionId, v8);
    }
    return;
  }
  while( 1 )
  {
    v14 = v14->NextSubsection;
    v13 -= PtesInSubsection;
    if( ++v12 == 3 && (ControlArea->u.LongFlags & 0x20) == 0 )
      break;
    if( !v14 )
      break;
    PtesInSubsection = v14->PtesInSubsection;
    if( v13 < PtesInSubsection )
      goto LABEL_10;
  }
  if( (ControlArea->u.LongFlags & 0x20) == 0 )
  {
    v16 = ((v8->StartingSector | ((unsigned __int64)(v8->u.SubsectionFlags._bf_0 & 0xFFC0) << 26)) + v10) << 12;
    if( (v5 & 1) != 0 )
      v7 = 1;
    SubsectionNode = MiLocateSubsectionNode(v8->ControlArea, v16, v7);
    v8 = SubsectionNode;
    if( SubsectionNode )
    {
      v15 = (v16 >> 12)
          - (SubsectionNode->StartingSector | ((unsigned __int64)(SubsectionNode->u.SubsectionFlags._bf_0 & 0xFFC0) << 26));
      goto LABEL_11;
    }
  }
}

Referenced by:

MiCfgMarkValidEntries
MiCheckUserVirtualAddress
MiCloneLargeFileOnlyVad
MiCommitPagefileBackedSection
MiComputeImageVadCommitCharge
MiCountSharedPages
MiDeletePartialCloneVads
MiDeletePartialVad
MiDeleteVad
MiExpandSharedZeroCluster
MiFillMapFileInfo
MiGetClusterPage
MiGetLargeVadMappingIndex
MiGetPageProtection
MiGetWorkingSetInfoList
MiIdealClusterPage
MiIsCfgBitMapPageShared
MiIsRangeFullyCommitted
MiMakePerSessionProtoPte
MiPrepareImagePagesForHotPatch
MiPteNeedsCommitCharge
MiQueryAddressState
MiResolvePageFileFault
MiResolveSharedZeroFault
MiSetProtectionOnSection
MiSetReadOnlyOnSectionView
MiSplitPrivatePage
MiTrimSharedPageFromViews
MiUpControlAreaRefs
MiUpdatePrivateDemandZeroView
MiWalkVaRange
MiZeroFault
MmAccessFault
MmFlushVirtualMemory