CmpCreateHwProfileFriendlyName

INT64 __stdcall CmpCreateHwProfileFriendlyName(
        PVOID IDConfigDB,
        UINT64 DockingState,
        UINT64 NewProfileNumber,
        UNICODE_STRING *FriendlyName){
  unsigned int v7; 
  const WCHAR *v8; 
  WCHAR v9; 
  unsigned __int16 Length; 
  wchar_t *Buffer; 
  NTSTATUS v12; 
  int v13; 
  PULONG ResultLength; 
  unsigned int Data; 
  void *KeyHandle; 
  ULONG v17; 
  struct _UNICODE_STRING DestinationString; 
  struct _UNICODE_STRING UnicodeString; 
  struct _STRING SourceString; 
  struct _UNICODE_STRING v21; 
  struct _OBJECT_ATTRIBUTES ObjectAttributes; 
  wchar_t Dst[80]; 
  int KeyValueInformation[64]; 
  v17 = 0;
  Data = 0;
  KeyHandle = 0i64;
  SourceString = 0i64;
  UnicodeString = 0i64;
  DestinationString = 0i64;
  v21 = 0i64;
  memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
  if( !FriendlyName )
    return 3221225485i64;
  if( IDConfigDB )
  {
    if( (DockingState & 3) == 3 )
      goto LABEL_9;
    if( (DockingState & 2) != 0 )
    {
      v7 = 1073807362;
      v8 = L"Docked";
      goto LABEL_10;
    }
    if( (DockingState & 1) == 0 )
    {
LABEL_9:
      v7 = 1073807363;
      v8 = L"Unknown";
    }
    else
    {
      v7 = 1073807361;
      v8 = L"Undocked";
    }
LABEL_10:
    RtlInitUnicodeString(&DestinationString, v8, NewProfileNumber);
    if( KeGetBugMessageText(v7, &SourceString) && RtlAnsiStringToUnicodeString(&UnicodeString, &SourceString, 1u) >= 0 )
    {
      Length = UnicodeString.Length;
      Buffer = UnicodeString.Buffer;
      if( UnicodeString.Length > 4u )
      {
        Length = UnicodeString.Length - 4;
        UnicodeString.Length = Length;
        UnicodeString.Buffer[(unsigned __int64)Length >> 1] = 0;
      }
      if( (unsigned __int64)Length + 12 <= 0xA0 )
      {
        RtlInitUnicodeString(&v21, L"Hardware Profiles", v9);
        ObjectAttributes.Length = 48;
        ObjectAttributes.ObjectName = &v21;
        ObjectAttributes.RootDirectory = IDConfigDB;
        ObjectAttributes.Attributes = 576;
        *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
        v12 = ZwOpenKey(&KeyHandle, 0x20019u, &ObjectAttributes);
        if( v12 >= 0 )
        {
          if( ZwQueryValueKey(
                 KeyHandle,
                 &DestinationString,
                 KeyValueFullInformation,
                 KeyValueInformation,
                 0x100u,
                 &v17) >= 0
            && KeyValueInformation[1] == 4 )
          {
            v13 = *(int *)((char *)KeyValueInformation + (unsigned int)KeyValueInformation[2]) + 1;
          }
          else
          {
            v13 = 1;
          }
          Data = v13;
          LODWORD(ResultLength) = 4;
          v12 = ZwSetValueKey(KeyHandle, &DestinationString, 0i64, 4ui64, &Data, (UINT64)ResultLength);
          if( v12 >= 0 )
          {
            if( v7 == 1073807363 || Data > 1 )
              swprintf_s(Dst, 0x50ui64, (WCHAR *)L"%s %u");
            else
              wcscpy_s(Dst, 0x50ui64, Buffer);
          }
        }
        else
        {
          KeyHandle = 0i64;
        }
      }
      else
      {
        v12 = -1073741823;
      }
      RtlFreeAnsiString(&UnicodeString);
      if( KeyHandle )
        ZwClose(KeyHandle);
      if( v12 >= 0 )
        goto LABEL_31;
    }
  }
  Dst[0] = 0;
  swprintf_s(Dst, 0x50ui64, (WCHAR *)L"%04d");
  v12 = 0;
LABEL_31:
  if( !RtlCreateUnicodeString(FriendlyName, Dst) )
    return(unsigned int)-1073741823;
  return(unsigned int)v12;
}

Referenced by:

CmpCloneHwProfile