CmAddDeviceToContainerWorker

NTSTATUS __stdcall CmAddDeviceToContainerWorker(
        HPNPCTX *hPnpCtx,
        WCHAR *ContainerId,
        WCHAR *BaseContainerId,
        WCHAR *DeviceInstanceId,
        UINT8 *DeviceAlreadyInContainer){
  UINT8 *v5; 
  NTSTATUS v10; 
  WCHAR *v11; 
  UINT64 v12; 
  VOID *v13; 
  int v14; 
  int Value; 
  __int64 v17; 
  VOID *v18; 
  __int64 v19; 
  VOID *v20; 
  INT64 a5; 
  INT64 a6; 
  UINT8 a6a; 
  INT64 a7; 
  INT64 a8; 
  _BYTE v26[12]; 
  VOID *Handle; 
  VOID *phkResult; 
  VOID *DeviceContainerKey; 

  v5 = DeviceAlreadyInContainer;
  DeviceContainerKey = 0i64;
  phkResult = 0i64;
  Handle = 0i64;
  *DeviceAlreadyInContainer = 0;
  v26[0] = 0;
  *(_QWORD *)&v26[4] = 0i64;
  v10 = CmCreateDeviceContainer(hPnpCtx, ContainerId, (INT64)BaseContainerId, &DeviceContainerKey, v26, a6);
  v13 = DeviceContainerKey;
  v14 = v10;
  if( v10 >= 0 )
  {
    LODWORD(a5) = 4;
    v14 = PnpCtxRegCreateKey(
            hPnpCtx,
            DeviceContainerKey,
            (WCHAR *)L"BaseContainers",
            0i64,
            a5,
            0i64,
            &phkResult,
            (UINT64 *)&v26[8]);
    if( v14 >= 0 )
    {
      LODWORD(a5) = 3;
      v14 = PnpCtxRegCreateKey(hPnpCtx, phkResult, BaseContainerId, 0i64, a5, 0i64, &Handle, (UINT64 *)&v26[4]);
      if( v14 >= 0 )
      {
        if( *(_DWORD *)&v26[4] == 2 )
        {
          LODWORD(DeviceAlreadyInContainer) = 0;
          Value = RegRtlQueryValue(Handle, DeviceInstanceId, 0i64, 0i64, (__int64)&DeviceAlreadyInContainer);
          v14 = Value;
          if( Value == -1073741772 || Value == -1073741444 )
          {
            v14 = 0;
          }
          else if( !Value )
          {
            *v5 = 1;
            goto LABEL_9;
          }
        }
        if( v14 >= 0 && !*v5 )
        {
          LODWORD(a5) = 0;
          v14 = RegRtlSetValue(Handle, DeviceInstanceId, 0, 0i64, a5);
          if( v14 >= 0 )
            PnpObjectRaisePropertyChangeEvent(
              (__int64)hPnpCtx,
              (INT64)DeviceInstanceId,
              1i64,
              0i64,
              0i64,
              (__int64)&DEVPKEY_Device_ContainerId);
        }
      }
    }
  }
  if( v14 == -1073741444 )
    v14 = -1073741772;
  if( v14 < 0 )
  {
    if( *(_DWORD *)&v26[4] == 1 )
    {
      if( hPnpCtx && (v17 = *((_QWORD *)hPnpCtx + 28)) != 0 )
        v18 = *(VOID **)(v17 + 8);
      else
        v18 = 0i64;
      RegRtlDeleteKeyTransacted(Handle, 0i64, v18);
    }
    if( *(_DWORD *)&v26[8] == 1 )
    {
      if( hPnpCtx && (v19 = *((_QWORD *)hPnpCtx + 28)) != 0 )
        v20 = *(VOID **)(v19 + 8);
      else
        v20 = 0i64;
      RegRtlDeleteKeyTransacted(phkResult, 0i64, v20);
    }
    if( v26[0] == 1 )
      CmDeleteDeviceContainer(hPnpCtx, ContainerId, v11, v12, a5, a6a, a7, a8, *(UINT64 **)v26);
  }
LABEL_9:
  if( Handle )
    ZwClose((_HANDLE)Handle);
  if( phkResult )
    ZwClose((_HANDLE)phkResult);
  if( v13 )
    ZwClose((_HANDLE)v13);
  return v14;
}

Referenced by:

CmAddDeviceToContainer