IopQuerySecureDeviceClassState

NTSTATUS __stdcall IopQuerySecureDeviceClassState(_HANDLE KeyHandle){
  __int64 v1; 
  __int64 v2; 
  void *v3; 
  PSECURITY_DESCRIPTOR v4; 
  NTSTATUS RegistryValue; 
  _KEY_VALUE_FULL_INFORMATION *v6; 
  int SecurityDescriptorInformation; 
  NTSTATUS v8; 
  NTSTATUS v9; 
  NTSTATUS v10; 
  void *v12; 
  _KEY_VALUE_FULL_INFORMATION *v13; 
  __int64 DataOffset; 
  int v15; 
  _KEY_VALUE_FULL_INFORMATION *v16; 
  __int64 v17; 
  int v18; 
  _KEY_VALUE_FULL_INFORMATION *v19; 
  __int64 v20; 
  int v21; 
  INT64 v22; 
  PSECURITY_DESCRIPTOR SecurityDescriptor; 
  _KEY_VALUE_FULL_INFORMATION *Information; 

  *(_OWORD *)v1 = 0i64;
  *(_QWORD *)(v1 + 16) = 0i64;
  v2 = v1;
  SecurityDescriptor = 0i64;
  Information = 0i64;
  v3 = *(void **)&KeyHandle;
  v4 = 0i64;
  RegistryValue = IopGetRegistryValue(*(PVOID *)&KeyHandle, (PWCHAR)L"Security", 0i64, &Information);
  v6 = Information;
  SecurityDescriptorInformation = RegistryValue;
  if( RegistryValue < 0 )
  {
    if( RegistryValue != -1073741772 )
      goto LABEL_22;
    SecurityDescriptorInformation = 0;
    goto LABEL_7;
  }
  if( Information->Type == 3 )
  {
    SecurityDescriptorInformation = SeCaptureSecurityDescriptor(
                                      (char *)Information + Information->DataOffset,
                                      0,
                                      PagedPool,
                                      1u,
                                      &SecurityDescriptor,
                                      v22,
                                      (INT64)SecurityDescriptor);
    if( SecurityDescriptorInformation < 0 )
    {
      v4 = SecurityDescriptor;
      goto LABEL_20;
    }
    ExFreePoolWithTag(v6, 0);
    v4 = SecurityDescriptor;
    v6 = 0i64;
    Information = 0i64;
    if( SecurityDescriptor )
    {
      SecurityDescriptorInformation = IopGetSecurityDescriptorInformation(SecurityDescriptor);
      if( SecurityDescriptorInformation < 0 )
        goto LABEL_20;
      *(_DWORD *)v2 |= 2u;
      *(_QWORD *)(v2 + 8) = v4;
      v4 = 0i64;
    }
LABEL_7:
    if( (*(_DWORD *)v2 & 1) == 0 )
    {
      v8 = IopGetRegistryValue(v3, (PWCHAR)L"DeviceType", 0i64, &Information);
      SecurityDescriptorInformation = v8;
      if( v8 >= 0 )
      {
        v13 = Information;
        if( Information->Type == 4 && Information->DataLength == 4 )
        {
          DataOffset = Information->DataOffset;
          *(_DWORD *)v2 |= 1u;
          v15 = *(ULONG *)((char *)&v13->TitleIndex + DataOffset);
        }
        else
        {
          v15 = 0;
        }
        *(_DWORD *)(v2 + 4) = v15;
        ExFreePoolWithTag(v13, 0);
        v6 = 0i64;
        Information = 0i64;
      }
      else
      {
        if( v8 != -1073741772 )
          goto LABEL_19;
        v6 = Information;
      }
    }
    if( (*(_DWORD *)v2 & 4) != 0 )
    {
LABEL_15:
      if( (*(_DWORD *)v2 & 8) != 0 )
        goto LABEL_20;
      v10 = IopGetRegistryValue(v3, (PWCHAR)L"Exclusive", 0i64, &Information);
      SecurityDescriptorInformation = v10;
      if( v10 < 0 )
      {
        if( v10 == -1073741772 )
          SecurityDescriptorInformation = 0;
        goto LABEL_19;
      }
      v19 = Information;
      if( Information->Type == 4 && Information->DataLength == 4 )
      {
        v20 = Information->DataOffset;
        *(_DWORD *)v2 |= 8u;
        v21 = *(ULONG *)((char *)&v19->TitleIndex + v20);
      }
      else
      {
        v21 = 0;
      }
      *(_DWORD *)(v2 + 20) = v21;
      ExFreePoolWithTag(v19, 0);
      v6 = 0i64;
LABEL_20:
      if( v4 )
        ExFreePoolWithTag(v4, 0);
LABEL_22:
      if( SecurityDescriptorInformation >= 0 )
        goto LABEL_23;
      goto LABEL_27;
    }
    v9 = IopGetRegistryValue(v3, (PWCHAR)L"DeviceCharacteristics", 0i64, &Information);
    SecurityDescriptorInformation = v9;
    if( v9 >= 0 )
    {
      v16 = Information;
      if( Information->Type == 4 && Information->DataLength == 4 )
      {
        v17 = Information->DataOffset;
        *(_DWORD *)v2 |= 4u;
        v18 = *(ULONG *)((char *)&v16->TitleIndex + v17);
      }
      else
      {
        v18 = 0;
      }
      *(_DWORD *)(v2 + 16) = v18;
      ExFreePoolWithTag(v16, 0);
      v6 = 0i64;
      Information = 0i64;
      goto LABEL_15;
    }
    if( v9 == -1073741772 )
    {
      v6 = Information;
      goto LABEL_15;
    }
LABEL_19:
    v6 = Information;
    goto LABEL_20;
  }
  SecurityDescriptorInformation = -1073741492;
LABEL_27:
  v12 = *(void **)(v2 + 8);
  if( v12 )
    ExFreePoolWithTag(v12, 0);
  *(_OWORD *)v2 = 0i64;
  *(_QWORD *)(v2 + 16) = 0i64;
LABEL_23:
  if( v6 )
    ExFreePoolWithTag(v6, 0);
  return SecurityDescriptorInformation;
}

Referenced by:

IopCreateSecureDeviceClassSettings