IopQuerySecureDeviceClassState

NTSTATUS __stdcall IopQuerySecureDeviceClassState(HANDLE KeyHandle){
  __int64 v1; 
  __int64 v2; 
  void *v4; 
  NTSTATUS RegistryValue; 
  PVOID v6; 
  int SecurityDescriptorInformation; 
  NTSTATUS v8; 
  NTSTATUS v9; 
  NTSTATUS v10; 
  void *v12; 
  char *v13; 
  __int64 v14; 
  int v15; 
  char *v16; 
  __int64 v17; 
  int v18; 
  char *v19; 
  __int64 v20; 
  int v21; 
  void *SecurityDescriptor[2]; 
  PVOID P; 
  *(_OWORD *)v1 = 0i64;
  *(_QWORD *)(v1 + 16) = 0i64;
  v2 = v1;
  SecurityDescriptor[0] = 0i64;
  P = 0i64;
  v4 = 0i64;
  RegistryValue = IopGetRegistryValue(KeyHandle, (PWCHAR)L"Security", 0i64, (KEY_VALUE_FULL_INFORMATION **)&P);
  v6 = P;
  SecurityDescriptorInformation = RegistryValue;
  if( RegistryValue < 0 )
  {
    if( RegistryValue != -1073741772 )
      goto LABEL_22;
    SecurityDescriptorInformation = 0;
    goto LABEL_7;
  }
  if( *((_DWORD *)P + 1) == 3 )
  {
    SecurityDescriptorInformation = SeCaptureSecurityDescriptor(
                                      (char *)P + *((unsigned int *)P + 2),
                                      0,
                                      PagedPool,
                                      1u,
                                      SecurityDescriptor);
    if( SecurityDescriptorInformation < 0 )
    {
      v4 = SecurityDescriptor[0];
      goto LABEL_20;
    }
    ExFreePoolWithTag(v6, 0);
    v4 = SecurityDescriptor[0];
    v6 = 0i64;
    P = 0i64;
    if( SecurityDescriptor[0] )
    {
      SecurityDescriptorInformation = IopGetSecurityDescriptorInformation(SecurityDescriptor[0]);
      if( SecurityDescriptorInformation < 0 )
        goto LABEL_20;
      *(_DWORD *)v2 |= 2u;
      *(_QWORD *)(v2 + 8) = v4;
      v4 = 0i64;
    }
LABEL_7:
    if( (*(_DWORD *)v2 & 1) == 0 )
    {
      v8 = IopGetRegistryValue(KeyHandle, (PWCHAR)L"DeviceType", 0i64, (KEY_VALUE_FULL_INFORMATION **)&P);
      SecurityDescriptorInformation = v8;
      if( v8 >= 0 )
      {
        v13 = (char *)P;
        if( *((_DWORD *)P + 1) == 4 && *((_DWORD *)P + 3) == 4 )
        {
          v14 = *((unsigned int *)P + 2);
          *(_DWORD *)v2 |= 1u;
          v15 = *(_DWORD *)&v13[v14];
        }
        else
        {
          v15 = 0;
        }
        *(_DWORD *)(v2 + 4) = v15;
        ExFreePoolWithTag(v13, 0);
        v6 = 0i64;
        P = 0i64;
      }
      else
      {
        if( v8 != -1073741772 )
          goto LABEL_19;
        v6 = P;
      }
    }
    if( (*(_DWORD *)v2 & 4) != 0 )
    {
LABEL_15:
      if( (*(_DWORD *)v2 & 8) != 0 )
        goto LABEL_20;
      v10 = IopGetRegistryValue(KeyHandle, (PWCHAR)L"Exclusive", 0i64, (KEY_VALUE_FULL_INFORMATION **)&P);
      SecurityDescriptorInformation = v10;
      if( v10 < 0 )
      {
        if( v10 == -1073741772 )
          SecurityDescriptorInformation = 0;
        goto LABEL_19;
      }
      v19 = (char *)P;
      if( *((_DWORD *)P + 1) == 4 && *((_DWORD *)P + 3) == 4 )
      {
        v20 = *((unsigned int *)P + 2);
        *(_DWORD *)v2 |= 8u;
        v21 = *(_DWORD *)&v19[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(KeyHandle, (PWCHAR)L"DeviceCharacteristics", 0i64, (KEY_VALUE_FULL_INFORMATION **)&P);
    SecurityDescriptorInformation = v9;
    if( v9 >= 0 )
    {
      v16 = (char *)P;
      if( *((_DWORD *)P + 1) == 4 && *((_DWORD *)P + 3) == 4 )
      {
        v17 = *((unsigned int *)P + 2);
        *(_DWORD *)v2 |= 4u;
        v18 = *(_DWORD *)&v16[v17];
      }
      else
      {
        v18 = 0;
      }
      *(_DWORD *)(v2 + 16) = v18;
      ExFreePoolWithTag(v16, 0);
      v6 = 0i64;
      P = 0i64;
      goto LABEL_15;
    }
    if( v9 == -1073741772 )
    {
      v6 = P;
      goto LABEL_15;
    }
LABEL_19:
    v6 = P;
    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