MiGetPhysicalMemoryRanges

INT64 __stdcall MiGetPhysicalMemoryRanges(_MI_PARTITION *Partition, INT8 a2){
  _ETHREAD *CurrentThread; 
  __int64 v3; 
  int v6; 
  PHYSICAL_MEMORY_DESCRIPTOR *v7; 
  _PHYSICAL_MEMORY_DESCRIPTOR *v8; 
  unsigned __int64 v9; 
  UINT8 *v10; 
  INT64 v11; 
  INT64 v12; 
  INT64 v13; 
  unsigned __int64 *p_PageCount; 
  unsigned __int64 v15; 
  __int64 v17; 
  CHAR *FileOnlyRanges; 
  UINT64 v19; 
  char v20; 
  __int64 a3; 
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v3 = 0i64;
  v20 = 0;
  v6 = a2 & 1;
  if( (a2 & 1) != 0 || Partition != (_MI_PARTITION *)&MiSystemPartition )
  {
    v20 = 1;
    MiLockDynamicMemoryShared((INT64)Partition, (INT64)CurrentThread);
    if( Partition != (_MI_PARTITION *)&MiSystemPartition )
    {
      while( *((_QWORD *)Partition + 866) && !*((_QWORD *)Partition + 12) )
      {
        MiUnlockDynamicMemoryShared((INT64)Partition, (INT64)CurrentThread);
        MiLockDynamicMemoryExclusive((__int64)Partition, (__int64)CurrentThread);
        v17 = *((_QWORD *)Partition + 866);
        if( v17 )
        {
          if( !*((_QWORD *)Partition + 12) )
          {
            MiMakePartitionMemoryBlock(Partition);
            v17 = *((_QWORD *)Partition + 866);
          }
          if( v17 && !*((_QWORD *)Partition + 12) )
          {
            MiUnlockDynamicMemoryExclusive(Partition, CurrentThread);
            return 0i64;
          }
        }
        MiUnlockDynamicMemoryExclusive(Partition, CurrentThread);
        MiLockDynamicMemoryShared((INT64)Partition, (INT64)CurrentThread);
      }
    }
  }
  v7 = MiReferencePageRuns(Partition, 0i64);
  v8 = v7;
  if( v7 )
    v9 = v7->NumberOfRuns & (unsigned __int64)-(__int64)(*((_QWORD *)Partition + 866) != 0i64);
  else
    v9 = 0i64;
  a3 = 0i64;
  v10 = 0i64;
  if( v6 )
  {
    FileOnlyRanges = MiGetFileOnlyRanges((INT16 *)Partition, a2, &a3);
    v3 = a3;
    v10 = (UINT8 *)FileOnlyRanges;
  }
  LODWORD(v11) = MiAllocatePool((struct _SLIST_ENTRY *)0x40);
  v12 = v11;
  if( v11 )
  {
    v13 = v11;
    if( v9 )
    {
      p_PageCount = &v8->Run[0].PageCount;
      do
      {
        *(_QWORD *)v13 = *(p_PageCount - 1) << 12;
        v15 = *p_PageCount;
        p_PageCount += 2;
        *(_QWORD *)(v13 + 8) = v15 << 12;
        v13 += 16i64;
        --v9;
      }
      while( v9 );
    }
    if( v3 )
    {
      v19 = 16 * v3;
      memmove((UINT8 *)v13, v10, v19);
      v13 += v19;
    }
    *(_QWORD *)v13 = 0i64;
    *(_QWORD *)(v13 + 8) = 0i64;
  }
  if( v20 )
    MiUnlockDynamicMemoryShared((INT64)Partition, (INT64)CurrentThread);
  if( v8 )
    MiDereferencePageRuns(v8);
  if( v10 )
    ExFreePoolWithTag(v10, 0);
  return v12;
}

Referenced by:

MmGetPhysicalMemoryRangesEx2