CmpInitializeRegistryNode

INT64 __stdcall CmpInitializeRegistryNode(
        _CONFIGURATION_COMPONENT_DATA *CurrentEntry,
        PVOID ParentHandle,
        PVOID *NewHandle,
        _INTERFACE_TYPE InterfaceType,
        UINT64 BusNumber,
        UINT16 *DeviceIndexTable){
  unsigned int v9; 
  _CONFIGURATION_TYPE Type; 
  INT64 result; 
  __int64 v12; 
  UINT16 v13; 
  _HANDLE v14; 
  NTSTATUS v15; 
  NTSTATUS v16; 
  void *ConfigurationData; 
  _DWORD *v18; 
  unsigned int ConfigurationDataLength; 
  char *v20; 
  VOID **PoolWithTag; 
  _UNICODE_STRING *Class; 
  UINT64 CreateOptions; 
  UINT64 CreateOptionsa; 
  UINT64 CreateOptionsb; 
  VOID *KeyHandle; 
  UINT64 Disposition; 
  _UNICODE_STRING ValueName; 
  _UNICODE_STRING v29; 
  _STRING DestinationString; 
  _UNICODE_STRING UnicodeString; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  CHAR String[16]; 
  char v34; 

  *(&ObjectAttributes.Length + 1) = 0;
  v9 = 0;
  *(&ObjectAttributes.Attributes + 1) = 0;
  v29 = 0i64;
  KeyHandle = 0i64;
  ValueName = 0i64;
  LODWORD(Disposition) = 0;
  UnicodeString = 0i64;
  DestinationString = 0i64;
  if( CurrentEntry->ComponentEntry.Class )
  {
    Type = CurrentEntry->ComponentEntry.Type;
  }
  else
  {
    CurrentEntry->ComponentEntry.Type = ArcSystem;
    Type = ArcSystem;
  }
  ObjectAttributes.RootDirectory = ParentHandle;
  ObjectAttributes.ObjectName = &CmTypeName + (int)Type;
  ObjectAttributes.Length = 48;
  LODWORD(CreateOptions) = 0;
  ObjectAttributes.Attributes = 576;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  LODWORD(result) = ZwCreateKey(&KeyHandle, 0x2001Fui64, &ObjectAttributes, 0i64, 0i64, CreateOptions, &Disposition);
  if( (int)result >= 0 )
  {
    if( CurrentEntry->ComponentEntry.Class )
    {
      v12 = CurrentEntry->ComponentEntry.Type;
      if( (unsigned int)v12 >= 0x2A )
      {
        v13 = 0;
      }
      else
      {
        v13 = DeviceIndexTable[v12];
        DeviceIndexTable[CurrentEntry->ComponentEntry.Type] = v13 + 1;
      }
      RtlIntegerToChar(v13, 0xAui64, 0xCu, String);
      RtlInitAnsiString(&DestinationString, String);
      *(_DWORD *)&v29.Length = 1572864;
      v29.Buffer = (wchar_t *)&v34;
      RtlAnsiStringToUnicodeString(&v29, &DestinationString, 0);
      v14 = (int)KeyHandle;
      ObjectAttributes.ObjectName = &v29;
      ObjectAttributes.Length = 48;
      LODWORD(CreateOptionsa) = 0;
      ObjectAttributes.RootDirectory = KeyHandle;
      ObjectAttributes.Attributes = 576;
      *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
      v15 = ZwCreateKey(&KeyHandle, 0x2001Fui64, &ObjectAttributes, 0i64, 0i64, CreateOptionsa, &Disposition);
      ZwClose(v14);
      if( v15 < 0 )
        return(unsigned int)v15;
    }
    RtlInitUnicodeString(&ValueName, L"Component Information");
    LODWORD(CreateOptionsa) = 16;
    v16 = ZwSetValueKey(KeyHandle, &ValueName, 0i64, 3ui64, &CurrentEntry->ComponentEntry.Flags, CreateOptionsa);
    if( v16 < 0 )
      goto LABEL_24;
    if( CurrentEntry->ComponentEntry.IdentifierLength )
    {
      RtlInitUnicodeString(&ValueName, L"Identifier");
      RtlInitAnsiString(&DestinationString, CurrentEntry->ComponentEntry.Identifier);
      v16 = RtlAnsiStringToUnicodeString(&UnicodeString, &DestinationString, 1u);
      if( v16 < 0 )
        goto LABEL_24;
      LODWORD(CreateOptionsb) = UnicodeString.Length + 2;
      v16 = ZwSetValueKey(KeyHandle, &ValueName, 0i64, 1ui64, UnicodeString.Buffer, CreateOptionsb);
      RtlFreeAnsiString(&UnicodeString);
      if( v16 < 0 )
        goto LABEL_24;
    }
    RtlInitUnicodeString(&ValueName, L"Configuration Data");
    ConfigurationData = CurrentEntry->ConfigurationData;
    if( !ConfigurationData )
    {
LABEL_13:
      if( !CurrentEntry->ConfigurationData )
      {
        v9 = 16;
        *((_QWORD *)CmpConfigurationData + 1) = 0i64;
      }
      v18 = CmpConfigurationData;
      LODWORD(CreateOptionsb) = v9;
      Class = (_UNICODE_STRING *)CmpConfigurationData;
      *(_DWORD *)CmpConfigurationData = InterfaceType;
      v18[1] = BusNumber;
      v16 = ZwSetValueKey(KeyHandle, &ValueName, 0i64, 9ui64, Class, CreateOptionsb);
      if( v16 >= 0 )
      {
        *NewHandle = KeyHandle;
        return 0i64;
      }
LABEL_24:
      ZwClose((_HANDLE)KeyHandle);
      return(unsigned int)v16;
    }
    v9 = CurrentEntry->ComponentEntry.ConfigurationDataLength + 8;
    if( v9 > (unsigned int)CmpConfigurationAreaSize )
    {
      PoolWithTag = ExAllocatePoolWithTag(1ui64, v9, 538987843i64);
      if( !PoolWithTag )
      {
        CurrentEntry->ComponentEntry.ConfigurationDataLength = 0;
        CurrentEntry->ConfigurationData = 0i64;
        goto LABEL_13;
      }
      LODWORD(CmpConfigurationAreaSize) = v9;
      ExFreePoolWithTag(CmpConfigurationData, 0);
      ConfigurationDataLength = CurrentEntry->ComponentEntry.ConfigurationDataLength;
      v20 = (char *)(PoolWithTag + 1);
      ConfigurationData = CurrentEntry->ConfigurationData;
      CmpConfigurationData = PoolWithTag;
    }
    else
    {
      ConfigurationDataLength = CurrentEntry->ComponentEntry.ConfigurationDataLength;
      v20 = (char *)CmpConfigurationData + 8;
    }
    memmove(v20, ConfigurationData, ConfigurationDataLength);
    goto LABEL_13;
  }
  return result;
}

Referenced by:

CmLogMcUpdateStatus
CmpAddProcessorConfigurationEntry
CmpSetupConfigurationTree