CmpQueryEditionVersion

NTSTATUS __fastcall CmpQueryEditionVersion(VOID *a1, void *a2, void *a3){
  INT64 v6; 
  NTSTATUS result; 
  NTSTATUS ValueKey; 
  VOID *v9; 
  VOID *v10; 
  __int64 v11; 
  __int64 v12; 
  __int64 v13; 
  _UNICODE_STRING *v14; 
  NTSTATUS v15; 
  INT64 Length; 
  UINT64 Lengtha; 
  UINT64 Lengthb; 
  UINT64 Lengthc; 
  UINT64 Lengthd; 
  UINT64 Lengthe; 
  UINT64 *ResultLength; 
  INT64 v23; 
  VOID *KeyHandle; 
  _STRING DestinationString; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  int KeyValueInformation[64]; 

  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  LODWORD(v23) = 0;
  *(_DWORD *)(&DestinationString.MaximumLength + 1) = 0;
  memset(KeyValueInformation, 0i64, sizeof(KeyValueInformation));
  memset(a1, 0i64, 0x238u);
  ObjectAttributes.RootDirectory = a2;
  ObjectAttributes.ObjectName = (_UNICODE_STRING *)&CmpEditionVersionString;
  ObjectAttributes.SecurityDescriptor = a3;
  ObjectAttributes.SecurityQualityOfService = 0i64;
  result = ZwOpenKey(&KeyHandle, 1ui64, &ObjectAttributes, v6, Length, (INT64)ResultLength, v23, 0i64);
  if( result >= 0 )
  {
    LODWORD(Lengtha) = 256;
    ValueKey = ZwQueryValueKey(
                 KeyHandle,
                 (_UNICODE_STRING *)&CmpEditionBuildNumberString,
                 KeyValueFullInformation,
                 KeyValueInformation,
                 Lengtha,
                 (UINT64 *)&v23);
    if( ValueKey >= 0 )
    {
      if( KeyValueInformation[1] != 4 )
      {
LABEL_33:
        ValueKey = -1073741788;
        goto LABEL_41;
      }
      if( KeyValueInformation[3] != 4 )
        goto LABEL_34;
      if( (unsigned int)KeyValueInformation[2] + 4i64 != (unsigned int)v23 )
        goto LABEL_35;
      v9 = KeyHandle;
      *(_DWORD *)a1 = *(int *)((char *)KeyValueInformation + (unsigned int)KeyValueInformation[2]);
      LODWORD(Lengthb) = 256;
      ValueKey = ZwQueryValueKey(
                   v9,
                   (_UNICODE_STRING *)&CmpEditionBuildQfeString,
                   KeyValueFullInformation,
                   KeyValueInformation,
                   Lengthb,
                   (UINT64 *)&v23);
      if( ValueKey >= 0 )
      {
        if( KeyValueInformation[1] == 4 )
        {
          if( KeyValueInformation[3] != 4 )
            goto LABEL_34;
          if( (unsigned int)KeyValueInformation[2] + 4i64 != (unsigned int)v23 )
            goto LABEL_35;
          v10 = KeyHandle;
          *((_DWORD *)a1 + 1) = *(int *)((char *)KeyValueInformation + (unsigned int)KeyValueInformation[2]);
          LODWORD(Lengthc) = 256;
          if( ZwQueryValueKey(
                 v10,
                 (_UNICODE_STRING *)&CmpEditionBuildBranchString,
                 KeyValueFullInformation,
                 KeyValueInformation,
                 Lengthc,
                 (UINT64 *)&v23) >= 0
            && KeyValueInformation[1] == 1 )
          {
            if( KeyValueInformation[2] + KeyValueInformation[3] != (_DWORD)v23 )
              goto LABEL_35;
            if( (KeyValueInformation[3] & 1) != 0 )
              goto LABEL_34;
            v11 = (unsigned int)KeyValueInformation[3];
            if( (unsigned __int64)(unsigned int)KeyValueInformation[3] + 2 > 0x80 )
              goto LABEL_36;
            memmove(
              (char *)a1 + 56,
              (char *)KeyValueInformation + (unsigned int)KeyValueInformation[2],
              KeyValueInformation[3]);
            *(_WORD *)((char *)a1 + v11 + 56) = 0;
            RtlInitUnicodeString((PUNICODE_STRING)((char *)a1 + 8), (PCWSTR)a1 + 28);
          }
          LODWORD(Lengthd) = 256;
          if( ZwQueryValueKey(
                 KeyHandle,
                 (_UNICODE_STRING *)&CmpEditionBuildLabString,
                 KeyValueFullInformation,
                 KeyValueInformation,
                 Lengthd,
                 (UINT64 *)&v23) < 0
            || KeyValueInformation[1] != 1 )
          {
LABEL_22:
            LODWORD(Lengthe) = 256;
            if( ZwQueryValueKey(
                   KeyHandle,
                   (_UNICODE_STRING *)&CmpEditionBuildLabExString,
                   KeyValueFullInformation,
                   KeyValueInformation,
                   Lengthe,
                   (UINT64 *)&v23) < 0
              || KeyValueInformation[1] != 1 )
            {
LABEL_28:
              *(_DWORD *)&DestinationString.Length = 0x800000;
              DestinationString.Buffer = (char *)a1 + 440;
              if( *((_QWORD *)a1 + 6) && (v14 = (_UNICODE_STRING *)((char *)a1 + 40), *((_WORD *)a1 + 20))
                || *((_QWORD *)a1 + 4) && (v14 = (_UNICODE_STRING *)((char *)a1 + 24), *((_WORD *)a1 + 12)) )
              {
                v15 = RtlUnicodeStringToAnsiString(&DestinationString, v14, 0);
              }
              else
              {
                v15 = -2147483614;
              }
              if( v15 < 0 )
                *((_BYTE *)a1 + 440) = 0;
              ValueKey = 0;
              goto LABEL_41;
            }
            if( KeyValueInformation[2] + KeyValueInformation[3] == (_DWORD)v23 )
            {
              if( (KeyValueInformation[3] & 1) == 0 )
              {
                v13 = (unsigned int)KeyValueInformation[3];
                if( (unsigned __int64)(unsigned int)KeyValueInformation[3] + 2 <= 0x80 )
                {
                  memmove(
                    (char *)a1 + 312,
                    (char *)KeyValueInformation + (unsigned int)KeyValueInformation[2],
                    KeyValueInformation[3]);
                  *(_WORD *)((char *)a1 + v13 + 312) = 0;
                  RtlInitUnicodeString((PUNICODE_STRING)((char *)a1 + 40), (PCWSTR)a1 + 156);
                  goto LABEL_28;
                }
                goto LABEL_36;
              }
              goto LABEL_34;
            }
LABEL_35:
            ValueKey = -1073741764;
            goto LABEL_41;
          }
          if( KeyValueInformation[2] + KeyValueInformation[3] != (_DWORD)v23 )
            goto LABEL_35;
          if( (KeyValueInformation[3] & 1) == 0 )
          {
            v12 = (unsigned int)KeyValueInformation[3];
            if( (unsigned __int64)(unsigned int)KeyValueInformation[3] + 2 <= 0x80 )
            {
              memmove(
                (char *)a1 + 184,
                (char *)KeyValueInformation + (unsigned int)KeyValueInformation[2],
                KeyValueInformation[3]);
              *(_WORD *)((char *)a1 + v12 + 184) = 0;
              RtlInitUnicodeString((PUNICODE_STRING)((char *)a1 + 24), (PCWSTR)a1 + 92);
              goto LABEL_22;
            }
LABEL_36:
            ValueKey = -1073741789;
            goto LABEL_41;
          }
LABEL_34:
          ValueKey = -1073741306;
          goto LABEL_41;
        }
        goto LABEL_33;
      }
    }
LABEL_41:
    ZwClose((_HANDLE)KeyHandle);
    return ValueKey;
  }
  return result;
}

Referenced by:

CmpSetVersionData