MiAssignSystemVa

NTSTATUS __stdcall MiAssignSystemVa(UINT32 NumberToFind){
  unsigned int v1; 
  UINT8 *v2; 
  unsigned int v3; 
  unsigned int v5; 
  int v6; 
  unsigned __int8 v7; 
  UINT32 ClearBitsAndSet; 
  UINT32 v10; 
  _RTL_BITMAP BitMapHeader; 

  *(&BitMapHeader.SizeOfBitMap + 1) = 0;
  v3 = v1;
  BitMapHeader.SizeOfBitMap = 256;
  BitMapHeader.Buffer = (unsigned int *)((char *)&stru_140C4DB30 + 1128);
  if( NumberToFind <= 2 )
  {
    v7 = ExGenRandom(ExGenRandomDomainUserVisible);
    v6 = 8;
    goto LABEL_7;
  }
  v5 = *(&stru_140C4DB30 + 290);
  v6 = v1 >= 4 ? 0x10 : 0;
  while( 1 )
  {
    ClearBitsAndSet = (unsigned int)RtlFindClearBitsAndSet(
                                      (_RTL_AVL_TABLE *)&BitMapHeader,
                                      (VOID *)NumberToFind,
                                      v5,
                                      v2,
                                      *(VOID **)&BitMapHeader.SizeOfBitMap,
                                      (_TABLE_SEARCH_RESULT)BitMapHeader.Buffer);
    if( ClearBitsAndSet == -1 )
      return 0;
    if( ClearBitsAndSet == v5 || !v6 )
      break;
    --v6;
    RtlClearBits(&BitMapHeader, ClearBitsAndSet, NumberToFind);
    v7 = ExGenRandom(ExGenRandomDomainUserVisible);
LABEL_7:
    v5 = v7;
  }
  v10 = ClearBitsAndSet + NumberToFind;
  if( v3 != 1 )
    v10 = (unsigned __int8)(v10 + (unsigned int)ExGenRandom(ExGenRandomDomainUserVisible) % v3);
  *(&stru_140C4DB30 + 290) = v10;
  return 0;
}

Referenced by:

MiAssignTopLevelRanges