VfCheckUserHandle

VOID __fastcall VfCheckUserHandle(VOID *Handle){
  _EPROCESS *v2; 
  UINT16 v3; 
  unsigned int v4; 
  __int64 v5; 
  void **v6; 
  PVOID v7; 
  VOID *v8; 
  NTSTATUS v9; 
  struct _DMA_ADAPTER *v10; 
  char v11; 
  UINT64 v12; 
  PVOID Object; 
  UINT64 ReturnLength; 
  void *BackTrace[8]; 
  UNICODE_STRING String1; 
  memset((INT64)BackTrace, 0i64);
  if( (MmVerifierData & 0x100) != 0 )
  {
    v2 = (_EPROCESS *)*((_QWORD *)KeGetCurrentThread() + 23);
    if( PsInitialSystemProcess )
    {
      if( v2 != (_EPROCESS *)PsInitialSystemProcess && v2 != PsIdleProcess )
      {
        if( Handle )
        {
          v3 = RtlCaptureStackBackTrace(2ui64, 8ui64, BackTrace, 0i64);
          v4 = v3;
          v5 = 0i64;
          if( v3 )
          {
            v6 = BackTrace;
            do
            {
              v7 = *v6;
              if( (unsigned int)VfDriverIsKernelImageAddress(*v6) )
              {
                if( (_DWORD)KernelVerifier )
                  break;
              }
              else
              {
                if( (unsigned int)VfTargetDriversIsEnabled(v8) )
                  break;
                if( !ViDriverXDVBase
                  || !ViDriverXDVImageSize
                  || (unsigned __int64)v7 < ViDriverXDVBase
                  || (unsigned __int64)v7 >= ViDriverXDVBase + (unsigned __int64)(unsigned int)ViDriverXDVImageSize )
                {
                  return;
                }
              }
              v5 = (unsigned int)(v5 + 1);
              ++v6;
            }
            while( (unsigned int)v5 < v4 );
            if( (unsigned int)v5 < v4 && !(unsigned int)VfUtilIsLocalSystem(v2) )
            {
              Object = 0i64;
              v9 = ObReferenceObjectByHandle(Handle, 0, 0i64, 1, &Object, 0i64);
              v10 = (struct _DMA_ADAPTER *)Object;
              if( v9 < 0 )
                goto LABEL_25;
              v11 = 0;
              if( (int)ObQueryTypeName(Object, &String1, 0x40ui64, &ReturnLength) >= 0
                && (RtlEqualUnicodeString(&String1, (UNICODE_STRING *)&ViDesktopTypeName, 0)
                 || RtlEqualUnicodeString(&String1, (UNICODE_STRING *)&ViWindowStationTypeName, 0)) )
              {
                v11 = 1;
              }
              HalPutDmaAdapter(v10);
              if( !v11 )
              {
LABEL_25:
                if( ViHandleBreaksEnabled )
                  VerifierBugCheckIfAppropriate(
                    0xC4ui64,
                    0xF6ui64,
                    (UINT64)Handle,
                    (UINT64)v2,
                    (UINT64)BackTrace[v5],
                    v12);
              }
            }
          }
        }
      }
    }
  }
}

Referenced by:

NtClose
ObCloseHandle
ObpReferenceObjectByHandleWithTag