PiDevCfgConfigureSoftwareDevices

NTSTATUS __stdcall PiDevCfgConfigureSoftwareDevices(
        VOID *DeviceInstanceKeyHandle,
        VOID *ConfigurationKeyHandle,
        INT64 a3,
        INT64 a4,
        INT64 a5,
        INT64 a6,
        INT64 a7,
        INT64 a8){
  NTSTATUS v9; 
  NTSTATUS v10; 
  NTSTATUS v12; 
  VOID *v13; 
  VOID **PoolWithTag; 
  unsigned int v15; 
  __int64 v16; 
  VOID *v17; 
  __int64 v18; 
  VOID *v19; 
  INT64 CreateOptions; 
  UINT64 CreateOptionsa; 
  UINT64 CreateOptionsb; 
  UINT64 CreateOptionsc; 
  UINT64 *Disposition; 
  INT64 v25; 
  INT64 v26; 
  _UNICODE_STRING KeyName; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  UINT64 ResultLength; 
  VOID *KeyHandle; 
  PVOID Handle; 

  ObjectAttributes.RootDirectory = ConfigurationKeyHandle;
  Handle = 0i64;
  LODWORD(ResultLength) = 0;
  KeyHandle = 0i64;
  ObjectAttributes.ObjectName = &KeyName;
  KeyName.Buffer = (wchar_t *)L"Devices";
  *(_QWORD *)&KeyName.Length = 1048590i64;
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  v9 = ZwOpenKey(&KeyHandle, 0x20019ui64, &ObjectAttributes, a4, CreateOptions, (INT64)Disposition, v25, v26);
  v10 = v9;
  if( v9 == -1073741772 )
  {
    v10 = 0;
  }
  else if( v9 >= 0 )
  {
    LODWORD(CreateOptionsa) = 0;
    *(_DWORD *)&KeyName.Length = 1048590;
    KeyName.Buffer = (wchar_t *)L"Devices";
    v12 = IopCreateRegistryKeyEx(&Handle, DeviceInstanceKeyHandle, &KeyName, 0xF003Fui64, CreateOptionsa, 0i64);
    v13 = Handle;
    v10 = v12;
    if( v12 >= 0 )
    {
      PoolWithTag = ExAllocatePoolWithTag(1ui64, 0x220ui64, 1667526736i64);
      if( PoolWithTag )
      {
        LODWORD(CreateOptionsb) = 544;
        v15 = 0;
        v10 = ZwEnumerateKey(KeyHandle, 0i64, KeyBasicInformation, PoolWithTag, CreateOptionsb, &ResultLength);
        if( v10 < 0 )
        {
LABEL_21:
          if( v10 == -2147483622 )
          {
            v10 = 0;
          }
          else if( v10 == -2147483643 )
          {
            v10 = -1073741773;
          }
        }
        else
        {
          while( 1 )
          {
            *((_WORD *)PoolWithTag + ((unsigned __int64)*((unsigned int *)PoolWithTag + 3) >> 1) + 8) = 0;
            if( *(&stru_140CF2E80 + 607) && (v16 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64)) != 0 )
              v17 = *(VOID **)(v16 + 8);
            else
              v17 = 0i64;
            RegRtlDeleteTreeInternal(v13, (WCHAR *)PoolWithTag + 8, v17, 0);
            if( *(&stru_140CF2E80 + 607) && (v18 = *(_QWORD *)(*(&stru_140CF2E80 + 607) + 224i64)) != 0 )
              v19 = *(VOID **)(v18 + 8);
            else
              v19 = 0i64;
            v10 = RegRtlCopyTreeInternal(
                    KeyHandle,
                    (const WCHAR *)PoolWithTag + 8,
                    v13,
                    (const WCHAR *)PoolWithTag + 8,
                    0,
                    v19,
                    0);
            if( v10 < 0 )
              break;
            ++v15;
            LODWORD(CreateOptionsc) = 544;
            v10 = ZwEnumerateKey(KeyHandle, v15, KeyBasicInformation, PoolWithTag, CreateOptionsc, &ResultLength);
            if( v10 < 0 )
              goto LABEL_21;
          }
        }
        ExFreePoolWithTag(PoolWithTag, 0);
      }
      else
      {
        v10 = -1073741670;
      }
    }
    if( v13 )
      ZwClose((_HANDLE)v13);
  }
  if( KeyHandle )
    ZwClose((_HANDLE)KeyHandle);
  return v10;
}

Referenced by:

PiDevCfgConfigureDeviceKeys