IopInitializeDeviceInstanceKey

VOID __stdcall IopInitializeDeviceInstanceKey(
        VOID *KeyHandle,
        _UNICODE_STRING *DeviceInstancePath,
        VOID *Context,
        INT64 a4){
  int v7; 
  _DEVICE_OBJECT *v8; 
  _ADAPTER_OBJECT *v9; 
  int v10; 
  _DEVICE_OBJECT *v11; 
  _DEVICE_OBJECT *v12; 
  _DEVICE_NODE *v13; 
  _UNICODE_STRING *v14; 
  unsigned int v15; 
  NTSTATUS DeviceRegProp; 
  __int16 v17; 
  int v18; 
  _KEY_VALUE_FULL_INFORMATION *v19; 
  int v20; 
  unsigned int v21; 
  VOID **PoolWithTag; 
  VOID **v23; 
  NTSTATUS FailedInstallProblemStatus; 
  UINT64 v25; 
  _DEVICE_NODE *v26; 
  UINT64 Flags; 
  UINT64 PropertySize; 
  _KEY_VALUE_FULL_INFORMATION *Information; 
  _DEVICE_OBJECT *PhysicalDeviceObject; 
  _DEVICE_NODE *DeviceNode; 
  int PropertyBuffer; 
  UINT64 CmRegPropType; 

  Information = 0i64;
  LODWORD(CmRegPropType) = 0;
  DeviceNode = 0i64;
  if( IopGetRegistryValue(KeyHandle, (PWCHAR)L"Phantom", 0i64, &Information) < 0
    || (Information->Type != 4 || Information->DataLength < 4 ? (v20 = 0) : (v20 = *(ULONG *)((char *)&Information->TitleIndex
                                                                                            + Information->DataOffset)),
        ExFreePoolWithTag(Information, 0),
        !v20) )
  {
    v7 = *((_DWORD *)Context + 1);
    if( *((_DWORD *)Context + 2) == v7 )
    {
      v21 = 8 * v7 + 1024;
      PoolWithTag = ExAllocatePoolWithTag(1ui64, v21, 1684303952i64);
      v23 = PoolWithTag;
      if( !PoolWithTag )
      {
        v10 = -1073741670;
        goto LABEL_67;
      }
      memmove(PoolWithTag, *((const VOID **)Context + 2), 8 * *((_DWORD *)Context + 2));
      ExFreePoolWithTag(*((PVOID *)Context + 2), 0);
      *((_DWORD *)Context + 1) = v21 >> 3;
      *((_QWORD *)Context + 2) = v23;
    }
    v8 = (_DEVICE_OBJECT *)PnpDeviceObjectFromDeviceInstanceWithTag((__int64)DeviceInstancePath, 0x746C6644u);
    PhysicalDeviceObject = v8;
    if( v8 )
    {
      if( !IopIsRootEnumeratedDeviceObjectActive((INT64)v8) )
      {
        HalPutDmaAdapter(v9);
        return;
      }
      *(_QWORD *)(*((_QWORD *)Context + 2) + 8i64 * *((unsigned int *)Context + 2)) = v9;
LABEL_6:
      ++*((_DWORD *)Context + 2);
      return;
    }
    v10 = IopCreateRootEnumeratedDeviceObject(&PhysicalDeviceObject);
    if( v10 >= 0 )
    {
      v11 = PhysicalDeviceObject;
      v12 = PhysicalDeviceObject;
      PhysicalDeviceObject->Flags |= 0x1000u;
      v12->DeviceObjectExtension->ExtensionFlags |= 0x10u;
      if( PipAllocateDeviceNode(v12, (PDEVICE_NODE *)&DeviceNode) == -1073740946 || (v13 = DeviceNode) == 0i64 )
      {
        IoDeleteDevice(v11);
        v10 = -1073741670;
      }
      else
      {
        v10 = PnpAllocateDeviceInstancePath((__int64)DeviceNode, (unsigned int)DeviceInstancePath->Length + 2);
        if( v10 >= 0 )
        {
          PnpCopyDeviceInstancePath((__int64)v13, DeviceInstancePath, v14);
          PipSetDevNodeFlags(v13, 0x11ui64);
          PipSetDevNodeState(v13, DeviceNodeInitialized);
          PpDevNodeInsertIntoTree(*(&PnpReplaceEvent + 831), v13);
          ObfReferenceObject(v11);
          v15 = 0;
          LODWORD(PropertySize) = 4;
          LODWORD(Flags) = 0;
          PropertyBuffer = 0;
          DeviceRegProp = CmGetDeviceRegProp(
                            *(&stru_140CF2E80 + 607),
                            v13->InstancePath.Buffer,
                            KeyHandle,
                            11i64,
                            &CmRegPropType,
                            (UINT8 *)&PropertyBuffer,
                            &PropertySize,
                            Flags);
          if( DeviceRegProp < 0 )
          {
            FailedInstallProblemStatus = -1073741275;
            if( DeviceRegProp != -1073741275 )
              goto LABEL_18;
            v25 = 1i64;
          }
          else
          {
            if( (_DWORD)CmRegPropType == 4 && (_DWORD)PropertySize == 4 )
            {
              v17 = PropertyBuffer;
            }
            else
            {
              v17 = 0;
              PropertyBuffer = 0;
            }
            if( (v17 & 0x20) != 0 )
            {
              FailedInstallProblemStatus = 0;
              v25 = 18i64;
            }
            else if( (v17 & 0x2000) != 0 )
            {
              FailedInstallProblemStatus = 0;
              v25 = 16i64;
            }
            else
            {
              if( (v17 & 0x40) == 0 )
              {
LABEL_18:
                if( IopGetRegistryValue(KeyHandle, (PWCHAR)L"NoResourceAtInitTime", 0i64, &Information) >= 0 )
                {
                  v19 = Information;
                  if( Information->Type == 4
                    && Information->DataLength >= 4
                    && *(ULONG *)((char *)&Information->TitleIndex + Information->DataOffset) )
                  {
                    PipSetDevNodeFlags(v13, 0x100ui64);
                  }
                  ExFreePoolWithTag(v19, 0);
                }
                PnpQueryAndSaveDeviceNodeCapabilities((__int64)v13);
                if( (v13->CapabilityFlags & 0x4000) != 0 && ((v13->Flags & 0x2000) == 0 || v13->Problem != 1) )
                {
                  PipClearDevNodeProblem(v13);
                  PipSetDevNodeProblem(v13, 0x1Dui64, 0);
                }
                v18 = v13->Flags & 0x6000;
                if( PnpBootMode )
                {
                  v13->StateFlags |= 0x1000u;
                  v15 = 2;
                }
                PnpClearDeviceTemporaryProperties((INT64)v13->InstancePath.Buffer, (INT64)KeyHandle);
                if( (v13->CapabilityFlags & 0x4000) == 0 && (PropertyBuffer & 1) == 0 )
                {
                  if( v18 )
                    PpDevCfgProcessDevice(v13, KeyHandle, v15);
                  else
                    PpDevCfgProcessDeviceOperations(v13, KeyHandle);
                }
                if( ((v13->Flags & 0x2000) == 0 || v13->Problem != 22)
                  && ((v13->Flags & 0x2000) == 0 || v13->Problem != 29)
                  && !(unsigned int)PnpIsDeviceInstanceEnabled(KeyHandle, &v13->InstancePath.Length, 1) )
                {
                  PipClearDevNodeProblem(v13);
                  PipSetDevNodeProblem(v13, 0x16ui64, 0);
                }
                PpDeviceRegistration(&v13->InstancePath, 1u, &v13->ServiceName, 0);
                PnpMapDeviceObjectToDeviceInstance((__int64)v13->PhysicalDeviceObject, (__int64)&v13->InstancePath);
                DeviceNode = 0i64;
                if( PnpGetDeviceResourcesFromRegistry(
                       (__int64)v11,
                       0,
                       4,
                       (VOID **)&DeviceNode,
                       (ULONG *)&PropertySize + 1) >= 0 )
                {
                  v26 = DeviceNode;
                  if( DeviceNode )
                  {
                    if( (int)(*(&PnpReplaceEvent + 683))(4i64, v13->PhysicalDeviceObject, DeviceNode) >= 0 )
                      PipSetDevNodeFlags(v13, 0x40ui64);
                    ExFreePoolWithTag(v26, 0);
                  }
                }
                ObfReferenceObject(v11);
                *(_QWORD *)(*((_QWORD *)Context + 2) + 8i64 * *((unsigned int *)Context + 2)) = v11;
                goto LABEL_6;
              }
              FailedInstallProblemStatus = PiDevCfgGetFailedInstallProblemStatus(v13->InstancePath.Buffer, KeyHandle);
              v25 = 28i64;
            }
          }
          PipSetDevNodeProblem(v13, v25, FailedInstallProblemStatus);
          goto LABEL_18;
        }
        IoDeleteDevice(v11);
      }
    }
LABEL_67:
    *(_DWORD *)Context = v10;
  }
}

Referenced by:

IopGetRootDevices