MmGetSessionMappedViewInformation

NTSTATUS __stdcall MmGetSessionMappedViewInformation(
        VOID *SystemInformation,
        UINT64 SystemInformationLength,
        UINT64 *Length,
        UINT64 *SessionId){
  char *v4; 
  UINT64 *v5; 
  unsigned int v6; 
  NTSTATUS result; 
  __int64 v8; 
  NTSTATUS v9; 
  char *v10; 
  _ADAPTER_OBJECT *i; 
  _EPROCESS *NextSession; 
  _ADAPTER_OBJECT *v13; 
  NTSTATUS v14; 
  unsigned int v15; 
  _MM_SESSION_SPACE *Session; 
  int v17; 
  VOID *LockedBuffer; 
  UINT64 TotalFree; 
  UINT64 ContiguousFree; 
  UINT64 *v21; 
  VOID *LockVariable; 
  UINT64 *v23; 
  _KAPC_STATE ApcState; 

  v4 = 0i64;
  v21 = SessionId;
  LockVariable = 0i64;
  ContiguousFree = 0i64;
  v5 = Length;
  TotalFree = 0i64;
  v6 = SystemInformationLength;
  v23 = Length;
  LockedBuffer = 0i64;
  memset(&ApcState, 0, sizeof(ApcState));
  if( (_DWORD)SystemInformationLength )
  {
    result = ExLockUserBuffer(
               SystemInformation,
               SystemInformationLength,
               KeGetCurrentThread()->PreviousMode,
               IoWriteAccess,
               &LockedBuffer,
               &LockVariable);
    if( result < 0 )
      return result;
    v4 = (char *)LockedBuffer;
  }
LABEL_4:
  *(_DWORD *)v5 = 0;
  LODWORD(v8) = 0;
  v9 = 0;
  v10 = 0i64;
  for( i = 0i64; ; i = v13 )
  {
    NextSession = (_EPROCESS *)MmGetNextSession(i);
    v13 = (_ADAPTER_OBJECT *)NextSession;
    if( !NextSession )
      break;
    v10 = &v4[(unsigned int)v8];
    v14 = MmGetSessionId(NextSession);
    if( *(_DWORD *)v21 == -1 || v14 == *(_DWORD *)v21 )
    {
      if( MmAttachSession(v13, &ApcState) >= 0 )
      {
        v15 = v8 + 32;
        if( (int)v8 + 32 < (unsigned int)v8 )
        {
          MmDetachSession(v13, &ApcState);
          HalPutDmaAdapter(v13);
          v5 = v23;
          goto LABEL_4;
        }
        v8 = v15;
        if( v15 <= v6 )
        {
          Session = KeGetCurrentThread()->ApcState.Process->Session;
          MiGetSystemPteStatistics((_MI_SYSTEM_PTE_TYPE *)((char *)Session + 880), &TotalFree, &ContiguousFree);
          *((_QWORD *)v10 + 2) = TotalFree << 12;
          *((_QWORD *)v10 + 3) = ContiguousFree << 12;
          *((_DWORD *)v10 + 2) = v14;
          v17 = *((_DWORD *)Session + 55);
          v4 = (char *)LockedBuffer;
          *((_DWORD *)v10 + 3) = v17;
          *(_QWORD *)v10 = v8;
        }
        else
        {
          v9 = -1073741820;
        }
        MmDetachSession(v13, &ApcState);
      }
      if( *(_DWORD *)v21 != -1 )
      {
        HalPutDmaAdapter(v13);
        break;
      }
    }
  }
  if( v9 >= 0 && v10 )
    *(_QWORD *)v10 = 0i64;
  if( v4 )
    ExUnlockUserBuffer(LockVariable);
  *(_DWORD *)v23 = v8;
  return v9;
}

Referenced by:

ExpQuerySystemInformation