IopCreateDefaultDeviceSecurityDescriptor

VOID *__stdcall IopCreateDefaultDeviceSecurityDescriptor(
        UINT64 DeviceType,
        UINT64 DeviceCharacteristics,
        UINT8 *Buffer,
        _ACL **AllocatedAcl,
        _ACL **AllocatedSacl,
        UINT64 *SecurityInformation,
        UINT64 a7){
  UINT64 *v7; 
  int v9; 
  _ACL **v10; 
  UINT64 v11; 
  NTSTATUS SecurityDescriptorPerType; 
  bool v14; 
  unsigned __int16 AclSize; 
  unsigned __int8 *v16; 
  VOID **PoolWithTag; 
  _ACL *v18; 
  int v19; 

  LOBYTE(v19) = (_BYTE)Buffer;
  v7 = (UINT64 *)a7;
  v9 = DeviceType;
  if( a7 )
    *(_DWORD *)a7 = 0;
  v10 = AllocatedSacl;
  *AllocatedSacl = 0i64;
  if( (unsigned int)DeviceType > 0x14 )
  {
    if( (_DWORD)DeviceType != 45 )
    {
      if( (_DWORD)DeviceType == 32 )
        goto LABEL_10;
      if( (_DWORD)DeviceType != 36 )
      {
        v14 = (_DWORD)DeviceType == 53;
LABEL_18:
        if( !v14 )
          goto LABEL_19;
      }
    }
LABEL_20:
    if( (_DWORD)DeviceType != 7 || (DeviceCharacteristics & 1) == 0 )
      goto LABEL_10;
LABEL_25:
    v19 = 0;
    AclSize = SePublicDefaultUnrestrictedDacl->AclSize;
    if( !RtlGetNtProductType((_NT_PRODUCT_TYPE *)&v19) )
      return 0i64;
    if( v19 == 1 )
    {
      v16 = (unsigned __int8 *)SeInteractiveSid;
    }
    else
    {
      if( v9 != 2 )
      {
LABEL_31:
        PoolWithTag = ExAllocatePoolWithTag(1ui64, AclSize, 1699966793i64);
        v18 = (_ACL *)PoolWithTag;
        if( !PoolWithTag )
          return 0i64;
        memmove(PoolWithTag, SePublicDefaultUnrestrictedDacl, SePublicDefaultUnrestrictedDacl->AclSize);
        v14 = v19 == 1;
        v18->AclSize = AclSize;
        if( v14 )
        {
          RtlpAddKnownAce(v18, 2ui64, 0i64, 0xC0010000ui64, (VOID *)SeInteractiveSid, 0);
        }
        else if( v9 == 2 )
        {
          RtlpAddKnownAce(v18, 2ui64, 0i64, 0x80000000ui64, SeWorldSid, 0);
        }
        RtlCreateSecurityDescriptor(AllocatedAcl, 1ui64);
        RtlSetDaclSecurityDescriptor(AllocatedAcl, 1u, v18, 0);
        if( v7 )
          *(_DWORD *)v7 |= 4u;
        *v10 = v18;
        SecurityDescriptorPerType = 0;
        goto LABEL_12;
      }
      v16 = (unsigned __int8 *)SeWorldSid;
    }
    AclSize += 4 * (v16[1] + 4);
    goto LABEL_31;
  }
  if( (_DWORD)DeviceType == 20 )
    goto LABEL_20;
  if( (_DWORD)DeviceType == 2 )
    goto LABEL_25;
  if( (_DWORD)DeviceType != 3 )
  {
    if( (_DWORD)DeviceType != 7 )
    {
      if( (unsigned int)DeviceType <= 7 )
      {
LABEL_19:
        v11 = 4i64;
        goto LABEL_11;
      }
      if( (unsigned int)DeviceType <= 9 )
        goto LABEL_10;
      v14 = (_DWORD)DeviceType == 18;
      goto LABEL_18;
    }
    goto LABEL_20;
  }
LABEL_10:
  v11 = 2i64;
LABEL_11:
  SecurityDescriptorPerType = IopCreateSecurityDescriptorPerType(AllocatedAcl, v11, (_ACL **)SecurityInformation, v7);
LABEL_12:
  if( SecurityDescriptorPerType >= 0 )
    return AllocatedAcl;
  return 0i64;
}

Referenced by:

IoCreateDevice
PipChangeDeviceObjectFromRegistryProperties