PiDcHandleCustomDeviceEvent

__int64 __fastcall PiDcHandleCustomDeviceEvent(__int64 a1){
  __int64 v1; 
  int DeviceRelations; 
  __int64 v4; 
  __int64 v5; 
  INT64 v7; 
  _DWORD *v8; 
  _ETHREAD *CurrentThread; 
  int v10; 
  _DWORD *v11; 
  bool v12; 
  __int64 i; 
  __int64 v14; 
  __int64 v15; 
  const WCHAR *v16; 
  NTSTATUS DeviceRegProp; 
  WCHAR *v18; 
  WCHAR *v19; 
  __int64 v20; 
  UINT64 *CmRegPropType; 
  UINT64 *CmRegPropTypea; 
  UINT64 v23; 
  UINT64 v24; 
  __int128 ContainerIdLength; 
  HPNPOPCTX *hPnpOpCtx; 
  WCHAR pszSrc[40]; 
  WCHAR ContainerId[40]; 
  UINT8 PropertyBuffer[80]; 
  UINT8 v30[80]; 

  v1 = *(_QWORD *)(a1 + 160);
  DeviceRelations = 0;
  ContainerIdLength = 0ui64;
  v4 = *(_QWORD *)(v1 + 4);
  hPnpOpCtx = 0i64;
  v5 = v4 - *(_QWORD *)&GUID_TARGET_DEVICE_TRANSPORT_RELATIONS_CHANGED.Data1;
  if( !v5 )
    v5 = *(_QWORD *)(v1 + 12) - *(_QWORD *)GUID_TARGET_DEVICE_TRANSPORT_RELATIONS_CHANGED.Data4;
  if( !v5 )
  {
    DeviceRelations = PiPnpRtlBeginOperation(&hPnpOpCtx);
    if( DeviceRelations >= 0 )
    {
      DeviceRelations = PnpQueryDeviceRelations(
                          *(_DEVICE_OBJECT **)(a1 + 152),
                          6,
                          0i64,
                          (UINT64 *)&ContainerIdLength + 1);
      if( DeviceRelations >= 0 )
      {
        v8 = (_DWORD *)*((_QWORD *)&ContainerIdLength + 1);
        if( !*((_QWORD *)&ContainerIdLength + 1) )
        {
LABEL_38:
          if( hPnpOpCtx )
            PiPnpRtlEndOperation(hPnpOpCtx);
          return(unsigned int)DeviceRelations;
        }
        if( !**((_DWORD **)&ContainerIdLength + 1) )
        {
LABEL_35:
          if( v8 )
          {
            v20 = 0i64;
            if( *v8 )
            {
              do
              {
                HalPutDmaAdapter(*(PADAPTER_OBJECT *)&v8[2 * v20 + 2]);
                v8 = (_DWORD *)*((_QWORD *)&ContainerIdLength + 1);
                v20 = (unsigned int)(v20 + 1);
              }
              while( (unsigned int)v20 < **((_DWORD **)&ContainerIdLength + 1) );
            }
          }
          goto LABEL_38;
        }
        CurrentThread = (_ETHREAD *)KeGetCurrentThread();
        --CurrentThread->Tcb.KernelApcDisable;
        ExAcquireResourceExclusiveLite((UINT64)&PnpReplaceEvent + 6688, 1, v7);
        LODWORD(v23) = 0;
        LODWORD(ContainerIdLength) = 78;
        if( CmGetDeviceRegProp(
               *(&stru_140CF2E80 + 607),
               (const WCHAR *)(a1 + 168),
               0i64,
               37i64,
               (UINT64 *)((char *)&ContainerIdLength + 4),
               PropertyBuffer,
               (UINT64 *)&ContainerIdLength,
               v23) >= 0
          && (_QWORD)ContainerIdLength == 0x10000004Ei64 )
        {
          DeviceRelations = CmGetDeviceContainerIdFromBase(
                              *(&stru_140CF2E80 + 607),
                              (const WCHAR *)(a1 + 168),
                              (const WCHAR *)PropertyBuffer,
                              ContainerId,
                              (UINT64)CmRegPropType);
          if( DeviceRelations >= 0 )
          {
            v10 = wcsicmp((const wchar_t *)PropertyBuffer, ContainerId);
            v11 = (_DWORD *)*((_QWORD *)&ContainerIdLength + 1);
            v12 = v10 != 0;
            for( i = 0i64; (unsigned int)i < *v11; i = (unsigned int)(i + 1) )
            {
              v14 = *(_QWORD *)&v11[2 * i + 2];
              if( v14 )
                v15 = *(_QWORD *)(*(_QWORD *)(v14 + 312) + 40i64);
              else
                v15 = 0i64;
              if( v15 )
              {
                v16 = *(const WCHAR **)(v15 + 48);
                if( v16 )
                {
                  LODWORD(v24) = 0;
                  LODWORD(ContainerIdLength) = 78;
                  DeviceRegProp = CmGetDeviceRegProp(
                                    *(&stru_140CF2E80 + 607),
                                    v16,
                                    0i64,
                                    37i64,
                                    (UINT64 *)((char *)&ContainerIdLength + 4),
                                    v30,
                                    (UINT64 *)&ContainerIdLength,
                                    v24);
                  DeviceRelations = DeviceRegProp;
                  if( DeviceRegProp != -1073741275 )
                  {
                    if( DeviceRegProp < 0 || (_QWORD)ContainerIdLength != 0x10000004Ei64 )
                      goto LABEL_32;
                    DeviceRelations = CmGetDeviceContainerIdFromBase(
                                        *(&stru_140CF2E80 + 607),
                                        v16,
                                        (const WCHAR *)v30,
                                        pszSrc,
                                        (UINT64)CmRegPropTypea);
                    if( DeviceRelations < 0 )
                      break;
                    if( !v12 )
                    {
                      DeviceRelations = CmMoveBaseContainer(v18, (WCHAR *)PropertyBuffer, ContainerId);
                      PiDcContainerRequiresConfiguration(pszSrc);
                      if( DeviceRelations < 0 )
                        break;
                      DeviceRelations = RtlStringCbCopyW(ContainerId, 0x4Eui64, pszSrc);
                      if( DeviceRelations < 0 )
                        break;
                      v12 = 1;
                    }
                    if( wcsicmp(pszSrc, ContainerId) )
                    {
                      if( !CmIsLocalMachineContainer(*(&stru_140CF2E80 + 607), pszSrc) )
                      {
                        DeviceRelations = CmMoveBaseContainer(v19, (WCHAR *)v30, pszSrc);
                        PiDcContainerRequiresConfiguration(ContainerId);
                        if( DeviceRelations < 0 )
                          break;
                      }
                    }
                  }
                  v11 = (_DWORD *)*((_QWORD *)&ContainerIdLength + 1);
                }
              }
            }
          }
        }
        else
        {
LABEL_32:
          DeviceRelations = -1073739509;
        }
        ExReleaseResourceLite((PERESOURCE)((char *)&PnpReplaceEvent + 6688));
        KeLeaveCriticalRegion();
      }
    }
    v8 = (_DWORD *)*((_QWORD *)&ContainerIdLength + 1);
    goto LABEL_35;
  }
  return(unsigned int)DeviceRelations;
}

Referenced by:

PnpProcessCustomDeviceEvent