ObpGetObjectSecurity

NTSTATUS __stdcall ObpGetObjectSecurity(
        VOID *Object,
        VOID **SecurityDescriptor,
        UINT8 *MemoryAllocated,
        INT8 AccessMode){
  __int64 v8; 
  VOID **PoolWithTag; 
  NTSTATUS v11; 
  int v12; 
  UINT64 v13; 
  VOID **v14; 
  int v15; 
  int v16[4]; 
  UINT64 NumberOfBytes; 

  v8 = ObTypeIndexTable[(unsigned __int8)ObHeaderCookie ^ (unsigned __int8)*((char *)Object - 24) ^ (unsigned __int64)(unsigned __int8)((unsigned __int16)((_WORD)Object - 48) >> 8)];
  if( *(NTSTATUS(__stdcall **)(VOID *, _SECURITY_OPERATION_CODE, UINT64 *, VOID *, UINT64 *, VOID **, POOL_TYPE, _GENERIC_MAPPING *, INT8))(v8 + 152) == SeDefaultObjectMethod )
  {
    *SecurityDescriptor = ObpReferenceSecurityDescriptor((_OBJECT_HEADER *)((char *)Object - 48));
    *MemoryAllocated = 0;
    if( *SecurityDescriptor || (*(_BYTE *)(v8 + 66) & 8) == 0 && (*((char *)Object - 22) & 2) == 0 )
      return 0;
LABEL_17:
    KeBugCheckEx(0x189u, (char *)Object - 48, (PVOID)v8, (PVOID)1, 0i64);
  }
  v16[0] = 447;
  LODWORD(NumberOfBytes) = ObpDefaultSecurityDescriptorLength;
  PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)ObpDefaultSecurityDescriptorLength, 1901290063i64);
  *SecurityDescriptor = PoolWithTag;
  if( !PoolWithTag )
    return -1073741670;
  *MemoryAllocated = 1;
  v11 = (*(__int64(__fastcall **)(VOID *, __int64, int *, VOID *, UINT64 *, char *, _DWORD, __int64, INT8))(v8 + 152))(
          Object,
          1i64,
          v16,
          *SecurityDescriptor,
          &NumberOfBytes,
          (char *)Object - 8,
          *(_DWORD *)(v8 + 100),
          v8 + 76,
          AccessMode);
  if( v11 == -1073741789 )
  {
    ExFreePoolWithTag(*SecurityDescriptor, 0);
    v12 = NumberOfBytes;
    v13 = (unsigned int)NumberOfBytes;
    *MemoryAllocated = 0;
    LODWORD(ObpDefaultSecurityDescriptorLength) = v12;
    v14 = ExAllocatePoolWithTag(1ui64, v13, 1901290063i64);
    *SecurityDescriptor = v14;
    if( v14 )
    {
      *MemoryAllocated = 1;
      LOBYTE(v15) = AccessMode;
      v11 = (*(__int64(__fastcall **)(VOID *, __int64, int *, VOID *, UINT64 *, char *, _DWORD, __int64, int))(v8 + 152))(
              Object,
              1i64,
              v16,
              *SecurityDescriptor,
              &NumberOfBytes,
              (char *)Object - 8,
              *(_DWORD *)(v8 + 100),
              v8 + 76,
              v15);
      goto LABEL_6;
    }
    return -1073741670;
  }
LABEL_6:
  if( v11 < 0 )
  {
    ExFreePoolWithTag(*SecurityDescriptor, 0);
    *MemoryAllocated = 0;
  }
  else if( !*SecurityDescriptor && ((*(_BYTE *)(v8 + 66) & 8) != 0 || (*((char *)Object - 22) & 2) != 0) )
  {
    goto LABEL_17;
  }
  return v11;
}

Referenced by:

EtwpCheckCurrentUserProcessAccess
MiAllowImageMap
ObCheckCreateObjectAccess
ObCheckObjectAccess
ObGetObjectSecurity
ObpCheckObjectReference
ObpCheckTraverseAccess
ObpInsertOrLocateNamedObject
PopBootStatAccessCheck
PspAllocateAndQueryNotificationChannel
PspCheckJobAccessState
SepAppendAceToTokenObjectAcl