PopFxRegisterDevice

NTSTATUS __fastcall PopFxRegisterDevice(
        PVOID Object,
        INT128 *a2,
        INT64 a3,
        _KNOWN_CONTROLLER_TYPE a4,
        INT64 a5,
        INT64 a6,
        INT64 a7){
  _DEVICE_OBJECT *DeviceAttachmentBaseRefWithTag; 
  _BYTE *v12; 
  _BYTE *v13; 
  _DEVICE_NODE *DeviceNode; 
  signed __int32 PowerFlags; 
  signed __int32 v16; 
  NTSTATUS v17; 
  __int64 v18; 
  __int64 v19; 
  _POP_FX_DEVICE *FxDevice; 

  FxDevice = 0i64;
  DeviceAttachmentBaseRefWithTag = IoGetDeviceAttachmentBaseRefWithTag((_DEVICE_OBJECT *)Object, 0x78466F50ui64);
  if( DeviceAttachmentBaseRefWithTag )
  {
    LODWORD(v12) = IoGetAttachedDeviceReferenceWithTag((PDEVICE_OBJECT)Object, 0x78466F50u);
    v13 = v12;
    if( v12 )
    {
      DeviceNode = (_DEVICE_NODE *)DeviceAttachmentBaseRefWithTag->DeviceObjectExtension->DeviceNode;
      if( DeviceNode )
      {
        _m_prefetchw((const void *)&DeviceNode->PowerFlags);
        PowerFlags = DeviceNode->PowerFlags;
        do
        {
          v16 = PowerFlags;
          PowerFlags = _InterlockedCompareExchange(&DeviceNode->PowerFlags, PowerFlags, PowerFlags);
        }
        while( v16 != PowerFlags );
        if( (PowerFlags & 1) != 0 )
        {
          v17 = PopFxRegisterDeviceWorker(
                  DeviceNode->Plugin,
                  &DeviceNode->UniqueId,
                  (__int128 *)a2,
                  a3,
                  a4,
                  a5,
                  v13[76] + 1,
                  a6,
                  (__int64)&FxDevice);
          if( v17 < 0 )
          {
            FxDevice = 0i64;
          }
          else
          {
            *((_QWORD *)FxDevice + 6) = DeviceNode;
            if( DeviceNode->FxDevice )
              PopFxBugCheck(0x600u, (ULONG_PTR)DeviceNode->PhysicalDeviceObject, 0, 0);
            PopGenerateDeviceFriendlyName((INT64)DeviceNode, (_UNICODE_STRING *)((char *)FxDevice + 1192));
            PopFxAssignDeviceToDevNode(DeviceNode, FxDevice);
            ObfReferenceObjectWithTag(Object, 0x78466F50ui64);
            *((_QWORD *)FxDevice + 12) = Object;
            *((_QWORD *)FxDevice + 13) = v13;
            PopFxTraceDeviceRegistration(FxDevice, 0);
            PopFxInsertDevice(v19, v18, FxDevice);
            v13 = 0i64;
            DeviceAttachmentBaseRefWithTag = 0i64;
            v17 = 0;
          }
        }
        else
        {
          v17 = -1073741661;
        }
      }
      else
      {
        v17 = -1073741811;
      }
      if( v13 )
        ObfDereferenceObjectWithTag(v13, 0x78466F50ui64);
    }
    else
    {
      v17 = -1073741811;
    }
    if( DeviceAttachmentBaseRefWithTag )
      ObfDereferenceObjectWithTag(DeviceAttachmentBaseRefWithTag, 0x78466F50ui64);
  }
  else
  {
    v17 = -1073741811;
  }
  *(_QWORD *)a7 = FxDevice;
  return v17;
}

Referenced by:

PoFxEnableDStateReporting
PoFxRegisterDevice
PoFxRegisterPrimaryDevice