PopFxRegisterDevice

INT64 __fastcall PopFxRegisterDevice(
        _DEVICE_OBJECT *DeviceObject,
        _POP_FX_DRIVER_CALLBACKS *Callbacks,
        _PO_FX_COMPONENT_V2 *Components,
        UINT64 ComponentCount,
        VOID *DeviceContext,
        UINT64 Flags,
        POHANDLE__ **Handle){
  int v8; 
  DEVICE_OBJECT *DeviceAttachmentBaseRefWithTag; 
  _BYTE *v12; 
  _BYTE *v13; 
  INT64 v14; 
  signed __int32 v15; 
  signed __int32 v16; 
  int v17; 
  EVENT_DESCRIPTOR *v18; 
  __int64 v19; 
  __int64 v20; 
  UINT64 ComponentCounta; 
  INT64 IrpStackSize; 
  _POP_FX_DEVICE *v24; 
  v24 = 0i64;
  v8 = ComponentCount;
  DeviceAttachmentBaseRefWithTag = IoGetDeviceAttachmentBaseRefWithTag(DeviceObject, 0x78466F50ui64);
  if( DeviceAttachmentBaseRefWithTag )
  {
    LODWORD(v12) = IoGetAttachedDeviceReferenceWithTag(DeviceObject, 0x78466F50u);
    v13 = v12;
    if( v12 )
    {
      v14 = *(_QWORD *)(*((_QWORD *)DeviceAttachmentBaseRefWithTag + 39) + 40i64);
      if( v14 )
      {
        _m_prefetchw((const void *)(v14 + 296));
        v15 = *(_DWORD *)(v14 + 296);
        do
        {
          v16 = v15;
          v15 = _InterlockedCompareExchange((volatile signed __int32 *)(v14 + 296), v15, v15);
        }
        while( v16 != v15 );
        if( (v15 & 1) != 0 )
        {
          LOBYTE(IrpStackSize) = v13[76] + 1;
          LODWORD(ComponentCounta) = v8;
          v17 = PopFxRegisterDeviceWorker(
                  *(_POP_FX_PLUGIN **)(v14 + 144),
                  (const _UNICODE_STRING *)(v14 + 128),
                  Callbacks,
                  Components,
                  ComponentCounta,
                  DeviceContext,
                  IrpStackSize,
                  Flags,
                  &v24);
          if( v17 < 0 )
          {
            v24 = 0i64;
          }
          else
          {
            *((_QWORD *)v24 + 6) = v14;
            if( *(_QWORD *)(v14 + 80) )
              PopFxBugCheck(0x600ui64, *(_QWORD *)(v14 + 32), 0i64, 0i64);
            PopGenerateDeviceFriendlyName(v14, (UNICODE_STRING *)((char *)v24 + 1192));
            PopFxAssignDeviceToDevNode(v14, (__int64)v24);
            ObfReferenceObjectWithTag(DeviceObject, 0x78466F50u);
            *((_QWORD *)v24 + 12) = DeviceObject;
            *((_QWORD *)v24 + 13) = v13;
            PopFxTraceDeviceRegistration((__int64)v24, 0, v18);
            PopFxInsertDevice(v20, v19, v24);
            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;
  }
  *Handle = (POHANDLE__ *)v24;
  return(unsigned int)v17;
}

Referenced by:

PoFxEnableDStateReporting
PoFxRegisterDevice
PoFxRegisterPrimaryDevice