IopInitializeDeviceInstanceKey

UINT64 __stdcall IopInitializeDeviceInstanceKey(PVOID KeyHandle, _UNICODE_STRING *DeviceInstancePath, PVOID Context){
  int v6; 
  _QWORD *v7; 
  struct _DMA_ADAPTER *v8; 
  UINT64 result; 
  int v10; 
  _DEVICE_OBJECT *v11; 
  _QWORD *v12; 
  char *v13; 
  UNICODE_STRING *v14; 
  _PNP_DEVNODE_STATE *v15; 
  char v16; 
  int DeviceRegProp; 
  __int16 v18; 
  const WCHAR *v19; 
  INT64 v20; 
  int v21; 
  const WCHAR *v22; 
  INT64 v23; 
  PVOID v24; 
  int v25; 
  unsigned int v26; 
  UINT8 *PoolWithTag; 
  UINT8 *v28; 
  int FailedInstallProblemStatus; 
  int v30; 
  PVOID v31; 
  int v32; 
  unsigned int Length; 
  PVOID P; 
  PVOID Object; 
  PVOID Resource; 
  int v37; 
  int v38; 
  P = 0i64;
  v38 = 0;
  Resource = 0i64;
  if( IopGetRegistryValue(KeyHandle, (PWCHAR)L"Phantom", 0i64, (KEY_VALUE_FULL_INFORMATION **)&P) >= 0 )
  {
    v25 = *((_DWORD *)P + 1) == 4 && *((_DWORD *)P + 3) >= 4u ? *(_DWORD *)((char *)P + *((unsigned int *)P + 2)) : 0;
    ExFreePoolWithTag(P, 0);
    if( v25 )
      return 1i64;
  }
  v6 = *((_DWORD *)Context + 1);
  if( *((_DWORD *)Context + 2) == v6 )
  {
    v26 = 8 * v6 + 1024;
    PoolWithTag = (UINT8 *)ExAllocatePoolWithTag(PagedPool, v26, 0x64647050ui64);
    v28 = PoolWithTag;
    if( !PoolWithTag )
    {
      v10 = -1073741670;
      goto LABEL_68;
    }
    memmove(PoolWithTag, *((UINT8 **)Context + 2), 8i64 * *((unsigned int *)Context + 2));
    ExFreePoolWithTag(*((PVOID *)Context + 2), 0);
    *((_DWORD *)Context + 1) = v26 >> 3;
    *((_QWORD *)Context + 2) = v28;
  }
  v7 = PnpDeviceObjectFromDeviceInstanceWithTag((INT64)DeviceInstancePath, 0x746C6644ui64);
  Object = v7;
  if( v7 )
  {
    if( !IopIsRootEnumeratedDeviceObjectActive((INT64)v7) )
    {
      HalPutDmaAdapter(v8);
      return 1i64;
    }
    *(_QWORD *)(*((_QWORD *)Context + 2) + 8i64 * *((unsigned int *)Context + 2)) = v8;
LABEL_6:
    ++*((_DWORD *)Context + 2);
    return 1i64;
  }
  v10 = IopCreateRootEnumeratedDeviceObject(&Object);
  if( v10 >= 0 )
  {
    v11 = (_DEVICE_OBJECT *)Object;
    v12 = Object;
    *((_DWORD *)Object + 12) |= 0x1000u;
    *(_DWORD *)(v12[39] + 32i64) |= 0x10u;
    if( (unsigned int)PipAllocateDeviceNode((__int64)v12, &Resource) == -1073740946 || (v13 = (char *)Resource) == 0i64 )
    {
      IoDeleteDevice(v11);
      v10 = -1073741670;
    }
    else
    {
      v10 = PnpAllocateDeviceInstancePath((__int64)Resource, (unsigned int)DeviceInstancePath->Length + 2);
      if( v10 >= 0 )
      {
        PnpCopyDeviceInstancePath((__int64)v13, DeviceInstancePath, v14);
        PipSetDevNodeFlags((__int64)v13, 17);
        PipSetDevNodeState((_DEVICE_NODE *)v13, DeviceNodeInitialized, v15);
        PpDevNodeInsertIntoTree((__int64)IopRootDeviceNode, (__int64)v13);
        ObfReferenceObject(v11);
        v16 = 0;
        v32 = 4;
        v37 = 0;
        DeviceRegProp = CmGetDeviceRegProp(
                          PiPnpRtlCtx,
                          *((const wchar_t **)v13 + 6),
                          (__int64)KeyHandle,
                          11,
                          (__int64)&v38,
                          (__int64)&v37,
                          (__int64)&v32,
                          0);
        if( DeviceRegProp < 0 )
        {
          FailedInstallProblemStatus = -1073741275;
          if( DeviceRegProp != -1073741275 )
            goto LABEL_19;
          v30 = 1;
        }
        else
        {
          if( v38 == 4 && v32 == 4 )
          {
            v18 = v37;
          }
          else
          {
            v18 = 0;
            v37 = 0;
          }
          if( (v18 & 0x20) != 0 )
          {
            FailedInstallProblemStatus = 0;
            v30 = 18;
          }
          else if( (v18 & 0x2000) != 0 )
          {
            FailedInstallProblemStatus = 0;
            v30 = 16;
          }
          else
          {
            if( (v18 & 0x40) == 0 )
            {
LABEL_19:
              if( IopGetRegistryValue(
                     KeyHandle,
                     (PWCHAR)L"NoResourceAtInitTime",
                     0i64,
                     (KEY_VALUE_FULL_INFORMATION **)&P) >= 0 )
              {
                v24 = P;
                if( *((_DWORD *)P + 1) == 4
                  && *((_DWORD *)P + 3) >= 4u
                  && *(_DWORD *)((char *)P + *((unsigned int *)P + 2)) )
                {
                  PipSetDevNodeFlags((__int64)v13, 256);
                }
                ExFreePoolWithTag(v24, 0);
              }
              PnpQueryAndSaveDeviceNodeCapabilities((__int64)v13);
              if( (*((_DWORD *)v13 + 140) & 0x4000) != 0
                && ((*((_DWORD *)v13 + 99) & 0x2000) == 0 || *((_DWORD *)v13 + 101) != 1) )
              {
                PipClearDevNodeProblem((INT64)v13, v19, v20);
                PipSetDevNodeProblem((__int64)v13, 29, 0);
              }
              v21 = *((_DWORD *)v13 + 99) & 0x6000;
              if( PnpBootMode )
              {
                *((_DWORD *)v13 + 176) |= 0x1000u;
                v16 = 2;
              }
              PnpClearDeviceTemporaryProperties(*((PWCHAR *)v13 + 6), KeyHandle);
              if( (*((_DWORD *)v13 + 140) & 0x4000) == 0 && (v37 & 1) == 0 )
              {
                if( v21 )
                  PpDevCfgProcessDevice((__int64)v13, (__int64)KeyHandle, v16);
                else
                  PpDevCfgProcessDeviceOperations((__int64)v13, KeyHandle);
              }
              if( ((*((_DWORD *)v13 + 99) & 0x2000) == 0 || *((_DWORD *)v13 + 101) != 22)
                && ((*((_DWORD *)v13 + 99) & 0x2000) == 0 || *((_DWORD *)v13 + 101) != 29)
                && !(unsigned int)PnpIsDeviceInstanceEnabled(KeyHandle, (UNICODE_STRING *)(v13 + 40), 1ui64) )
              {
                PipClearDevNodeProblem((INT64)v13, v22, v23);
                PipSetDevNodeProblem((__int64)v13, 22, 0);
              }
              PpDeviceRegistration((UNICODE_STRING *)(v13 + 40), 1u, (UNICODE_STRING *)(v13 + 56), 0);
              PnpMapDeviceObjectToDeviceInstance(*((DEVICE_OBJECT **)v13 + 4), (UNICODE_STRING *)(v13 + 40));
              Resource = 0i64;
              if( (int)PnpGetDeviceResourcesFromRegistry(v11, 0, 4u, &Resource, &Length) >= 0 )
              {
                v31 = Resource;
                if( Resource )
                {
                  if( (int)((__int64(__fastcall *)(__int64, _QWORD, PVOID))IopAllocateBootResourcesRoutine)(
                              4i64,
                              *((_QWORD *)v13 + 4),
                              Resource) >= 0 )
                    PipSetDevNodeFlags((__int64)v13, 64);
                  ExFreePoolWithTag(v31, 0);
                }
              }
              ObfReferenceObject(v11);
              *(_QWORD *)(*((_QWORD *)Context + 2) + 8i64 * *((unsigned int *)Context + 2)) = v11;
              goto LABEL_6;
            }
            FailedInstallProblemStatus = PiDevCfgGetFailedInstallProblemStatus(*((WCHAR **)v13 + 6), KeyHandle);
            v30 = 28;
          }
        }
        PipSetDevNodeProblem((__int64)v13, v30, FailedInstallProblemStatus);
        goto LABEL_19;
      }
      IoDeleteDevice(v11);
    }
  }
LABEL_68:
  result = 0i64;
  *(_DWORD *)Context = v10;
  return result;
}

Referenced by:

IopGetRootDevices