SepReferenceTokenUsingPseudoHandle

NTSTATUS __stdcall SepReferenceTokenUsingPseudoHandle(
        PVOID TokenHandle,
        PVOID *Token,
        BYTE *UseNewTrust,
        PVOID *TrustLevelSid){
  _ETHREAD *CurrentThread; 
  struct _DMA_ADAPTER *v8; 
  PVOID v9; 
  PVOID v10; 
  void *v11; 
  _SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; 
  _TOKEN_TYPE TokenType[13]; 
  _PS_PROTECTION ProcessProtection; 
  BOOL EffectiveOnly; 
  UINT8 pbDominate; 
  BYTE v18; 
  LOBYTE(EffectiveOnly) = 0;
  *Token = 0i64;
  *UseNewTrust = 0;
  *TrustLevelSid = 0i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  ImpersonationLevel = SecurityAnonymous;
  TokenType[0] = 0;
  ProcessProtection.Level = 0;
  if( TokenHandle == (PVOID)-4i64 )
  {
    *Token = PsReferencePrimaryToken(*((PEPROCESS *)CurrentThread + 23));
    return 0;
  }
  if( TokenHandle == (PVOID)-5i64 )
  {
    v8 = (struct _DMA_ADAPTER *)PsReferenceImpersonationTokenEx(
                                  (INT64)CurrentThread,
                                  0,
                                  &v18,
                                  &EffectiveOnly,
                                  (INT64 *)&ImpersonationLevel,
                                  &ProcessProtection.Level);
    if( !v8 )
      return -1073741700;
  }
  else
  {
    v8 = (struct _DMA_ADAPTER *)PsReferenceEffectiveToken(
                                  CurrentThread,
                                  TokenType,
                                  (UINT8 *)&EffectiveOnly,
                                  &ImpersonationLevel,
                                  &ProcessProtection);
    if( TokenType[0] != TokenImpersonation )
      goto LABEL_7;
  }
  if( ImpersonationLevel == SecurityAnonymous )
  {
    HalPutDmaAdapter(v8);
    return -1073741658;
  }
LABEL_7:
  *UseNewTrust = 0;
  *TrustLevelSid = 0i64;
  pbDominate = 0;
  v9 = SepSidFromProcessProtection(&ProcessProtection);
  RtlSidDominatesForTrust(v9, v10, &pbDominate);
  if( !pbDominate )
  {
    *UseNewTrust = 1;
    *TrustLevelSid = v9;
  }
  *Token = v11;
  return 0;
}

Referenced by:

SepReferenceTokenByHandle